diff --git a/CHANGES.md b/CHANGES.md index 01a94c1a4..a6a3b762b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,35 @@ +---- + PUBLIC DOMAIN NOTICE + National Center for Biotechnology Information + +This software/database is a "United States Government Work" under the +terms of the United States Copyright Act. It was written as part of +the author's official duties as a United States Government employee and +thus cannot be copyrighted. This software/database is freely available +to the public for use. The National Library of Medicine and the U.S. +Government have not placed any restriction on its use or reproduction. + +Although all reasonable efforts have been taken to ensure the accuracy +and reliability of the software and data, the NLM and the U.S. +Government do not and cannot warrant the performance or results that +may be obtained by using this software or data. The NLM and the U.S. +Government disclaim all warranties, express or implied, including +warranties of performance, merchantability or fitness for any particular +purpose. + +Please cite the author in any work or product based on this material. + +---- # NCBI External Developer Release: +## NCBI VDB 3.2.1 +**March 18, 2025** + + **fasterq-dump, kns, sratools, vdb, vfs**: fixed failure of fasterq-dump when accessing run via HTTP + **kdb**: fixed memory leak + + ## NCBI VDB 3.2.0 **January 14, 2025** diff --git a/build/.gitignore b/build/.gitignore index fa1854bfa..70f16d35b 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1,4 +1,4 @@ ld.linux.exe_cmd.sh Makefile.config* COMP.* - +a.out diff --git a/build/Makefile.env b/build/Makefile.env index 53e05b3c5..4ee7373e5 100644 --- a/build/Makefile.env +++ b/build/Makefile.env @@ -82,6 +82,8 @@ endif unexport TOP SRCDIR +export OS_DISTRIBUTOR + # CPP comes from Makefile.config.$(OS_ARCH) # TODO: simplify Makefile.config.$(OS_ARCH) generated by ./configure - switch from using LD to a new variable CMAKEFLAGS = \ diff --git a/build/Makefile.vers b/build/Makefile.vers index 8139b66eb..af7c8d732 100644 --- a/build/Makefile.vers +++ b/build/Makefile.vers @@ -23,4 +23,4 @@ # =========================================================================== # NCBI-VDB and library version -VERSION = 3.2.1 +VERSION = 3.2.2 diff --git a/build/common.cmake b/build/common.cmake index d4d17f617..4da8b1033 100644 --- a/build/common.cmake +++ b/build/common.cmake @@ -39,6 +39,13 @@ function( MSVS_DLLRuntime name ) endif() endfunction() +# +# sanitizer settings +# address sanitizer: stop and fail the test if undefined behavior is detected +set( asan_defs "-fsanitize=address" "-fsanitize=undefined" "-fno-sanitize-recover=undefined" ) +set( tsan_defs "-fsanitize=thread" ) +# + function( GenerateStaticLibsWithDefs target_name sources compile_defs ) add_library( ${target_name} STATIC ${sources} ) if( NOT "" STREQUAL "${compile_defs}" ) @@ -54,7 +61,6 @@ function( GenerateStaticLibsWithDefs target_name sources compile_defs ) endif() if( RUN_SANITIZER_TESTS ) - set( asan_defs "-fsanitize=address" "-fsanitize=undefined" ) add_library( "${target_name}-asan" STATIC ${sources} ) if( NOT "" STREQUAL "${compile_defs}" ) target_compile_definitions( "${target_name}-asan" PRIVATE ${compile_defs} ) @@ -62,7 +68,6 @@ function( GenerateStaticLibsWithDefs target_name sources compile_defs ) target_compile_options( "${target_name}-asan" PUBLIC ${asan_defs} ) target_link_options( "${target_name}-asan" PUBLIC ${asan_defs} ) - set( tsan_defs "-fsanitize=thread" "-fsanitize=undefined" ) add_library( "${target_name}-tsan" STATIC ${sources} ) if( NOT "" STREQUAL "${compile_defs}" ) target_compile_definitions( "${target_name}-tsan" PRIVATE ${compile_defs} ) @@ -198,9 +203,13 @@ endfunction() function( BuildExecutableForTest exe_name sources libraries ) add_executable( ${exe_name} ${sources} ) - if(NOT _NCBIVDB_CFG_PACKAGING) + if( WIN32 ) + target_link_options( ${exe_name} PRIVATE "/ENTRY:mainCRTStartup" ) + endif() + + if(NOT _NCBIVDB_CFG_PACKAGING) MSVS_StaticRuntime( ${exe_name} ) - endif() + endif() target_link_libraries( ${exe_name} ${libraries} ) endfunction() @@ -209,13 +218,11 @@ function( AddExecutableTest test_name sources libraries ) add_test( NAME ${test_name} COMMAND ${test_name} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) if( RUN_SANITIZER_TESTS ) - set( asan_defs "-fsanitize=address" "-fsanitize=undefined" ) BuildExecutableForTest( "${test_name}_asan" "${sources}" "${libraries}" ) target_compile_options( "${test_name}_asan" PRIVATE ${asan_defs} ) target_link_options( "${test_name}_asan" PRIVATE ${asan_defs} ) add_test( NAME "${test_name}_asan" COMMAND "${test_name}_asan" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) - set( tsan_defs "-fsanitize=thread" "-fsanitize=undefined" ) BuildExecutableForTest( "${test_name}_tsan" "${sources}" "${libraries}" ) target_compile_options( "${test_name}_tsan" PRIVATE ${tsan_defs} ) target_link_options( "${test_name}_tsan" PRIVATE ${tsan_defs} ) diff --git a/build/env.cmake b/build/env.cmake index 5fe6f2fd4..45981a0a5 100644 --- a/build/env.cmake +++ b/build/env.cmake @@ -389,31 +389,51 @@ if ( SINGLE_CONFIG ) ) endif() -if( NOT SINGLE_CONFIG ) - if( RUN_SANITIZER_TESTS ) - message( "RUN_SANITIZER_TESTS (${RUN_SANITIZER_TESTS}) cannot be turned on in a non single config mode - overriding to OFF" ) - endif() - set( RUN_SANITIZER_TESTS OFF ) -endif() +execute_process( COMMAND sh -c "${CMAKE_CXX_COMPILER} -fsanitize=address test.cpp && ./a.out" + RESULT_VARIABLE ASAN_WORKS + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build ) +execute_process( COMMAND sh -c "${CMAKE_CXX_COMPILER} -fsanitize=thread test.cpp && ./a.out" + RESULT_VARIABLE TSAN_WORKS + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build ) + +if( ASAN_WORKS EQUAL 0 AND TSAN_WORKS EQUAL 0 ) + + if( NOT SINGLE_CONFIG AND RUN_SANITIZER_TESTS ) + message( "RUN_SANITIZER_TESTS (${RUN_SANITIZER_TESTS}) cannot be turned on in a non single config mode - overriding to OFF" ) + set( RUN_SANITIZER_TESTS OFF ) + endif() -if( RUN_SANITIZER_TESTS ) - find_program(LSB_RELEASE_EXEC lsb_release) - execute_process(COMMAND ${LSB_RELEASE_EXEC} -is - OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - message("LSB_RELEASE_ID_SHORT: ${LSB_RELEASE_ID_SHORT}") - if( LSB_RELEASE_ID_SHORT STREQUAL "Ubuntu" ) - message("Disabling sanitizer tests on Ubuntu...") - set( RUN_SANITIZER_TESTS OFF ) - endif() -endif() + if( RUN_SANITIZER_TESTS_OVERRIDE ) + message("Overriding sanitizer tests due to RUN_SANITIZER_TESTS_OVERRIDE: ${RUN_SANITIZER_TESTS_OVERRIDE}") + set( RUN_SANITIZER_TESTS ON ) + endif() + + # + # TSAN-instrumented programs used to crash on starup with certain version of Ubuntu kernel. Seems to be not thecase anymore, so disabling this section. + # + # if( RUN_SANITIZER_TESTS ) + # find_program(LSB_RELEASE_EXEC lsb_release) + # execute_process(COMMAND ${LSB_RELEASE_EXEC} -is + # OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT + # OUTPUT_STRIP_TRAILING_WHITESPACE + # ) + # message("LSB_RELEASE_ID_SHORT: ${LSB_RELEASE_ID_SHORT}") + # if( LSB_RELEASE_ID_SHORT STREQUAL "Ubuntu" ) + # message("Disabling sanitizer tests on Ubuntu...") + # set( RUN_SANITIZER_TESTS OFF ) + # endif() + # endif() + +else() + + message("ASAN suport is not detected. Disabling sanitizer tests.") + set( RUN_SANITIZER_TESTS OFF ) + set( RUN_SANITIZER_TESTS_OVERRIDE OFF ) -if( RUN_SANITIZER_TESTS_OVERRIDE ) - message("Overriding sanitizer tests due to RUN_SANITIZER_TESTS_OVERRIDE: ${RUN_SANITIZER_TESTS_OVERRIDE}") - set( RUN_SANITIZER_TESTS ON ) endif() message( "RUN_SANITIZER_TESTS: ${RUN_SANITIZER_TESTS}" ) + + endif(NOT _NCBIVDB_CFG_PACKAGING) if( NOT HAVE_MBEDTLS_F ) diff --git a/build/san_test.cpp b/build/san_test.cpp new file mode 100644 index 000000000..979a1cd78 --- /dev/null +++ b/build/san_test.cpp @@ -0,0 +1 @@ +int main(){} diff --git a/build/test.cpp b/build/test.cpp new file mode 100644 index 000000000..97a268f69 --- /dev/null +++ b/build/test.cpp @@ -0,0 +1,6 @@ +#include +int main() +{ + //void* p = malloc(1); + return 0; +} diff --git a/interfaces/cc/clang/arm64/atomic.h b/interfaces/cc/clang/atomic.h similarity index 93% rename from interfaces/cc/clang/arm64/atomic.h rename to interfaces/cc/clang/atomic.h index 27d5eb515..cacdb79fe 100644 --- a/interfaces/cc/clang/arm64/atomic.h +++ b/interfaces/cc/clang/atomic.h @@ -42,11 +42,9 @@ extern "C" { #if DFLT_ATOMIC_BITS == 32 #define ATOMIC_NAME( suffix ) \ atomic32_ ## suffix -typedef int atomic_int; #else #define ATOMIC_NAME( suffix ) \ atomic64_ ## suffix -typedef long int atomic_int; #endif typedef struct ATOMIC_NAME ( t ) atomic_t; @@ -108,14 +106,16 @@ struct atomic_ptr_t /* int atomic_read_ptr ( const atomic_ptr_t *v ); */ #define atomic_read_ptr( v ) \ - ( ( v ) -> ptr ) + __atomic_load_n( & ( ( v ) -> ptr ), __ATOMIC_SEQ_CST ) + +#define atomic_set_ptr( v, s ) \ + __atomic_store_n( & ( ( v ) -> ptr ), s, __ATOMIC_SEQ_CST ) static __inline__ -void *atomic_test_and_set_ptr ( atomic_ptr_t *v, void *s, void *t ) +void *atomic_test_and_set_ptr ( atomic_ptr_t *const v, void *const s, void *const t ) { - void *rtn = v -> ptr; - if ( rtn == t ) - v -> ptr = s; + void *rtn = t; + __atomic_compare_exchange_n(&v->ptr, &rtn, s, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return rtn; } @@ -178,6 +178,7 @@ void *atomic_test_and_set_ptr ( atomic_ptr_t *v, void *s, void *t ) #ifdef __cplusplus } + #endif #endif /* _h_atomic_ */ diff --git a/interfaces/cc/clang/arm64/atomic32.h b/interfaces/cc/clang/atomic32.h similarity index 82% rename from interfaces/cc/clang/arm64/atomic32.h rename to interfaces/cc/clang/atomic32.h index 99bb7f3c0..d2ec5ee0e 100644 --- a/interfaces/cc/clang/arm64/atomic32.h +++ b/interfaces/cc/clang/atomic32.h @@ -39,64 +39,64 @@ extern "C" { typedef struct atomic32_t atomic32_t; struct atomic32_t { - volatile int counter; + int volatile counter; }; /* int atomic32_read ( const atomic32_t *v ); */ #define atomic32_read( v ) \ - ( ( v ) -> counter ) + __atomic_load_n(&((v)->counter), __ATOMIC_SEQ_CST) /* void atomic32_set ( atomic32_t *v, int i ); */ #define atomic32_set( v, i ) \ - ( ( void ) ( ( ( v ) -> counter ) = ( i ) ) ) + __atomic_store_n(&((v)->counter), i, __ATOMIC_SEQ_CST) /* add to v -> counter and return the prior value */ -static __inline__ int atomic32_read_and_add ( atomic32_t *v, int i ) -{ - return __sync_fetch_and_add( & v -> counter, i ); -} +#define atomic32_read_and_add( v, i ) \ + __atomic_fetch_add(&((v)->counter), i, __ATOMIC_SEQ_CST) /* if no read is needed, define the least expensive atomic add */ #define atomic32_add( v, i ) \ - atomic32_read_and_add ( v, i ) + ((void)atomic32_read_and_add(v, i)) /* add to v -> counter and return the result */ -static __inline__ int atomic32_add_and_read ( atomic32_t *v, int i ) +static __inline__ int atomic32_add_and_read ( atomic32_t *const v, int const i ) { - return __sync_add_and_fetch( & v -> counter, i ); + return __atomic_add_fetch(&((v)->counter), i, __ATOMIC_SEQ_CST); } /* just don't try to find out what the result was */ -static __inline__ void atomic32_inc ( atomic32_t *v ) +static __inline__ void atomic32_inc ( atomic32_t *const v ) { atomic32_add( v, 1 ); } -static __inline__ void atomic32_dec ( atomic32_t *v ) +static __inline__ void atomic32_dec ( atomic32_t *const v ) { - atomic32_add( v, -1 ); + __atomic_fetch_sub(&((v)->counter), 1, __ATOMIC_SEQ_CST); } /* decrement by one and test result for 0 */ -static __inline__ int atomic32_dec_and_test ( atomic32_t *v ) +static __inline__ int atomic32_dec_and_test ( atomic32_t *const v ) { - return __sync_add_and_fetch( & v -> counter, -1 ) == 0; + return __atomic_sub_fetch(&((v)->counter), 1, __ATOMIC_SEQ_CST) == 0; } /* when atomic32_dec_and_test uses predecrement, you want postincrement to this function. so it isn't very useful */ -static __inline__ int atomic32_inc_and_test ( atomic32_t *v ) +static __inline__ int atomic32_inc_and_test ( atomic32_t *const v ) { - return __sync_add_and_fetch( & v -> counter, 1 ) == 0; + return atomic32_add_and_read(v, 1) == 0; } /* HERE's useful */ #define atomic32_test_and_inc( v ) \ ( atomic32_read_and_add ( v, 1 ) == 0 ) -static __inline__ int atomic32_test_and_set ( atomic32_t *v, int newval, int oldval ) +static __inline__ int atomic32_test_and_set ( atomic32_t *const v, int const newval, int const oldval ) { - return __sync_val_compare_and_swap( & v -> counter, oldval, newval ); //NB: newval/oldval switched around + int expected = oldval; + __atomic_compare_exchange_n(&((v)->counter), &expected, newval, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); + return expected; } /* conditional modifications */ diff --git a/interfaces/cc/clang/arm64/atomic64.h b/interfaces/cc/clang/atomic64.h similarity index 79% rename from interfaces/cc/clang/arm64/atomic64.h rename to interfaces/cc/clang/atomic64.h index 90d200d09..27980861e 100644 --- a/interfaces/cc/clang/arm64/atomic64.h +++ b/interfaces/cc/clang/atomic64.h @@ -39,71 +39,71 @@ extern "C" { typedef struct atomic64_t atomic64_t; struct atomic64_t { - volatile long int counter; + long volatile counter; }; /* int atomic64_read ( const atomic64_t *v ); */ #define atomic64_read( v ) \ - ( ( v ) -> counter ) + __atomic_load_n(&((v)->counter), __ATOMIC_SEQ_CST) /* void atomic64_set ( atomic64_t *v, long int i ); */ #define atomic64_set( v, i ) \ - ( ( void ) ( ( ( v ) -> counter ) = ( i ) ) ) + __atomic_store_n(&((v)->counter), i, __ATOMIC_SEQ_CST) /* add to v -> counter and return the prior value */ -static __inline__ long int atomic64_read_and_add ( atomic64_t *v, long int i ) -{ - return __sync_fetch_and_add( & v -> counter, i ); -} +#define atomic64_read_and_add( v, i ) \ + __atomic_fetch_add(&((v)->counter), i, __ATOMIC_SEQ_CST) /* if no read is needed, define the least expensive atomic add */ #define atomic64_add( v, i ) \ - atomic64_read_and_add ( v, i ) + ((void)atomic64_read_and_add(v, i)) /* add to v -> counter and return the result */ -static __inline__ long int atomic64_add_and_read ( atomic64_t *v, long int i ) +static __inline__ long atomic64_add_and_read ( atomic64_t *const v, long const i ) { - return __sync_add_and_fetch( & v -> counter, i ); + return __atomic_add_fetch(&((v)->counter), i, __ATOMIC_SEQ_CST); } /* just don't try to find out what the result was */ -static __inline__ void atomic64_inc ( atomic64_t *v ) +static __inline__ void atomic64_inc ( atomic64_t *const v ) { atomic64_add( v, 1 ); } -static __inline__ void atomic64_dec ( atomic64_t *v ) +static __inline__ void atomic64_dec ( atomic64_t *const v ) { - atomic64_add( v, -1 ); + __atomic_fetch_sub(&((v)->counter), 1, __ATOMIC_SEQ_CST); } /* decrement by one and test result for 0 */ -static __inline__ int atomic64_dec_and_test ( atomic64_t *v ) +static __inline__ int atomic64_dec_and_test ( atomic64_t *const v ) { - return __sync_add_and_fetch( & v -> counter, -1 ) == 0; + return __atomic_sub_fetch(&((v)->counter), 1, __ATOMIC_SEQ_CST) == 0; } /* when atomic64_dec_and_test uses predecrement, you want postincrement to this function. so it isn't very useful */ -static __inline__ int atomic64_inc_and_test ( atomic64_t *v ) +static __inline__ int atomic64_inc_and_test ( atomic64_t *const v ) { - return __sync_add_and_fetch( & v -> counter, 1 ) == 0; + return atomic64_add_and_read(v, 1) == 0; } /* HERE's useful */ #define atomic64_test_and_inc( v ) \ ( atomic64_read_and_add ( v, 1L ) == 0 ) -static __inline__ long int atomic64_test_and_set ( atomic64_t *v, long int newval, long int oldval ) +static __inline__ long int atomic64_test_and_set ( atomic64_t *const v, long int const newval, long int const oldval ) { - return __sync_val_compare_and_swap( & v -> counter, oldval, newval ); //NB: newval/oldval switched around + long expected = oldval; + __atomic_compare_exchange_n(&((v)->counter), &expected, newval, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); + return expected; } /* conditional modifications */ static __inline__ long int atomic64_read_and_add_lt ( atomic64_t *v, long int i, long int t ) { - int val, val_intern; + long val, val_intern; for ( val = atomic64_read ( v ); val < t; val = val_intern ) { val_intern = atomic64_test_and_set ( v, val + i, val ); @@ -119,7 +119,7 @@ long int atomic64_read_and_add_lt ( atomic64_t *v, long int i, long int t ) static __inline__ long int atomic64_read_and_add_le ( atomic64_t *v, long int i, long int t ) { - int val, val_intern; + long int val, val_intern; for ( val = atomic64_read ( v ); val <= t; val = val_intern ) { val_intern = atomic64_test_and_set ( v, val + i, val ); @@ -135,7 +135,7 @@ long int atomic64_read_and_add_le ( atomic64_t *v, long int i, long int t ) static __inline__ long int atomic64_read_and_add_eq ( atomic64_t *v, long int i, long int t ) { - int val, val_intern; + long int val, val_intern; for ( val = atomic64_read ( v ); val == t; val = val_intern ) { val_intern = atomic64_test_and_set ( v, val + i, val ); @@ -151,7 +151,7 @@ long int atomic64_read_and_add_eq ( atomic64_t *v, long int i, long int t ) static __inline__ long int atomic64_read_and_add_ne ( atomic64_t *v, long int i, long int t ) { - int val, val_intern; + long int val, val_intern; for ( val = atomic64_read ( v ); val != t; val = val_intern ) { val_intern = atomic64_test_and_set ( v, val + i, val ); @@ -167,7 +167,7 @@ long int atomic64_read_and_add_ne ( atomic64_t *v, long int i, long int t ) static __inline__ long int atomic64_read_and_add_ge ( atomic64_t *v, long int i, long int t ) { - int val, val_intern; + long int val, val_intern; for ( val = atomic64_read ( v ); val >= t; val = val_intern ) { val_intern = atomic64_test_and_set ( v, val + i, val ); @@ -183,7 +183,7 @@ long int atomic64_read_and_add_ge ( atomic64_t *v, long int i, long int t ) static __inline__ long int atomic64_read_and_add_gt ( atomic64_t *v, long int i, long int t ) { - int val, val_intern; + long int val, val_intern; for ( val = atomic64_read ( v ); val > t; val = val_intern ) { val_intern = atomic64_test_and_set ( v, val + i, val ); @@ -199,7 +199,7 @@ long int atomic64_read_and_add_gt ( atomic64_t *v, long int i, long int t ) static __inline__ long int atomic64_read_and_add_odd ( atomic64_t *v, long int i ) { - int val, val_intern; + long int val, val_intern; for ( val = atomic64_read ( v ); val & 1; val = val_intern ) { val_intern = atomic64_test_and_set ( v, val + i, val ); @@ -212,7 +212,7 @@ long int atomic64_read_and_add_odd ( atomic64_t *v, long int i ) static __inline__ long int atomic64_read_and_add_even ( atomic64_t *v, long int i ) { - int val, val_intern; + long int val, val_intern; for ( val = atomic64_read ( v ); ! ( val & 1 ); val = val_intern ) { val_intern = atomic64_test_and_set ( v, val + i, val ); diff --git a/interfaces/cc/clang/x86_64/atomic.h b/interfaces/cc/clang/x86_64/atomic.h deleted file mode 100644 index a76db5880..000000000 --- a/interfaces/cc/clang/x86_64/atomic.h +++ /dev/null @@ -1,188 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#ifndef _h_atomic_ -#define _h_atomic_ - -#ifndef _h_atomic32_ -#include "atomic32.h" -#endif - -#ifndef _h_atomic64_ -#include "atomic64.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#if DFLT_ATOMIC_BITS == 32 -#define ATOMIC_NAME( suffix ) \ - atomic32_ ## suffix -typedef int atomic_int; -#else -#define ATOMIC_NAME( suffix ) \ - atomic64_ ## suffix -typedef long int atomic_int; -#endif - -typedef struct ATOMIC_NAME ( t ) atomic_t; - -typedef struct atomic_ptr_t atomic_ptr_t; -struct atomic_ptr_t -{ - void * volatile ptr; -}; - -/* ( * v ) */ -#define atomic_read( v ) \ - ATOMIC_NAME ( read ) ( v ) - -/* ( * v ) = i */ -#define atomic_set( v, i ) \ - ATOMIC_NAME ( set ) ( v, i ) - -/* prior = ( * v ), ( * v ) += i, prior */ -#define atomic_read_and_add( v, i ) \ - ATOMIC_NAME ( read_and_add ) ( v, i ) - -/* ( * v ) += i */ -#define atomic_add( v, i ) \ - ATOMIC_NAME ( add ) ( v, i ) - -/* ( * v ) += i */ -#define atomic_add_and_read( v, i ) \ - ATOMIC_NAME ( add_and_read ) ( v, i ) - -/* ( void ) ++ ( * v ) */ -#define atomic_inc( v ) \ - ATOMIC_NAME ( inc ) ( v ) - -/* ( void ) -- ( * v ) */ -#define atomic_dec( v ) \ - ATOMIC_NAME ( dec ) ( v ) - -/* -- ( * v ) == 0 */ -#define atomic_dec_and_test( v ) \ - ATOMIC_NAME ( dec_and_test ) ( v ) - -/* ++ ( * v ) == 0 - when atomic_dec_and_test uses predecrement, you want - postincrement to this function. so it isn't very useful */ -#define atomic_inc_and_test( v ) \ - ATOMIC_NAME ( inc_and_test ) ( v ) - -/* ( * v ) -- == 0 - HERE's useful */ -#define atomic_test_and_inc( v ) \ - ATOMIC_NAME ( test_and_inc ) ( v ) - -/* prior = ( * v ), ( * v ) = ( prior == t ? s : prior ), prior */ -#define atomic_test_and_set( v, s, t ) \ - ATOMIC_NAME ( test_and_set ) ( v, s, t ) - -/* N.B. - THESE FUNCTIONS ARE FOR 64 BIT PTRS ONLY */ - -/* int atomic_read_ptr ( const atomic_ptr_t *v ); */ -#define atomic_read_ptr( v ) \ - ( ( v ) -> ptr ) - -static __inline__ -void *atomic_test_and_set_ptr ( atomic_ptr_t *v, void *s, void *t ) -{ - void *rtn; - __asm__ __volatile__ - ( - "lock;" - "cmpxchg %%rsi,(%%rdi)" - : "=a" ( rtn ) - : "D" ( v ), "S" ( s ), "a" ( t ) - ); - return rtn; -} - -/* val = ( * v ), ( ( * v ) = ( val < t ) ? val + i : val ), val */ -#define atomic_read_and_add_lt( v, i, t ) \ - ATOMIC_NAME ( read_and_add_lt ) ( v, i, t ) - -/* val = ( * v ), ( ( * v ) = ( val <= t ) ? val + i : val ), val */ -#define atomic_read_and_add_le( v, i, t ) \ - ATOMIC_NAME ( read_and_add_le ) ( v, i, t ) - -/* val = ( * v ), ( ( * v ) = ( val == t ) ? val + i : val ), val */ -#define atomic_read_and_add_eq( v, i, t ) \ - ATOMIC_NAME ( read_and_add_eq ) ( v, i, t ) - -/* val = ( * v ), ( ( * v ) = ( val != t ) ? val + i : val ), val */ -#define atomic_read_and_add_ne( v, i, t ) \ - ATOMIC_NAME ( read_and_add_ne ) ( v, i, t ) - -/* val = ( * v ), ( ( * v ) = ( val >= t ) ? val + i : val ), val */ -#define atomic_read_and_add_ge( v, i, t ) \ - ATOMIC_NAME ( read_and_add_ge ) ( v, i, t ) - -/* val = ( * v ), ( ( * v ) = ( val > t ) ? val + i : val ), val */ -#define atomic_read_and_add_gt( v, i, t ) \ - ATOMIC_NAME ( read_and_add_gt ) ( v, i, t ) - -/* val = ( * v ), ( ( * v ) = ( ( val & 1 ) == 1 ) ? val + i : val ), val */ -#define atomic_read_and_add_odd( v, i ) \ - ATOMIC_NAME ( read_and_add_odd ) ( v, i ) - -/* val = ( * v ), ( ( * v ) = ( ( val & 1 ) == 0 ) ? val + i : val ), val */ -#define atomic_read_and_add_even( v, i ) \ - ATOMIC_NAME ( read_and_add_even ) ( v, i ) - -/* DEPRECATED */ - -/* val = ( * v ), ( * v ) = ( val < t ? val + i : val ), ( val < t ? 1 : 0 ) */ -#define atomic_add_if_lt( v, i, t ) \ - ATOMIC_NAME ( add_if_lt ) ( v, i, t ) - -/* val = ( * v ), ( * v ) = ( val <= t ? val + i : val ), ( val <= t ? 1 : 0 ) */ -#define atomic_add_if_le( v, i, t ) \ - ATOMIC_NAME ( add_if_le ) ( v, i, t ) - -/* val = ( * v ), ( * v ) = ( val == t ? val + i : val ), ( val == t ? 1 : 0 ) */ -#define atomic_add_if_eq( v, i, t ) \ - ATOMIC_NAME ( add_if_eq ) ( v, i, t ) - -/* val = ( * v ), ( * v ) = ( val >= t ? val + i : val ), ( val >= t ? 1 : 0 ) */ -#define atomic_add_if_ge( v, i, t ) \ - ATOMIC_NAME ( add_if_ge ) ( v, i, t ) - -/* val = ( * v ), ( * v ) = ( val > t ? val + i : val ), ( val > t ? 1 : 0 ) */ -#define atomic_add_if_gt( v, i, t ) \ - ATOMIC_NAME ( add_if_gt ) ( v, i, t ) - -#undef LOCK - - -#ifdef __cplusplus -} -#endif - -#endif /* _h_atomic_ */ diff --git a/interfaces/cc/clang/x86_64/atomic32.h b/interfaces/cc/clang/x86_64/atomic32.h deleted file mode 100644 index 7584643fc..000000000 --- a/interfaces/cc/clang/x86_64/atomic32.h +++ /dev/null @@ -1,365 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#ifndef _h_atomic32_ -#define _h_atomic32_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Make sure gcc doesn't try to be clever and move things around - * on us. We need to use _exactly_ the address the user gave us, - * not some alias that contains the same information. - */ -typedef struct atomic32_t atomic32_t; -struct atomic32_t -{ - volatile int counter; -}; - -/* int atomic32_read ( const atomic32_t *v ); */ -#define atomic32_read( v ) \ - ( ( v ) -> counter ) - -/* void atomic32_set ( atomic32_t *v, int i ); */ -#define atomic32_set( v, i ) \ - ( ( void ) ( ( ( v ) -> counter ) = ( i ) ) ) - -/* add to v -> counter and return the prior value */ -static __inline__ int atomic32_read_and_add ( atomic32_t *v, int i ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "mov %3, %1;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ) - ); - return rtn; -} - -/* if no read is needed, define the least expensive atomic add */ -#define atomic32_add( v, i ) \ - atomic32_read_and_add ( v, i ) - -/* add to v -> counter and return the result */ -static __inline__ int atomic32_add_and_read ( atomic32_t *v, int i ) -{ - int rtn, cmp; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "mov %3, %1;" - "add %0, %1;" - "lock;" - "cmpxchg %1,(%2);" - "jne 1b;" - : "=&a" ( cmp ), "=&r" ( rtn ) - : "r" ( & v -> counter ), "r" ( i ) - ); - return rtn; -} - -/* just don't try to find out what the result was */ -static __inline__ void atomic32_inc ( atomic32_t *v ) -{ - __asm__ __volatile__ - ( - "lock;" - "incl %0" - : "=m" ( v -> counter ) - : "m" ( v -> counter ) - ); -} - -static __inline__ void atomic32_dec ( atomic32_t *v ) -{ - __asm__ __volatile__ - ( - "lock;" - "decl %0" - : "=m" ( v -> counter ) - : "m" ( v -> counter ) - ); -} - -/* decrement by one and test result for 0 */ -static __inline__ int atomic32_dec_and_test ( atomic32_t *v ) -{ - unsigned char c; - __asm__ __volatile__ - ( - "lock;" - "decl %1;" - "sete %0" - : "=r" ( c ), "=m" ( v -> counter ) - : "m" ( v -> counter ) - ); - return c; -} - -/* when atomic32_dec_and_test uses predecrement, you want - postincrement to this function. so it isn't very useful */ -static __inline__ int atomic32_inc_and_test ( atomic32_t *v ) -{ - unsigned char c; - __asm__ __volatile__ - ( - "lock;" - "incl %1;" - "sete %0" - : "=r" ( c ), "=m" ( v -> counter ) - : "m" ( v -> counter ) - ); - return c; -} - -/* HERE's useful */ -#define atomic32_test_and_inc( v ) \ - ( atomic32_read_and_add ( v, 1 ) == 0 ) - -static __inline__ int atomic32_test_and_set ( atomic32_t *v, int s, int t ) -{ - int rtn; - __asm__ __volatile__ - ( - "lock;" - "cmpxchg %2, (%1)" - : "=a" ( rtn ) - : "r" ( & v -> counter ), "r" ( s ), "a" ( t ) - ); - return rtn; -} - -/* conditional modifications */ -static __inline__ -int atomic32_read_and_add_lt ( atomic32_t *v, int i, int t ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jge 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic32_add_if_lt( v, i, t ) \ - ( atomic32_read_and_add_lt ( v, i, t ) < ( t ) ) - -static __inline__ -int atomic32_read_and_add_le ( atomic32_t *v, int i, int t ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jg 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic32_add_if_le( v, i, t ) \ - ( atomic32_read_and_add_le ( v, i, t ) <= ( t ) ) - -static __inline__ -int atomic32_read_and_add_eq ( atomic32_t *v, int i, int t ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jne 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic32_add_if_eq( v, i, t ) \ - ( atomic32_read_and_add_eq ( v, i, t ) == ( t ) ) - -static __inline__ -int atomic32_read_and_add_ne ( atomic32_t *v, int i, int t ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "je 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic32_add_if_ne( v, i, t ) \ - ( atomic32_read_and_add_ne ( v, i, t ) != ( t ) ) - -static __inline__ -int atomic32_read_and_add_ge ( atomic32_t *v, int i, int t ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jl 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic32_add_if_ge( v, i, t ) \ - ( atomic32_read_and_add_ge ( v, i, t ) >= ( t ) ) - -static __inline__ -int atomic32_read_and_add_gt ( atomic32_t *v, int i, int t ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jle 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic32_add_if_gt( v, i, t ) \ - ( atomic32_read_and_add_gt ( v, i, t ) > ( t ) ) - -static __inline__ -int atomic32_read_and_add_odd ( atomic32_t *v, int i ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "bt $0, %0;" - "mov %3, %1;" - "jnc 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ) - ); - return rtn; -} - -static __inline__ -int atomic32_read_and_add_even ( atomic32_t *v, int i ) -{ - int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "bt $0, %0;" - "mov %3, %1;" - "jc 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ) - ); - return rtn; -} - -#ifdef __cplusplus -} -#endif - -#endif /* _h_atomic32_ */ diff --git a/interfaces/cc/clang/x86_64/atomic64.h b/interfaces/cc/clang/x86_64/atomic64.h deleted file mode 100644 index 4a1ce7e2d..000000000 --- a/interfaces/cc/clang/x86_64/atomic64.h +++ /dev/null @@ -1,365 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#ifndef _h_atomic64_ -#define _h_atomic64_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Make sure gcc doesn't try to be clever and move things around - * on us. We need to use _exactly_ the address the user gave us, - * not some alias that contains the same information. - */ -typedef struct atomic64_t atomic64_t; -struct atomic64_t -{ - volatile long int counter; -}; - -/* int atomic64_read ( const atomic64_t *v ); */ -#define atomic64_read( v ) \ - ( ( v ) -> counter ) - -/* void atomic64_set ( atomic64_t *v, long int i ); */ -#define atomic64_set( v, i ) \ - ( ( void ) ( ( ( v ) -> counter ) = ( i ) ) ) - -/* add to v -> counter and return the prior value */ -static __inline__ long int atomic64_read_and_add ( atomic64_t *v, long int i ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "mov %3, %1;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ) - ); - return rtn; -} - -/* if no read is needed, define the least expensive atomic add */ -#define atomic64_add( v, i ) \ - atomic64_read_and_add ( v, i ) - -/* add to v -> counter and return the result */ -static __inline__ long int atomic64_add_and_read ( atomic64_t *v, long int i ) -{ - long int rtn, cmp; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "mov %3, %1;" - "add %0, %1;" - "lock;" - "cmpxchg %1,(%2);" - "jne 1b;" - : "=&a" ( cmp ), "=&r" ( rtn ) - : "r" ( & v -> counter ), "r" ( i ) - ); - return rtn; -} - -/* just don't try to find out what the result was */ -static __inline__ void atomic64_inc ( atomic64_t *v ) -{ - __asm__ __volatile__ - ( - "lock;" - "incq %0" - : "=m" ( v -> counter ) - : "m" ( v -> counter ) - ); -} - -static __inline__ void atomic64_dec ( atomic64_t *v ) -{ - __asm__ __volatile__ - ( - "lock;" - "decq %0" - : "=m" ( v -> counter ) - : "m" ( v -> counter ) - ); -} - -/* decrement by one and test result for 0 */ -static __inline__ int atomic64_dec_and_test ( atomic64_t *v ) -{ - unsigned char c; - __asm__ __volatile__ - ( - "lock;" - "decq %1;" - "sete %0" - : "=r" ( c ), "=m" ( v -> counter ) - : "m" ( v -> counter ) - ); - return c; -} - -/* when atomic64_dec_and_test uses predecrement, you want - postincrement to this function. so it isn't very useful */ -static __inline__ int atomic64_inc_and_test ( atomic64_t *v ) -{ - unsigned char c; - __asm__ __volatile__ - ( - "lock;" - "incq %1;" - "sete %0" - : "=r" ( c ), "=m" ( v -> counter ) - : "m" ( v -> counter ) - ); - return c; -} - -/* HERE's useful */ -#define atomic64_test_and_inc( v ) \ - ( atomic64_read_and_add ( v, 1L ) == 0 ) - -static __inline__ long int atomic64_test_and_set ( atomic64_t *v, long int s, long int t ) -{ - long int rtn; - __asm__ __volatile__ - ( - "lock;" - "cmpxchg %2, (%1)" - : "=a" ( rtn ) - : "r" ( & v -> counter ), "r" ( s ), "a" ( t ) - ); - return rtn; -} - -/* conditional modifications */ -static __inline__ -long int atomic64_read_and_add_lt ( atomic64_t *v, long int i, long int t ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jge 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic64_add_if_lt( v, i, t ) \ - ( atomic64_read_and_add_lt ( v, i, t ) < ( t ) ) - -static __inline__ -long int atomic64_read_and_add_le ( atomic64_t *v, long int i, long int t ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jg 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic64_add_if_le( v, i, t ) \ - ( atomic64_read_and_add_le ( v, i, t ) <= ( t ) ) - -static __inline__ -long int atomic64_read_and_add_eq ( atomic64_t *v, long int i, long int t ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jne 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic64_add_if_eq( v, i, t ) \ - ( atomic64_read_and_add_eq ( v, i, t ) == ( t ) ) - -static __inline__ -long int atomic64_read_and_add_ne ( atomic64_t *v, long int i, long int t ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "je 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic64_add_if_ne( v, i, t ) \ - ( atomic64_read_and_add_ne ( v, i, t ) != ( t ) ) - -static __inline__ -long int atomic64_read_and_add_ge ( atomic64_t *v, long int i, long int t ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jl 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic64_add_if_ge( v, i, t ) \ - ( atomic64_read_and_add_ge ( v, i, t ) >= ( t ) ) - -static __inline__ -long int atomic64_read_and_add_gt ( atomic64_t *v, long int i, long int t ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "cmp %4, %0;" - "mov %3, %1;" - "jle 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ), "r" ( t ) - ); - return rtn; -} - -#define atomic64_add_if_gt( v, i, t ) \ - ( atomic64_read_and_add_gt ( v, i, t ) > ( t ) ) - -static __inline__ -long int atomic64_read_and_add_odd ( atomic64_t *v, long int i ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "bt $0, %0;" - "mov %3, %1;" - "jnc 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ) - ); - return rtn; -} - -static __inline__ -long int atomic64_read_and_add_even ( atomic64_t *v, long int i ) -{ - long int rtn, sum; - __asm__ __volatile__ - ( - "mov (%2), %0;" - "1:" - "bt $0, %0;" - "mov %3, %1;" - "jc 2f;" - "add %0, %1;" - "lock;" - "cmpxchg %1, (%2);" - "jne 1b;" - "2:" - : "=&a" ( rtn ), "=&r" ( sum ) - : "r" ( & v -> counter ), "r" ( i ) - ); - return rtn; -} - -#ifdef __cplusplus -} -#endif - -#endif /* _h_atomic64_ */ diff --git a/interfaces/cc/gcc/x86_64/arch-impl.h b/interfaces/cc/gcc/x86_64/arch-impl.h index ba0412e4f..4aea00c20 100644 --- a/interfaces/cc/gcc/x86_64/arch-impl.h +++ b/interfaces/cc/gcc/x86_64/arch-impl.h @@ -282,6 +282,10 @@ void uint128_bswap_copy ( uint128_t *to, const uint128_t *from ) static __inline__ uint32_t uint32_rol ( uint32_t val, uint8_t bits ) { + if ( bits == 0 ) + { + return val; + } uint32_t rtn; rtn = ( val << bits ) | ( val >> ( 32 - bits ) ); return rtn; @@ -290,6 +294,10 @@ uint32_t uint32_rol ( uint32_t val, uint8_t bits ) static __inline__ uint32_t uint32_ror ( uint32_t val, uint8_t bits ) { + if ( bits == 0 ) + { + return val; + } uint32_t rtn; rtn = ( val >> bits ) | ( val << ( 32 - bits ) ); return rtn; @@ -298,6 +306,10 @@ uint32_t uint32_ror ( uint32_t val, uint8_t bits ) static __inline__ uint64_t uint64_rol ( uint64_t val, uint8_t bits ) { + if ( bits == 0 ) + { + return val; + } uint64_t rtn; rtn = ( val << bits ) | ( val >> ( 64 - bits ) ); return rtn; @@ -306,6 +318,10 @@ uint64_t uint64_rol ( uint64_t val, uint8_t bits ) static __inline__ uint64_t uint64_ror ( uint64_t val, uint8_t bits ) { + if ( bits == 0 ) + { + return val; + } uint64_t rtn; rtn = ( val >> bits ) | ( val << ( 64 - bits ) ); return rtn; diff --git a/interfaces/ext/zlib.h b/interfaces/ext/zlib.h index 953cb5012..8d4b932ea 100644 --- a/interfaces/ext/zlib.h +++ b/interfaces/ext/zlib.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.13, October 13th, 2022 + version 1.3.1, January 22nd, 2024 - Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.13" -#define ZLIB_VERNUM 0x12d0 +#define ZLIB_VERSION "1.3.1" +#define ZLIB_VERNUM 0x1310 #define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 13 +#define ZLIB_VER_MINOR 3 +#define ZLIB_VER_REVISION 1 #define ZLIB_VER_SUBREVISION 0 /* @@ -78,8 +78,8 @@ extern "C" { even in the case of corrupted input. */ -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); +typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size); +typedef void (*free_func)(voidpf opaque, voidpf address); struct internal_state; @@ -217,7 +217,7 @@ typedef gz_header FAR *gz_headerp; /* basic functions */ -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +ZEXTERN const char * ZEXPORT zlibVersion(void); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check @@ -225,12 +225,12 @@ ZEXTERN const char * ZEXPORT zlibVersion OF((void)); */ /* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); +ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. + allocation functions. total_in, total_out, adler, and msg are initialized. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all @@ -247,7 +247,7 @@ ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); */ -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); /* deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -320,8 +320,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. + avail_out is greater than six when the flush marker begins, in order to avoid + repeated flush markers upon calling deflate() again when avail_out == 0. If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was @@ -360,7 +360,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); */ -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -375,7 +375,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); /* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateInit(z_streamp strm); Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by @@ -383,7 +383,8 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); read or consumed. The allocation of a sliding window will be deferred to the first call of inflate (if the decompression does not complete on the first call). If zalloc and zfree are set to Z_NULL, inflateInit updates - them to use default allocation functions. + them to use default allocation functions. total_in, total_out, adler, and + msg are initialized. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the @@ -397,7 +398,7 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); */ -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); /* inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -517,7 +518,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); */ -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -535,12 +536,12 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); */ /* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); +ZEXTERN int ZEXPORT deflateInit2(z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy); This is another version of deflateInit with more compression options. The fields zalloc, zfree and opaque must be initialized before by the caller. @@ -607,9 +608,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); +ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, + const Bytef *dictionary, + uInt dictLength); /* Initializes the compression dictionary from the given byte sequence without producing any compressed output. When using the zlib format, this @@ -651,9 +652,9 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, not perform any compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); +ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, + Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by deflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -673,8 +674,8 @@ ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT deflateCopy(z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -691,20 +692,20 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, destination. */ -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateReset(z_streamp strm); /* This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream will leave the compression level and any other attributes that may have been - set unchanged. + set unchanged. total_in, total_out, adler, and msg are initialized. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); +ZEXTERN int ZEXPORT deflateParams(z_streamp strm, + int level, + int strategy); /* Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2(). This can be @@ -729,7 +730,7 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, Then no more input data should be provided before the deflateParams() call. If this is done, the old level and strategy will be applied to the data compressed before deflateParams(), and the new level and strategy will be - applied to the the data compressed after deflateParams(). + applied to the data compressed after deflateParams(). deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if @@ -740,11 +741,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, retried with more output space. */ -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain)); +ZEXTERN int ZEXPORT deflateTune(z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain); /* Fine tune deflate's internal compression parameters. This should only be used by someone who understands the algorithm used by zlib's deflate for @@ -757,8 +758,8 @@ ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. */ -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); +ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, + uLong sourceLen); /* deflateBound() returns an upper bound on the compressed size after deflation of sourceLen bytes. It must be called after deflateInit() or @@ -772,9 +773,9 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, than Z_FINISH or Z_NO_FLUSH are used. */ -ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, - unsigned *pending, - int *bits)); +ZEXTERN int ZEXPORT deflatePending(z_streamp strm, + unsigned *pending, + int *bits); /* deflatePending() returns the number of bytes and bits of output that have been generated, but not yet provided in the available output. The bytes not @@ -787,9 +788,9 @@ ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); +ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, + int bits, + int value); /* deflatePrime() inserts bits in the deflate output stream. The intent is that this function is used to start off the deflate output with the bits @@ -804,8 +805,8 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, source stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, + gz_headerp head); /* deflateSetHeader() provides gzip header information for when a gzip stream is requested by deflateInit2(). deflateSetHeader() may be called @@ -821,16 +822,17 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, gzip file" and give up. If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). + the time set to zero, and os set to the current operating system, with no + extra, name, or comment fields. The gzip header is returned to the default + state by deflateReset(). deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. */ /* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateInit2(z_streamp strm, + int windowBits); This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized @@ -883,9 +885,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, deferred until inflate() is called. */ -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); +ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, + const Bytef *dictionary, + uInt dictLength); /* Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate, @@ -906,9 +908,9 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, inflate(). */ -ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); +ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, + Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by inflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -921,7 +923,7 @@ ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateSync(z_streamp strm); /* Skips invalid compressed data until a possible full flush point (see above for the description of deflate with Z_FULL_FLUSH) can be found, or until all @@ -934,14 +936,14 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); inflateSync returns Z_OK if a possible full flush point has been found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current current value of - total_in which indicates where valid compressed data was found. In the - error case, the application may repeatedly call inflateSync, providing more - input each time, until success or end of the input data. + In the success case, the application may save the current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. */ -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -956,18 +958,19 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, destination. */ -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateReset(z_streamp strm); /* This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The stream will keep attributes that may have been set by inflateInit2. + total_in, total_out, adler, and msg are initialized. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, + int windowBits); /* This function is the same as inflateReset, but it also permits changing the wrap and window size requests. The windowBits parameter is interpreted @@ -980,9 +983,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, the windowBits parameter is invalid. */ -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, - int bits, - int value)); +ZEXTERN int ZEXPORT inflatePrime(z_streamp strm, + int bits, + int value); /* This function inserts bits in the inflate input stream. The intent is that this function is used to start inflating at a bit position in the @@ -1001,7 +1004,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, stream state was inconsistent. */ -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +ZEXTERN long ZEXPORT inflateMark(z_streamp strm); /* This function returns two values, one in the lower 16 bits of the return value, and the other in the remaining upper bits, obtained by shifting the @@ -1029,8 +1032,8 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); source stream state was inconsistent. */ -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, + gz_headerp head); /* inflateGetHeader() requests that gzip header information be stored in the provided gz_header structure. inflateGetHeader() may be called after @@ -1070,8 +1073,8 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, */ /* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); +ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits, + unsigned char FAR *window); Initialize the internal stream state for decompression using inflateBack() calls. The fields zalloc, zfree and opaque in strm must be initialized @@ -1091,13 +1094,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, the version of the header file. */ -typedef unsigned (*in_func) OF((void FAR *, - z_const unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); +typedef unsigned (*in_func)(void FAR *, + z_const unsigned char FAR * FAR *); +typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned); -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); +ZEXTERN int ZEXPORT inflateBack(z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc); /* inflateBack() does a raw inflate with a single call using a call-back interface for input and output. This is potentially more efficient than @@ -1165,7 +1168,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, cannot return Z_OK. */ -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm); /* All memory allocated by inflateBackInit() is freed. @@ -1173,7 +1176,7 @@ ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); state was inconsistent. */ -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +ZEXTERN uLong ZEXPORT zlibCompileFlags(void); /* Return flags indicating compile-time options. Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: @@ -1226,8 +1229,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); you need special options. */ -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1241,9 +1244,9 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, buffer. */ -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); +ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level); /* Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte @@ -1257,15 +1260,15 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, Z_STREAM_ERROR if the level parameter is invalid. */ -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); /* compressBound() returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() call to allocate the destination buffer. */ -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1282,8 +1285,8 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, buffer with the uncompressed data up to that point. */ -ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong *sourceLen)); +ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen); /* Same as uncompress, except that sourceLen is a pointer, where the length of the source is *sourceLen. On return, *sourceLen is the number of @@ -1302,7 +1305,7 @@ ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ /* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode); Open the gzip (.gz) file at path for reading and decompressing, or compressing and writing. The mode parameter is as in fopen ("rb" or "wb") @@ -1339,7 +1342,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); file could not be opened. */ -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode); /* Associate a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (if the file has @@ -1362,7 +1365,7 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); will not detect if fd is invalid (unless fd is -1). */ -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size); /* Set the internal buffer size used by this library's functions for file to size. The default buffer size is 8192 bytes. This function must be called @@ -1378,7 +1381,7 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); too late. */ -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy); /* Dynamically update the compression level and strategy for file. See the description of deflateInit2 for the meaning of these parameters. Previously @@ -1389,7 +1392,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); or Z_MEM_ERROR if there is a memory allocation error. */ -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len); /* Read and decompress up to len uncompressed bytes from file into buf. If the input file is not in gzip format, gzread copies the given number of @@ -1419,8 +1422,8 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); Z_STREAM_ERROR. */ -ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, - gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, + gzFile file); /* Read and decompress up to nitems items of size size from file into buf, otherwise operating as gzread() does. This duplicates the interface of @@ -1445,14 +1448,14 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, file, resetting and retrying on end-of-file, when size is not 1. */ -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); +ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); /* Compress and write the len uncompressed bytes at buf to file. gzwrite returns the number of uncompressed bytes written or 0 in case of error. */ -ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, - z_size_t nitems, gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, + z_size_t nitems, gzFile file); /* Compress and write nitems items of size size from buf to file, duplicating the interface of stdio's fwrite(), with size_t request and return types. If @@ -1465,7 +1468,7 @@ ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, is returned, and the error state is set to Z_STREAM_ERROR. */ -ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...); /* Convert, format, compress, and write the arguments (...) to file under control of the string format, as in fprintf. gzprintf returns the number of @@ -1480,7 +1483,7 @@ ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); This can be determined using zlibCompileFlags(). */ -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); /* Compress and write the given null-terminated string s to file, excluding the terminating null character. @@ -1488,7 +1491,7 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); gzputs returns the number of characters written, or -1 in case of error. */ -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); /* Read and decompress bytes from file into buf, until len-1 characters are read, or until a newline character is read and transferred to buf, or an @@ -1502,13 +1505,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); buf are indeterminate. */ -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +ZEXTERN int ZEXPORT gzputc(gzFile file, int c); /* Compress and write c, converted to an unsigned char, into file. gzputc returns the value that was written, or -1 in case of error. */ -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +ZEXTERN int ZEXPORT gzgetc(gzFile file); /* Read and decompress one byte from file. gzgetc returns this byte or -1 in case of end of file or error. This is implemented as a macro for speed. @@ -1517,7 +1520,7 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); points to has been clobbered or not. */ -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +ZEXTERN int ZEXPORT gzungetc(int c, gzFile file); /* Push c back onto the stream for file to be read as the first character on the next read. At least one character of push-back is always allowed. @@ -1529,7 +1532,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); gzseek() or gzrewind(). */ -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +ZEXTERN int ZEXPORT gzflush(gzFile file, int flush); /* Flush all pending output to file. The parameter flush is as in the deflate() function. The return value is the zlib error number (see function @@ -1545,8 +1548,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); */ /* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); +ZEXTERN z_off_t ZEXPORT gzseek(gzFile file, + z_off_t offset, int whence); Set the starting position to offset relative to whence for the next gzread or gzwrite on file. The offset represents a number of bytes in the @@ -1564,7 +1567,7 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, would be before the current position. */ -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +ZEXTERN int ZEXPORT gzrewind(gzFile file); /* Rewind file. This function is supported only for reading. @@ -1572,7 +1575,7 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); */ /* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gztell(gzFile file); Return the starting position for the next gzread or gzwrite on file. This position represents a number of bytes in the uncompressed data stream, @@ -1583,7 +1586,7 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); */ /* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file); Return the current compressed (actual) read or write offset of file. This offset includes the count of bytes that precede the gzip stream, for example @@ -1592,7 +1595,7 @@ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); be used for a progress indicator. On error, gzoffset() returns -1. */ -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +ZEXTERN int ZEXPORT gzeof(gzFile file); /* Return true (1) if the end-of-file indicator for file has been set while reading, false (0) otherwise. Note that the end-of-file indicator is set @@ -1607,7 +1610,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file)); has grown since the previous end of file was detected. */ -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +ZEXTERN int ZEXPORT gzdirect(gzFile file); /* Return true (1) if file is being copied directly while reading, or false (0) if file is a gzip stream being decompressed. @@ -1628,7 +1631,7 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); gzip file reading and decompression, which may not be desired.) */ -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose(gzFile file); /* Flush all pending output for file, if necessary, close file and deallocate the (de)compression state. Note that once file is closed, you @@ -1641,8 +1644,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); last read ended in the middle of a gzip stream, or Z_OK on success. */ -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_r(gzFile file); +ZEXTERN int ZEXPORT gzclose_w(gzFile file); /* Same as gzclose(), but gzclose_r() is only for use when reading, and gzclose_w() is only for use when writing or appending. The advantage to @@ -1653,7 +1656,7 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); zlib library. */ -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); /* Return the error message for the last error which occurred on file. errnum is set to zlib error number. If an error occurred in the file system @@ -1669,7 +1672,7 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); functions above that do not distinguish those cases in their return values. */ -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +ZEXTERN void ZEXPORT gzclearerr(gzFile file); /* Clear the error and end-of-file flags for file. This is analogous to the clearerr() function in stdio. This is useful for continuing to read a gzip @@ -1686,7 +1689,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); library. */ -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len); /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. An Adler-32 value is in the range of a 32-bit @@ -1706,15 +1709,15 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); if (adler != original_adler) error(); */ -ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, + z_size_t len); /* Same as adler32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); +ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, + z_off_t len2); Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for @@ -1724,7 +1727,7 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, negative, the result has no meaning or utility. */ -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len); /* Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. @@ -1742,30 +1745,30 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); if (crc != original_crc) error(); */ -ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, + z_size_t len); /* Same as crc32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); Combine two CRC-32 check values into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. + len2. len2 must be non-negative. */ /* -ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); Return the operator corresponding to length len2, to be used with - crc32_combine_op(). + crc32_combine_op(). len2 must be non-negative. */ -ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); +ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); /* Give the same result as crc32_combine(), using op in place of len2. op is is generated from len2 by crc32_combine_gen(). This will be faster than @@ -1778,20 +1781,20 @@ ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); +ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, + const char *version, int stream_size); +ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size); +ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size); #ifdef Z_PREFIX_SET # define z_deflateInit(strm, level) \ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) @@ -1836,7 +1839,7 @@ struct gzFile_s { unsigned char *next; z_off64_t pos; }; -ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ #ifdef Z_PREFIX_SET # undef z_gzgetc # define z_gzgetc(g) \ @@ -1853,13 +1856,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ * without large file support, _LFS64_LARGEFILE must also be true */ #ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); #endif #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) @@ -1881,50 +1884,50 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ # define crc32_combine_gen crc32_combine_gen64 # endif # ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); # endif #else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell(gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif #else /* Z_SOLO */ - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif /* !Z_SOLO */ /* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); -ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); -ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF((z_streamp)); -ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); -ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +ZEXTERN const char * ZEXPORT zError(int); +ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void); +ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); +ZEXTERN int ZEXPORT inflateValidate(z_streamp, int); +ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); +ZEXTERN int ZEXPORT inflateResetKeep(z_streamp); +ZEXTERN int ZEXPORT deflateResetKeep(z_streamp); #if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, - const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, + const char *mode); #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) # ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, - const char *format, - va_list va)); +ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, + const char *format, + va_list va); # endif #endif diff --git a/interfaces/kapp/args.h b/interfaces/kapp/args.h index d3ed19c46..4f36e4c74 100644 --- a/interfaces/kapp/args.h +++ b/interfaces/kapp/args.h @@ -65,12 +65,12 @@ typedef struct Args Args; * Structure to define a command line option * * these are fed in one by one or through arrays to build up the - * tables used to parse the caommand line argc/argv + * tables used to parse the command line argc/argv */ typedef void (CC * WhackParamFnP) (void * object); typedef rc_t (CC * ConvertParamFnP) (const Args * self, uint32_t arg_index, const char * arg, size_t arg_len, void ** result, WhackParamFnP * whack); - + typedef struct OptDef { const char * name; /* UTF8/ASCII NUL terminated long name */ @@ -83,7 +83,7 @@ typedef struct OptDef bool required; /* is this a required parameter? Not supported yet. */ ConvertParamFnP convert_fn; /* function to convert option. can perform binary conversions. may be NULL */ } OptDef; - + typedef struct ParamDef ParamDef; struct ParamDef { @@ -197,9 +197,9 @@ rc_t CC ArgsAddStandardOptions ( Args * self ); /* Parse - * parse the argc/argv as presented to KMain using the Args structure as built up + * parse the argc/argv as presented to main() using the Args structure as built up */ -rc_t CC ArgsParse ( Args * self, int argc, char *argv[] ); +rc_t CC ArgsParse ( Args * self, int argc, const char *argv[] ); /* tokenizes a file into an user supplied argv array ( not the one from main() ! ) @@ -293,7 +293,7 @@ rc_t CC ArgsArgvValue (const Args * self, uint32_t iteration, const char ** valu * MakeStandardOptions * Calls both Make() and AddStandardOptions() * - * This is probably the first thing to do in KMain(), then add other Options + * This is probably the first thing to do in main(), then add other Options * via OptDef arracys and structures. Then call parse. */ rc_t CC ArgsMakeStandardOptions (Args** pself); @@ -358,14 +358,15 @@ rc_t CC ArgsCheckRequired (Args * args); * * More than one example line can be present if desired. */ -rc_t CC UsageSummary (const char * prog_name); +typedef rc_t (CC *UsageSummary_t) (const char * prog_name); +UsageSummary_t SetUsageSummary ( UsageSummary_t func ); /* * A program should define this which will be used only of the actual * program name as called is somehow irretrievable */ -extern const char UsageDefaultName[]; - +//extern const char UsageDefaultName[]; +void SetUsageDefaultName( const char* ); /* * Version @@ -387,17 +388,13 @@ void CC HelpOptionsStandard (void); /* - * This Macro creates a default short form usage output typically + * Default short form usage output typically * used when no options/parameters are given for a program * - * It requires 'void summary (const char * program_name)' that is also - * used in 'rc_t Usage (const Args* args)' that is the usage function - * called when -? -h or --help is given as an option on the command line + * It calls 'void UsageSummary (const char * program_name)' if it was set with SetUsageSummary() */ rc_t CC MiniUsage ( const Args * args ); -rc_t CC Usage ( const Args * args ); - uint32_t CC ArgsGetGlobalTries(bool *isSet); diff --git a/interfaces/kapp/main.h b/interfaces/kapp/vdbapp.h similarity index 71% rename from interfaces/kapp/main.h rename to interfaces/kapp/vdbapp.h index 313983446..01e051e0a 100644 --- a/interfaces/kapp/main.h +++ b/interfaces/kapp/vdbapp.h @@ -24,26 +24,37 @@ * */ -#ifndef _h_kapp_main_ -#define _h_kapp_main_ +#pragma once -#ifndef _h_klib_defs_ -#include -#endif +#include -#ifndef _h_kapp_args_ +#include #include -#endif + +/*-------------------------------------------------------------------------- + * Vdb initialization/termination API + */ #ifdef __cplusplus extern "C" { #endif +/* Initialize the VDB environment +*/ +KAPP_EXTERN rc_t VdbInitialize( int argc, char *argv [], ver_t vers ); -/*-------------------------------------------------------------------------- - * KMain - * invoked by platform specific "main" entrypoint - */ +#if WINDOWS + KAPP_EXTERN rc_t wVdbInitialize(int argc, wchar_t* wargv[], char*** argv); +#endif + +/* Recommended exit code (return from main) if VdbInitialize fails */ +#define VDB_INIT_FAILED 3 + +/* Terminate the VDB environment + * "rc" [ IN ] - result code as reported by VDB + * return recommended exit code for main() +*/ +KAPP_EXTERN int VdbTerminate( rc_t rc ); /* Quitting * is the program supposed to exit @@ -75,40 +86,24 @@ rc_t CC SignalNoHup ( void ); * MM = major release * mm = minor release * rrrr = bug-fix release + * default 0 */ -ver_t CC KAppVersion ( void ); - -/* KMain - EXTERN - * executable entrypoint "main" is implemented by - * an OS-specific wrapper that takes care of establishing - * signal handlers, logging, etc. - * - * in turn, OS-specific "main" will invoke "KMain" as - * platform independent main entrypoint. - * - * "argc" [ IN ] - the number of textual parameters in "argv" - * should never be < 0, but has been left as a signed int - * for reasons of tradition. - * - * "argv" [ IN ] - array of NUL terminated strings expected - * to be in the shell-native character set: ASCII or UTF-8 - * element 0 is expected to be executable identity or path. - */ -rc_t CC KMain ( int argc, char *argv [] ); - +//ver_t CC KAppVersion ( void ); +ver_t GetKAppVersion (); +ver_t SetKAppVersion ( ver_t ver ); /* Usage - EXTERN * This function is called when the command line argument * handling sees -? -h or --help */ -rc_t CC Usage ( struct Args const * args ); - +typedef rc_t (CC *Usage_t) ( const Args * args ); +Usage_t SetUsage ( Usage_t func ); /* Version - EXTERN * Obsolete: formerly called when the command line option handler * saw -V or --version */ -rc_t CC Version ( struct Args const * args ); +//rc_t CC Version ( struct Args const * args ); /* Usage - EXTERN @@ -152,7 +147,7 @@ uint64_t CC AsciiToU64 ( const char *arg, * legal values for the parameter are: * 1. a sequence of + or - characters that each bump the current log level * up or down one. - * 2. an integer with a decimal value from 0 to 13 (octal and hex with the + * 2. an integer with a decimal value from 0 to 13 (octal and hex with the * same range are accepted. * 3. fatal, err, warn, info, debug1, debug3, debug3, debug4, debug5, debug6 * debug7, debug8, debug9, debug10 @@ -168,7 +163,38 @@ void CC NextLogLevelh ( int *ip, int argc, char *argv [], rc_t CC NextLogLevelCommon ( const char * level_parameter ); #ifdef __cplusplus + + namespace VDB + { + + class Application + { + public: + Application(int argc, char* argv[], ver_t vers = 0); +#if WINDOWS && UNICODE + Application( int argc, wchar_t* argv[], ver_t vers = 0); +#endif + ~Application(); + + operator bool() const { return m_rc == 0; } + rc_t getRc() const { return m_rc; } + void setRc( rc_t p_rc ) { m_rc = p_rc; } + + // recommended exit code for main() based on reported rc + int getExitCode() const { return m_rc == 0 ? 0 : IF_EXITCODE( m_rc, 3 ); } + + int getArgC() const { return m_argc; } + char** getArgV() { return m_argv; } + const char** getArgV() const { return (const char**)m_argv; } + + private: + int m_argc; + char** m_argv; + bool m_argvOwned; // true if args have been rewritten + rc_t m_rc = 0; + }; + + } } #endif -#endif /* _h_kapp_main_ */ diff --git a/libs/kapp/win/main-priv-win.h b/interfaces/kapp/win/main-priv-win.h similarity index 78% rename from libs/kapp/win/main-priv-win.h rename to interfaces/kapp/win/main-priv-win.h index b5484f9dc..03a0f03ca 100644 --- a/libs/kapp/win/main-priv-win.h +++ b/interfaces/kapp/win/main-priv-win.h @@ -33,17 +33,10 @@ extern "C" { /* * Windows function to convert arguments from wchar_t string to utf-8 string - * Also checks and converts path from Windows to POSIX format - * - * "arg" windows command line argument - * - * "known_as_path" indicates whether we need a path conversion path. - * If it set to false, then rewrite_arg will only convert argument to utf-8. - * - * "after_main" indicates whether rewrite happens before or inside calling KMane + * Also checks and converts paths from Windows to POSIX format */ -char * CC rewrite_arg_as_path ( const wchar_t *arg, bool before_kmane ); - +int ConvertWArgsToUtf8(int argc, wchar_t* wargv[], char** argv[], bool convert_args_paths); + #ifdef __cplusplus } #endif diff --git a/interfaces/kfg/config.h b/interfaces/kfg/config.h index ca81eaf53..886a0d672 100644 --- a/interfaces/kfg/config.h +++ b/interfaces/kfg/config.h @@ -41,18 +41,6 @@ extern "C" { #endif -/* - * This flag has important ramifications to all programs. - * If set then all programs that use KMain()/KMane() - * become dependant on the kfg and kfs libraries. - * - * This will also modify the behavior of program tear down. - * if unset the memory used by the singleton config manager - * will not be freed. - */ -#define KFG_COMMON_CREATION 0 - - /*-------------------------------------------------------------------------- * forwards */ @@ -127,7 +115,7 @@ KFG_EXTERN rc_t CC KConfigRead ( const KConfig *self, const char *path, */ KFG_EXTERN rc_t CC KConfigReadBool ( const KConfig* self, const char* path, bool* result ); KFG_EXTERN rc_t CC KConfigWriteBool( KConfig *self, const char * path, bool value ); - + /* ReadI64 * read an integer node value * @@ -288,7 +276,7 @@ KFG_EXTERN rc_t CC KConfigNodeRead ( const KConfigNode *self, */ KFG_EXTERN rc_t CC KConfigNodeReadBool ( const KConfigNode *self, bool* result ); - + /* ReadI64 * read an integer node value * diff --git a/interfaces/kfs/file-impl.h b/interfaces/kfs/file-impl.h index ee9a1eee2..7a78e9313 100644 --- a/interfaces/kfs/file-impl.h +++ b/interfaces/kfs/file-impl.h @@ -72,6 +72,10 @@ struct KFile_v1 KRefcount refcount; uint8_t read_enabled; uint8_t write_enabled; + void ( CC * read_observer_update ) + ( void *self, rc_t rc, uint64_t pos, void *buffer, size_t num_read ); + rc_t ( CC * read_observer_destroy ) ( void *self ); + void *read_observer; uint8_t align [ 2 ]; }; diff --git a/interfaces/kfs/file-v1.h b/interfaces/kfs/file-v1.h index f7af62621..a4e0bf97e 100644 --- a/interfaces/kfs/file-v1.h +++ b/interfaces/kfs/file-v1.h @@ -265,6 +265,25 @@ KFS_EXTERN rc_t CC KFileMakeStdOut_v1 ( KFile_v1 **std_out ); KFS_EXTERN rc_t CC KFileMakeStdErr_v1 ( KFile_v1 **std_err ); +/* SetReadObserver + * set observer that is called after each read. + * + * "read_observer_update" [ IN ] - observer's update function + * + * "read_observer_destroy" [ IN ] - function to release observer + * to be called when KFile is deleted + * + * "read_observer" [ IN ] - has to be passed when "read_observer_update" + * or "read_observer_destroy" is called. + */ +KFS_EXTERN rc_t CC KFileSetReadObserver ( + KFile * self, + void ( CC * read_observer_update ) + ( void * self, rc_t rc, uint64_t pos, void *buffer, size_t num_read ), + rc_t ( CC * read_observer_destroy ) ( void *self ), + void * read_observer + ); + #ifdef __cplusplus } #endif diff --git a/interfaces/kfs/md5.h b/interfaces/kfs/md5.h index 798f82780..8cd45be05 100644 --- a/interfaces/kfs/md5.h +++ b/interfaces/kfs/md5.h @@ -1,4 +1,4 @@ -/*======================================================================================= +/*============================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information @@ -282,6 +282,44 @@ KFS_EXTERN rc_t CC KMD5FileRevert ( KMD5File *self ); KFS_EXTERN rc_t CC KMD5FileReset ( KMD5File *self ); +/*------------------------------------------------------------------------------ + * MD5 KFile Read Observer + */ + +typedef struct KFileMD5ReadObserver KFileMD5ReadObserver; +/* Make + * Creates a Read Observer for KFile that calculates + * the md5 checksum of the read data. + * To calculate the md5, the file must be read sequentially + * from start to end. + * + * "self" [ IN ] - the input file to which the read observer is attached + * "observer" [ OUT ] - created observer. + */ + +KFS_EXTERN rc_t CC KFileMakeMD5ReadObserver ( const struct KFile * self, + const KFileMD5ReadObserver ** observer ); + +/* Release */ +KFS_EXTERN rc_t CC KFileMD5ReadObserverRelease ( + const KFileMD5ReadObserver *self ); + + +/*------------------------------------------------------------------------------ + * GetDigest + * a formatter for reading or writing an md5sum-style checksum file. + * Returns a non-zero rc value if md5 cannot be calculated for the entire file. + * + * "digest" [ OUT ] - return parameter for the MD5 checksum + * + * "error" [ OUT, NULL OKAY ] - optional error message that is returned + * when md5 cannot be calculated because not all file was read sequentially. + * "free(error)" has to be called after you have finished using it. + */ +KFS_EXTERN rc_t CC KFileMD5ReadObserverGetDigest ( + const KFileMD5ReadObserver *self, uint8_t digest [ 16 ], + const char ** error); + #ifdef __cplusplus } #endif diff --git a/interfaces/klib/klib-priv.h b/interfaces/klib/klib-priv.h index 2b2580dee..12e139eb5 100644 --- a/interfaces/klib/klib-priv.h +++ b/interfaces/klib/klib-priv.h @@ -101,6 +101,10 @@ KLIB_EXTERN rc_t CC ReportInitVDB( */ KLIB_EXTERN void CC ReportRecordZombieFile ( void ); +/* ReportGet + */ +KLIB_EXTERN rc_t ReportGetVersion( ver_t * version ); + #ifdef __cplusplus } #endif diff --git a/interfaces/klib/vdb_release_version.h b/interfaces/klib/vdb_release_version.h index 2dbb8460c..6d60584e8 100644 --- a/interfaces/klib/vdb_release_version.h +++ b/interfaces/klib/vdb_release_version.h @@ -26,6 +26,6 @@ * ============================================================================== */ -#define VDB_RELEASE_VERSION 0x03020001 +#define VDB_RELEASE_VERSION 0x03020002 #endif /* _h_klib_vdb_release_version_ */ diff --git a/interfaces/ktst/unit_test_suite.hpp b/interfaces/ktst/unit_test_suite.hpp index 250406303..4cf394b8b 100644 --- a/interfaces/ktst/unit_test_suite.hpp +++ b/interfaces/ktst/unit_test_suite.hpp @@ -131,7 +131,7 @@ class TestEnv { static void set_handlers(void); - static std::string lastLocation; + static char lastLocation[]; static LogLevel::E verbosity; static bool verbositySet; bool catch_system_errors; @@ -470,26 +470,30 @@ class SharedTest : protected TestCase { class TestInvoker { protected: - TestInvoker(const std::string& name) : _name(name), _ec(0) {} + TestInvoker(const std::string& name) : _ec(0) + { + strncpy( _name, name.c_str(), sizeof(_name) - 1 ); + _name[ sizeof(_name) - 1 ] = 0; + } virtual ~TestInvoker(void) {} public: virtual void Run(void* globalFixtute) throw () = 0; - const std::string& GetName(void) const { return _name; } + std::string GetName(void) const { return _name; } ncbi::NK::counter_t GetErrorCounter(void) { return _ec; } protected: void SetErrorCounter(ncbi::NK::counter_t ec) { _ec = ec; } private: - const std::string _name; + char _name[1024]; ncbi::NK::counter_t _ec; }; class TestRunner { - typedef std::vector T; - typedef T::const_iterator TCI; + typedef ncbi::NK::TestInvoker* T[1024]; // pointers are not owned public: TestRunner(); + virtual ~TestRunner(); int argc; char** argv; @@ -501,6 +505,7 @@ class TestRunner { private: T _cases; + size_t _cases_count = 0; }; extern ncbi::NK::TestRunner* GetTestSuite(); diff --git a/interfaces/os/mac/os-native.h b/interfaces/os/mac/os-native.h index a609839fd..bb65b0ccd 100644 --- a/interfaces/os/mac/os-native.h +++ b/interfaces/os/mac/os-native.h @@ -66,18 +66,6 @@ char *strndup ( const char *str, size_t n ) } #endif -/*-------------------------------------------------------------------------- - * strchrnul - implemented inline here - */ -static __inline__ -char *strchrnul ( const char *str, int c ) -{ - int i; - for ( i = 0; str [ i ] != 0 && str [ i ] != c; ++i ) - ( void ) 0; - return & ( ( char* ) str ) [ i ]; -} - /*-------------------------------------------------------------------------- * memchr - implemented inline here */ diff --git a/interfaces/sra/454.vschema b/interfaces/sra/454.vschema index 0722fc435..d075a37b2 100644 --- a/interfaces/sra/454.vschema +++ b/interfaces/sra/454.vschema @@ -53,7 +53,9 @@ include 'ncbi/clip.vschema'; * all bases following "key" into mate pair biological reads * * returns a trio for each identified read, with read type, start and length - */ + * / + +******** moved to sra-tools: VDB-4799 ******** typeset NCBI:SRA:_454_:drdparam_set { ascii, U8, INSDC:2na:packed }; extern function U32 [ 3 ] NCBI:SRA:_454_:dynamic_read_desc #1 < * U32 edit_distance > @@ -63,7 +65,7 @@ U32 [ 3 ] NCBI:SRA:_454_:dynamic_read_desc #1 < * U32 edit_distance > const U32 NCBI:SRA:_454_:dyn_read_type = 0; const U32 NCBI:SRA:_454_:dyn_read_start = 1; const U32 NCBI:SRA:_454_:dyn_read_len = 2; - +*/ /* tokenize_spot_name * scans name on input diff --git a/interfaces/vfs/resolver.h b/interfaces/vfs/resolver.h index f083dc190..efbafb770 100644 --- a/interfaces/vfs/resolver.h +++ b/interfaces/vfs/resolver.h @@ -252,7 +252,8 @@ enum { vrUseConfig = 0, /* take enable/disable state from KConfig */ vrAlwaysEnable = 1, /* always enable, regardless of KConfig */ - vrAlwaysDisable = 2 /* always disable, regardless of KConfig */ + vrAlwaysDisable = 2, /* always disable, regardless of KConfig */ + vrUninitialized = 3, }; diff --git a/libs/align/align-access.c b/libs/align/align-access.c index a3c81d65d..723851de9 100644 --- a/libs/align/align-access.c +++ b/libs/align/align-access.c @@ -675,7 +675,7 @@ LIB_EXPORT rc_t CC AlignAccessAlignmentEnumeratorGetCIGAR( #ifdef WINDOWS cig1len = sprintf_s(cig1, sizeof(cig1), "%c%u", op, len); #else - cig1len = sprintf(cig1, "%c%u", op, len); + cig1len = snprintf(cig1, sizeof(cig1), "%c%u", op, len); #endif if (cigbuf + cig1len < endp) { if (cigar_buffer != NULL) { diff --git a/libs/align/samextract-lib.cpp b/libs/align/samextract-lib.cpp index 26cbe7e9f..6c56e820b 100644 --- a/libs/align/samextract-lib.cpp +++ b/libs/align/samextract-lib.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +//#include #include #include #include @@ -553,6 +553,7 @@ LIB_EXPORT rc_t CC SAMExtractorMake( SAMExtractor ** state, const KFile * fin, pool_init(); s->infile = fin; + KFileAddRef(s->infile); fname_desc = string_dup_measure( fname->addr, NULL ); // s->fname = fname_desc; @@ -618,6 +619,7 @@ LIB_EXPORT rc_t CC SAMExtractorRelease( SAMExtractor * s ) KQueueRelease( s->inflatequeue ); KQueueRelease( s->parsequeue ); VectorWhack( &s->threads, NULL, NULL ); + KFileRelease(s->infile); free( s->readbuf ); free( s->filter_rname ); free( fname_desc ); diff --git a/libs/align/writer-cmn.c b/libs/align/writer-cmn.c index ddb9552c2..789ff32fc 100644 --- a/libs/align/writer-cmn.c +++ b/libs/align/writer-cmn.c @@ -28,7 +28,7 @@ #include #include #include -#include +//#include #include #include #include @@ -290,7 +290,7 @@ rc_t CC TableWriter_Whack(const TableWriter* cself, bool commit, uint64_t* rows) if( cself != NULL ) { TableWriter* self = (TableWriter*)cself; uint32_t i, j; - + for(i = 0; i < TW_MAX_CURSORS; i++) { if( self->cursors[i].col_qty > 0 ) { self->curr = &self->cursors[i]; @@ -417,7 +417,7 @@ rc_t CC TableWriter_CloseCursor(const TableWriter* cself, uint8_t cursor_id, uin rc_t CC TableWriter_Flush(const TableWriter *cself, const uint8_t cursor_id) { rc_t rc = 0; - + if( cself == NULL || cursor_id >= TW_MAX_CURSORS || cself->cursors[cursor_id].col_qty == 0 ) { rc = RC(rcAlign, rcType, rcOpening, rcParam, rcInvalid); ALIGN_DBGERR(rc); @@ -460,7 +460,7 @@ rc_t CC TableWriter_OpenRow(const TableWriter* cself, int64_t* rowid, const uint rc_t CC TableWriter_OpenRowId(const TableWriter* cself, const int64_t rowid, const uint8_t cursor_id) { rc_t rc = 0; - + if( cself == NULL || cursor_id >= TW_MAX_CURSORS || cself->cursors[cursor_id].col_qty == 0 ) { rc = RC(rcAlign, rcType, rcOpening, rcParam, rcInvalid); ALIGN_DBGERR(rc); @@ -497,7 +497,7 @@ rc_t CC TableWriter_OpenRowId(const TableWriter* cself, const int64_t rowid, con rc_t CC TableWriter_GetNextRowId(const TableWriter* cself, int64_t* rowid, const uint8_t cursor_id) { rc_t rc = 0; - + if( cself == NULL || cursor_id >= TW_MAX_CURSORS || cself->cursors[cursor_id].col_qty == 0 ) { rc = RC(rcAlign, rcType, rcOpening, rcParam, rcInvalid); ALIGN_DBGERR(rc); diff --git a/libs/align/writer-reference.c b/libs/align/writer-reference.c index 94dc4ba24..181802a1f 100644 --- a/libs/align/writer-reference.c +++ b/libs/align/writer-reference.c @@ -818,6 +818,8 @@ rc_t ImportFasta(ReferenceSeq *const obj, KDataBuffer const *const buf) ++dst; } MD5StateFinish(&mds, obj->md5); + if (dst == start) + (void)PLOGERR(klogWarn, (klogWarn, SILENT_RC(rcAlign, rcFile, rcReading, rcData, rcEmpty), "Reference sequence '$(defline)' is empty", "defline=%s", fastaSeqId)); rc = KDataBufferSub(buf, &obj->u.local.buf, start, dst - start); if (rc == 0) { obj->fastaSeqId = fastaSeqId; @@ -1154,7 +1156,7 @@ rc_t OpenFastaFile(KFile const **const kf, return rc; } -#if 1 +#if _DEBUGGING void ReferenceSeq_Dump(ReferenceSeq const *const rs) { static char const *types[] = { @@ -1168,7 +1170,6 @@ void ReferenceSeq_Dump(ReferenceSeq const *const rs) }; unsigned j; - ((void)types); /* stupid warning */ ALIGN_CF_DBGF(("{ ")); ALIGN_CF_DBGF(("type: %s, ", (rs->type < 0 || rs->type > rst_dead) ? "null" : types[rs->type])); @@ -1204,9 +1205,11 @@ void ReferenceSeq_Dump(ReferenceSeq const *const rs) } ALIGN_CF_DBGF(("] }")); } +#endif LIB_EXPORT void ReferenceMgr_DumpConfig(ReferenceMgr const *const self) { +#if _DEBUGGING unsigned const n = (unsigned)self->refSeqs.elem_count; unsigned i; @@ -1217,8 +1220,8 @@ LIB_EXPORT void ReferenceMgr_DumpConfig(ReferenceMgr const *const self) ALIGN_CF_DBGF((",\n")); } ALIGN_CF_DBGF(("]\n")); -} #endif +} static rc_t ReferenceSeq_GetRefSeqInfo(ReferenceSeq *const self) @@ -1322,8 +1325,8 @@ static void sortCandidateList(unsigned const len, struct Candidate *list) ksort(list, len, sizeof(list[0]), cmpCandidate, NULL); } -static void candidates(ReferenceMgr *const self, - unsigned *const count, +static +unsigned candidates(ReferenceMgr *const self, struct Candidate **const rslt, unsigned const idLen, char const id[], @@ -1360,8 +1363,8 @@ static void candidates(ReferenceMgr *const self, free(possible); possible = NULL; } - *count = num_possible; *rslt = possible; + return num_possible; } static rc_t tryFastaOrRefSeq(ReferenceMgr *const self, @@ -1523,12 +1526,11 @@ static rc_t findSeq(ReferenceMgr *const self, bool wasRenamed[]) { unsigned const idLen = (unsigned)string_size(id); - unsigned num_possible = 0; - struct Candidate *possible = NULL; ReferenceSeq *chosen = NULL; rc_t rc = 0; - - candidates(self, &num_possible, &possible, idLen, id, seq_len, md5); + struct Candidate *possible = NULL; + unsigned const num_possible = candidates(self, &possible, idLen, id, seq_len, md5); + if (num_possible == 0) { /* nothing was found; try a fasta file */ bool tryAgain = false; @@ -2137,8 +2139,8 @@ rc_t ReferenceMgr_ReCover(const ReferenceMgr* cself, uint64_t ref_rows, rc_t (*c if (hi < depth) hi = depth; if (lo > depth) lo = depth; } - assert ( FITS_INTO_INT8 ( hi ) ); - assert ( FITS_INTO_INT8 ( lo ) ); + if ( hi > 255 ) hi = 255; + if ( lo > 255 ) lo = 255; data[rr].cover.high = (uint8_t)hi; data[rr].cover.low = (uint8_t)lo; rc = TableWriterRefCoverage_WriteCoverage(cover_writer,rr+1, &data[rr].cover); @@ -2335,6 +2337,11 @@ LIB_EXPORT rc_t CC ReferenceMgr_GetSeq(ReferenceMgr const * cself, *shouldUnmap = true; return 0; } + if (obj->seq_len == 0) { + rc = RC(rcAlign, rcFile, rcReading, rcData, rcEmpty); + PLOGERR(klogErr, (klogErr, rc, "Reference sequence '$(id)' is empty", "id=%s", id)); + return rc; + } if (obj->start_rowid == 0 && self->db != NULL) { rc = ReferenceMgr_LoadSeq(self, obj); if (rc) return rc; @@ -2428,9 +2435,8 @@ LIB_EXPORT rc_t CC ReferenceMgr_FastaPath(const ReferenceMgr* cself, const char* LIB_EXPORT rc_t CC ReferenceMgr_FastaFile(const ReferenceMgr* cself, const KFile* file) { - if(cself == NULL || file == NULL) { + if (cself == NULL || file == NULL) return RC(rcAlign, rcFile, rcConstructing, rcParam, rcNull); - } return ImportFastaFile((ReferenceMgr *)cself, file, NULL); } diff --git a/libs/axf/refseq.c b/libs/axf/refseq.c index 9cda83c6b..74b2b9757 100644 --- a/libs/axf/refseq.c +++ b/libs/axf/refseq.c @@ -47,7 +47,6 @@ typedef RefSeq Object; struct RefSeqAsyncLoadInfo { KRefcount refcount; - KThread *th; KLock *mutex; /**< mostly guards the cursor against concurrent use */ VCursor const *curs; /**< can be used by either thread after acquiring the mutex */ RowRange rr; /**< of the table */ @@ -72,27 +71,20 @@ static void RefSeqAsyncLoadInfo_Release(RefSeqAsyncLoadInfo *const self) } VCursorRelease(self->curs); KLockRelease(self->mutex); - KThreadRelease(self->th); free(self); } -static rc_t RefSeqAsyncLoadInfoFree(RefSeqAsyncLoadInfo *const self) +static void RefSeqAsyncLoadInfoFree(RefSeqAsyncLoadInfo *const self) { - rc_t rc = 0; if (self) { /* Synchronize with background thread in preparation for clean up */ - KRefcountAdd(&self->refcount, "RefSeqAsyncLoadInfo"); // keep alive; let die at line 89 + KRefcountAdd(&self->refcount, "RefSeqAsyncLoadInfo"); // keep alive; let die at line 88 LOGMSG(klogDebug, "Foreground thread ending background thread"); KLockAcquire(self->mutex); self->count = 0; KLockUnlock(self->mutex); - KThreadWait(self->th, &rc); - LOGERR(klogDebug, rc, "Background thread ended"); RefSeqAsyncLoadInfo_Release(self); - if (rc) - LOGERR(klogErr, rc, "asynchronous loader thread failed"); } - return rc; } // packed 2na to unpacked 4na @@ -424,6 +416,19 @@ char const *RefSeq_Scheme(void) { return "NCBI:refseq:tbl:reference"; } +static rc_t cleanUpAsyncThread(Object const *self) +{ + rc_t rc = 0; + if (self->th) { + KThreadWait(self->th, &rc); + if (rc) + LOGERR(klogErr, rc, "asynchronous loader thread failed"); + KThreadRelease(self->th); + ((Object *)self)->th = NULL; + } + return rc; +} + unsigned RefSeq_getBases(Object const * self, uint8_t *const dst, unsigned const start, unsigned const len) { atomic_t *const rwl = &((Object *)self)->rwl; @@ -445,6 +450,10 @@ unsigned RefSeq_getBases(Object const * self, uint8_t *const dst, unsigned const while ((atomic_read(rwl) & 1) != 0) ; /* the state has been updated; use the new state */ + if (self->async == NULL) { + rc_t const rc = cleanUpAsyncThread(self); + if (rc) return rc; + } return RefSeq_getBases(self, dst, start, len); } @@ -574,7 +583,7 @@ static rc_t load( Object *result result->length = (unsigned)baseCount; result->async = RefSeqAsyncLoadInfoMake(curs, rowRange, info + 1, &rc); if (rc == 0) { - rc = KThreadMake(&result->async->th, run_load_thread, result); + rc = KThreadMake(&result->th, run_load_thread, result); if (rc == 0) { result->reader = readNormalIncomplete; return 0; @@ -618,6 +627,7 @@ static rc_t init(Object *result, VTable const *const tbl) void RefSeqFree(Object *self) { RefSeqAsyncLoadInfoFree(self->async); + cleanUpAsyncThread(self); RangeListFree(&self->Ns); free(self->bases); free(self); diff --git a/libs/axf/refseq.h b/libs/axf/refseq.h index 57a560ea3..81c03bb8f 100644 --- a/libs/axf/refseq.h +++ b/libs/axf/refseq.h @@ -38,6 +38,7 @@ struct RefSeq { uint8_t *bases; RefSeqReaderFunc volatile reader; RefSeqAsyncLoadInfo *volatile async; + struct KThread *th; atomic_t rwl; unsigned length; ///< logical length, is base count of the reference }; diff --git a/libs/blast/blast-mgr.c b/libs/blast/blast-mgr.c index 0e71c77aa..edd3068e5 100644 --- a/libs/blast/blast-mgr.c +++ b/libs/blast/blast-mgr.c @@ -50,7 +50,7 @@ #include /* fprintf */ #include /* memset */ -#define TOOLKIT "sratoolkit3_2_1" +#define TOOLKIT "sratoolkit3_2_2" /******************************************************************************/ diff --git a/libs/blast/reader.c b/libs/blast/reader.c index 5593a52cf..5d4df1fb6 100644 --- a/libs/blast/reader.c +++ b/libs/blast/reader.c @@ -512,11 +512,12 @@ bool _ReadDescNextRead(ReadDesc *self, VdbBlastStatus *status) *status = _ReadDescFixReadId(self); return true; } - else + else { TRACE(); return read; } + } } static diff --git a/libs/cipher/.gitignore b/libs/cipher/cipher-1.7/.gitignore similarity index 76% rename from libs/cipher/.gitignore rename to libs/cipher/cipher-1.7/.gitignore index 7db5002e8..1e362807d 100644 --- a/libs/cipher/.gitignore +++ b/libs/cipher/cipher-1.7/.gitignore @@ -1 +1,2 @@ cipher.egg-info +.eggs \ No newline at end of file diff --git a/libs/ext/zlib/adler32.c b/libs/ext/zlib/adler32.c index d0be4380a..04b81d29b 100644 --- a/libs/ext/zlib/adler32.c +++ b/libs/ext/zlib/adler32.c @@ -7,8 +7,6 @@ #include "zutil.h" -local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); - #define BASE 65521U /* largest prime smaller than 65536 */ #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ @@ -60,11 +58,7 @@ local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); #endif /* ========================================================================= */ -uLong ZEXPORT adler32_z(adler, buf, len) - uLong adler; - const Bytef *buf; - z_size_t len; -{ +uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) { unsigned long sum2; unsigned n; @@ -131,20 +125,12 @@ uLong ZEXPORT adler32_z(adler, buf, len) } /* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ +uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { return adler32_z(adler, buf, len); } /* ========================================================================= */ -local uLong adler32_combine_(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ +local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) { unsigned long sum1; unsigned long sum2; unsigned rem; @@ -169,18 +155,10 @@ local uLong adler32_combine_(adler1, adler2, len2) } /* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off_t len2; -{ +uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) { return adler32_combine_(adler1, adler2, len2); } -uLong ZEXPORT adler32_combine64(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ +uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) { return adler32_combine_(adler1, adler2, len2); } diff --git a/libs/ext/zlib/compress.c b/libs/ext/zlib/compress.c index 2ad5326c1..f43bacf7a 100644 --- a/libs/ext/zlib/compress.c +++ b/libs/ext/zlib/compress.c @@ -19,13 +19,8 @@ memory, Z_BUF_ERROR if there was not enough room in the output buffer, Z_STREAM_ERROR if the level parameter is invalid. */ -int ZEXPORT compress2(dest, destLen, source, sourceLen, level) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; - int level; -{ +int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen, int level) { z_stream stream; int err; const uInt max = (uInt)-1; @@ -65,12 +60,8 @@ int ZEXPORT compress2(dest, destLen, source, sourceLen, level) /* =========================================================================== */ -int ZEXPORT compress(dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ +int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen) { return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); } @@ -78,9 +69,7 @@ int ZEXPORT compress(dest, destLen, source, sourceLen) If the default memLevel or windowBits for deflateInit() is changed, then this function needs to be updated. */ -uLong ZEXPORT compressBound(sourceLen) - uLong sourceLen; -{ +uLong ZEXPORT compressBound(uLong sourceLen) { return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13; } diff --git a/libs/ext/zlib/crc32.c b/libs/ext/zlib/crc32.c index f8357b083..6c38f5c04 100644 --- a/libs/ext/zlib/crc32.c +++ b/libs/ext/zlib/crc32.c @@ -103,19 +103,6 @@ # define ARMCRC32 #endif -/* Local functions. */ -local z_crc_t multmodp OF((z_crc_t a, z_crc_t b)); -local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); - -#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) - local z_word_t byte_swap OF((z_word_t word)); -#endif - -#if defined(W) && !defined(ARMCRC32) - local z_crc_t crc_word OF((z_word_t data)); - local z_word_t crc_word_big OF((z_word_t data)); -#endif - #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) /* Swap the bytes in a z_word_t to convert between little and big endian. Any @@ -123,9 +110,7 @@ local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); instruction, if one is available. This assumes that word_t is either 32 bits or 64 bits. */ -local z_word_t byte_swap(word) - z_word_t word; -{ +local z_word_t byte_swap(z_word_t word) { # if W == 8 return (word & 0xff00000000000000) >> 56 | @@ -146,24 +131,77 @@ local z_word_t byte_swap(word) } #endif +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Table of powers of x for combining CRC-32s, filled in by make_crc_table() + * below. + */ + local z_crc_t FAR x2n_table[32]; +#else +/* ========================================================================= + * Tables for byte-wise and braided CRC-32 calculations, and a table of powers + * of x for combining CRC-32s, all made by make_crc_table(). + */ +# include "crc32.h" +#endif + /* CRC polynomial. */ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ -#ifdef DYNAMIC_CRC_TABLE +/* + Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, + reflected. For speed, this requires that a not be zero. + */ +local z_crc_t multmodp(z_crc_t a, z_crc_t b) { + z_crc_t m, p; + + m = (z_crc_t)1 << 31; + p = 0; + for (;;) { + if (a & m) { + p ^= b; + if ((a & (m - 1)) == 0) + break; + } + m >>= 1; + b = b & 1 ? (b >> 1) ^ POLY : b >> 1; + } + return p; +} +/* + Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been + initialized. + */ +local z_crc_t x2nmodp(z_off64_t n, unsigned k) { + z_crc_t p; + + p = (z_crc_t)1 << 31; /* x^0 == 1 */ + while (n) { + if (n & 1) + p = multmodp(x2n_table[k & 31], p); + n >>= 1; + k++; + } + return p; +} + +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Build the tables for byte-wise and braided CRC-32 calculations, and a table + * of powers of x for combining CRC-32s. + */ local z_crc_t FAR crc_table[256]; -local z_crc_t FAR x2n_table[32]; -local void make_crc_table OF((void)); #ifdef W local z_word_t FAR crc_big_table[256]; local z_crc_t FAR crc_braid_table[W][256]; local z_word_t FAR crc_braid_big_table[W][256]; - local void braid OF((z_crc_t [][256], z_word_t [][256], int, int)); + local void braid(z_crc_t [][256], z_word_t [][256], int, int); #endif #ifdef MAKECRCH - local void write_table OF((FILE *, const z_crc_t FAR *, int)); - local void write_table32hi OF((FILE *, const z_word_t FAR *, int)); - local void write_table64 OF((FILE *, const z_word_t FAR *, int)); + local void write_table(FILE *, const z_crc_t FAR *, int); + local void write_table32hi(FILE *, const z_word_t FAR *, int); + local void write_table64(FILE *, const z_word_t FAR *, int); #endif /* MAKECRCH */ /* @@ -176,7 +214,6 @@ local void make_crc_table OF((void)); /* Definition of once functionality. */ typedef struct once_s once_t; -local void once OF((once_t *, void (*)(void))); /* Check for the availability of atomics. */ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ @@ -196,10 +233,7 @@ struct once_s { invoke once() at the same time. The state must be a once_t initialized with ONCE_INIT. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!atomic_load(&state->done)) { if (atomic_flag_test_and_set(&state->begun)) while (!atomic_load(&state->done)) @@ -222,10 +256,7 @@ struct once_s { /* Test and set. Alas, not atomic, but tries to minimize the period of vulnerability. */ -local int test_and_set OF((int volatile *)); -local int test_and_set(flag) - int volatile *flag; -{ +local int test_and_set(int volatile *flag) { int was; was = *flag; @@ -234,10 +265,7 @@ local int test_and_set(flag) } /* Run the provided init() function once. This is not thread-safe. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!state->done) { if (test_and_set(&state->begun)) while (!state->done) @@ -279,8 +307,7 @@ local once_t made = ONCE_INIT; combinations of CRC register values and incoming bytes. */ -local void make_crc_table() -{ +local void make_crc_table(void) { unsigned i, j, n; z_crc_t p; @@ -447,11 +474,7 @@ local void make_crc_table() Write the 32-bit values in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table(out, table, k) - FILE *out; - const z_crc_t FAR *table; - int k; -{ +local void write_table(FILE *out, const z_crc_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -464,11 +487,7 @@ local void write_table(out, table, k) Write the high 32-bits of each value in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table32hi(out, table, k) -FILE *out; -const z_word_t FAR *table; -int k; -{ +local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -484,11 +503,7 @@ int k; bits. If not, then the type cast and format string can be adjusted accordingly. */ -local void write_table64(out, table, k) - FILE *out; - const z_word_t FAR *table; - int k; -{ +local void write_table64(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -498,8 +513,7 @@ local void write_table64(out, table, k) } /* Actually do the deed. */ -int main() -{ +int main(void) { make_crc_table(); return 0; } @@ -511,12 +525,7 @@ int main() Generate the little and big-endian braid tables for the given n and z_word_t size w. Each array must have room for w blocks of 256 elements. */ -local void braid(ltl, big, n, w) - z_crc_t ltl[][256]; - z_word_t big[][256]; - int n; - int w; -{ +local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) { int k; z_crc_t i, p, q; for (k = 0; k < w; k++) { @@ -531,69 +540,13 @@ local void braid(ltl, big, n, w) } #endif -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables for byte-wise and braided CRC-32 calculations, and a table of powers - * of x for combining CRC-32s, all made by make_crc_table(). - */ -#include "crc32.h" #endif /* DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Routines used for CRC calculation. Some are also required for the table - * generation above. - */ - -/* - Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, - reflected. For speed, this requires that a not be zero. - */ -local z_crc_t multmodp(a, b) - z_crc_t a; - z_crc_t b; -{ - z_crc_t m, p; - - m = (z_crc_t)1 << 31; - p = 0; - for (;;) { - if (a & m) { - p ^= b; - if ((a & (m - 1)) == 0) - break; - } - m >>= 1; - b = b & 1 ? (b >> 1) ^ POLY : b >> 1; - } - return p; -} - -/* - Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been - initialized. - */ -local z_crc_t x2nmodp(n, k) - z_off64_t n; - unsigned k; -{ - z_crc_t p; - - p = (z_crc_t)1 << 31; /* x^0 == 1 */ - while (n) { - if (n & 1) - p = multmodp(x2n_table[k & 31], p); - n >>= 1; - k++; - } - return p; -} - /* ========================================================================= * This function can be used by asm versions of crc32(), and to force the * generation of the CRC tables in a threaded application. */ -const z_crc_t FAR * ZEXPORT get_crc_table() -{ +const z_crc_t FAR * ZEXPORT get_crc_table(void) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -619,11 +572,8 @@ const z_crc_t FAR * ZEXPORT get_crc_table() #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */ #define Z_BATCH_MIN 800 /* fewest words in a final batch */ -unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - z_size_t len; -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { z_crc_t val; z_word_t crc1, crc2; const z_word_t *word; @@ -723,18 +673,14 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) least-significant byte of the word as the first byte of data, without any pre or post conditioning. This is used to combine the CRCs of each braid. */ -local z_crc_t crc_word(data) - z_word_t data; -{ +local z_crc_t crc_word(z_word_t data) { int k; for (k = 0; k < W; k++) data = (data >> 8) ^ crc_table[data & 0xff]; return (z_crc_t)data; } -local z_word_t crc_word_big(data) - z_word_t data; -{ +local z_word_t crc_word_big(z_word_t data) { int k; for (k = 0; k < W; k++) data = (data << 8) ^ @@ -745,11 +691,8 @@ local z_word_t crc_word_big(data) #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32_z(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - z_size_t len; -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { /* Return initial CRC, if requested. */ if (buf == Z_NULL) return 0; @@ -781,8 +724,8 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) words = (z_word_t const *)buf; /* Do endian check at execution time instead of compile time, since ARM - processors can change the endianess at execution time. If the - compiler knows what the endianess will be, it can optimize out the + processors can change the endianness at execution time. If the + compiler knows what the endianness will be, it can optimize out the check and the unused branch. */ endian = 1; if (*(unsigned char *)&endian) { @@ -1069,20 +1012,13 @@ unsigned long ZEXPORT crc32_z(crc, buf, len) #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - uInt len; -{ +unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, + uInt len) { return crc32_z(crc, buf, len); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine64(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ +uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1090,18 +1026,12 @@ uLong ZEXPORT crc32_combine64(crc1, crc2, len2) } /* ========================================================================= */ -uLong ZEXPORT crc32_combine(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off_t len2; -{ +uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) { return crc32_combine64(crc1, crc2, (z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen64(len2) - z_off64_t len2; -{ +uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1109,17 +1039,11 @@ uLong ZEXPORT crc32_combine_gen64(len2) } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen(len2) - z_off_t len2; -{ +uLong ZEXPORT crc32_combine_gen(z_off_t len2) { return crc32_combine_gen64((z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_op(crc1, crc2, op) - uLong crc1; - uLong crc2; - uLong op; -{ +uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) { return multmodp(op, crc1) ^ (crc2 & 0xffffffff); } diff --git a/libs/ext/zlib/deflate.c b/libs/ext/zlib/deflate.c index 4a689db35..012ea8148 100644 --- a/libs/ext/zlib/deflate.c +++ b/libs/ext/zlib/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -52,7 +52,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; + " deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -60,9 +60,6 @@ const char deflate_copyright[] = copyright string in the executable of your product. */ -/* =========================================================================== - * Function prototypes. - */ typedef enum { need_more, /* block not completed, need more input or more output */ block_done, /* block flush performed */ @@ -70,29 +67,16 @@ typedef enum { finish_done /* finish done, accept no more input or output */ } block_state; -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +typedef block_state (*compress_func)(deflate_state *s, int flush); /* Compression function. Returns the block state after the call. */ -local int deflateStateCheck OF((z_streamp strm)); -local void slide_hash OF((deflate_state *s)); -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); +local block_state deflate_stored(deflate_state *s, int flush); +local block_state deflate_fast(deflate_state *s, int flush); #ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); -#endif -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -local uInt longest_match OF((deflate_state *s, IPos cur_match)); - -#ifdef ZLIB_DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); +local block_state deflate_slow(deflate_state *s, int flush); #endif +local block_state deflate_rle(deflate_state *s, int flush); +local block_state deflate_huff(deflate_state *s, int flush); /* =========================================================================== * Local data @@ -195,9 +179,12 @@ local const config configuration_table[10] = { * bit values at the expense of memory usage). We slide even when level == 0 to * keep the hash table consistent if we switch back to level > 0 later. */ -local void slide_hash(s) - deflate_state *s; -{ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __attribute__((no_sanitize("memory"))) +# endif +#endif +local void slide_hash(deflate_state *s) { unsigned n, m; Posf *p; uInt wsize = s->w_size; @@ -221,30 +208,177 @@ local void slide_hash(s) #endif } +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) { + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, buf, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, buf, len); + } +#endif + strm->next_in += len; + strm->total_in += len; + + return len; +} + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(deflate_state *s) { + unsigned n; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize + MAX_DIST(s)) { + + zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + if (s->insert > s->strstart) + s->insert = s->strstart; + slide_hash(s); + more += wsize; + } + if (s->strm->avail_in == 0) break; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead + s->insert >= MIN_MATCH) { + uInt str = s->strstart - s->insert; + s->ins_h = s->window[str]; + UPDATE_HASH(s, s->ins_h, s->window[str + 1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + while (s->insert) { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + s->insert--; + if (s->lookahead + s->insert < MIN_MATCH) + break; + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } + + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "not enough room for search"); +} + /* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ +int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, + int stream_size) { return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, version, stream_size); /* To do: ignore strm->next_in if we use it as window */ } /* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - version, stream_size) - z_streamp strm; - int level; - int method; - int windowBits; - int memLevel; - int strategy; - const char *version; - int stream_size; -{ +int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, int strategy, + const char *version, int stream_size) { deflate_state *s; int wrap = 1; static const char my_version[] = ZLIB_VERSION; @@ -359,7 +493,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, * symbols from which it is being constructed. */ - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4); + s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS); s->pending_buf_size = (ulg)s->lit_bufsize * 4; if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || @@ -369,8 +503,14 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, deflateEnd (strm); return Z_MEM_ERROR; } +#ifdef LIT_MEM + s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1)); + s->l_buf = s->pending_buf + (s->lit_bufsize << 2); + s->sym_end = s->lit_bufsize - 1; +#else s->sym_buf = s->pending_buf + s->lit_bufsize; s->sym_end = (s->lit_bufsize - 1) * 3; +#endif /* We avoid equality with lit_bufsize*3 because of wraparound at 64K * on 16 bit machines and because stored blocks are restricted to * 64K-1 bytes. @@ -386,9 +526,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, /* ========================================================================= * Check for a valid deflate stream state. Return 0 if ok, 1 if not. */ -local int deflateStateCheck(strm) - z_streamp strm; -{ +local int deflateStateCheck(z_streamp strm) { deflate_state *s; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -409,11 +547,8 @@ local int deflateStateCheck(strm) } /* ========================================================================= */ -int ZEXPORT deflateSetDictionary(strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ +int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { deflate_state *s; uInt str, n; int wrap; @@ -478,11 +613,8 @@ int ZEXPORT deflateSetDictionary(strm, dictionary, dictLength) } /* ========================================================================= */ -int ZEXPORT deflateGetDictionary(strm, dictionary, dictLength) - z_streamp strm; - Bytef *dictionary; - uInt *dictLength; -{ +int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { deflate_state *s; uInt len; @@ -500,9 +632,7 @@ int ZEXPORT deflateGetDictionary(strm, dictionary, dictLength) } /* ========================================================================= */ -int ZEXPORT deflateResetKeep(strm) - z_streamp strm; -{ +int ZEXPORT deflateResetKeep(z_streamp strm) { deflate_state *s; if (deflateStateCheck(strm)) { @@ -537,10 +667,32 @@ int ZEXPORT deflateResetKeep(strm) return Z_OK; } +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init(deflate_state *s) { + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->insert = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +} + /* ========================================================================= */ -int ZEXPORT deflateReset(strm) - z_streamp strm; -{ +int ZEXPORT deflateReset(z_streamp strm) { int ret; ret = deflateResetKeep(strm); @@ -550,10 +702,7 @@ int ZEXPORT deflateReset(strm) } /* ========================================================================= */ -int ZEXPORT deflateSetHeader(strm, head) - z_streamp strm; - gz_headerp head; -{ +int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { if (deflateStateCheck(strm) || strm->state->wrap != 2) return Z_STREAM_ERROR; strm->state->gzhead = head; @@ -561,11 +710,7 @@ int ZEXPORT deflateSetHeader(strm, head) } /* ========================================================================= */ -int ZEXPORT deflatePending(strm, pending, bits) - unsigned *pending; - int *bits; - z_streamp strm; -{ +int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (pending != Z_NULL) *pending = strm->state->pending; @@ -575,19 +720,21 @@ int ZEXPORT deflatePending(strm, pending, bits) } /* ========================================================================= */ -int ZEXPORT deflatePrime(strm, bits, value) - z_streamp strm; - int bits; - int value; -{ +int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { deflate_state *s; int put; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; s = strm->state; +#ifdef LIT_MEM + if (bits < 0 || bits > 16 || + (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3)) + return Z_BUF_ERROR; +#else if (bits < 0 || bits > 16 || s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) return Z_BUF_ERROR; +#endif do { put = Buf_size - s->bi_valid; if (put > bits) @@ -602,11 +749,7 @@ int ZEXPORT deflatePrime(strm, bits, value) } /* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ +int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { deflate_state *s; compress_func func; @@ -651,13 +794,8 @@ int ZEXPORT deflateParams(strm, level, strategy) } /* ========================================================================= */ -int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) - z_streamp strm; - int good_length; - int max_lazy; - int nice_length; - int max_chain; -{ +int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain) { deflate_state *s; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -693,10 +831,7 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) * * Shifts are used to approximate divisions, for speed. */ -uLong ZEXPORT deflateBound(strm, sourceLen) - z_streamp strm; - uLong sourceLen; -{ +uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { deflate_state *s; uLong fixedlen, storelen, wraplen; @@ -752,7 +887,8 @@ uLong ZEXPORT deflateBound(strm, sourceLen) /* if not default parameters, return one of the conservative bounds */ if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen; + return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + + wraplen; /* default settings: return tight bound for that case -- ~0.03% overhead plus a small constant */ @@ -765,10 +901,7 @@ uLong ZEXPORT deflateBound(strm, sourceLen) * IN assertion: the stream state is correct and there is enough room in * pending_buf. */ -local void putShortMSB(s, b) - deflate_state *s; - uInt b; -{ +local void putShortMSB(deflate_state *s, uInt b) { put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b & 0xff)); } @@ -779,9 +912,7 @@ local void putShortMSB(s, b) * applications may wish to modify it to avoid allocating a large * strm->next_out buffer and copying into it. (See also read_buf()). */ -local void flush_pending(strm) - z_streamp strm; -{ +local void flush_pending(z_streamp strm) { unsigned len; deflate_state *s = strm->state; @@ -812,10 +943,7 @@ local void flush_pending(strm) } while (0) /* ========================================================================= */ -int ZEXPORT deflate(strm, flush) - z_streamp strm; - int flush; -{ +int ZEXPORT deflate(z_streamp strm, int flush) { int old_flush; /* value of flush param for previous deflate call */ deflate_state *s; @@ -1127,9 +1255,7 @@ int ZEXPORT deflate(strm, flush) } /* ========================================================================= */ -int ZEXPORT deflateEnd(strm) - z_streamp strm; -{ +int ZEXPORT deflateEnd(z_streamp strm) { int status; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1153,11 +1279,10 @@ int ZEXPORT deflateEnd(strm) * To simplify the source, this is not supported for 16-bit MSDOS (which * doesn't have enough memory anyway to duplicate compression states). */ -int ZEXPORT deflateCopy(dest, source) - z_streamp dest; - z_streamp source; -{ +int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { #ifdef MAXSEG_64K + (void)dest; + (void)source; return Z_STREAM_ERROR; #else deflate_state *ds; @@ -1181,7 +1306,7 @@ int ZEXPORT deflateCopy(dest, source) ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS); if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || ds->pending_buf == Z_NULL) { @@ -1192,10 +1317,15 @@ int ZEXPORT deflateCopy(dest, source) zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); +#ifdef LIT_MEM + ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1)); + ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2); +#else ds->sym_buf = ds->pending_buf + ds->lit_bufsize; +#endif ds->l_desc.dyn_tree = ds->dyn_ltree; ds->d_desc.dyn_tree = ds->dyn_dtree; @@ -1205,66 +1335,6 @@ int ZEXPORT deflateCopy(dest, source) #endif /* MAXSEG_64K */ } -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local unsigned read_buf(strm, buf, size) - z_streamp strm; - Bytef *buf; - unsigned size; -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init(s) - deflate_state *s; -{ - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -} - #ifndef FASTEST /* =========================================================================== * Set match_start to the longest match starting at the given string and @@ -1275,10 +1345,7 @@ local void lm_init(s) * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * OUT assertion: the match length is not greater than s->lookahead. */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { unsigned chain_length = s->max_chain_length;/* max hash chain length */ register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ @@ -1426,10 +1493,7 @@ local uInt longest_match(s, cur_match) /* --------------------------------------------------------------------------- * Optimized version for FASTEST only */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { register Bytef *scan = s->window + s->strstart; /* current string */ register Bytef *match; /* matched string */ register int len; /* length of current match */ @@ -1490,19 +1554,23 @@ local uInt longest_match(s, cur_match) /* =========================================================================== * Check that the match at match_start is indeed a match. */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ +local void check_match(deflate_state *s, IPos start, IPos match, int length) { /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); + Bytef *back = s->window + (int)match, *here = s->window + start; + IPos len = length; + if (match == (IPos)-1) { + /* match starts one byte before the current window -- just compare the + subsequent length-1 bytes */ + back++; + here++; + len--; + } + if (zmemcmp(back, here, len) != EQUAL) { + fprintf(stderr, " start %u, match %d, length %d\n", + start, (int)match, length); do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); + fprintf(stderr, "(%02x %02x)", *back++, *here++); + } while (--len != 0); z_error("invalid match"); } if (z_verbose > 1) { @@ -1514,137 +1582,6 @@ local void check_match(s, start, match, length) # define check_match(s, start, match, length) #endif /* ZLIB_DEBUG */ -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(s) - deflate_state *s; -{ - unsigned n; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize + MAX_DIST(s)) { - - zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - if (s->insert > s->strstart) - s->insert = s->strstart; - slide_hash(s); - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - /* =========================================================================== * Flush the current block, with given end-of-file flag. * IN assertion: strstart is set to the end of the current match. @@ -1687,10 +1624,7 @@ local void fill_window(s) * copied. It is most efficient with large input and output buffers, which * maximizes the opportunities to have a single copy from next_in to next_out. */ -local block_state deflate_stored(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_stored(deflate_state *s, int flush) { /* Smallest worthy block size when not flushing or finishing. By default * this is 32K. This can be as small as 507 bytes for memLevel == 1. For * large input and output buffers, the stored block size will be larger. @@ -1874,10 +1808,7 @@ local block_state deflate_stored(s, flush) * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */ -local block_state deflate_fast(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_fast(deflate_state *s, int flush) { IPos hash_head; /* head of the hash chain */ int bflush; /* set if current block must be flushed */ @@ -1976,10 +1907,7 @@ local block_state deflate_fast(s, flush) * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */ -local block_state deflate_slow(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_slow(deflate_state *s, int flush) { IPos hash_head; /* head of hash chain */ int bflush; /* set if current block must be flushed */ @@ -2107,10 +2035,7 @@ local block_state deflate_slow(s, flush) * one. Do not maintain a hash table. (It will be regenerated if this run of * deflate switches away from Z_RLE.) */ -local block_state deflate_rle(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_rle(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ uInt prev; /* byte at distance one to match */ Bytef *scan, *strend; /* scan goes up to strend for length of run */ @@ -2181,10 +2106,7 @@ local block_state deflate_rle(s, flush) * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. * (It will be regenerated if this run of deflate switches away from Huffman.) */ -local block_state deflate_huff(s, flush) - deflate_state *s; - int flush; -{ +local block_state deflate_huff(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ for (;;) { diff --git a/libs/ext/zlib/deflate.h b/libs/ext/zlib/deflate.h index 1a06cd5f2..300c6ada6 100644 --- a/libs/ext/zlib/deflate.h +++ b/libs/ext/zlib/deflate.h @@ -1,5 +1,5 @@ /* deflate.h -- internal compression state - * Copyright (C) 1995-2018 Jean-loup Gailly + * Copyright (C) 1995-2024 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -23,6 +23,10 @@ # define GZIP #endif +/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at + the cost of a larger memory footprint */ +/* #define LIT_MEM */ + /* =========================================================================== * Internal compression state. */ @@ -217,7 +221,14 @@ typedef struct internal_state { /* Depth of each subtree used as tie breaker for trees of equal frequency */ +#ifdef LIT_MEM +# define LIT_BUFS 5 + ushf *d_buf; /* buffer for distances */ + uchf *l_buf; /* buffer for literals/lengths */ +#else +# define LIT_BUFS 4 uchf *sym_buf; /* buffer for distances and literals/lengths */ +#endif uInt lit_bufsize; /* Size of match buffer for literals/lengths. There are 4 reasons for @@ -239,7 +250,7 @@ typedef struct internal_state { * - I can't count above 4 */ - uInt sym_next; /* running index in sym_buf */ + uInt sym_next; /* running index in symbol buffer */ uInt sym_end; /* symbol table full when sym_next reaches this */ ulg opt_len; /* bit length of current block with optimal trees */ @@ -291,14 +302,14 @@ typedef struct internal_state { memory checker errors from longest match routines */ /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); +void ZLIB_INTERNAL _tr_init(deflate_state *s); +int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc); +void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, + ulg stored_len, int last); +void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s); +void ZLIB_INTERNAL _tr_align(deflate_state *s); +void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last); #define d_code(dist) \ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) @@ -318,6 +329,25 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, extern const uch ZLIB_INTERNAL _dist_code[]; #endif +#ifdef LIT_MEM +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->sym_next] = 0; \ + s->l_buf[s->sym_next++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (uch)(length); \ + ush dist = (ush)(distance); \ + s->d_buf[s->sym_next] = dist; \ + s->l_buf[s->sym_next++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +#else # define _tr_tally_lit(s, c, flush) \ { uch cc = (c); \ s->sym_buf[s->sym_next++] = 0; \ @@ -337,6 +367,7 @@ void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, s->dyn_dtree[d_code(dist)].Freq++; \ flush = (s->sym_next == s->sym_end); \ } +#endif #else # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_dist(s, distance, length, flush) \ diff --git a/libs/ext/zlib/gzclose.c b/libs/ext/zlib/gzclose.c index caeb99a31..48d6a86f0 100644 --- a/libs/ext/zlib/gzclose.c +++ b/libs/ext/zlib/gzclose.c @@ -8,9 +8,7 @@ /* gzclose() is in a separate file so that it is linked in only if it is used. That way the other gzclose functions can be used instead to avoid linking in unneeded compression or decompression routines. */ -int ZEXPORT gzclose(file) - gzFile file; -{ +int ZEXPORT gzclose(gzFile file) { #ifndef NO_GZCOMPRESS gz_statep state; diff --git a/libs/ext/zlib/gzguts.h b/libs/ext/zlib/gzguts.h index 57faf3716..eba72085b 100644 --- a/libs/ext/zlib/gzguts.h +++ b/libs/ext/zlib/gzguts.h @@ -1,5 +1,5 @@ /* gzguts.h -- zlib internal header definitions for gz* operations - * Copyright (C) 2004-2019 Mark Adler + * Copyright (C) 2004-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -7,9 +7,8 @@ # ifndef _LARGEFILE_SOURCE # define _LARGEFILE_SOURCE 1 # endif -# ifdef _FILE_OFFSET_BITS -# undef _FILE_OFFSET_BITS -# endif +# undef _FILE_OFFSET_BITS +# undef _TIME_BITS #endif #ifdef HAVE_HIDDEN @@ -119,8 +118,8 @@ /* gz* functions always use library allocation functions */ #ifndef STDC - extern voidp malloc OF((uInt size)); - extern void free OF((voidpf ptr)); + extern voidp malloc(uInt size); + extern void free(voidpf ptr); #endif /* get errno and strerror definition */ @@ -138,10 +137,10 @@ /* provide prototypes for these when building zlib without LFS */ #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); #endif /* default memLevel */ @@ -203,17 +202,13 @@ typedef struct { typedef gz_state FAR *gz_statep; /* shared functions */ -void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); +void ZLIB_INTERNAL gz_error(gz_statep, int, const char *); #if defined UNDER_CE -char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); +char ZLIB_INTERNAL *gz_strwinerror(DWORD error); #endif /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t value -- needed when comparing unsigned to z_off64_t, which is signed (possible z_off64_t types off_t, off64_t, and long are all signed) */ -#ifdef INT_MAX -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) -#else -unsigned ZLIB_INTERNAL gz_intmax OF((void)); -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) -#endif +unsigned ZLIB_INTERNAL gz_intmax(void); +#define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) diff --git a/libs/ext/zlib/gzlib.c b/libs/ext/zlib/gzlib.c index 55da46a45..983153cc8 100644 --- a/libs/ext/zlib/gzlib.c +++ b/libs/ext/zlib/gzlib.c @@ -1,5 +1,5 @@ /* gzlib.c -- zlib functions common to reading and writing gzip files - * Copyright (C) 2004-2019 Mark Adler + * Copyright (C) 2004-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -15,10 +15,6 @@ #endif #endif -/* Local functions */ -local void gz_reset OF((gz_statep)); -local gzFile gz_open OF((const void *, int, const char *)); - #if defined UNDER_CE /* Map the Windows error number in ERROR to a locale-dependent error message @@ -30,9 +26,7 @@ local gzFile gz_open OF((const void *, int, const char *)); The gz_strwinerror function does not change the current setting of GetLastError. */ -char ZLIB_INTERNAL *gz_strwinerror(error) - DWORD error; -{ +char ZLIB_INTERNAL *gz_strwinerror(DWORD error) { static char buf[1024]; wchar_t *msgbuf; @@ -72,9 +66,7 @@ char ZLIB_INTERNAL *gz_strwinerror(error) #endif /* UNDER_CE */ /* Reset gzip file state */ -local void gz_reset(state) - gz_statep state; -{ +local void gz_reset(gz_statep state) { state->x.have = 0; /* no output data available */ if (state->mode == GZ_READ) { /* for reading ... */ state->eof = 0; /* not at end of file */ @@ -90,11 +82,7 @@ local void gz_reset(state) } /* Open a gzip file either by name or file descriptor. */ -local gzFile gz_open(path, fd, mode) - const void *path; - int fd; - const char *mode; -{ +local gzFile gz_open(const void *path, int fd, const char *mode) { gz_statep state; z_size_t len; int oflag; @@ -269,26 +257,17 @@ local gzFile gz_open(path, fd, mode) } /* -- see zlib.h -- */ -gzFile ZEXPORT gzopen(path, mode) - const char *path; - const char *mode; -{ +gzFile ZEXPORT gzopen(const char *path, const char *mode) { return gz_open(path, -1, mode); } /* -- see zlib.h -- */ -gzFile ZEXPORT gzopen64(path, mode) - const char *path; - const char *mode; -{ +gzFile ZEXPORT gzopen64(const char *path, const char *mode) { return gz_open(path, -1, mode); } /* -- see zlib.h -- */ -gzFile ZEXPORT gzdopen(fd, mode) - int fd; - const char *mode; -{ +gzFile ZEXPORT gzdopen(int fd, const char *mode) { char *path; /* identifier for error messages */ gzFile gz; @@ -306,19 +285,13 @@ gzFile ZEXPORT gzdopen(fd, mode) /* -- see zlib.h -- */ #ifdef WIDECHAR -gzFile ZEXPORT gzopen_w(path, mode) - const wchar_t *path; - const char *mode; -{ +gzFile ZEXPORT gzopen_w(const wchar_t *path, const char *mode) { return gz_open(path, -2, mode); } #endif /* -- see zlib.h -- */ -int ZEXPORT gzbuffer(file, size) - gzFile file; - unsigned size; -{ +int ZEXPORT gzbuffer(gzFile file, unsigned size) { gz_statep state; /* get internal structure and check integrity */ @@ -335,16 +308,14 @@ int ZEXPORT gzbuffer(file, size) /* check and set requested size */ if ((size << 1) < size) return -1; /* need to be able to double it */ - if (size < 2) - size = 2; /* need two bytes to check magic header */ + if (size < 8) + size = 8; /* needed to behave well with flushing */ state->want = size; return 0; } /* -- see zlib.h -- */ -int ZEXPORT gzrewind(file) - gzFile file; -{ +int ZEXPORT gzrewind(gzFile file) { gz_statep state; /* get internal structure */ @@ -365,11 +336,7 @@ int ZEXPORT gzrewind(file) } /* -- see zlib.h -- */ -z_off64_t ZEXPORT gzseek64(file, offset, whence) - gzFile file; - z_off64_t offset; - int whence; -{ +z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) { unsigned n; z_off64_t ret; gz_statep state; @@ -442,11 +409,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence) } /* -- see zlib.h -- */ -z_off_t ZEXPORT gzseek(file, offset, whence) - gzFile file; - z_off_t offset; - int whence; -{ +z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence) { z_off64_t ret; ret = gzseek64(file, (z_off64_t)offset, whence); @@ -454,9 +417,7 @@ z_off_t ZEXPORT gzseek(file, offset, whence) } /* -- see zlib.h -- */ -z_off64_t ZEXPORT gztell64(file) - gzFile file; -{ +z_off64_t ZEXPORT gztell64(gzFile file) { gz_statep state; /* get internal structure and check integrity */ @@ -471,9 +432,7 @@ z_off64_t ZEXPORT gztell64(file) } /* -- see zlib.h -- */ -z_off_t ZEXPORT gztell(file) - gzFile file; -{ +z_off_t ZEXPORT gztell(gzFile file) { z_off64_t ret; ret = gztell64(file); @@ -481,9 +440,7 @@ z_off_t ZEXPORT gztell(file) } /* -- see zlib.h -- */ -z_off64_t ZEXPORT gzoffset64(file) - gzFile file; -{ +z_off64_t ZEXPORT gzoffset64(gzFile file) { z_off64_t offset; gz_statep state; @@ -504,9 +461,7 @@ z_off64_t ZEXPORT gzoffset64(file) } /* -- see zlib.h -- */ -z_off_t ZEXPORT gzoffset(file) - gzFile file; -{ +z_off_t ZEXPORT gzoffset(gzFile file) { z_off64_t ret; ret = gzoffset64(file); @@ -514,9 +469,7 @@ z_off_t ZEXPORT gzoffset(file) } /* -- see zlib.h -- */ -int ZEXPORT gzeof(file) - gzFile file; -{ +int ZEXPORT gzeof(gzFile file) { gz_statep state; /* get internal structure and check integrity */ @@ -531,10 +484,7 @@ int ZEXPORT gzeof(file) } /* -- see zlib.h -- */ -const char * ZEXPORT gzerror(file, errnum) - gzFile file; - int *errnum; -{ +const char * ZEXPORT gzerror(gzFile file, int *errnum) { gz_statep state; /* get internal structure and check integrity */ @@ -552,9 +502,7 @@ const char * ZEXPORT gzerror(file, errnum) } /* -- see zlib.h -- */ -void ZEXPORT gzclearerr(file) - gzFile file; -{ +void ZEXPORT gzclearerr(gzFile file) { gz_statep state; /* get internal structure and check integrity */ @@ -578,11 +526,7 @@ void ZEXPORT gzclearerr(file) memory). Simply save the error message as a static string. If there is an allocation failure constructing the error message, then convert the error to out of memory. */ -void ZLIB_INTERNAL gz_error(state, err, msg) - gz_statep state; - int err; - const char *msg; -{ +void ZLIB_INTERNAL gz_error(gz_statep state, int err, const char *msg) { /* free previously allocated message and clear */ if (state->msg != NULL) { if (state->err != Z_MEM_ERROR) @@ -619,21 +563,20 @@ void ZLIB_INTERNAL gz_error(state, err, msg) #endif } -#ifndef INT_MAX /* portably return maximum value for an int (when limits.h presumed not available) -- we need to do this to cover cases where 2's complement not used, since C standard permits 1's complement and sign-bit representations, otherwise we could just use ((unsigned)-1) >> 1 */ -unsigned ZLIB_INTERNAL gz_intmax() -{ - unsigned p, q; - - p = 1; +unsigned ZLIB_INTERNAL gz_intmax(void) { +#ifdef INT_MAX + return INT_MAX; +#else + unsigned p = 1, q; do { q = p; p <<= 1; p++; } while (p > q); return q >> 1; -} #endif +} diff --git a/libs/ext/zlib/gzread.c b/libs/ext/zlib/gzread.c index dd7738159..4168cbc88 100644 --- a/libs/ext/zlib/gzread.c +++ b/libs/ext/zlib/gzread.c @@ -5,25 +5,12 @@ #include "gzguts.h" -/* Local functions */ -local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); -local int gz_avail OF((gz_statep)); -local int gz_look OF((gz_statep)); -local int gz_decomp OF((gz_statep)); -local int gz_fetch OF((gz_statep)); -local int gz_skip OF((gz_statep, z_off64_t)); -local z_size_t gz_read OF((gz_statep, voidp, z_size_t)); - /* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from state->fd, and update state->eof, state->err, and state->msg as appropriate. This function needs to loop on read(), since read() is not guaranteed to read the number of bytes requested, depending on the type of descriptor. */ -local int gz_load(state, buf, len, have) - gz_statep state; - unsigned char *buf; - unsigned len; - unsigned *have; -{ +local int gz_load(gz_statep state, unsigned char *buf, unsigned len, + unsigned *have) { int ret; unsigned get, max = ((unsigned)-1 >> 2) + 1; @@ -53,9 +40,7 @@ local int gz_load(state, buf, len, have) If strm->avail_in != 0, then the current data is moved to the beginning of the input buffer, and then the remainder of the buffer is loaded with the available data from the input file. */ -local int gz_avail(state) - gz_statep state; -{ +local int gz_avail(gz_statep state) { unsigned got; z_streamp strm = &(state->strm); @@ -88,9 +73,7 @@ local int gz_avail(state) case, all further file reads will be directly to either the output buffer or a user buffer. If decompressing, the inflate state will be initialized. gz_look() will return 0 on success or -1 on failure. */ -local int gz_look(state) - gz_statep state; -{ +local int gz_look(gz_statep state) { z_streamp strm = &(state->strm); /* allocate read buffers and inflate memory */ @@ -170,9 +153,7 @@ local int gz_look(state) data. If the gzip stream completes, state->how is reset to LOOK to look for the next gzip stream or raw data, once state->x.have is depleted. Returns 0 on success, -1 on failure. */ -local int gz_decomp(state) - gz_statep state; -{ +local int gz_decomp(gz_statep state) { int ret = Z_OK; unsigned had; z_streamp strm = &(state->strm); @@ -224,9 +205,7 @@ local int gz_decomp(state) looked for to determine whether to copy or decompress. Returns -1 on error, otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the end of the input file has been reached and all data has been processed. */ -local int gz_fetch(state) - gz_statep state; -{ +local int gz_fetch(gz_statep state) { z_streamp strm = &(state->strm); do { @@ -254,10 +233,7 @@ local int gz_fetch(state) } /* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ -local int gz_skip(state, len) - gz_statep state; - z_off64_t len; -{ +local int gz_skip(gz_statep state, z_off64_t len) { unsigned n; /* skip over len bytes or reach end-of-file, whichever comes first */ @@ -289,11 +265,7 @@ local int gz_skip(state, len) input. Return the number of bytes read. If zero is returned, either the end of file was reached, or there was an error. state->err must be consulted in that case to determine which. */ -local z_size_t gz_read(state, buf, len) - gz_statep state; - voidp buf; - z_size_t len; -{ +local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) { z_size_t got; unsigned n; @@ -370,11 +342,7 @@ local z_size_t gz_read(state, buf, len) } /* -- see zlib.h -- */ -int ZEXPORT gzread(file, buf, len) - gzFile file; - voidp buf; - unsigned len; -{ +int ZEXPORT gzread(gzFile file, voidp buf, unsigned len) { gz_statep state; /* get internal structure */ @@ -406,12 +374,7 @@ int ZEXPORT gzread(file, buf, len) } /* -- see zlib.h -- */ -z_size_t ZEXPORT gzfread(buf, size, nitems, file) - voidp buf; - z_size_t size; - z_size_t nitems; - gzFile file; -{ +z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, gzFile file) { z_size_t len; gz_statep state; @@ -442,9 +405,7 @@ z_size_t ZEXPORT gzfread(buf, size, nitems, file) #else # undef gzgetc #endif -int ZEXPORT gzgetc(file) - gzFile file; -{ +int ZEXPORT gzgetc(gzFile file) { unsigned char buf[1]; gz_statep state; @@ -469,17 +430,12 @@ int ZEXPORT gzgetc(file) return gz_read(state, buf, 1) < 1 ? -1 : buf[0]; } -int ZEXPORT gzgetc_(file) -gzFile file; -{ +int ZEXPORT gzgetc_(gzFile file) { return gzgetc(file); } /* -- see zlib.h -- */ -int ZEXPORT gzungetc(c, file) - int c; - gzFile file; -{ +int ZEXPORT gzungetc(int c, gzFile file) { gz_statep state; /* get internal structure */ @@ -487,6 +443,10 @@ int ZEXPORT gzungetc(c, file) return -1; state = (gz_statep)file; + /* in case this was just opened, set up the input buffer */ + if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) + (void)gz_look(state); + /* check that we're reading and that there's no (serious) error */ if (state->mode != GZ_READ || (state->err != Z_OK && state->err != Z_BUF_ERROR)) @@ -536,11 +496,7 @@ int ZEXPORT gzungetc(c, file) } /* -- see zlib.h -- */ -char * ZEXPORT gzgets(file, buf, len) - gzFile file; - char *buf; - int len; -{ +char * ZEXPORT gzgets(gzFile file, char *buf, int len) { unsigned left, n; char *str; unsigned char *eol; @@ -600,9 +556,7 @@ char * ZEXPORT gzgets(file, buf, len) } /* -- see zlib.h -- */ -int ZEXPORT gzdirect(file) - gzFile file; -{ +int ZEXPORT gzdirect(gzFile file) { gz_statep state; /* get internal structure */ @@ -620,9 +574,7 @@ int ZEXPORT gzdirect(file) } /* -- see zlib.h -- */ -int ZEXPORT gzclose_r(file) - gzFile file; -{ +int ZEXPORT gzclose_r(gzFile file) { int ret, err; gz_statep state; diff --git a/libs/ext/zlib/gzwrite.c b/libs/ext/zlib/gzwrite.c index eb8a0e589..435b4621b 100644 --- a/libs/ext/zlib/gzwrite.c +++ b/libs/ext/zlib/gzwrite.c @@ -5,18 +5,10 @@ #include "gzguts.h" -/* Local functions */ -local int gz_init OF((gz_statep)); -local int gz_comp OF((gz_statep, int)); -local int gz_zero OF((gz_statep, z_off64_t)); -local z_size_t gz_write OF((gz_statep, voidpc, z_size_t)); - /* Initialize state for writing a gzip file. Mark initialization by setting state->size to non-zero. Return -1 on a memory allocation failure, or 0 on success. */ -local int gz_init(state) - gz_statep state; -{ +local int gz_init(gz_statep state) { int ret; z_streamp strm = &(state->strm); @@ -70,10 +62,7 @@ local int gz_init(state) deflate() flush value. If flush is Z_FINISH, then the deflate() state is reset to start a new gzip stream. If gz->direct is true, then simply write to the output file without compressing, and ignore flush. */ -local int gz_comp(state, flush) - gz_statep state; - int flush; -{ +local int gz_comp(gz_statep state, int flush) { int ret, writ; unsigned have, put, max = ((unsigned)-1 >> 2) + 1; z_streamp strm = &(state->strm); @@ -151,10 +140,7 @@ local int gz_comp(state, flush) /* Compress len zeros to output. Return -1 on a write error or memory allocation failure by gz_comp(), or 0 on success. */ -local int gz_zero(state, len) - gz_statep state; - z_off64_t len; -{ +local int gz_zero(gz_statep state, z_off64_t len) { int first; unsigned n; z_streamp strm = &(state->strm); @@ -184,11 +170,7 @@ local int gz_zero(state, len) /* Write len bytes from buf to file. Return the number of bytes written. If the returned value is less than len, then there was an error. */ -local z_size_t gz_write(state, buf, len) - gz_statep state; - voidpc buf; - z_size_t len; -{ +local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) { z_size_t put = len; /* if len is zero, avoid unnecessary operations */ @@ -252,11 +234,7 @@ local z_size_t gz_write(state, buf, len) } /* -- see zlib.h -- */ -int ZEXPORT gzwrite(file, buf, len) - gzFile file; - voidpc buf; - unsigned len; -{ +int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len) { gz_statep state; /* get internal structure */ @@ -280,12 +258,8 @@ int ZEXPORT gzwrite(file, buf, len) } /* -- see zlib.h -- */ -z_size_t ZEXPORT gzfwrite(buf, size, nitems, file) - voidpc buf; - z_size_t size; - z_size_t nitems; - gzFile file; -{ +z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, z_size_t nitems, + gzFile file) { z_size_t len; gz_statep state; @@ -310,10 +284,7 @@ z_size_t ZEXPORT gzfwrite(buf, size, nitems, file) } /* -- see zlib.h -- */ -int ZEXPORT gzputc(file, c) - gzFile file; - int c; -{ +int ZEXPORT gzputc(gzFile file, int c) { unsigned have; unsigned char buf[1]; gz_statep state; @@ -358,10 +329,7 @@ int ZEXPORT gzputc(file, c) } /* -- see zlib.h -- */ -int ZEXPORT gzputs(file, s) - gzFile file; - const char *s; -{ +int ZEXPORT gzputs(gzFile file, const char *s) { z_size_t len, put; gz_statep state; @@ -388,8 +356,7 @@ int ZEXPORT gzputs(file, s) #include /* -- see zlib.h -- */ -int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) -{ +int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) { int len; unsigned left; char *next; @@ -460,8 +427,7 @@ int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) return len; } -int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) -{ +int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) { va_list va; int ret; @@ -474,13 +440,10 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) #else /* !STDC && !Z_HAVE_STDARG_H */ /* -- see zlib.h -- */ -int ZEXPORTVA gzprintf(file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) - gzFile file; - const char *format; - int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; -{ +int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, + int a4, int a5, int a6, int a7, int a8, int a9, int a10, + int a11, int a12, int a13, int a14, int a15, int a16, + int a17, int a18, int a19, int a20) { unsigned len, left; char *next; gz_statep state; @@ -562,10 +525,7 @@ int ZEXPORTVA gzprintf(file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, #endif /* -- see zlib.h -- */ -int ZEXPORT gzflush(file, flush) - gzFile file; - int flush; -{ +int ZEXPORT gzflush(gzFile file, int flush) { gz_statep state; /* get internal structure */ @@ -594,11 +554,7 @@ int ZEXPORT gzflush(file, flush) } /* -- see zlib.h -- */ -int ZEXPORT gzsetparams(file, level, strategy) - gzFile file; - int level; - int strategy; -{ +int ZEXPORT gzsetparams(gzFile file, int level, int strategy) { gz_statep state; z_streamp strm; @@ -609,7 +565,7 @@ int ZEXPORT gzsetparams(file, level, strategy) strm = &(state->strm); /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) + if (state->mode != GZ_WRITE || state->err != Z_OK || state->direct) return Z_STREAM_ERROR; /* if no change is requested, then do nothing */ @@ -636,9 +592,7 @@ int ZEXPORT gzsetparams(file, level, strategy) } /* -- see zlib.h -- */ -int ZEXPORT gzclose_w(file) - gzFile file; -{ +int ZEXPORT gzclose_w(gzFile file) { int ret = Z_OK; gz_statep state; diff --git a/libs/ext/zlib/infback.c b/libs/ext/zlib/infback.c index babeaf180..e7b25b307 100644 --- a/libs/ext/zlib/infback.c +++ b/libs/ext/zlib/infback.c @@ -15,9 +15,6 @@ #include "inflate.h" #include "inffast.h" -/* function prototypes */ -local void fixedtables OF((struct inflate_state FAR *state)); - /* strm provides memory allocation functions in zalloc and zfree, or Z_NULL to use the library memory allocation functions. @@ -25,13 +22,9 @@ local void fixedtables OF((struct inflate_state FAR *state)); windowBits is in the range 8..15, and window is a user-supplied window and output buffer that is 2**windowBits bytes. */ -int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) -z_streamp strm; -int windowBits; -unsigned char FAR *window; -const char *version; -int stream_size; -{ +int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, + unsigned char FAR *window, const char *version, + int stream_size) { struct inflate_state FAR *state; if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || @@ -80,9 +73,7 @@ int stream_size; used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ +local void fixedtables(struct inflate_state FAR *state) { #ifdef BUILDFIXED static int virgin = 1; static code *lenfix, *distfix; @@ -248,13 +239,8 @@ struct inflate_state FAR *state; inflateBack() can also return Z_STREAM_ERROR if the input parameters are not correct, i.e. strm is Z_NULL or the state was not initialized. */ -int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) -z_streamp strm; -in_func in; -void FAR *in_desc; -out_func out; -void FAR *out_desc; -{ +int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ @@ -632,9 +618,7 @@ void FAR *out_desc; return ret; } -int ZEXPORT inflateBackEnd(strm) -z_streamp strm; -{ +int ZEXPORT inflateBackEnd(z_streamp strm) { if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) return Z_STREAM_ERROR; ZFREE(strm, strm->state); diff --git a/libs/ext/zlib/inffast.c b/libs/ext/zlib/inffast.c index 1fec7f363..9354676e7 100644 --- a/libs/ext/zlib/inffast.c +++ b/libs/ext/zlib/inffast.c @@ -47,10 +47,7 @@ requires strm->avail_out >= 258 for each loop to avoid checking for output space. */ -void ZLIB_INTERNAL inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ -{ +void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { struct inflate_state FAR *state; z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *last; /* have enough input while in < last */ diff --git a/libs/ext/zlib/inffast.h b/libs/ext/zlib/inffast.h index e5c1aa4ca..49c6d156c 100644 --- a/libs/ext/zlib/inffast.h +++ b/libs/ext/zlib/inffast.h @@ -8,4 +8,4 @@ subject to change. Applications should only use zlib.h. */ -void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); +void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start); diff --git a/libs/ext/zlib/inflate.c b/libs/ext/zlib/inflate.c index 8acbef44e..94ecff015 100644 --- a/libs/ext/zlib/inflate.c +++ b/libs/ext/zlib/inflate.c @@ -91,20 +91,7 @@ # endif #endif -/* function prototypes */ -local int inflateStateCheck OF((z_streamp strm)); -local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, - unsigned copy)); -#ifdef BUILDFIXED - void makefixed OF((void)); -#endif -local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, - unsigned len)); - -local int inflateStateCheck(strm) -z_streamp strm; -{ +local int inflateStateCheck(z_streamp strm) { struct inflate_state FAR *state; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -116,9 +103,7 @@ z_streamp strm; return 0; } -int ZEXPORT inflateResetKeep(strm) -z_streamp strm; -{ +int ZEXPORT inflateResetKeep(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -142,9 +127,7 @@ z_streamp strm; return Z_OK; } -int ZEXPORT inflateReset(strm) -z_streamp strm; -{ +int ZEXPORT inflateReset(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -155,10 +138,7 @@ z_streamp strm; return inflateResetKeep(strm); } -int ZEXPORT inflateReset2(strm, windowBits) -z_streamp strm; -int windowBits; -{ +int ZEXPORT inflateReset2(z_streamp strm, int windowBits) { int wrap; struct inflate_state FAR *state; @@ -195,12 +175,8 @@ int windowBits; return inflateReset(strm); } -int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) -z_streamp strm; -int windowBits; -const char *version; -int stream_size; -{ +int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size) { int ret; struct inflate_state FAR *state; @@ -239,22 +215,17 @@ int stream_size; return ret; } -int ZEXPORT inflateInit_(strm, version, stream_size) -z_streamp strm; -const char *version; -int stream_size; -{ +int ZEXPORT inflateInit_(z_streamp strm, const char *version, + int stream_size) { return inflateInit2_(strm, DEF_WBITS, version, stream_size); } -int ZEXPORT inflatePrime(strm, bits, value) -z_streamp strm; -int bits; -int value; -{ +int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits == 0) + return Z_OK; state = (struct inflate_state FAR *)strm->state; if (bits < 0) { state->hold = 0; @@ -278,9 +249,7 @@ int value; used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ +local void fixedtables(struct inflate_state FAR *state) { #ifdef BUILDFIXED static int virgin = 1; static code *lenfix, *distfix; @@ -342,7 +311,7 @@ struct inflate_state FAR *state; a.out > inffixed.h */ -void makefixed() +void makefixed(void) { unsigned low, size; struct inflate_state state; @@ -396,11 +365,7 @@ void makefixed() output will fall in the output data, making match copies simpler and faster. The advantage may be dependent on the size of the processor's data caches. */ -local int updatewindow(strm, end, copy) -z_streamp strm; -const Bytef *end; -unsigned copy; -{ +local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) { struct inflate_state FAR *state; unsigned dist; @@ -622,10 +587,7 @@ unsigned copy; will return Z_BUF_ERROR if it has not reached the end of the stream. */ -int ZEXPORT inflate(strm, flush) -z_streamp strm; -int flush; -{ +int ZEXPORT inflate(z_streamp strm, int flush) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ @@ -1301,9 +1263,7 @@ int flush; return ret; } -int ZEXPORT inflateEnd(strm) -z_streamp strm; -{ +int ZEXPORT inflateEnd(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1315,11 +1275,8 @@ z_streamp strm; return Z_OK; } -int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) -z_streamp strm; -Bytef *dictionary; -uInt *dictLength; -{ +int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { struct inflate_state FAR *state; /* check state */ @@ -1338,11 +1295,8 @@ uInt *dictLength; return Z_OK; } -int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) -z_streamp strm; -const Bytef *dictionary; -uInt dictLength; -{ +int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { struct inflate_state FAR *state; unsigned long dictid; int ret; @@ -1373,10 +1327,7 @@ uInt dictLength; return Z_OK; } -int ZEXPORT inflateGetHeader(strm, head) -z_streamp strm; -gz_headerp head; -{ +int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) { struct inflate_state FAR *state; /* check state */ @@ -1401,11 +1352,8 @@ gz_headerp head; called again with more data and the *have state. *have is initialized to zero for the first call. */ -local unsigned syncsearch(have, buf, len) -unsigned FAR *have; -const unsigned char FAR *buf; -unsigned len; -{ +local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, + unsigned len) { unsigned got; unsigned next; @@ -1424,9 +1372,7 @@ unsigned len; return next; } -int ZEXPORT inflateSync(strm) -z_streamp strm; -{ +int ZEXPORT inflateSync(z_streamp strm) { unsigned len; /* number of bytes to look at or looked at */ int flags; /* temporary to save header status */ unsigned long in, out; /* temporary to save total_in and total_out */ @@ -1441,7 +1387,7 @@ z_streamp strm; /* if first time, start search in bit buffer */ if (state->mode != SYNC) { state->mode = SYNC; - state->hold <<= state->bits & 7; + state->hold >>= state->bits & 7; state->bits -= state->bits & 7; len = 0; while (state->bits >= 8) { @@ -1482,9 +1428,7 @@ z_streamp strm; block. When decompressing, PPP checks that at the end of input packet, inflate is waiting for these length bytes. */ -int ZEXPORT inflateSyncPoint(strm) -z_streamp strm; -{ +int ZEXPORT inflateSyncPoint(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1492,10 +1436,7 @@ z_streamp strm; return state->mode == STORED && state->bits == 0; } -int ZEXPORT inflateCopy(dest, source) -z_streamp dest; -z_streamp source; -{ +int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { struct inflate_state FAR *state; struct inflate_state FAR *copy; unsigned char FAR *window; @@ -1539,10 +1480,7 @@ z_streamp source; return Z_OK; } -int ZEXPORT inflateUndermine(strm, subvert) -z_streamp strm; -int subvert; -{ +int ZEXPORT inflateUndermine(z_streamp strm, int subvert) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1557,10 +1495,7 @@ int subvert; #endif } -int ZEXPORT inflateValidate(strm, check) -z_streamp strm; -int check; -{ +int ZEXPORT inflateValidate(z_streamp strm, int check) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1572,9 +1507,7 @@ int check; return Z_OK; } -long ZEXPORT inflateMark(strm) -z_streamp strm; -{ +long ZEXPORT inflateMark(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) @@ -1585,9 +1518,7 @@ z_streamp strm; (state->mode == MATCH ? state->was - state->length : 0)); } -unsigned long ZEXPORT inflateCodesUsed(strm) -z_streamp strm; -{ +unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return (unsigned long)-1; state = (struct inflate_state FAR *)strm->state; diff --git a/libs/ext/zlib/inftrees.c b/libs/ext/zlib/inftrees.c index 57d2793be..98cfe1644 100644 --- a/libs/ext/zlib/inftrees.c +++ b/libs/ext/zlib/inftrees.c @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2022 Mark Adler + * Copyright (C) 1995-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.13 Copyright 1995-2022 Mark Adler "; + " inflate 1.3.1 Copyright 1995-2024 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -29,14 +29,9 @@ const char inflate_copyright[] = table index bits. It will differ if the request is greater than the longest code or if it is less than the shortest code. */ -int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) -codetype type; -unsigned short FAR *lens; -unsigned codes; -code FAR * FAR *table; -unsigned FAR *bits; -unsigned short FAR *work; -{ +int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work) { unsigned len; /* a code's length in bits */ unsigned sym; /* index of code symbols */ unsigned min, max; /* minimum and maximum code lengths */ @@ -62,7 +57,7 @@ unsigned short FAR *work; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 77}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff --git a/libs/ext/zlib/inftrees.h b/libs/ext/zlib/inftrees.h index f53665311..396f74b5d 100644 --- a/libs/ext/zlib/inftrees.h +++ b/libs/ext/zlib/inftrees.h @@ -41,8 +41,8 @@ typedef struct { examples/enough.c found in the zlib distribution. The arguments to that program are the number of symbols, the initial root table size, and the maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument of the + returns 852, and "enough 30 6 15" for distance codes returns 592. The + initial root table size (9 or 6) is found in the fifth argument of the inflate_table() calls in inflate.c and infback.c. If the root table size is changed, then these maximum sizes would be need to be recalculated and updated. */ @@ -57,6 +57,6 @@ typedef enum { DISTS } codetype; -int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); +int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work); diff --git a/libs/ext/zlib/trees.c b/libs/ext/zlib/trees.c index 5f305c472..6a523ef34 100644 --- a/libs/ext/zlib/trees.c +++ b/libs/ext/zlib/trees.c @@ -1,5 +1,5 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2021 Jean-loup Gailly + * Copyright (C) 1995-2024 Jean-loup Gailly * detect_data_type() function provided freely by Cosmin Truta, 2006 * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -122,39 +122,116 @@ struct static_tree_desc_s { int max_length; /* max bit length for the codes */ }; -local const static_tree_desc static_l_desc = +#ifdef NO_INIT_GLOBAL_POINTERS +# define TCONST +#else +# define TCONST const +#endif + +local TCONST static_tree_desc static_l_desc = {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; -local const static_tree_desc static_d_desc = +local TCONST static_tree_desc static_d_desc = {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; -local const static_tree_desc static_bl_desc = +local TCONST static_tree_desc static_bl_desc = {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; /* =========================================================================== - * Local (static) routines in this file. + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 */ +local unsigned bi_reverse(unsigned code, int len) { + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, const ct_data *ltree, - const ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned code, int len)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(deflate_state *s) { + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(deflate_state *s) { + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef ZLIB_DEBUG + s->bits_sent = (s->bits_sent + 7) & ~7; +#endif +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) { + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + unsigned code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + code = (code + bl_count[bits - 1]) << 1; + next_code[bits] = (ush)code; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, + "inconsistent bit counts"); + Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); + + for (n = 0; n <= max_code; n++) { + int len = tree[n].Len; + if (len == 0) continue; + /* Now reverse the bits */ + tree[n].Code = (ush)bi_reverse(next_code[len]++, len); + + Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", + n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1)); + } +} #ifdef GEN_TREES_H -local void gen_trees_header OF((void)); +local void gen_trees_header(void); #endif #ifndef ZLIB_DEBUG @@ -167,27 +244,12 @@ local void gen_trees_header OF((void)); send_bits(s, tree[c].Code, tree[c].Len); } #endif -/* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - /* =========================================================================== * Send a value on a given number of bits. * IN assertion: length <= 16 and value fits in length bits. */ #ifdef ZLIB_DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ +local void send_bits(deflate_state *s, int value, int length) { Tracevv((stderr," l %2d v %4x ", length, value)); Assert(length > 0 && length <= 15, "invalid length"); s->bits_sent += (ulg)length; @@ -229,8 +291,7 @@ local void send_bits(s, value, length) /* =========================================================================== * Initialize the various 'constant' tables. */ -local void tr_static_init() -{ +local void tr_static_init(void) { #if defined(GEN_TREES_H) || !defined(STDC) static int static_init_done = 0; int n; /* iterates over tree elements */ @@ -323,8 +384,7 @@ local void tr_static_init() ((i) == (last)? "\n};\n\n" : \ ((i) % (width) == (width) - 1 ? ",\n" : ", ")) -void gen_trees_header() -{ +void gen_trees_header(void) { FILE *header = fopen("trees.h", "w"); int i; @@ -373,12 +433,26 @@ void gen_trees_header() } #endif /* GEN_TREES_H */ +/* =========================================================================== + * Initialize a new block. + */ +local void init_block(deflate_state *s) { + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->sym_next = s->matches = 0; +} + /* =========================================================================== * Initialize the tree data structures for a new zlib stream. */ -void ZLIB_INTERNAL _tr_init(s) - deflate_state *s; -{ +void ZLIB_INTERNAL _tr_init(deflate_state *s) { tr_static_init(); s->l_desc.dyn_tree = s->dyn_ltree; @@ -401,24 +475,6 @@ void ZLIB_INTERNAL _tr_init(s) init_block(s); } -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(s) - deflate_state *s; -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->sym_next = s->matches = 0; -} - #define SMALLEST 1 /* Index within the heap array of least frequent node in the Huffman tree */ @@ -448,11 +504,7 @@ local void init_block(s) * when the heap property is re-established (each father smaller than its * two sons). */ -local void pqdownheap(s, tree, k) - deflate_state *s; - ct_data *tree; /* the tree to restore */ - int k; /* node to move down */ -{ +local void pqdownheap(deflate_state *s, ct_data *tree, int k) { int v = s->heap[k]; int j = k << 1; /* left son of k */ while (j <= s->heap_len) { @@ -483,10 +535,7 @@ local void pqdownheap(s, tree, k) * The length opt_len is updated; static_len is also updated if stree is * not null. */ -local void gen_bitlen(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ +local void gen_bitlen(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; int max_code = desc->max_code; const ct_data *stree = desc->stat_desc->static_tree; @@ -561,48 +610,9 @@ local void gen_bitlen(s, desc) } } -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes(tree, max_code, bl_count) - ct_data *tree; /* the tree to decorate */ - int max_code; /* largest code with non zero frequency */ - ushf *bl_count; /* number of codes at each bit length */ -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - unsigned code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits - 1]) << 1; - next_code[bits] = (ush)code; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, - "inconsistent bit counts"); - Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); - - for (n = 0; n <= max_code; n++) { - int len = tree[n].Len; - if (len == 0) continue; - /* Now reverse the bits */ - tree[n].Code = (ush)bi_reverse(next_code[len]++, len); - - Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", - n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1)); - } -} +#ifdef DUMP_BL_TREE +# include +#endif /* =========================================================================== * Construct one Huffman tree and assigns the code bit strings and lengths. @@ -612,10 +622,7 @@ local void gen_codes(tree, max_code, bl_count) * and corresponding code. The length opt_len is updated; static_len is * also updated if stree is not null. The field max_code is set. */ -local void build_tree(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ +local void build_tree(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; const ct_data *stree = desc->stat_desc->static_tree; int elems = desc->stat_desc->elems; @@ -700,11 +707,7 @@ local void build_tree(s, desc) * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */ -local void scan_tree(s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ +local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -745,11 +748,7 @@ local void scan_tree(s, tree, max_code) * Send a literal or distance tree in compressed form, using the codes in * bl_tree. */ -local void send_tree(s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ +local void send_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -796,9 +795,7 @@ local void send_tree(s, tree, max_code) * Construct the Huffman tree for the bit lengths and return the index in * bl_order of the last bit length code to send. */ -local int build_bl_tree(s) - deflate_state *s; -{ +local int build_bl_tree(deflate_state *s) { int max_blindex; /* index of last bit length code of non zero freq */ /* Determine the bit length frequencies for literal and distance trees */ @@ -831,10 +828,8 @@ local int build_bl_tree(s) * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ -local void send_all_trees(s, lcodes, dcodes, blcodes) - deflate_state *s; - int lcodes, dcodes, blcodes; /* number of codes for each tree */ -{ +local void send_all_trees(deflate_state *s, int lcodes, int dcodes, + int blcodes) { int rank; /* index in bl_order */ Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); @@ -860,12 +855,8 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) /* =========================================================================== * Send a stored block */ -void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ +void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */ bi_windup(s); /* align on byte boundary */ put_short(s, (ush)stored_len); @@ -884,9 +875,7 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) /* =========================================================================== * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) */ -void ZLIB_INTERNAL _tr_flush_bits(s) - deflate_state *s; -{ +void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) { bi_flush(s); } @@ -894,9 +883,7 @@ void ZLIB_INTERNAL _tr_flush_bits(s) * Send one empty static block to give enough lookahead for inflate. * This takes 10 bits, of which 7 may remain in the bit buffer. */ -void ZLIB_INTERNAL _tr_align(s) - deflate_state *s; -{ +void ZLIB_INTERNAL _tr_align(deflate_state *s) { send_bits(s, STATIC_TREES<<1, 3); send_code(s, END_BLOCK, static_ltree); #ifdef ZLIB_DEBUG @@ -905,16 +892,108 @@ void ZLIB_INTERNAL _tr_align(s) bi_flush(s); } +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(deflate_state *s, const ct_data *ltree, + const ct_data *dtree) { + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned sx = 0; /* running index in symbol buffers */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->sym_next != 0) do { +#ifdef LIT_MEM + dist = s->d_buf[sx]; + lc = s->l_buf[sx++]; +#else + dist = s->sym_buf[sx++] & 0xff; + dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; + lc = s->sym_buf[sx++]; +#endif + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code + LITERALS + 1, ltree); /* send length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= (unsigned)base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check for no overlay of pending_buf on needed symbols */ +#ifdef LIT_MEM + Assert(s->pending < 2 * (s->lit_bufsize + sx), "pendingBuf overflow"); +#else + Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); +#endif + + } while (sx < s->sym_next); + + send_code(s, END_BLOCK, ltree); +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "block list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local int detect_data_type(deflate_state *s) { + /* block_mask is the bit mask of block-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long block_mask = 0xf3ffc07fUL; + int n; + + /* Check for non-textual ("block-listed") bytes. */ + for (n = 0; n <= 31; n++, block_mask >>= 1) + if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("allow-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) + if (s->dyn_ltree[n].Freq != 0) + return Z_TEXT; + + /* There are no "block-listed" or "allow-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + /* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static * trees or store, and write out the encoded block. */ -void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block, or NULL if too old */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ +void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex = 0; /* index of last bit length code of non zero freq */ @@ -1011,14 +1090,15 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) * Save the match info and tally the frequency counts. Return true if * the current block must be flushed. */ -int ZLIB_INTERNAL _tr_tally(s, dist, lc) - deflate_state *s; - unsigned dist; /* distance of matched string */ - unsigned lc; /* match length - MIN_MATCH or unmatched char (dist==0) */ -{ +int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { +#ifdef LIT_MEM + s->d_buf[s->sym_next] = (ush)dist; + s->l_buf[s->sym_next++] = (uch)lc; +#else s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)lc; +#endif if (dist == 0) { /* lc is the unmatched char */ s->dyn_ltree[lc].Freq++; @@ -1035,147 +1115,3 @@ int ZLIB_INTERNAL _tr_tally(s, dist, lc) } return (s->sym_next == s->sym_end); } - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(s, ltree, dtree) - deflate_state *s; - const ct_data *ltree; /* literal tree */ - const ct_data *dtree; /* distance tree */ -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in sym_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->sym_next != 0) do { - dist = s->sym_buf[sx++] & 0xff; - dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; - lc = s->sym_buf[sx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code + LITERALS + 1, ltree); /* send length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= (unsigned)base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and sym_buf is ok: */ - Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); - - } while (sx < s->sym_next); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "block list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type(s) - deflate_state *s; -{ - /* block_mask is the bit mask of block-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long block_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("block-listed") bytes. */ - for (n = 0; n <= 31; n++, block_mask >>= 1) - if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("allow-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "block-listed" or "allow-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(s) - deflate_state *s; -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(s) - deflate_state *s; -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->bits_sent = (s->bits_sent + 7) & ~7; -#endif -} diff --git a/libs/ext/zlib/uncompr.c b/libs/ext/zlib/uncompr.c index f9532f46c..5e256663b 100644 --- a/libs/ext/zlib/uncompr.c +++ b/libs/ext/zlib/uncompr.c @@ -24,12 +24,8 @@ Z_DATA_ERROR if the input data was corrupted, including if the input data is an incomplete zlib stream. */ -int ZEXPORT uncompress2(dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong *sourceLen; -{ +int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong *sourceLen) { z_stream stream; int err; const uInt max = (uInt)-1; @@ -83,11 +79,7 @@ int ZEXPORT uncompress2(dest, destLen, source, sourceLen) err; } -int ZEXPORT uncompress(dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ +int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen) { return uncompress2(dest, destLen, source, &sourceLen); } diff --git a/libs/ext/zlib/zconf.h b/libs/ext/zlib/zconf.h index bf977d3e7..62adc8d84 100644 --- a/libs/ext/zlib/zconf.h +++ b/libs/ext/zlib/zconf.h @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -241,7 +241,11 @@ #endif #ifdef Z_SOLO - typedef unsigned long z_size_t; +# ifdef _WIN64 + typedef unsigned long long z_size_t; +# else + typedef unsigned long z_size_t; +# endif #else # define z_longlong long long # if defined(NO_SIZE_T) @@ -296,14 +300,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have @@ -520,7 +516,7 @@ typedef uLong FAR uLongf; #if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# if defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t diff --git a/libs/ext/zlib/zlib.h b/libs/ext/zlib/zlib.h index 953cb5012..8d4b932ea 100644 --- a/libs/ext/zlib/zlib.h +++ b/libs/ext/zlib/zlib.h @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.13, October 13th, 2022 + version 1.3.1, January 22nd, 2024 - Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.13" -#define ZLIB_VERNUM 0x12d0 +#define ZLIB_VERSION "1.3.1" +#define ZLIB_VERNUM 0x1310 #define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 13 +#define ZLIB_VER_MINOR 3 +#define ZLIB_VER_REVISION 1 #define ZLIB_VER_SUBREVISION 0 /* @@ -78,8 +78,8 @@ extern "C" { even in the case of corrupted input. */ -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); +typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size); +typedef void (*free_func)(voidpf opaque, voidpf address); struct internal_state; @@ -217,7 +217,7 @@ typedef gz_header FAR *gz_headerp; /* basic functions */ -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +ZEXTERN const char * ZEXPORT zlibVersion(void); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check @@ -225,12 +225,12 @@ ZEXTERN const char * ZEXPORT zlibVersion OF((void)); */ /* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); +ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. + allocation functions. total_in, total_out, adler, and msg are initialized. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all @@ -247,7 +247,7 @@ ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); */ -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); /* deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -320,8 +320,8 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. + avail_out is greater than six when the flush marker begins, in order to avoid + repeated flush markers upon calling deflate() again when avail_out == 0. If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was @@ -360,7 +360,7 @@ ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); */ -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -375,7 +375,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); /* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateInit(z_streamp strm); Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by @@ -383,7 +383,8 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); read or consumed. The allocation of a sliding window will be deferred to the first call of inflate (if the decompression does not complete on the first call). If zalloc and zfree are set to Z_NULL, inflateInit updates - them to use default allocation functions. + them to use default allocation functions. total_in, total_out, adler, and + msg are initialized. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the @@ -397,7 +398,7 @@ ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); */ -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); /* inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -517,7 +518,7 @@ ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); */ -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -535,12 +536,12 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); */ /* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); +ZEXTERN int ZEXPORT deflateInit2(z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy); This is another version of deflateInit with more compression options. The fields zalloc, zfree and opaque must be initialized before by the caller. @@ -607,9 +608,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); +ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, + const Bytef *dictionary, + uInt dictLength); /* Initializes the compression dictionary from the given byte sequence without producing any compressed output. When using the zlib format, this @@ -651,9 +652,9 @@ ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, not perform any compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); +ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, + Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by deflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -673,8 +674,8 @@ ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT deflateCopy(z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -691,20 +692,20 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, destination. */ -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateReset(z_streamp strm); /* This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream will leave the compression level and any other attributes that may have been - set unchanged. + set unchanged. total_in, total_out, adler, and msg are initialized. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); +ZEXTERN int ZEXPORT deflateParams(z_streamp strm, + int level, + int strategy); /* Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2(). This can be @@ -729,7 +730,7 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, Then no more input data should be provided before the deflateParams() call. If this is done, the old level and strategy will be applied to the data compressed before deflateParams(), and the new level and strategy will be - applied to the the data compressed after deflateParams(). + applied to the data compressed after deflateParams(). deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if @@ -740,11 +741,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, retried with more output space. */ -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain)); +ZEXTERN int ZEXPORT deflateTune(z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain); /* Fine tune deflate's internal compression parameters. This should only be used by someone who understands the algorithm used by zlib's deflate for @@ -757,8 +758,8 @@ ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. */ -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); +ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, + uLong sourceLen); /* deflateBound() returns an upper bound on the compressed size after deflation of sourceLen bytes. It must be called after deflateInit() or @@ -772,9 +773,9 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, than Z_FINISH or Z_NO_FLUSH are used. */ -ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, - unsigned *pending, - int *bits)); +ZEXTERN int ZEXPORT deflatePending(z_streamp strm, + unsigned *pending, + int *bits); /* deflatePending() returns the number of bytes and bits of output that have been generated, but not yet provided in the available output. The bytes not @@ -787,9 +788,9 @@ ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); +ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, + int bits, + int value); /* deflatePrime() inserts bits in the deflate output stream. The intent is that this function is used to start off the deflate output with the bits @@ -804,8 +805,8 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, source stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, + gz_headerp head); /* deflateSetHeader() provides gzip header information for when a gzip stream is requested by deflateInit2(). deflateSetHeader() may be called @@ -821,16 +822,17 @@ ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, gzip file" and give up. If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). + the time set to zero, and os set to the current operating system, with no + extra, name, or comment fields. The gzip header is returned to the default + state by deflateReset(). deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. */ /* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateInit2(z_streamp strm, + int windowBits); This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized @@ -883,9 +885,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, deferred until inflate() is called. */ -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); +ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, + const Bytef *dictionary, + uInt dictLength); /* Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate, @@ -906,9 +908,9 @@ ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, inflate(). */ -ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); +ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, + Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by inflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -921,7 +923,7 @@ ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, stream state is inconsistent. */ -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateSync(z_streamp strm); /* Skips invalid compressed data until a possible full flush point (see above for the description of deflate with Z_FULL_FLUSH) can be found, or until all @@ -934,14 +936,14 @@ ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); inflateSync returns Z_OK if a possible full flush point has been found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current current value of - total_in which indicates where valid compressed data was found. In the - error case, the application may repeatedly call inflateSync, providing more - input each time, until success or end of the input data. + In the success case, the application may save the current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. */ -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -956,18 +958,19 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, destination. */ -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateReset(z_streamp strm); /* This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The stream will keep attributes that may have been set by inflateInit2. + total_in, total_out, adler, and msg are initialized. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, + int windowBits); /* This function is the same as inflateReset, but it also permits changing the wrap and window size requests. The windowBits parameter is interpreted @@ -980,9 +983,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, the windowBits parameter is invalid. */ -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, - int bits, - int value)); +ZEXTERN int ZEXPORT inflatePrime(z_streamp strm, + int bits, + int value); /* This function inserts bits in the inflate input stream. The intent is that this function is used to start inflating at a bit position in the @@ -1001,7 +1004,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, stream state was inconsistent. */ -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +ZEXTERN long ZEXPORT inflateMark(z_streamp strm); /* This function returns two values, one in the lower 16 bits of the return value, and the other in the remaining upper bits, obtained by shifting the @@ -1029,8 +1032,8 @@ ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); source stream state was inconsistent. */ -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, + gz_headerp head); /* inflateGetHeader() requests that gzip header information be stored in the provided gz_header structure. inflateGetHeader() may be called after @@ -1070,8 +1073,8 @@ ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, */ /* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); +ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits, + unsigned char FAR *window); Initialize the internal stream state for decompression using inflateBack() calls. The fields zalloc, zfree and opaque in strm must be initialized @@ -1091,13 +1094,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, the version of the header file. */ -typedef unsigned (*in_func) OF((void FAR *, - z_const unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); +typedef unsigned (*in_func)(void FAR *, + z_const unsigned char FAR * FAR *); +typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned); -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); +ZEXTERN int ZEXPORT inflateBack(z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc); /* inflateBack() does a raw inflate with a single call using a call-back interface for input and output. This is potentially more efficient than @@ -1165,7 +1168,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, cannot return Z_OK. */ -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm); /* All memory allocated by inflateBackInit() is freed. @@ -1173,7 +1176,7 @@ ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); state was inconsistent. */ -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +ZEXTERN uLong ZEXPORT zlibCompileFlags(void); /* Return flags indicating compile-time options. Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: @@ -1226,8 +1229,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); you need special options. */ -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1241,9 +1244,9 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, buffer. */ -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); +ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level); /* Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte @@ -1257,15 +1260,15 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, Z_STREAM_ERROR if the level parameter is invalid. */ -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); /* compressBound() returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() call to allocate the destination buffer. */ -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1282,8 +1285,8 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, buffer with the uncompressed data up to that point. */ -ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong *sourceLen)); +ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen); /* Same as uncompress, except that sourceLen is a pointer, where the length of the source is *sourceLen. On return, *sourceLen is the number of @@ -1302,7 +1305,7 @@ ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ /* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode); Open the gzip (.gz) file at path for reading and decompressing, or compressing and writing. The mode parameter is as in fopen ("rb" or "wb") @@ -1339,7 +1342,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); file could not be opened. */ -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode); /* Associate a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (if the file has @@ -1362,7 +1365,7 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); will not detect if fd is invalid (unless fd is -1). */ -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size); /* Set the internal buffer size used by this library's functions for file to size. The default buffer size is 8192 bytes. This function must be called @@ -1378,7 +1381,7 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); too late. */ -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy); /* Dynamically update the compression level and strategy for file. See the description of deflateInit2 for the meaning of these parameters. Previously @@ -1389,7 +1392,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); or Z_MEM_ERROR if there is a memory allocation error. */ -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len); /* Read and decompress up to len uncompressed bytes from file into buf. If the input file is not in gzip format, gzread copies the given number of @@ -1419,8 +1422,8 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); Z_STREAM_ERROR. */ -ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, - gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, + gzFile file); /* Read and decompress up to nitems items of size size from file into buf, otherwise operating as gzread() does. This duplicates the interface of @@ -1445,14 +1448,14 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, file, resetting and retrying on end-of-file, when size is not 1. */ -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); +ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); /* Compress and write the len uncompressed bytes at buf to file. gzwrite returns the number of uncompressed bytes written or 0 in case of error. */ -ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, - z_size_t nitems, gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, + z_size_t nitems, gzFile file); /* Compress and write nitems items of size size from buf to file, duplicating the interface of stdio's fwrite(), with size_t request and return types. If @@ -1465,7 +1468,7 @@ ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, is returned, and the error state is set to Z_STREAM_ERROR. */ -ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...); /* Convert, format, compress, and write the arguments (...) to file under control of the string format, as in fprintf. gzprintf returns the number of @@ -1480,7 +1483,7 @@ ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); This can be determined using zlibCompileFlags(). */ -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); /* Compress and write the given null-terminated string s to file, excluding the terminating null character. @@ -1488,7 +1491,7 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); gzputs returns the number of characters written, or -1 in case of error. */ -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); /* Read and decompress bytes from file into buf, until len-1 characters are read, or until a newline character is read and transferred to buf, or an @@ -1502,13 +1505,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); buf are indeterminate. */ -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +ZEXTERN int ZEXPORT gzputc(gzFile file, int c); /* Compress and write c, converted to an unsigned char, into file. gzputc returns the value that was written, or -1 in case of error. */ -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +ZEXTERN int ZEXPORT gzgetc(gzFile file); /* Read and decompress one byte from file. gzgetc returns this byte or -1 in case of end of file or error. This is implemented as a macro for speed. @@ -1517,7 +1520,7 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); points to has been clobbered or not. */ -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +ZEXTERN int ZEXPORT gzungetc(int c, gzFile file); /* Push c back onto the stream for file to be read as the first character on the next read. At least one character of push-back is always allowed. @@ -1529,7 +1532,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); gzseek() or gzrewind(). */ -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +ZEXTERN int ZEXPORT gzflush(gzFile file, int flush); /* Flush all pending output to file. The parameter flush is as in the deflate() function. The return value is the zlib error number (see function @@ -1545,8 +1548,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); */ /* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); +ZEXTERN z_off_t ZEXPORT gzseek(gzFile file, + z_off_t offset, int whence); Set the starting position to offset relative to whence for the next gzread or gzwrite on file. The offset represents a number of bytes in the @@ -1564,7 +1567,7 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, would be before the current position. */ -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +ZEXTERN int ZEXPORT gzrewind(gzFile file); /* Rewind file. This function is supported only for reading. @@ -1572,7 +1575,7 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); */ /* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gztell(gzFile file); Return the starting position for the next gzread or gzwrite on file. This position represents a number of bytes in the uncompressed data stream, @@ -1583,7 +1586,7 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); */ /* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file); Return the current compressed (actual) read or write offset of file. This offset includes the count of bytes that precede the gzip stream, for example @@ -1592,7 +1595,7 @@ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); be used for a progress indicator. On error, gzoffset() returns -1. */ -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +ZEXTERN int ZEXPORT gzeof(gzFile file); /* Return true (1) if the end-of-file indicator for file has been set while reading, false (0) otherwise. Note that the end-of-file indicator is set @@ -1607,7 +1610,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile file)); has grown since the previous end of file was detected. */ -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +ZEXTERN int ZEXPORT gzdirect(gzFile file); /* Return true (1) if file is being copied directly while reading, or false (0) if file is a gzip stream being decompressed. @@ -1628,7 +1631,7 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); gzip file reading and decompression, which may not be desired.) */ -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose(gzFile file); /* Flush all pending output for file, if necessary, close file and deallocate the (de)compression state. Note that once file is closed, you @@ -1641,8 +1644,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFile file)); last read ended in the middle of a gzip stream, or Z_OK on success. */ -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_r(gzFile file); +ZEXTERN int ZEXPORT gzclose_w(gzFile file); /* Same as gzclose(), but gzclose_r() is only for use when reading, and gzclose_w() is only for use when writing or appending. The advantage to @@ -1653,7 +1656,7 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); zlib library. */ -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); /* Return the error message for the last error which occurred on file. errnum is set to zlib error number. If an error occurred in the file system @@ -1669,7 +1672,7 @@ ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); functions above that do not distinguish those cases in their return values. */ -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +ZEXTERN void ZEXPORT gzclearerr(gzFile file); /* Clear the error and end-of-file flags for file. This is analogous to the clearerr() function in stdio. This is useful for continuing to read a gzip @@ -1686,7 +1689,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); library. */ -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len); /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. An Adler-32 value is in the range of a 32-bit @@ -1706,15 +1709,15 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); if (adler != original_adler) error(); */ -ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, + z_size_t len); /* Same as adler32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); +ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, + z_off_t len2); Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for @@ -1724,7 +1727,7 @@ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, negative, the result has no meaning or utility. */ -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len); /* Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. @@ -1742,30 +1745,30 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); if (crc != original_crc) error(); */ -ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, + z_size_t len); /* Same as crc32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); Combine two CRC-32 check values into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. + len2. len2 must be non-negative. */ /* -ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); Return the operator corresponding to length len2, to be used with - crc32_combine_op(). + crc32_combine_op(). len2 must be non-negative. */ -ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); +ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); /* Give the same result as crc32_combine(), using op in place of len2. op is is generated from len2 by crc32_combine_gen(). This will be faster than @@ -1778,20 +1781,20 @@ ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); +ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, + const char *version, int stream_size); +ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size); +ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size); #ifdef Z_PREFIX_SET # define z_deflateInit(strm, level) \ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) @@ -1836,7 +1839,7 @@ struct gzFile_s { unsigned char *next; z_off64_t pos; }; -ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ #ifdef Z_PREFIX_SET # undef z_gzgetc # define z_gzgetc(g) \ @@ -1853,13 +1856,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ * without large file support, _LFS64_LARGEFILE must also be true */ #ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); #endif #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) @@ -1881,50 +1884,50 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ # define crc32_combine_gen crc32_combine_gen64 # endif # ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); # endif #else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell(gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif #else /* Z_SOLO */ - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif /* !Z_SOLO */ /* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); -ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); -ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF((z_streamp)); -ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); -ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +ZEXTERN const char * ZEXPORT zError(int); +ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void); +ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); +ZEXTERN int ZEXPORT inflateValidate(z_streamp, int); +ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); +ZEXTERN int ZEXPORT inflateResetKeep(z_streamp); +ZEXTERN int ZEXPORT deflateResetKeep(z_streamp); #if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, - const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, + const char *mode); #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) # ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, - const char *format, - va_list va)); +ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, + const char *format, + va_list va); # endif #endif diff --git a/libs/ext/zlib/zutil.c b/libs/ext/zlib/zutil.c index 9543ae825..b1c5d2d3c 100644 --- a/libs/ext/zlib/zutil.c +++ b/libs/ext/zlib/zutil.c @@ -24,13 +24,11 @@ z_const char * const z_errmsg[10] = { }; -const char * ZEXPORT zlibVersion() -{ +const char * ZEXPORT zlibVersion(void) { return ZLIB_VERSION; } -uLong ZEXPORT zlibCompileFlags() -{ +uLong ZEXPORT zlibCompileFlags(void) { uLong flags; flags = 0; @@ -121,9 +119,7 @@ uLong ZEXPORT zlibCompileFlags() # endif int ZLIB_INTERNAL z_verbose = verbose; -void ZLIB_INTERNAL z_error(m) - char *m; -{ +void ZLIB_INTERNAL z_error(char *m) { fprintf(stderr, "%s\n", m); exit(1); } @@ -132,9 +128,7 @@ void ZLIB_INTERNAL z_error(m) /* exported to allow conversion of error code to string for compress() and * uncompress() */ -const char * ZEXPORT zError(err) - int err; -{ +const char * ZEXPORT zError(int err) { return ERR_MSG(err); } @@ -148,22 +142,14 @@ const char * ZEXPORT zError(err) #ifndef HAVE_MEMCPY -void ZLIB_INTERNAL zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ +void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) { if (len == 0) return; do { *dest++ = *source++; /* ??? to be unrolled */ } while (--len != 0); } -int ZLIB_INTERNAL zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ +int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) { uInt j; for (j = 0; j < len; j++) { @@ -172,10 +158,7 @@ int ZLIB_INTERNAL zmemcmp(s1, s2, len) return 0; } -void ZLIB_INTERNAL zmemzero(dest, len) - Bytef* dest; - uInt len; -{ +void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) { if (len == 0) return; do { *dest++ = 0; /* ??? to be unrolled */ @@ -216,8 +199,7 @@ local ptr_table table[MAX_PTR]; * a protected system like OS/2. Use Microsoft C instead. */ -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { voidpf buf; ulg bsize = (ulg)items*size; @@ -242,8 +224,7 @@ voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) return buf; } -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { int n; (void)opaque; @@ -279,14 +260,12 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) # define _hfree hfree #endif -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) { (void)opaque; return _halloc((long)items, size); } -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { (void)opaque; _hfree(ptr); } @@ -299,25 +278,18 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) #ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); +extern voidp malloc(uInt size); +extern voidp calloc(uInt items, uInt size); +extern void free(voidpf ptr); #endif -voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { (void)opaque; return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : (voidpf)calloc(items, size); } -void ZLIB_INTERNAL zcfree(opaque, ptr) - voidpf opaque; - voidpf ptr; -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { (void)opaque; free(ptr); } diff --git a/libs/ext/zlib/zutil.h b/libs/ext/zlib/zutil.h index 0bc7f4ecd..48dd7feba 100644 --- a/libs/ext/zlib/zutil.h +++ b/libs/ext/zlib/zutil.h @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2022 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -56,7 +56,7 @@ typedef unsigned long ulg; extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] +#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)] #define ERR_RETURN(strm,err) \ return (strm->msg = ERR_MSG(err), (err)) @@ -137,17 +137,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # endif #endif -#if defined(MACOS) || defined(TARGET_OS_MAC) +#if defined(MACOS) # define OS_CODE 7 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif #endif #ifdef __acorn @@ -170,18 +161,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define OS_CODE 19 #endif -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - #if defined(__BORLANDC__) && !defined(MSDOS) #pragma warn -8004 #pragma warn -8008 @@ -191,9 +170,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* provide prototypes for these when building zlib without LFS */ #if !defined(_WIN32) && \ (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); #endif /* common defaults */ @@ -232,16 +211,16 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define zmemzero(dest, len) memset(dest, 0, len) # endif #else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); + void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len); + int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len); + void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len); #endif /* Diagnostic functions */ #ifdef ZLIB_DEBUG # include extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); + extern void ZLIB_INTERNAL z_error(char *m); # define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;} @@ -258,9 +237,9 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ #endif #ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); - void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); + voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, + unsigned size); + void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr); #endif #define ZALLOC(strm, items, size) \ diff --git a/libs/kapp/CMakeLists.txt b/libs/kapp/CMakeLists.txt index 998709044..2282587f2 100644 --- a/libs/kapp/CMakeLists.txt +++ b/libs/kapp/CMakeLists.txt @@ -22,41 +22,38 @@ # # =========================================================================== -set ( UNIX_SRC unix/args-conv-os.c unix/sysmain.c ) +set ( UNIX_SRC unix/args-conv-os.c ) # FIXME: Maybe mac/ram.c should be moved to bsd/ram.c. FreeBSD, mac, and # NetBSD are the same, except for the specific sysctl variable. set ( BSD_SRC ${UNIX_SRC} mac/ram.c ) set ( LINUX_SRC ${UNIX_SRC} linux/ram.c ) set ( MAC_SRC ${UNIX_SRC} mac/ram.c ) -set ( WIN_SRC win/args-conv-os.c win/ram.c win/sysmain.c ) +set ( WIN_SRC win/args-conv-os.c win/ram.c ) if( "bsd" STREQUAL ${OS} ) - set ( OS_SPECIFIC_SRC ${BSD_SRC} ) + set ( OS_SPECIFIC_SRC ${BSD_SRC} unix/sysapp.c ) + set ( SYSMAIN unix/sysmain.c ) elseif( "linux" STREQUAL ${OS} ) - set ( OS_SPECIFIC_SRC ${LINUX_SRC} ) + set ( OS_SPECIFIC_SRC ${LINUX_SRC} unix/sysapp.c ) + set ( SYSMAIN unix/sysmain.c ) elseif( "mac" STREQUAL ${OS} ) - set ( OS_SPECIFIC_SRC ${MAC_SRC} ) + set ( OS_SPECIFIC_SRC ${MAC_SRC} unix/sysapp.c ) + set ( SYSMAIN unix/sysmain.c ) elseif ( "windows" STREQUAL ${OS} ) - set ( OS_SPECIFIC_SRC ${WIN_SRC} ) + set ( OS_SPECIFIC_SRC ${WIN_SRC} win/sysapp.c ) + set ( SYSMAIN win/sysmain.c ) endif() -set( KAPP_CMN - args - args-conv - tokenizer - log-xml +set( APP_CMN + args.c + args-conv.c + tokenizer.c + log-xml.c + vdbapp.c + vdbapp.cpp ) -set( KAPP_SRC - main - ${KAPP_CMN} -) - -set( SRC ${KAPP_SRC} ${OS_SPECIFIC_SRC} ) - -GenerateStaticLibs( kapp "${SRC}" ) -ExportStatic( kapp true ) - -GenerateStaticLibsWithDefs( kapp-norsrc "${SRC}" "NO_KRSRC=1" ) +GenerateStaticLibs( vdbapp "${APP_CMN};${OS_SPECIFIC_SRC}" ) +ExportStatic( vdbapp true ) add_compile_definitions (__mod__="libs/kapp") diff --git a/libs/kapp/args.c b/libs/kapp/args.c index 5bb9d31b8..46d9f4f13 100644 --- a/libs/kapp/args.c +++ b/libs/kapp/args.c @@ -40,11 +40,12 @@ #include #include -#include +#include #include #include #include "args_debug.h" +#include "version-hash.h" /* HASH_SRA_TOOLS */ #include #include @@ -71,6 +72,45 @@ #define LEGACY_Q_ALIAS_ERROR 0 #endif +static const char * UsageDefaultName = ""; +static Usage_t Usage = NULL; +static UsageSummary_t UsageSummary = NULL; +static ver_t KAppVersion = 0; + +void SetUsageDefaultName( const char* str ) +{ + if ( str != NULL ) + { + UsageDefaultName = str; + } +} + +Usage_t SetUsage ( Usage_t func ) +{ + Usage_t ret = Usage; + Usage = func; + return ret; +} + +UsageSummary_t SetUsageSummary ( UsageSummary_t func ) +{ + UsageSummary_t ret = UsageSummary; + UsageSummary = func; + return ret; +} + +ver_t SetKAppVersion ( ver_t ver ) +{ + ver_t ret = KAppVersion; + KAppVersion = ver; + return ret; +} + +ver_t GetKAppVersion () +{ + return KAppVersion; +} + bool CC is_valid_name (const char * string) { /* we do not allow leading - or empty names */ @@ -1130,7 +1170,7 @@ rc_t CC ProcessArgsConversion(Args * self) } static -rc_t ArgsParseInt (Args * self, int argc, char *argv[]) +rc_t ArgsParseInt (Args * self, int argc, const char *argv[]) { rc_t rc = 0; /* hard fail - quit processing */ rc_t orc = 0; /* soft fail - keep processing but we'll fail in the end */ @@ -1464,7 +1504,7 @@ rc_t ArgsParseInt (Args * self, int argc, char *argv[]) return rc; } -rc_t CC ArgsParse_int (Args * self, int argc, char *argv[]) +rc_t CC ArgsParse_int (Args * self, int argc, const char *argv[]) { KLogLevel lvl = KLogLevelGet (); rc_t rc = KLogLevelSet ( klogWarn ); @@ -1474,7 +1514,7 @@ rc_t CC ArgsParse_int (Args * self, int argc, char *argv[]) } /** Process `argv` using the options that have been defined. */ -rc_t CC ArgsParse (Args * self, int argc, char *argv[]) +rc_t CC ArgsParse (Args * self, int argc, const char *argv[]) { /* This function is called AFTER all options have been defined, @@ -1822,7 +1862,10 @@ rc_t CC ArgsHandleHelp (Args * self) if (count) { /* this is a call into the main program code */ - Usage(self); + if ( Usage ) + { + Usage(self); + } ArgsWhack (self); exit (0); } @@ -1858,7 +1901,7 @@ rc_t CC ArgsHandleVersion (Args * self) if (self) rc = ArgsProgram (self, &fullpath, &progname); - HelpVersion (fullpath, KAppVersion()); + HelpVersion (fullpath, KAppVersion); ArgsWhack (self); exit (0); @@ -2021,7 +2064,7 @@ rc_t CC ArgsHandleStandardOptions (Args * self) /* if pself == NULL then process / initialize standard arguments and release Args */ static -rc_t ArgsMakeAndHandleInt ( Args ** pself, int argc, char ** argv, +rc_t ArgsMakeAndHandleInt ( Args ** pself, int argc, const char ** argv, const ParamDef *params, uint32_t param_count, uint32_t optdef_count, va_list ap ) { rc_t rc; @@ -2112,7 +2155,7 @@ rc_t CC ArgsMakeAndHandle (Args ** pself, int argc, char ** argv, uint32_t table rc_t rc; va_list args; va_start ( args, table_count ); - rc = ArgsMakeAndHandleInt ( pself, argc, argv, NULL, 0, table_count, args ); + rc = ArgsMakeAndHandleInt ( pself, argc, (const char**)argv, NULL, 0, table_count, args ); va_end ( args ); return rc; } @@ -2123,7 +2166,7 @@ rc_t CC ArgsMakeAndHandle2 (Args ** pself, int argc, char ** argv, rc_t rc; va_list args; va_start ( args, table_count ); - rc = ArgsMakeAndHandleInt ( pself, argc, argv, params, param_count, table_count, args ); + rc = ArgsMakeAndHandleInt ( pself, argc, (const char**)argv, params, param_count, table_count, args ); va_end ( args ); return rc; } @@ -2195,10 +2238,11 @@ void CC HelpVersion (const char * fullpath, ver_t version) (sraVersion.version == version && sraVersion.revision == 0 && sraVersion.type == eSraReleaseVersionTypeFinal)) { - OUTMSG (("\n%s : %.3V\n\n", fullpath, version)); + OUTMSG (("%s : %.3V\n\n", fullpath, version)); } else { - OUTMSG (("\n%s : %.3V ( %s )\n\n", fullpath, version, cSra)); + OUTMSG (("%s : %.3V%s ( %s%s )\n\n", + fullpath, version, HASH_SRA_TOOLS, cSra, HASH_NCBI_VDB)); } } @@ -2385,7 +2429,10 @@ rc_t CC MiniUsage (const Args * args) if (rc) progname = UsageDefaultName; KOutHandlerSetStdErr(); - UsageSummary (progname); + if ( UsageSummary ) + { + UsageSummary (progname); + } KOutMsg ("\nUse option --help for more information.\n\n"); KOutHandlerSet (w,d); diff --git a/libs/kapp/linux/ram.c b/libs/kapp/linux/ram.c index 47ccfb0b4..5556d9541 100644 --- a/libs/kapp/linux/ram.c +++ b/libs/kapp/linux/ram.c @@ -24,8 +24,6 @@ * */ -#include "../main-priv.h" -#include #include #include @@ -55,7 +53,7 @@ rc_t KAppGetTotalRam ( uint64_t * totalRam ) PLOGERR ( klogFatal, ( klogFatal, rc, "failed to retrieve number of RAM pages. error code: $(status) - $(msg)" , "status=%d,msg=%!" - , status, status + , status, status )); return rc; } diff --git a/libs/kapp/log-xml.c b/libs/kapp/log-xml.c index 0e5dba465..c73b05538 100644 --- a/libs/kapp/log-xml.c +++ b/libs/kapp/log-xml.c @@ -24,7 +24,6 @@ * */ #include -#include #include #include #include diff --git a/libs/kapp/mac/ram.c b/libs/kapp/mac/ram.c index 8f5b10203..0a5dd227d 100644 --- a/libs/kapp/mac/ram.c +++ b/libs/kapp/mac/ram.c @@ -24,8 +24,7 @@ * */ -#include "../main-priv.h" -#include +#include "../vdbapp-priv.h" #include #include diff --git a/libs/kapp/sun/sysmain.c b/libs/kapp/sun/sysmain.c deleted file mode 100644 index d0c53e3e5..000000000 --- a/libs/kapp/sun/sysmain.c +++ /dev/null @@ -1,243 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#include "../main-priv.h" -#include -#include -#include -#include -#include -#include - -#undef __XOPEN_OR_POSIX -#define __XOPEN_OR_POSIX 1 - -#undef __EXTENSIONS__ -#define __EXTENSIONS__ 1 - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if ! _DEBUGGING && ! defined CATCH_SIGSEGV -#define CATCH_SIGSEGV 1 -#endif - -/*-------------------------------------------------------------------------- - * Main - */ - -static bool no_hup; -static atomic32_t hangup; -static atomic32_t quitting; - -/* Quitting - * is the program supposed to exit - */ -rc_t Quitting ( void ) -{ - if ( atomic32_read ( & quitting ) == 0 ) - return 0; - LOGMSG ( klogInfo, "EXITING..." ); - return RC ( rcExe, rcProcess, rcExecuting, rcProcess, rcCanceled ); -} - -/* SignalQuit - * tell the program to quit - */ -rc_t SignalQuit ( void ) -{ - ReportSilence (); - - if ( kill ( 0, SIGTERM ) != 0 ) switch ( errno ) - { - case EINVAL: - return RC ( rcExe, rcProcess, rcSignaling, rcMessage, rcInvalid ); - case EPERM: - return RC ( rcExe, rcProcess, rcSignaling, rcMessage, rcUnauthorized ); - default: - return RC ( rcExe, rcProcess, rcSignaling, rcNoObj, rcUnknown ); - } - return 0; -} - -/* Hangup - * has the program received a SIGHUP - */ -rc_t Hangup ( void ) -{ - if ( atomic32_read ( & hangup ) == 0 ) - return 0; - LOGMSG ( klogInfo, "HANGUP...\n" ); - return RC ( rcExe, rcProcess, rcExecuting, rcProcess, rcIncomplete ); -} - -/* SignalHup - * send the program a SIGHUP - */ -rc_t SignalHup ( void ) -{ - if ( kill ( 0, SIGHUP ) != 0 ) switch ( errno ) - { - case EINVAL: - return RC ( rcExe, rcProcess, rcSignaling, rcMessage, rcInvalid ); - case EPERM: - return RC ( rcExe, rcProcess, rcSignaling, rcMessage, rcUnauthorized ); - default: - return RC ( rcExe, rcProcess, rcSignaling, rcNoObj, rcUnknown ); - } - return 0; -} - -/* SignalNoHup - * tell the program to stay alive even after SIGHUP - */ -rc_t SignalNoHup ( void ) -{ - no_hup = true; - return 0; -} - -/* SigHupHandler - */ -static -void SigHupHandler ( int sig ) -{ - ( ( void ) sig ); - atomic32_inc ( & hangup ); - if ( ! no_hup ) - atomic32_inc ( & quitting ); - PLOGMSG ( klogInfo, ( klogInfo, "SIGNAL - $(sig)\n", "sig=HUP" )); -} - -/* SigQuitHandler - */ -static -void SigQuitHandler ( int sig ) -{ - const char *msg; - - ReportSilence (); - - atomic32_inc ( & quitting ); - switch ( sig ) - { - case SIGINT: - msg = "^C"; - break; - case SIGQUIT: - msg = "QUIT"; - break; - case SIGTERM: - msg = "TERM"; - break; - default: - PLOGMSG ( klogWarn, ( klogWarn, "SIGNAL - $(sig)\n", "sig=%d", sig )); - return; - } - - PLOGMSG ( klogInfo, ( klogInfo, "SIGNAL - $(sig)", "sig=%s", msg ) ); -} - -/* SigSegvHandler - */ -#if CATCH_SIGSEGV -static -void SigSegvHandler ( int sig ) -{ - ( ( void ) sig ); - PLOGMSG ( klogFatal, ( klogFatal, "SIGNAL - $(sig)\n", "sig=Segmentation fault" )); - abort (); - exit ( 1 ); -} -#endif - -/* main - * Unix specific main entrypoint - */ -int main ( int argc, char *argv [] ) -{ - static struct - { - void ( * handler ) ( int ); - int sig; - } sigs [] = - { - { SigHupHandler, SIGHUP }, - { SigQuitHandler, SIGINT }, - { SigQuitHandler, SIGQUIT }, -#if CATCH_SIGSEGV - { SigSegvHandler, SIGSEGV }, -#endif - { SigQuitHandler, SIGTERM } - }; - - rc_t rc; - int i, status; - struct sigaction sig_saves [ sizeof sigs / sizeof sigs [ 0 ] ]; - - /* get application version */ - uint32_t vers = KAppVersion (); - - /* initialize logging to default values */ - KLogInit (); - - /* install signal handlers */ - for ( i = 0; i < sizeof sigs / sizeof sigs [ 0 ]; ++ i ) - { - struct sigaction act; - memset ( & act, 0, sizeof act ); - act . sa_handler = sigs [ i ] . handler; - act . sa_flags = SA_RESETHAND; - - status = sigaction ( sigs [ i ] . sig, & act, & sig_saves [ i ] ); - if ( status < 0 ) - { - PLOGMSG ( klogFatal, ( klogFatal, - "failed to install handler for signal $(sig) - $(msg)" - , "sig=%d,msg='%s'" - , sigs [ i ] . sig - , strerror ( errno ) - )); - return 2; - } - } - - /* run this guy */ - rc = KMane ( argc, argv ); - - /* remove handlers, for what it's worth */ - for ( i = 0; i < sizeof sigs / sizeof sigs [ 0 ]; ++ i ) - sigaction ( sigs [ i ] . sig, & sig_saves [ i ], NULL ); - - return ( rc == 0 ) ? 0 : 3; -} diff --git a/libs/kapp/tokenizer.c b/libs/kapp/tokenizer.c index 1184fdeeb..9ace350c9 100644 --- a/libs/kapp/tokenizer.c +++ b/libs/kapp/tokenizer.c @@ -510,7 +510,7 @@ rc_t CC Args_parse_inf_file( Args * args, const char * file_option ) rc = Args_tokenize_file_into_argv( filename, &argc, &argv ); if ( rc == 0 && argv != NULL && argc > 0 ) { - rc = ArgsParse ( args, argc, argv ); + rc = ArgsParse ( args, argc, (const char**)argv ); Args_free_token_argv( argc, argv ); } } diff --git a/libs/kapp/unix/sysmain.c b/libs/kapp/unix/sysapp.c similarity index 67% rename from libs/kapp/unix/sysmain.c rename to libs/kapp/unix/sysapp.c index 3460ce362..ae692b45c 100644 --- a/libs/kapp/unix/sysmain.c +++ b/libs/kapp/unix/sysapp.c @@ -24,57 +24,23 @@ * */ -#include "../main-priv.h" -#include -#include -#include -#include -#include +#include "../vdbapp-priv.h" + #include #include -#include +#include -#include #include -#include -#include -#include -#include #include -#include #if ! _DEBUGGING && ! defined CATCH_SIGSEGV #define CATCH_SIGSEGV 1 #endif -#if ! defined CATCH_SIGHUP -#define CATCH_SIGHUP 0 -#endif - #if _DEBUGGING && ! defined PRODUCE_CORE #define PRODUCE_CORE 1 #endif - -/*-------------------------------------------------------------------------- - * Main - */ - -static bool no_hup; -static atomic32_t hangup; -static atomic32_t quitting; - -/* Quitting - * is the program supposed to exit - */ -rc_t Quitting ( void ) -{ - if ( atomic32_read ( & quitting ) == 0 ) - return 0; - LOGMSG ( klogInfo, "EXITING..." ); - return RC ( rcExe, rcProcess, rcExecuting, rcProcess, rcCanceled ); -} - /* SignalQuit * tell the program to quit */ @@ -94,20 +60,6 @@ rc_t SignalQuit ( void ) return 0; } -/* Hangup - * has the program received a SIGHUP - */ -rc_t Hangup ( void ) -{ - if ( atomic32_read ( & hangup ) == 0 ) - return 0; - LOGMSG ( klogInfo, "HANGUP...\n" ); - return RC ( rcExe, rcProcess, rcExecuting, rcProcess, rcIncomplete ); -} - -/* SignalHup - * send the program a SIGHUP - */ rc_t SignalHup ( void ) { if ( kill ( 0, SIGHUP ) != 0 ) switch ( errno ) @@ -122,29 +74,6 @@ rc_t SignalHup ( void ) return 0; } -/* SignalNoHup - * tell the program to stay alive even after SIGHUP - */ -rc_t SignalNoHup ( void ) -{ - no_hup = true; - return 0; -} - -/* SigHupHandler - */ -#if CATCH_SIGHUP -static -void SigHupHandler ( int sig ) -{ - ( ( void ) sig ); - atomic32_inc ( & hangup ); - if ( ! no_hup ) - atomic32_inc ( & quitting ); - PLOGMSG ( klogInfo, (klogInfo, "SIGNAL - $(sig)\n", "sig=HUP" )); -} -#endif - /* SigQuitHandler */ static @@ -152,9 +81,8 @@ void SigQuitHandler ( int sig ) { const char *msg; - ReportSilence (); + SetQuitting(); - atomic32_inc ( & quitting ); switch ( sig ) { case SIGINT: @@ -200,47 +128,42 @@ void SigSegvHandler ( int sig ) } #endif -/* main - * Unix specific main entrypoint - */ -int main ( int argc, char *argv [] ) +static struct { - static struct - { - void ( * handler ) ( int ); - int sig; - } sigs [] = - { -#if CATCH_SIGHUP - { SigHupHandler, SIGHUP }, -#endif - { SigQuitHandler, SIGINT }, + void ( * handler ) ( int ); + int sig; +} sigs [] = +{ + { SigQuitHandler, SIGINT }, #if CATCH_SIGSEGV - { SigSegvHandler, SIGSEGV }, + { SigSegvHandler, SIGSEGV }, #endif - { SigQuitHandler, SIGTERM } - } + { SigQuitHandler, SIGTERM } +} #if ! PRODUCE_CORE - , core_sigs [] = - { +, core_sigs [] = +{ #if ! CATCH_SIGSEGV - { SigCoreHandler, SIGSEGV }, + { SigCoreHandler, SIGSEGV }, #endif - { SigCoreHandler, SIGQUIT }, - { SigCoreHandler, SIGILL }, - { SigCoreHandler, SIGABRT }, - { SigCoreHandler, SIGFPE } - } + { SigCoreHandler, SIGQUIT }, + { SigCoreHandler, SIGILL }, + { SigCoreHandler, SIGABRT }, + { SigCoreHandler, SIGFPE } +} #endif - ; +; - rc_t rc; - int i, status; - struct sigaction sig_saves [ sizeof sigs / sizeof sigs [ 0 ] ]; +struct sigaction sig_saves [ sizeof sigs / sizeof sigs [ 0 ] ]; #if ! PRODUCE_CORE - struct sigaction core_sig_saves [ sizeof core_sigs / sizeof core_sigs [ 0 ] ]; +struct sigaction core_sig_saves [ sizeof core_sigs / sizeof core_sigs [ 0 ] ]; #endif +int +VdbInitializeSystem() +{ + int i, status; + /* install signal handlers */ for ( i = 0; i < sizeof sigs / sizeof sigs [ 0 ]; ++ i ) { @@ -283,14 +206,13 @@ int main ( int argc, char *argv [] ) } } #endif + return 0; +} - /* run this guy */ - rc = KMane ( argc, argv ); - +void +VdbTerminateSystem() +{ /* remove handlers, for what it's worth */ - for ( i = 0; i < sizeof sigs / sizeof sigs [ 0 ]; ++ i ) + for ( size_t i = 0; i < sizeof sigs / sizeof sigs [ 0 ]; ++ i ) sigaction ( sigs [ i ] . sig, & sig_saves [ i ], NULL ); - - return ( rc == 0 ) ? 0 : IF_EXITCODE(rc, 3); } - diff --git a/libs/kapp/main-priv.h b/libs/kapp/vdbapp-priv.h similarity index 60% rename from libs/kapp/main-priv.h rename to libs/kapp/vdbapp-priv.h index 7c9c82730..102ffb39c 100644 --- a/libs/kapp/main-priv.h +++ b/libs/kapp/vdbapp-priv.h @@ -24,53 +24,35 @@ * */ -#ifndef _h_main_priv_ -#define _h_main_priv_ +#pragma once -#ifndef _h_klib_defs_ -#include -#endif - -#ifndef _h_kapp_extern_ - #include -#endif +#include #ifdef __cplusplus extern "C" { #endif - -/*-------------------------------------------------------------------------- - * KMane - * invoked by platform specific "main" entrypoint - */ - -/* KMane - * executable entrypoint "main" is implemented by - * an OS-specific wrapper that takes care of establishing - * signal handlers, logging, etc. - * - * in turn, OS-specific "main" will invoke "KMain" as - * platform independent main entrypoint. - * - * "argc" [ IN ] - the number of textual parameters in "argv" - * should never be < 0, but has been left as a signed int - * for reasons of tradition. - * - * "argv" [ IN ] - array of NUL terminated strings expected - * to be in the shell-native character set: ASCII or UTF-8 - * element 0 is expected to be executable identity or path. - */ -rc_t KMane ( int argc, char *argv [] ); - /*KAppGetTotalRam * returns total physical RAM installed in the system * in bytes */ rc_t KAppGetTotalRam ( uint64_t * totalRam ); +/* VdbInitializeSystem + * OS-specific VDB initialization + */ +int VdbInitializeSystem(); + +/* VdbTerminateSystem + * OS-specific VDB termination + */ +void VdbTerminateSystem(); + +/* SetQuitting + * set the quitting flag (for internal use in this library) + */ +void SetQuitting(); + #ifdef __cplusplus } #endif - -#endif /* _h_main_priv_ */ diff --git a/libs/kapp/main.c b/libs/kapp/vdbapp.c similarity index 74% rename from libs/kapp/main.c rename to libs/kapp/vdbapp.c index 3254f6dbe..78ce598cd 100644 --- a/libs/kapp/main.c +++ b/libs/kapp/vdbapp.c @@ -25,31 +25,225 @@ */ #include -#include "main-priv.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #if ! NO_KRSRC #include -#include #include #include #endif +#include "vdbapp-priv.h" +#include +#include + +#if WINDOWS +#include +#endif + +#include +#include +#include +#include +#include /* KStsLibHandlerSetStdOut */ +#include +#include + +#include +#include + +#include #include -#include -#include -#include +static atomic32_t hangup; +static atomic32_t quitting; + +/* Hangup + * has the program received a SIGHUP + */ +rc_t Hangup ( void ) +{ + if ( atomic32_read ( & hangup ) == 0 ) + return 0; + LOGMSG ( klogInfo, "HANGUP...\n" ); + return RC ( rcExe, rcProcess, rcExecuting, rcProcess, rcIncomplete ); +} + +/* SignalNoHup + * tell the program to stay alive even after SIGHUP + */ +rc_t CC SignalNoHup ( void ) +{ // not implemented + return 0; +} + +/* Quitting + * is the program supposed to exit + */ +rc_t CC Quitting ( void ) +{ + if ( atomic32_read ( & quitting ) == 0 ) + return 0; + LOGMSG ( klogInfo, "EXITING..." ); + return RC ( rcExe, rcProcess, rcExecuting, rcProcess, rcCanceled ); +} + +/* SetQuitting + * set the quitting flag (for internal use in this library) + */ +void SetQuitting() +{ + ReportSilence (); + atomic32_inc ( & quitting ); +} + +static KNSManager * kns = NULL; +#if ! NO_KRSRC +static KCtx local_ctx, * ctx = & local_ctx; +#else +void CC atexit_task ( void ) +{ + KProcMgrWhack (); +} +#endif + +LIB_EXPORT +rc_t +VdbInitialize( int argc, char *argv [], ver_t vers ) +{ + int ret = VdbInitializeSystem(); + if ( ret != 0 ) + { + return RC( rcExe, rcProcess, rcInitializing, rcLibrary, rcFailed ); + } + +#if NO_KRSRC + int status; +#else + DECLARE_FUNC_LOC ( rcExe, rcProcess, rcExecuting ); + //UNUSED(s_func_loc); +#endif + + rc_t rc = 0; + + if ( vers == 0 ) + { // by default, use the version # of the library + SraReleaseVersion v; + memset(&v, 0, sizeof v); + SraReleaseVersionGet( &v ); + SetKAppVersion( v . version ); + vers = v . version; + } + else + { + SetKAppVersion( vers ); + } + + /* initialize error reporting */ + ReportInit ( argc, argv, vers ); + +#if NO_KRSRC + /* initialize cleanup tasks */ + status = atexit ( atexit_task ); + if ( status != 0 ) + return SILENT_RC ( rcApp, rcNoTarg, rcInitializing, rcFunction, rcNotAvailable ); + + /* initialize proc mgr */ + rc = KProcMgrInit (); + if ( rc != 0 ) + return rc; + + kns = NULL; +#else + ON_FAIL ( KRsrcGlobalInit ( & local_ctx, & s_func_loc, false ) ) + { + assert ( ctx -> rc != 0 ); + return ctx -> rc; + } + + kns = ctx -> rsrc -> kns; +#endif + + /* initialize the default User-Agent in the kns-manager to default value - using "vers" and argv[0] above strrchr '/' */ + { + char * path; + + rc = ArgsConvFilepath(NULL, 0, argv[0], string_size(argv[0]), (void**)&path, NULL); + + size_t tool_size = string_size (path); + const char* tool = path; + + const char * sep = string_rchr ( tool, tool_size, '/' ); + if ( sep ++ == NULL ) + sep = tool; + else + tool_size -= sep - tool; + + sep = string_chr ( tool = sep, tool_size, '.' ); + if ( sep != NULL ) +#if WINDOWS + if (strcmp(sep, ".exe") != 0) +#endif + tool_size = sep - tool; + + KNSManagerSetUserAgent ( kns, PKGNAMESTR " sra-toolkit %.*s.%.3V", ( uint32_t ) tool_size, tool, vers ); + + free(path); + } + + KNSManagerSetQuitting ( kns, Quitting ); + + /* initialize logging */ + rc = KWrtInit(argv[0], vers); + if ( rc == 0 ) + rc = KLogLibHandlerSetStdErr (); + if ( rc == 0 ) + rc = KStsLibHandlerSetStdOut (); + + return rc; +} + +#if WINDOWS +LIB_EXPORT +rc_t +wVdbInitialize(int argc, wchar_t* wargv[], char*** argv) +{ + rc_t rc = ConvertWArgsToUtf8(argc, wargv, argv, true); + if (rc != 0) + { + return rc; + } + + return VdbInitialize( argc, *argv, 0 ); +} +#endif + +LIB_EXPORT +int +VdbTerminate( rc_t rc ) +{ + { + rc_t r2 = 0; + if ( kns != NULL ) + r2 = KNSManagerRelease ( kns ); + else + r2 = KNSManagerSetUserAgent ( kns, NULL ); + if ( rc == 0 && r2 != 0 ) + rc = r2; + kns = NULL; + } + + /* finalize error reporting */ + ReportSilence (); + ReportFinalize ( rc ); + +#if ! NO_KRSRC + KRsrcGlobalWhack ( ctx ); +#endif + + VdbTerminateSystem(); + return rc ? 3 : 0; +} + #ifdef WINDOWS #pragma warning(disable:4127) @@ -81,11 +275,12 @@ rc_t CC KAppCheckEnvironment ( bool require64Bits, uint64_t requireRamSize ) if ( requireRamSize && totalRam < requireRamSize ) { rc = RC ( rcApp, rcNoTarg, rcInitializing, rcResources, rcUnsupported ); - PLOGERR ( klogFatal, ( klogFatal, rc, "there is not enough RAM in the system." + /* PLOGERR ( klogFatal, - to eliminate Windows warning: <=: is always true (for klogFatal)*/ + pLogLibErr ( klogFatal, rc, "there is not enough RAM in the system." " required size: $(REQUIRED) B, present: $(PRESENT) B" , "REQUIRED=%lu,PRESENT=%lu" , requireRamSize - , totalRam ) ); + , totalRam ) /* ) */; return rc; } @@ -120,7 +315,8 @@ void CC HandleAsciiToIntError ( const char *arg, void *ignore ) else rc = RC ( rcApp, rcNumeral, rcConverting, rcString, rcInvalid ); - LOGERR ( klogFatal, rc, "expected numeral" ); + /* LOGERR - to eliminate Windows warning: <=: is always true (for klogFatal)*/ + LogLibErr ( klogFatal, rc, "expected numeral" ); exit ( 10 ); } @@ -233,8 +429,9 @@ void CC logLevelFromString ( const char * str, void *data ) } /* this RC should reflect an invalid string parameter to set the log level */ - PLOGERR ( klogFatal, ( klogFatal, RC ( rcApp, rcArgv, rcParsing, rcRange, rcInvalid ), - "log level '$(lvl)' is unrecognized", "lvl=%s", str )); + /* PLOGERR ( klogFatal, -to eliminate Windows warning: <= is always true for klogFatal*/ + pLogLibErr ( klogFatal, RC ( rcApp, rcArgv, rcParsing, rcRange, rcInvalid ), + "log level '$(lvl)' is unrecognized", "lvl=%s", str ) /* ) */; exit ( 10 ); } @@ -263,11 +460,11 @@ rc_t LogLevelRelative ( const char * string ) case '+': ++ adjust; break; - + case '-': -- adjust; break; - + default: return RC ( rcApp, rcArgv, rcParsing, rcToken, rcUnrecognized ); } @@ -286,149 +483,3 @@ rc_t CC NextLogLevelCommon ( const char * level_parameter ) return LogLevelAbsolute ( level_parameter ); } - -/* KMane - * executable entrypoint "main" is implemented by - * an OS-specific wrapper that takes care of establishing - * signal handlers, logging, etc. - * - * in turn, OS-specific "main" will invoke "KMain" as - * platform independent main entrypoint. - * - * "argc" [ IN ] - the number of textual parameters in "argv" - * should never be < 0, but has been left as a signed int - * for reasons of tradition. - * - * "argv" [ IN ] - array of NUL terminated strings expected - * to be in the shell-native character set: ASCII or UTF-8 - * element 0 is expected to be executable identity or path. - */ -#if NO_KRSRC -static -void CC atexit_task ( void ) -{ - KProcMgrWhack (); -} -#endif - -rc_t KMane ( int argc, char *argv [] ) -{ - rc_t rc = 0; - KNSManager * kns = NULL; -#if NO_KRSRC - int status; -#else - KCtx local_ctx, * ctx = & local_ctx; - DECLARE_FUNC_LOC ( rcExe, rcProcess, rcExecuting ); -#endif - - /* get application version */ - ver_t vers = KAppVersion (); - - /* initialize error reporting */ - ReportInit ( argc, argv, vers ); - -#if NO_KRSRC - /* initialize cleanup tasks */ - status = atexit ( atexit_task ); - if ( status != 0 ) - return SILENT_RC ( rcApp, rcNoTarg, rcInitializing, rcFunction, rcNotAvailable ); - - /* initialize proc mgr */ - rc = KProcMgrInit (); - if ( rc != 0 ) - return rc; - - kns = NULL; -#else - ON_FAIL ( KRsrcGlobalInit ( & local_ctx, & s_func_loc, false ) ) - { - assert ( ctx -> rc != 0 ); - return ctx -> rc; - } - - kns = ctx -> rsrc -> kns; -#endif - - /* initialize the default User-Agent in the kns-manager to default value - using "vers" and argv[0] above strrchr '/' */ - { - const char * tool = argv[ 0 ]; - size_t tool_size = string_size ( tool ); - - const char * sep = string_rchr ( tool, tool_size, '/' ); - if ( sep ++ == NULL ) - sep = tool; - else - tool_size -= sep - tool; - - sep = string_chr ( tool = sep, tool_size, '.' ); - if ( sep != NULL ) - tool_size = sep - tool; - - KNSManagerSetUserAgent ( kns, PKGNAMESTR " sra-toolkit %.*s.%.3V", - ( uint32_t ) tool_size, tool, vers ); - } - - KNSManagerSetQuitting ( kns, Quitting ); - - /* initialize logging */ - rc = KWrtInit(argv[0], vers); - if ( rc == 0 ) - rc = KLogLibHandlerSetStdErr (); - if ( rc == 0 ) - rc = KStsLibHandlerSetStdOut (); - - if ( rc == 0 ) - { -#if KFG_COMMON_CREATION - KConfig *kfg; - rc = KConfigMake ( & kfg ); - if ( rc == 0 ) - { -#endif - rc = KMain ( argc, argv ); - if ( rc != 0 ) - { - -#if _DEBUGGING - rc_t rc2; - uint32_t lineno; - const char *filename, *function; - while ( GetUnreadRCInfo ( & rc2, & filename, & function, & lineno ) ) - { - pLogErr ( klogWarn, rc2, "$(filename):$(lineno) within $(function)" - , "filename=%s,lineno=%u,function=%s" - , filename - , lineno - , function - ); - } -#endif - - } - { - rc_t r2 = 0; - if ( kns != NULL ) - r2 = KNSManagerRelease ( kns ); - else - r2 = KNSManagerSetUserAgent ( kns, NULL ); - if ( rc == 0 && r2 != 0 ) - rc = r2; - kns = NULL; - } -#if KFG_COMMON_CREATION - KConfigRelease ( kfg ); - } -#endif - } - - /* finalize error reporting */ - ReportSilence (); - ReportFinalize ( rc ); - -#if ! NO_KRSRC - KRsrcGlobalWhack ( ctx ); -#endif - - return rc; -} diff --git a/libs/kapp/vdbapp.cpp b/libs/kapp/vdbapp.cpp new file mode 100644 index 000000000..3a49f160f --- /dev/null +++ b/libs/kapp/vdbapp.cpp @@ -0,0 +1,67 @@ +/*=========================================================================== +* +* PUBLIC DOMAIN NOTICE +* National Center for Biotechnology Information +* +* This software/database is a "United States Government Work" under the +* terms of the United States Copyright Act. It was written as part of +* the author's official duties as a United States Government employee and +* thus cannot be copyrighted. This software/database is freely available +* to the public for use. The National Library of Medicine and the U.S. +* Government have not placed any restriction on its use or reproduction. +* +* Although all reasonable efforts have been taken to ensure the accuracy +* and reliability of the software and data, the NLM and the U.S. +* Government do not and cannot warrant the performance or results that +* may be obtained by using this software or data. The NLM and the U.S. +* Government disclaim all warranties, express or implied, including +* warranties of performance, merchantability or fitness for any particular +* purpose. +* +* Please cite the author in any work or product based on this material. +* +* =========================================================================== +* +*/ + +#include + +using namespace VDB; + +Application::Application(int argc, char* argv[], ver_t vers) + : m_argc( argc ), m_argv( argv ), m_argvOwned ( false ) +{ + m_rc = VdbInitialize(argc, argv, vers); +} + +#if WINDOWS && UNICODE +#include +Application::Application(int argc, wchar_t* argv[], ver_t vers) + : m_argc( argc ), m_argvOwned ( false ) +{ + int status = ConvertWArgsToUtf8(argc, argv, &m_argv, true); + if (status != 0) + { + m_rc = RC(rcApp, rcArgv, rcParsing, rcParam, rcFailed); + } + else + { + m_argvOwned = true; + m_rc = VdbInitialize(argc, m_argv, vers); + } +} +#endif + +Application::~Application() +{ + VdbTerminate(m_rc); + if (m_argvOwned) + { + int i = m_argc; + while ( -- i >= 0 ) + { + free ( m_argv [ i ] ); + } + free ( m_argv ); + } +} diff --git a/test/kapp/report-kns-agent.c b/libs/kapp/version-hash.h similarity index 73% rename from test/kapp/report-kns-agent.c rename to libs/kapp/version-hash.h index 49eec09bd..88a3f2b5b 100644 --- a/test/kapp/report-kns-agent.c +++ b/libs/kapp/version-hash.h @@ -24,35 +24,5 @@ * */ -#include -#include - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x01020003; -} - -rc_t CC UsageSummary ( const char *progname ) -{ - return 0; -} - -rc_t CC Usage ( const Args *args ) -{ - return 0; -} - - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc; - const char * user_agent; - - rc = KNSManagerGetUserAgent ( &user_agent ); - if ( rc == 0 ) - printf("%s\n", user_agent); - - return rc; -} +#define HASH_NCBI_VDB "" +#define HASH_SRA_TOOLS "" diff --git a/libs/kapp/win/args-conv-os.c b/libs/kapp/win/args-conv-os.c index 87596de31..9ab80e98d 100644 --- a/libs/kapp/win/args-conv-os.c +++ b/libs/kapp/win/args-conv-os.c @@ -26,23 +26,168 @@ #include #include +#include #include -#include "main-priv-win.h" -rc_t ArgsConvFilepath(const Args * args, uint32_t arg_index, const char * arg, size_t arg_len, void ** result, WhackParamFnP * whack) +static +char* convert_arg_utf8(const wchar_t* arg) +{ + /* measure the string; assumes NUL-termination, the resulting size includes NUL */ + //wchar_cvt_string_measure(arg, &src_size, &dst_size); + int dst_size = WideCharToMultiByte(CP_UTF8, 0, arg, -1, NULL, 0, NULL, FALSE); + if (dst_size <= 0) + { + return NULL; + } + + /* allocate a UTF-8 buffer */ + char* utf8 = malloc(dst_size); + if (utf8 != NULL) + { + int ret = WideCharToMultiByte(CP_UTF8, 0, arg, -1, utf8, dst_size, NULL, FALSE); + if (ret != dst_size) + { + free(utf8); + return NULL; + } + } + + return utf8; +} + +char* CC rewrite_arg_as_path(const wchar_t* arg, bool convert_args_paths) +{ + char* utf8; + bool has_drive = false; + size_t i, dst_size; + DWORD len; + + if (arg == NULL) + { + return NULL; + } + + /* detect drive or full path */ + wchar_t rewrit[MAX_PATH]; + if (arg[0] < 128 && convert_args_paths) + { + bool rewrite = false; + + /* look for non-drive path */ + if (arg[0] == '\\' || arg[0] == '/') + { + /* full path - not network */ + if (arg[1] != '\\' && arg[1] != '/') + { + /* check for cygdrive */ + if (memcmp(arg, L"/cygdrive/", sizeof L"/cygdrive/" - sizeof L"") == 0) + arg += sizeof "/cygdrive" - 1; + else + rewrite = true; + + } + + } + /* look for drive path */ + else if (isalpha(arg[0]) && arg[1] == ':') + { + has_drive = true; + + /* look for drive relative */ + if (arg[2] != '\\' && arg[2] != '/') + rewrite = true; + } + if (rewrite) + { + /* incomplete path */ + len = GetFullPathNameW(arg, sizeof rewrit / sizeof rewrit[0], rewrit, NULL); + if (len == 0 || len >= MAX_PATH) + { + /* complain */ + return NULL; + } + arg = rewrit; + + has_drive = (isalpha(arg[0]) && arg[1] == ':'); + } + } + + /* allocate a UTF-8 buffer */ + utf8 = convert_arg_utf8(arg); + if (utf8 != NULL) + { + dst_size = string_size(utf8); + if (has_drive) + { + utf8[1] = utf8[0]; + utf8[0] = '/'; + } + + /* map all backslashes to fwdslashes */ + for (i = 0; i < dst_size; ++i) + { + if (utf8[i] == '\\') + utf8[i] = '/'; + } + } + + return utf8; +} + +int ConvertWArgsToUtf8(int argc, wchar_t* wargv[], char** argv[], bool convert_args_paths) +{ + int status = 0; + /* create a copy of args */ + *argv = calloc(argc + 1, sizeof * *argv); + if (argv == NULL) + status = 5; + else + { + int i; + /* convert wchar_t arguments to UTF-8 + rewriting anything that looks like a path */ + for (i = 0; i < argc; ++i) + { + if (convert_args_paths) + { + (*argv)[i] = rewrite_arg_as_path(wargv[i], true); + } + else + { + (*argv)[i] = convert_arg_utf8(wargv[i]); + } + + if ((*argv)[i] == NULL) + break; + } + + if (i != argc) + { + status = 6; + } + } + return status; +} + +rc_t ArgsConvFilepath(const Args* args, uint32_t arg_index, const char* arg, size_t arg_len, void** result, WhackParamFnP* whack) { wchar_t arg_wide[MAX_PATH]; - char * res; - - string_cvt_wchar_copy(arg_wide, MAX_PATH, arg, arg_len); - + char* res; + + //string_cvt_wchar_copy(arg_wide, MAX_PATH, arg, arg_len); + int size = MultiByteToWideChar(CP_UTF8, 0, arg, (int)arg_len, arg_wide, sizeof(arg_wide)-1); // reserve 1 byte for NUL + if ( size == 0 ) + return RC(rcRuntime, rcArgv, rcConverting, rcFunction, rcFailed); + arg_wide[size] = 0; + res = rewrite_arg_as_path(arg_wide, false); if (!res) - return RC (rcRuntime, rcArgv, rcConstructing, rcMemory, rcExhausted); - + return RC(rcRuntime, rcArgv, rcConstructing, rcMemory, rcExhausted); + *result = res; - + return 0; } + diff --git a/libs/kapp/win/ram.c b/libs/kapp/win/ram.c index 27743c571..9982c37ec 100644 --- a/libs/kapp/win/ram.c +++ b/libs/kapp/win/ram.c @@ -27,7 +27,7 @@ #define UNICODE 1 #define _UNICODE 1 -#include "../main-priv.h" +#include "../vdbapp-priv.h" #include #include diff --git a/interfaces/kfs/teefile.h b/libs/kapp/win/sysapp.c similarity index 55% rename from interfaces/kfs/teefile.h rename to libs/kapp/win/sysapp.c index 698e91c64..670e40d30 100644 --- a/interfaces/kfs/teefile.h +++ b/libs/kapp/win/sysapp.c @@ -24,43 +24,57 @@ * */ -#ifndef _h_kfs_teefile_ -#define _h_kfs_teefile_ +#include "../vdbapp-priv.h" -#ifndef _h_kfs_extern_ -#include -#endif +#include +#include -#ifndef _h_klib_defs_ -#include -#endif +#include -#ifdef __cplusplus -extern "C" { -#endif +/* SignalQuit + * tell the program to quit + */ +rc_t CC SignalQuit ( void ) +{ + return RC ( rcExe, rcProcess, rcSignaling, rcNoObj, rcUnknown ); +} -struct KFile; +/* SignalHup + * send the program a SIGHUP + */ +rc_t CC SignalHup ( void ) +{ + return RC ( rcExe, rcProcess, rcSignaling, rcNoObj, rcUnknown ); +} -typedef struct KTeeFile KTeeFile; +BOOL CC Our_HandlerRoutine(DWORD dwCtrlType) +{ + BOOL res = FALSE; + switch (dwCtrlType) + { + case CTRL_C_EVENT: SetQuitting(); + res = TRUE; + break; + } + return res; +} -/* ----- - * Copy can be a serialized type KFile for a KTeeFile opened for Read but - * not when opened for write. - * - * Specifically this means copy can be a KMD5File for read but not for write - * other KFile subtypes might have the same restriction. - * - * A seekless update KTeefile can be created but does not now exist. - */ -KFS_EXTERN rc_t CC KFileMakeTeeRead (const struct KFile ** self, - const struct KFile * original, - struct KFile * copy); -KFS_EXTERN rc_t CC KFileMakeTeeUpdate (struct KFile ** self, - struct KFile * original, - struct KFile * copy); +int +VdbInitializeSystem() +{ + /* must initialize COM... must initialize COM... */ + /* CoInitializeEx ( NULL, COINIT_MULTITHREADED ); */ + CoInitialize(NULL); + + SetConsoleCtrlHandler((PHANDLER_ROUTINE)Our_HandlerRoutine, TRUE); + + return 0; +} -#ifdef __cplusplus +void +VdbTerminateSystem() +{ + /* balance the COM initialization */ + CoUninitialize(); } -#endif -#endif /* _h_kfs_teefile_ */ diff --git a/libs/kapp/win/sysmain.c b/libs/kapp/win/sysmain.c deleted file mode 100644 index 30c43d5bf..000000000 --- a/libs/kapp/win/sysmain.c +++ /dev/null @@ -1,300 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#define UNICODE 1 -#define _UNICODE 1 - -#include "../main-priv.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* #define _WIN32_WINNT 0x0500 */ -/* commented out: 10/21/2010 by wolfgang - reason: Kurt introduced in sysdll.c a new functionality - which requires a newer windows-version - (i realized it as compiler parameter in build/Makefile.vc++) */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/*-------------------------------------------------------------------------- - * Main - */ - -static bool no_hup; -static atomic32_t hangup; -static atomic32_t quitting; - -static bool convert_args_paths = true; - -/* Quitting - * is the program supposed to exit - */ -rc_t CC Quitting ( void ) -{ - if ( atomic32_read ( & quitting ) == 0 ) - return 0; - LOGMSG ( klogInfo, "EXITING..." ); - return RC ( rcExe, rcProcess, rcExecuting, rcProcess, rcCanceled ); -} - -/* SignalQuit - * tell the program to quit - */ -rc_t CC SignalQuit ( void ) -{ - return RC ( rcExe, rcProcess, rcSignaling, rcNoObj, rcUnknown ); -} - -/* Hangup - * has the program received a SIGHUP - */ -rc_t CC Hangup ( void ) -{ - if ( atomic32_read ( & hangup ) == 0 ) - return 0; - LOGMSG ( klogInfo, "HANGUP...\n" ); - return RC ( rcExe, rcProcess, rcExecuting, rcProcess, rcIncomplete ); -} - -/* SignalHup - * send the program a SIGHUP - */ -rc_t CC SignalHup ( void ) -{ - return RC ( rcExe, rcProcess, rcSignaling, rcNoObj, rcUnknown ); -} - -/* SignalNoHup - * tell the program to stay alive even after SIGHUP - */ -rc_t CC SignalNoHup ( void ) -{ - no_hup = true; - return 0; -} - - -BOOL CC Our_HandlerRoutine( DWORD dwCtrlType ) -{ - BOOL res = FALSE; - switch( dwCtrlType ) - { - case CTRL_C_EVENT : ReportSilence (); - atomic32_inc ( & quitting ); - res = TRUE; - break; - } - return res; -} - - -/* main - * Windows specific main entrypoint - */ -static -int main2 ( int argc, char *argv [] ) -{ - rc_t rc; - - SetConsoleCtrlHandler( ( PHANDLER_ROUTINE ) Our_HandlerRoutine, TRUE ); - - /* run this guy */ - rc = KMane ( argc, argv ); - - return ( rc == 0 ) ? 0 : IF_EXITCODE(rc, 3); -} - -static -char * convert_arg_utf8( const wchar_t *arg ) -{ - size_t src_size, dst_size; - char * utf8; - /* measure the string */ - wchar_cvt_string_measure ( arg, & src_size, & dst_size ); - - /* allocate a UTF-8 buffer */ - utf8 = malloc ( dst_size + 1 ); - if ( utf8 != NULL ) - { - /* copy the wide argument to utf8 */ - wchar_cvt_string_copy ( utf8, dst_size + 1, - arg, src_size ); - - /* terminate the string */ - utf8 [ dst_size ] = 0; - } - - return utf8; -} - -char * CC rewrite_arg_as_path ( const wchar_t *arg, bool before_kmane ) -{ - char *utf8; - bool has_drive = false; - size_t i, dst_size; - DWORD len; - - /* detect drive or full path */ - wchar_t rewrit [ MAX_PATH ]; - /* - we don't want to rewrite twice, - so if we rewrote first time - from wmain (before_kmane = true, convert_args_paths = true), - then we skip second rewrite by checking convert_args_paths to be true - */ - if ( arg [ 0 ] < 128 && (before_kmane || !convert_args_paths)) - { - bool rewrite = false; - - /* look for non-drive path */ - if ( arg [ 0 ] == '\\' || arg [ 0 ] == '/' ) - { - /* full path - not network */ - if ( arg [ 1 ] != '\\' && arg [ 1 ] != '/' ) - { - /* check for cygdrive */ - if ( memcmp( arg, L"/cygdrive/", sizeof L"/cygdrive/" - sizeof L"" ) == 0 ) - arg += sizeof "/cygdrive" - 1; - else - rewrite = true; - - } - - } - /* look for drive path */ - else if ( isalpha ( arg [ 0 ] ) && arg [ 1 ] == ':' ) - { - has_drive = true; - - /* look for drive relative */ - if ( arg [ 2 ] != '\\' && arg [ 2 ] != '/' ) - rewrite = true; - } - if ( rewrite ) - { - /* incomplete path */ - len = GetFullPathNameW ( arg, sizeof rewrit / sizeof rewrit [ 0 ], rewrit, NULL ); - if ( len == 0 || len >= MAX_PATH ) - { - /* complain */ - return NULL; - } - arg = rewrit; - - has_drive = ( isalpha ( arg [ 0 ] ) && arg [ 1 ] == ':' ); - } - } - - /* allocate a UTF-8 buffer */ - utf8 = convert_arg_utf8 ( arg ); - if ( utf8 != NULL ) - { - dst_size = string_size(utf8); - if (has_drive) - { - utf8 [ 1 ] = utf8 [ 0 ]; - utf8 [ 0 ] = '/'; - } - - /* map all backslashes to fwdslashes */ - for ( i = 0; i < dst_size; ++ i ) - { - if ( utf8 [ i ] == '\\' ) - utf8 [ i ] = '/'; - } - } - - return utf8; -} - -int __cdecl wmain ( int argc, wchar_t *wargv [], wchar_t *envp [] ) -{ - char **argv; - int i, status = 0; - - /* must initialize COM... must initialize COM... */ - /* CoInitializeEx ( NULL, COINIT_MULTITHREADED ); */ - CoInitialize(NULL); - - /* create a copy of args */ - argv = calloc ( argc + 1, sizeof * argv ); - if ( argv == NULL ) - status = 5; - else - { - /* convert wchar_t arguments to UTF-8 - rewriting anything that looks like a path */ - for ( i = 0; i < argc; ++ i ) - { - if ( convert_args_paths ) - { - argv [ i ] = rewrite_arg_as_path ( wargv [ i ], true ); - } - else - { - argv [ i ] = convert_arg_utf8 ( wargv [ i ] ); - } - - if ( argv [ i ] == NULL ) - break; - } - - /* perform normal main operations on UTF-8 with POSIX-style paths */ - if ( i == argc ) - status = main2 ( argc, argv ); - - /* tear down argv */ - while ( -- i >= 0 ) - free ( argv [ i ] ); - free ( argv ); - } - - /* balance the COM initialization */ - CoUninitialize (); - - return status; -} - -void __declspec( dllexport ) __stdcall wmainCRTStartupNoPathConversion() -{ - convert_args_paths = false; - wmainCRTStartup(); -} diff --git a/libs/kdb/libkdb.vers.h b/libs/kdb/libkdb.vers.h index 46d1c50ca..ab8fe3d36 100644 --- a/libs/kdb/libkdb.vers.h +++ b/libs/kdb/libkdb.vers.h @@ -26,4 +26,4 @@ #pragma once -#define LIBKDB_VERS 0x03020001 +#define LIBKDB_VERS 0x03020002 diff --git a/libs/kdb/rdbmgr.c b/libs/kdb/rdbmgr.c index ff7b570b6..ef28a0cb3 100644 --- a/libs/kdb/rdbmgr.c +++ b/libs/kdb/rdbmgr.c @@ -617,12 +617,9 @@ rc_t KDBManagerVOpenDBReadInt ( const KDBManager *self, const KDatabase **dbp, /* allocate a new guy */ rc = KRDatabaseMake ( & db, dir, dbpath, self ); if ( rc == 0 ) - { * dbp = db; - return 0; - } - - KDirectoryRelease ( dir ); + else + KDirectoryRelease ( dir ); } } if (aDbpath != dbpath) diff --git a/libs/kdb/wdatabase.c b/libs/kdb/wdatabase.c index 8c67683b5..b769a8adb 100644 --- a/libs/kdb/wdatabase.c +++ b/libs/kdb/wdatabase.c @@ -46,6 +46,8 @@ #include +#include + /*-------------------------------------------------------------------------- * KDatabase * connection to a database within file system @@ -1077,7 +1079,10 @@ KWDatabaseVOpenTableRead ( const KDatabase *self, const KTable **tblp, const cha if ( rc == 0 ) { KWTable *tbl = ( KWTable* ) * tblp; - tbl -> db = KDatabaseAttach ( self ); + if ( atomic_read(&tbl->dad.refcount) == 1) + { // newly created + tbl -> db = KDatabaseAttach ( self ); + } } } diff --git a/libs/kdb/wmeta.c b/libs/kdb/wmeta.c index 8d6e94cb3..fd9cf337e 100644 --- a/libs/kdb/wmeta.c +++ b/libs/kdb/wmeta.c @@ -261,6 +261,119 @@ rc_t CC KWMDataNodeAuxFunc ( void *param, const void *node, size_t *num_writ, return rc; } +static +rc_t KWMetadataFlushToMem(KWMetadata* self, KMDFlushData* pb) +{ + rc_t rc = 0; + + /* write header */ + KDBHdr* hdr = (KDBHdr*)pb->buffer; + hdr->endian = eByteOrderTag; + hdr->version = KMETADATAVERS; + pb->marker = sizeof * hdr; + + /* persist root node */ + rc = BSTreePersist(&self->root->child, NULL, + KMDWriteFunc, pb, KWMDataNodeAuxFunc, NULL); + + return rc; +} + +static +rc_t +MetadataPopulateFromMem( + KMetadata* bself, bool read_only, const void* addr, size_t size) +{ + rc_t rc = 0; + + CAST(); + + union + { + KDBHdr v1; + KDBHdr v2; + } hdrs; + + const KDBHdr* hdr = (const KDBHdr*)addr; + const void* pbstree_src = hdr + 1; + + rc = KDBHdrValidate(hdr, size, 1, KMETADATAVERS); + if (self->read_only + && GetRCState(rc) == rcIncorrect && GetRCObject(rc) == rcByteOrder) + { + hdrs.v1.endian = bswap_32(hdr->endian); + hdrs.v1.version = bswap_32(hdr->version); + rc = KDBHdrValidate(&hdrs.v1, size, 1, KMETADATAVERS); + if (rc == 0) + { + self->byteswap = true; + switch (hdrs.v1.version) + { + case 1: + hdr = &hdrs.v1; + break; + case 2: + hdr = &hdrs.v2; + break; + } + } + } + if (rc == 0) + { + PBSTree* bst; + rc = PBSTreeMake( + &bst, pbstree_src, size - sizeof * hdr, self->byteswap); + if (rc != 0) + rc = RC(rcDB, rcMetadata, rcConstructing, rcData, rcCorrupt); + else + { + KWMDataNodeInflateData pb; + + pb.meta = self; + pb.par = self->root; + pb.bst = &self->root->child; + pb.node_size_limit = read_only ? NODE_SIZE_LIMIT : 0; + pb.node_child_limit = read_only ? NODE_CHILD_LIMIT : 0; + pb.rc = 0; + pb.byteswap = self->byteswap; + + if (hdr->version == 1) + PBSTreeDoUntil(bst, false, KWMDataNodeInflate_v1, &pb); + else + PBSTreeDoUntil(bst, false, KWMDataNodeInflate, &pb); + rc = pb.rc; + + self->vers = hdr->version; + + PBSTreeWhack(bst); + } + } + + return rc; +} + +/* Verify that we will be able to load the P_BSTree that we are going to save */ +static +rc_t +KWMetadataCheckPBSTree ( const void *addr, size_t size ) +{ + bool read_only = false; + + KWMetadata* self = NULL; + rc_t rc = KWMetadataMake(&self, NULL, "", 0, false, read_only); + + if (rc == 0) + assert(self); + + if (rc == 0) + rc = MetadataPopulateFromMem ( & self -> dad, read_only, addr, size ); + + if (rc == 0) + rc = KMetadataRelease ( & self -> dad ); + + return rc; +} + static rc_t KWMetadataFlush ( KWMetadata *self ) { @@ -280,23 +393,26 @@ rc_t KWMetadataFlush ( KWMetadata *self ) /* ZZZZ do we need a "KMD5FileReset ( pb -> fmd5 )" ? I don't think so */ if ( rc == 0 ) { - /* write header */ - KDBHdr *hdr = ( KDBHdr* ) pb . buffer; - hdr -> endian = eByteOrderTag; - hdr -> version = KMETADATAVERS; - pb . marker = sizeof * hdr; - - /* persist root node */ - rc = BSTreePersist ( & self -> root -> child, NULL, - KMDWriteFunc, & pb, KWMDataNodeAuxFunc, NULL ); + // This function writes KWMetadata to pb.buffer. + // However if the amount of data is > pb . bsize + // then pb.buffer is flushed to disk, pb . pos becomes > 0 + // and pb.buffer will contain remaining data + rc = KWMetadataFlushToMem ( self, & pb ); if ( rc == 0 && pb . marker != 0 ) { + // if (pb.pos > 0) then we cannot validate pb . buffer + if (pb.pos == 0) + rc = KWMetadataCheckPBSTree ( pb . buffer, pb . marker ); + + if ( rc == 0 ) { size_t num_flushed; rc = KFileWrite ( pb . f, pb . pos, pb . buffer, pb . marker, & num_flushed ); if ( rc == 0 && num_flushed != pb . marker ) rc = RC ( rcDB, rcMetadata, rcPersisting, rcTransfer, rcIncomplete ); + } } + pb . rc = KFileRelease ( pb . f ); if ( pb . rc == 0 ) pb . fmd5 = NULL; @@ -329,7 +445,6 @@ KWMetadataWhack ( KMetadata *bself ) rc_t rc = 0; KSymbol * symb; KDBManager *mgr = self -> mgr; - assert ( mgr != NULL ); if ( self -> dirty ) { @@ -379,10 +494,12 @@ KWMetadataWhack ( KMetadata *bself ) self -> md5 = NULL; } - /* remove from mgr */ - symb = KDBManagerOpenObjectFind (mgr, self->path); - if (symb != NULL) - { + /* mgr can we NULL when called from KWMetadataCheckPBSTree */ + if ( mgr != NULL ) { + /* remove from mgr */ + symb = KDBManagerOpenObjectFind (mgr, self->path); + if (symb != NULL) + { rc = KDBManagerOpenObjectDelete (mgr, symb); if (rc == 0) { @@ -391,14 +508,16 @@ KWMetadataWhack ( KMetadata *bself ) rc = KDBManagerSever ( mgr ); if ( rc != 0 ) KDBManagerOpenObjectAdd (mgr, symb); - else - { + } + } + } + + if ( rc == 0 ) + { /* complete */ KDirectoryRelease ( self -> dir ); KMDataNodeRelease ( & self -> root -> dad ); return KMetadataBaseWhack( bself ); - } - } } KRefcountInit ( & self -> dad . refcount, 1, "KMetadata", "whack", "kmeta" ); @@ -445,8 +564,6 @@ static rc_t KMetadataPopulate ( KMetadata *bself, const KDirectory *dir, const char *path, bool read_only ) { - CAST(); - const KFile *f; rc_t rc = KDirectoryOpenFileRead ( dir, & f, "%s", path ); if ( rc == 0 ) @@ -463,64 +580,7 @@ KMetadataPopulate ( KMetadata *bself, const KDirectory *dir, const char *path, b if ( rc == 0 ) { - union - { - KDBHdr v1; - KDBHdr v2; - } hdrs; - - const KDBHdr *hdr = ( const KDBHdr* ) addr; - const void *pbstree_src = hdr + 1; - - rc = KDBHdrValidate ( hdr, size, 1, KMETADATAVERS ); - if ( self -> read_only && GetRCState ( rc ) == rcIncorrect && GetRCObject ( rc ) == rcByteOrder ) - { - hdrs . v1 . endian = bswap_32 ( hdr -> endian ); - hdrs . v1 . version = bswap_32 ( hdr -> version ); - rc = KDBHdrValidate ( & hdrs . v1, size, 1, KMETADATAVERS ); - if ( rc == 0 ) - { - self -> byteswap = true; - switch ( hdrs . v1 . version ) - { - case 1: - hdr = & hdrs . v1; - break; - case 2: - hdr = & hdrs . v2; - break; - } - } - } - if ( rc == 0 ) - { - PBSTree *bst; - rc = PBSTreeMake ( & bst, pbstree_src, size - sizeof * hdr, self -> byteswap ); - if ( rc != 0 ) - rc = RC ( rcDB, rcMetadata, rcConstructing, rcData, rcCorrupt ); - else - { - KWMDataNodeInflateData pb; - - pb . meta = self; - pb . par = self -> root; - pb . bst = & self -> root -> child; - pb . node_size_limit = read_only ? NODE_SIZE_LIMIT : 0; - pb . node_child_limit = read_only ? NODE_CHILD_LIMIT : 0; - pb . rc = 0; - pb . byteswap = self -> byteswap; - - if ( hdr -> version == 1 ) - PBSTreeDoUntil ( bst, false, KWMDataNodeInflate_v1, & pb ); - else - PBSTreeDoUntil ( bst, false, KWMDataNodeInflate, & pb ); - rc = pb . rc; - - self -> vers = hdr -> version; - - PBSTreeWhack ( bst ); - } - } + rc = MetadataPopulateFromMem ( bself, read_only, addr, size ); } KMMapRelease ( mm ); diff --git a/libs/kdb/wmetadatanode.c b/libs/kdb/wmetadatanode.c index 1ad0312b4..0fdf84fd8 100644 --- a/libs/kdb/wmetadatanode.c +++ b/libs/kdb/wmetadatanode.c @@ -1105,7 +1105,7 @@ KWMDataNodeReadAttr ( const KMDataNode *bself, const char *name, char *buffer, s * size = 0; if ( bsize != 0 ) buffer [ 0 ] = 0; - rc = RC ( rcDB, rcMetadata, rcReading, rcAttr, rcNotFound ); + rc = SILENT_RC ( rcDB, rcMetadata, rcReading, rcAttr, rcNotFound ); } else { @@ -1117,7 +1117,7 @@ KWMDataNodeReadAttr ( const KMDataNode *bself, const char *name, char *buffer, s return 0; } - return RC ( rcDB, rcMetadata, rcReading, rcBuffer, rcInsufficient ); + return SILENT_RC ( rcDB, rcMetadata, rcReading, rcBuffer, rcInsufficient ); } } @@ -1269,10 +1269,10 @@ KMDataNodeVDropChild ( KMDataNode *bself, const char *path, va_list args ) { CAST(); - int len = 0; + int len = 0, lead = 0; rc_t rc; KWMDataNode *found; - char full [ 4096 ], *p = full; + char orig [ 4096 ], full [ 4096 ], *p = full; if ( self == NULL ) return RC ( rcDB, rcNode, rcUpdating, rcSelf, rcNull ); @@ -1284,10 +1284,6 @@ KMDataNodeVDropChild ( KMDataNode *bself, const char *path, va_list args ) return RC ( rcDB, rcNode, rcUpdating, rcPath, rcInvalid ); /* generate full path */ - /* VDB-4386: cannot treat va_list as a pointer! */ - /*if ( args == NULL ) - len = snprintf ( full, sizeof full, "%s", path ); - else*/ if ( path != NULL ) len = vsnprintf ( full, sizeof full, path, args ); if ( len < 0 || len >= sizeof full ) @@ -1297,6 +1293,21 @@ KMDataNodeVDropChild ( KMDataNode *bself, const char *path, va_list args ) if ( self -> read_only ) return RC ( rcDB, rcNode, rcUpdating, rcNode, rcReadonly ); + /* remove trailing slashes */ + while ( len > 1 && full [ len - 1 ] == '/' ) + full [ len-- - 1 ] = '\0'; + + /* remove leading slashes */ + while ( len - lead > 1 && full [ lead ] == '/' ) + ++lead; + if ( lead > 0 ) { + memmove ( full, full + lead, len - lead + 1 ); + len -= lead; + } + + /* full is updated in KWMDataNodeFind */ + string_copy ( orig, sizeof orig, full, len ); + rc = KWMDataNodeFind ( self, & found, & p ); if ( GetRCState ( rc ) == rcNotFound ) { @@ -1307,7 +1318,20 @@ KMDataNodeVDropChild ( KMDataNode *bself, const char *path, va_list args ) BSTreeInit ( & found -> child ); } else - { + { /* "/" agrument is accepted */ + char *slash = NULL; + if ( len > 1 ) + slash = string_rchr ( orig, len, '/' ); + if ( slash != NULL ) { + KMDataNode *node = NULL; + rc = KMDataNodeOpenNodeUpdate ( bself, & node, + "%.*s", slash - orig, orig ); + if ( rc == 0 ) + rc = KMDataNodeDropChild ( node, slash + 1 ); + KMDataNodeRelease ( node ); + return rc; + } + BSTreeUnlink ( & self -> child, & found -> dad . n ); KMDataNodeRelease ( & found -> dad ); } diff --git a/libs/kdb/wtrieidx-v2.c b/libs/kdb/wtrieidx-v2.c index 8aa23b57c..257b55b81 100644 --- a/libs/kdb/wtrieidx-v2.c +++ b/libs/kdb/wtrieidx-v2.c @@ -1801,7 +1801,7 @@ rc_t KWTrieIndexPersist_v2 ( const KWTrieIndex_v2 *self, { /* create the name of temporary md5 file */ char tmpmd5name [ 260 ]; - sprintf ( tmpmd5name, "%s.md5", tmpname ); + snprintf ( tmpmd5name, sizeof(tmpmd5name), "%s.md5", tmpname ); /* create the output file under temporary name ? why does it need read/write capabilities? */ diff --git a/libs/kfg/config.c b/libs/kfg/config.c index c2872d56a..0d74b8513 100644 --- a/libs/kfg/config.c +++ b/libs/kfg/config.c @@ -188,9 +188,10 @@ void CC KConfigNodeWhack ( BSTNode *n, void * data ) if ( mgr == NULL ) { /* just releasing reference */ - KConfigSever ( self -> mgr ); - self -> mgr = NULL; + mgr = self -> mgr; + self -> mgr = NULL; /* update self before releasing self -> mgr */ self -> read_only = false; + KConfigSever ( mgr ); } else { @@ -519,7 +520,7 @@ static rc_t init_token_source ( KTokenText *tt, KTokenSource *src, char *full, size_t fsize, const char *srcpath, const char *path, va_list args ) { - size_t num_writ; + size_t num_writ = 0; rc_t rc = 0; /* VDB-4386: cannot treat va_list as a pointer! */ @@ -1155,7 +1156,8 @@ LIB_EXPORT rc_t CC KConfigNodeAppend ( KConfigNode *self, const char *buffer, si LIB_EXPORT rc_t CC KConfigNodeReadAttr ( const KConfigNode *self, const char *name, char *buffer, size_t bsize, size_t *size ) { - PLOGMSG (klogFatal, (klogFatal, "$(F) unimplemented", "F=%s", __func__)); + /* PLOGMSG (klogFatal,-to eliminate warning: <=: is always true for klogFatal*/ + pLogLibMsg(klogFatal, "$(F) unimplemented", "F=%s", __func__); /* ); */ return -1; } @@ -1170,7 +1172,8 @@ LIB_EXPORT rc_t CC KConfigNodeReadAttr ( const KConfigNode *self, const char *na LIB_EXPORT rc_t CC KConfigNodeWriteAttr ( KConfigNode *self, const char *name, const char *value ) { - PLOGMSG (klogFatal, (klogFatal, "$(F) unimplemented", "F=%s", __func__)); + /* PLOGMSG (klogFatal,-to eliminate warning: <=: is always true for klogFatal*/ + pLogLibMsg(klogFatal, "$(F) unimplemented", "F=%s", __func__); /* ); */ return -1; } @@ -1189,19 +1192,22 @@ LIB_EXPORT rc_t CC KConfigNodeDropAll ( KConfigNode *self ) LIB_EXPORT rc_t CC KConfigNodeDropAttr ( KConfigNode *self, const char *attr ) { - PLOGMSG (klogFatal, (klogFatal, "$(F) unimplemented", "F=%s", __func__)); + /* PLOGMSG (klogFatal,-to eliminate warning: <=: is always true for klogFatal*/ + pLogLibMsg(klogFatal, "$(F) unimplemented", "F=%s", __func__); /* ); */ return -1; } LIB_EXPORT rc_t CC KConfigNodeVDropChild ( KConfigNode *self, const char *path, va_list args ) { - PLOGMSG (klogFatal, (klogFatal, "$(F) unimplemented", "F=%s", __func__)); + /* PLOGMSG (klogFatal,-to eliminate warning: <=: is always true for klogFatal*/ + pLogLibMsg(klogFatal, "$(F) unimplemented", "F=%s", __func__); /* ); */ return -1; } LIB_EXPORT rc_t CC KConfigNodeDropChild ( KConfigNode *self, const char *path, ... ) { - PLOGMSG (klogFatal, (klogFatal, "$(F) unimplemented", "F=%s", __func__)); + /* PLOGMSG (klogFatal,-to eliminate warning: <=: is always true for klogFatal*/ + pLogLibMsg(klogFatal, "$(F) unimplemented", "F=%s", __func__); /* ); */ return -1; } @@ -1217,13 +1223,15 @@ LIB_EXPORT rc_t CC KConfigNodeDropChild ( KConfigNode *self, const char *path, . */ LIB_EXPORT rc_t CC KConfigNodeRenameAttr ( KConfigNode *self, const char *from, const char *to ) { - PLOGMSG (klogFatal, (klogFatal, "$(F) unimplemented", "F=%s", __func__)); + /* PLOGMSG (klogFatal,-to eliminate warning: <=: is always true for klogFatal*/ + pLogLibMsg(klogFatal, "$(F) unimplemented", "F=%s", __func__); /* ); */ return -1; } LIB_EXPORT rc_t CC KConfigNodeRenameChild ( KConfigNode *self, const char *from, const char *to ) { - PLOGMSG (klogFatal, (klogFatal, "$(F) unimplemented", "F=%s", __func__)); + /* PLOGMSG (klogFatal,-to eliminate warning: <=: is always true for klogFatal*/ + pLogLibMsg(klogFatal, "$(F) unimplemented", "F=%s", __func__); /* ); */ return -1; } @@ -1307,9 +1315,10 @@ rc_t write_nvp(void* pself, const char* name, size_t nameLen, VNamelist* values) String* nameStr; /* some old config files may have "dbGaP" in their repository keys misspelled as "dbGap" - fix if seen */ + bool needsFix = false; const char* oldGaPprefix = "/repository/user/protected/dbGap-"; - size_t size = sizeof("/repository/user/protected/dbGap-") - 1; - bool needsFix = string_cmp(name, string_size(name), oldGaPprefix, size, (uint32_t)size) == 0; + size = sizeof("/repository/user/protected/dbGap-") - 1; + needsFix = string_cmp(name, string_size(name), oldGaPprefix, size, (uint32_t)size) == 0; String tmp; StringInit(&tmp, name, nameLen, (uint32_t)nameLen); @@ -1509,8 +1518,9 @@ static rc_t KConfigNodeReadData(const KConfigNode* self, char ToHex(uint32_t i) { if (i <= 9) - return '0' + i; - return 'A' + (i - 10); + return (char)('0' + i); + else + return (char)('A' + (i - 10)); } static @@ -1620,11 +1630,10 @@ static rc_t KConfigNodePrintWithIncluded (const KConfigNode *self, int indent, rc = printIndent(indent, pb); if (rc == 0) { bool found = false; - uint32_t i = 0; va_list args_copy; - if (skipCount > 0) - va_copy(args_copy, args); - for (i = 0; i < skipCount; ++i) { + if (skipCount > 0) { + va_copy(args_copy, args); + for (i = 0; i < skipCount; ++i) { const char *skip = va_arg(args_copy, const char*); if (string_cmp(skip, string_measure(skip, NULL), root, string_measure(root, NULL), string_measure(root, NULL)) @@ -1635,6 +1644,7 @@ static rc_t KConfigNodePrintWithIncluded (const KConfigNode *self, int indent, found = true; break; } + } } if (skipCount > 0) va_end(args_copy); @@ -1643,25 +1653,22 @@ static rc_t KConfigNodePrintWithIncluded (const KConfigNode *self, int indent, rc = PrintBuffPrint(pb, "<%s>", root); if ( withIncluded ) { // bool hasAny = false; - uint32_t count = 0; - KNamelist * names = NULL; - rc_t rc = KConfigListIncluded ( withIncluded, & names ); - if ( rc == 0 ) - rc = KNamelistCount ( names, & count ); - if ( rc == 0 ) { - uint32_t i = 0; - rc = printIndent(indent, pb); + rc_t r2 = KConfigListIncluded ( withIncluded, & names ); + if ( r2 == 0 ) + r2 = KNamelistCount ( names, & count ); + if ( r2 == 0 ) { + r2 = printIndent(indent, pb); PrintBuffPrint ( pb, "\n \n" ); - for ( i = 0; i < count && rc == 0; ++i ) { + for ( i = 0; i < count && r2 == 0; ++i ) { const char * name = NULL; - if ( rc == 0 ) - rc = KNamelistGet(names, i, &name); - if (rc == 0) { + if ( r2 == 0 ) + r2 = KNamelistGet(names, i, &name); + if (r2 == 0) { PrintBuffPrint ( pb, "%s\n", name ); // hasAny = true; } } - rc = printIndent(indent, pb); + r2 = printIndent(indent, pb); PrintBuffPrint ( pb, " " ); } RELEASE ( KNamelist, names ); @@ -1670,10 +1677,10 @@ static rc_t KConfigNodePrintWithIncluded (const KConfigNode *self, int indent, } if (rc == 0) { - rc_t rc = KConfigNodeReadData(self, data, sizeof data, &num_data); - DISP_RC2(rc, "KConfigNodeReadData()", root); - if (rc == 0 && num_data > 0) { - _printNodeData(root, data, num_data, + rc_t r2 = KConfigNodeReadData(self, data, sizeof data, &num_data); + DISP_RC2(r2, "KConfigNodeReadData()", root); + if (r2 == 0 && num_data > 0) { + _printNodeData(root, data, (uint32_t)num_data, native, aFullpath, !native, pb); } if (debug && self->came_from) { @@ -1937,7 +1944,7 @@ LIB_EXPORT rc_t CC KConfigLoadFile ( KConfig * self, const char * path, const KF rc = KMMapMakeRead ( & mm, file ); if ( rc == 0 ) { - size_t size; + size_t size = 0; const void * ptr; rc = KMMapAddrRead ( mm, & ptr ); if ( rc == 0 ) @@ -2628,8 +2635,9 @@ bool load_from_fs_location ( KConfig *self, const char *confdir ) { rc = KConfigAppendToLoadPath(self, resolved); } - if ((loaded = load_from_dir_path(self, dir, confdir, - string_measure ( confdir, NULL )))) + loaded = load_from_dir_path(self, dir, confdir, + string_measure(confdir, NULL)); + if (loaded) DBGMSG( DBG_KFG, DBG_FLAG(DBG_KFG), ( "KFG: found from dyn. loader %s\n", confdir ) ); KDirectoryRelease ( dir ); @@ -2966,7 +2974,7 @@ void add_predefined_nodes ( KConfig * self, const char * appname ) #if WINDOWS -static isexistingdir(const char *path, const KDirectory *dir) { +static bool isexistingdir(const char* path, const KDirectory* dir) { return (KDirectoryPathType(dir, path) & ~kptAlias) == kptDir; } @@ -3058,7 +3066,7 @@ static rc_t _KConfigNodeFixChildRepeatedDrives(KConfigNode *self, rc = KConfigNodeVOpenNodeUpdate(self, &node, name, args); if (rc == 0) { - rc_t rc = _KConfigNodeFixRepeatedDrives(node, updated, dir); + /* rc_t rc = */ _KConfigNodeFixRepeatedDrives(node, updated, dir); KConfigNodeRelease(node); } @@ -3084,28 +3092,28 @@ static rc_t _KConfigFixRepeatedDrives(KConfig *self, uint32_t i = 0; uint32_t count = 0; KNamelist *categories = NULL; - rc_t rc = KConfigNodeListChildren(user, &categories); - if (rc == 0) { /* main protected ... */ - rc = KNamelistCount(categories, &count); + rc_t r2 = KConfigNodeListChildren(user, &categories); + if (r2 == 0) { /* main protected ... */ + r2 = KNamelistCount(categories, &count); } - for (i = 0; rc == 0 && i < count; ++i) { + for (i = 0; r2 == 0 && i < count; ++i) { const char *nCategory = NULL; - rc_t rc = KNamelistGet(categories, i, &nCategory); - if (rc == 0) { /* main protected ... */ + r2 = KNamelistGet(categories, i, &nCategory); + if (r2 == 0) { /* main protected ... */ KConfigNode *category = NULL; - rc_t rc = KConfigNodeOpenNodeUpdate(user, &category, nCategory); - if (rc == 0) { - uint32_t i = 0; - uint32_t count = 0; + r2 = KConfigNodeOpenNodeUpdate(user, &category, nCategory); + if (r2 == 0) { + uint32_t j = 0; + uint32_t cnt = 0; KNamelist *subcategories = NULL; - rc_t rc = KConfigNodeListChildren(category, &subcategories); - if (rc == 0) { /* main protected ... */ - rc = KNamelistCount(subcategories, &count); + r2 = KConfigNodeListChildren(category, &subcategories); + if (r2 == 0) { /* main protected ... */ + r2 = KNamelistCount(subcategories, &cnt); } - for (i = 0; rc == 0 && i < count; ++i) { + for (j = 0; r2 == 0 && j < cnt; ++j) { const char *name = NULL; - rc_t rc = KNamelistGet(subcategories, i, &name); - if (rc == 0) { + r2 = KNamelistGet(subcategories, j, &name); + if (r2 == 0) { _KConfigNodeFixChildRepeatedDrives(category, dir, updated, "%s/%s", name, "root"); } @@ -3305,8 +3313,23 @@ static rc_t _KConfigCheckAd(KConfig * self) { const KConfigNode * kfg = NULL; KConfigNode * flat = NULL; - const char * name = "/repository/user/ad/public/apps/file/volumes/flat"; + const char * name = "/repository/user/ad/disabled"; rc_t rc = KConfigOpenNodeUpdate(self, &flat, name); + if (rc == 0) { + bool disabled = false; + rc = KConfigNodeReadBool(flat, &disabled); + { + rc_t r2 = KConfigNodeRelease(flat); + if (rc == 0 && r2 != 0) + rc = r2; + } + if (disabled) /* AD is disabled in configuration, do not fix it */ + return rc; + } + rc = 0; + + name = "/repository/user/ad/public/apps/file/volumes/flat"; + rc = KConfigOpenNodeUpdate(self, &flat, name); if (rc == 0) { rc_t r2 = 0; char buffer[1] = ""; @@ -3479,24 +3502,24 @@ rc_t KConfigMakeImpl ( KConfig ** cfg, const KDirectory * cfgdir, bool local, rc = KLockMake ( & mgr -> nodeLock ); if ( rc == 0 ) { - rc_t rc = 0; + rc_t r2 = 0; bool updated = false; if ( ! KConfigDisabledUserSettings() ) { bool updatd2 = false; - if (rc == 0) { - rc = _KConfigUsePileupAppWithExtFlatAlg(mgr, &updatd2); + if (r2 == 0) { + r2 = _KConfigUsePileupAppWithExtFlatAlg(mgr, &updatd2); updated |= updatd2; } - if (rc == 0) { - rc = _KConfigUseRealignAppWithExtFlatAlg(mgr, &updatd2); + if (r2 == 0) { + r2 = _KConfigUseRealignAppWithExtFlatAlg(mgr, &updatd2); updated |= updatd2; } - if ( rc == 0 && updated ) { + if (r2 == 0 && updated ) { KConfigCommit ( mgr ); /* keep if commit fails: */ updated = false; /* ignore rc */ } @@ -4129,7 +4152,7 @@ LIB_EXPORT rc_t CC KConfigRead ( const KConfig * self, const char * path, /* this macro wraps a call to KConfigNodeGetXXX in a node-accessing code to implement the corresponding KConfigGetXXX function */ #define NODE_TO_CONFIG_ACCESSOR(fn) \ - const KConfigNode* node; \ + const KConfigNode* node = NULL; \ assert(self); \ rc_t rc = KLockAcquire ( self->nodeLock ), rc2 = 0; \ if (rc == 0) \ @@ -4525,7 +4548,6 @@ static rc_t _KConfigMkPwdFileAndNode(KConfig *self, ncbiHome = NULL; if (rc == 0) { - size_t num_writ = 0; assert(result && result->addr); rc = string_printf(encryptionKeyPath, sizeof encryptionKeyPath, &num_writ, "%s/dbGaP-%s.enc_key", result->addr, kgc->projectId); diff --git a/libs/kfs/CMakeLists.txt b/libs/kfs/CMakeLists.txt index 775012df3..5eebcb992 100644 --- a/libs/kfs/CMakeLists.txt +++ b/libs/kfs/CMakeLists.txt @@ -66,7 +66,6 @@ set( KFS_CMN tocfile sra tar - teefile buffile buffile-read buffile-write diff --git a/libs/kfs/arc.c b/libs/kfs/arc.c index 2f6c3ed1e..334eeda5f 100644 --- a/libs/kfs/arc.c +++ b/libs/kfs/arc.c @@ -515,6 +515,7 @@ static rc_t KArcListingInit (KArcListing *self, } else { + void *r = NULL; const char *name; @@ -599,6 +600,7 @@ static rc_t KArcListingInit (KArcListing *self, */ else { + free( self->namelist ); self->namelist = r; } } @@ -1098,7 +1100,6 @@ rc_t CC KArcDirList (const KArcDir *self, if (rc == 0) { KArcListing *list = malloc (sizeof *list); - if (list == NULL) { rc = RC (rcFS, rcDirectory, rcListing, rcMemory, rcExhausted); diff --git a/libs/kfs/cacheteefile3.c b/libs/kfs/cacheteefile3.c index befeb59f7..c6968cd38 100644 --- a/libs/kfs/cacheteefile3.c +++ b/libs/kfs/cacheteefile3.c @@ -1061,6 +1061,8 @@ rc_t CC KCacheTeeFileTimedReadImpl ( const KCacheTeeFile_v3 *cself, uint64_t cur_thread_id = CUR_THREAD_ID (); + assert ( num_read ); + /* 1. limit request to file dimensions */ if ( pos >= self -> source_size || bsize == 0 ) { @@ -1184,6 +1186,10 @@ rc_t CC KCacheTeeFileTimedReadImpl ( const KCacheTeeFile_v3 *cself, rc = KCacheTeeFileReadFromFile ( self, pos, buffer, bsize, num_read, initial_page_idx ); } + if ( self -> dad . read_observer_update != NULL ) + ( * self -> dad . read_observer_update ) + ( self -> dad . read_observer, rc, pos, buffer, *num_read ); + /* 9. release lock */ STATUS ( STAT_PRG, "%lu: %s - releasing cache mutex\n", cur_thread_id, __func__ ); KLockUnlock ( self -> cache_lock ); @@ -1283,7 +1289,7 @@ rc_t CC KCacheTeeFileReadChunked ( const KCacheTeeFile_v3 *self, uint64_t pos, KChunkReader * chunks, size_t bsize, size_t * total_read ) { rc_t rc = 0; - size_t total, num_read; + size_t total, num_read = 0; assert ( chunks != NULL ); @@ -1332,7 +1338,7 @@ rc_t CC KCacheTeeFileTimedReadChunked ( const KCacheTeeFile_v3 *self, uint64_t p KChunkReader * chunks, size_t bsize, size_t * total_read, struct timeout_t * tm ) { rc_t rc = 0; - size_t total, num_read; + size_t total, num_read = 0; assert ( chunks != NULL ); @@ -2103,6 +2109,8 @@ rc_t KCacheTeeFileOpen ( KCacheTeeFile_v3 * self, KDirectory * dir, const KFile KFileRelease ( self -> cache_file ); self -> cache_file = NULL; } + else + STATUS (STAT_PWR, "Use '%s' as cache file\n", self -> path); } /* always break */ diff --git a/libs/kfs/file.c b/libs/kfs/file.c index 114b154c6..eb5c34b30 100644 --- a/libs/kfs/file.c +++ b/libs/kfs/file.c @@ -49,8 +49,17 @@ LIB_EXPORT rc_t CC KFileDestroy_v1 ( KFile_v1 *self ) switch ( self -> vt -> v1 . maj ) { - case 1: - return ( * self -> vt -> v1 . destroy ) ( self ); + case 1: { + rc_t rc = 0, r2 = 0; + if ( self -> read_observer_destroy != NULL ) + rc = ( * self -> read_observer_destroy ) ( self -> read_observer ); + self -> read_observer = NULL; + + r2 = ( * self -> vt -> v1 . destroy ) ( self ); + if ( rc == 0 && r2 != 0 ) + rc = r2; + return rc; + } } return RC ( rcFS, rcFile, rcDestroying, rcInterface, rcBadVersion ); @@ -241,8 +250,14 @@ LIB_EXPORT rc_t CC KFileRead_v1 ( const KFile_v1 *self, uint64_t pos, switch ( self -> vt -> v1 . maj ) { - case 1: - return ( * self -> vt -> v1 . read ) ( self, pos, buffer, bsize, num_read ); + case 1: { + rc_t rc = ( * self -> vt -> v1 . read ) + ( self, pos, buffer, bsize, num_read ); + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos, buffer, *num_read ); + return rc; + } } return RC ( rcFS, rcFile, rcReading, rcInterface, rcBadVersion ); @@ -269,12 +284,22 @@ LIB_EXPORT rc_t CC KFileTimedRead_v1 ( const KFile_v1 *self, uint64_t pos, switch ( self -> vt -> v1 . maj ) { - case 1: + case 1: { + rc_t rc = ~0; if ( self -> vt -> v1 . min >= 2 ) - return ( * self -> vt -> v1 . timed_read ) ( self, pos, buffer, bsize, num_read, tm ); - if ( tm == NULL ) - return ( * self -> vt -> v1 . read ) ( self, pos, buffer, bsize, num_read ); + rc = ( * self -> vt -> v1 . timed_read ) + ( self, pos, buffer, bsize, num_read, tm ); + else if ( tm == NULL ) + rc = ( * self -> vt -> v1 . read ) + ( self, pos, buffer, bsize, num_read ); + if ( rc != ~0 ) { + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos, buffer, *num_read ); + return rc; + } break; + } } return RC ( rcFS, rcFile, rcReading, rcInterface, rcBadVersion ); @@ -322,6 +347,9 @@ LIB_EXPORT rc_t CC KFileReadAll_v1 ( const KFile_v1 *self, uint64_t pos, case 1: count = 0; rc = ( * self -> vt -> v1 . read ) ( self, pos, buffer, bsize, & count ); + if ( self -> read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos, buffer, count ); total = count; STATUS ( STAT_GEEK, "%s initial read rc = %R, count = %zu\n", __func__, rc, count ); @@ -339,6 +367,10 @@ LIB_EXPORT rc_t CC KFileReadAll_v1 ( const KFile_v1 *self, uint64_t pos, { count = 0; rc = ( * self -> vt -> v1 . timed_read ) ( self, pos + total, b + total, bsize - total, & count, & no_block ); + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos + total, + b + total, count ); STATUS ( STAT_GEEK, "%s ( %p, %lu, %p, %zu, [ %zu ] )\n", __func__, self, pos + total, b + total, bsize - total, count ); if ( rc != 0 ) { @@ -360,6 +392,10 @@ LIB_EXPORT rc_t CC KFileReadAll_v1 ( const KFile_v1 *self, uint64_t pos, { count = 0; rc = ( * self -> vt -> v1 . read ) ( self, pos + total, b + total, bsize - total, & count ); + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos + total, + b + total, count ); STATUS ( STAT_GEEK, "%s ( %p, %lu, %p, %zu, [ %zu ] )\n", __func__, self, pos + total, b + total, bsize - total, count ); if ( rc != 0 ) { @@ -418,6 +454,9 @@ LIB_EXPORT rc_t CC KFileTimedReadAll_v1 ( const KFile_v1 *self, uint64_t pos, { count = 0; rc = ( * self -> vt -> v1 . timed_read ) ( self, pos, buffer, bsize, & count, tm ); + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos, buffer, count ); total = count; if ( rc == 0 && count != 0 && count < bsize ) @@ -429,6 +468,10 @@ LIB_EXPORT rc_t CC KFileTimedReadAll_v1 ( const KFile_v1 *self, uint64_t pos, { count = 0; rc = ( * self -> vt -> v1 . timed_read ) ( self, pos + total, b + total, bsize - total, & count, & no_block ); + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos + total, + b + total, count ); if ( rc != 0 ) break; if ( count == 0 ) @@ -446,6 +489,10 @@ LIB_EXPORT rc_t CC KFileTimedReadAll_v1 ( const KFile_v1 *self, uint64_t pos, { count = 0; rc = ( * self -> vt -> v1 . read ) ( self, pos + total, b + total, bsize - total, & count ); + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos + total, + b + total, count ); if ( rc != 0 ) break; if ( count == 0 ) @@ -489,7 +536,7 @@ LIB_EXPORT rc_t CC KFileTimedReadAll_v1 ( const KFile_v1 *self, uint64_t pos, LIB_EXPORT rc_t CC KFileReadExactly_v1 ( const KFile_v1 *self, uint64_t pos, void *buffer, size_t bytes ) { - rc_t rc; + rc_t rc = 0; uint8_t *b; size_t total, count; @@ -511,6 +558,10 @@ LIB_EXPORT rc_t CC KFileReadExactly_v1 ( const KFile_v1 *self, { count = 0; rc = ( * self -> vt -> v1 . read ) ( self, pos + total, b + total, bytes - total, & count ); + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos + total, + b + total, count ); if ( rc != 0 ) { if ( GetRCObject ( rc ) != ( enum RCObject ) rcTimeout || GetRCState ( rc ) != rcExhausted ) @@ -533,7 +584,7 @@ LIB_EXPORT rc_t CC KFileReadExactly_v1 ( const KFile_v1 *self, LIB_EXPORT rc_t CC KFileTimedReadExactly_v1 ( const KFile_v1 *self, uint64_t pos, void *buffer, size_t bytes, struct timeout_t *tm ) { - rc_t rc; + rc_t rc = 0; uint8_t *b; size_t total, count; @@ -557,6 +608,10 @@ LIB_EXPORT rc_t CC KFileTimedReadExactly_v1 ( const KFile_v1 *self, { count = 0; rc = ( * self -> vt -> v1 . timed_read ) ( self, pos + total, b + total, bytes - total, & count, tm ); + if ( self->read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self -> read_observer, rc, pos + total, + b + total, count ); if ( rc != 0 ) { if ( tm != NULL ) @@ -579,6 +634,10 @@ LIB_EXPORT rc_t CC KFileTimedReadExactly_v1 ( const KFile_v1 *self, { count = 0; rc = ( * self -> vt -> v1 . read ) ( self, pos + total, b + total, bytes - total, & count ); + if ( self -> read_observer_update != NULL ) + ( * self -> read_observer_update ) + ( self->read_observer, rc, pos + total, + b + total, count ); if ( rc != 0 ) { if ( GetRCObject ( rc ) != ( enum RCObject ) rcTimeout || GetRCState ( rc ) != rcExhausted ) @@ -905,7 +964,7 @@ LIB_EXPORT rc_t CC KFileTimedWriteAll_v1 ( KFile_v1 *self, uint64_t pos, LIB_EXPORT rc_t CC KFileWriteExactly_v1 ( KFile_v1 *self, uint64_t pos, const void *buffer, size_t size ) { - rc_t rc; + rc_t rc = 0; const uint8_t *b; size_t total, count; @@ -949,7 +1008,7 @@ LIB_EXPORT rc_t CC KFileWriteExactly_v1 ( KFile_v1 *self, uint64_t pos, LIB_EXPORT rc_t CC KFileTimedWriteExactly_v1 ( KFile_v1 *self, uint64_t pos, const void *buffer, size_t size, struct timeout_t *tm ) { - rc_t rc; + rc_t rc = 0; const uint8_t *b; size_t total, count; @@ -1083,6 +1142,10 @@ LIB_EXPORT rc_t CC KFileInit ( KFile_v1 *self, const KFile_vt *vt, self -> read_enabled = ( uint8_t ) ( read_enabled != 0 ); self -> write_enabled = ( uint8_t ) ( write_enabled != 0 ); + self -> read_observer = NULL; + self -> read_observer_destroy = NULL; + self -> read_observer_update = NULL; + return 0; } @@ -1225,3 +1288,21 @@ LIB_EXPORT rc_t CC KFileMakeStdErr ( KFile_v1 **std_err ) { return KFileMakeStdErr_v1 ( std_err ); } + + +LIB_EXPORT rc_t CC KFileSetReadObserver( + KFile * self, + void (CC * read_observer_update) + (void *self, rc_t rc, uint64_t pos, void *buffer, size_t num_read), + rc_t (CC * read_observer_destroy) (void *self), + void *read_observer) +{ + if (self == NULL) + return RC(rcFS, rcFile, rcUpdating, rcSelf, rcNull); + + self->read_observer_update = read_observer_update; + self->read_observer_destroy = read_observer_destroy; + self->read_observer = read_observer; + + return 0; +} diff --git a/libs/kfs/md5.c b/libs/kfs/md5.c index 386fb08c6..a5b5d30e8 100644 --- a/libs/kfs/md5.c +++ b/libs/kfs/md5.c @@ -1,4 +1,4 @@ -/*======================================================================================= +/*============================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information @@ -30,12 +30,15 @@ struct KMD5File; #include #include #include + #include #include -#include #include #include +#include /* string_printf */ #include +#include + #include #include @@ -1917,4 +1920,179 @@ LIB_EXPORT rc_t CC KFileMakeNewMD5Read ( const KFile **fp, } -/* end of file */ +/* + * Observer to calculate md5 checksum when KFile is read + */ +struct KFileMD5ReadObserver { + KRefcount refcount; + bool completed; /* entire file was read */ + bool finished; /* digest is ready */ + uint8_t digest[16]; + uint64_t size; /* file size, 0 if unknown */ + uint64_t pos; /* last processed position in file */ + MD5State md5; +}; + +LIB_EXPORT rc_t CC KFileMD5ReadObserverAddRef( + const KFileMD5ReadObserver *self) +{ + if (self != NULL) { + switch (KRefcountAdd(&self->refcount, "KFileMD5ReadObserver")) + { + case krefLimit: + return RC(rcFS, rcFile, rcAttaching, rcRange, rcExcessive); + case krefNegative: + return RC(rcFS, rcFile, rcAttaching, rcSelf, rcInvalid); + default: + break; + } + } + + return 0; +} + +LIB_EXPORT rc_t CC KFileMD5ReadObserverRelease( + const KFileMD5ReadObserver *self) +{ + if (self != NULL) { + switch (KRefcountDrop(&self->refcount, "KFileMD5ReadObserver")) { + case krefWhack: + memset((void*)self, 0, sizeof *self); + free((void*)self); + return 0; + case krefNegative: + return RC(rcNS, rcMgr, rcAttaching, rcRefcount, rcInvalid); + } + } + + return 0; +} + +LIB_EXPORT rc_t CC KFileMD5ReadObserverGetDigest( + const KFileMD5ReadObserver *cself, uint8_t digest[16], + const char **error) +{ + KFileMD5ReadObserver *self = (KFileMD5ReadObserver*)cself; + + if (error != NULL) + *error = NULL; + + if (self == NULL) + return RC(rcFS, rcFile, rcReading, rcSelf, rcNull); + + if (!self->completed) { + if (error != NULL) { + size_t num_writ = 0; + string_printf(NULL, 0, &num_writ, + "The file was not read to the end; it was read to byte %lu " + "of %lu.", self->pos, self->size); + if (num_writ > 0) { + rc_t rc = 0; + char *e = malloc(num_writ + 1); + if (e == NULL) + return RC(rcFS, rcFile, rcUpdating, rcMemory, rcExhausted); + if (self->size > 0) + rc = string_printf(e, num_writ + 1, &num_writ, + "The file was not read to the end; it was read " + "to byte %lu of %lu.", self->pos, self->size); + else + rc = string_printf(e, num_writ + 1, &num_writ, + "The file was not read to the end; it was read " + "to byte %lu.", self->pos); + if (rc != 0) { + free(e); + e = NULL; + } + *error = e; + } + } + + return RC(rcFS, rcFile, rcReading, rcFile, rcIncomplete); + } + + if (!self->finished) { + MD5StateFinish(&self->md5, self->digest); + self->finished = true; + } + + memmove(digest, self->digest, sizeof self->digest); + return 0; +} + +static void CC read_observer_update( + void *self, rc_t rc, uint64_t pos, void *vbuffer, size_t num_read) +{ + KFileMD5ReadObserver * observer = (KFileMD5ReadObserver*)self; + unsigned char *buffer = (unsigned char*)vbuffer; + + if (rc != 0 || observer == NULL) + return; + + if (observer->completed) + return; + + if (pos > observer->pos) /* a part of file was skipped */ + return; + + if (pos < observer->pos) { + uint64_t diff = 0; + if (pos + num_read <= observer->pos) /* this part was read before */ + return; + diff = observer->pos - pos; + buffer += diff; + num_read -= diff; + } + + if (num_read == 0) { + observer->completed = true; + return; + } + + MD5StateAppend(&observer->md5, buffer, num_read); + observer->pos += num_read; + + if (observer->size > 0 && observer->pos >= observer->size) + observer->completed = true; +} + +static rc_t CC read_observer_destroy(void *self ) +{ return KFileMD5ReadObserverRelease(self); } + +LIB_EXPORT rc_t CC KFileMakeMD5ReadObserver(const KFile *self, + const KFileMD5ReadObserver **observer) +{ + rc_t rc = 0; + KFileMD5ReadObserver * obj = NULL; + + if (observer == NULL) + return RC(rcFS, rcFile, rcUpdating, rcParam, rcNull); + *observer = NULL; + + if (self == NULL) + return RC(rcFS, rcFile, rcUpdating, rcSelf, rcNull); + + obj = calloc(1, sizeof * obj); + if (obj == NULL) + return RC(rcFS, rcFile, rcUpdating, rcMemory, rcExhausted); + + rc = KFileSize(self, &obj->size); + if (rc != 0) + obj->size = 0; + + KRefcountInit(&obj->refcount, 1, "KFileMD5ReadObserver", "make", "file"); + + MD5StateInit(&obj->md5); + + rc = KFileSetReadObserver( + (KFile*)self, read_observer_update, read_observer_destroy, obj); + + if (rc == 0) + rc = KFileMD5ReadObserverAddRef(obj); + + if (rc == 0) + *observer = obj; + + return rc; +} + +/******************************************************************************/ diff --git a/libs/kfs/teefile.c b/libs/kfs/teefile.c deleted file mode 100644 index 17f9d2acc..000000000 --- a/libs/kfs/teefile.c +++ /dev/null @@ -1,532 +0,0 @@ -/*=========================================================================== - * - * PUBLIC DOMAIN NOTICE - * National Center for Biotechnology Information - * - * This software/database is a "United States Government Work" under the - * terms of the United States Copyright Act. It was written as part of - * the author's official duties as a United States Government employee and - * thus cannot be copyrighted. This software/database is freely available - * to the public for use. The National Library of Medicine and the U.S. - * Government have not placed any restriction on its use or reproduction. - * - * Although all reasonable efforts have been taken to ensure the accuracy - * and reliability of the software and data, the NLM and the U.S. - * Government do not and cannot warrant the performance or results that - * may be obtained by using this software or data. The NLM and the U.S. - * Government disclaim all warranties, express or implied, including - * warranties of performance, merchantability or fitness for any particular - * purpose. - * - * Please cite the author in any work or product based on this material. - * - * =========================================================================== - */ - -#include -/* #include */ -/* #include */ -/* #include */ -/* #include */ -/* #include */ -/* #include */ -/* #include */ -/* #include */ -/* #include */ -/* #include */ - -/* #include */ -/* #include */ -/* #include */ -/* #include */ -#include -#include -#include -#include -#include - -#include -/* #include */ -/* #include */ -#include -/* #include */ - -/* ====================================================================== - * KTeeFile - * a file inside an archive - */ - -/* ----- - * define the specific types to be used in the templatish/inheritancish - * definition of vtables and their elements - */ -#define KFILE_IMPL struct KTeeFile -#include - -static rc_t CC KTeeFileDestroy (KTeeFile *self); -static struct KSysFile *CC KTeeFileGetSysFile (const KTeeFile *self, - uint64_t *offset); -static rc_t CC KTeeFileRandomAccessRead (const KTeeFile *self); -static rc_t CC KTeeFileRandomAccessUpdate (const KTeeFile *self); -static uint32_t CC KTeeFileType (const KTeeFile *self); -static rc_t CC KTeeFileSize (const KTeeFile *self, uint64_t *size); -static rc_t CC KTeeFileSetSizeRead (KTeeFile *self, uint64_t size); -static rc_t CC KTeeFileSetSizeUpdate (KTeeFile *self, uint64_t size); -static rc_t CC KTeeFileRead (const KTeeFile *self, uint64_t pos, - void *buffer, size_t bsize, size_t *num_read); -static rc_t CC KTeeFileWriteRead (KTeeFile *self, uint64_t pos, const void *buffer, - size_t size, size_t *num_writ); -static rc_t CC KTeeFileWriteUpdate (KTeeFile *self, uint64_t pos, const void *buffer, - size_t size, size_t *num_writ); - - -static const KFile_vt_v1 vtKTeeFileRead = -{ - /* version */ - 1, 1, - - /* 1.0 */ - KTeeFileDestroy, - KTeeFileGetSysFile, - KTeeFileRandomAccessRead, - KTeeFileSize, - KTeeFileSetSizeRead, - KTeeFileRead, - KTeeFileWriteRead, - - /* 1.1 */ - KTeeFileType -}; -static const KFile_vt_v1 vtKTeeFileUpdate = -{ - /* version */ - 1, 1, - - /* 1.0 */ - KTeeFileDestroy, - KTeeFileGetSysFile, - KTeeFileRandomAccessUpdate, - KTeeFileSize, - KTeeFileSetSizeUpdate, - KTeeFileRead, - KTeeFileWriteUpdate, - - /* 1.1 */ - KTeeFileType -}; - - -/*----------------------------------------------------------------------- - * KTeeFile - * an archive file including tar and sra - */ -struct KTeeFile -{ - KFile dad; - uint64_t maxposition; - KFile * original; - KFile * copy; -}; - -static -rc_t KTeeFileSeek (const KTeeFile *cself, uint64_t pos) -{ - KTeeFile * self; - rc_t rc = 0; - size_t num_read; - uint8_t buff [ 32 * 1024 ]; - - self = (KTeeFile *)cself; - /* seek to "pos" */ - while (self->maxposition < pos) - { - /* maximum to read in this buffer */ - size_t to_read = sizeof buff; - if (self->maxposition + sizeof buff > pos ) - to_read = (size_t) (pos - self->maxposition); - - /* read bytes */ - rc = KFileRead (&self->dad, self->maxposition, buff, to_read, &num_read ); - if ( rc != 0 ) - break; - - /* detect EOF */ - if (num_read == 0) - { - break; - } - } - - return rc; -} - - -/* ---------------------------------------------------------------------- - * KTeeFileMake - * create a new file object - */ - -static -rc_t KTeeFileMake (KTeeFile ** self, - KFile * original, - KFile * copy, - const KFile_vt * vt, - bool read_enabled, - bool write_enabled) -{ - rc_t rc; - KTeeFile * pF; - - /* ----- - * we can not accept any of the three pointer parameters as NULL - */ - assert (self != NULL); - assert (original != NULL); - assert (copy != NULL); - - /* ----- - * the enables should be true or false - */ - assert ((read_enabled == true)||(read_enabled == false)); - assert ((write_enabled == true)||(write_enabled == false)); - - /* ----- - * get space for the object - */ - pF = malloc (sizeof (KTeeFile)); - if (pF == NULL) /* allocation failed */ - { - /* fail */ - rc = RC (rcFS, rcFile, rcConstructing, rcMemory, rcExhausted); - } - else - { - rc = KFileInit (&pF->dad, /* initialize base class */ - vt, /* VTable for KTeeFile */ - "KTeeFile", "no-name", - read_enabled, /* read allowed */ - write_enabled); /* write disallowed */ - if (rc == 0) - { -/* take over the existing KFile Reference for original and copy*/ - /* succeed */ - pF->original = original; - pF->copy = copy; - pF->maxposition = 0; - *self = pF; - return 0; - } - /* fail */ - free (pF); - } - return rc; -} - -LIB_EXPORT rc_t CC KFileMakeTeeRead (const KFile ** self, const KFile * original, KFile * copy) -{ - return KTeeFileMake ((KTeeFile **)self, (KFile*)original, copy, - (const KFile_vt*)&vtKTeeFileRead, true, false); -} - -LIB_EXPORT rc_t CC KFileMakeTeeUpdate (KFile ** self, KFile * original, KFile * copy) -{ - return KTeeFileMake ((KTeeFile **)self, original, copy, - (const KFile_vt*)&vtKTeeFileUpdate, true, true); -} - -/* ---------------------------------------------------------------------- - * Destroy - * - */ -static -rc_t CC KTeeFileDestroy (KTeeFile *self) -{ - rc_t rc; - uint64_t last_max; - - assert (self != NULL); - - do - { - last_max = self->maxposition; - - /* keep seeking ahead by a Gigabyte until we read no more */ - rc = KTeeFileSeek (self, last_max + 1024*1024*1024); - if (rc != 0) - return rc; - - } while (last_max < self->maxposition); - - rc = KFileRelease (self->original); - if ( rc == 0 ) - { - KFileRelease (self->copy); - free (self); - } - return rc; -} - -/* ---------------------------------------------------------------------- - * GetSysFile - * returns an underlying system file object - * and starting offset to contiguous region - * suitable for memory mapping, or NULL if - * no such file is available. - * - * We cant allow memory mapping a tee file as the read?writes ar needed - * to trigger the writes to the copy KFile - */ - -static -struct KSysFile *CC KTeeFileGetSysFile (const KTeeFile *self, uint64_t *offset) -{ - /* parameters must be non-NULL */ - assert (self != NULL); - assert (offset != NULL); - - return NULL; -} - -/* ---------------------------------------------------------------------- - * RandomAccess - * - * returns 0 if random access, error code otherwise - * - * Update needs to be able to seek both original and copy while read - * only needs to be able to seek the original. - */ -static -rc_t CC KTeeFileRandomAccessUpdate (const KTeeFile *self) -{ - rc_t rc; - assert (self != NULL); - rc = KFileRandomAccess (self->original); - if (rc == 0) - rc = KFileRandomAccess (self->copy); - return rc; -} -static -rc_t CC KTeeFileRandomAccessRead (const KTeeFile *self) -{ - rc_t rc; - assert (self != NULL); - rc = KFileRandomAccess (self->original); - return rc; -} - -/* ---------------------------------------------------------------------- - * Type - * returns a KFileDesc - * not intended to be a content type, - * but rather an implementation class - */ -static -uint32_t CC KTeeFileType (const KTeeFile *self) -{ - return KFileType (self->original); -} - - -/* ---------------------------------------------------------------------- - * Size - * returns size in bytes of file - * - * "size" [ OUT ] - return parameter for file size - */ -static -rc_t CC KTeeFileSize (const KTeeFile *self, uint64_t *size) -{ - rc_t rc; - uint64_t fsize; - - assert (self != NULL); - assert (size != NULL); - - rc = KFileSize (self->original, &fsize); - - if (rc == 0) - { - /* success */ - *size = fsize; - } - /* pass along RC value */ - return rc; -} - -/* ---------------------------------------------------------------------- - * SetSize - * sets size in bytes of file - * - * "size" [ IN ] - new file size - */ -static -rc_t CC KTeeFileSetSizeUpdate (KTeeFile *self, uint64_t size) -{ - rc_t rc; - - rc = KFileSetSize (self->original, size); - if (rc == 0) - rc = KFileSetSize (self->copy, size); - return rc; -} -static -rc_t CC KTeeFileSetSizeRead (KTeeFile *self, uint64_t size) -{ - return RC (rcFS, rcFile, rcUpdating, rcSelf, rcUnsupported); -} - -/* ---------------------------------------------------------------------- - * Read - * read file from known position - * - * "pos" [ IN ] - starting position within file - * - * "buffer" [ OUT ] and "bsize" [ IN ] - return buffer for read - * - * "num_read" [ OUT, NULL OKAY ] - optional return parameter - * giving number of bytes actually read - */ -static -rc_t CC KTeeFileRead (const KTeeFile *cself, - uint64_t pos, - void *buffer, - size_t bsize, - size_t *num_read) -{ - KTeeFile * self; - uint64_t maxposition; - size_t read; - size_t written; - size_t sofar; - rc_t rc; - - - /* ----- - * self and buffer were validated as not NULL before calling here - * - * So get the KTTOCNode type: chunked files and contiguous files - * are read differently. - */ - assert (cself != NULL); - assert (buffer != NULL); - assert (num_read != NULL); - assert (bsize != 0); - - rc = 0; - read = 0; - self = (KTeeFile*)cself; - maxposition = self->maxposition; - if (pos > maxposition) - rc = KTeeFileSeek (self, pos); - if (rc == 0) - { - rc = KFileRead (self->original, pos, buffer, bsize, &read); - if (rc == 0) - { - if (pos + read > maxposition) - { - for ( sofar = (size_t)( maxposition - pos ); - sofar < read; - sofar += written) - { - rc = KFileWrite (self->copy, pos + sofar, (uint8_t*)buffer + sofar, - read - sofar, &written); - if (rc != 0) - break; - if (written == 0) - { - LOGERR (klogErr, rc, "Failure to write to copy in KTeeFileRead"); - rc = RC (rcFS, rcFile, rcReading, rcFile, rcIncomplete); - break; - } - } - maxposition = pos + sofar; - if (maxposition > self->maxposition) - self->maxposition = maxposition; - } - } - } - *num_read = read; - return rc; -} - -/* ---------------------------------------------------------------------- - * Write - * write file at known position - * - * "pos" [ IN ] - starting position within file - * - * "buffer" [ IN ] and "size" [ IN ] - data to be written - * - * "num_writ" [ OUT, NULL OKAY ] - optional return parameter - * giving number of bytes actually written - * - * Unsupported as we now treat archives as READ ONLY - */ -static -rc_t CC KTeeFileWriteUpdate (KTeeFile *self, uint64_t pos, - const void *buffer, size_t bsize, - size_t *num_writ) -{ - uint64_t max_position; - size_t writ; - size_t written; - size_t sofar; - rc_t rc; - - assert (self != NULL); - assert (buffer != NULL); - assert (num_writ != NULL); - assert (bsize != 0); - - writ = 0; - rc = 0; - if (pos > self->maxposition) - rc = KTeeFileSeek (self, pos); - if (rc == 0) - { - rc = KFileWrite (self->original, pos, buffer, bsize, &writ); - if (rc == 0) - { - for ( sofar = written = 0; sofar < writ; sofar += written) - { - rc = KFileWrite (self->copy, pos + sofar, (uint8_t*)buffer + sofar, - writ - sofar, &written); - if (rc != 0) - break; - if (written == 0) - { - rc = RC (rcFS, rcFile, rcReading, rcFile, rcIncomplete); - LOGERR (klogErr, rc, "Failure to write to copy in KTeeFileWrite"); - break; - } - } - max_position = pos + sofar; - if (max_position > self->maxposition) - self->maxposition = max_position; - } - } - *num_writ = writ; - return rc; -} -static -rc_t CC KTeeFileWriteRead (KTeeFile *self, uint64_t pos, - const void *buffer, size_t bsize, - size_t *num_writ) -{ - assert (self != NULL); - assert (buffer != NULL); - assert (num_writ != NULL); - assert (bsize != 0); - - *num_writ = 0; - return RC (rcFS, rcFile, rcWriting, rcSelf, rcUnsupported); -} - -/* ---------------------------------------------------------------------- - * - */ - - -/* end of file teefile.c */ - diff --git a/libs/kfs/win/sysdir.c b/libs/kfs/win/sysdir.c index a648d8432..3b5b26a4c 100644 --- a/libs/kfs/win/sysdir.c +++ b/libs/kfs/win/sysdir.c @@ -2695,7 +2695,7 @@ rc_t CC KSysDirOpenDirRead ( const KSysDir *self, #if _DEBUGGING char output[4096] = ""; - sprintf(output, "%ws", dir_name); + snprintf(output, sizeof(output), "%ws", dir_name); DBGMSG(DBG_KFS, DBG_FLAG(DBG_KFS_FILE), ("'%s' resolved to '%s'\n", path, output)); #endif diff --git a/libs/klib/btree.c b/libs/klib/btree.c index bfb0d3861..0ca129c2c 100644 --- a/libs/klib/btree.c +++ b/libs/klib/btree.c @@ -39,7 +39,7 @@ #include "int_checks-priv.h" - + //#define assert(e) { if ( ! (e) ) abort(); } #if ! _DEBUGGING @@ -875,8 +875,6 @@ rc_t branch_insert ( BranchNode *node, const Split *split, int32_t slot ) memmove ( & ( ( uint8_t* ) node ) [ PGSIZE - node -> key_bytes ], key, ksize + (int16_t) sizeof ( uint32_t ) ); /* enter the new transitions */ - assert ( node -> ord [ ( int ) slot - 1 ] . trans == split -> left ); - node -> ord [ ( int ) slot - 1 ] . trans = split -> left; node -> ord [ slot ] . trans = split -> right; ++ node -> count; @@ -960,7 +958,16 @@ static rc_t split_branch ( BranchNode *left, BranchNode *right, const Split *val right -> key_bytes += (int16_t) ksize; right -> ord [ i ] . key = PGSIZE - right -> key_bytes; memmove ( & rpage [ PGSIZE - right -> key_bytes ], & lpage [ left -> ord [ j ] . key ], ksize ); - right -> ord [ i - 1 ] . trans = left -> ord [ j - 1 ] . trans; + + if ( i == 0 ) + { + right -> ltrans = left -> ord [ j - 1 ] . trans; + } + else + { + right -> ord [ i - 1 ] . trans = left -> ord [ j - 1 ] . trans; + } + if(i == 0 && left->key_prefix_len > 0){ off = PGSIZE - right -> key_bytes - left -> key_prefix_len; memmove ( & rpage [ off ], lpage + left -> key_prefix, left -> key_prefix_len ); @@ -1293,7 +1300,9 @@ rc_t branch_entry ( EntryData *pb, void const *page, Split *rsplit) /* the node id is left-shifted by 1 and has the "branch-bit" indicator in the LSB. the remaining bits should NOT be zero */ - nid = cnode -> ord [ upper - 1 ] . trans; + /* NB - if "upper" is 0 and type is signed, + this will access entry -1, giving "ltrans" */ + nid = (upper == 0) ? cnode->ltrans : cnode -> ord [ upper - 1 ] . trans; assert ( ( nid >> 1 ) != 0 ); /* access child node */ @@ -1471,7 +1480,7 @@ MIN_KEY_COUNT * ( sizeof ( BranchEntry ) + sizeof ( uint32_t ) ) \ if ( key_size > MAX_KEY_SIZE) { return RC ( rcDB, rcTree, rcInserting, rcData, rcTooLong ); - } + } { EntryData pb; @@ -1830,7 +1839,7 @@ static void printf_branch(uint32_t nodeid, Pager *pager, Pager_vt const *vt ) printf("Branch id = %u:\n", (nodeid << 1) + 1); PrintBranch(node); - + { // left transition uint32_t const child = node->ltrans; if (child != 0) diff --git a/libs/klib/hashfile.c b/libs/klib/hashfile.c index 54211a4f7..514d49a92 100755 --- a/libs/klib/hashfile.c +++ b/libs/klib/hashfile.c @@ -600,12 +600,17 @@ LIB_EXPORT bool KHashFileFind( const KHashFile * self, const void * key, u8 ** table = hashtable->table; const uint64_t mask = hashtable->table_sz - 1; + KLockAcquire( seg->seglock ); + + bool ret = false; while ( 1 ) { bucket &= mask; const u8 * kv = table[bucket]; if ( kv == BUCKET_INVALID ) - return false; + { + break; + } if ( kv != BUCKET_INVISIBLE ) { @@ -632,7 +637,8 @@ LIB_EXPORT bool KHashFileFind( const KHashFile * self, const void * key, memcpy( value, bkv.value, bkv.value_size ); if ( value_size ) *value_size = bkv.value_size; - return true; + ret = true; + break; } } @@ -644,6 +650,9 @@ LIB_EXPORT bool KHashFileFind( const KHashFile * self, const void * key, ++triangle; bucket += ( triangle * ( triangle + 1 ) / 2 ); } + + KLockUnlock( seg->seglock ); + return ret; } LIB_EXPORT rc_t KHashFileAdd( KHashFile * self, const void * key, diff --git a/libs/klib/pbstree-impl.c b/libs/klib/pbstree-impl.c index 924c84328..378480822 100644 --- a/libs/klib/pbstree-impl.c +++ b/libs/klib/pbstree-impl.c @@ -804,8 +804,27 @@ rc_t CC PBSTreeImplCheckPersisted ( const P_BSTree *pt, size_t size ) const uint8_t *end, *data_start; GET32 ( data_size, pt -> data_size ); - if ( size < sizeof * pt || data_size == 0 ) + if ( data_size == 0 ) return RC ( rcCont, rcTree, rcConstructing, rcData, rcIncomplete ); + else if ( size < sizeof * pt ) { + /* size of P_BSTree without data_idx union */ + size_t dSize = sizeof * pt - sizeof pt -> data_idx; + if ( + ( data_size <= 256 /* if less than 256 nodes... */ + /* ...then v8 member of union is used */ + && + size < + dSize + sizeof pt -> data_idx . v8 [ 0 ] + /* minimum data size is 2: offset(1 byte) + minimum node name(1 byte) */ + + 2 + ) + || + ( data_size > 256 && size < sizeof * pt ) + ) + { + return RC ( rcCont, rcTree, rcConstructing, rcData, rcIncomplete ); + } + } end = ( const uint8_t* ) pt + size; diff --git a/libs/klib/printf.c b/libs/klib/printf.c index d6d7a29fa..e2fe32354 100644 --- a/libs/klib/printf.c +++ b/libs/klib/printf.c @@ -2997,7 +2997,8 @@ rc_t structured_print_engine ( KBufferedWrtHandler *out, , ( char ) c ); cvt_len = _snprintf_s(text, sizeof text, sizeof text - 1, ffmt, f64); #else - sprintf(&ffmt[++i], ".%u%c" + ++i; + snprintf(&ffmt[i], sizeof(ffmt) - i, ".%u%c" , (uint32_t)f.u.f.precision , (char)c); cvt_len = snprintf(text, sizeof text, ffmt, f64); @@ -3090,7 +3091,7 @@ rc_t structured_print_engine ( KBufferedWrtHandler *out, , VersionGetRelease((uint32_t)u64) ); #else - dst_len = sprintf ( text, cfmt + dst_len = snprintf ( text, sizeof(text), cfmt , VersionGetMajor ( ( uint32_t ) u64 ) , VersionGetMinor ( ( uint32_t ) u64 ) , VersionGetRelease ( ( uint32_t ) u64 ) @@ -3136,12 +3137,13 @@ rc_t structured_print_engine ( KBufferedWrtHandler *out, , tm->year ); #else - dst_len = sprintf ( text, "%s %s %u %u" + dst_len = snprintf ( text, sizeof(text), "%s %s %u %u" , weekdays [ tm -> weekday ] , months [ tm -> month ] , tm -> day + 1 , tm -> year ); + assert(0 < dst_len && dst_len < sizeof(text)); #endif } else @@ -3153,11 +3155,12 @@ rc_t structured_print_engine ( KBufferedWrtHandler *out, , tm->year ); #else - dst_len = sprintf ( text, "%s %u %u" + dst_len = snprintf ( text, sizeof(text), "%s %u %u" , months [ tm -> month ] , tm -> day + 1 , tm -> year ); + assert(0 < dst_len && dst_len < sizeof(text)); #endif } } @@ -3177,12 +3180,13 @@ rc_t structured_print_engine ( KBufferedWrtHandler *out, , tm->second ); #else - dst_len += sprintf ( & text [ dst_len ] + dst_len += snprintf ( & text [ dst_len ], sizeof(text) - dst_len , f . left_fill == '0' ? "%02u:%02u:%02u" : "%u:%02u:%02u" , tm -> hour , tm -> minute , tm -> second ); + assert(0 < dst_len && dst_len < sizeof(text)); #endif } else @@ -3196,13 +3200,14 @@ rc_t structured_print_engine ( KBufferedWrtHandler *out, , (tm->hour < 12) ? 'A' : 'P' ); #else - dst_len += sprintf ( & text [ dst_len ] + dst_len += snprintf ( & text [ dst_len ], sizeof(text) - dst_len , f . left_fill == '0' ? "%02u:%02u:%02u %cM" : "%u:%02u:%02u %cM" , ( tm -> hour + 11 ) % 12 + 1 , tm -> minute , tm -> second , ( tm -> hour < 12 ) ? 'A' : 'P' ); + assert(0 < dst_len && dst_len < sizeof(text)); #endif } @@ -3214,10 +3219,11 @@ rc_t structured_print_engine ( KBufferedWrtHandler *out, , tm->tzoff / 60 ); #else - dst_len += sprintf ( & text [ dst_len ] + dst_len += snprintf ( & text [ dst_len ], sizeof(text) - dst_len , " %+02d" , tm -> tzoff / 60 ); + assert(0 < dst_len && dst_len < sizeof(text)); #endif } } diff --git a/libs/klib/release-vers.h b/libs/klib/release-vers.h index 842fe64f8..8a1eaa4a6 100644 --- a/libs/klib/release-vers.h +++ b/libs/klib/release-vers.h @@ -43,7 +43,7 @@ * 'c' - release candidate * 'r' - final */ -#define RELEASE_TYPE 'r' +#define RELEASE_TYPE 'd' /* Revision of Version of current SRA Toolkit Release */ #define RELEASE_REVISION 0 diff --git a/libs/klib/report-klib.c b/libs/klib/report-klib.c index e2629124d..c42eac101 100644 --- a/libs/klib/report-klib.c +++ b/libs/klib/report-klib.c @@ -441,7 +441,7 @@ static void CC reportError3Str(uint32_t indent, rc_t rc, const char* function, #ifdef WINDOWS sprintf_s(buffer, buffer_size, "%s%s%s", v1, v2, v3); #else - sprintf(buffer, "%s%s%s", v1, v2, v3); + snprintf(buffer, buffer_size, "%s%s%s", v1, v2, v3); #endif reportErrorStrImpl(indent, rc, function, name, buffer, eol); free(buffer); @@ -886,6 +886,25 @@ LIB_EXPORT void CC ReportInit(int argc, char* argv[], ver_t tool_version) } } +LIB_EXPORT +rc_t +ReportGetVersion( ver_t * version ) +{ + rc_t rc = 0; + Report* self = NULL; + ReportGet(&self); + if ( self == NULL ) + { + rc = RC(rcApp, rcQuery, rcAccessing, rcData, rcUndefined); + } + else + { + *version = self -> tool_ver; + return 0; + } + return rc; +} + /* BuildDate * set the build date of the tool diff --git a/libs/klib/status-rc.c b/libs/klib/status-rc.c index 2a3b364d2..e9f62e5b8 100644 --- a/libs/klib/status-rc.c +++ b/libs/klib/status-rc.c @@ -24,11 +24,6 @@ * */ -// need for strchrnul -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include #include "writer-priv.h" #include @@ -36,17 +31,28 @@ #include #include #include -#include /* for strchrnul on non-linux */ #include #include #include #include +/* Copied from interfaces/os/mac/os-native.h + * and then removed from there + */ +static +char *str_chr_nul ( const char *str, int c ) +{ + int i; + for ( i = 0; str [ i ] != 0 && str [ i ] != c; ++i ) + ( void ) 0; + return & ( ( char* ) str ) [ i ]; +} + static size_t measure(char const *const str) { assert(str != NULL); - return (size_t)(strchrnul(str, ' ') - str); + return (size_t)(str_chr_nul(str, ' ') - str); } static char const *const INVALID = "INVALID"; diff --git a/libs/kns/CMakeLists.txt b/libs/kns/CMakeLists.txt index 9b58ace7b..1e582532d 100644 --- a/libs/kns/CMakeLists.txt +++ b/libs/kns/CMakeLists.txt @@ -22,10 +22,10 @@ # # =========================================================================== -set ( UNIX_SRC unix/sysmgr.c unix/syssock.c unix/sysstream.c ) -set ( BSD_SRC ${UNIX_SRC} mac/sysendpoint.c mac/syspoll.c ) -set ( LINUX_SRC ${UNIX_SRC} linux/sysendpoint.c linux/syspoll.c ) -set ( MAC_SRC ${UNIX_SRC} mac/sysendpoint.c mac/syspoll.c ) +set ( UNIX_SRC unix/sysmgr.c unix/syssock.c unix/sysstream.c unix/sysendpoint.c ) +set ( BSD_SRC ${UNIX_SRC} mac/syspoll.c ) +set ( LINUX_SRC ${UNIX_SRC} linux/syspoll.c ) +set ( MAC_SRC ${UNIX_SRC} mac/syspoll.c ) set ( WIN_SRC win/sysendpoint.c win/sysmgr.c win/syssock.c win/sysstream.c ) if( "bsd" STREQUAL ${OS} ) diff --git a/libs/kns/http-file.c b/libs/kns/http-file.c index ec199bf0d..a3a241d35 100644 --- a/libs/kns/http-file.c +++ b/libs/kns/http-file.c @@ -1355,7 +1355,7 @@ static rc_t KNSManagerVMakeHttpFileIntUnstableImpl( const KNSManager *self, rc = KClientHttpMakeRequestInt ( http, & req, & f -> block, buf_f ); if ( rc == 0 ) { - KClientHttpResult *rslt; + KClientHttpResult *rslt = NULL; KClientHttpRequestSetCloudParams ( req, need_env_token, payRequired ); if ( need_env_token ) @@ -1392,6 +1392,7 @@ static rc_t KNSManagerVMakeHttpFileIntUnstableImpl( const KNSManager *self, buf_f -> elem_count - 1, buf_f -> base, ep . ip_address, local_ep . ip_address ) ); } + KClientHttpResultRelease ( rslt ); } else { diff --git a/libs/kns/http-request.c b/libs/kns/http-request.c index a966f8d21..21f82fc21 100644 --- a/libs/kns/http-request.c +++ b/libs/kns/http-request.c @@ -1609,13 +1609,13 @@ rc_t KClientHttpRequestSendReceiveNoBodyInt ( KClientHttpRequest *self, KClientH } /* send the message and create a response */ - rc = KClientHttpSendReceiveMsg ( self -> http, _rslt, + rc = KClientHttpSendReceiveMsg ( self -> http, & rslt, (char *) buffer.base, buffer.elem_count - 1, NULL, (char *) self -> url_buffer . base ); if ( rc != 0 ) { KClientHttpClose ( self -> http ); - rc = KClientHttpSendReceiveMsg ( self -> http, _rslt, + rc = KClientHttpSendReceiveMsg ( self -> http, & rslt, (char *) buffer.base, buffer.elem_count - 1, NULL, (char *) self -> url_buffer . base ); if ( rc != 0 ) { @@ -1624,9 +1624,6 @@ rc_t KClientHttpRequestSendReceiveNoBodyInt ( KClientHttpRequest *self, KClientH } } - KDataBufferWhack( & buffer ); - - rslt = * _rslt; rslt -> expiration = expiration; /* expiration has to reach the caller */ expiration = NULL; @@ -1635,6 +1632,8 @@ rc_t KClientHttpRequestSendReceiveNoBodyInt ( KClientHttpRequest *self, KClientH if (rc != 0) return rc; + * _rslt = rslt; + /* look at status code */ switch ( rslt -> status ) { @@ -1666,6 +1665,7 @@ rc_t KClientHttpRequestSendReceiveNoBodyInt ( KClientHttpRequest *self, KClientH /* downgrade version requested */ self -> http -> vers -= 0x00010000; /* TBD - remove any HTTP/1.1 specific headers */ + KClientHttpResultRelease( rslt ); continue; } @@ -1674,6 +1674,7 @@ rc_t KClientHttpRequestSendReceiveNoBodyInt ( KClientHttpRequest *self, KClientH case 400: if ( uriForm == 1 ) { ++ uriForm; /* got 400; try to use different Request-URI form */ + KClientHttpResultRelease( rslt ); continue; } /* else no break here: tried both Request-URI forms */ diff --git a/libs/kns/linux/sysendpoint.c b/libs/kns/linux/sysendpoint.c deleted file mode 100644 index cf67bf530..000000000 --- a/libs/kns/linux/sysendpoint.c +++ /dev/null @@ -1,168 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#include -#include -#include -#include -#include -#include /* STATUS */ -#include -#include /* DBGMSG */ - -#include "stream-priv.h" - -#include -#include -#include -#include - -#include /* ERANGE definition */ - -#include - -extern int h_errno; - -/* InitDNSEndpoint - * initialize the endpoint with a DNS name and a port number - * - * "ep" [ OUT ] - address of endpoint block to be intialized - * - * "dns" [ IN ] - textual DNS address. - * - * "port" [ IN, DEFAULT 0 ] - binary port number in native integer byte order. - * if the special port number 0 is given, it represents any available port. - */ -LIB_EXPORT -rc_t CC KNSManagerInitDNSEndpoint ( struct KNSManager const *self, - KEndPoint *ep, struct String const *dns, uint16_t port ) -{ - rc_t rc = 0; - - if ( ep == NULL ) - rc = RC (rcNS, rcNoTarg, rcInitializing, rcParam, rcNull ); - else - { - if ( self == NULL ) - rc = RC ( rcNS, rcNoTarg, rcInitializing, rcSelf, rcNull ); - else if ( dns == NULL ) - rc = RC ( rcNS, rcNoTarg, rcInitializing, rcParam, rcNull ); - else if ( dns -> size == 0 ) - rc = RC ( rcNS, rcNoTarg, rcInitializing, rcSelf, rcInsufficient ); - else - { - KDataBuffer b; - char buffer [ 4096 ], * hostname = buffer; - size_t buff_size = sizeof buffer; - - if ( dns -> size >= sizeof buffer ) - { - rc = KDataBufferMakeBytes ( & b, dns -> size + 1 ); - if ( rc == 0 ) - { - hostname = b . base; - buff_size = ( size_t ) b . elem_count; - } - } - - if ( rc == 0 ) - { - size_t size; - rc = string_printf ( hostname, buff_size, & size, "%S", dns ); - - assert ( rc == 0 ); - assert ( size < buff_size ); - assert ( hostname [ size ] == 0 ); - - if ( rc == 0 ) - { - char BB [ 1024 ]; - struct hostent ret; - struct hostent * remote = NULL; - int h_errnop = 0; - int ghbnr = 0; - - ghbnr = gethostbyname_r ( - hostname, - & ret, - BB, - sizeof ( BB ), - & remote, - & h_errnop - ); - if ( ghbnr == 0 && remote != NULL ) - { - struct in_addr ** addr_list - = ( struct in_addr ** ) remote -> h_addr_list; - string_copy_measure ( ep -> ip_address, - sizeof ep -> ip_address, - inet_ntoa ( * addr_list [ 0 ] )); - STATUS ( STAT_PRG, "%s resolved to %s\n", - hostname , ep -> ip_address ); - - ep -> type = epIPV4; - memmove ( & ep -> u . ipv4 . addr, remote -> h_addr_list [ 0 ], sizeof ep -> u . ipv4 . addr ); - ep -> u . ipv4 . addr = htonl ( ep -> u . ipv4 . addr ); - ep -> u . ipv4 . port = ( uint16_t ) port; - } - else switch ( h_errnop ) - { - case HOST_NOT_FOUND: /* The specified host is unknown */ - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcNotFound ); - break; - case NO_ADDRESS: /* The requested names valid but does not have an IP address */ - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcInconsistent ); - break; -#if ! defined NO_ADDRESS || ! defined NO_DATA || NO_ADDRESS != NO_DATA - case NO_DATA: /* The requested name s valid but does not have an IP address */ - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcEmpty ); - break; -#endif - case NO_RECOVERY: /* A nonrecoverable name server error occured */ - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcDestroyed ); - break; - case TRY_AGAIN: /* A temporary error occured on an authoritative name server. Try again later */ - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcBusy ); - break; - case ERANGE: - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcExhausted ); - break; - default : - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcUnknown ); - } - } - } - - if ( hostname != buffer ) - KDataBufferWhack ( & b ); - } - - if ( rc != 0 ) - memset ( ep, 0, sizeof * ep ); - } - - return rc; -} diff --git a/libs/kns/manager.c b/libs/kns/manager.c index 69b7daead..496a27938 100644 --- a/libs/kns/manager.c +++ b/libs/kns/manager.c @@ -98,7 +98,7 @@ _Thread_local char kns_manager_sessionid [ KNSMANAGER_STRING_MAX ] = { 0 }; _Thread_local char kns_manager_pagehitid [ KNSMANAGER_STRING_MAX ] = { 0 }; _Thread_local char kns_manager_ua_suffix [ KNSMANAGER_STRING_MAX ] = { 0 }; -quitting_t quitting; +quitting_t quitting = NULL; static atomic_ptr_t kns_singleton; diff --git a/libs/kns/mac/sysendpoint.c b/libs/kns/unix/sysendpoint.c similarity index 75% rename from libs/kns/mac/sysendpoint.c rename to libs/kns/unix/sysendpoint.c index cc3f54e11..5a64051da 100644 --- a/libs/kns/mac/sysendpoint.c +++ b/libs/kns/unix/sysendpoint.c @@ -31,13 +31,15 @@ #include #include /* STATUS */ #include +#include /* DBGMSG */ #include "stream-priv.h" -#include +#define __USE_GNU #include #include -#include + +#include /* ERANGE definition */ #include @@ -96,43 +98,50 @@ rc_t CC KNSManagerInitDNSEndpoint ( struct KNSManager const *self, if ( rc == 0 ) { - struct hostent *remote = gethostbyname ( hostname ); - if ( remote != NULL ) - { - struct in_addr ** addr_list - = ( struct in_addr ** ) remote -> h_addr_list; + struct addrinfo hints; + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_INET; // IPv4 + + char port_s [ 6 ]; + rc = string_printf ( port_s, sizeof( port_s ), NULL, "%u", port ); + + struct addrinfo * res = NULL; + int ret = getaddrinfo ( hostname, port_s, & hints, & res ); + if ( ret == 0 && res != NULL ) + { + struct sockaddr_in * ipv4 + = ( struct sockaddr_in * ) res -> ai_addr; string_copy_measure ( ep -> ip_address, sizeof ep -> ip_address, - inet_ntoa ( * addr_list [ 0 ] )); + inet_ntoa ( ipv4->sin_addr ) ); STATUS ( STAT_PRG, "%s resolved to %s\n", - hostname , ep -> ip_address ); + hostname , ep -> ip_address ); ep -> type = epIPV4; - memmove ( & ep -> u . ipv4 . addr, remote -> h_addr_list [ 0 ], sizeof ep -> u . ipv4 . addr ); - ep -> u . ipv4 . addr = htonl ( ep -> u . ipv4 . addr ); + ep -> u . ipv4 . addr = htonl ( ipv4 ->sin_addr.s_addr ); ep -> u . ipv4 . port = ( uint16_t ) port; + + freeaddrinfo( res ); } - else switch ( h_errno ) + else switch ( ret ) { - case HOST_NOT_FOUND: /* The specified host is unknown */ + case EAI_NONAME: /* The specified host is unknown */ rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcNotFound ); break; - case NO_ADDRESS: /* The requested names valid but does not have an IP address */ + case EAI_NODATA: /* The requested names valid but does not have an IP address */ rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcInconsistent ); break; -#if ! defined NO_ADDRESS || ! defined NO_DATA || NO_ADDRESS != NO_DATA - case NO_DATA: /* The requested name s valid but does not have an IP address */ + case EAI_ADDRFAMILY: /* The requested name is valid but does not have an IPv4 address */ rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcEmpty ); break; -#endif - case NO_RECOVERY: /* A nonrecoverable name server error occured */ + case EAI_FAIL: /* A nonrecoverable name server error occured */ rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcDestroyed ); break; - case TRY_AGAIN: /* A temporary error occured on an authoritative name server. Try again later */ + case EAI_AGAIN: /* A temporary error occured on an authoritative name server. Try again later */ rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcBusy ); break; default : - rc = RC ( rcNS, rcNoTarg, rcValidating, rcError, rcUnknown ); + rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcUnknown ); } } } @@ -142,7 +151,7 @@ rc_t CC KNSManagerInitDNSEndpoint ( struct KNSManager const *self, } if ( rc != 0 ) - memset ( ep, 0, sizeof * ep ); + memset ( ep, 0, sizeof * ep ); } return rc; diff --git a/libs/kns/win/sysendpoint.c b/libs/kns/win/sysendpoint.c index fc05ad15c..a8acddf98 100644 --- a/libs/kns/win/sysendpoint.c +++ b/libs/kns/win/sysendpoint.c @@ -98,54 +98,47 @@ rc_t CC KNSManagerInitDNSEndpoint ( struct KNSManager const *self, if ( rc == 0 ) { - int lerrno; - struct hostent *remote = gethostbyname ( hostname ); - if ( remote != NULL ) - { - struct in_addr ** addr_list - = ( struct in_addr ** ) remote -> h_addr_list; + struct addrinfo hints; + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_INET; // IPv4 + + char port_s [ 6 ]; + rc = string_printf ( port_s, sizeof( port_s ), NULL, "%u", port ); + + struct addrinfo * res = NULL; + int ret = getaddrinfo ( hostname, port_s, & hints, & res ); + if ( ret == 0 && res != NULL ) + { + struct sockaddr_in * ipv4 + = ( struct sockaddr_in * ) res -> ai_addr; string_copy_measure ( ep -> ip_address, sizeof ep -> ip_address, - inet_ntoa ( * addr_list [ 0 ] )); + inet_ntoa ( ipv4->sin_addr ) ); STATUS ( STAT_PRG, "%s resolved to %s\n", - hostname , ep -> ip_address ); + hostname , ep -> ip_address ); ep -> type = epIPV4; - memmove ( & ep -> u . ipv4 . addr, remote -> h_addr_list [ 0 ], sizeof ep -> u . ipv4 . addr ); - ep -> u . ipv4 . addr = htonl ( ep -> u . ipv4 . addr ); + ep -> u . ipv4 . addr = htonl ( ipv4 ->sin_addr.s_addr ); ep -> u . ipv4 . port = ( uint16_t ) port; + + freeaddrinfo( res ); } - else switch ( lerrno = WSAGetLastError () ) + else switch ( ret ) { - case WSANOTINITIALISED: /* Must have WSAStartup call */ - rc = RC ( rcNS, rcNoTarg, rcInitializing, rcEnvironment, rcUndefined ); - break; - case WSAENETDOWN:/* network subsystem failed */ - rc = RC ( rcNS, rcNoTarg, rcInitializing, rcNoObj, rcFailed ); - break; - case WSAHOST_NOT_FOUND: /* Answer host not found */ + case EAI_NONAME: /* The specified host is unknown */ rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcNotFound ); break; - case WSATRY_AGAIN: /* host not found or server failure */ - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcBusy ); - break; - case WSANO_RECOVERY: /* non-recoverable error */ - rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcDestroyed ); - break; - case WSANO_DATA: /* name is valid but no data */ + case EAI_FAMILY: /* The requested name is valid but does not have an IPv4 address */ rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcEmpty ); break; - case WSAEINPROGRESS: /* call is in progress */ - rc = RC ( rcNS, rcNoTarg, rcReading, rcId, rcUndefined ); - break; - case WSAEFAULT: /* name paremeter is not valid part of addr space */ - rc = RC ( rcNS, rcNoTarg, rcReading, rcMemory, rcOutofrange ); + case EAI_FAIL: /* A nonrecoverable name server error occured */ + rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcDestroyed ); break; - case WSAEINTR: /* socket call was calanceled */ - rc = RC ( rcNS, rcNoTarg, rcReading, rcConnection, rcCanceled ); + case EAI_AGAIN: /* A temporary error occured on an authoritative name server. Try again later */ + rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcBusy ); break; - default: - rc = RC ( rcNS, rcNoTarg, rcReading, rcError, rcUnknown ); + default : + rc = RC ( rcNS, rcNoTarg, rcValidating, rcConnection, rcUnknown ); } } } diff --git a/libs/ktst/testenv.cpp b/libs/ktst/testenv.cpp index 5a9e0df81..f91f7edcd 100644 --- a/libs/ktst/testenv.cpp +++ b/libs/ktst/testenv.cpp @@ -26,14 +26,6 @@ #include -#if ALLOW_TESTING_CODE_TO_RELY_UPON_CODE_BEING_TESTED - -#include // KAppVersion -#include // ArgsWhack -#include // KOutMsg - -#endif - #include #include #include @@ -50,10 +42,6 @@ using std::string; bool TestEnv::in_child_process = false; -#if ALLOW_TESTING_CODE_TO_RELY_UPON_CODE_BEING_TESTED -struct Args* TestEnv::args = 0; -#endif - TestEnv::TestEnv(int argc, char* argv[], ArgsHandler* argsHandler) : catch_system_errors(true) , argc2(0) @@ -74,14 +62,9 @@ TestEnv::~TestEnv () } free(argv2); } - -#if ALLOW_TESTING_CODE_TO_RELY_UPON_CODE_BEING_TESTED - ArgsWhack(args); - args = NULL; -#endif } -string TestEnv::lastLocation = ""; +char TestEnv::lastLocation[] = ""; LogLevel::E TestEnv::verbosity = LogLevel::e_error; bool TestEnv::verbositySet = false; @@ -121,38 +104,6 @@ void CC TestEnv::SigHandler(int sig) noexcept exit(sig); } - -#if ALLOW_TESTING_CODE_TO_RELY_UPON_CODE_BEING_TESTED - -#define OPTION_DBG "verbose_cmd_line" -#define ALIAS_DBG "a" -static const char * dbg_usage[] = { "print command line argument processing information", NULL }; - -#define OPTION_CSE "catch_system_errors" -#define ALIAS_CSE "c" -static const char * cse_usage[] = { "[yes|y|no|n] catch system errors, default is yes", NULL }; - -#define OPTION_LOG "test_log_level" -#define ALIAS_LOG "t" -static const char * log_usage[] = { "test log level, one of:", - "'all': report all log messages", - " including the passed test notification;", - "'test_suite': show test suite messages;", - "'message': show user messages", - "'warning': report warnings issued by user;", - "'error': report all error conditions (default);", - "'fatal_error': report user or system originated fatal errors", - " (for example, memory access violation);", - "'nothing': do not report any information", NULL }; - -OptDef Options[] = { - { OPTION_DBG, ALIAS_DBG, NULL, dbg_usage, 1, false, false } - , { OPTION_CSE, ALIAS_CSE, NULL, cse_usage, 1, true , false } - , { OPTION_LOG, ALIAS_LOG, NULL, log_usage, 1, true , false } -}; - -#endif - rc_t TestEnv::process_args(int argc, char* argv[], ArgsHandler* argsHandler) { size_t arg2 = 9; @@ -164,97 +115,6 @@ rc_t TestEnv::process_args(int argc, char* argv[], ArgsHandler* argsHandler) { return RC (rcApp, rcArgv, rcAccessing, rcMemory, rcExhausted); } ++argc2; -#if ALLOW_TESTING_CODE_TO_RELY_UPON_CODE_BEING_TESTED - - rc_t rc = ArgsMakeAndHandle(&args, argc, argv, 1, - Options, sizeof Options / sizeof (OptDef)); - if (rc) - { return rc; } - - bool debug = false; - LogLevel::E detected = LogLevel::e_undefined; - do { - uint32_t pcount = 0; - - rc = ArgsOptionCount(args, OPTION_DBG, &pcount); - if (rc) - { return rc; } - if (pcount) { - debug = true; - LOG(LogLevel::e_nothing, "debug: debug was set to true\n"); - } - - rc = ArgsOptionCount(args, OPTION_CSE, &pcount); - if (rc) - { return rc; } - if (pcount) { - const char* pc = NULL; - rc = ArgsOptionValue(args, OPTION_CSE, 0, (const void **)&pc); - if (rc) - { return rc; } - if (!strcmp(pc, "n") || !strcmp(pc, "no")) { - catch_system_errors = false; - if (debug) { - LOG(LogLevel::e_nothing, - "debug: arg_catch_system_errors was set to false\n"); - } - } - else { - if (debug) { - LOG(LogLevel::e_nothing, - "debug: arg_catch_system_errors was set to true\n"); - } - } - } - - rc = ArgsOptionCount(args, OPTION_LOG, &pcount); - if (rc) - { return rc; } - if (pcount) { - const char* a = NULL; - rc = ArgsOptionValue(args, OPTION_LOG, 0, (const void **)&a); - if (rc) - { return rc; } - if (!strcmp(a, "test_suite")) - { detected = LogLevel::e_test_suite; } - else if (strcmp(a, "all" ) == 0) - { detected = LogLevel::e_all; } - else if (strcmp(a, "message") == 0) - { detected = LogLevel::e_message; } - else if (strcmp(a, "warning") == 0) - { detected = LogLevel::e_warning; } - else if (strcmp(a, "error" ) == 0) - { detected = LogLevel::e_error; } - else if (strcmp(a, "nothing") == 0) - { detected = LogLevel::e_nothing; } - else if (strcmp(a, "fatal_error") == 0) - { detected = LogLevel::e_fatal_error; } - if (detected != LogLevel::e_undefined) { - verbosity = detected; - if (debug) { - LOG(LogLevel::e_nothing, - "debug: log_level was set to " << a << std::endl); - } - } - else { - verbosity = LogLevel::e_error; - if (debug) { - LOG(LogLevel::e_nothing, - "debug: log_level was set to error\n"); - } - } - } - } while (0); - - if (verbosity == LogLevel::e_undefined) { - verbosity = LogLevel::e_error; - if (debug) { - LOG(LogLevel::e_nothing, - "debug: log_level was set to error\n"); - } - } -#else - rc_t rc = 0; bool debug = false; @@ -419,7 +279,6 @@ rc_t TestEnv::process_args(int argc, char* argv[], ArgsHandler* argsHandler) "debug: log_level was set to error\n"); } } -#endif if (rc == 0) { if (argsHandler) @@ -435,7 +294,8 @@ void ::ncbi::NK::saveLocation(const char* file, unsigned int line) std::ostringstream s; s << file << "(" << line << ")"; saveLocation_mtx.lock(); - TestEnv::lastLocation = s.str(); + strncpy( TestEnv::lastLocation, s.str().c_str(), sizeof(TestEnv::lastLocation) - 1 ); + TestEnv::lastLocation [ sizeof(TestEnv::lastLocation) - 1 ] = 0; saveLocation_mtx.unlock(); } @@ -463,48 +323,14 @@ ncbi::NK::GetTestSuite(void) } rc_t CC TestEnv::UsageSummary(const char* progname) { -#if ALLOW_TESTING_CODE_TO_RELY_UPON_CODE_BEING_TESTED - return KOutMsg( - "Usage:\n" - " %s [--verbose_cmd_line] [--catch_system_errors [yes|y|no|n]] " - "[-t ] [-h] [...]\n", progname); -#else std::cout << "Usage:\n" << progname << " [-debug] [-catch_system_errors=[yes|y|no|n]] " "[-l=] [-h] [...]\n"; return 0; -#endif } -#if ALLOW_TESTING_CODE_TO_RELY_UPON_CODE_BEING_TESTED -rc_t CC TestEnv::Usage(const Args* args) -{ - const char* progname = UsageDefaultName; - const char* fullpath = UsageDefaultName; - - rc_t rc = (args == NULL) ? - RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull): - ArgsProgram(args, &fullpath, &progname); - - if (rc != 0) - progname = fullpath = UsageDefaultName; - - UsageSummary(progname); - - KOutMsg("\nOptions:\n"); - - HelpOptionLine(ALIAS_DBG, OPTION_DBG, NULL, dbg_usage); - HelpOptionLine(ALIAS_CSE, OPTION_CSE, NULL, cse_usage); - HelpOptionLine(ALIAS_LOG, OPTION_LOG, NULL, log_usage); - KOutMsg("\n"); - HelpOptionsStandard(); - HelpVersion(fullpath, KAppVersion()); - - return rc; -} -#else rc_t CC TestEnv::Usage(const char *progname) { UsageSummary ( progname ); @@ -526,7 +352,6 @@ rc_t CC TestEnv::Usage(const char *progname) "h (help) - this help message\n"; return 0; } -#endif bool TestEnv::Sleep(unsigned int seconds) { diff --git a/libs/ktst/testrunner.cpp b/libs/ktst/testrunner.cpp index 5c0f9fcf9..8364af99e 100644 --- a/libs/ktst/testrunner.cpp +++ b/libs/ktst/testrunner.cpp @@ -29,14 +29,14 @@ using namespace ncbi::NK; TestRunner::TestRunner() : argc(0), argv(NULL) {} +TestRunner::~TestRunner() {} void TestRunner::ReportTestNumber(void) { - T::size_type sz = _cases.size(); - if (sz == 1) { - LOG(LogLevel::e_fatal_error, "Running " << sz << " test case...\n"); - } else if (sz > 1) { - LOG(LogLevel::e_fatal_error, "Running " << sz << " test cases...\n"); + if (_cases_count == 1) { + LOG(LogLevel::e_fatal_error, "Running " << _cases_count << " test case...\n"); + } else if (_cases_count > 1) { + LOG(LogLevel::e_fatal_error, "Running " << _cases_count << " test cases...\n"); } } @@ -48,18 +48,20 @@ void TestRunner::SetArgs(int p_argc, char* p_argv[]) void TestRunner::Add(ncbi::NK::TestInvoker* t) { - if (t) + if (t && _cases_count < sizeof(_cases) ) { - _cases.push_back(t); + _cases[ _cases_count ] = t; + ++ _cases_count; } } counter_t TestRunner::Run(void* globalFixture) const throw () { counter_t ec = 0; - for (TCI it = _cases.begin(); it != _cases.end(); ++it) + for( size_t i = 0; i < _cases_count; ++i ) + //for (TCI it = _cases.begin(); it != _cases.end(); ++it) { - ncbi::NK::TestInvoker* c = *it; + ncbi::NK::TestInvoker* c = _cases[ i ]; auto start = std::chrono::high_resolution_clock::now(); try { diff --git a/libs/ncbi-vdb/CMakeLists.txt b/libs/ncbi-vdb/CMakeLists.txt index 1e3109e73..fe82d0dd7 100644 --- a/libs/ncbi-vdb/CMakeLists.txt +++ b/libs/ncbi-vdb/CMakeLists.txt @@ -40,6 +40,7 @@ set( VDB_LIB_CMN_TARGETS kfc schema kdb + vdbapp ) if ( HAVE_MBEDTLS_F ) message("Using mbedtls installed in the system") diff --git a/libs/ncbi-vdb/libncbi-vdb.vers b/libs/ncbi-vdb/libncbi-vdb.vers index e4604e3af..be94e6f53 100644 --- a/libs/ncbi-vdb/libncbi-vdb.vers +++ b/libs/ncbi-vdb/libncbi-vdb.vers @@ -1 +1 @@ -3.2.1 +3.2.2 diff --git a/libs/schema/ASTBuilder-func.cpp b/libs/schema/ASTBuilder-func.cpp index b2f9bc3bf..ad4871ed7 100644 --- a/libs/schema/ASTBuilder-func.cpp +++ b/libs/schema/ASTBuilder-func.cpp @@ -100,8 +100,10 @@ FunctionDeclaration :: HandleOverload ( ctx_t ctx, const AST_FQN & p_fqn, const rc_t rc = VectorInsertUnique ( & name -> items, m_self, & idx, SFunctionSort ); if ( rc == 0 ) // overload added { + m_self->name = name -> name; return m_builder . VectorAppend ( ctx, functions, & m_self -> id, m_self ); } + if ( GetRCState ( rc ) == rcExists ) { /* an overload with the same major version exists */ /* see if new function trumps old */ @@ -114,13 +116,17 @@ FunctionDeclaration :: HandleOverload ( ctx_t ctx, const AST_FQN & p_fqn, const /* if existing is in the same schema... */ if ( ( const void* ) name == exist -> name -> u . obj ) - { - /* need to swap with old */ + { /* replace the old one with the new */ assert ( exist -> id >= VectorStart ( & functions ) ); VectorSwap ( & functions, exist -> id, m_self, & prior ); m_self -> id = exist -> id; SFunctionWhack ( (SFunction*)prior, 0 ); } + else + { /* add to the current schema */ + m_builder . VectorAppend ( ctx, functions, & m_self -> id, m_self ); + m_self -> name = name -> name; + } return true; } } @@ -178,8 +184,8 @@ FunctionDeclaration :: SetName ( ctx_t ctx, } } } - else - { + else // declared previously + { if ( ! p_canOverload || priorDecl -> type == eFactory ) { m_builder . ReportError ( ctx, "Declared earlier and cannot be overloaded", p_fqn ); @@ -187,8 +193,7 @@ FunctionDeclaration :: SetName ( ctx_t ctx, } if ( HandleOverload ( ctx, p_fqn, priorDecl ) ) - { // declared previously, this version not ignored - m_self -> name = priorDecl; + { // our version is used m_destroy = false; return true; } diff --git a/libs/schema/ASTBuilder.cpp b/libs/schema/ASTBuilder.cpp index 43c1a2820..feb1faf62 100644 --- a/libs/schema/ASTBuilder.cpp +++ b/libs/schema/ASTBuilder.cpp @@ -350,7 +350,7 @@ ASTBuilder :: EvalConstExpr ( ctx_t ctx, const AST_Expr & p_expr ) { SConstExpr* cexpr = reinterpret_cast < SConstExpr* > ( expr ); // this may change as more kinds of const expressions are supported - assert ( cexpr -> td . type_id = IntrinsicTypeId ( "U64" ) ); + assert ( cexpr -> td . type_id == IntrinsicTypeId ( "U64" ) ); ret = cexpr -> u . u64 [ 0 ]; } break; diff --git a/libs/sra/sramgr-cmn.c b/libs/sra/sramgr-cmn.c index 88d839787..0e5f6ccb0 100644 --- a/libs/sra/sramgr-cmn.c +++ b/libs/sra/sramgr-cmn.c @@ -433,6 +433,19 @@ LIB_EXPORT rc_t CC SRAMgrGetTableModDate ( const SRAMgr *self, return rc; } +static rc_t resolveTablePath( const SRAMgr *self, + char *path, size_t psize, const char *spec, ... ) +{ + rc_t rc; + + va_list args; + va_start ( args, spec ); + rc = ResolveTablePath (self, path, psize, spec, args ); + va_end ( args ); + + return rc; +} + LIB_EXPORT rc_t CC SRAMgrSingleFileArchiveExt(const SRAMgr *self, const char* spec, const bool lightweight, const char** ext) { rc_t rc; @@ -441,9 +454,8 @@ LIB_EXPORT rc_t CC SRAMgrSingleFileArchiveExt(const SRAMgr *self, const char* sp rc = RC(rcSRA, rcFile, rcConstructing, rcParam, rcNull); } else { char buf[4096]; - va_list args; - if( (rc = ResolveTablePath(self, buf, sizeof(buf), spec, args)) == 0 ) { + if( (rc = resolveTablePath(self, buf, sizeof(buf), "%s", spec)) == 0 ) { const KDBManager* kmgr; if( (rc = SRAMgrGetKDBManagerRead(self, &kmgr)) == 0 ) { int type = KDBManagerPathType(kmgr, "%s", buf) & ~kptAlias; diff --git a/libs/sraxf/format-spot-name.c b/libs/sraxf/format-spot-name.c index f9cdc28f9..879fad2a6 100644 --- a/libs/sraxf/format-spot-name.c +++ b/libs/sraxf/format-spot-name.c @@ -124,7 +124,7 @@ rc_t CC format_spot_name ( void *self, #ifdef WINDOWS j+= sprintf_s(sname+j, sizeof(sname) - j,"%d",x); #else - j+=sprintf(sname+j,"%d",x); + j += snprintf(sname+j, sizeof(sname) - j, "%d", x); #endif } else @@ -143,7 +143,7 @@ rc_t CC format_spot_name ( void *self, #ifdef WINDOWS j+=sprintf_s(sname+j, sizeof(sname) - j, "%d",y); #else - j+=sprintf(sname+j,"%d",y); + j += snprintf(sname+j, sizeof(sname) - j, "%d", y); #endif } else diff --git a/libs/sraxf/index_lookup.c b/libs/sraxf/index_lookup.c index b4d5d4a80..15d139219 100644 --- a/libs/sraxf/index_lookup.c +++ b/libs/sraxf/index_lookup.c @@ -234,7 +234,7 @@ static rc_t CC index_lookup_impl( #ifdef WINDOWS sprintf_s(query, sizeof(query), "%1X%03X%03X%03X", lane, tile, x, y); #else - sprintf(query, "%1X%03X%03X%03X", lane, tile, x, y); + snprintf(query, sizeof(query), "%1X%03X%03X%03X", lane, tile, x, y); #endif } } diff --git a/libs/sraxf/rewrite-spot-name.c b/libs/sraxf/rewrite-spot-name.c index 1de6a0dca..b7b6b6c54 100644 --- a/libs/sraxf/rewrite-spot-name.c +++ b/libs/sraxf/rewrite-spot-name.c @@ -162,7 +162,7 @@ rc_t CC illumina_rewrite_spot_name ( void *data, const VXformInfo *info, int64_t #ifdef WINDOWS coord_len = sprintf_s ( buffer, sizeof(buffer), ":%d:%d:%d:%d", a, b, c, d ); #else - coord_len = sprintf ( buffer, ":%d:%d:%d:%d", a, b, c, d ); + coord_len = snprintf ( buffer, sizeof(buffer), ":%d:%d:%d:%d", a, b, c, d ); #endif /* get size of prefix */ @@ -197,7 +197,7 @@ rc_t CC illumina_rewrite_spot_name ( void *data, const VXformInfo *info, int64_t , ( int ) i, skey , buffer ); #else - rslt -> elem_count = sprintf ( dst -> base, "%.*s%.*s%s" + rslt -> elem_count = snprintf ( dst -> base, dst->elem_count, "%.*s%.*s%s" , ( int ) prefix_len, prefix , ( int ) i, skey , buffer ); diff --git a/libs/vdb/database-cmn.c b/libs/vdb/database-cmn.c index be9831492..511f53980 100644 --- a/libs/vdb/database-cmn.c +++ b/libs/vdb/database-cmn.c @@ -111,12 +111,18 @@ rc_t CC VDatabaseWhack ( VDatabase *self ) if ( rc == 0 ) { /* complete */ - KMetadataRelease ( self -> meta ); - KDatabaseRelease ( self -> kdb ); - VSchemaRelease ( self -> schema ); + rc_t r2 = KMetadataRelease ( self -> meta ); + if (rc == 0 && r2 != 0) + rc = r2; + r2 = KDatabaseRelease ( self -> kdb ); + if (rc == 0 && r2 != 0) + rc = r2; + r2 = VSchemaRelease ( self -> schema ); + if (rc == 0 && r2 != 0) + rc = r2; free ( self ); - return 0; + return rc; } KRefcountInit ( & self -> refcount, 1, "VDatabase", "whack", "vdb" ); diff --git a/libs/vdb/database-depend.c b/libs/vdb/database-depend.c index b53ba5679..381725cb7 100644 --- a/libs/vdb/database-depend.c +++ b/libs/vdb/database-depend.c @@ -413,11 +413,12 @@ static rc_t FindRef(Ctx* ctx, const char* seqId, Resolved* resolved, VPath* acc = NULL; size_t num_writ = 0; char ncbiAcc[512] = ""; + VResolverEnableState oldState = vrUninitialized; assert(ctx && resolved); if (cacheState != -1) { - VResolverCacheEnable(ctx->resolver, cacheState); + oldState = VResolverCacheEnable(ctx->resolver, cacheState); } if (rc == 0) { @@ -508,8 +509,8 @@ static rc_t FindRef(Ctx* ctx, const char* seqId, Resolved* resolved, RELEASE(VPath, acc); - if (cacheState != -1) - VResolverCacheEnable(ctx->resolver, vrAlwaysDisable); + if (cacheState != -1 && oldState != vrUninitialized) + VResolverCacheEnable(ctx->resolver, oldState); return rc; } diff --git a/libs/vdb/libvdb.vers.h b/libs/vdb/libvdb.vers.h index 11a5c88ad..a20f220ae 100644 --- a/libs/vdb/libvdb.vers.h +++ b/libs/vdb/libvdb.vers.h @@ -24,4 +24,4 @@ * */ -#define LIBVDB_VERS 0x03020001 +#define LIBVDB_VERS 0x03020002 diff --git a/libs/vdb/phys-load.c b/libs/vdb/phys-load.c index 2f22cb429..b44f45aed 100644 --- a/libs/vdb/phys-load.c +++ b/libs/vdb/phys-load.c @@ -130,16 +130,17 @@ rc_t CC VPhysicalLoadV1Schema ( VPhysical *self, { #endif /* build sphysical name */ - sprintf ( sphysical_name, "%s_only", decoding_expr ); + snprintf ( sphysical_name, sizeof(sphysical_name), "%s_only", decoding_expr ); /* build physical decl */ - pb . pos = sprintf ( pb . buff, "version 1;" - "physical %s %s:phys#1" - "{decode{%s k=@;return %s(k);}}" - , type_expr - , sphysical_name - , enc_type - , decoding_expr + pb . pos = snprintf(pb . buff, sizeof(pb.buff) + , "version 1;" + "physical %s %s:phys#1" + "{decode{%s k=@;return %s(k);}}" + , type_expr + , sphysical_name + , enc_type + , decoding_expr ); #if ALLOW_V1_UPDATE } @@ -156,7 +157,7 @@ rc_t CC VPhysicalLoadV1Schema ( VPhysical *self, } /* build sphysical name */ - sprintf ( sphysical_name, "%s_%s", decoding_expr, & encoding_expr [ ns_size ] ); + snprintf ( sphysical_name, sizeof(sphysical_name), "%s_%s", decoding_expr, & encoding_expr [ ns_size ] ); for ( i = ns_size; sphysical_name [ i ] != 0; ++ i ) { if ( sphysical_name [ i ] == ':' ) @@ -164,15 +165,16 @@ rc_t CC VPhysicalLoadV1Schema ( VPhysical *self, } /* build physical decl */ - pb . pos = sprintf ( pb . buff, "version 1;" - "physical %s %s:phys#1" - "{encode{return %s(@);}" - "decode{%s k=@;return %s(k);}}" - , type_expr - , sphysical_name - , encoding_expr - , enc_type - , decoding_expr + pb . pos = snprintf( pb . buff, sizeof(pb.buff) + , "version 1;" + "physical %s %s:phys#1" + "{encode{return %s(@);}" + "decode{%s k=@;return %s(k);}}" + , type_expr + , sphysical_name + , encoding_expr + , enc_type + , decoding_expr ); } #endif @@ -184,15 +186,16 @@ rc_t CC VPhysicalLoadV1Schema ( VPhysical *self, else if ( GetRCState ( rc ) == rcNotFound ) { /* build sphysical name */ - sprintf ( sphysical_name, "%s_only", decoding_expr ); + snprintf( sphysical_name, sizeof(sphysical_name), "%s_only", decoding_expr ); /* build decode-only physical decl */ - pb . pos = sprintf ( pb . buff, "version 1;" - "physical %s %s:phys#1" - "{decode{opaque k=@;return %s(k);}}" - , type_expr - , sphysical_name - , decoding_expr + pb . pos = snprintf( pb . buff, sizeof(pb.buff) + , "version 1;" + "physical %s %s:phys#1" + "{decode{opaque k=@;return %s(k);}}" + , type_expr + , sphysical_name + , decoding_expr ); rc = 0; } @@ -206,7 +209,7 @@ rc_t CC VPhysicalLoadV1Schema ( VPhysical *self, VTypedecl etd; /* create a new expression object */ - sprintf ( pb . buff, "%s:phys#1", sphysical_name ); + snprintf ( pb . buff, sizeof(pb.buff), "%s:phys#1", sphysical_name ); rc = VSchemaImplicitPhysEncExpr ( schema, & etd, & self -> enc, pb . buff, "VPhysicalLoadV1Schema" ); if ( rc != 0 ) diff --git a/libs/vdb/prod-cmn.c b/libs/vdb/prod-cmn.c index 4c0307937..7ba167dd1 100644 --- a/libs/vdb/prod-cmn.c +++ b/libs/vdb/prod-cmn.c @@ -1567,13 +1567,13 @@ rc_t VFunctionProdCallCompare1(VFunctionProd *self, VBlob **vblob, int64_t id, u for (k = 0, m = 0; k != count; ++k) { if (m == 0) { - sprintf(ax, "%08X>", k); - sprintf(bx, "%08X<", k); + snprintf(ax, sizeof(ax), "%08X>", k); + snprintf(bx, sizeof(bx), "%08X<", k); } f = a[k] == b[k] ? ' ': '*'; - sprintf(ax + m * 4 + 9, " %02x%c", a[k], f); + snprintf(ax + m * 4 + 9, sizeof(ax) - (m * 4 + 9), " %02x%c", a[k], f); av[m] = isprint(a[k]) ? a[k] : '.'; - sprintf(bx + m * 4 + 9, " %02x%c", b[k], f); + snprintf(bx + m * 4 + 9, sizeof(bx) - (m * 4 + 9), " %02x%c", b[k], f); bv[m] = isprint(b[k]) ? b[k] : '.'; m++; if(m == 16 || k == count - 1) { diff --git a/libs/vdb/report-vdb.c b/libs/vdb/report-vdb.c index 77c491a2d..11228a5ee 100644 --- a/libs/vdb/report-vdb.c +++ b/libs/vdb/report-vdb.c @@ -330,7 +330,7 @@ static rc_t ReportDepend(const ReportFuncs *f, else { uint32_t count = 0; rc = VDBDependenciesCount(dep, &count); - if (rc != 0) { + if (rc != 0) { reportError(indent + 1, rc, "VDBDependenciesCount"); } else { @@ -346,7 +346,7 @@ static rc_t ReportDepend(const ReportFuncs *f, else { reportOpen(indent + 1, tag, 1, "count", 'd', count); } - + rc = VDBDependenciesReportDepend1(dep, f, count, indent + 2, true, &missing); reportClose(indent + 1, tag); @@ -383,7 +383,7 @@ static rc_t CC visitor(const KDirectory* dir, ++total->files; break; } - case kptDir: + case kptDir: rc = KDirectoryVisit(dir, false, visitor, total, "%s", name); break; default: @@ -527,9 +527,9 @@ static rc_t CC ReportObj(const ReportFuncs *f, uint32_t indent, if (object || type != kptNotFound) { const char* path = fullpath ? fullpath : object ? object : "not set"; - const char* stype = type == kptTable ? "table" : + const char* stype = type == kptTable ? "table" : type == kptDatabase ? "database" : "unknown"; - const char* sfile_type = file_type == kptFile ? "archive" : + const char* sfile_type = file_type == kptFile ? "archive" : file_type == kptDir ? "dir" : "unexpected"; if (fullpath && !size_unknown) { diff --git a/libs/vdb/schema-dump.c b/libs/vdb/schema-dump.c index cac3e3330..5bc974e0f 100644 --- a/libs/vdb/schema-dump.c +++ b/libs/vdb/schema-dump.c @@ -254,23 +254,23 @@ rc_t SDumperVPrint ( SDumper *self, const char *fmt, va_list args ) switch ( * ( ++ end ) ) { case 'd': - len = sprintf ( buffer, "%d", va_arg ( args, int ) ); + len = snprintf ( buffer, sizeof(buffer), "%d", va_arg ( args, int ) ); rc = SDumperWrite ( self, buffer, len ); break; case 'u': - len = sprintf ( buffer, "%u", va_arg ( args, unsigned int ) ); + len = snprintf ( buffer, sizeof(buffer), "%u", va_arg ( args, unsigned int ) ); rc = SDumperWrite ( self, buffer, len ); break; case 'x': - len = sprintf ( buffer, "%x", va_arg ( args, unsigned int ) ); + len = snprintf ( buffer, sizeof(buffer), "%x", va_arg ( args, unsigned int ) ); rc = SDumperWrite ( self, buffer, len ); break; case 'X': - len = sprintf ( buffer, "%X", va_arg ( args, unsigned int ) ); + len = snprintf ( buffer, sizeof(buffer), "%X", va_arg ( args, unsigned int ) ); rc = SDumperWrite ( self, buffer, len ); break; case 'f': - len = sprintf ( buffer, "%f", va_arg ( args, double ) ); + len = snprintf ( buffer, sizeof(buffer), "%f", va_arg ( args, double ) ); rc = SDumperWrite ( self, buffer, len ); break; case 'l': @@ -324,7 +324,7 @@ rc_t SDumperVPrint ( SDumper *self, const char *fmt, va_list args ) rc = RC ( rcVDB, rcSchema, rcWriting, rcString, rcExcessive ); else { - len = sprintf ( buffer, "%.*s", len, va_arg ( args, const char* ) ); + len = snprintf ( buffer, sizeof(buffer), "%.*s", len, va_arg ( args, const char* ) ); rc = SDumperWrite ( self, buffer, len ); } break; diff --git a/libs/vdb/schema-expr.c b/libs/vdb/schema-expr.c index bcfd9885b..6c5cde0db 100644 --- a/libs/vdb/schema-expr.c +++ b/libs/vdb/schema-expr.c @@ -431,22 +431,22 @@ rc_t SConstExprDump ( const SConstExpr *self, SDumper *b ) self -> u . utf32 [ i ]; if ( ch >= 128 ) - sprintf ( buff, "\\u%04x", ch ); + snprintf ( buff, sizeof(buff), "\\u%04x", ch ); else if ( isprint ( ( int ) ch ) ) buff [ 0 ] = ( char ) ch, buff [ 1 ] = 0; else switch ( ch ) { case '\n': - sprintf ( buff, "\\n" ); + snprintf ( buff, sizeof(buff), "\\n" ); break; case '\r': - sprintf ( buff, "\\r" ); + snprintf ( buff, sizeof(buff), "\\r" ); break; case '\t': - sprintf ( buff, "\\t" ); + snprintf ( buff, sizeof(buff), "\\t" ); break; default: - sprintf ( buff, "\\x%02x", ch ); + snprintf ( buff, sizeof(buff), "\\x%02x", ch ); } rc = SDumperPrint ( b, buff ); diff --git a/libs/vdb/wphys.c b/libs/vdb/wphys.c index ae03d7fd6..f9afd8a05 100644 --- a/libs/vdb/wphys.c +++ b/libs/vdb/wphys.c @@ -104,9 +104,10 @@ void CC VPhysicalWhack ( void *item, void *ignore ) /* create rename strings */ char buff [ 300 ]; char *oldname, *colname, *tmpname = buff; - int sz = snprintf ( buff, sizeof buff / 3, "%.*s.tmp", + char *tmpname_end = buff + 100; + int sz = snprintf ( tmpname, tmpname_end - tmpname, "%.*s.tmp", ( int ) name -> size - 1, name -> addr + 1 ); - if ( sz < 0 || sz > sizeof buff / 3 ) + if ( sz < 0 || tmpname + sz >= tmpname_end ) { tmpname = malloc ( 3 * 4 * 1024 ); if ( tmpname == NULL ) @@ -116,15 +117,15 @@ void CC VPhysicalWhack ( void *item, void *ignore ) "colname=%.*s", ( int ) name -> size - 1, name -> addr + 1 )); return; } - - sz = snprintf ( tmpname, 4 * 1024, "%.*s.tmp", - ( int ) name -> size - 1, name -> addr + 1 ); - assert ( sz > 0 && sz < 4 * 1024 ); + tmpname_end = tmpname + 4 * 1024; + sz = snprintf ( tmpname, tmpname_end - tmpname, "%.*s.tmp", + ( int ) name -> size - 1, name -> addr + 1 ); + assert ( sz > 0 && tmpname + sz < tmpname_end ); } oldname = & tmpname [ ++ sz ]; colname = & oldname [ sz ]; - sprintf ( oldname, "%.*s.old", ( int ) name -> size - 1, name -> addr + 1 ); - sprintf ( colname, "%.*s", ( int ) name -> size - 1, name -> addr + 1 ); + snprintf ( oldname, tmpname_end - oldname, "%.*s.old", ( int ) name -> size - 1, name -> addr + 1 ); + snprintf ( colname, tmpname_end - colname, "%.*s", ( int ) name -> size - 1, name -> addr + 1 ); /* close and rename static column */ if ( self -> knode != NULL ) diff --git a/libs/vfs/SraDesc.c b/libs/vfs/SraDesc.c index 2ebd03f9b..34316bbd2 100644 --- a/libs/vfs/SraDesc.c +++ b/libs/vfs/SraDesc.c @@ -115,7 +115,7 @@ static rc_t SraDescLoadBin(SraDesc * self, return RC(rcExe, rcFile, rcReading, rcData, rcInvalid); } - q = in[8]; + q = (uint8_t)in[8]; q &= 3; if (q < 1 || q > 3) return RC(rcExe, rcFile, rcReading, rcData, rcInvalid); @@ -136,7 +136,7 @@ static rc_t SraDescLoadBin(SraDesc * self, int i = 0; for (i = 0, n.u = 0; i < 8 && from < size; ++i, ++from) - n.b[i] = in[from]; + n.b[i] = (uint8_t)in[from]; } self->_size = n.u; diff --git a/libs/vfs/manager-priv.h b/libs/vfs/manager-priv.h index dadc421d6..063855f19 100644 --- a/libs/vfs/manager-priv.h +++ b/libs/vfs/manager-priv.h @@ -59,7 +59,7 @@ typedef enum { eSCSFound, } ESdlCacheState; uint32_t VFSManagerSdlCacheCount -(const struct VFSManager * self, ESdlCacheState * state); +(const struct VFSManager * self, uint32_t * state); rc_t VFSManagerSdlCacheClear(struct VFSManager * self); /******************************************************************************/ @@ -89,7 +89,7 @@ struct VFSManager /**************************************************************************/ /* Cache of names resolve results / SDL responses */ bool notCachingSdlResponse; - ESdlCacheState trSdlState; + /* ESdlCacheState */ uint32_t trSdlState; BSTree trSdl; struct KLock * trSdlMutex; /**************************************************************************/ diff --git a/libs/vfs/manager.c b/libs/vfs/manager.c index d64efea2b..ed4abc52c 100644 --- a/libs/vfs/manager.c +++ b/libs/vfs/manager.c @@ -78,6 +78,7 @@ #include #include #include +#include /* STATUS */ #include /* ENV_VDB_REMOTE_NEED_CE */ #include #include @@ -375,7 +376,8 @@ static void CC BstCount(BSTNode * n, void * data) { } uint32_t -VFSManagerSdlCacheCount(const VFSManager * self, ESdlCacheState * state) +VFSManagerSdlCacheCount(const VFSManager * self, + /* ESdlCacheState */ uint32_t * state) { uint32_t count = 0; @@ -734,10 +736,18 @@ static rc_t wrap_in_rr_cache( KDirectory * dir, const char * get_fallback_cache_location( void ) { + static bool reported = false; + const char * c = getenv ( "TMPDIR" ); - if ( c != NULL ) - return c; - return fallback_cache_location; + if ( c == NULL ) + c = fallback_cache_location; + + if ( ! reported ) { + STATUS ( STAT_USR, "Using '%s' as cache directory\n", c ); + reported = true; + } + + return c; } @@ -845,31 +855,34 @@ static rc_t wrap_in_cachetee3( KDirectory * dir, /* if we have been given a location, we use it. CacheTeeV3 can deal with invalid/unreachable ones! */ if ( NULL != cache_loc && NULL == definitve_cache_location ) { + STATUS ( STAT_PWR, "Using '%s' as cache file\n", cache_loc ); rc = KDirectoryResolvePath ( dir, true, location, sizeof location, "%s", cache_loc ); } else { /* if we have no given location or it does not exist or it is not read/writable for us */ const String * id = make_id( path ); if ( NULL != id ) { + const char * root = NULL; + remove_on_close = true; promote = false; if ( NULL != definitve_cache_location ) { /* use definitve location ( do not try promotion, remove-on-close ) */ - rc = KDirectoryResolvePath ( dir, true, location, sizeof location, - "%s/%s.sra", - definitve_cache_location, id -> addr ); + root = definitve_cache_location; } else if ( cps -> temp_cache[ 0 ] != 0 ) { /* we have user given temp cache - location ( do not try promotion, remove-on-close ) */ - rc = KDirectoryResolvePath ( dir, true, location, sizeof location, - "%s/%s.sra", cps -> temp_cache, id -> addr ); + root = cps -> temp_cache; } else { /* fallback to hardcoded path location ( do not try promotion, remove-on-close ) */ - rc = KDirectoryResolvePath ( dir, true, location, sizeof location, - "%s/%s.sra", - get_fallback_cache_location(), id -> addr ); + root = get_fallback_cache_location(); } + STATUS ( STAT_PWR, "Using '%s' as cache directory\n", root ); + rc = KDirectoryResolvePath ( dir, true, location, sizeof location, + "%s/%s.sra", + root, id -> addr ); + StringWhack ( id ); } else { rc = SILENT_RC( rcVFS, rcPath, rcReading, rcFormat, rcInvalid ); diff --git a/libs/vfs/path.c b/libs/vfs/path.c index 17eee11f1..531d4adf6 100644 --- a/libs/vfs/path.c +++ b/libs/vfs/path.c @@ -2392,6 +2392,10 @@ LIB_EXPORT rc_t CC VFSManagerExtractAccessionOrOID ( const VFSManager * self, return 0; } } + else if ( orig -> path . addr == NULL ) + { + rc = RC ( rcVFS, rcPath, rcConstructing, rcParam, rcIncorrect ); + } else { String path = orig -> path; @@ -4765,7 +4769,7 @@ rc_t VPathGetDirectory(const VPath * self, const KDirectory ** dir) { rc_t VPathSetDirectory(VPath * self, const KDirectory * dir) { static int DISABLE_DIRECTORY_CACHING = -1; - + rc_t rc = 0; if (DISABLE_DIRECTORY_CACHING < 0) diff --git a/libs/vfs/resolver.c b/libs/vfs/resolver.c index b7ab7fcf9..cbd3d113f 100644 --- a/libs/vfs/resolver.c +++ b/libs/vfs/resolver.c @@ -1271,7 +1271,7 @@ rc_t VResolverAlgParseResolverCGIResponse_1_0 ( const char *start, size_t size, if ( rslt_code . size == 0 ) return RC ( rcVFS, rcResolver, rcResolving, rcMessage, rcCorrupt ); result_code = strtoul ( rslt_code . addr, & rslt_end, 10 ); - if ( ( const char* ) rslt_end - rslt_code . addr != rslt_code . size ) + if ( (size_t)(( const char* ) rslt_end - rslt_code . addr) != rslt_code . size ) return RC ( rcVFS, rcResolver, rcResolving, rcMessage, rcCorrupt ); /* still have to test the URL */ @@ -1378,7 +1378,7 @@ static int getDigit ( char c, rc_t * rc ) { if ( * rc != 0 ) return 0; - c = tolower ( c ); + c = (char) tolower ( c ); if ( ! isdigit ( c ) && c < 'a' && c > 'f' ) { * rc = RC ( rcVFS, rcQuery, rcExecuting, rcItem, rcIncorrect ); return 0; @@ -1509,7 +1509,7 @@ rc_t VResolverAlgParseResolverCGIResponse_1_1 ( const char *astart, size_t size, if ( rslt_code . size == 0 ) return RC ( rcVFS, rcResolver, rcResolving, rcMessage, rcCorrupt ); result_code = strtoul ( rslt_code . addr, & rslt_end, 10 ); - if ( ( const char* ) rslt_end - rslt_code . addr != rslt_code . size ) + if ( (size_t) (( const char* ) rslt_end - rslt_code . addr) != rslt_code . size ) return RC ( rcVFS, rcResolver, rcResolving, rcMessage, rcCorrupt ); /* still have to test the URL */ @@ -1548,8 +1548,8 @@ rc_t VResolverAlgParseResolverCGIResponse_1_1 ( const char *astart, size_t size, if ( md5 . addr != NULL && md5 . size == 32 ) { int i = 0; for ( i = 0; i < 16 && rc == 0; ++ i ) { - ud5 [ i ] = getDigit ( md5 . addr [ 2 * i ], & rc ) * 16; - ud5 [ i ] += getDigit ( md5 . addr [ 2 * i + 1 ], & rc ); + ud5 [ i ] = (uint8_t) (getDigit ( md5 . addr [ 2 * i ], & rc ) * 16); + ud5 [ i ] += (uint8_t) getDigit ( md5 . addr [ 2 * i + 1 ], & rc ); } has_md5 = rc == 0; } @@ -2077,7 +2077,6 @@ rc_t VResolverAlgRemoteResolve ( const VResolverAlg *self, ) { bool done = false; - int i = 0; for ( i = 0; i < 2 && ! done; ++i ) { if ( version == NULL ) #ifdef TESTING_SERVICES_VS_OLD_RESOLVING @@ -2117,7 +2116,7 @@ rc_t VResolverAlgRemoteResolve ( const VResolverAlg *self, VPathGetUri_t ( * path ) != vpuri_fasp ) { const String *s = NULL; - rc_t rc = VPathMakeString(*path, &s); + rc = VPathMakeString(*path, &s); if (rc != 0) { LOGERR(klogInt, rc, @@ -2280,7 +2279,7 @@ rc_t VResolverAlgMakeCachePath ( const VResolverAlg *self, const VResolverAccToken *tok, const VPath ** path, bool legacy_wgs_refseq, const KDirectory * wd ) { - uint32_t i, count; + uint32_t i = 0, count; /* expanded accession */ String exp; @@ -2304,8 +2303,8 @@ rc_t VResolverAlgMakeCachePath ( const VResolverAlg *self, /* now search all volumes */ count = VectorLength ( & self -> vols ); - for ( i = 0; i < count; ++ i ) - { + /* for (i = 0; i < count; ++i) */ + if ( count > 0 ) { vol = VectorGet ( & self -> vols, i ); return VResolverAlgMakeLocalPath ( self, vol, & exp, path, wd ); } @@ -2333,9 +2332,9 @@ rc_t VResolverAlgMakeCacheFilePath ( const VResolverAlg *self, ? ".ncbi_enc" : ""; /* now search all volumes */ - uint32_t i, count = VectorLength ( & self -> vols ); - for ( i = 0; i < count; ++ i ) - { + uint32_t i = 0, count = VectorLength ( & self -> vols ); + /* for ( i = 0; i < count; ++ i ) */ + if ( count > 0 ) { const String *vol = VectorGet ( & self -> vols, i ); return VResolverAlgMakeLocalFilePath ( self, vol, & fname, krypto_ext, path, wd, query->projectId ); @@ -2638,22 +2637,22 @@ uint32_t get_accession_code ( const String * accession, VResolverAccToken *tok ) size -= i; /* check pileup extension */ - if ( string_cmp( acc, size, "pileup", 6, size + 6 ) == 0 ) + if ( string_cmp( acc, size, "pileup", 6, (uint32_t)(size + 6) ) == 0 ) { i = 6; } /* check realign extension */ - else if (string_cmp(acc, size, "realign", 7, size + 7) == 0) + else if (string_cmp(acc, size, "realign", 7, (uint32_t)(size + 7)) == 0) { i = 7; } /* check vdbcache extension */ - else if (string_cmp(acc, size, "vdbcache", 8, size + 8) == 0) + else if (string_cmp(acc, size, "vdbcache", 8, (uint32_t)(size + 8)) == 0) { /* vdbcache uses the same code as its accession */ tok -> vdbcache = true; return code; } - else if (string_cmp(acc, size, "sra.vdbcache", 12, size + 8) == 0) + else if (string_cmp(acc, size, "sra.vdbcache", 12, (uint32_t)(size + 8)) == 0) { /* vdbcache uses the same code as its accession */ tok->vdbcache = true; return code; @@ -3294,7 +3293,7 @@ rc_t VResolverLocalResolve ( const VResolver *self, const String * accession, for (j = 0; quality[j] != '\0'; ++j) { const bool for_cache = false; tok.noqual = quality[j] == 'Z'; - rc_t rc = VResolverAlgLocalResolve ( alg, self -> wd, + rc = VResolverAlgLocalResolve ( alg, self -> wd, & tok, path, legacy_wgs_refseq, for_cache, dir, false, VFSManagerExtNoqual(NULL) ); if ( rc == 0 ) @@ -3934,7 +3933,7 @@ rc_t VResolverCacheResolve ( const VResolver *self, const VPath * query, count = VResolverResolveToAd(self) ? VectorLength(&self->ad) : 0; for (i = 0; i < count; ++i) { - const VResolverAlg *alg = VectorGet(&self->ad, i); + alg = VectorGet(&self->ad, i); if (alg->cache_capable && alg -> protected == protected && (alg->app_id == app || alg->app_id == appAny)) { @@ -4034,7 +4033,7 @@ rc_t VResolverCacheResolve ( const VResolver *self, const VPath * query, count = useAd ? VectorLength(&self->ad) : 0; for (i = 0; i < count; ++i) { - const VResolverAlg *alg = VectorGet(&self->ad, i); + alg = VectorGet(&self->ad, i); if (alg->cache_enabled && alg -> protected == protected && (alg->app_id == app || alg->app_id == appAny)) { @@ -4136,7 +4135,7 @@ rc_t VResolverCacheFile ( const VResolver *self, const VPath * query, const VPat /* check AD */ count = VResolverResolveToAd(self) ? VectorLength(&self->ad) : 0; for (i = 0; i < count; ++i) { - const VResolverAlg *alg = VectorGet(&self->ad, i); + alg = VectorGet(&self->ad, i); if (alg->cache_capable && ( alg -> protected == protected || protected ) /* file AD app is not protected: use it to resolve dbGaP numeric id-s */ @@ -5955,7 +5954,8 @@ rc_t VResolverLoadRepo ( VResolver *self, Vector *algs, const KConfigNode *repo, KConfigNodeRelease ( node ); if ( GetRCState ( rc ) == rcNotFound ) rc = 0; - else if (root->size == 0); /* ignore repository with empty root node */ + else if (root->size == 0) /* ignore repository with empty root node */ + StringWhack ( root ); else if ( rc == 0 ) { /* perform a bit of cleanup on root */ @@ -6518,7 +6518,7 @@ static rc_t VResolverLoad(VResolver *self, const KRepository *protectedRepo, if (rc == 0) { const KConfigNode * node = NULL; - rc_t rc = + rc = KConfigNodeOpenNodeRead ( kfg, & node, "user/cache-disabled" ); if ( rc == 0 ) { bool disabled = false; @@ -6803,7 +6803,7 @@ rc_t VResolverMake ( VResolver ** objp, const KDirectory *wd, if ( mgr != NULL ) { - rc_t rc = VFSManagerGetKNSMgr ( mgr, & kns ); + rc = VFSManagerGetKNSMgr ( mgr, & kns ); if ( rc != 0 ) { rc = 0; @@ -6811,7 +6811,7 @@ rc_t VResolverMake ( VResolver ** objp, const KDirectory *wd, } } else { - rc_t rc = KNSManagerMake ( & kns ); + rc = KNSManagerMake ( & kns ); if ( rc != 0 ) { rc = 0; diff --git a/libs/vxf/simple-sub-select.c b/libs/vxf/simple-sub-select.c index 049aa76aa..37422f5e1 100644 --- a/libs/vxf/simple-sub-select.c +++ b/libs/vxf/simple-sub-select.c @@ -148,7 +148,7 @@ rc_t open_sub_cursor ( SubSelect **fself, const VXfactInfo *info, const VFactory if ( cp -> argv [ 0 ] . count > 0 ) { - sprintf(name,"%.*s",(int)cp->argv[0].count,cp->argv[0].data.ascii); + snprintf(name,sizeof(name),"%.*s",(int)cp->argv[0].count,cp->argv[0].data.ascii); rc = VCursorLinkedCursorGet(native_curs,name,&curs); if(rc == 0) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ad3e2f1c5..2c4907ede 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,7 +33,7 @@ endif() add_subdirectory(kfc) -set( COMMON_LINK_LIBRARIES ktst kapp ) +set( COMMON_LINK_LIBRARIES ktst vdbapp ) set( ADDITIONAL_LIBS "" ) # for the tests that link against libncbi-[w]vdb diff --git a/test/align/CMakeLists.txt b/test/align/CMakeLists.txt index 713922cb0..aed3ba267 100644 --- a/test/align/CMakeLists.txt +++ b/test/align/CMakeLists.txt @@ -36,19 +36,31 @@ if (NOT WIN32) add_test( NAME Test_Align_Config_2 COMMAND - Test_Align_Config_Tool - --config db/valid.config - --ref-list db/valid.references + Test_Align_Config_Tool + --config db/valid.config + --ref-list db/valid.references --ref-file db/ref.fasta WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_test( NAME Test_Align_Config_3 COMMAND - Test_Align_Config_Tool - --config db/VDB-3698.config - --ref-list db/VDB-3698.references + Test_Align_Config_Tool + --config db/VDB-3698.config + --ref-list db/VDB-3698.references --ref-file db/VDB-3698.fasta - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + add_test( NAME Test_Align_Config_Empty_Sequence + COMMAND + Test_Align_Config_Tool + --config db/VDB-5931.config + --ref-list db/VDB-5931.references + --ref-file db/VDB-5931.fasta + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + set_property(TEST Test_Align_Config_Empty_Sequence PROPERTY + PASS_REGULAR_EXPRESSION "data empty while reading file within alignment module" + ) endif() diff --git a/test/align/db/VDB-5931.config b/test/align/db/VDB-5931.config new file mode 100644 index 000000000..643a44ff2 --- /dev/null +++ b/test/align/db/VDB-5931.config @@ -0,0 +1,2 @@ +chrM NC_001643.1 circular +chrZ NC_045512.2 diff --git a/test/align/db/VDB-5931.fasta b/test/align/db/VDB-5931.fasta new file mode 100644 index 000000000..275a4f61c --- /dev/null +++ b/test/align/db/VDB-5931.fasta @@ -0,0 +1,11 @@ +>NC_001643.1 Pan troglodytes mitochondrion, complete genome +GTTTATGTAGCTTACCCCCTCAAAGCAATACACTGAAAATGTTTCGACGGGTTTACATCACCCCATAAAC +AAACAGGTTTGGTCCTAGCCTTTCTATTAGCTCTTAGTAAGATTACACATGCAAGCATCCCCGCCCCGTG +AGTCACCCTCTAAATCGCCATGATCAAAAGGAACAAGTATCAAGCACGCAGCAATGCAGCTCAAAACGCT +TAGCCTAGCCACACCCCCACGGGAGACAGCAGTGATAAACCTTTAGCAATAAACGAAAGTTTAACTAAGC +CATACTAACCTCAGGGTTGGTCAATTTCGTGCTAGCCACCGCGGTCATACGATTAACCCAAGTCAATAGA +AACCGGCGTAAAGAGTGTTTTAGATCACCCCCCCATAAAGCTAAAATTCACCTGAGTTGTAAAAAACTCC +AGCTGATACAAAATAAACTACGAAAGTGGCTTTAACACATCTGAATACACAATAGCTAAGACCCAAACTG +GGATTAGATACCCCACTATGCTTAGCCCTAAACTTCAACAGTTAAATTAACAAAACTGCTCGCCAGAACA +CTACGAGCCACAGCTTAAAACTCAAAGGACCTGGCGGTGCTTCATATCCCTCTAGAGGAGCCTGTTCTGT +>NC_045512.2 Bad Empty diff --git a/test/align/db/VDB-5931.references b/test/align/db/VDB-5931.references new file mode 100644 index 000000000..4d19072bb --- /dev/null +++ b/test/align/db/VDB-5931.references @@ -0,0 +1,2 @@ +chrM +chrZ diff --git a/test/align/test-config.cpp b/test/align/test-config.cpp index 15b2a75bf..870c6d8b6 100644 --- a/test/align/test-config.cpp +++ b/test/align/test-config.cpp @@ -33,7 +33,9 @@ #include #include #include +#include #include +#include #include #include @@ -53,6 +55,21 @@ struct ErrorCode { static inline void throwIf(rc_t const rc) { if (rc) throw ErrorCode{ rc }; } + operator std::string() const { + char buffer[1024]; + size_t n = 0; + string_printf(buffer, sizeof(buffer), &n, "%#R", rc); + + std::string ret; + if (n < sizeof(buffer)) { + ret.assign(buffer, n); + } + else { + ret.assign(n, ' '); + string_printf(&ret[0], n, &n, "%#R", rc); + } + return ret; + } }; class cArgs { @@ -70,7 +87,7 @@ class cArgs { ErrorCode::throwIf(ArgsMakeAndHandle(&args, argc, argv, 1, table, tableSize)); } #define ARGS(DEFS) cArgs{ argc, argv, sizeof(DEFS)/sizeof(OptDef), DEFS } - + unsigned countOf(char const *name) const { uint32_t count = 0; ErrorCode::throwIf(ArgsOptionCount(args, name, &count)); @@ -115,7 +132,7 @@ struct CommandLine { { "ref-list" , NULL, NULL, ref_list_help , 1, true, false, NULL }, }; auto args = ARGS(defs); - + opt_skip_verify = args.countOf(defs[0]) > 0; opt_only_verify = args.countOf(defs[1]) > 0; opt_config_file = args.valueOf(defs[2]); @@ -132,8 +149,8 @@ struct CommandLine { } args_p = args.take(); } - ~CommandLine() { - delete references; + ~CommandLine() { + delete references; ArgsWhack(args_p); } @@ -148,11 +165,11 @@ struct CommandLine { std::istream &references_file() const { return references ? *references : std::cin; } - - /// is `--skip-verify` on + + /// is `--skip-verify` on bool skip_verify() const { return opt_skip_verify; } - - /// is `--only-verify` on + + /// is `--only-verify` on bool only_verify() const { return opt_only_verify; } private: @@ -171,12 +188,12 @@ struct ConfigFile { std::string name; std::string seqId; std::string extra; - + Entry() = default; Entry(std::string const &line) { std::istringstream strm(line); - + strm >> name >> seqId; if (strm) { strm >> std::ws; @@ -199,10 +216,10 @@ struct ConfigFile { } }; std::vector entries; - + ConfigFile(char const *filePath) { auto file = std::ifstream{ filePath }; - + file >> std::ws; for (std::string line; std::getline(file, line); file >> std::ws) { #if ALLOW_COMMENT_LINES @@ -249,7 +266,7 @@ struct Fixture { Fixture() : mgr(referenceManager("db/empty.config")) {} - + Fixture(CommandLine const &cmdline) : mgr(referenceManager(cmdline.config_file())) { @@ -260,7 +277,7 @@ struct Fixture { throw ErrorCode{ rc }; } } - + ~Fixture() { ReferenceMgr_Release(mgr, false, nullptr, false, nullptr); } @@ -275,11 +292,16 @@ struct Fixture { ReferenceSeq const *findSeq(std::string const &key) const { return findSeq(key.c_str()); } - ReferenceSeq const *getSeq(char const *key, bool *shouldUnmap = nullptr, bool* wasRenamed = nullptr) const + std::pairgetSeq_2(char const *key, bool *shouldUnmap = nullptr, bool* wasRenamed = nullptr) const { bool dummy1{ false }, dummy2{ false }; ReferenceSeq const *seq{ nullptr }; auto const rc = ReferenceMgr_GetSeq(mgr, &seq, key, shouldUnmap ? shouldUnmap : &dummy1, false, wasRenamed ? wasRenamed : &dummy2); + return {rc, seq}; + } + ReferenceSeq const *getSeq(char const *key, bool *shouldUnmap = nullptr, bool* wasRenamed = nullptr) const + { + auto [rc, seq] = getSeq_2(key, shouldUnmap, wasRenamed); return rc == 0 ? seq : nullptr; } ReferenceSeq const *getSeq(std::string const &key, bool *shouldUnmap = nullptr, bool* wasRenamed = nullptr) const @@ -331,7 +353,7 @@ TEST_SUITE(LoaderTestSuite); TEST_CASE ( LoadNoConfig ) { auto const h = Fixture{ }; - + // not a valid RefSeq accession REQUIRE_NULL(h.findSeq("NC_000000")); REQUIRE_NOT_NULL(h.getSeq("NC_000001.11")); @@ -341,21 +363,21 @@ TEST_CASE ( LoadConfig ) { if (arguments == nullptr) throw std::logic_error("no command line arguments!?"); - + auto const &args = *arguments; auto const configFile = args.config_file(); if (configFile == nullptr) throw test_skipped{ "no config file" }; - + auto const fixture = Fixture{ args }; auto const config = ConfigFile{ configFile }; - + for (auto & entry : config.entries) { auto const seq = fixture.findSeq(entry.name); bool circular = false; // must be able to find every name that was in the config file - REQUIRE_NOT_NULL(seq); + REQUIRE_NOT_NULL(seq); REQUIRE_RC(ReferenceSeq_IsCircular(seq, &circular)); REQUIRE_EQ(entry.circular(), circular); @@ -366,12 +388,12 @@ TEST_CASE ( VerifyConfig ) { if (arguments == nullptr) throw std::logic_error("no command line arguments!?"); - + auto const &args = *arguments; auto const configFile = args.config_file(); if (configFile == nullptr) throw test_skipped{ "no config file" }; - + auto const references = referenceList(args); if (references.empty()) throw test_skipped{ "no reference list" }; @@ -386,47 +408,28 @@ TEST_CASE ( VerifyConfig ) } if (!arguments->only_verify()) { for (auto & ref : references) { - auto const seq = fixture.getSeq(ref); + auto rc_seq = fixture.getSeq_2(ref.c_str()); - REQUIRE_NOT_NULL(seq); + REQUIRE_NOT_NULL(rc_seq.second); - auto const e = config.find(ref); - if (e && e->circular()) { - bool circular = false; - REQUIRE_RC(ReferenceSeq_IsCircular(seq, &circular)); - REQUIRE(circular); + if (rc_seq.first) { + std::cerr << ref << ": " << std::string(ErrorCode{rc_seq.first}) << std::endl; + } + else { + auto const e = config.find(ref); + if (e && e->circular()) { + bool circular = false; + REQUIRE_RC(ReferenceSeq_IsCircular(rc_seq.second, &circular)); + REQUIRE(circular); + } } } } } //////////////////////////////////////////// Main -#include -#include -#include -#include - -extern "C" -{ -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "test-loader"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options]\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); { @@ -435,6 +438,3 @@ rc_t CC KMain ( int argc, char *argv [] ) return LoaderTestSuite(argc, argv); } } - -} - diff --git a/test/axf/test-RestoreRead.cpp b/test/axf/test-RestoreRead.cpp index 4e8597c64..5b3180eb3 100644 --- a/test/axf/test-RestoreRead.cpp +++ b/test/axf/test-RestoreRead.cpp @@ -28,6 +28,7 @@ #include #include #include +#include extern "C" { #include "../../libs/axf/restore-read.h" @@ -161,34 +162,9 @@ FIXTURE_TEST_CASE(ReadSomeAndClose, RR_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-RestoreRead"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); // KLogLevelSet(klogDebug); - rc_t rc = RestoreReadSuite(argc, argv); - return rc; -} - + return RestoreReadSuite(argc, argv); } diff --git a/test/cc/CMakeLists.txt b/test/cc/CMakeLists.txt index 62bc623dc..28c8d7645 100644 --- a/test/cc/CMakeLists.txt +++ b/test/cc/CMakeLists.txt @@ -24,5 +24,7 @@ add_compile_definitions( __mod__="test/cc" ) -AddExecutableTest( Test_CC_Asm "asm-test" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_CC_Int128 "test-int128" "${COMMON_LIBS_READ}" ) \ No newline at end of file +set( LIBS "${COMMON_LIBS_READ}") + +AddExecutableTest( Test_CC_Asm "asm-test" "${LIBS}" ) +AddExecutableTest( Test_CC_Int128 "test-int128" "${LIBS}" ) \ No newline at end of file diff --git a/test/cc/asm-test.cpp b/test/cc/asm-test.cpp index 7a4114e1b..4691c3125 100644 --- a/test/cc/asm-test.cpp +++ b/test/cc/asm-test.cpp @@ -506,33 +506,9 @@ TEST_CASE(uint32__ror) #endif //////////////////////////////////////////// Main -extern "C" +int main ( int argc, char *argv [] ) { - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-asm"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc=AsmTestSuite(argc, argv); - return rc; -} - + return AsmTestSuite(argc, argv); } diff --git a/test/cc/test-int128.cpp b/test/cc/test-int128.cpp index d4c28df98..8c01e2386 100644 --- a/test/cc/test-int128.cpp +++ b/test/cc/test-int128.cpp @@ -72,33 +72,8 @@ TEST_CASE(shl_0) } //////////////////////////////////////////// Main -extern "C" +int main ( int argc, char *argv [] ) { - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; + return Int128TestSuite(argc, argv); } -const char UsageDefaultName[] = "test-int128"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc=Int128TestSuite(argc, argv); - return rc; -} - -} - - diff --git a/test/cipher/CMakeLists.txt b/test/cipher/CMakeLists.txt index 46dddce3c..3484876f5 100644 --- a/test/cipher/CMakeLists.txt +++ b/test/cipher/CMakeLists.txt @@ -23,11 +23,10 @@ # =========================================================================== if ( Python3_FOUND AND NOT WIN32 ) - if( "linux" STREQUAL ${OS} ) # fails on Teamcity/Mac due to apparent misconfiguration of Python - add_test( NAME Test_CIPHER COMMAND ./test.sh ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + add_test( NAME Test_CIPHER COMMAND sh test.sh ${CMAKE_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_tests_properties(Test_CIPHER PROPERTIES ENVIRONMENT - "PYTHON=${Python3_EXECUTABLE};LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" + "LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY};OS=${OS};PYTHON=${Python3_EXECUTABLE}" ) - endif() endif() diff --git a/test/cipher/test.sh b/test/cipher/test.sh old mode 100755 new mode 100644 index 6d18ff542..4e66f2ea2 --- a/test/cipher/test.sh +++ b/test/cipher/test.sh @@ -1,3 +1,27 @@ +# =========================================================================== +# +# PUBLIC DOMAIN NOTICE +# National Center for Biotechnology Information +# +# This software/database is a "United States Government Work" under the +# terms of the United States Copyright Act. It was written as part of +# the author's official duties as a United States Government employee and +# thus cannot be copyrighted. This software/database is freely available +# to the public for use. The National Library of Medicine and the U.S. +# Government have not placed any restriction on its use or reproduction. +# +# Although all reasonable efforts have been taken to ensure the accuracy +# and reliability of the software and data, the NLM and the U.S. +# Government do not and cannot warrant the performance or results that +# may be obtained by using this software or data. The NLM and the U.S. +# Government disclaim all warranties, express or implied, including +# warranties of performance, merchantability or fitness for any particular +# purpose. +# +# Please cite the author in any work or product based on this material. +# +# =========================================================================== + TOP=$1 CIPHER_DIR=${TOP}/libs/cipher/cipher-1.7 VIRTUALENV=$(which virtualenv) @@ -6,57 +30,59 @@ if [ "${PYTHON}" = "" ]; then echo "skipping python cipher test: PYTHON not defined" exit 0 fi -if [ "${VIRTUALENV}" = "" ]; then - echo "skipping python cipher test: no virtualenv" - exit 0 -fi #installing cipher module into newly created virtual env -tmp_py_env=$(pwd)/temp_env +tmp_py_env=$(pwd)/temp_env_${OS} -${PYTHON} -V -${VIRTUALENV} -p ${PYTHON} $tmp_py_env -. $tmp_py_env/bin/activate +if [ "${VIRTUALENV}" != "" ]; then + virtualenv -p ${PYTHON} $tmp_py_env || exit 1 +else + ${PYTHON} -m venv $tmp_py_env || exit 1 +fi +. $tmp_py_env/bin/activate || exit 2 -#now inside the virtual env, python is ${PYTHON} +#now inside the virtual env, python is python # the following creates "build dist .eggs" in $CIPHER_DIR tmp_cur_dir=$(pwd) -cd $CIPHER_DIR -python setup.py install -cd $tmp_cur_dir +cd $CIPHER_DIR || exit 3 +python -m pip install --use-pep517 . || exit 4 +cd $tmp_cur_dir || exit 5 unset tmp_cur_dir echo "Running python cipher test..." #running cipher test in py virtual env rm -f test.in test.enc test.out +if [ "${OS}" = "mac" ]; then + rm -f libncbi-vdb.dylib + ln -s $LD_LIBRARY_PATH/libncbi-vdb.dylib || exit 6 +fi for i in {0..10000} do echo "Hello world $i" >> test.in done -python ${CIPHER_DIR}/encrypt.py --password=password123 test.in test.enc -python ${CIPHER_DIR}/decrypt.py --password=password123 test.enc test.out +encrypt.py --password=password123 test.in test.enc || exit 7 +decrypt.py --password=password123 test.enc test.out || exit 8 diff test.in test.out exit_code=$? rm test.in test.enc test.out +if [ "${OS}" = "mac" ]; then rm libncbi-vdb.dylib; fi -echo "python cipher test is complete." +echo "...python cipher test is complete." # cleanup -deactivate +deactivate || exit 9 #now outside the virtual env rm -rf $tmp_py_env unset tmp_py_env -cd $CIPHER_DIR -rm -r build dist .eggs +cd $CIPHER_DIR || exit 10 rm -rf packit-0.18-py2.7.egg pbr-3.1.1-py2.7.egg wheel-0.30.0-py2.7.egg -rm -v cipher.egg-info/SOURCES.txt rm -vf glob2-0.4.1-py2.7.egg exit $exit_code diff --git a/test/cloud/CMakeLists.txt b/test/cloud/CMakeLists.txt index 88f3fa0ea..3534342d6 100644 --- a/test/cloud/CMakeLists.txt +++ b/test/cloud/CMakeLists.txt @@ -24,6 +24,8 @@ add_compile_definitions( __mod__="test/cloud" ) -AddExecutableTest( Test_CLOUD_aws "test-aws" "${COMMON_LINK_LIBRARIES};${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_CLOUD_gcp "test-gcp;TestStream" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_CLOUD_cloud "test-cloud" "${COMMON_LINK_LIBRARIES};${COMMON_LIBS_READ}" ) +set( LIBS "${COMMON_LIBS_READ}") + +AddExecutableTest( Test_CLOUD_aws "test-aws" "${COMMON_LINK_LIBRARIES};${LIBS}" ) +AddExecutableTest( Test_CLOUD_gcp "test-gcp;TestStream" "${LIBS}" ) +AddExecutableTest( Test_CLOUD_cloud "test-cloud" "${COMMON_LINK_LIBRARIES};${LIBS}" ) diff --git a/test/cloud/test-aws.cpp b/test/cloud/test-aws.cpp index d1bc81275..4f6923f9d 100644 --- a/test/cloud/test-aws.cpp +++ b/test/cloud/test-aws.cpp @@ -215,7 +215,7 @@ TEST_CASE(Get_IMDS_version) REQUIRE_RC( CloudMgrGetCurrentCloud ( mgr, & cloud ) ); AWS * aws = nullptr; REQUIRE_RC( CloudToAWS ( cloud, & aws ) ); -#ifdef TO_SHOW_RESULTS +#if TO_SHOW_RESULTS std::cout << "***IMDSv=" << (unsigned int)aws -> IMDS_version << endl; #endif REQUIRE( aws -> IMDS_version == 1 || aws -> IMDS_version == 2); @@ -241,7 +241,7 @@ TEST_CASE(Get_Pkcs7) uint32_t len = string_measure(pkcs7, nullptr); REQUIRE_LT( 1000u, len); REQUIRE_GT( 3000u, len); -#ifdef TO_SHOW_RESULTS +#if TO_SHOW_RESULTS std::cout << "***Pkcs7=" << string( pkcs7, len ) << endl; #endif @@ -293,7 +293,7 @@ TEST_CASE(PrintInstance_Allowed) { const String * ce_token = nullptr; REQUIRE_RC( CloudMakeComputeEnvironmentToken(cloud, &ce_token) ); REQUIRE_NOT_NULL(ce_token); - #ifdef TO_SHOW_RESULTS + #if TO_SHOW_RESULTS std::cout << "***ce_token=" << ce_token->addr << endl; #endif StringWhack(ce_token); @@ -356,9 +356,10 @@ TEST_CASE(GetLocation) { else { REQUIRE_NOT_NULL( location ); -#ifdef TO_SHOW_RESULTS +#if TO_SHOW_RESULTS cout << "***location=" << string( location -> addr, location -> size ) << endl; #endif + StringWhack( location ); } REQUIRE_RC( CloudRelease(cloud) ); } @@ -375,25 +376,7 @@ static rc_t argsHandler(int argc, char * argv[]) { return rc; } -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-aws"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); @@ -403,13 +386,13 @@ rc_t CC KMain ( int argc, char *argv [] ) // (same as running the executable with "-l=message") //TestEnv::verbosity = LogLevel::e_message; -#ifdef TO_SHOW_RESULTS +#if TO_SHOW_RESULTS assert(!KDbgSetString("KNS")); #endif KDbgSetString ( "KNS-PROXY" ); if (rc == 0) - rc = AwsTestSuite(argc, argv); + rc = (rc_t)AwsTestSuite(argc, argv); { rc_t r = KConfigRelease(KFG); @@ -417,7 +400,5 @@ KDbgSetString ( "KNS-PROXY" ); rc = r; } - return rc; -} - + return (int)rc; } diff --git a/test/cloud/test-cloud.cpp b/test/cloud/test-cloud.cpp index e1621a850..56996facf 100644 --- a/test/cloud/test-cloud.cpp +++ b/test/cloud/test-cloud.cpp @@ -146,7 +146,7 @@ class CloudMgrFixture { CreateFile(p_name, p_content, p_content2, p_content3, true); } - + CloudMgr * m_mgr; CloudProviderId m_id; Cloud * m_cloud; @@ -1011,34 +1011,18 @@ static rc_t argsHandler(int argc, char * argv[]) { #include #include /* KLogLevelSet */ -extern "C" { - ver_t CC KAppVersion ( void ) - { - return 0x1000000; - } - rc_t CC UsageSummary (const char * progname) - { - return 0; - } - rc_t CC Usage ( const Args * args ) - { - return 0; - } - const char UsageDefaultName[] = "test-kns"; - rc_t CC KMain ( int argc, char *argv [] ) - { - setenv("HOME", ".", 1); +int main( int argc, char *argv [] ) +{ + setenv("HOME", ".", 1); - KConfigDisableUserSettings(); + KConfigDisableUserSettings(); - // assert(!KDbgSetString("CLOUD")); - // KLogLevelSet( klogInfo ); + // assert(!KDbgSetString("CLOUD")); + // KLogLevelSet( klogInfo ); - // this makes messages from the test code appear - // (same as running the executable with "-l=message") - // TestEnv::verbosity = LogLevel::e_message; + // this makes messages from the test code appear + // (same as running the executable with "-l=message") + // TestEnv::verbosity = LogLevel::e_message; - rc_t rc=CloudTestSuite(argc, argv); - return rc; - } + return CloudTestSuite(argc, argv); } diff --git a/test/cloud/test-gcp.cpp b/test/cloud/test-gcp.cpp index 1deae9c2d..958d0ff2d 100644 --- a/test/cloud/test-gcp.cpp +++ b/test/cloud/test-gcp.cpp @@ -36,6 +36,7 @@ #include #include /* ArgsMakeAndHandle */ +#include /* ArgsMakeAndHandle */ #include /* KConfigMakeLocal */ @@ -349,6 +350,7 @@ TEST_CASE( Parse_Access_Token ) char * token; KTime_t expiration; REQUIRE_RC( ParseAccessToken( json, & token, & expiration ) ); + free( token ); } TEST_CASE( Parse_Access_Token_Bad ) {// VDB-5300, check protection against truncated json @@ -373,26 +375,9 @@ static rc_t argsHandler(int argc, char * argv[]) { return rc; } -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-gcp"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { + VDB::Application app(argc,argv); KConfigDisableUserSettings(); // this makes messages from the test code appear @@ -403,8 +388,5 @@ rc_t CC KMain ( int argc, char *argv [] ) assert(!KDbgSetString("KNS")); #endif - rc_t rc = GcpTestSuite(argc, argv); - return rc; -} - + return GcpTestSuite(argc, argv); } diff --git a/test/ext/bzip2/test-bzip2.cpp b/test/ext/bzip2/test-bzip2.cpp index 5217cd5a6..b7b1632bc 100644 --- a/test/ext/bzip2/test-bzip2.cpp +++ b/test/ext/bzip2/test-bzip2.cpp @@ -26,6 +26,8 @@ #include +#include + #include #include @@ -59,9 +61,9 @@ class BZip2Fixture THROW_ON_FALSE( BZ_OK == BZ2_bzCompressInit ( & s, blockSize100k, 0, workFactor ) ); s.next_in = const_cast( src.data() ); - s.avail_in = src.size(); + s.avail_in = (unsigned int)src.size(); s.next_out = dst.data(); - s.avail_out = dst.size(); + s.avail_out = (unsigned int)dst.size(); THROW_ON_FALSE( BZ_STREAM_END >= BZ2_bzCompress(&s, BZ_FINISH) ); assert ( s.total_out_hi32 == 0 ); @@ -79,9 +81,9 @@ class BZip2Fixture THROW_ON_FALSE( BZ_OK == BZ2_bzDecompressInit ( & s, 0, 0 ) ); s.next_in = const_cast( input.data() ); - s.avail_in = input.size(); + s.avail_in = (unsigned int)input.size(); s.next_out = decomp.data(); - s.avail_out = decomp.size(); + s.avail_out = (unsigned int)decomp.size(); THROW_ON_FALSE( BZ_STREAM_END >= BZ2_bzDecompress(&s) ); assert ( s.total_out_hi32 == 0 ); @@ -98,7 +100,7 @@ FIXTURE_TEST_CASE(RoundTrip, BZip2Fixture) { const size_t SrcSize = 2048; Buffer src; - srand (time(NULL)); + srand ((unsigned int)time(NULL)); for (size_t i = 0; i < SrcSize; ++i) src.push_back('A'+(rand() % 26)); Buffer comp = Compress( src ); @@ -111,39 +113,14 @@ FIXTURE_TEST_CASE(Buffer_TooShort, BZip2Fixture) const size_t SrcSize = 26; Buffer src; for (size_t i = 0; i < SrcSize; ++i) - src.push_back('a'+i); + src.push_back('a'+(char)i); Buffer comp = Compress( src ); REQUIRE_THROW( Decompress( comp, SrcSize ) ); } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-bzip2"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=Bzip2TestSuite(argc, argv); - return rc; -} - + return Bzip2TestSuite(argc, argv); } diff --git a/test/ext/mbedtls/test-mbedtls.cpp b/test/ext/mbedtls/test-mbedtls.cpp index 4e6dcdb53..a2488b86a 100644 --- a/test/ext/mbedtls/test-mbedtls.cpp +++ b/test/ext/mbedtls/test-mbedtls.cpp @@ -275,32 +275,8 @@ FIXTURE_TEST_CASE(WindowsRootStore, MbedTlsFixture) #endif -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-mmbedtls"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KDbgSetString ( "KNS-PROXY" ); - rc_t rc=MbedTlsTestSuite(argc, argv); - return rc; -} - + return MbedTlsTestSuite(argc, argv); } diff --git a/test/ext/zstd/test-zstd.cpp b/test/ext/zstd/test-zstd.cpp index da7f77114..a8652b9f7 100755 --- a/test/ext/zstd/test-zstd.cpp +++ b/test/ext/zstd/test-zstd.cpp @@ -26,6 +26,8 @@ #include +#include + #include #include /* srand, rand */ @@ -98,33 +100,8 @@ TEST_CASE(getFrameContentSize) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-zstd"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=ZstdTestSuite(argc, argv); - return rc; -} - + return ZstdTestSuite(argc, argv); } diff --git a/test/judy_test/judytest.c b/test/judy_test/judytest.c index 7f7ee710b..23746296b 100644 --- a/test/judy_test/judytest.c +++ b/test/judy_test/judytest.c @@ -23,7 +23,7 @@ * =========================================================================== * */ -#include +#include #include #include #include @@ -77,7 +77,7 @@ rc_t CC Usage ( const Args * args ) HelpOptionLine ( ALIAS_COUNT, OPTION_COUNT, "count", count_usage ); HelpOptionsStandard (); - HelpVersion ( fullpath, KAppVersion() ); + HelpVersion ( fullpath, GetKAppVersion() ); return rc; } @@ -1811,9 +1811,10 @@ rc_t perform_test( const uint32_t count ) return rc; } -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args * args; + SetUsage( Usage ); rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 1, JudyTestOptions, sizeof ( JudyTestOptions ) / sizeof ( OptDef ) ); diff --git a/test/kapp/.gitignore b/test/kapp/.gitignore new file mode 100644 index 000000000..0ccd05bf0 --- /dev/null +++ b/test/kapp/.gitignore @@ -0,0 +1 @@ +file.test diff --git a/test/kapp/CMakeLists.txt b/test/kapp/CMakeLists.txt index fe7246830..e5c9fe421 100644 --- a/test/kapp/CMakeLists.txt +++ b/test/kapp/CMakeLists.txt @@ -30,4 +30,18 @@ endif() add_compile_definitions( __mod__="test/kapp" ) -AddExecutableTest( Test_KAPP_args "kapp-test" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) +AddExecutableTest( Test_VDBAPP "vdbapp-test" "${COMMON_LIBS_READ};${ADDITIONAL_LIBS}" ) + +if ( NOT WIN32 ) + + BuildExecutableForTest( sig-core-vdbapp "sig-core-vdbapp.c" "${COMMON_LIBS_READ}" ) + + if ( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" ) + set( BLD dbg) + else() + set( BLD rel) + endif() + + add_test( NAME CoreGenerationVdbapp COMMAND run-sig-core.sh ${CMAKE_TEST_OUTPUT_DIRECTORY}/sig-core-vdbapp ${OS} ${BLD} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + +endif() \ No newline at end of file diff --git a/test/kapp/append-arg-test.c b/test/kapp/append-arg-test.c deleted file mode 100644 index 1072ca914..000000000 --- a/test/kapp/append-arg-test.c +++ /dev/null @@ -1,120 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#include -#include -#include -#include -#include - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0; -} - -const char UsageDefaultName[] = "append-arg-test"; - -rc_t CC UsageSummary ( const char *progname ) -{ - return KOutMsg ( "\n" - "Usage:\n" - " %s [Options]\n" - "\n" - "Summary:\n" - " Test append argument. [-h for help]\n" - , progname - ); -} - -rc_t CC Usage ( const Args *args ) -{ - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - if (rc) - progname = fullpath = UsageDefaultName; - - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionsStandard (); - HelpVersion ( fullpath, KAppVersion () ); - - return rc; -} - - -rc_t CC KMain ( int argc, char *argv [] ) -{ - Args *args; - rc_t rc; - bool Jojoba = false; - - if ( argc != 2 && argc != 1 ) { - if ( argc == 3 && strcmp ( argv [ 2 ], "jojoba" ) == 0 ) { - Jojoba = true; - } - else { - printf ( "INVALID ARGUMENTS\n" ); - UsageSummary ( UsageDefaultName ); - return 22; - } - } - - rc = ArgsMakeStandardOptions ( & args ); - if ( rc == 0 ) { - if ( ! Jojoba ) { - rc = ArgsAddAppendModeOption ( args ); - } - if ( rc == 0 ) { - rc = ArgsParse ( args, argc, argv ); - if ( rc == 0 ) { - ArgsHandleHelp ( args ); - - rc = ArgsHandleAppendMode ( args ); - if ( rc == 0 ) { - printf ( - "APPEND_MODE: %s\n", - ( ArgsIsAppendModeSet () ? "Y" : "N" ) - ); - } - } - } - - ArgsWhack ( args ); - } - - return rc; -} diff --git a/test/kapp/env-test-tool.c b/test/kapp/env-test-tool.c deleted file mode 100644 index 2f7010bbe..000000000 --- a/test/kapp/env-test-tool.c +++ /dev/null @@ -1,173 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#include -#include -#include -#include -#include - -#include -#include - -// TODO: provide short ones -#define ALIAS_AMD64 NULL -#define OPTION_AMD64 "amd64" -static const char* USAGE_AMD64[] = { "require tool to be run under 64-bit environment", NULL }; - -#define ALIAS_RAM NULL -#define OPTION_RAM "ram" -static const char* USAGE_RAM[] = { "require system RAM to be at least B", NULL }; - -OptDef Options[] = -{ /* needs_value, required */ - { OPTION_AMD64, ALIAS_AMD64, NULL, USAGE_AMD64, 1, false, false } - , { OPTION_RAM , ALIAS_RAM , NULL, USAGE_RAM , 1, true , false } -}; - -ver_t CC KAppVersion ( void ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-env"; - -rc_t CC UsageSummary ( const char *progname ) -{ - return KOutMsg ( "\n" - "Usage:\n" - " %s [Options]\n" - "\n" - "Summary:\n" - " Test system environment.\n" - , progname - ); -} - -rc_t CC Usage ( const Args *args ) -{ - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - if (rc) - progname = fullpath = UsageDefaultName; - - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionLine (ALIAS_AMD64, OPTION_AMD64, NULL, USAGE_AMD64); - HelpOptionLine (ALIAS_RAM , OPTION_RAM , NULL, USAGE_RAM); - KOutMsg ("\n"); - - HelpOptionsStandard (); - HelpVersion ( fullpath, KAppVersion () ); - - return rc; -} - - -rc_t CC KMain ( int argc, char *argv [] ) -{ - Args *args; - rc_t rc; - do { - uint32_t paramc; - bool requireAmd64 = false; - uint64_t requireRam = 0; - - rc = ArgsMakeAndHandle ( & args, argc, argv, 1, - Options, sizeof Options / sizeof (OptDef) ); - if ( rc != 0 ) - { - LogErr ( klogErr, rc, "failed to parse arguments" ); - break; - } - - // TODO: cehck if we need it - rc = ArgsParamCount ( args, & paramc ); - if ( rc != 0 ) { - LogErr ( klogInt, rc, "failed to obtain param count" ); - break; - } - - { // OPTION_AMD64 - rc = ArgsOptionCount( args, OPTION_AMD64, & paramc ); - if ( rc ) { - LOGERR( klogErr, rc, "Failure to get '" OPTION_AMD64 "' argument" ); - break; - } - if ( paramc ) { - requireAmd64 = true; - } - } - - { - // OPTION_RAM - rc = ArgsOptionCount ( args, OPTION_RAM, & paramc ); - if ( rc ) { - LOGERR ( klogErr, rc, "Failure to get '" OPTION_RAM "' argument" ); - break; - } - if ( paramc ) { - long long unsigned int sscanf_param; - - const char* dummy = NULL; - rc = ArgsOptionValue(args, OPTION_RAM, 0, (const void **)&dummy); - if ( rc ) { - LOGERR(klogErr, rc, "Failure to get '" OPTION_RAM "' argument"); - break; - } - - rc = sscanf(dummy, "%llu", &sscanf_param); - requireRam = ( uint64_t ) sscanf_param; - if ( rc != 1) - { - LOGMSG(klogErr, "Failure to parse '" OPTION_RAM "' argument value"); - break; - } - } - - } - - { - rc = KAppCheckEnvironment(requireAmd64, requireRam); - if (rc != 0 ) - printf("Invalid environment\n"); - else - printf("Enviroment is fine!\n"); - } - } while (false); - - ArgsWhack ( args ); - - return rc; -} diff --git a/test/kapp/kapp-test.cpp b/test/kapp/kapp-test.cpp deleted file mode 100644 index 5d20ce6df..000000000 --- a/test/kapp/kapp-test.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/*=========================================================================== - * - * PUBLIC DOMAIN NOTICE - * National Center for Biotechnology Information - * - * This software/database is a "United States Government Work" under the - * terms of the United States Copyright Act. It was written as part of - * the author's official duties as a United States Government employee and - * thus cannot be copyrighted. This software/database is freely available - * to the public for use. The National Library of Medicine and the U.S. - * Government have not placed any restriction on its use or reproduction. - * - * Although all reasonable efforts have been taken to ensure the accuracy - * and reliability of the software and data, the NLM and the U.S. - * Government do not and cannot warrant the performance or results that - * may be obtained by using this software or data. The NLM and the U.S. - * Government disclaim all warranties, express or implied, including - * warranties of performance, merchantability or fitness for any particular - * purpose. - * - * Please cite the author in any work or product based on this material. - * - * =========================================================================== - * - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace ncbi::NK; - -TEST_SUITE(KAppTestSuite); - -const char UsageDefaultName[] = "args-test"; - -#if ! ALLOW_TESTING_CODE_TO_RELY_UPON_CODE_BEING_TESTED -extern "C" -{ - rc_t CC UsageSummary ( const char *progname ) - { - return TestEnv::UsageSummary ( progname ); - } - - rc_t CC Usage ( const Args *args ) - { - const char* progname = UsageDefaultName; - const char* fullpath = UsageDefaultName; - - rc_t rc = (args == NULL) ? - RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull): - ArgsProgram(args, &fullpath, &progname); - if ( rc == 0 ) - rc = TestEnv::Usage ( progname ); - return rc; - } -} -#endif - -#define OPTION_TEST "test" - -static char arg_append_string[] = "__T__"; -static size_t arg_append_string_len = sizeof arg_append_string / sizeof arg_append_string[0] - 1; - -rc_t TestArgConvAppender(const Args * args, uint32_t arg_index, const char * arg, size_t arg_len, void ** result, WhackParamFnP * whack) -{ - char * res = (char *)malloc(arg_len + arg_append_string_len + 1); - assert(res); - - memmove(res, arg, arg_len); - memmove(res + arg_len, arg_append_string, arg_append_string_len); - res[arg_len + arg_append_string_len] = 0; - - *result = res; - - return 0; -} - -void WhackArgFile(void * file) -{ - KFileRelease(reinterpret_cast(file)); -} - -rc_t TestArgConvFileCreator(const Args * args, uint32_t arg_index, const char * arg, size_t arg_len, void ** result, WhackParamFnP * whack) -{ - rc_t rc; - KDirectory * dir; - KFile * file; - - char * file_path = const_cast(arg); - - rc = KDirectoryNativeDir( &dir ); - if (rc == 0) - { - KDirectoryRemove(dir, true, "%s", file_path); - rc = KDirectoryCreateFile(dir, &file, false, 0664, kcmCreate, "%s", file_path); - if (rc == 0) - { - char buffer[4] = { 'a', 'b', 'c', 'd' }; - size_t num_written; - - rc = KFileWriteAll(file, 0, buffer, sizeof buffer / sizeof buffer[0], &num_written); - if (rc == 0) - { - assert(num_written == sizeof buffer / sizeof buffer[0]); - - *result = file; - *whack = WhackArgFile; - KDirectoryRelease( dir ); - return 0; - } - - fprintf(stderr, "cannot write test buffer to create file: %s\n", file_path); - KFileRelease(file); - } - else - { - fprintf(stderr, "cannot create file from argument: %s\n", file_path); - } - KDirectoryRelease( dir ); - } - - return rc; -} - -TEST_CASE(KApp_ArgsMakeParams) -{ - int argc; - const char * argv[16]; - - /* testing params */ - argc = 6; - argv[0] = "test_1"; - argv[1] = "0"; - argv[2] = "1"; - argv[3] = "2"; - argv[4] = "3"; - argv[5] = "4"; - - Args * args; - REQUIRE_RC(ArgsMake (&args)); - REQUIRE_RC(ArgsParse (args, argc, (char**)argv)); - - { - uint32_t param_count; - uint32_t ix; - - REQUIRE_RC(ArgsParamCount (args, ¶m_count)); - REQUIRE_EQ(param_count, (uint32_t)argc-1); - for (ix = 0; ix < param_count; ix++) - { - const char * value; - REQUIRE_RC(ArgsParamValue (args, ix, reinterpret_cast(&value))); - { - /* valgrind whines about the line below. I can't see - * the problem with a uninitialized variable used for - * a conditional jump unless its in libc */ - REQUIRE_EQ(atoi(value), (int)ix); - } - } - } - REQUIRE_RC(ArgsWhack (args)); -} - -TEST_CASE(KApp_ArgsMakeParamsConvAppend) -{ - ParamDef Parameters[] = - { - { TestArgConvAppender } - }; - int argc; - const char * argv[16]; - - /* testing params */ - argc = 2; - argv[0] = "test_1"; - argv[1] = "abcd"; - - Args * args; - REQUIRE_RC(ArgsMake (&args)); - REQUIRE_RC(ArgsAddParamArray (args, Parameters, sizeof Parameters / sizeof Parameters[0])); - REQUIRE_RC(ArgsParse (args, argc, (char**)argv)); - - { - const char * value; - uint32_t param_count; - - REQUIRE_RC(ArgsParamCount (args, ¶m_count)); - REQUIRE_EQ(param_count, (uint32_t)argc-1); - - REQUIRE_RC(ArgsParamValue (args, 0, reinterpret_cast(&value))); - - REQUIRE(memcmp(value, argv[1], 4) == 0); - REQUIRE(memcmp(value + 4, arg_append_string, arg_append_string_len + 1) == 0); - } - REQUIRE_RC(ArgsWhack (args)); -} - -TEST_CASE(KApp_ArgsMakeOptions) -{ - OptDef Options[] = - { /* needs_value, required */ - { OPTION_TEST, NULL, NULL, NULL, 1, true, false } - }; - int argc; - const char * argv[16]; - - /* testing params */ - argc = 3; - argv[0] = "test_2"; - argv[1] = "--test"; - argv[2] = "abcd"; - - Args * args; - REQUIRE_RC(ArgsMake (&args)); - REQUIRE_RC(ArgsAddOptionArray (args, Options, sizeof Options / sizeof Options[0])); - REQUIRE_RC(ArgsParse (args, argc, (char**)argv)); - - { - const char * value; - uint32_t count; - - REQUIRE_RC(ArgsParamCount (args, &count)); - REQUIRE_EQ(count, (uint32_t)0); - - REQUIRE_RC(ArgsOptionCount (args, OPTION_TEST, &count)); - REQUIRE_EQ(count, (uint32_t)1); - - REQUIRE_RC(ArgsOptionValue (args, OPTION_TEST, 0, reinterpret_cast(&value))); - REQUIRE_EQ(std::string(value), std::string(argv[2])); - } - REQUIRE_RC(ArgsWhack (args)); -} - -TEST_CASE(KApp_ArgsMakeOptionsConversion) -{ - OptDef Options[] = - { /* needs_value, required */ - { OPTION_TEST, NULL, NULL, NULL, 1, true, false, TestArgConvFileCreator } - }; - int argc; - const char * argv[16]; - KDirectory * dir; - - /* testing params */ - argc = 3; - argv[0] = "test_2"; - argv[1] = "--test"; - argv[2] = "file.test"; - - Args * args; - REQUIRE_RC(ArgsMake (&args)); - REQUIRE_RC(ArgsAddOptionArray (args, Options, sizeof Options / sizeof Options[0])); - REQUIRE_RC(ArgsParse (args, argc, (char**)argv)); - - { - const KFile * file; - uint32_t count; - uint64_t file_size; - - REQUIRE_RC(ArgsParamCount (args, &count)); - REQUIRE_EQ(count, (uint32_t)0); - - REQUIRE_RC(ArgsOptionCount (args, OPTION_TEST, &count)); - REQUIRE_EQ(count, (uint32_t)1); - - REQUIRE_RC(ArgsOptionValue (args, OPTION_TEST, 0, reinterpret_cast(&file))); - - REQUIRE_RC(KFileSize (file, &file_size)); - - REQUIRE_EQ(file_size, (uint64_t)4); - } - REQUIRE_RC(ArgsWhack (args)); - - REQUIRE_RC(KDirectoryNativeDir ( &dir )); - REQUIRE_RC(KDirectoryRemove(dir, true, "%s", argv[2])); - REQUIRE_RC(KDirectoryRelease (dir)); -} -//////////////////////////////////////////// Main - -extern "C" -{ - -/* Version EXTERN - * return 4-part version code: 0xMMmmrrrr, where - * MM = major release - * mm = minor release - * rrrr = bug-fix release - */ -ver_t CC KAppVersion (void) -{ - return 0; -} - -/* KMain - EXTERN - * executable entrypoint "main" is implemented by - * an OS-specific wrapper that takes care of establishing - * signal handlers, logging, etc. - * - * in turn, OS-specific "main" will invoke "KMain" as - * platform independent main entrypoint. - * - * "argc" [ IN ] - the number of textual parameters in "argv" - * should never be < 0, but has been left as a signed int - * for reasons of tradition. - * - * "argv" [ IN ] - array of NUL terminated strings expected - * to be in the shell-native character set: ASCII or UTF-8 - * element 0 is expected to be executable identity or path. - */ -rc_t CC KMain ( int argc, char *argv [] ) -{ - KConfigDisableUserSettings(); - rc_t rc=KAppTestSuite(argc, argv); - return rc; -} - -} diff --git a/test/kapp/options.txt b/test/kapp/options.txt new file mode 100644 index 000000000..6913b2811 --- /dev/null +++ b/test/kapp/options.txt @@ -0,0 +1 @@ +-L debug --verbose \ No newline at end of file diff --git a/test/kapp/run-sig-core.sh b/test/kapp/run-sig-core.sh index 98f5878ab..1b602960d 100755 --- a/test/kapp/run-sig-core.sh +++ b/test/kapp/run-sig-core.sh @@ -76,15 +76,20 @@ elif [ "$HOST_OS" = "bsd" ]; then CORE_FOLDER="./" elif [ "$HOST_OS" = "linux" ]; then - if [ "`ulimit -c`" = "0" ]; then - echo "Core files are disabled. Skipping core file tests" - exit 0 - fi + if [ "$OS_DISTRIBUTOR" = "Ubuntu" ]; then + if [ "`ulimit -c`" = "0" ]; then + echo "Core files are disabled. Skipping core file tests" + exit 0 + fi - if [ "`cat /proc/sys/kernel/core_pattern`" != "core" ]; then - echo "Unknown core file pattern" 1>&2 - exit 2 - fi + if [ "`cat /proc/sys/kernel/core_pattern`" != "core" ]; then + echo "Unknown core file pattern. Skipping core file tests" 1>&2 + exit 0 + fi + else + echo "Non-Ubuntu Linux. Skipping core file tests" + exit 0 + fi CORE_FOLDER="./" else echo "Should be run from unix-compatible OS" 1>&2 @@ -95,7 +100,7 @@ fi # them in background. Lets start it normally and run # `kill` command in background. killFromBackground $$ & -$BINARY_PATH +$BINARY_PATH # Wait for `kill` job wait @@ -107,26 +112,26 @@ rm killed.pid if [ "$HOST_OS" = "bsd" ]; then CORE_FILE="${CORE_FOLDER}${BINARY_PATH##*/}.core" else - CORE_FILE="${CORE_FOLDER}core.${BINARY_PID}" + CORE_FILE="${CORE_FOLDER}core" fi if [ "$BUILD_TYPE" = "dbg" ]; then if [ -f $CORE_FILE ]; then rm $CORE_FILE - echo "Success: Core file was generated and was removed" + echo "Success: Core file $CORE_FILE was generated and was removed" exit 0 else - echo "Failed: No core file detected" 1>&2 + echo "Failed: No core file $CORE_FILE detected" 1>&2 exit 3 fi else if [ -f $CORE_FILE ]; then - rm $CORE_FILE - echo "Failed: Core file generated while shouldn't and was removed" 1>&2 + rm $CORE_FILE + echo "Failed: Core file $CORE_FILE generated while shouldn't and was removed" 1>&2 exit 4 else - echo "Success: No core file detected" + echo "Success: No core file $CORE_FILE detected" exit 0 - fi + fi fi diff --git a/test/kapp/rc-mod-exitcode.c b/test/kapp/sig-core-vdbapp.c similarity index 78% rename from test/kapp/rc-mod-exitcode.c rename to test/kapp/sig-core-vdbapp.c index 8059b6adc..91a03f52e 100644 --- a/test/kapp/rc-mod-exitcode.c +++ b/test/kapp/sig-core-vdbapp.c @@ -24,31 +24,21 @@ * */ -#include #include +#include -#include -#include +#include -ver_t CC KAppVersion ( void ) +int main ( int argc, char *argv [] ) { - return 0x01020003; -} + if ( VdbInitialize( argc, argv, 0 ) ) + return VDB_INIT_FAILED; -rc_t CC UsageSummary ( const char *progname ) -{ - return 0; -} - -rc_t CC Usage ( const Args *args ) -{ - return 0; -} - - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc = RC_EXITCODE(EX_TEMPFAIL); + do { + while ( true ) { + sleep ( 1000 ); + } + } while (false); - return rc; + return VdbTerminate( 0 ); } diff --git a/test/kapp/sig-core.c b/test/kapp/sig-core.c deleted file mode 100644 index c1de00cd8..000000000 --- a/test/kapp/sig-core.c +++ /dev/null @@ -1,101 +0,0 @@ -/*=========================================================================== -* -* PUBLIC DOMAIN NOTICE -* National Center for Biotechnology Information -* -* This software/database is a "United States Government Work" under the -* terms of the United States Copyright Act. It was written as part of -* the author's official duties as a United States Government employee and -* thus cannot be copyrighted. This software/database is freely available -* to the public for use. The National Library of Medicine and the U.S. -* Government have not placed any restriction on its use or reproduction. -* -* Although all reasonable efforts have been taken to ensure the accuracy -* and reliability of the software and data, the NLM and the U.S. -* Government do not and cannot warrant the performance or results that -* may be obtained by using this software or data. The NLM and the U.S. -* Government disclaim all warranties, express or implied, including -* warranties of performance, merchantability or fitness for any particular -* purpose. -* -* Please cite the author in any work or product based on this material. -* -* =========================================================================== -* -*/ - -#include -#include -#include -#include -#include - -#include -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0; -} - -const char UsageDefaultName[] = "sig-core"; - -rc_t CC UsageSummary ( const char *progname ) -{ - return KOutMsg ( "\n" - "Usage:\n" - " %s [Options]\n" - "\n" - "Summary:\n" - " Test core generation by killing it with signal.\n" - " The tool enter into infinite loop after start .\n" - , progname - ); -} - -rc_t CC Usage ( const Args *args ) -{ - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - if (rc) - progname = fullpath = UsageDefaultName; - - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionsStandard (); - HelpVersion ( fullpath, KAppVersion () ); - - return rc; -} - - -rc_t CC KMain ( int argc, char *argv [] ) -{ - Args *args; - rc_t rc; - do { - rc = ArgsMakeAndHandle ( & args, argc, argv, 0 ); - if ( rc != 0 ) - { - LogErr ( klogErr, rc, "failed to parse arguments" ); - break; - } - - while ( true ) { - sleep ( 1000 ); - } - } while (false); - - ArgsWhack ( args ); - - return rc; -} diff --git a/test/kapp/vdbapp-test.cpp b/test/kapp/vdbapp-test.cpp new file mode 100644 index 000000000..a4e4209d4 --- /dev/null +++ b/test/kapp/vdbapp-test.cpp @@ -0,0 +1,120 @@ +/*=========================================================================== + * + * PUBLIC DOMAIN NOTICE + * National Center for Biotechnology Information + * + * This software/database is a "United States Government Work" under the + * terms of the United States Copyright Act. It was written as part of + * the author's official duties as a United States Government employee and + * thus cannot be copyrighted. This software/database is freely available + * to the public for use. The National Library of Medicine and the U.S. + * Government have not placed any restriction on its use or reproduction. + * + * Although all reasonable efforts have been taken to ensure the accuracy + * and reliability of the software and data, the NLM and the U.S. + * Government do not and cannot warrant the performance or results that + * may be obtained by using this software or data. The NLM and the U.S. + * Government disclaim all warranties, express or implied, including + * warranties of performance, merchantability or fitness for any particular + * purpose. + * + * Please cite the author in any work or product based on this material. + * + * =========================================================================== + * + */ + +#include + +#include + +#include +#include +#include + +using namespace std; +using namespace ncbi::NK; + +TEST_SUITE(VDBAppTestSuite); + +TEST_CASE(NotQuitting) +{ + REQUIRE( ! Quitting() ); +} + +TEST_CASE(NoHangUp) +{ + REQUIRE_RC( Hangup() ); +} +TEST_CASE(SignalNoHup_ignored) +{ + REQUIRE_RC( SignalNoHup() ); +} + +const ver_t AppVersion = 12; +TEST_CASE(ReportInitialized) +{ // main() initialized report module + ver_t version = 0; + ReportGetVersion( & version ); + REQUIRE_EQ( AppVersion, version ); +} + +TEST_CASE(ProcMgrInitialized) +{ + KProcMgr * mgr = nullptr; + REQUIRE_RC( KProcMgrMakeSingleton( & mgr ) ); + REQUIRE_NOT_NULL( mgr ); + REQUIRE_RC( KProcMgrRelease( mgr ) ); +} + +TEST_CASE(UserAgentInitialized) +{ + const char * agent = nullptr; + REQUIRE_RC( KNSManagerGetUserAgent( & agent ) ); + REQUIRE_NOT_NULL( agent ); + //cout< +#include + #include #include @@ -64,8 +66,6 @@ using namespace std; TEST_SUITE ( KdbTestSuite ); -const char UsageDefaultName[] = "VDB-4705"; - class KDB_ColumnCopyFixture { public: void createTable ( const char *tblname ) @@ -306,20 +306,8 @@ FIXTURE_TEST_CASE ( CopyColumn, KDB_ColumnCopyFixture ) checkTable ( tableName2 ); } -extern "C" { - -#include -#include -#include // KDbgSetString - -ver_t CC KAppVersion ( void ) { return 0x1000000; } -rc_t CC UsageSummary ( const char *progname ) { return 0; } - -rc_t CC Usage ( const Args *args ) { return 0; } - -rc_t CC KMain ( int argc, char *argv[] ) +int main( int argc, char *argv[] ) { KConfigDisableUserSettings (); return KdbTestSuite ( argc, argv ); } -} diff --git a/test/kdb/VDB-4706.cpp b/test/kdb/VDB-4706.cpp index a84cf3e46..977e0df62 100644 --- a/test/kdb/VDB-4706.cpp +++ b/test/kdb/VDB-4706.cpp @@ -34,6 +34,8 @@ #include +#include + #include #include @@ -58,8 +60,6 @@ using namespace std; TEST_SUITE ( KdbTestSuite ); -const char UsageDefaultName[] = "VDB-4706"; - class KDB_ColumnCopyFixture { public: void createTable ( const char *tblname ) @@ -327,20 +327,9 @@ FIXTURE_TEST_CASE ( CopyMeta, KDB_ColumnCopyFixture ) checkTable ( tableName2 ); } -extern "C" { - -#include -#include -#include // KDbgSetString - -ver_t CC KAppVersion ( void ) { return 0x1000000; } -rc_t CC UsageSummary ( const char *progname ) { return 0; } - -rc_t CC Usage ( const Args *args ) { return 0; } - -rc_t CC KMain ( int argc, char *argv[] ) +int main ( int argc, char *argv[] ) { KConfigDisableUserSettings (); return KdbTestSuite ( argc, argv ); } -} + diff --git a/test/kdb/VDB-5323.cpp b/test/kdb/VDB-5323.cpp index 3861ff33c..fc9885b37 100644 --- a/test/kdb/VDB-5323.cpp +++ b/test/kdb/VDB-5323.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -54,7 +56,6 @@ using namespace std; TEST_SUITE ( KdbTestSuite ); -const char UsageDefaultName[] = "VDB-5323"; #define INSERT_2 0 class KDB_KIndexFixture { @@ -148,20 +149,9 @@ FIXTURE_TEST_CASE ( CheckIndex1, KDB_KIndexFixture ) checkTable(tableName, 1, &keyValues[0]); } -extern "C" { - -#include -#include -#include // KDbgSetString - -ver_t CC KAppVersion ( void ) { return 0x1000000; } -rc_t CC UsageSummary ( const char *progname ) { return 0; } - -rc_t CC Usage ( const Args *args ) { return 0; } - -rc_t CC KMain ( int argc, char *argv[] ) +int main( int argc, char *argv[] ) { KConfigDisableUserSettings (); return KdbTestSuite ( argc, argv ); } -} + diff --git a/test/kdb/kdbtest.cpp b/test/kdb/kdbtest.cpp index 7a3a8c340..8004ba4cb 100644 --- a/test/kdb/kdbtest.cpp +++ b/test/kdb/kdbtest.cpp @@ -39,6 +39,10 @@ #include #include +#include + +#include // KDbgSetString + #include using namespace std; @@ -56,37 +60,12 @@ static rc_t argsHandler(int argc, char* argv[]) { ArgsWhack(args); return rc; } -extern "C" -{ -#include -#include -#include // KDbgSetString - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-kdb"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { // assert(!KDbgSetString("KFG")); // assert(!KDbgSetString("VFS")); //KDbgSetModConds ( DBG_KNS, DBG_FLAG ( DBG_KNS_SOCKET ), DBG_FLAG ( DBG_KNS_SOCKET ) ); KConfigDisableUserSettings(); - rc_t rc=KdbTestSuite(argc, argv); - return rc; -} - + return KdbTestSuite(argc, argv); } diff --git a/test/kdb/makedb.cpp b/test/kdb/makedb.cpp index 9d80024c5..d8e0074c0 100644 --- a/test/kdb/makedb.cpp +++ b/test/kdb/makedb.cpp @@ -36,6 +36,8 @@ #include #include +#include + #include #include @@ -140,33 +142,9 @@ MakeDatabase() } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "makedb"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - return MakeDatabase(); -} - + return (int)MakeDatabase(); } diff --git a/test/kdb/rowsettest.cpp b/test/kdb/rowsettest.cpp index 566e6733e..5d1ce5e63 100644 --- a/test/kdb/rowsettest.cpp +++ b/test/kdb/rowsettest.cpp @@ -761,60 +761,8 @@ FIXTURE_TEST_CASE ( KRowSetUnionNormalTest, RowSetFixture ) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0; -} - - -const char UsageDefaultName[] = "test-rowset"; - -rc_t CC UsageSummary ( const char *progname ) -{ - return KOutMsg ( "\n" - "Usage:\n" - " %s [Options] \n" - "\n" - "Summary:\n" - " test the rowset.\n" - , progname - ); -} - -rc_t CC Usage ( const Args *args ) -{ - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - if (rc) - progname = fullpath = UsageDefaultName; - - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionsStandard (); - - HelpVersion (fullpath, KAppVersion()); - - return rc; -} -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { srand ( time(NULL) ); return KRowSetTestSuite(argc, argv); } - -} - diff --git a/test/kdb/test-pagemap.cpp b/test/kdb/test-pagemap.cpp index 51ca09b52..6d7877692 100644 --- a/test/kdb/test-pagemap.cpp +++ b/test/kdb/test-pagemap.cpp @@ -25,6 +25,8 @@ #include +#include + #include using namespace std; @@ -109,33 +111,9 @@ TEST_CASE ( PageMap_AppendRows ) //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-pagemap"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KdbPageMapTestSuite(argc, argv); - return rc; + return KdbPageMapTestSuite(argc, argv); } -} diff --git a/test/kdb/test-rblob.cpp b/test/kdb/test-rblob.cpp index 34574bed9..6a77e2877 100644 --- a/test/kdb/test-rblob.cpp +++ b/test/kdb/test-rblob.cpp @@ -30,6 +30,8 @@ #include +#include + extern "C" { #include "../libs/kdb/rcolumnblob.h" @@ -224,33 +226,8 @@ FIXTURE_TEST_CASE ( ColumnBlobRead_insufficient_buffer, RColumnBlobFixture_API ) //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RBlob"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=RBlobTestSuite(argc, argv); - return rc; -} - + return RBlobTestSuite(argc, argv); } diff --git a/test/kdb/test-rcolumn.cpp b/test/kdb/test-rcolumn.cpp index bb045621c..d960ce998 100644 --- a/test/kdb/test-rcolumn.cpp +++ b/test/kdb/test-rcolumn.cpp @@ -30,6 +30,8 @@ #include +#include + extern "C" { #include <../libs/kdb/rcolumnblob.h> @@ -150,33 +152,8 @@ FIXTURE_TEST_CASE(KRColumn_OpenBlobRead, KColumn_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_KRColumn"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KRColumnTestSuite(argc, argv); - return rc; -} - + return KRColumnTestSuite(argc, argv); } diff --git a/test/kdb/test-rdatabase.cpp b/test/kdb/test-rdatabase.cpp index b35fbaaa6..0d23930a0 100644 --- a/test/kdb/test-rdatabase.cpp +++ b/test/kdb/test-rdatabase.cpp @@ -30,6 +30,8 @@ #include +#include + #include <../libs/kdb/rdatabase.h> #include <../libs/kdb/dbmgr.h> @@ -249,9 +251,9 @@ FIXTURE_TEST_CASE(KDBRManager_PathContents_dir, KDatabase_Fixture) REQUIRE_RC(KDBRManagerPathContents(m_mgr, &contents, 0, "%s", name.c_str())); REQUIRE_NOT_NULL(contents); REQUIRE_EQ(name, string(contents->name)); - + // REQUIRE_EQ((int)(contents->fstype | kptAlias), (int)(kptDir | kptAlias)); - + REQUIRE_EQ((int)contents->dbtype, (int)kptDatabase); REQUIRE_EQ((int)(contents->attributes & cca_HasErrors), (int)cca_HasErrors); @@ -305,9 +307,9 @@ FIXTURE_TEST_CASE(KDBRManager_PathContents_kar, KDatabase_Fixture) REQUIRE_RC(KDBRManagerPathContents(m_mgr, &contents, 0, "%s", name.c_str())); REQUIRE_NOT_NULL(contents); REQUIRE_EQ(name, string(contents->name)); - + REQUIRE_EQ((int)(contents->fstype | kptAlias), (int)(kptFile | kptAlias)); - + REQUIRE_EQ((int)contents->dbtype, (int)kptDatabase); REQUIRE_EQ((int)(contents->attributes & cca_HasErrors), (int)cca_HasErrors); @@ -358,15 +360,15 @@ FIXTURE_TEST_CASE(KDBRManager_PathContents_kar_shallow, KDatabase_Fixture) { auto const name = std::string("testdb.kar"); KDBContents const *contents = NULL; - + // Set levelOfDetail to shallow REQUIRE_RC(KDBRManagerPathContents(m_mgr, &contents, 1, "%s", name.c_str())); REQUIRE_NOT_NULL(contents); REQUIRE_EQ(name, string(contents->name)); - + REQUIRE_EQ((int)(contents->fstype | kptAlias), (int)(kptFile | kptAlias)); REQUIRE_EQ(contents->levelOfDetail, 1); - + REQUIRE_EQ((int)contents->dbtype, (int)kptDatabase); // shallow does not check for errors REQUIRE_EQ((int)(contents->attributes & cca_HasErrors), 0); @@ -419,9 +421,9 @@ FIXTURE_TEST_CASE(KDBRManager_PathContents_SRR, KDatabase_Fixture) KDBContents const *contents = NULL; REQUIRE_RC(KDBRManagerPathContents(m_mgr, &contents, "SRR000001")); REQUIRE_NOT_NULL(contents); - + REQUIRE_EQ((int)(contents->fstype), 0); ///< fstype is unknown - + REQUIRE_EQ((int)contents->dbtype, (int)kptTable); ///< SRR000001 is a table REQUIRE_EQ((int)(contents->attributes & cca_HasMetadata), (int)cca_HasMetadata); REQUIRE_EQ((int)(contents->attributes & cca_HasMD5_File), (int)cca_HasMD5_File); @@ -443,33 +445,8 @@ FIXTURE_TEST_CASE(KDBRManager_PathContents_SRR, KDatabase_Fixture) //KDB_EXTERN rc_t CC KDatabaseGetPath ( struct KDatabase const *self, const char **path ); //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_KRDatabase"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KRDatabaseTestSuite(argc, argv); - return rc; -} - + return KRDatabaseTestSuite(argc, argv); } diff --git a/test/kdb/test-rindex.cpp b/test/kdb/test-rindex.cpp index 9e6126e57..31d0a8fec 100644 --- a/test/kdb/test-rindex.cpp +++ b/test/kdb/test-rindex.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -144,7 +146,7 @@ static int64_t fat_start_id = 0; static uint64_t fat_id_count = 0; static rc_t CC -findAllTextCallback (int64_t p_startId, uint64_t p_count, void*) +findAllTextCallback (int64_t p_startId, uint64_t p_count, void*) noexcept { ++ fat_called; fat_start_id = p_startId; @@ -179,7 +181,7 @@ FIXTURE_TEST_CASE(KRIndex_ProjectAllText, KIndex_Fixture) { Open( "testdb", "index" ); - auto f = [] (int64_t p_startId, uint64_t p_count, const char *key, void*) -> rc_t { return 0; }; + auto f = [] (int64_t p_startId, uint64_t p_count, const char *key, void*) noexcept -> rc_t { return 0; }; rc_t rc = SILENT_RC(rcDB,rcIndex,rcProjecting,rcIndex,rcIncorrect); REQUIRE_EQ( rc, KIndexProjectAllText ( m_idx, 1, f, nullptr ) ); @@ -202,7 +204,7 @@ FIXTURE_TEST_CASE(KRIndex_FindAllU64, KIndex_Fixture) { Open( "testdb", "index" ); - auto f = [] ( uint64_t key, uint64_t key_size, int64_t start_id, uint64_t id_count, void *data ) -> rc_t { return 0; }; + auto f = [] ( uint64_t key, uint64_t key_size, int64_t start_id, uint64_t id_count, void *data ) noexcept -> rc_t { return 0; }; rc_t rc = SILENT_RC(rcDB, rcIndex, rcSelecting, rcNoObj, rcUnknown); REQUIRE_EQ( rc, KIndexFindAllU64 ( m_idx, 0, f, nullptr ) ); @@ -217,33 +219,8 @@ FIXTURE_TEST_CASE(KRIndex_SetMaxRowId, KIndex_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RIndex"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBRIndexTestSuite(argc, argv); - return rc; -} - + return KDBRIndexTestSuite(argc, argv); } diff --git a/test/kdb/test-rmanager.cpp b/test/kdb/test-rmanager.cpp index b76716324..19e93c94d 100644 --- a/test/kdb/test-rmanager.cpp +++ b/test/kdb/test-rmanager.cpp @@ -30,6 +30,8 @@ #include +#include + #include <../libs/kdb/rdatabase.h> #include <../libs/kdb/dbmgr.h> #include <../libs/kdb/libkdb.vers.h> @@ -215,33 +217,8 @@ FIXTURE_TEST_CASE(KDBRManager_OpenColumnRead, KDBManager_Fixture) //KDBManagerVPathOpenRemoteDBRead //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RManager"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBRManagerTestSuite(argc, argv); - return rc; -} - + return KDBRManagerTestSuite(argc, argv); } diff --git a/test/kdb/test-rmetadata.cpp b/test/kdb/test-rmetadata.cpp index b9b08ef3c..d0d58b2b8 100644 --- a/test/kdb/test-rmetadata.cpp +++ b/test/kdb/test-rmetadata.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -144,33 +146,8 @@ FIXTURE_TEST_CASE(KRMetadata_OpenNodeRead, KMetadata_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RMetadata"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBRMetadataTestSuite(argc, argv); - return rc; -} - + return KDBRMetadataTestSuite(argc, argv); } diff --git a/test/kdb/test-rmetanode.cpp b/test/kdb/test-rmetanode.cpp index 8435b48c1..e7b952c60 100644 --- a/test/kdb/test-rmetanode.cpp +++ b/test/kdb/test-rmetanode.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -586,33 +588,8 @@ FIXTURE_TEST_CASE(KRMDataNode_ListChildren, KRMDataNode_Fixture) //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RMDataNode"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBRMDataNodeTestSuite(argc, argv); - return rc; -} - + return KDBRMDataNodeTestSuite(argc, argv); } diff --git a/test/kdb/test-rtable.cpp b/test/kdb/test-rtable.cpp index c8c7f0c1c..ddbd8c3a6 100644 --- a/test/kdb/test-rtable.cpp +++ b/test/kdb/test-rtable.cpp @@ -30,6 +30,8 @@ #include +#include + #include <../libs/kdb/rtable.h> #include <../libs/kdb/dbmgr.h> @@ -241,33 +243,9 @@ FIXTURE_TEST_CASE(KRTable_MetaCompare, KTable_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_KRTable"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KRTableTestSuite(argc, argv); - return rc; + return KRTableTestSuite(argc, argv); } -} diff --git a/test/kdb/test-wblob.cpp b/test/kdb/test-wblob.cpp index 7ce916eb4..3f9c849bf 100644 --- a/test/kdb/test-wblob.cpp +++ b/test/kdb/test-wblob.cpp @@ -30,6 +30,8 @@ #include +#include + extern "C" { #include "../libs/kdb/wcolumnblob.h" @@ -227,33 +229,8 @@ FIXTURE_TEST_CASE ( ColumnBlobRead_insufficient_buffer, WColumnBlobFixture_API ) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_WBlob"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=WBlobTestSuite(argc, argv); - return rc; -} - + return WBlobTestSuite(argc, argv); } diff --git a/test/kdb/test-wcolumn.cpp b/test/kdb/test-wcolumn.cpp index 5192980d9..a04b59beb 100644 --- a/test/kdb/test-wcolumn.cpp +++ b/test/kdb/test-wcolumn.cpp @@ -30,6 +30,8 @@ #include +#include + extern "C" { #include <../libs/kdb/wcolumnblob.h> @@ -157,33 +159,8 @@ FIXTURE_TEST_CASE(KWColumn_OpenBlobRead, KColumn_Fixture) //TODO: non-virtual write-side only methods //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_KWColumn"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KWColumnTestSuite(argc, argv); - return rc; -} - + return KWColumnTestSuite(argc, argv); } diff --git a/test/kdb/test-wdatabase.cpp b/test/kdb/test-wdatabase.cpp index 405509f91..74b865e45 100644 --- a/test/kdb/test-wdatabase.cpp +++ b/test/kdb/test-wdatabase.cpp @@ -30,6 +30,8 @@ #include +#include + #include <../libs/kdb/wdatabase.h> #include <../libs/kdb/dbmgr.h> @@ -266,33 +268,8 @@ FIXTURE_TEST_CASE(KWDatabase_CreateIndex, KDatabase_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_KWDatabase"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KWDatabaseTestSuite(argc, argv); - return rc; -} - + return KWDatabaseTestSuite(argc, argv); } diff --git a/test/kdb/test-windex.cpp b/test/kdb/test-windex.cpp index d9e6b3ec6..279ae6116 100644 --- a/test/kdb/test-windex.cpp +++ b/test/kdb/test-windex.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -147,7 +149,7 @@ static int64_t fat_start_id = 0; static uint64_t fat_id_count = 0; static rc_t CC -findAllTextCallback (int64_t p_startId, uint64_t p_count, void*) +findAllTextCallback (int64_t p_startId, uint64_t p_count, void*) noexcept { ++ fat_called; fat_start_id = p_startId; @@ -182,7 +184,7 @@ FIXTURE_TEST_CASE(KWIndex_ProjectAllText, KIndex_Fixture) { Open( "testdb", "index" ); - auto f = [] (int64_t p_startId, uint64_t p_count, const char *key, void*) -> rc_t { return 0; }; + auto f = [] (int64_t p_startId, uint64_t p_count, const char *key, void*) noexcept -> rc_t { return 0; }; rc_t rc = SILENT_RC(rcDB, rcIndex, rcProjecting, rcFunction, rcInvalid); REQUIRE_EQ( rc, KIndexProjectAllText ( m_idx, 1, f, nullptr ) ); @@ -205,7 +207,7 @@ FIXTURE_TEST_CASE(KWIndex_FindAllU64, KIndex_Fixture) { Open( "testdb", "index" ); - auto f = [] ( uint64_t key, uint64_t key_size, int64_t start_id, uint64_t id_count, void *data ) -> rc_t { return 0; }; + auto f = [] ( uint64_t key, uint64_t key_size, int64_t start_id, uint64_t id_count, void *data ) noexcept -> rc_t { return 0; }; rc_t rc = SILENT_RC(rcDB, rcIndex, rcSelecting, rcType, rcUnsupported); REQUIRE_EQ( rc, KIndexFindAllU64 ( m_idx, 0, f, nullptr ) ); @@ -220,33 +222,8 @@ FIXTURE_TEST_CASE(KWIndex_SetMaxRowId, KIndex_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RIndex"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBRIndexTestSuite(argc, argv); - return rc; -} - + return KDBRIndexTestSuite(argc, argv); } diff --git a/test/kdb/test-wmanager.cpp b/test/kdb/test-wmanager.cpp index d7dc80afc..f960e00f2 100644 --- a/test/kdb/test-wmanager.cpp +++ b/test/kdb/test-wmanager.cpp @@ -30,6 +30,8 @@ #include +#include + #include <../libs/kdb/rdatabase.h> #include <../libs/kdb/wdbmgr.h> #include <../libs/kdb/libkdb.vers.h> @@ -229,33 +231,8 @@ FIXTURE_TEST_CASE(KDBWManager_OpenColumnRead, KDBManager_Fixture) //KDBManagerVPathOpenRemoteDBRead //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RManager"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBWManagerTestSuite(argc, argv); - return rc; -} - + return KDBWManagerTestSuite(argc, argv); } diff --git a/test/kdb/test-wmetadata.cpp b/test/kdb/test-wmetadata.cpp index ae04d925e..76288e9d4 100644 --- a/test/kdb/test-wmetadata.cpp +++ b/test/kdb/test-wmetadata.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -143,33 +145,8 @@ FIXTURE_TEST_CASE(KWMetadata_OpenNodeRead, KMetadata_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RMetadata"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBWMetadataTestSuite(argc, argv); - return rc; -} - + return KDBWMetadataTestSuite(argc, argv); } diff --git a/test/kdb/test-wmetanode.cpp b/test/kdb/test-wmetanode.cpp index ffc71b5ac..3c1785812 100644 --- a/test/kdb/test-wmetanode.cpp +++ b/test/kdb/test-wmetanode.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -582,33 +584,8 @@ FIXTURE_TEST_CASE(KWRMDataNode_ListChildren, KWMDataNode_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_RMDataNode"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBWMDataNodeTestSuite(argc, argv); - return rc; -} - + return KDBWMDataNodeTestSuite(argc, argv); } diff --git a/test/kdb/test-wtable.cpp b/test/kdb/test-wtable.cpp index bbe0c210c..c8dd90ca2 100644 --- a/test/kdb/test-wtable.cpp +++ b/test/kdb/test-wtable.cpp @@ -30,6 +30,8 @@ #include +#include + #include <../libs/kdb/wtable.h> #include <../libs/kdb/dbmgr.h> @@ -248,33 +250,8 @@ FIXTURE_TEST_CASE(KWTable_MetaCompare, KTable_Fixture) //TODO: non-virtual write-side only methods //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDB_KWTable"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KWTableTestSuite(argc, argv); - return rc; -} - + return KWTableTestSuite(argc, argv); } diff --git a/test/kdb/wkdbtest.cpp b/test/kdb/wkdbtest.cpp index 94cddb1d8..106168ded 100644 --- a/test/kdb/wkdbtest.cpp +++ b/test/kdb/wkdbtest.cpp @@ -30,9 +30,12 @@ #include +#include + #include #include +#include // KDbgSetString #include #include #include @@ -169,36 +172,10 @@ FIXTURE_TEST_CASE ( ColumnMetadata, WKDB_Fixture ) //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include -#include // KDbgSetString - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-wkdb"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { //assert(!KDbgSetString("KFG")); //assert(!KDbgSetString("VFS")); KConfigDisableUserSettings(); - rc_t rc=KdbTestSuite(argc, argv); - return rc; -} - + return KdbTestSuite(argc, argv); } diff --git a/test/kdbtext/CMakeLists.txt b/test/kdbtext/CMakeLists.txt index 71322c438..319eeec86 100644 --- a/test/kdbtext/CMakeLists.txt +++ b/test/kdbtext/CMakeLists.txt @@ -32,7 +32,7 @@ add_compile_definitions( __mod__="test/kdbtext" ) -set( LIBS ${COMMON_LIBS_READ};kdbtext ) +set( LIBS kdbtext;${COMMON_LIBS_READ} ) AddExecutableTest( Test_KDBText_Path "test-path" "${LIBS}" ) AddExecutableTest( Test_KDBText_Metadata "test-metadata" "${LIBS}" ) AddExecutableTest( Test_KDBText_Index "test-index" "${LIBS}" ) diff --git a/test/kdbtext/test-blob.cpp b/test/kdbtext/test-blob.cpp index 1fd475365..691be2e49 100644 --- a/test/kdbtext/test-blob.cpp +++ b/test/kdbtext/test-blob.cpp @@ -37,6 +37,7 @@ #include #include #include +#include using namespace std; using namespace KDBText; @@ -251,7 +252,7 @@ class KTextColumnBlob_ApiFixture } ~KTextColumnBlob_ApiFixture() { - KColumnBlobRelease( m_blob ); + delete (ColumnBlob*) m_blob; KJsonValueWhack( m_json ); } void Setup( const string & data ) @@ -490,33 +491,8 @@ FIXTURE_TEST_CASE(KTextColumnBlob_IdRange, KTextColumnBlob_ApiFixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Column"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KTextColumnBlobTestSuite(argc, argv); - return rc; -} - + return KTextColumnBlobTestSuite(argc, argv); } diff --git a/test/kdbtext/test-column.cpp b/test/kdbtext/test-column.cpp index 242818b9c..cc972c906 100644 --- a/test/kdbtext/test-column.cpp +++ b/test/kdbtext/test-column.cpp @@ -40,6 +40,8 @@ #include #include +#include + using namespace std; using namespace KDBText; @@ -311,40 +313,17 @@ FIXTURE_TEST_CASE(KColumn_OpenBlobRead_Int, KTextColumn_ApiFixture) // 1st byte: length = 1element (011), no extra bits (000), little endian (10) REQUIRE_EQ( 0b01100010, (int)buffer[0] ); // bytes 3-5: data - REQUIRE_EQ( (uint32_t)12345, ((uint32_t*)(buffer + 1))[0] ); + uint32_t temp; + memmove( &temp, buffer + 1, sizeof temp ); // avoid misaligned read + REQUIRE_EQ( (uint32_t)12345, temp ); REQUIRE_RC( KColumnBlobRelease( blob ) ); } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Column"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KTextColumnTestSuite(argc, argv); - return rc; -} - + return KTextColumnTestSuite(argc, argv); } diff --git a/test/kdbtext/test-database.cpp b/test/kdbtext/test-database.cpp index e31dc6354..2785a885e 100644 --- a/test/kdbtext/test-database.cpp +++ b/test/kdbtext/test-database.cpp @@ -46,6 +46,8 @@ #include #include +#include + using namespace std; using namespace KDBText; @@ -565,33 +567,8 @@ FIXTURE_TEST_CASE(KTextDatabase_GetPath, KTextDatabase_ApiFixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Database"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KTextDatabaseTestSuite(argc, argv); - return rc; -} - + return KTextDatabaseTestSuite(argc, argv); } diff --git a/test/kdbtext/test-index.cpp b/test/kdbtext/test-index.cpp index 5cd6e1380..c44c1dfe9 100644 --- a/test/kdbtext/test-index.cpp +++ b/test/kdbtext/test-index.cpp @@ -37,6 +37,8 @@ #include #include +#include + using namespace std; using namespace KDBText; @@ -361,7 +363,7 @@ FIXTURE_TEST_CASE(KIndex_FindText_Found, KTextIndex_ApiFixture) REQUIRE_EQ( (uint64_t)2, m_id_count ); } -int CC Compare ( const void *item, struct PBSTNode const *n, void *data ) +int CC Compare ( const void *item, struct PBSTNode const *n, void *data ) noexcept { return 0; } @@ -631,33 +633,8 @@ FIXTURE_TEST_CASE(KIndex_SetMaxRowId, KTextIndex_ApiFixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Index"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBTextIndexTestSuite(argc, argv); - return rc; -} - + return KDBTextIndexTestSuite(argc, argv); } diff --git a/test/kdbtext/test-manager.cpp b/test/kdbtext/test-manager.cpp index 15a1449bc..1dcb0e770 100644 --- a/test/kdbtext/test-manager.cpp +++ b/test/kdbtext/test-manager.cpp @@ -40,6 +40,8 @@ #include #include +#include + using namespace std; TEST_SUITE(KDBTextManagerTestSuite); @@ -366,35 +368,10 @@ FIXTURE_TEST_CASE(KDBManager_getVFSManager, KDBTextManager_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Manager"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBTextManagerTestSuite(argc, argv); - return rc; -} - + return KDBTextManagerTestSuite(argc, argv); } #if 0 diff --git a/test/kdbtext/test-metadata.cpp b/test/kdbtext/test-metadata.cpp index ee8dcfe0b..5ae45578b 100644 --- a/test/kdbtext/test-metadata.cpp +++ b/test/kdbtext/test-metadata.cpp @@ -38,6 +38,8 @@ #include #include +#include + using namespace std; using namespace KDBText; @@ -254,7 +256,7 @@ FIXTURE_TEST_CASE(KMetadata_GetSequence_SeqNull, KTextMetadata_ApiFixture) FIXTURE_TEST_CASE(KMetadata_GetSequence_ValNull, KTextMetadata_ApiFixture) { Setup(R"({"name":"md","revision":1})"); - const char * seq; + const char * seq = nullptr; REQUIRE_RC_FAIL( KMetadataGetSequence( m_md, seq, nullptr ) ); } @@ -310,33 +312,8 @@ FIXTURE_TEST_CASE(KMetadata_OpenNodeRead, KTextMetadata_ApiFixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Metadata"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBTextMetadataTestSuite(argc, argv); - return rc; -} - + return KDBTextMetadataTestSuite(argc, argv); } diff --git a/test/kdbtext/test-metanode.cpp b/test/kdbtext/test-metanode.cpp index aa3ebb470..fe542c13b 100644 --- a/test/kdbtext/test-metanode.cpp +++ b/test/kdbtext/test-metanode.cpp @@ -41,6 +41,8 @@ #include #include +#include + #include using namespace std; @@ -662,33 +664,8 @@ FIXTURE_TEST_CASE(KMetanode_ListChildren, KTextMetanode_ApiFixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Metanode"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBTextMetanodeTestSuite(argc, argv); - return rc; -} - + return KDBTextMetanodeTestSuite(argc, argv); } diff --git a/test/kdbtext/test-path.cpp b/test/kdbtext/test-path.cpp index a2346c387..9c2f733f7 100644 --- a/test/kdbtext/test-path.cpp +++ b/test/kdbtext/test-path.cpp @@ -35,6 +35,8 @@ #include #include +#include + #include using namespace std; @@ -99,33 +101,8 @@ TEST_CASE(KDBTextPath_fromVPath) REQUIRE( path.empty() ); } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Path"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KDBTextPathTestSuite(argc, argv); - return rc; -} - + return KDBTextPathTestSuite(argc, argv); } diff --git a/test/kdbtext/test-table.cpp b/test/kdbtext/test-table.cpp index 268ccbaf2..e182429d3 100644 --- a/test/kdbtext/test-table.cpp +++ b/test/kdbtext/test-table.cpp @@ -45,6 +45,8 @@ #include #include +#include + using namespace std; using namespace KDBText; @@ -445,33 +447,8 @@ FIXTURE_TEST_CASE(KTextTable_MetaCompare, KTextTable_ApiFixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "Test_KDBText_Table"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KTextTableTestSuite(argc, argv); - return rc; -} - + return KTextTableTestSuite(argc, argv); } diff --git a/test/kfc/test-except.c b/test/kfc/test-except.c index e7dd4e8cc..881d27e0d 100644 --- a/test/kfc/test-except.c +++ b/test/kfc/test-except.c @@ -108,26 +108,3 @@ int main ( int argc, char * argv [] ) return status; } -#if WINDOWS -int CC wmain ( int argc, wchar_t * wargv [] ) -{ - int i, status; - char ** argv = malloc ( argc * sizeof * argv ); - for ( i = 0; i < argc; ++ i ) - { - size_t src_size, dst_size; - uint32_t len = wchar_cvt_string_measure ( wargv [ i ], & src_size, & dst_size ); - char * dst = malloc ( dst_size + 1 ); - wchar_cvt_string_copy ( dst, dst_size + 1, wargv [ i ], src_size ); - argv [ i ] = dst; - } - - status = main ( argc, argv ); - - for ( i = 0; i < argc; ++ i ) - free ( argv [ i ] ); - free ( argv ); - - return status; -} -#endif diff --git a/test/kfg/CMakeLists.txt b/test/kfg/CMakeLists.txt index b0b04b6c3..e7ae5495f 100644 --- a/test/kfg/CMakeLists.txt +++ b/test/kfg/CMakeLists.txt @@ -26,9 +26,11 @@ add_compile_definitions( __mod__="test/kfg" ) -#AddExecutableTest( Test_KFG_NCBI_Env "ncbi-home-from-env" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFG_Wb_test_kfg "wb-test-kfg" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFG_test_kfg "kfg-fixture;kfgtest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFG_repository "repositorytest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFG_Keystore "keystoretest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFG_Properties "kfg-fixture;propertiestest" "${COMMON_LIBS_READ}" ) +set( LIBS "${COMMON_LIBS_READ}") + +#AddExecutableTest( Test_KFG_NCBI_Env "ncbi-home-from-env" "${LIBS}" ) +AddExecutableTest( Test_KFG_Wb_test_kfg "wb-test-kfg" "${LIBS}" ) +AddExecutableTest( Test_KFG_test_kfg "kfg-fixture;kfgtest" "${LIBS}" ) +AddExecutableTest( Test_KFG_repository "repositorytest" "${LIBS}" ) +AddExecutableTest( Test_KFG_Keystore "keystoretest" "${LIBS}" ) +AddExecutableTest( Test_KFG_Properties "kfg-fixture;propertiestest" "${LIBS}" ) diff --git a/test/kfg/keystoretest.cpp b/test/kfg/keystoretest.cpp index ff340cccb..cdb0a7933 100644 --- a/test/kfg/keystoretest.cpp +++ b/test/kfg/keystoretest.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -83,16 +85,16 @@ class KeyStoreFixture if (KConfigRelease(kfg) != 0) cerr << "~KeyStoreFixture: KConfigRelease failed" << endl; } - void KfgUpdateNode(const char* key, const char* value) + void KfgUpdateNode(const char* p_key, const char* p_value) { KConfigNode *node; - if (KConfigOpenNodeUpdate(kfg, &node, key) != 0) + if (KConfigOpenNodeUpdate(kfg, &node, p_key) != 0) throw logic_error("KfgUpdateNode: KConfigOpenNodeUpdate failed"); - if (KConfigNodeWrite(node, value, string_measure(value, NULL)) != 0) + if (KConfigNodeWrite(node, p_value, string_measure(p_value, NULL)) != 0) throw logic_error("KfgUpdateNode: KConfigNodeWrite failed"); if (KConfigNodeRelease(node) != 0) throw logic_error("KfgUpdateNode: KConfigNodeRelease failed"); - } + } KConfig* kfg; KKeyStore* ks; @@ -112,17 +114,17 @@ FIXTURE_TEST_CASE(KeyStoreGetKey_TempFile, KeyStoreFixture) const KFile* file; REQUIRE_RC(KDirectoryOpenFileRead(wd, &file, GetName())); - + REQUIRE_RC(KKeyStoreSetTemporaryKeyFromFile(ks, file)); - - REQUIRE_RC(KKeyStoreGetKey(ks, "boohoo i am ignored here", &key)); + + REQUIRE_RC(KKeyStoreGetKey(ks, "boohoo i am ignored here", &key)); REQUIRE_NOT_NULL(key); REQUIRE_EQ(string(tempKey), string(key->value.addr, key->value.len)); - + // now. ask to forget REQUIRE_RC(KKeyStoreSetTemporaryKeyFromFile(ks, NULL)); - REQUIRE_RC_FAIL(KKeyStoreGetKey(ks, "boohoo i am ignored here", &key)); - + REQUIRE_RC_FAIL(KKeyStoreGetKey(ks, "boohoo i am ignored here", &key)); + REQUIRE_RC(KFileRelease(file)); REQUIRE_RC(KDirectoryRemove(wd, true, GetName())); } @@ -139,15 +141,15 @@ FIXTURE_TEST_CASE(KeyStoreGetKey_Kfg, KeyStoreFixture) ofstream f(GetName()); f << tempKey << endl; } - + KfgUpdateNode(KFG_KRYPTO_PWFILE, GetName()); - + REQUIRE_RC(KKeyStoreSetConfig(ks, kfg)); - + REQUIRE_RC(KKeyStoreGetKey(ks, NULL, &key)); REQUIRE_NOT_NULL(key); REQUIRE_EQ(string(tempKey), string(key->value.addr, key->value.len)); - + REQUIRE_RC(KDirectoryRemove(wd, true, GetName())); } @@ -158,17 +160,17 @@ FIXTURE_TEST_CASE(KeyStoreGetKey_Protected, KeyStoreFixture) ofstream f(GetName()); f << tempKey << endl; } - + KfgUpdateNode("/repository/user/protected/dbGaP-2956/root", "."); KfgUpdateNode("/repository/user/protected/dbGaP-2956/encryption-key-path", GetName()); REQUIRE_RC(KKeyStoreSetConfig(ks, kfg)); - + // VDB-4394: protected repos are ignored REQUIRE_RC_FAIL(KKeyStoreGetKey(ks, "just give us the current repo's key", &key)); REQUIRE_NULL(key); // REQUIRE_EQ(string(tempKey), string(key->value.addr, key->value.len)); - + REQUIRE_RC(KDirectoryRemove(wd, true, GetName())); } @@ -179,7 +181,7 @@ FIXTURE_TEST_CASE(KeyStoreGetKeyById_Protected, KeyStoreFixture) ofstream f(GetName()); f << tempKey << endl; } - + KfgUpdateNode("/repository/user/protected/dbGaP-2956/root", "."); KfgUpdateNode("/repository/user/protected/dbGaP-2956/encryption-key-path", "wrong file!"); @@ -188,12 +190,12 @@ FIXTURE_TEST_CASE(KeyStoreGetKeyById_Protected, KeyStoreFixture) GetName()); REQUIRE_RC(KKeyStoreSetConfig(ks, kfg)); - + REQUIRE_RC_FAIL(KKeyStoreGetKeyByProjectId(ks, "give us the key for 2957", &key, 2957)); REQUIRE_NULL(key); // REQUIRE_EQ(string(tempKey), string(key->value.addr, key->value.len)); - + REQUIRE_RC(KDirectoryRemove(wd, true, GetName())); } @@ -201,7 +203,7 @@ FIXTURE_TEST_CASE(KeyStoreGetKeyById_Protected, KeyStoreFixture) // Object Id / Object name bindings // -class ObjIdBindingFixture : public KeyStoreFixture +class ObjIdBindingFixture : public KeyStoreFixture { public: ObjIdBindingFixture() @@ -210,27 +212,27 @@ class ObjIdBindingFixture : public KeyStoreFixture ~ObjIdBindingFixture() { if (bindings.length() != 0 && KDirectoryRemove(wd, true, bindings.c_str()) != 0) - cerr << "ObjIdBindingFixture::TearDown: KDirectoryRemove failed" << endl; + cerr << "ObjIdBindingFixture::TearDown: KDirectoryRemove failed" << endl; } void SetUp(const string& bindingsFileName) { bindings = string("./") + bindingsFileName; if (KKeyStoreSetBindingsFile(ks, bindings.c_str()) != 0) - throw logic_error("ObjIdBindingFixture::SetUp: KeyStoreSetBindingsFile failed"); + throw logic_error("ObjIdBindingFixture::SetUp: KeyStoreSetBindingsFile failed"); KDirectoryRemove(wd, true, bindings.c_str()); // does not have to exist } - + string bindings; }; FIXTURE_TEST_CASE(ObjIdRegister, ObjIdBindingFixture) { SetUp(GetName()); - + String name1; CONST_STRING(&name1, "name1"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 1, &name1)); - + String name2; CONST_STRING(&name2, "name2"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 2, &name2)); @@ -239,30 +241,30 @@ FIXTURE_TEST_CASE(ObjIdRegister, ObjIdBindingFixture) FIXTURE_TEST_CASE(ObjIdRegister_Found_Same, ObjIdBindingFixture) { SetUp(GetName()); - + String name1; CONST_STRING(&name1, "name1"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 1, &name1)); - + String name2; CONST_STRING(&name2, "name2"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 2, &name2)); - + REQUIRE_RC(KKeyStoreRegisterObject(ks, 1, &name1)); // same name, no problem } FIXTURE_TEST_CASE(ObjIdRegister_Found_Different, ObjIdBindingFixture) { SetUp(GetName()); - + String name1; CONST_STRING(&name1, "name1"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 1, &name1)); - + String name2; CONST_STRING(&name2, "name2"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 2, &name2)); - + REQUIRE_RC_FAIL(KKeyStoreRegisterObject(ks, 1, &name2)); // name differs } @@ -273,27 +275,27 @@ FIXTURE_TEST_CASE(ObjIdById_Found, ObjIdBindingFixture) String name123; CONST_STRING(&name123, "name123"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 123, &name123)); - + String name12; CONST_STRING(&name12, "name12"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 12, &name12)); - + String name1; CONST_STRING(&name1, "name1"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 1, &name1)); - + const String* res; - + REQUIRE_RC(KKeyStoreGetObjectName(ks, 123, &res)); REQUIRE_NOT_NULL(res); REQUIRE_EQ(StringCompare(res, &name123), 0); StringWhack(res); - + REQUIRE_RC(KKeyStoreGetObjectName(ks, 12, &res)); REQUIRE_NOT_NULL(res); REQUIRE_EQ(StringCompare(res, &name12), 0); StringWhack(res); - + REQUIRE_RC(KKeyStoreGetObjectName(ks, 1, &res)); REQUIRE_NOT_NULL(res); REQUIRE_EQ(StringCompare(res, &name1), 0); @@ -303,15 +305,15 @@ FIXTURE_TEST_CASE(ObjIdById_Found, ObjIdBindingFixture) FIXTURE_TEST_CASE(ObjIdById_NotFound, ObjIdBindingFixture) { SetUp(GetName()); - + String name100; CONST_STRING(&name100, "name100"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 100, &name100)); - + String name200; CONST_STRING(&name200, "name200"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 200, &name200)); - + const String* res; REQUIRE_RC_FAIL(KKeyStoreGetObjectName(ks, 100200, &res)); } @@ -320,62 +322,62 @@ FIXTURE_TEST_CASE(ObjId_DefaultLocation, ObjIdBindingFixture) { const String* res; REQUIRE_RC_FAIL(KKeyStoreGetObjectName(ks, 1, &res)); // this will fail but set location to default - + // verify default location String* home; REQUIRE_RC(KConfigReadString(kfg, "NCBI_HOME", &home)); REQUIRE_NOT_NULL(home); - + const char* loc = KKeyStoreGetBindingsFile(ks); REQUIRE_NOT_NULL(loc); - REQUIRE_EQ(string(loc), string(home->addr, home->size) + "/objid.mapping"); + REQUIRE_EQ(string(loc), string(home->addr, home->size) + "/objid.mapping"); StringWhack(home); } FIXTURE_TEST_CASE(ObjIdByName_Found, ObjIdBindingFixture) { SetUp(GetName()); - + String name11; CONST_STRING(&name11, "name11"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 11, &name11)); - + String name21; CONST_STRING(&name21, "name21"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 21, &name21)); - + String name1; CONST_STRING(&name1, "name1"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 1, &name1)); - + uint32_t id; - + REQUIRE_RC(VKKeyStoreGetObjectId(ks, &name11, &id)); REQUIRE_EQ((uint32_t)11, id); REQUIRE_RC(VKKeyStoreGetObjectId(ks, &name21, &id)); REQUIRE_EQ((uint32_t)21, id); - + REQUIRE_RC(VKKeyStoreGetObjectId(ks, &name1, &id)); REQUIRE_EQ((uint32_t)1, id); } FIXTURE_TEST_CASE(ObjIdByName_NotFound, ObjIdBindingFixture) { SetUp(GetName()); - + String name11; CONST_STRING(&name11, "name11"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 11, &name11)); - + String name21; CONST_STRING(&name21, "name21"); REQUIRE_RC(KKeyStoreRegisterObject(ks, 21, &name21)); - + String name1; CONST_STRING(&name1, "name1"); - + uint32_t id; - + REQUIRE_RC_FAIL(VKKeyStoreGetObjectId(ks, &name1, &id)); } @@ -385,46 +387,20 @@ FIXTURE_TEST_CASE(ObjIdRegister_Lock, ObjIdBindingFixture) KFile* lockedFile; REQUIRE_RC(KDirectoryCreateExclusiveAccessFile(wd, &lockedFile, true, 0600, kcmOpen, GetName())); - + String name11; CONST_STRING(&name11, "name11"); REQUIRE_RC_FAIL(KKeyStoreRegisterObject(ks, 11, &name11)); - + REQUIRE_RC(KFileRelease(lockedFile)); - + // now, will work REQUIRE_RC(KKeyStoreRegisterObject(ks, 11, &name11)); } //////////////////////////////////////////// Main - -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-keystore"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KeyStoreTestSuite(argc, argv); - return rc; -} - + return KeyStoreTestSuite(argc, argv); } diff --git a/test/kfg/kfgtest.cpp b/test/kfg/kfgtest.cpp index 93ea9ed49..c01be0bc3 100644 --- a/test/kfg/kfgtest.cpp +++ b/test/kfg/kfgtest.cpp @@ -31,6 +31,7 @@ #include #include /* Args */ +#include #include #include @@ -81,9 +82,9 @@ FIXTURE_TEST_CASE(testKConfigPrint, KfgFixture) #ifdef ALL FIXTURE_TEST_CASE(KConfigLoadFile_should_report_null_inputs, KfgFixture) { - KFile file; - memset(&file, 0, sizeof file); - REQUIRE_RC_FAIL(KConfigLoadFile ( 0, "qweert", &file)); + KFile f; + memset(&f, 0, sizeof f); + REQUIRE_RC_FAIL(KConfigLoadFile ( 0, "qweert", &f)); REQUIRE_RC_FAIL(KConfigLoadFile ( kfg, "qweert", 0)); } @@ -204,12 +205,12 @@ FIXTURE_TEST_CASE(long_key, KfgFixture) FIXTURE_TEST_CASE(long_path, KfgFixture) { - string path=string(4097, 'v'); + string p=string(4097, 'v'); string line("k='"); - line+=path; + line+=p; line+="'"; CreateAndLoad(GetName(), line.c_str()); - REQUIRE(ValueMatches("k", path.c_str())); + REQUIRE(ValueMatches("k", p.c_str())); } FIXTURE_TEST_CASE(KConfigParse_SelfNull, KfgFixture) @@ -1069,7 +1070,7 @@ TEST_CASE(DontSaveCustomUserKfg) { size_t num_read = 0; REQUIRE_RC(KFileRead(r, 0, b, sizeof b, &num_read)); REQUIRE_EQ(strlen(contents), num_read); - REQUIRE_EQ(string_cmp(contents, num_read, b, num_read, num_read), 0); + REQUIRE_EQ(string_cmp(contents, num_read, b, num_read, (uint32_t)num_read), 0); REQUIRE_RC(KFileRelease(r)); REQUIRE_RC(KConfigRelease(kfg)); @@ -1081,7 +1082,7 @@ TEST_CASE(DontSaveCustomUserKfg) { REQUIRE_RC(KDirectoryOpenFileRead(d, &r, NAME)); REQUIRE_RC(KFileRead(r, 0, b, sizeof b, &num_read)); REQUIRE_EQ(strlen(contents), num_read); - REQUIRE_EQ(string_cmp(contents, num_read, b, num_read, num_read), 0); + REQUIRE_EQ(string_cmp(contents, num_read, b, num_read, (uint32_t)num_read), 0); REQUIRE_RC(KFileRelease(r)); REQUIRE_RC(KConfigRelease(kfg)); @@ -1100,32 +1101,9 @@ static rc_t argsHandler(int argc, char* argv[]) { return rc; } -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-kfg"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { + VDB::Application app(argc, argv); KConfigDisableUserSettings(); - rc_t rc=KfgTestSuite(argc, argv); - return rc; -} - + return KfgTestSuite(argc, argv); } diff --git a/test/kfg/ncbi-home-from-env.cpp b/test/kfg/ncbi-home-from-env.cpp index 3c0fcf69a..71ef7f1e7 100644 --- a/test/kfg/ncbi-home-from-env.cpp +++ b/test/kfg/ncbi-home-from-env.cpp @@ -43,7 +43,7 @@ int main(int argc, char **argv) { tail -= last - argv[0]; size_t sPfx = n - argv[0]; char command[PATH_MAX] = ""; - sprintf(command, + snprintf(command, sizeof(command), "./ncbi-home-from-env.sh %.*ssra-tools%.*s/../bin/vdb-config", sPfx, argv[0], l - tail - s, n + s); return system(command) != 0; diff --git a/test/kfg/propertiestest.cpp b/test/kfg/propertiestest.cpp index 7aa467fbc..4923a5c34 100644 --- a/test/kfg/propertiestest.cpp +++ b/test/kfg/propertiestest.cpp @@ -30,6 +30,9 @@ #include +#include + +#include #include "kfg-fixture.hpp" #include @@ -429,34 +432,10 @@ FIXTURE_TEST_CASE( GetSet_Telemetry, KfgFixture ) { #endif //////////////////////////////////////////// Main - -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-properties"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { + VDB::Application app(argc, argv); KConfigDisableUserSettings(); - rc_t rc=PropertiesTestSuite(argc, argv); - return rc; + return PropertiesTestSuite(argc, argv); } -} diff --git a/test/kfg/repositorytest.cpp b/test/kfg/repositorytest.cpp index e15d1f8e6..e5cd03438 100644 --- a/test/kfg/repositorytest.cpp +++ b/test/kfg/repositorytest.cpp @@ -58,7 +58,7 @@ class RepositoryFixture VectorInit(&repos, 0, 0); // in order to be able to whack it when we are done, even if not used by the test case ClearRepositories(); } - ~RepositoryFixture() + ~RepositoryFixture() { if (repo && KRepositoryRelease(repo) != 0) cerr << "~RepositoryFixture: KRepositoryRelease failed" << endl; @@ -69,7 +69,7 @@ class RepositoryFixture if (KConfigRelease(kfg) != 0) cerr << "~RepositoryFixture: KConfigRelease failed" << endl; } - + void UpdateNode(const char* key, const char* value) { KConfigNode *node; @@ -79,8 +79,8 @@ class RepositoryFixture throw logic_error("UpdateNode: KConfigNodeWrite failed"); if (KConfigNodeRelease(node) != 0) throw logic_error("UpdateNode: KConfigNodeRelease failed"); - } - + } + void ClearRepositories() { KConfigNode *node; @@ -91,7 +91,7 @@ class RepositoryFixture if (KConfigNodeRelease(node) != 0) throw logic_error("ClearRepositories: KConfigNodeRelease failed"); } - + bool ValidateRepository(const KRepository* r, KRepCategory cat, KRepSubCategory subcat, const char* name) { if (KRepositoryCategory( r ) != cat) @@ -104,12 +104,12 @@ class RepositoryFixture return false; return true; } - + KConfig* kfg; KRepositoryMgr* mgr; KRepositoryVector repos; const KRepository* repo; - + static const int BufSize = 1024; char buf[BufSize]; size_t num_writ; @@ -136,7 +136,7 @@ FIXTURE_TEST_CASE(Mgr_UserRepositoriesEmpty, RepositoryFixture) { KRepositoryVector v; // using a local vector to make sure it is initialized by the call UpdateNode("/repository/user", ""); - + REQUIRE_RC(KRepositoryMgrUserRepositories(mgr, &v)); REQUIRE_EQ(VectorLength(&v), (uint32_t)0); @@ -156,7 +156,7 @@ FIXTURE_TEST_CASE(Mgr_UserRepositories, RepositoryFixture) REQUIRE_RC(KRepositoryMgrUserRepositories(mgr, &repos)); REQUIRE_EQ(VectorLength(&repos), (uint32_t)4); - + // verify the values and that the vector has been sorted on: subcategory(main -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-kfg"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=RepositoryTestSuite(argc, argv); - return rc; -} - + return RepositoryTestSuite(argc, argv); } diff --git a/test/kfg/wb-test-kfg.cpp b/test/kfg/wb-test-kfg.cpp index 214ada95f..1798cfeb0 100644 --- a/test/kfg/wb-test-kfg.cpp +++ b/test/kfg/wb-test-kfg.cpp @@ -28,7 +28,7 @@ * Unit tests for Kfg interface */ -#include +#include #include #include @@ -597,32 +597,8 @@ FIXTURE_TEST_CASE(KfgParseVarRefPath, KfgParseFixture) } //////////////////////////////////////////// Main -extern "C" -{ -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "wb-test-kfg"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc = KfgWbTestSuite(argc, argv); - return rc; -} - + return KfgWbTestSuite(argc, argv); } diff --git a/test/kfs/CMakeLists.txt b/test/kfs/CMakeLists.txt index a397f892b..08fe858fd 100644 --- a/test/kfs/CMakeLists.txt +++ b/test/kfs/CMakeLists.txt @@ -24,29 +24,35 @@ add_compile_definitions( __mod__="test/kfs" ) +set( LIBS "${COMMON_LIBS_READ}") + if( NOT WIN32 ) - AddExecutableTest( Test_KFS_kdf "kdf" "${COMMON_LIBS_READ}" ) + AddExecutableTest( Test_KFS_kdf "kdf" "${LIBS}" ) endif() -AddExecutableTest( Test_KFS_base "kfstest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFS_ramfile "ramfiletest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFS_resolve "resolvetest" "${COMMON_LIBS_READ}" ) +AddExecutableTest( Test_KFS_base "kfstest" "${LIBS}" ) +AddExecutableTest( Test_KFS_ramfile "ramfiletest" "${LIBS}" ) +AddExecutableTest( Test_KFS_resolve "resolvetest" "${LIBS}" ) if( NOT WIN32 ) - AddExecutableTest( Test_KFS_link "test-link" "${COMMON_LIBS_READ}" ) + AddExecutableTest( Test_KFS_link "test-link" "${LIBS}" ) endif() -AddExecutableTest( Test_KFS_cachetee "cacheteetest" "${COMMON_LIBS_READ}" ) +AddExecutableTest( Test_KFS_read_observer-file "test-read_observer" "${LIBS}" ) +AddExecutableTest( Test_KFS_read_observer-bz "test-read_observer-bz2" "${LIBS}" +) +AddExecutableTest( Test_KFS_read_observer-gz "test-read_observer-gz" "${LIBS}" ) +AddExecutableTest( Test_KFS_cachetee "cacheteetest" "${LIBS}" ) if( NOT WIN32 ) # TODO: these fail on Windows - AddExecutableTest( Test_KFS_cachetee2 "cachetee2test" "${COMMON_LIBS_READ}" ) - AddExecutableTest( SlowTest_KFS_cachetee3 "cachetee3test" "${COMMON_LIBS_READ}" ) + AddExecutableTest( Test_KFS_cachetee2 "cachetee2test" "${LIBS}" ) + AddExecutableTest( SlowTest_KFS_cachetee3 "cachetee3test" "${LIBS}" ) endif() -AddExecutableTest( Test_KFS_lru_cache "lru_cache_test" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFS_md5 "md5test" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KFS_appendfile "appendfiletest" "${COMMON_LIBS_READ}" ) +AddExecutableTest( Test_KFS_lru_cache "lru_cache_test" "${LIBS}" ) +AddExecutableTest( Test_KFS_md5 "md5test" "${LIBS}" ) +AddExecutableTest( Test_KFS_appendfile "appendfiletest" "${LIBS}" ) if( NOT WIN32 ) - AddExecutableTest( Test_KFS_GZip "test-gzip" "${COMMON_LIBS_READ}" ) + AddExecutableTest( Test_KFS_GZip "test-gzip" "${LIBS}" ) endif() diff --git a/test/kfs/appendfiletest.cpp b/test/kfs/appendfiletest.cpp index f8ca73e6b..ab1934d39 100644 --- a/test/kfs/appendfiletest.cpp +++ b/test/kfs/appendfiletest.cpp @@ -35,6 +35,7 @@ #include #include +#include #include using namespace std; @@ -69,7 +70,7 @@ checkWriteFile ( KFile * File, size_t Pos, size_t Size ) } RCt = KFileWrite ( - File, + File, Offset + Pos, StringOne, ToWr, @@ -109,7 +110,7 @@ checkReadFile ( KFile * File, size_t Pos, size_t Size ) } RCt = KFileReadAll ( - File, + File, Pos, Buf, Size, @@ -146,7 +147,7 @@ checkMakeFile ( const char * Name, size_t Size ) RCt = KDirectoryNativeDir ( & Dir ); if ( RCt == 0 ) { - RCt = KDirectoryCreateFile ( + RCt = KDirectoryCreateFile ( Dir, & File, true, @@ -183,7 +184,7 @@ checkOpenFile ( KFile ** File, const char * Name, bool Write ) RCt = KDirectoryNativeDir ( & Dir ); if ( RCt == 0 ) { RCt = Write - ? KDirectoryOpenFileWrite ( Dir, File, "%s", Name ) + ? KDirectoryOpenFileWrite ( Dir, File, true, "%s", Name ) : KDirectoryOpenFileRead ( Dir, ( const KFile ** ) File, "%s", Name ) ; KDirectoryRelease ( Dir ); @@ -363,30 +364,9 @@ TEST_CASE(KAppendFile_set_size) //////////////////////////////////////////// Main -extern "C" +int +main ( int argc, char *argv [] ) { - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -rc_t CC UsageSummary (const char * prog_name) -{ - return 0; -} - -rc_t CC Usage ( const Args * args) -{ - return 0; -} - -const char UsageDefaultName[] = "test-appendfile"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc=AppendFileTestSuite(argc, argv); - return rc; -} - + VDB::Application app(argc, argv); + return AppendFileTestSuite(argc, argv); } diff --git a/test/kfs/cachetee-out-of-space.cpp b/test/kfs/cachetee-out-of-space.cpp index 65a900d49..46ef99f46 100644 --- a/test/kfs/cachetee-out-of-space.cpp +++ b/test/kfs/cachetee-out-of-space.cpp @@ -29,6 +29,8 @@ #include +#include + #include #include @@ -66,7 +68,7 @@ static rc_t fill_file_with_random_data( KFile * file, size_t file_size ) uint32_t data[ 512 ]; uint32_t i; size_t to_write, num_writ; - + for ( i = 0; i < 512; ++i ) data[ i ] = rand_32( 0, 0xFFFFFFFF - 1 ); to_write = ( file_size - total ); if ( to_write > sizeof data ) to_write = sizeof data; @@ -134,7 +136,7 @@ static rc_t remove_file( KDirectory * dir, const char * filename ) TEST_CASE( CacheTee_out_of_space ) { KOutMsg( "Test: CacheTee_out_of_space\n" ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); @@ -145,31 +147,31 @@ TEST_CASE( CacheTee_out_of_space ) // we open this file with random-data, created above const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + // we wrap this data-file into a cache-file const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTee ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); // now we can release the original data-file, the tee-file holds a reference to it... REQUIRE_RC( KFileRelease( org ) ); - + // this is the part that should not fail: we are reading the whole content of the tee-file. // because we have created the tee-file in a directory that has a quota... // the tee-file cannot grow to the necessary size, it should internally switch into // a passtrough-mode and just read the org-file instead of trying to cache... REQUIRE_RC( read_all( tee, ( 1024 * 7 ) ) ); - + // we clean up, by releasing the tee-file, and removing all the temp. files we created REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( remove_file( dir, CACHEFILE ) ); REQUIRE_RC( remove_file( dir, DATAFILE ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); -} +} TEST_CASE( CacheTee_v2_out_of_space ) { KOutMsg( "Test: CacheTee_v2_out_of_space\n" ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); @@ -180,31 +182,31 @@ TEST_CASE( CacheTee_v2_out_of_space ) // we open this file with random-data, created above const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + // we wrap this data-file into a cache-file const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTee2 ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); - + // now we can release the original data-file, the tee-file holds a reference to it... REQUIRE_RC( KFileRelease( org ) ); - + // this is the part that should not fail: we are reading the whole content of the tee-file. // because we have created the tee-file in a directory that has a quota... // the tee-file cannot grow to the necessary size, it should internally switch into // a passtrough-mode and just read the org-file instead of trying to cache... REQUIRE_RC( read_all( tee, ( 1024 * 7 ) ) ); - + // we clean up, by releasing the tee-file, and removing all the temp. files we created REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( remove_file( dir, CACHEFILE ) ); REQUIRE_RC( remove_file( dir, DATAFILE ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); -} +} TEST_CASE( CacheTee_v3_out_of_space ) { KOutMsg( "Test: CacheTee_v3_out_of_space\n" ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); @@ -215,44 +217,30 @@ TEST_CASE( CacheTee_v3_out_of_space ) // we open this file with random-data, created above const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + // we wrap this data-file into a cache-file const KFile * tee; REQUIRE_RC( KDirectoryMakeKCacheTeeFile_v3 ( dir, &tee, org, BLOCKSIZE, 2, 0, false, false, "%s", CACHEFILE ) ); - + // now we can release the original data-file, the tee-file holds a reference to it... REQUIRE_RC( KFileRelease( org ) ); - + // this is the part that should not fail: we are reading the whole content of the tee-file. // because we have created the tee-file in a directory that has a quota... // the tee-file cannot grow to the necessary size, it should internally switch into // a passtrough-mode and just read the org-file instead of trying to cache... REQUIRE_RC( read_all( tee, ( 1024 * 7 ) ) ); - + // we clean up, by releasing the tee-file, and removing all the temp. files we created REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( remove_file( dir, CACHEFILE ) ); REQUIRE_RC( remove_file( dir, DATAFILE ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); -} +} //////////////////////////////////////////// Main -extern "C" +int main ( int argc, char *argv [] ) { - -#include -#include - - ver_t CC KAppVersion ( void ) { return 0x1000000; } - rc_t CC UsageSummary ( const char * progname ) { return 0; } - rc_t CC Usage ( const Args * args ) { return 0; } - const char UsageDefaultName[] = "test-cachetee-out-of-space"; - - rc_t CC KMain ( int argc, char *argv [] ) - { - KConfigDisableUserSettings(); - return CacheTeeOutOfSpaceSuite( argc, argv ); - } - + KConfigDisableUserSettings(); + return CacheTeeOutOfSpaceSuite( argc, argv ); } - diff --git a/test/kfs/cachetee2test.cpp b/test/kfs/cachetee2test.cpp index ca75490d1..6b16e672e 100644 --- a/test/kfs/cachetee2test.cpp +++ b/test/kfs/cachetee2test.cpp @@ -35,6 +35,8 @@ #include +#include + #include #include @@ -76,7 +78,7 @@ static rc_t fill_file_with_random_data( KFile * file, size_t file_size ) uint32_t data[ 512 ]; uint32_t i; size_t to_write, num_writ; - + for ( i = 0; i < 512; ++i ) data[ i ] = rand_32( 0, 0xFFFFFFFF - 1 ); to_write = ( file_size - total ); if ( to_write > sizeof data ) to_write = sizeof data; @@ -251,47 +253,47 @@ static void finish_cachetee_tests( void ) TEST_CASE( CacheTee2_Basic ) { KOutMsg( "Test: CacheTee2_Basic\n" ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTee2 ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( KFileRelease( org ) ); - + const KFile * cache; REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s.cache", CACHEFILE ) ); - + bool is_complete; - REQUIRE_RC( IsCacheTee2FileComplete( cache, &is_complete ) ); + REQUIRE_RC( IsCacheTee2FileComplete( cache, &is_complete ) ); REQUIRE( !is_complete ); - + float percent; uint64_t bytes_in_cache; REQUIRE_RC( GetCacheTee2FileCompleteness( cache, &percent, &bytes_in_cache ) ); REQUIRE( ( percent == 0.0 ) ); REQUIRE( ( bytes_in_cache == 0 ) ); - + REQUIRE_RC( KFileRelease( cache ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); -} +} TEST_CASE( CacheTee2_Read ) { KOutMsg( "Test: CacheTee2_Read\n" ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTee2 ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); @@ -301,7 +303,7 @@ TEST_CASE( CacheTee2_Read ) REQUIRE_RC( compare_file_content( org, tee, 0, 100 ) ); // do it again, now from the cache REQUIRE_RC( compare_file_content( org, tee, 10, 100 ) ); - + REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE, 100 ) ); // small read at block boundary REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE, 100 ) ); // do it again, now from cache @@ -315,13 +317,13 @@ TEST_CASE( CacheTee2_Read ) REQUIRE_RC( compare_file_content( org, tee, 200, 1024 * BLOCKSIZE * 3 ) ); // very large read at pos 200 REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE * 2 + 10, 100 ) ); // small read after block boundary - REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE * 2 - 10, 100 ) ); // small read crossing block boundary + REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE * 2 - 10, 100 ) ); // small read crossing block boundary REQUIRE_RC( compare_file_content( org, tee, DATAFILESIZE - 100, 300 ) ); // small read crossing EOF REQUIRE_RC( compare_file_content( org, tee, DATAFILESIZE - 100, BLOCKSIZE * 10 ) ); // big read crossing EOF REQUIRE_RC( compare_file_content( org, tee, DATAFILESIZE - 10000, 10000 ) ); // big read right at EOF - - REQUIRE_RC( KFileRelease( tee ) ); + + REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); } @@ -330,7 +332,7 @@ TEST_CASE( CacheTee2_Read ) TEST_CASE( CacheTee2_Promoting ) { KOutMsg( "Test: CacheTee2_Promoting\n" ); - + remove_file( CACHEFILE ); // to start with a clean slate on caching... remove_file( CACHEFILE1 ); @@ -339,18 +341,18 @@ TEST_CASE( CacheTee2_Promoting ) const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTee2 ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( read_partial( tee, 1024 * 32, DATAFILESIZE / 2 ) ); REQUIRE_RC( KFileRelease( tee ) ); - + const KFile * cache; REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s.cache", CACHEFILE ) ); bool is_complete; - REQUIRE_RC( IsCacheTee2FileComplete( cache, &is_complete ) ); + REQUIRE_RC( IsCacheTee2FileComplete( cache, &is_complete ) ); REQUIRE( !is_complete ); float percent; @@ -363,12 +365,12 @@ TEST_CASE( CacheTee2_Promoting ) REQUIRE_RC( KDirectoryMakeCacheTee2 ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( read_all( tee, 1024 * 32 ) ); // this should trigger the promotion of the cache file from cache.dat.cache to cache.dat - REQUIRE_RC( KFileRelease( tee ) ); - + REQUIRE_RC( KFileRelease( tee ) ); + REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE ) ); // if we can open this file then, it was promoted... REQUIRE_RC( KFileRelease( cache ) ); - - REQUIRE_RC( KFileRelease( org ) ); + + REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); } @@ -401,7 +403,7 @@ static rc_t cache_access( int tid, int num_threads, const KFile * origfile, cons KOutMsg( "Test: Thread #%d OK\n", tid ); else KOutMsg( "Test: Thread #%d failed\n", tid ); - + return rc; } @@ -461,7 +463,7 @@ TEST_CASE( CacheTee2_Multiple_Users_Multiple_Inst ) rc = KThreadMake ( &( t[ i ] ), thread_func, &( td[ i ] ) ); REQUIRE_RC( rc ); } - + for ( int i = 0; i < n && rc == 0; ++i ) { rc_t rc_thread; @@ -534,7 +536,7 @@ TEST_CASE( CacheTee2_ReadOnly ) REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( KDirectorySetAccess ( dir, false, 0, 0222, "%s", CACHEFILE1 ) ); - + /* make a second cache-tee and read all from it... */ REQUIRE_RC( KDirectoryMakeCacheTee2( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( read_all( tee, 1024 * 32 ) ); @@ -543,11 +545,11 @@ TEST_CASE( CacheTee2_ReadOnly ) /* we read all from the tee-file that should have promoted it on Release, but we made it read only before the creation of the 2nd tee-file because of that it should not be promoted and not complete */ - + const KFile * cache; REQUIRE_RC_FAIL( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE ) ); REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE1 ) ); - + /* make a second cache-tee and read all from it... */ REQUIRE_RC( KDirectoryMakeCacheTee2 ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); @@ -558,18 +560,18 @@ TEST_CASE( CacheTee2_ReadOnly ) /* we read all from the tee-file that should have promoted it on Release, but we made it read only before the creation of the 2nd tee-file because of that it should not be promoted and not complete */ - + REQUIRE_RC_FAIL( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE ) ); REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE1 ) ); - + bool is_complete; - REQUIRE_RC( IsCacheTee2FileComplete( cache, &is_complete ) ); + REQUIRE_RC( IsCacheTee2FileComplete( cache, &is_complete ) ); REQUIRE( !is_complete ); - REQUIRE_RC( KFileRelease( cache ) ); - REQUIRE_RC( KFileRelease( org ) ); + REQUIRE_RC( KFileRelease( cache ) ); + REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); - + } #endif @@ -595,7 +597,7 @@ TEST_CASE( CacheTee2_Multiple_Users_with_Promoting ) REQUIRE_RC( read_all( tee1, 1024 * 32 ) ); REQUIRE_RC( KFileRelease( tee1 ) ); - /* read a little bit from tee2 and release it, will it corrupt the cache? */ + /* read a little bit from tee2 and release it, will it corrupt the cache? */ REQUIRE_RC( read_partial( tee2, 100, 100 ) ); REQUIRE_RC( KFileRelease( tee2 ) ); @@ -609,46 +611,21 @@ TEST_CASE( CacheTee2_Multiple_Users_with_Promoting ) REQUIRE( pt == kptNotFound ); #endif - REQUIRE_RC( KFileRelease( org ) ); + REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -rc_t CC UsageSummary ( const char * progname ) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "cachetee2-test"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { srand( time( NULL ) ); KConfigDisableUserSettings(); rc_t rc = prepare_cachetee_tests(); if ( rc == 0 ) { - rc = CacheTeeTests( argc, argv ); + rc = (rc_t)CacheTeeTests( argc, argv ); finish_cachetee_tests(); } KOutMsg( "and the result is: %R\n", rc ); - return rc; -} - + return (int)rc; } diff --git a/test/kfs/cachetee3test.cpp b/test/kfs/cachetee3test.cpp index 21dfca797..588cfc9ba 100755 --- a/test/kfs/cachetee3test.cpp +++ b/test/kfs/cachetee3test.cpp @@ -37,9 +37,15 @@ #include #include #include +#include #include +#include + +#include + + #include #include #include @@ -988,9 +994,9 @@ rc_t CC MakeCallBackFile ( struct KFile **callback_file, struct CallBackCounter { - uint64_t events; - uint64_t bytes; - uint64_t pos; + atomic events; + atomic bytes; + atomic pos; CallBackCounter( void ) : events( 0 ), bytes( 0 ), pos( 0 ) {} void count( uint64_t a_pos, uint64_t n ) { events++; bytes += n; pos = a_pos; } @@ -1059,9 +1065,9 @@ FIXTURE_TEST_CASE ( CacheTee3_request_count, CT3Fixture ) REQUIRE_RC( compare_file_content_3 ( org2, tee_counted, pos, len, NULL ) ); } - KOutMsg ( "requested = %,lu, bytes = %,lu\n", cbc2 . events, cbc2 . bytes ); - KOutMsg ( "orig. file = %,lu, bytes = %,lu\n", cbc1 . events, cbc1 . bytes ); - REQUIRE( cbc1 . events < cbc2 . events ); + KOutMsg ( "requested = %,lu, bytes = %,lu\n", cbc2 . events.load(), cbc2 . bytes.load() ); + KOutMsg ( "orig. file = %,lu, bytes = %,lu\n", cbc1 . events.load(), cbc1 . bytes.load() ); + REQUIRE( cbc1 . events.load() < cbc2 . events.load() ); // after reading the whole thing - no read-request should be made via orig... KOutMsg ( "requesting whole file\n" ); @@ -1081,8 +1087,8 @@ FIXTURE_TEST_CASE ( CacheTee3_request_count, CT3Fixture ) } REQUIRE_RC( compare_file_content_3 ( org2, tee_counted, DATAFILESIZE - 1000, 2000, NULL ) ); - KOutMsg ( "requested = %,lu, bytes = %,lu\n", cbc2 . events, cbc2 . bytes ); - KOutMsg ( "orig. file = %,lu, bytes = %,lu\n", cbc1 . events, cbc1 . bytes ); + KOutMsg ( "requested = %,lu, bytes = %,lu\n", cbc2 . events.load(), cbc2 . bytes.load() ); + KOutMsg ( "orig. file = %,lu, bytes = %,lu\n", cbc1 . events.load(), cbc1 . bytes.load() ); REQUIRE( cbc1 . events == 0 ); REQUIRE( cbc1 . bytes == 0 ); @@ -1462,19 +1468,6 @@ TEST_CASE( concurrent_reads_from_different_files ) } //////////////////////////////////////////// Main -extern "C" { - -#include -#include - -ver_t CC KAppVersion ( void ) { return 0x1000000; } - -rc_t CC UsageSummary ( const char *progname ) { return 0; } - -rc_t CC Usage ( const Args *args ) { return 0; } - -const char UsageDefaultName[] = "cachetee3-test"; - #define OPTION_DUMMY "dummy" #define ALIAS_DUMMY "d" @@ -1483,7 +1476,7 @@ static const char *dummy_usage[] = {"dummy argument", NULL}; OptDef TestOptions[] = {{OPTION_DUMMY, ALIAS_DUMMY, NULL, dummy_usage, 1, false, false}}; -rc_t CC KMain ( int argc, char *argv[] ) +int main ( int argc, char *argv[] ) { Args *args; @@ -1505,4 +1498,3 @@ rc_t CC KMain ( int argc, char *argv[] ) return rc; } -} /* extern "C" */ diff --git a/test/kfs/cacheteetest.cpp b/test/kfs/cacheteetest.cpp index d0fde3dd3..dc5944eb8 100644 --- a/test/kfs/cacheteetest.cpp +++ b/test/kfs/cacheteetest.cpp @@ -35,6 +35,10 @@ #include +#include + +#include + #include #include @@ -44,8 +48,6 @@ #include #include #include -//#include -//#include using namespace std; @@ -62,7 +64,7 @@ TEST_SUITE( CacheTeeTests ); static uint32_t rand_32( uint32_t min, uint32_t max ) { double scaled = ( ( double )rand() / RAND_MAX ); - return ( ( max - min + 1 ) * scaled ) + min; + return (uint32_t) ( ( ( max - min + 1 ) * scaled ) + min ); } static rc_t fill_file_with_random_data( KFile * file, size_t file_size ) @@ -77,7 +79,7 @@ static rc_t fill_file_with_random_data( KFile * file, size_t file_size ) uint32_t data[ 512 ]; uint32_t i; size_t to_write, num_writ; - + for ( i = 0; i < 512; ++i ) data[ i ] = rand_32( 0, 0xFFFFFFFF - 1 ); to_write = ( file_size - total ); if ( to_write > sizeof data ) to_write = sizeof data; @@ -252,47 +254,47 @@ static void finish_cachetee_tests( void ) TEST_CASE( CacheTee_Basic ) { KOutMsg( "Test: CacheTee_Basic\n" ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTeePromote ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( KFileRelease( org ) ); - + const KFile * cache; REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s.cache", CACHEFILE ) ); - + bool is_complete; - REQUIRE_RC( IsCacheFileComplete( cache, &is_complete ) ); + REQUIRE_RC( IsCacheFileComplete( cache, &is_complete ) ); REQUIRE( !is_complete ); - + float percent; uint64_t bytes_in_cache; REQUIRE_RC( GetCacheCompleteness( cache, &percent, &bytes_in_cache ) ); REQUIRE( ( percent == 0.0 ) ); REQUIRE( ( bytes_in_cache == 0 ) ); - + REQUIRE_RC( KFileRelease( cache ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); -} +} TEST_CASE( CacheTee_Read ) { KOutMsg( "Test: CacheTee_Read\n" ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTeePromote ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); @@ -301,7 +303,7 @@ TEST_CASE( CacheTee_Read ) REQUIRE_RC( compare_file_content( org, tee, 0, 100 ) ); // do it again, now from the cache REQUIRE_RC( compare_file_content( org, tee, 10, 100 ) ); - + REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE, 100 ) ); // small read at block boundary REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE, 100 ) ); // do it again, now from cache @@ -315,13 +317,13 @@ TEST_CASE( CacheTee_Read ) REQUIRE_RC( compare_file_content( org, tee, 200, 1024 * BLOCKSIZE * 3 ) ); // very large read at pos 200 REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE * 2 + 10, 100 ) ); // small read after block boundary - REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE * 2 - 10, 100 ) ); // small read crossing block boundary + REQUIRE_RC( compare_file_content( org, tee, 1024 * BLOCKSIZE * 2 - 10, 100 ) ); // small read crossing block boundary REQUIRE_RC( compare_file_content( org, tee, DATAFILESIZE - 100, 300 ) ); // small read crossing EOF REQUIRE_RC( compare_file_content( org, tee, DATAFILESIZE - 100, BLOCKSIZE * 10 ) ); // big read crossing EOF REQUIRE_RC( compare_file_content( org, tee, DATAFILESIZE - 10000, 10000 ) ); // big read right at EOF - - REQUIRE_RC( KFileRelease( tee ) ); + + REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); } @@ -330,7 +332,7 @@ TEST_CASE( CacheTee_Read ) TEST_CASE( CacheTee_Promoting ) { KOutMsg( "Test: CacheTee_Promoting\n" ); - + remove_file( CACHEFILE ); // to start with a clean slate on caching... remove_file( CACHEFILE1 ); @@ -339,18 +341,18 @@ TEST_CASE( CacheTee_Promoting ) const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", DATAFILE ) ); - + const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTeePromote ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( read_partial( tee, 1024 * 32, DATAFILESIZE / 2 ) ); REQUIRE_RC( KFileRelease( tee ) ); - + const KFile * cache; REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s.cache", CACHEFILE ) ); bool is_complete; - REQUIRE_RC( IsCacheFileComplete( cache, &is_complete ) ); + REQUIRE_RC( IsCacheFileComplete( cache, &is_complete ) ); REQUIRE( !is_complete ); float percent; @@ -363,12 +365,12 @@ TEST_CASE( CacheTee_Promoting ) REQUIRE_RC( KDirectoryMakeCacheTeePromote ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( read_all( tee, 1024 * 32 ) ); // this should trigger the promotion of the cache file from cache.dat.cache to cache.dat - REQUIRE_RC( KFileRelease( tee ) ); - + REQUIRE_RC( KFileRelease( tee ) ); + REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE ) ); // if we can open this file then, it was promoted... REQUIRE_RC( KFileRelease( cache ) ); - - REQUIRE_RC( KFileRelease( org ) ); + + REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); } @@ -393,7 +395,7 @@ static rc_t cache_access( int tid, int num_threads, const KFile * origfile, cons std::random_shuffle( &chunk_pos[ 0 ], &chunk_pos[ num_chunks ] ); for ( i = 0; i < num_chunks; ++i ) { - rc = compare_file_content( origfile, cacheteefile, chunk_pos[ i ], chunk_size ); + rc = compare_file_content( origfile, cacheteefile, (uint64_t) chunk_pos[ i ], (size_t) chunk_size ); if ( rc != 0 ) break; } @@ -401,10 +403,43 @@ static rc_t cache_access( int tid, int num_threads, const KFile * origfile, cons KOutMsg( "Test: Thread #%d OK\n", tid ); else KOutMsg( "Test: Thread #%d failed\n", tid ); - + return rc; } +#if 0 + +// this might work in the future when we make cacheteefile thread safe (probably in the context of making the entinr VDB library thread safe) +// for now, disabling the test since it triggers this thread sanitizer failure: + +27: CacheTee_Promoting (0 s) +27: Test: CacheTee_Multiple_Users_Multiple_Inst +27: ================== +27: WARNING: ThreadSanitizer: data race (pid=1845751) +27: Write of size 8 at 0x7b0400000040 by thread T1: +27: #0 open (libtsan.so.2+0x42e42) +27: #1 KSysDirCreateFile_v1 /home/boshkina/devel/ncbi-vdb/libs/kfs/unix/sysdir.c:2105 (Test_KFS_cachetee_tsan+0x4e7594) +27: #2 KThreadRun /home/boshkina/devel/ncbi-vdb/libs/kproc/unix/systhread.c:81 (Test_KFS_cachetee_tsan+0x59b3c7) +27: +27: Previous write of size 8 at 0x7b0400000040 by main thread: +27: #0 pipe (libtsan.so.2+0x43e81) +27: #1 __sanitizer::IsAccessibleMemoryRange(unsigned long, unsigned long) (libubsan.so.1+0x1f75e) +27: #2 ncbi::NK::TestCaseInvoker::Run(void*) (Test_KFS_cachetee_tsan+0x42037d) +27: #3 ncbi::NK::TestRunner::Run(void*) const /home/boshkina/devel/ncbi-vdb/libs/ktst/testrunner.cpp:70 (Test_KFS_cachetee_tsan+0x42503e) +27: #4 CacheTeeTests(int, char**) /home/boshkina/devel/ncbi-vdb/test/kfs/cacheteetest.cpp:60 (Test_KFS_cachetee_tsan+0x4063ad) +27: #5 main /home/boshkina/devel/ncbi-vdb/test/kfs/cacheteetest.cpp:669 (Test_KFS_cachetee_tsan+0x412bf9) +27: +27: Thread T1 (tid=1845781, running) created by main thread at: +27: #0 pthread_create (libtsan.so.2+0x41436) +27: #1 KThreadMakeStackSize /home/boshkina/devel/ncbi-vdb/libs/kproc/unix/systhread.c:154 (Test_KFS_cachetee_tsan+0x59b60d) +27: #2 ncbi::NK::TestCaseInvoker::Run(void*) (Test_KFS_cachetee_tsan+0x42037d) +27: #3 ncbi::NK::TestRunner::Run(void*) const /home/boshkina/devel/ncbi-vdb/libs/ktst/testrunner.cpp:70 (Test_KFS_cachetee_tsan+0x42503e) +27: #4 CacheTeeTests(int, char**) /home/boshkina/devel/ncbi-vdb/test/kfs/cacheteetest.cpp:60 (Test_KFS_cachetee_tsan+0x4063ad) +27: #5 main /home/boshkina/devel/ncbi-vdb/test/kfs/cacheteetest.cpp:669 (Test_KFS_cachetee_tsan+0x412bf9) +27: +27: SUMMARY: ThreadSanitizer: data race (/opt/ncbi/gcc/13.2.0/lib64/libtsan.so.2+0x42e42) in __interceptor_open +27: ================== + struct ThreadData { int tid; @@ -462,7 +497,7 @@ TEST_CASE( CacheTee_Multiple_Users_Multiple_Inst ) rc = KThreadMake ( &( t[ i ] ), thread_func, &( td[ i ] ) ); REQUIRE_RC( rc ); } - + for ( int i = 0; i < n && rc == 0; ++i ) { rc_t rc_thread; @@ -473,7 +508,6 @@ TEST_CASE( CacheTee_Multiple_Users_Multiple_Inst ) } } - TEST_CASE( CacheTee_Multiple_Users_Single_Inst ) { KOutMsg( "Test: CacheTee_Multiple_Users_Single_Inst\n" ); @@ -514,6 +548,7 @@ TEST_CASE( CacheTee_Multiple_Users_Single_Inst ) REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); } +#endif // TODO: fix, this does not work on Windows #if !defined(WINDOWS) && !defined(_WIN32) && !defined(MAC) @@ -536,7 +571,7 @@ TEST_CASE( CacheTee_ReadOnly ) REQUIRE_RC( KFileRelease( tee ) ); REQUIRE_RC( KDirectorySetAccess ( dir, false, 0, 0222, "%s", CACHEFILE1 ) ); - + /* make a second cache-tee and read all from it... */ REQUIRE_RC( KDirectoryMakeCacheTee( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( read_all( tee, 1024 * 32 ) ); @@ -545,11 +580,11 @@ TEST_CASE( CacheTee_ReadOnly ) /* we read all from the tee-file that should have promoted it on Release, but we made it read only before the creation of the 2nd tee-file because of that it should not be promoted and not complete */ - + const KFile * cache; REQUIRE_RC_FAIL( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE ) ); REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE1 ) ); - + /* make a second cache-tee and read all from it... */ REQUIRE_RC( KDirectoryMakeCacheTeePromote ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( read_all( tee, 1024 * 32 ) ); @@ -559,18 +594,18 @@ TEST_CASE( CacheTee_ReadOnly ) /* we read all from the tee-file that should have promoted it on Release, but we made it read only before the creation of the 2nd tee-file because of that it should not be promoted and not complete */ - + REQUIRE_RC_FAIL( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE ) ); REQUIRE_RC( KDirectoryOpenFileRead( dir, &cache, "%s", CACHEFILE1 ) ); - + bool is_complete; - REQUIRE_RC( IsCacheFileComplete( cache, &is_complete ) ); + REQUIRE_RC( IsCacheFileComplete( cache, &is_complete ) ); REQUIRE( !is_complete ); - REQUIRE_RC( KFileRelease( cache ) ); - REQUIRE_RC( KFileRelease( org ) ); + REQUIRE_RC( KFileRelease( cache ) ); + REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); - + } #endif @@ -596,7 +631,7 @@ TEST_CASE( CacheTee_Multiple_Users_with_Promoting ) REQUIRE_RC( read_all( tee1, 1024 * 32 ) ); REQUIRE_RC( KFileRelease( tee1 ) ); - /* read a little bit from tee2 and release it, will it corrupt the cache? */ + /* read a little bit from tee2 and release it, will it corrupt the cache? */ REQUIRE_RC( read_partial( tee2, 100, 100 ) ); REQUIRE_RC( KFileRelease( tee2 ) ); @@ -606,7 +641,7 @@ TEST_CASE( CacheTee_Multiple_Users_with_Promoting ) /* the .cache - file has to be gone */ /* NB: promoting on Windows with multiple threads does not work!*/ -#if !defined(WINDOWS) && !defined(_WIN32) +#if !defined(WINDOWS) && !defined(_WIN32) uint32_t pt = KDirectoryPathType(dir, "%s", CACHEFILE1); REQUIRE( pt == kptNotFound ); #endif @@ -630,7 +665,7 @@ TEST_CASE( CacheTee_None_Promoting ) /* make a non-promotiong CacheTeeFile */ const KFile * tee; REQUIRE_RC( KDirectoryMakeCacheTee ( dir, &tee, org, BLOCKSIZE, "%s", CACHEFILE ) ); - + /* read all from tee and release it, that should not trigger promotion !!! */ REQUIRE_RC( read_all( tee, 1024 * 32 ) ); REQUIRE_RC( KFileRelease( tee ) ); @@ -638,7 +673,7 @@ TEST_CASE( CacheTee_None_Promoting ) /* the cache.dat.cache - file should still be there */ uint32_t pt = KDirectoryPathType ( dir, "%s", CACHEFILE1 ); REQUIRE( pt == kptFile ); - + /* the cache.dat - file should not be there */ pt = KDirectoryPathType ( dir, "%s", CACHEFILE ); REQUIRE( pt == kptNotFound ); @@ -648,48 +683,25 @@ TEST_CASE( CacheTee_None_Promoting ) REQUIRE_RC( KDirectoryMakeCacheTee ( dir, &tee1, org, BLOCKSIZE, "%s", CACHEFILE ) ); REQUIRE_RC( KFileRelease( tee1 ) ); - REQUIRE_RC( KFileRelease( org ) ); + REQUIRE_RC( KFileRelease( org ) ); REQUIRE_RC( KDirectoryRelease( dir ) ); } //////////////////////////////////////////// Main -extern "C" +int main ( int argc, char *argv [] ) { + VDB::Application app(argc, argv); -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -rc_t CC UsageSummary ( const char * progname ) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "cachetee-test"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - srand( time( NULL ) ); + srand( (unsigned int) time( NULL ) ); KConfigDisableUserSettings(); rc_t rc = prepare_cachetee_tests(); if ( rc == 0 ) { - rc = CacheTeeTests( argc, argv ); + rc = (rc_t) CacheTeeTests( argc, argv ); finish_cachetee_tests(); } KOutMsg( "and the result is: %R\n", rc ); - return rc; -} - + return (int) rc; } diff --git a/test/kfs/kdf.cpp b/test/kfs/kdf.cpp index 5da45770d..ab8270357 100644 --- a/test/kfs/kdf.cpp +++ b/test/kfs/kdf.cpp @@ -290,22 +290,14 @@ static rc_t argsHandler ( int argc, char * argv [] ) { return rc; } -rc_t CC UsageSummary (const char * progname) { return 0; } -rc_t CC Usage ( const Args * args ) { return 0; } -const char UsageDefaultName [] = "kdf"; - -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - - rc_t KMain ( int argc, char * argv [] ) { +int main ( int argc, char * argv [] ) { ncbi::NK::TestEnv::SetVerbosity(ncbi::NK::LogLevel::e_all); - rc_t rc = DuSuite ( argc, argv ); + int rc = DuSuite ( argc, argv ); - s_path = NULL; + s_path = NULL; - ArgsWhack ( args ); - args = NULL; + ArgsWhack ( args ); + args = NULL; - return rc; - } + return rc; } diff --git a/test/kfs/kfstest.cpp b/test/kfs/kfstest.cpp index 25eb2a149..e85248690 100644 --- a/test/kfs/kfstest.cpp +++ b/test/kfs/kfstest.cpp @@ -31,6 +31,9 @@ #include #include + +#include + #include #include #include @@ -83,7 +86,7 @@ TEST_CASE(Tar_Parse) REQUIRE_RC(KDirectoryNativeDir(&dir)); const KDirectory *tarDir; - REQUIRE_RC(KDirectoryOpenTarArchiveRead(dir, &tarDir, false, "test.tar")); + REQUIRE_EQ(0, KDirectoryOpenTarArchiveRead(dir, &tarDir, false, "test.tar")); struct KNamelist *list; REQUIRE_RC(KDirectoryList(tarDir, &list, NULL, NULL, NULL)); @@ -104,33 +107,8 @@ TEST_CASE(Tar_Parse) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-kfs"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KfsTestSuite(argc, argv); - return rc; -} - + return KfsTestSuite(argc, argv); } diff --git a/test/kfs/lru_cache_test.cpp b/test/kfs/lru_cache_test.cpp index 146318fc4..d0adfaa48 100644 --- a/test/kfs/lru_cache_test.cpp +++ b/test/kfs/lru_cache_test.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -41,7 +43,7 @@ static size_t rand_32( size_t min, size_t max ) { double scaled = ( ( double )rand() / RAND_MAX ); - return ( (double)( max - min + 1 ) * scaled ) + min; + return (size_t)( (double)( max - min + 1 ) * scaled ) + min; } static rc_t fill_file_with_random_data( KFile * file, size_t file_size ) @@ -56,8 +58,8 @@ static rc_t fill_file_with_random_data( KFile * file, size_t file_size ) uint32_t data[ 512 ]; uint32_t i; size_t to_write, num_writ; - - for ( i = 0; i < 512; ++i ) data[ i ] = rand_32( 0, 0xFFFFFFFF - 1 ); + + for ( i = 0; i < 512; ++i ) data[ i ] = (uint32_t)rand_32( 0, 0xFFFFFFFF - 1 ); to_write = ( file_size - total ); if ( to_write > sizeof data ) to_write = sizeof data; rc = KFileWriteAll ( file, pos, data, to_write, &num_writ ); @@ -131,23 +133,23 @@ static rc_t compare_file_content( const KFile * file1, const KFile * file2, uint void seed_random_number_generator( void ) { KTime_t t = KTimeStamp (); /* klib/time.h */ - srand( t ); + srand( (unsigned int)t ); } TEST_SUITE( LRU_Cache_Test ); #define PAGE_SIZE 128 * 1024 -#define PAGE_COUNT 1024 +#define PAGE_COUNT 1024 TEST_CASE( LRU_Cache_Test_Basic ) { KOutMsg( "Test: LRU-Cache-Test-Basic\n" ); - + REQUIRE_RC_FAIL( MakeRRCached ( NULL, NULL, 0, 0 ) ); REQUIRE_RC_FAIL( MakeRRCached ( NULL, NULL, PAGE_SIZE, PAGE_COUNT ) ); REQUIRE_RC_FAIL( MakeRRCached ( NULL, NULL, 0, PAGE_COUNT ) ); REQUIRE_RC_FAIL( MakeRRCached ( NULL, NULL, PAGE_SIZE, 0 ) ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); @@ -160,23 +162,23 @@ TEST_CASE( LRU_Cache_Test_Basic ) const KFile * org; REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", filename ) ); - + REQUIRE_RC_FAIL( MakeRRCached ( NULL, org, 0, 0L ) ); REQUIRE_RC_FAIL( MakeRRCached ( NULL, org, PAGE_SIZE, PAGE_COUNT ) ); REQUIRE_RC_FAIL( MakeRRCached ( NULL, org, 0, PAGE_COUNT ) ); REQUIRE_RC_FAIL( MakeRRCached ( NULL, org, PAGE_SIZE, 0 ) ); - + const KFile * cache; REQUIRE_RC_FAIL( MakeRRCached ( &cache, org, 0, 0 ) ); REQUIRE_RC_FAIL( MakeRRCached ( &cache, org, 0, PAGE_COUNT ) ); REQUIRE_RC_FAIL( MakeRRCached ( &cache, org, PAGE_SIZE, 0 ) ); REQUIRE_RC( MakeRRCached ( &cache, org, PAGE_SIZE, PAGE_COUNT ) ); - + KFileRelease( org ); KFileRelease( cache ); KDirectoryRemove ( dir, true, "%s", filename ); - + REQUIRE_RC( KDirectoryRelease( dir ) ); } @@ -203,7 +205,7 @@ void on_event( void * data, enum cache_event event, uint64_t pos, size_t len, ui case CE_ENTER : ev -> enter++; //KOutMsg( "E %lx.%lx (%u)\n", pos, len, block_nr ); break; - + case CE_DISCARD : ev -> discard++; //KOutMsg( "D %lx.%lx (%u)\n", pos, len, block_nr ); break; @@ -225,7 +227,7 @@ void print_events( events * events ) TEST_CASE( LRU_Cache_Test_Linear_Reading ) { KOutMsg( "Test: LRU-Cache-Test-Linear-Reading\n" ); - + KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); @@ -241,7 +243,7 @@ TEST_CASE( LRU_Cache_Test_Linear_Reading ) const KFile * cache; REQUIRE_RC( MakeRRCached ( &cache, org, 64 * 1024, 22 ) ); - + uint64_t file_size; REQUIRE_RC( KFileSize ( cache, &file_size ) ); REQUIRE( ( file_size == ( PAGE_SIZE * 10 ) ) ); @@ -249,7 +251,7 @@ TEST_CASE( LRU_Cache_Test_Linear_Reading ) events events; memset( &events, 0, sizeof events ); REQUIRE_RC( SetRRCachedEventHandler( cache, &events, on_event ) ); - + REQUIRE_RC( compare_file_content( org, cache, 0, file_size ) ); REQUIRE_RC( compare_file_content( org, cache, 0, file_size ) ); @@ -260,12 +262,12 @@ TEST_CASE( LRU_Cache_Test_Linear_Reading ) // print_events( &events ); REQUIRE( events . requests == 21 ); REQUIRE( events . found == 20 ); - REQUIRE( events . enter == 20 ); + REQUIRE( events . enter == 20 ); REQUIRE( events . discard == 0 ); REQUIRE( events . failed == 0 ); #endif - REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", filename ) ); + REQUIRE_RC( KDirectoryOpenFileRead( dir, &org, "%s", filename ) ); REQUIRE_RC( MakeRRCached ( &cache, org, 64 * 1024, 20 ) ); memset( &events, 0, sizeof events ); REQUIRE_RC( SetRRCachedEventHandler( cache, &events, on_event ) ); @@ -277,7 +279,7 @@ TEST_CASE( LRU_Cache_Test_Linear_Reading ) //print_events( &events ); REQUIRE( events . requests == 21 ); REQUIRE( events . found == 20 ); - REQUIRE( events . enter == 20 ); + REQUIRE( events . enter == 20 ); REQUIRE( events . discard == 0 ); REQUIRE( events . failed == 0 ); #endif @@ -295,7 +297,7 @@ TEST_CASE( LRU_Cache_Test_Random_Reading ) KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); - const char * filename = "./LRU_Cache_Test_Random_Reading.txt"; + const char * filename = "./LRU_Cache_Test_Random_Reading.txt"; KFile * file; size_t file_size = PAGE_SIZE * 10; @@ -330,7 +332,7 @@ TEST_CASE( LRU_Cache_Test_Random_Reading ) //print_events( &events ); REQUIRE( events . requests >= loops ); REQUIRE( events . found >= loops ); - REQUIRE( events . enter = page_count ); + REQUIRE( events . enter == page_count ); REQUIRE( events . failed == 0 ); #endif @@ -341,36 +343,11 @@ TEST_CASE( LRU_Cache_Test_Random_Reading ) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -rc_t CC UsageSummary ( const char * progname ) +int main ( int argc, char *argv [] ) { - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "lru-cache-test"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc; + int rc; seed_random_number_generator(); rc = LRU_Cache_Test( argc, argv ); KOutMsg( "lru-cache-test : %R\n", rc ); return rc; } - -} diff --git a/test/kfs/md5test.cpp b/test/kfs/md5test.cpp index 3819c75f4..99fb7ea65 100644 --- a/test/kfs/md5test.cpp +++ b/test/kfs/md5test.cpp @@ -33,6 +33,8 @@ #include +#include + #include #include #include @@ -162,33 +164,9 @@ TEST_CASE(KMD5WriteFileNotTruncateWithoutChange) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-kfs-md5"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KMD5FileTestSuite(argc, argv); - return rc; + return KMD5FileTestSuite(argc, argv); } -} diff --git a/test/kfs/ramfiletest.cpp b/test/kfs/ramfiletest.cpp index f7b60d8c9..2b1118f4e 100644 --- a/test/kfs/ramfiletest.cpp +++ b/test/kfs/ramfiletest.cpp @@ -168,32 +168,8 @@ TEST_CASE(KRamFileWrite_shift_right) } //////////////////////////////////////////// Main - -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -rc_t CC UsageSummary (const char * prog_name) -{ - return 0; -} - -rc_t CC Usage ( const Args * args) -{ - return 0; -} - -const char UsageDefaultName[] = "test-kfg"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=RamFileTestSuite(argc, argv); - return rc; -} - + return RamFileTestSuite(argc, argv); } diff --git a/test/kfs/resolvetest.cpp b/test/kfs/resolvetest.cpp index 827e69829..5b24f890a 100644 --- a/test/kfs/resolvetest.cpp +++ b/test/kfs/resolvetest.cpp @@ -55,7 +55,7 @@ class ResolveFixture { KDirectoryRelease( m_dir ); } } - + char m_resolved[ 4 * 1024 ]; KDirectory *m_dir; }; @@ -73,7 +73,7 @@ FIXTURE_TEST_CASE( ResolveTest_Simple, ResolveFixture ) FIXTURE_TEST_CASE( ResolveTest_DoubleLeading, ResolveFixture ) { REQUIRE_RC( KDirectoryResolvePath ( m_dir, true, m_resolved, sizeof m_resolved, "//1/22/333" ) ); -#ifdef WINDOWS +#ifdef WINDOWS REQUIRE_RESOLVE( "//1/22/333", "//1/22/333"); #else REQUIRE_RESOLVE( "//1/22/333", "/1/22/333"); @@ -122,11 +122,11 @@ FIXTURE_TEST_CASE( ResolveTest_TrailingTripleSlash, ResolveFixture ) FIXTURE_TEST_CASE( ResolveTest_ShortTrailingTripleSlash, ResolveFixture ) { -#ifdef WINDOWS +#ifdef WINDOWS REQUIRE_RESOLVE( "/a///", "/a/" ); // should not drop the '/' after the drive letter since it is significant #else - REQUIRE_RESOLVE( "/a///", "/a" ); -#endif + REQUIRE_RESOLVE( "/a///", "/a" ); +#endif } FIXTURE_TEST_CASE( ResolveTest_DotsAgogo, ResolveFixture ) @@ -141,23 +141,23 @@ FIXTURE_TEST_CASE( ResolveTest_DoubleDotsAgogo, ResolveFixture ) FIXTURE_TEST_CASE( ResolveTest_LeadingDoubleSlash, ResolveFixture ) { -#ifdef WINDOWS +#ifdef WINDOWS REQUIRE_RESOLVE( "//pqrst/pon1", "//pqrst/pon1" ); #else REQUIRE_RESOLVE( "//pqrst/pon1", "/pqrst/pon1" ); -#endif +#endif } FIXTURE_TEST_CASE( ResolveTest_LeadingTripleSlash, ResolveFixture ) { -#ifdef WINDOWS +#ifdef WINDOWS REQUIRE_RESOLVE( "///pqrst/pon1", "//pqrst/pon1" ); #else REQUIRE_RESOLVE( "///pqrst/pon1", "/pqrst/pon1" ); -#endif +#endif } -#ifndef WINDOWS +#ifndef WINDOWS FIXTURE_TEST_CASE( ResolveTest_Relative, ResolveFixture ) { REQUIRE_RC( KDirectoryResolvePath ( m_dir, false, m_resolved, sizeof m_resolved, "/" ) ); @@ -166,31 +166,7 @@ FIXTURE_TEST_CASE( ResolveTest_Relative, ResolveFixture ) #endif //////////////////////////////////////////// Main - -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -rc_t CC UsageSummary (const char * prog_name) +int main( int argc, char *argv [] ) { - return 0; -} - -rc_t CC Usage ( const Args * args) -{ - return 0; -} - -const char UsageDefaultName[] = "test-resolve"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc = ResolveSuite( argc, argv ); - return rc; -} - + return ResolveSuite( argc, argv ); } diff --git a/test/kfs/simple_q_test.cpp b/test/kfs/simple_q_test.cpp index 3fcbcf1dd..c18c8c334 100644 --- a/test/kfs/simple_q_test.cpp +++ b/test/kfs/simple_q_test.cpp @@ -33,6 +33,8 @@ #include +#include + #include #include #include @@ -54,7 +56,7 @@ class TOFixture { public: timeout_t to; - + TOFixture () { timeout_init ( timeout_milliseconds ); @@ -69,16 +71,16 @@ class TOFixture class SQFixture : public TOFixture { public: - KQueue * q; + KQueue * q; int values[ num_values ]; - + SQFixture () : TOFixture(), q( NULL ) { for ( int i = 0; i < num_values; ++i ) values[ i ] = i + 1; } - + ~SQFixture () {} - + rc_t push_some( KQueue * q, int count, timeout_t * tm ) { rc_t rc = 0; @@ -115,7 +117,7 @@ FIXTURE_TEST_CASE( SimpleQ_3, SQFixture ) REQUIRE_RC( KQueuePop ( q, ( void ** )&value, NULL ) ); REQUIRE_EQ( * value, values[ i ] ); } - + REQUIRE_RC( KQueueRelease ( q ) ); } @@ -131,7 +133,7 @@ FIXTURE_TEST_CASE( SimpleQ_4, SQFixture ) REQUIRE_RC( KQueuePop ( q, ( void ** )&value, &to ) ); REQUIRE_EQ( * value, values[ i ] ); } - + REQUIRE_RC( KQueueRelease ( q ) ); } @@ -143,7 +145,7 @@ FIXTURE_TEST_CASE( SimpleQ_5, SQFixture ) REQUIRE_RC_FAIL( KQueuePush ( q, &( values[ 0 ] ), &to ) ); REQUIRE_EQ( ( uint32_t )0, TimeoutRemaining ( &to ) ); - + REQUIRE_RC( KQueueRelease ( q ) ); } @@ -153,16 +155,16 @@ FIXTURE_TEST_CASE( SimpleQ_6, SQFixture ) REQUIRE_RC( KQueueMake ( &q, num_values ) ); REQUIRE_RC( push_some( q, num_values, &to ) ); - int * value; + int * value; for ( int i = 0; i < num_values; ++i ) { REQUIRE_RC( KQueuePop ( q, ( void ** )&value, &to ) ); REQUIRE_EQ( * value, values[ i ] ); } - + REQUIRE_RC_FAIL( KQueuePop ( q, ( void ** )&value, &to ) ); REQUIRE_EQ( ( uint32_t )0, TimeoutRemaining ( &to ) ); - + REQUIRE_RC( KQueueRelease ( q ) ); } @@ -170,7 +172,7 @@ class CONDFixture : public TOFixture { public: KCondition * cond; - + CONDFixture () : TOFixture(), cond( NULL ) { } @@ -192,52 +194,29 @@ static rc_t CC thread_func_2( const KThread *self, void *data ) FIXTURE_TEST_CASE( SimpleCOND_2, CONDFixture ) { REQUIRE_RC( KConditionMake ( &cond ) ); - + KLock * lock; REQUIRE_RC( KLockMake ( &lock ) ); - + KThread * t; REQUIRE_RC( KThreadMake ( &t, thread_func_2, cond ) ); KOutMsg( "COND2: Thread started\n" ); - REQUIRE_RC( KLockAcquire ( lock ) ); + REQUIRE_RC( KLockAcquire ( lock ) ); REQUIRE_RC( KConditionWait ( cond, lock ) ); - KOutMsg( "COND2: condition received\n" ); + KOutMsg( "COND2: condition received\n" ); REQUIRE_RC( KLockUnlock ( lock ) ); rc_t rc_thread; REQUIRE_RC( KThreadWait ( t, &rc_thread ) ); REQUIRE_RC( rc_thread ); REQUIRE_RC( KThreadRelease ( t ) ); - - REQUIRE_RC( KLockRelease ( lock ) ); + + REQUIRE_RC( KLockRelease ( lock ) ); REQUIRE_RC( KConditionRelease ( cond ) ); } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -rc_t CC UsageSummary ( const char * progname ) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "simple_q"; - #define OPTION_DUMMY "dummy" #define ALIAS_DUMMY "d" @@ -248,7 +227,7 @@ OptDef TestOptions[] = { OPTION_DUMMY, ALIAS_DUMMY, NULL, dummy_usage, 1, false, false } }; -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args * args; rc_t rc = ArgsMakeAndHandle( &args, argc, argv, @@ -259,5 +238,3 @@ rc_t CC KMain ( int argc, char *argv [] ) } return rc; } - -} diff --git a/test/kfs/test-gzip.cpp b/test/kfs/test-gzip.cpp old mode 100755 new mode 100644 index 2b3fbb8c5..4362e4845 --- a/test/kfs/test-gzip.cpp +++ b/test/kfs/test-gzip.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -271,8 +273,6 @@ FIXTURE_TEST_CASE(KGZipFile_Test, KGZipFileFixture) TestRead(); } -#include - static rc_t argsHandler(int argc, char * argv[]) { Args * args = NULL; rc_t rc = ArgsMakeAndHandle(&args, argc, argv, 0, NULL, 0); @@ -280,27 +280,7 @@ static rc_t argsHandler(int argc, char * argv[]) { return rc; } -#include -#include - -extern "C" -{ -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-gzip-file"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); @@ -308,8 +288,5 @@ rc_t CC KMain ( int argc, char *argv [] ) // (same as running the executable with "-l=message") //TestEnv::verbosity = LogLevel::e_message; - rc_t rc = KGZipFileTestSuite(argc, argv); - return rc; -} - + return KGZipFileTestSuite(argc, argv); } diff --git a/test/kfs/test-link.cpp b/test/kfs/test-link.cpp index 3414fc29e..193718a6f 100644 --- a/test/kfs/test-link.cpp +++ b/test/kfs/test-link.cpp @@ -135,9 +135,6 @@ FIXTURE_TEST_CASE(Test_Link, Fixture) { REQUIRE_RC(Fini()); } -extern "C" { - ver_t CC KAppVersion(void) { return 0; } - rc_t CC KMain(int argc, char *argv[]) { - return LinkSuite(argc, argv); - } +int main(int argc, char *argv[]) { + return LinkSuite(argc, argv); } diff --git a/test/kfs/test-read_observer-bz2.cpp b/test/kfs/test-read_observer-bz2.cpp new file mode 100644 index 000000000..76bcc95bc --- /dev/null +++ b/test/kfs/test-read_observer-bz2.cpp @@ -0,0 +1,334 @@ +/*============================================================================== +* +* PUBLIC DOMAIN NOTICE +* National Center for Biotechnology Information +* +* This software/database is a "United States Government Work" under the +* terms of the United States Copyright Act. It was written as part of +* the author's official duties as a United States Government employee and +* thus cannot be copyrighted. This software/database is freely available +* to the public for use. The National Library of Medicine and the U.S. +* Government have not placed any restriction on its use or reproduction. +* +* Although all reasonable efforts have been taken to ensure the accuracy +* and reliability of the software and data, the NLM and the U.S. +* Government do not and cannot warrant the performance or results that +* may be obtained by using this software or data. The NLM and the U.S. +* Government disclaim all warranties, express or implied, including +* warranties of performance, merchantability or fitness for any particular +* purpose. +* +* Please cite the author in any work or product based on this material. +* +* ============================================================================== +* Tests of KFileMD5ReadObserver for bz2 file +*/ + +#include "../vfs/observer-test.hpp" // ObserverTest + +#include /* KConfigDisableUserSettings */ + +TEST_SUITE(ReadObserverTestSuite) + +using std::string; + +//////////////////////////////////////////////////////////////////////////////// +// KFileReadAll + +TEST_CASE(ReadAllExactly) { + ObserverTest t(this, "ReadAllExactly"); + t.Start(true); + size_t num_read(0); + // request exactly all file; EOF cannot be detected by file size + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size, &num_read)); + REQUIRE(num_read == t.size); + if (t.sizeUnknown) { + // EOF was not detected by file size + REQUIRE_RC_FAIL( + KFileMD5ReadObserverGetDigest(t.md5, t.digest, &t.error)); + REQUIRE_EQ(string(t.error), string(ERR_HEAD "12887839.")); + FREE(t.error); + // detect EOF + REQUIRE_RC(KFileReadAll(t.file, t.size, t.buf, 1, &num_read)); + } + t.Finish("", true); +} + +TEST_CASE(ReadAllExactlyPlus1) { + ObserverTest t(this, "ReadAllExactlyPlus1"); + t.Start(); + size_t num_read(0); + // request all file + 1 byte + // will read one byte less than requested; + // EOF will be detected by last read that returns 0 bytes + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size + 1, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadAllSkip0) { + ObserverTest t(this, "ReadAllSkip0"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 1, t.buf, t.size, &num_read)); + // the first byte was not read + t.Finish(ERR_HEAD "0.", true); +} + +TEST_CASE(ReadAllSkip1) { + ObserverTest t(this, "ReadAllSkip1"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 1, &num_read)); +// REQUIRE_RC(KFileReadAll(t.file, 1, t.buf, 1, &num_read)); + REQUIRE_RC(KFileReadAll(t.file, 2, t.buf, t.size, &num_read)); + // the second byte was not read + t.Finish(ERR_HEAD "1."); +} + +TEST_CASE(ReadAllSkipLast) { + ObserverTest t(this, "ReadAllSkipLast"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size - 1, &num_read)); +// REQUIRE_RC(KFileReadAll(t.file, t.size - 1, t.buf, 2, &num_read)); + // the last byte was not read + t.Finish(ERR_HEAD "12887838."); +} + +// bzip KFile does not allow re-reading the part that was previously read +TEST_CASE(ReadAllTwice) { + ObserverTest t(this, "ReadAllTwice"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 1234567, &num_read)); + // this call will request the part that was already completely read + REQUIRE_RC_FAIL(KFileReadAll(t.file, 1, t.buf, 123456, &num_read)); + t.Finish(ERR_HEAD "1234567.", true); +} + +// bzip KFile does not allow re-reading the part that was previously read +TEST_CASE(ReadAllTwicePartially) { + ObserverTest t(this, "ReadAllTwicePartially"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 2000000, &num_read)); + // this call will request the part that was already read and new data + REQUIRE_RC_FAIL(KFileReadAll(t.file, 1000000, t.buf, t.size, &num_read)); + t.Finish(ERR_HEAD "2000000."); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileRead + +TEST_CASE(Read) { + ObserverTest t(this, "Read"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 2, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadSkip0) { + ObserverTest t(this, "ReadSkip0"); + t.Start(); + size_t num_read(0); + uint64_t pos(1); + for (pos = 1; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 2, &num_read)); + t.Finish(ERR_HEAD "0."); +} + +TEST_CASE(ReadSkip1) { + ObserverTest t(this, "ReadSkip1"); + t.Start(); + size_t num_read(0); + uint64_t pos(0); + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1, &num_read)); + pos += num_read; +// REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1, &num_read)); + for (++pos; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 3, &num_read)); + t.Finish(ERR_HEAD "1."); +} + +// bzip KFile does not allow re-reading the part that was previously read +TEST_CASE(ReadTwice) { + ObserverTest t(this, "ReadTwice"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0 ; num_read > 0 && pos < 1234567; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + for (size_t n = 0; n > 0; ) + { REQUIRE_RC_FAIL(KFileRead(t.file, 1, t.buf, 10000, &n)); break; } + for ( ; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + t.Finish(); +} + +// bzip KFile does not allow re-reading the part that was previously read +TEST_CASE(ReadTwicePartially) { + ObserverTest t(this, "ReadTwicePartially"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 2000000; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + for (pos = 1000000; num_read > 0; pos += num_read) + REQUIRE_RC_FAIL(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + t.Finish(ERR_HEAD "2000000.", true); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedRead is not supported for bzip KFile + +TEST_CASE(TimedRead) { + ObserverTest t(this, "TimedRead"); + t.Start(true); + size_t num_read(1); + REQUIRE_RC_FAIL(KFileTimedRead(t.file, 0, t.buf, 99, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0.", true); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedReadAll is not supported for bzip KFile + +TEST_CASE(TimedReadAllExactly) { + ObserverTest t(this, "TimedReadAllExactly"); + t.Start(); + size_t num_read(0); + REQUIRE_RC_FAIL(KFileTimedReadAll(t.file, 0, t.buf, 999, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0."); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileReadExactly + +TEST_CASE(ReadExactly) { + ObserverTest t(this, "ReadExactly"); + t.Start(); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, t.size)); + // EOF was not detected by file size + REQUIRE_RC_FAIL(KFileMD5ReadObserverGetDigest(t.md5, t.digest, &t.error)); + REQUIRE_EQ(string(t.error), string(ERR_HEAD "12887839.")); + FREE(t.error); + size_t num_read(0); + REQUIRE_RC(KFileRead(t.file, t.size, t.buf, 1, &num_read)); + t.Finish("", true); +} + +#if 0 +TEST_CASE(ReadExactlySkip0) { + ObserverTest t(this, "ReadExactlySkip0"); + t.Start(true); + //REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1)); + REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, t.size - 1)); + t.Finish(ERR_HEAD "0."); +} + +TEST_CASE(ReadExactlySkip1) { + ObserverTest t(this, "ReadExactlySkip1"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1)); + //REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, 1)); + REQUIRE_RC(KFileReadExactly(t.file, 2, t.buf, t.size - 2)); + t.Finish(ERR_HEAD "1."); +} + +TEST_CASE(ReadExactlySkipLast) { + ObserverTest t(this, "ReadExactlySkipLast"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, t.size - 1)); + //REQUIRE_RC(KFileReadExactly(t.file, t.size - 1, t.buf, 1)); + t.Finish(ERR_HEAD "12887838."); +} + +TEST_CASE(ReadExactlyTwice) { + ObserverTest t(this, "ReadExactlyTwice"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1234567)); + REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, 123456)); + REQUIRE_RC(KFileReadExactly(t.file, 1234567, t.buf, t.size - 1234567)); + t.Finish(); +} + +TEST_CASE(ReadExactlyTwicePartially) { + ObserverTest t(this, "ReadExactlyTwicePartially"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 2000000)); + REQUIRE_RC(KFileReadExactly(t.file, 1000000, t.buf, t.size - 1000000)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedReadExactly + +TEST_CASE(TimedReadExactly) { + ObserverTest t(this, "TimedReadExactly"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, t.size, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadExactlySkip0) { + ObserverTest t(this, "TimedReadExactlySkip0"); + t.Start(true); + //REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, t.size - 1, &t.tm)); + t.Finish(ERR_HEAD "0."); +} + +TEST_CASE(TimedReadExactlySkip1) { + ObserverTest t(this, "ReadExactlySkip1"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1, &t.tm)); + //REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, 1, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 2, t.buf, t.size - 2, &t.tm)); + t.Finish(ERR_HEAD "1."); +} + +TEST_CASE(TimedReadExactlySkipLast) { + ObserverTest t(this, "TimedReadExactlySkipLast"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, t.size - 1, &t.tm)); + //REQUIRE_RC(KFileTimedReadExactly(t.file, t.size - 1, t.buf, 1, &t.tm)); + t.Finish(ERR_HEAD "12887838."); +} + +TEST_CASE(TimedReadExactlyTwice) { + ObserverTest t(this, "TimedReadExactlyTwice"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1234567, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, 123456, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1234567, + t.buf, t.size - 1234567, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadExactlyTwicePartially) { + ObserverTest t(this, "TimedReadExactlyTwicePartially"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 2000000, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 999, t.buf, t.size - 999, &t.tm)); + t.Finish(); +} +#endif + +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); + + rc_t rc(ObserverTest::Begin(eBz2)); + + if (rc == 0) + rc = ReadObserverTestSuite(argc, argv); + + rc_t r2(ObserverTest::End()); + if (rc == 0 && r2 != 0) + rc = r2; + + return (rc == 0) ? 0 : IF_EXITCODE(rc, 3); +} + +/******************************************************************************/ diff --git a/test/kfs/test-read_observer-gz.cpp b/test/kfs/test-read_observer-gz.cpp new file mode 100644 index 000000000..bfb5ff282 --- /dev/null +++ b/test/kfs/test-read_observer-gz.cpp @@ -0,0 +1,434 @@ +/*============================================================================== +* +* PUBLIC DOMAIN NOTICE +* National Center for Biotechnology Information +* +* This software/database is a "United States Government Work" under the +* terms of the United States Copyright Act. It was written as part of +* the author's official duties as a United States Government employee and +* thus cannot be copyrighted. This software/database is freely available +* to the public for use. The National Library of Medicine and the U.S. +* Government have not placed any restriction on its use or reproduction. +* +* Although all reasonable efforts have been taken to ensure the accuracy +* and reliability of the software and data, the NLM and the U.S. +* Government do not and cannot warrant the performance or results that +* may be obtained by using this software or data. The NLM and the U.S. +* Government disclaim all warranties, express or implied, including +* warranties of performance, merchantability or fitness for any particular +* purpose. +* +* Please cite the author in any work or product based on this material. +* +* ============================================================================== +* Tests of KFileMD5ReadObserver for gz file +*/ + +#include "../vfs/observer-test.hpp" // ObserverTest + +#include /* KConfigDisableUserSettings */ + +TEST_SUITE(ReadObserverTestSuite) + +using std::string; + +//////////////////////////////////////////////////////////////////////////////// +// KFileReadAll + +TEST_CASE(ReadAllExactly) { + ObserverTest t(this, "ReadAllExactly"); + t.Start(true); + size_t num_read(0); + // request exactly all file; EOF cannot be detected by file size + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size, &num_read)); + REQUIRE(num_read == t.size); + if (t.sizeUnknown) { + // EOF was not detected by file size + REQUIRE_RC_FAIL( + KFileMD5ReadObserverGetDigest(t.md5, t.digest, &t.error)); + REQUIRE_EQ(string(t.error), string(ERR_HEAD "12887839.")); + FREE(t.error); + // detect EOF + REQUIRE_RC(KFileReadAll(t.file, t.size, t.buf, 1, &num_read)); + } + t.Finish("", true); +} + +TEST_CASE(ReadAllExactlyPlus1) { + ObserverTest t(this, "ReadAllExactlyPlus1"); + t.Start(); + size_t num_read(0); + // request all file + 1 byte + // will read one byte less than requested; + // EOF will be detected by last read that returns 0 bytes + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size + 1, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadAllSkip0) { + ObserverTest t(this, "ReadAllSkip0"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 1, t.buf, t.size, &num_read)); + // the first byte was not read + t.Finish(ERR_HEAD "0.", true); +} + +TEST_CASE(ReadAllSkip1) { + ObserverTest t(this, "ReadAllSkip1"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 1, &num_read)); +// REQUIRE_RC(KFileReadAll(t.file, 1, t.buf, 1, &num_read)); + REQUIRE_RC(KFileReadAll(t.file, 2, t.buf, t.size, &num_read)); + // the second byte was not read + t.Finish(ERR_HEAD "1."); +} + +TEST_CASE(ReadAllSkipLast) { + ObserverTest t(this, "ReadAllSkipLast"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size - 1, &num_read)); +// REQUIRE_RC(KFileReadAll(t.file, t.size - 1, t.buf, 2, &num_read)); + // the last byte was not read + t.Finish(ERR_HEAD "12887838."); +} + +// gzip KFile does not allow re-reading the part that was previously read +TEST_CASE(ReadAllTwice) { + ObserverTest t(this, "ReadAllTwice"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 1234567, &num_read)); + // this call will request the part that was already completely read + REQUIRE_RC_FAIL(KFileReadAll(t.file, 1, t.buf, 123456, &num_read)); + t.Finish(ERR_HEAD "1234567.", true); +} + +// gzip KFile does not allow re-reading the part that was previously read +TEST_CASE(ReadAllTwicePartially) { + ObserverTest t(this, "ReadAllTwicePartially"); + t.Start(); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 2000000, &num_read)); + // this call will request the part that was already read and new data + REQUIRE_RC_FAIL(KFileReadAll(t.file, 1000000, t.buf, t.size, &num_read)); + t.Finish(ERR_HEAD "2000000."); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileRead + +TEST_CASE(Read) { + ObserverTest t(this, "Read"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 2, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadSkip0) { + ObserverTest t(this, "ReadSkip0"); + t.Start(); + size_t num_read(0); + uint64_t pos(1); + for (pos = 1; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 2, &num_read)); + t.Finish(ERR_HEAD "0."); +} + +TEST_CASE(ReadSkip1) { + ObserverTest t(this, "ReadSkip1"); + t.Start(); + size_t num_read(0); + uint64_t pos(0); + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1, &num_read)); + pos += num_read; +// REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1, &num_read)); + for (++pos; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 3, &num_read)); + t.Finish(ERR_HEAD "1."); +} + +// gzip KFile does not allow re-reading the part that was previously read +TEST_CASE(ReadTwice) { + ObserverTest t(this, "ReadTwice"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 1234567; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + for (size_t n = 0; n > 0; ) + { REQUIRE_RC_FAIL(KFileRead(t.file, 1, t.buf, 10000, &n)); break; } + for ( ; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + t.Finish(); +} + +// gzip KFile does not allow re-reading the part that was previously read +TEST_CASE(ReadTwicePartially) { + ObserverTest t(this, "ReadTwicePartially"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 2000000; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + for (pos = 1000000; num_read > 0; pos += num_read) + REQUIRE_RC_FAIL(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + t.Finish(ERR_HEAD "2000000.", true); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedRead + +TEST_CASE(TimedRead) { + ObserverTest t(this, "TimedRead"); + t.Start(true); + size_t num_read(1); + // KFileTimedRead is not supported for bzip KFile + REQUIRE_RC_FAIL(KFileTimedRead(t.file, 0, t.buf, 99, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0.", true); +} + +#if 0 +TEST_CASE(TimedReadSkip0) { + ObserverTest t(this, "TimedReadSkip0"); + t.Start(true); + size_t num_read(0); + uint64_t pos(1); + for (pos = 1; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0."); +} + +TEST_CASE(TimedReadSkip1) { + ObserverTest t(this, "TimedReadSkip1"); + t.Start(true); + size_t num_read(0); + uint64_t pos(0); + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 1, &num_read, &t.tm)); + pos += num_read; +//REQUIRE_RC(KFileTimedRead(t.file, pos,t.buf,1,&num_read,&t.tm));pos+=num_read; + for (++pos; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(ERR_HEAD "1."); +} + +TEST_CASE(TimedReadTwice) { + ObserverTest t(this, "TimedReadTwice"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 1234567; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + for (pos = 1; num_read > 0 && pos < 123456; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + for (pos = 1234567; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadTwicePartially) { + ObserverTest t(this, "TimedReadTwicePartially"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 2000000; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + for (pos = 1000000; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedReadAll + +TEST_CASE(TimedReadAllExactly) { + ObserverTest t(this, "TimedReadAllExactly"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, t.size, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadAllExactlyPlus1) { + ObserverTest t(this, "TimedReadAllExactlyPlus1"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, t.size + 1, &num_read, + &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadAllSkip0) { + ObserverTest t(this, "TimedReadAllSkip0"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 1, t.buf, t.size, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0."); +} + +TEST_CASE(TimedReadAllSkip1) { + ObserverTest t(this, "TimedReadAllSkip1"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, 1, &num_read, &t.tm)); + //REQUIRE_RC(KFileTimedReadAll(t.file, 1, t.buf, 1, &num_read, &t.tm)); + REQUIRE_RC(KFileTimedReadAll(t.file, 2, t.buf, t.size, &num_read, &t.tm)); + t.Finish(ERR_HEAD "1."); +} + +TEST_CASE(TimedReadAllSkipLast) { + ObserverTest t(this, "TimedReadAllSkipLast"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, t.size - 1, &num_read, + &t.tm)); +//REQUIRE_RC(KFileTimedReadAll(t.file, t.size - 1, t.buf, 1, &num_read, &t.tm)); + t.Finish(ERR_HEAD "12887838."); +} + +TEST_CASE(TimedReadAllTwice) { + ObserverTest t(this, "TimedReadAllTwice"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, 123, &num_read, &t.tm)); + REQUIRE_RC(KFileTimedReadAll(t.file, 1, t.buf, 12, &num_read, &t.tm)); + REQUIRE_RC(KFileTimedReadAll(t.file, 123, t.buf, t.size, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadAllTwicePartially) { + ObserverTest t(this, "TimedReadAllTwicePartially"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, 2000000, &num_read, &t.tm)); + REQUIRE_RC(KFileTimedReadAll(t.file, 999, t.buf, t.size, &num_read, &t.tm)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileReadExactly + +TEST_CASE(ReadExactly) { + ObserverTest t(this, "ReadExactly"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, t.size)); + t.Finish("", true); +} + +TEST_CASE(ReadExactlySkip0) { + ObserverTest t(this, "ReadExactlySkip0"); + t.Start(true); + //REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1)); + REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, t.size - 1)); + t.Finish(ERR_HEAD "0."); +} + +TEST_CASE(ReadExactlySkip1) { + ObserverTest t(this, "ReadExactlySkip1"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1)); + //REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, 1)); + REQUIRE_RC(KFileReadExactly(t.file, 2, t.buf, t.size - 2)); + t.Finish(ERR_HEAD "1."); +} + +TEST_CASE(ReadExactlySkipLast) { + ObserverTest t(this, "ReadExactlySkipLast"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, t.size - 1)); + //REQUIRE_RC(KFileReadExactly(t.file, t.size - 1, t.buf, 1)); + t.Finish(ERR_HEAD "12887838."); +} + +TEST_CASE(ReadExactlyTwice) { + ObserverTest t(this, "ReadExactlyTwice"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1234567)); + REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, 123456)); + REQUIRE_RC(KFileReadExactly(t.file, 1234567, t.buf, t.size - 1234567)); + t.Finish(); +} + +TEST_CASE(ReadExactlyTwicePartially) { + ObserverTest t(this, "ReadExactlyTwicePartially"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 2000000)); + REQUIRE_RC(KFileReadExactly(t.file, 1000000, t.buf, t.size - 1000000)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedReadExactly + +TEST_CASE(TimedReadExactly) { + ObserverTest t(this, "TimedReadExactly"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, t.size, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadExactlySkip0) { + ObserverTest t(this, "TimedReadExactlySkip0"); + t.Start(true); + //REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, t.size - 1, &t.tm)); + t.Finish(ERR_HEAD "0."); +} + +TEST_CASE(TimedReadExactlySkip1) { + ObserverTest t(this, "ReadExactlySkip1"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1, &t.tm)); + //REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, 1, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 2, t.buf, t.size - 2, &t.tm)); + t.Finish(ERR_HEAD "1."); +} + +TEST_CASE(TimedReadExactlySkipLast) { + ObserverTest t(this, "TimedReadExactlySkipLast"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, t.size - 1, &t.tm)); + //REQUIRE_RC(KFileTimedReadExactly(t.file, t.size - 1, t.buf, 1, &t.tm)); + t.Finish(ERR_HEAD "12887838."); +} + +TEST_CASE(TimedReadExactlyTwice) { + ObserverTest t(this, "TimedReadExactlyTwice"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1234567, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, 123456, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1234567, + t.buf, t.size - 1234567, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadExactlyTwicePartially) { + ObserverTest t(this, "TimedReadExactlyTwicePartially"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 2000000, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 999, t.buf, t.size - 999, &t.tm)); + t.Finish(); +} +#endif + +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); + + rc_t rc(ObserverTest::Begin(eGzip)); + + if (rc == 0) + rc = ReadObserverTestSuite(argc, argv); + + rc_t r2(ObserverTest::End()); + if (rc == 0 && r2 != 0) + rc = r2; + + return (rc == 0) ? 0 : IF_EXITCODE(rc, 3); +} + +/******************************************************************************/ diff --git a/test/kfs/test-read_observer.cpp b/test/kfs/test-read_observer.cpp new file mode 100644 index 000000000..8fb6f5f65 --- /dev/null +++ b/test/kfs/test-read_observer.cpp @@ -0,0 +1,424 @@ +/*============================================================================== +* +* PUBLIC DOMAIN NOTICE +* National Center for Biotechnology Information +* +* This software/database is a "United States Government Work" under the +* terms of the United States Copyright Act. It was written as part of +* the author's official duties as a United States Government employee and +* thus cannot be copyrighted. This software/database is freely available +* to the public for use. The National Library of Medicine and the U.S. +* Government have not placed any restriction on its use or reproduction. +* +* Although all reasonable efforts have been taken to ensure the accuracy +* and reliability of the software and data, the NLM and the U.S. +* Government do not and cannot warrant the performance or results that +* may be obtained by using this software or data. The NLM and the U.S. +* Government disclaim all warranties, express or implied, including +* warranties of performance, merchantability or fitness for any particular +* purpose. +* +* Please cite the author in any work or product based on this material. +* +* ============================================================================== +* Tests of KFileMD5ReadObserver for file from filesystem +*/ + +#include "../vfs/observer-test.hpp" // ObserverTest + +#include /* KConfigDisableUserSettings */ + +TEST_SUITE(ReadObserverTestSuite) + +using std::string; + +//////////////////////////////////////////////////////////////////////////////// +// KFileReadAll + +TEST_CASE(ReadAllExactly) { + ObserverTest t(this, "ReadAllExactly"); + t.Start(true); + size_t num_read(0); + // request exactly all file; EOF is detected by file size + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size, &num_read)); + t.Finish("", true); +} + +TEST_CASE(ReadAllExactlyPlus1) { + ObserverTest t(this, "ReadAllExactlyPlus1"); + t.Start(true); + size_t num_read(0); + // request all file + 1 byte + // will read one byte less than requested; + // EOF can be detected by last read that returns 0 bytes + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size + 1, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadAllSkip0) { + ObserverTest t(this, "ReadAllSkip0"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 1, t.buf, t.size, &num_read)); + // the first byte was not read + t.Finish(ERR_HEAD "0 of 12887839."); +} + +TEST_CASE(ReadAllSkip1) { + ObserverTest t(this, "ReadAllSkip1"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 1, &num_read)); +// REQUIRE_RC(KFileReadAll(t.file, 1, t.buf, 1, &num_read)); + REQUIRE_RC(KFileReadAll(t.file, 2, t.buf, t.size, &num_read)); + // the second byte was not read + t.Finish(ERR_HEAD "1 of 12887839."); +} + +TEST_CASE(ReadAllSkipLast) { + ObserverTest t(this, "ReadAllSkipLast"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, t.size - 1, &num_read)); +// REQUIRE_RC(KFileReadAll(t.file, t.size - 1, t.buf, 1, &num_read)); + // the last byte was not read + t.Finish(ERR_HEAD "12887838 " + "of 12887839.", true); +} + +TEST_CASE(ReadAllTwice) { + ObserverTest t(this, "ReadAllTwice"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 1234567, &num_read)); + // this call will request the part that was already completely read + REQUIRE_RC(KFileReadAll(t.file, 1, t.buf, 123456, &num_read)); + REQUIRE_RC(KFileReadAll(t.file, 1234567, t.buf, t.size, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadAllTwicePartially) { + ObserverTest t(this, "ReadAllTwicePartially"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 2000000, &num_read)); + // this call will request the part that was already read and new data + REQUIRE_RC(KFileReadAll(t.file, 1000000, t.buf, t.size, &num_read)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileRead + +TEST_CASE(Read) { + ObserverTest t(this, "Read"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 2, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadSkip0) { + ObserverTest t(this, "ReadSkip0"); + t.Start(true); + size_t num_read(0); + uint64_t pos(1); + for (pos = 1; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 2, &num_read)); + t.Finish(ERR_HEAD "0 of 12887839."); +} + +TEST_CASE(ReadSkip1) { + ObserverTest t(this, "ReadSkip1"); + t.Start(true); + size_t num_read(0); + uint64_t pos(0); + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1, &num_read)); + pos += num_read; +// REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1, &num_read)); pos += num_read; + for (++pos; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 3, &num_read)); + t.Finish(ERR_HEAD "1 of 12887839."); +} + +TEST_CASE(ReadTwice) { + ObserverTest t(this, "ReadTwice"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 1234567; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + for (pos = 1; num_read > 0 && pos < 123456; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 10000, &num_read)); + for (pos = 1234567; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadTwicePartially) { + ObserverTest t(this, "ReadTwicePartially"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 2000000; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + for (pos = 1000000; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 100000, &num_read)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedRead + +TEST_CASE(TimedRead) { + ObserverTest t(this, "TimedRead"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadSkip0) { + ObserverTest t(this, "TimedReadSkip0"); + t.Start(true); + size_t num_read(0); + uint64_t pos(1); + for (pos = 1; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0 of 12887839."); +} + +TEST_CASE(TimedReadSkip1) { + ObserverTest t(this, "TimedReadSkip1"); + t.Start(true); + size_t num_read(0); + uint64_t pos(0); + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 1, &num_read, &t.tm)); + pos += num_read; +//REQUIRE_RC(KFileTimedRead(t.file, pos,t.buf,1,&num_read,&t.tm));pos+=num_read; + for (++pos; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(ERR_HEAD "1 of 12887839."); +} + +TEST_CASE(TimedReadTwice) { + ObserverTest t(this, "TimedReadTwice"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 1234567; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + for (pos = 1; num_read > 0 && pos < 123456; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + for (pos = 1234567; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadTwicePartially) { + ObserverTest t(this, "TimedReadTwicePartially"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 2000000; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + for (pos = 1000000; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 90000, &num_read, &t.tm)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedReadAll + +TEST_CASE(TimedReadAllExactly) { + ObserverTest t(this, "TimedReadAllExactly"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, t.size, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadAllExactlyPlus1) { + ObserverTest t(this, "TimedReadAllExactlyPlus1"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, t.size + 1, &num_read, + &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadAllSkip0) { + ObserverTest t(this, "TimedReadAllSkip0"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 1, t.buf, t.size, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0 of 12887839."); +} + +TEST_CASE(TimedReadAllSkip1) { + ObserverTest t(this, "TimedReadAllSkip1"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, 1, &num_read, &t.tm)); + //REQUIRE_RC(KFileTimedReadAll(t.file, 1, t.buf, 1, &num_read, &t.tm)); + REQUIRE_RC(KFileTimedReadAll(t.file, 2, t.buf, t.size, &num_read, &t.tm)); + t.Finish(ERR_HEAD "1 of 12887839."); +} + +TEST_CASE(TimedReadAllSkipLast) { + ObserverTest t(this, "TimedReadAllSkipLast"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, t.size - 1, &num_read, + &t.tm)); +//REQUIRE_RC(KFileTimedReadAll(t.file, t.size - 1, t.buf, 1, &num_read, &t.tm)); + t.Finish(ERR_HEAD "12887838 of " + "12887839.", true); +} + +TEST_CASE(TimedReadAllTwice) { + ObserverTest t(this, "TimedReadAllTwice"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, 123, &num_read, &t.tm)); + REQUIRE_RC(KFileTimedReadAll(t.file, 1, t.buf, 12, &num_read, &t.tm)); + REQUIRE_RC(KFileTimedReadAll(t.file, 123, t.buf, t.size, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadAllTwicePartially) { + ObserverTest t(this, "TimedReadAllTwicePartially"); + t.Start(true); + size_t num_read(0); + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, 2000000, &num_read, &t.tm)); + REQUIRE_RC(KFileTimedReadAll(t.file, 999, t.buf, t.size, &num_read, &t.tm)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileReadExactly + +TEST_CASE(ReadExactly) { + ObserverTest t(this, "ReadExactly"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, t.size)); + t.Finish("", true); +} + +TEST_CASE(ReadExactlySkip0) { + ObserverTest t(this, "ReadExactlySkip0"); + t.Start(true); + //REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1)); + REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, t.size - 1)); + t.Finish(ERR_HEAD "0 of 12887839."); +} + +TEST_CASE(ReadExactlySkip1) { + ObserverTest t(this, "ReadExactlySkip1"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1)); + //REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, 1)); + REQUIRE_RC(KFileReadExactly(t.file, 2, t.buf, t.size - 2)); + t.Finish(ERR_HEAD "1 of 12887839."); +} + +TEST_CASE(ReadExactlySkipLast) { + ObserverTest t(this, "ReadExactlySkipLast"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, t.size - 1)); + //REQUIRE_RC(KFileReadExactly(t.file, t.size - 1, t.buf, 1)); + t.Finish(ERR_HEAD "12887838 " + "of 12887839.", true); +} + +TEST_CASE(ReadExactlyTwice) { + ObserverTest t(this, "ReadExactlyTwice"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1234567)); + REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, 123456)); + REQUIRE_RC(KFileReadExactly(t.file, 1234567, t.buf, t.size - 1234567)); + t.Finish(); +} + +TEST_CASE(ReadExactlyTwicePartially) { + ObserverTest t(this, "ReadExactlyTwicePartially"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 2000000)); + REQUIRE_RC(KFileReadExactly(t.file, 1000000, t.buf, t.size - 1000000)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedReadExactly + +TEST_CASE(TimedReadExactly) { + ObserverTest t(this, "TimedReadExactly"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, t.size, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadExactlySkip0) { + ObserverTest t(this, "TimedReadExactlySkip0"); + t.Start(true); + //REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, t.size - 1, &t.tm)); + t.Finish(ERR_HEAD "0 of 12887839."); +} + +TEST_CASE(TimedReadExactlySkip1) { + ObserverTest t(this, "ReadExactlySkip1"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1, &t.tm)); + //REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, 1, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 2, t.buf, t.size - 2, &t.tm)); + t.Finish(ERR_HEAD "1 of 12887839."); +} + +TEST_CASE(TimedReadExactlySkipLast) { + ObserverTest t(this, "TimedReadExactlySkipLast"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, t.size - 1, &t.tm)); + //REQUIRE_RC(KFileTimedReadExactly(t.file, t.size - 1, t.buf, 1, &t.tm)); + t.Finish(ERR_HEAD "12887838 " + "of 12887839."); +} + +TEST_CASE(TimedReadExactlyTwice) { + ObserverTest t(this, "TimedReadExactlyTwice"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1234567, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, 123456, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1234567, + t.buf, t.size - 1234567, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadExactlyTwicePartially) { + ObserverTest t(this, "TimedReadExactlyTwicePartially"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 2000000, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 999, t.buf, t.size - 999, &t.tm)); + t.Finish(); +} + +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); + + rc_t rc(ObserverTest::Begin()); + + if (rc == 0) + rc = ReadObserverTestSuite(argc, argv); + + rc_t r2(ObserverTest::End()); + if (rc == 0 && r2 != 0) + rc = r2; + + return (rc == 0) ? 0 : IF_EXITCODE(rc, 3); +} + +/******************************************************************************/ diff --git a/test/klib/CMakeLists.txt b/test/klib/CMakeLists.txt index 8c139a47e..bc8eeb98d 100644 --- a/test/klib/CMakeLists.txt +++ b/test/klib/CMakeLists.txt @@ -24,25 +24,27 @@ add_compile_definitions( __mod__="test/klib" ) -AddExecutableTest( Test_KLIB_asm "asm-test" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_printf "printf-test" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_data_buffer_print "test-data-buffer-print" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_log "test-log" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_out "test-out" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_SraReleaseVersion "test-SraReleaseVersion" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_time "test-time" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_rcenum "test-rcenum" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_myKLIB "test-klib" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_KOutMsgOverflow "test-KOutMsgOverflow" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_vnamelist "test-vnamelist" "${COMMON_LIBS_READ}" ) -AddExecutableTest( SlowTest_KLIB_progressbar "test-progress" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_symtab "test-symtab" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_json "test-json" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_base64 "test-base64" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_guid "test-guid" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_report "test-report" "${COMMON_LIBS_READ}" ) -AddExecutableTest( SlowTest_KLIB_hashfile "test-hashfile" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_hashtable "test-hashtable" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_pack "test-pack" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_btree "test-btree" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KLIB_sha-32bit "test-sha-32bit" "${COMMON_LIBS_READ}" ) +set( LIBS "${COMMON_LIBS_READ}") + +AddExecutableTest( Test_KLIB_asm "asm-test" "${LIBS}" ) +AddExecutableTest( Test_KLIB_printf "printf-test" "${LIBS}" ) +AddExecutableTest( Test_KLIB_data_buffer_print "test-data-buffer-print" "${LIBS}" ) +AddExecutableTest( Test_KLIB_log "test-log" "${LIBS}" ) +AddExecutableTest( Test_KLIB_out "test-out" "${LIBS}" ) +AddExecutableTest( Test_KLIB_SraReleaseVersion "test-SraReleaseVersion" "${LIBS}" ) +AddExecutableTest( Test_KLIB_time "test-time" "${LIBS}" ) +AddExecutableTest( Test_KLIB_rcenum "test-rcenum" "${LIBS}" ) +AddExecutableTest( Test_myKLIB "test-klib" "${LIBS}" ) +AddExecutableTest( Test_KLIB_KOutMsgOverflow "test-KOutMsgOverflow" "${LIBS}" ) +AddExecutableTest( Test_KLIB_vnamelist "test-vnamelist" "${LIBS}" ) +AddExecutableTest( SlowTest_KLIB_progressbar "test-progress" "${LIBS}" ) +AddExecutableTest( Test_KLIB_symtab "test-symtab" "${LIBS}" ) +AddExecutableTest( Test_KLIB_json "test-json" "${LIBS}" ) +AddExecutableTest( Test_KLIB_base64 "test-base64" "${LIBS}" ) +AddExecutableTest( Test_KLIB_guid "test-guid" "${LIBS}" ) +AddExecutableTest( Test_KLIB_report "test-report" "${LIBS}" ) +AddExecutableTest( SlowTest_KLIB_hashfile "test-hashfile" "${LIBS}" ) +AddExecutableTest( Test_KLIB_hashtable "test-hashtable" "${LIBS}" ) +AddExecutableTest( Test_KLIB_pack "test-pack" "${LIBS}" ) +AddExecutableTest( Test_KLIB_btree "test-btree" "${LIBS}" ) +AddExecutableTest( Test_KLIB_sha-32bit "test-sha-32bit" "${LIBS}" ) diff --git a/test/klib/asm-test.c b/test/klib/asm-test.c index 7d47b980d..59c046504 100644 --- a/test/klib/asm-test.c +++ b/test/klib/asm-test.c @@ -24,7 +24,6 @@ * */ -#include #include #include #include @@ -33,10 +32,10 @@ #include static -rc_t run ( uint32_t x, uint32_t expected_result ) +int run ( uint32_t x, uint32_t expected_result ) { int32_t lsb = uint32_lsbit(x); - if (lsb != expected_result) + if (lsb != (int32_t)expected_result) { KOutMsg ( "uint32_lsbit(%u) failed, expected %u, actual %u\n", x, expected_result, lsb ); return -1; @@ -44,71 +43,7 @@ rc_t run ( uint32_t x, uint32_t expected_result ) return 0; } - -/* Version EXTERN - * return 4-part version code: 0xMMmmrrrr, where - * MM = major release - * mm = minor release - * rrrr = bug-fix release - */ -ver_t CC KAppVersion ( void ) -{ - return 0; -} - - -/* Usage - * This function is called when the command line argument - * handling sees -? -h or --help - */ -rc_t CC UsageSummary ( const char *progname ) -{ - return KOutMsg ( - "\n" - "Usage:\n" - " %s [Options]\n" - "\n" - "Summary:\n" - " Simple test of functions potentially impemented using asm.\n" - , progname ); -} - -const char UsageDefaultName[] = "asm-test"; - -rc_t CC Usage ( const Args *args ) -{ - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionsStandard(); - - HelpVersion (fullpath, KAppVersion()); - - return rc; -} - - -/* KMain - */ -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { - Args *args; - rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0 ); - if ( rc == 0 ) - { - rc = run (8, 3); - ArgsWhack ( args ); - } - - return rc; + return run (8, 3); } diff --git a/test/klib/md5appendtest.c b/test/klib/md5appendtest.c index 68102fe7b..d42a40624 100644 --- a/test/klib/md5appendtest.c +++ b/test/klib/md5appendtest.c @@ -114,7 +114,7 @@ rc_t runtest (KDirectory * kdir,const char * filename) return rc; } file = KMD5FileToKFile ( md5file ); - + c = ' '; memset (buff, c, sizeof (buff)); OUTMSG (("write to file %lu\n", iteration)); @@ -140,7 +140,7 @@ rc_t runtest (KDirectory * kdir,const char * filename) OUTMSG (("unable to close md5 formatter: %d\n", rc)); return rc; } - + #if 1 for (iteration = 1; iteration < 1024; ++iteration) { @@ -190,45 +190,7 @@ rc_t runtest (KDirectory * kdir,const char * filename) return rc; } -uint32_t CC KAppVersion ( void ) -{ - return 0; -} - -const char UsageDefaultName[] = "md5appendtest"; - -rc_t CC UsageSummary (const char * name) -{ - return KOutMsg ( - "Usage:\n" - " %s \n" - "\n" - " run a test of the KMD5File in append mode\n" - "\n", name); -} - - -rc_t CC Usage ( const Args * args ) -{ - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionsStandard(); - - return rc; -} - - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args * args; rc_t rc; diff --git a/test/klib/printf-test.c b/test/klib/printf-test.c index 9ee624d6d..9bb2e8628 100644 --- a/test/klib/printf-test.c +++ b/test/klib/printf-test.c @@ -24,7 +24,6 @@ * */ -#include #include #include #include @@ -136,7 +135,7 @@ rc_t final ( const char *flags, int32_t *field_width, int32_t *precision, rc_t rc; uint32_t i, j; va_list arg_copy; - char stdcfmt [ 32 ], fmt [ 32 ], expected [ 4096 ]; + char stdcfmt [ 256 ], fmt [ 256 ], expected [ 4096 ]; /* initialize counters */ i = 0; @@ -145,13 +144,13 @@ rc_t final ( const char *flags, int32_t *field_width, int32_t *precision, fmt [ i ++ ] = '%'; if ( flags != NULL ) - i += sprintf ( & fmt [ i ], "%s", flags ); + i += snprintf ( & fmt [ i ], sizeof(fmt) - i, "%s", flags ); if ( field_width != NULL ) { if ( field_width [ 0 ] == -1 ) fmt [ i ++ ] = '*'; else - i += sprintf ( & fmt [ i ], "%u", field_width [ 0 ] ); + i += snprintf ( & fmt [ i ], sizeof(fmt) - i, "%u", field_width [ 0 ] ); } if ( precision != NULL ) { @@ -160,7 +159,7 @@ rc_t final ( const char *flags, int32_t *field_width, int32_t *precision, if ( precision [ 0 ] == -1 ) fmt [ i ++ ] = '*'; else - i += sprintf ( & fmt [ i ], "%u", precision [ 0 ] ); + i += snprintf ( & fmt [ i ], sizeof(fmt) - i, "%u", precision [ 0 ] ); } fmt[i]=0; @@ -313,7 +312,7 @@ static rc_t sign_flag ( int32_t *field_width, int32_t *precision, /* with forces + */ flags [ 0 ] = '+'; - flags [ 1 ] = 0; + flags [ 1 ] = 0; rc = alignment_flag ( flags, 1, field_width, precision, size_modifier, storage_class, args ); if ( rc != 0 ) return rc; @@ -332,7 +331,7 @@ static rc_t do_field_width ( int32_t *field_width, int32_t *precision, char size_modifier, char storage_class, va_list args) { rc_t rc; - uint32_t i; + uint32_t i; rc = sign_flag ( NULL, precision, size_modifier, storage_class, args ); @@ -398,7 +397,7 @@ static rc_t make_initial_test ( int32_t *field_width, int32_t *precision, va_start ( args, storage_class ); rc = do_storage_class ( field_width, precision, size_modifier, storage_class, args ); - + va_end ( args ); return rc; } @@ -414,7 +413,7 @@ rc_t run ( const char *progname ) char c [ ] = { "aA!@0{;>" }; int32_t ext_value [ ] = { -1, -2 }; - int32_t randValue, randValue_2, randValue_3; + int32_t randValue = 0, randValue_2 = 0, randValue_3 = 0; double randValue_f; @@ -422,21 +421,21 @@ rc_t run ( const char *progname ) { /* create random number */ srand ( (unsigned int) time ( NULL ) ); - - + + /* signed integer */ if ( rc == 0 ) { randValue = rand (); randValue_2 = rand () % 10; randValue_3 = rand () % 5; - + rc = make_initial_test ( field_width, precision, " ht", "di", randValue ); if ( rc == 0 ) rc = make_initial_test ( ext_value, precision, " ht", "di", randValue_2, randValue ); if ( rc == 0 ) rc = make_initial_test ( field_width, ext_value, " ht", "di", randValue_3, randValue ); - + if ( rc == 0 ) rc = make_initial_test ( field_width, precision, "l", "di", ( int64_t ) randValue ); if ( rc == 0 ) @@ -444,7 +443,7 @@ rc_t run ( const char *progname ) if ( rc == 0 ) rc = make_initial_test ( field_width, ext_value, "l", "di", randValue_3, ( int64_t ) randValue ); } - + /* unsigned integer */ if ( rc == 0 ) { @@ -453,14 +452,14 @@ rc_t run ( const char *progname ) rc = make_initial_test ( ext_value, precision, " ht", "uxXo", randValue_2, randValue ); if ( rc == 0 ) rc = make_initial_test ( field_width, ext_value, " ht", "uxXo", randValue_3, randValue ); - + if ( rc == 0 ) rc = make_initial_test ( field_width, precision, "l", "uxXo", ( uint64_t ) randValue ); if ( rc == 0 ) rc = make_initial_test ( ext_value, precision, "l", "uxXo", randValue_2, ( uint64_t )randValue ); if ( rc == 0 ) rc = make_initial_test ( field_width, ext_value, "l", "uxXo", randValue_3, ( uint64_t ) randValue ); - + if ( rc == 0 ) rc = make_initial_test ( field_width, precision, "z", "uxXo", ( size_t ) randValue ); if ( rc == 0 ) @@ -468,21 +467,21 @@ rc_t run ( const char *progname ) if ( rc == 0 ) rc = make_initial_test ( field_width, ext_value, "z", "uxXo", randValue_3, ( size_t ) randValue ); } - + /* float */ if ( rc == 0 ) { - + randValue_f = ( double ) randValue / ( ( randValue % 100 ) + 1 ); - + /*** could use some floating point random numbers here */ -#if 0 +#if 0 rc = make_initial_test ( field_width, precision, " ", "feg", randValue ); if ( rc == 0 ) rc = make_initial_test ( ext_value, precision, " ", "feg", randValue_2, randValue ); if ( rc == 0 ) rc = make_initial_test ( field_width, ext_value, " ", "feg", randValue_3, randValue ); -#endif +#endif if ( rc == 0 ) rc = make_initial_test ( field_width, precision, " ", "feg", randValue_f ); @@ -491,7 +490,7 @@ rc_t run ( const char *progname ) if ( rc == 0 ) rc = make_initial_test ( field_width, ext_value, " ", "feg", randValue_3, randValue_f ); } - + /* character */ if ( rc == 0 ) { @@ -499,7 +498,7 @@ rc_t run ( const char *progname ) if ( rc == 0 ) rc = test_printf ( "I like 1 embedded % character", "I like %u embedded %% character", 1 ); } - + /* text string */ if ( rc == 0 ) { @@ -510,19 +509,19 @@ rc_t run ( const char *progname ) /* The standard says this result is undefined, we shouldn't test for it, it is not consistent */ rc = make_initial_test ( field_width, precision, " ", "s", NULL ); #endif -#endif +#endif rc = make_initial_test ( field_width, precision, " ", "s", "" ); rc = make_initial_test ( field_width, precision, " ", "s", "OK" ); rc = make_initial_test ( field_width, precision, " ", "s", "1234567890" ); rc = make_initial_test ( field_width, precision, " ", "s", "\"`~!@#$%^&*()-_=+[]{}|\\';:?/.,<>" ); } - - } - + + } + /* hand written tests */ { - + int8_t t [ ] = { -128, -67, 0, 4, 56, 100, 127 }; int16_t h [ ] = { -32768, -2546, -398, -89, 0, 34, 123, 5736, 32767 }; int32_t v [ ] = { -2147483648, -45287957, -100001, 45, 0, 106, 7234, 546963874, 2147483647 }; @@ -533,9 +532,9 @@ rc_t run ( const char *progname ) which is in fact 64 bits on this machine. on a 32-bit machine, you need type "long long int". - you can make use of a pre-processor symbol to do this properly - I'll do it below. + you can make use of a pre-processor symbol to do this properly - I'll do it below. */ - int64_t l [ ] = { INT64_C(-9223372036854775807) - INT64_C(1), INT64_C(-67283678467328376), INT64_C(-2837640198), INT64_C(0), INT64_C(187267509872), INT64_C(9223372036854775807) }; + int64_t l [ ] = { INT64_C(-9223372036854775807) - INT64_C(1), INT64_C(-67283678467328376), INT64_C(-2837640198), INT64_C(0), INT64_C(187267509872), INT64_C(9223372036854775807) }; /* d, i */ @@ -575,7 +574,7 @@ rc_t run ( const char *progname ) test_printf ( "00000000187267509872" , "%020:4ld", l ); test_printf ( "9223372036854775807" , "%.2:5ld", l ); - } + } { @@ -617,11 +616,11 @@ rc_t run ( const char *progname ) { - /* float */ + /* float */ - float f [ ] = { -2.1474836, -45.287957, -10000.1, 0.45, 0, 1.06 }; + float f [ ] = { -2.1474836f, -45.287957f, -10000.1f, 0.45f, 0.0f, 1.06f }; double lf [ ] = { -9223372036854775808.0, -28.37640198 }; - + /* 32 bit */ test_printf ( " -2.15" , "%7.2:0hf", f ); test_printf ( "-00045.288" , "%010.3:1hf" , f ); @@ -752,12 +751,12 @@ rc_t run ( const char *progname ) if ( rc == 0 ) { pLogErr ( klogErr, rc, "string_vprintf returned zero rc with insufficient buffer", ""); - rc = -1; + rc = (rc_t) - 1; } else { rc = 0; - } + } } #if LINUX @@ -766,66 +765,10 @@ rc_t run ( const char *progname ) #endif return rc; - -} - - -/* Version EXTERN - * return 4-part version code: 0xMMmmrrrr, where - * MM = major release - * mm = minor release - * rrrr = bug-fix release - */ -ver_t CC KAppVersion ( void ) -{ - return 0; -} - -/* Usage - * This function is called when the command line argument - * handling sees -? -h or --help - */ -rc_t CC UsageSummary ( const char *progname ) -{ - return KOutMsg ( - "\n" - "Usage:\n" - " %s [Options]\n" - "\n" - "Summary:\n" - " Simple test of printf.\n" - , progname ); } -const char UsageDefaultName[] = "time-test"; - -rc_t CC Usage ( const Args *args ) -{ - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionsStandard(); - - HelpVersion (fullpath, KAppVersion()); - - return rc; -} - - -/* KMain - */ -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { Args *args; rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0 ); @@ -836,5 +779,5 @@ rc_t CC KMain ( int argc, char *argv [] ) ArgsWhack ( args ); } - return rc; + return (int)rc; } diff --git a/test/klib/test-KOutMsgOverflow.cpp b/test/klib/test-KOutMsgOverflow.cpp index 538ddc503..d9ca49bbe 100644 --- a/test/klib/test-KOutMsgOverflow.cpp +++ b/test/klib/test-KOutMsgOverflow.cpp @@ -170,12 +170,7 @@ TEST_CASE(TestOUTMSG_c) { REQUIRE_EQ(output, string("c.")); } -extern "C" { -#ifdef WINDOWS - #define main wmain -#endif - int main(int argc, char *argv[]) { - KWrtInit(argv[0], 0); - return KOutTestSuite(argc, argv); - } +int main(int argc, char *argv[]) { + KWrtInit(argv[0], 0); + return KOutTestSuite(argc, argv); } diff --git a/test/klib/test-SraReleaseVersion.cpp b/test/klib/test-SraReleaseVersion.cpp index 50615dc9f..65ff6906b 100644 --- a/test/klib/test-SraReleaseVersion.cpp +++ b/test/klib/test-SraReleaseVersion.cpp @@ -304,13 +304,6 @@ TEST_CASE(SraReleaseVersionTest) { } //////////////////////////////////////////////////// Main -extern "C" { - ver_t CC KAppVersion(void) { return 0; } - rc_t CC Usage(const Args *args) { return 0; } - const char UsageDefaultName[] = "test-SraReleaseVersion"; - rc_t CC UsageSummary(const char *progname) { return 0; } - - rc_t CC KMain(int argc, char *argv[]) { - return SraReleaseVersionTestSuite(argc, argv); - } +int main(int argc, char *argv[]) { + return SraReleaseVersionTestSuite(argc, argv); } diff --git a/test/klib/test-base64.cpp b/test/klib/test-base64.cpp index 470d13ce7..47ca71c63 100644 --- a/test/klib/test-base64.cpp +++ b/test/klib/test-base64.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -46,16 +48,16 @@ TEST_CASE ( KBase64_encodeBase64 ) rc_t rc = 0; const String *encoded; const char *data = "Test for basic Base64 encoding"; - + rc = encodeBase64 ( &encoded, data, strlen (data) ); - + REQUIRE_RC ( rc ); - + std :: string expected ( "VGVzdCBmb3IgYmFzaWMgQmFzZTY0IGVuY29kaW5n" ); std :: string result ( encoded -> addr, encoded -> size ); - + REQUIRE_EQ ( expected, result ); - + StringWhack ( encoded ); } @@ -67,14 +69,14 @@ TEST_CASE ( KBase64_decodeBase64 ) StringInitCString ( &str, "VGVzdCBmb3IgYmFzaWMgQmFzZTY0IGVuY29kaW5n" ); const String *encoding; StringCopy ( &encoding, &str ); - + rc = decodeBase64 ( &decoded, encoding ); StringWhack ( encoding ); REQUIRE_RC ( rc ); std :: string expected ( "Test for basic Base64 encoding" ); std :: string result ( ( char * ) decoded . base, decoded . elem_count ); - + REQUIRE_EQ ( expected, result ); rc = KDataBufferWhack ( &decoded ); @@ -87,16 +89,16 @@ TEST_CASE ( KBase64_encodeBase64_rfc1 ) rc_t rc = 0; const String *encoded; const char *data = ""; - + rc = encodeBase64 ( &encoded, data, strlen (data) ); - + REQUIRE_RC ( rc ); - + std :: string expected ( "" ); std :: string result ( encoded -> addr, encoded -> size ); - + REQUIRE_EQ ( expected, result ); - + StringWhack ( encoded ); } @@ -108,14 +110,14 @@ TEST_CASE ( KBase64_decodeBase64_rfc1 ) StringInitCString ( &str, "" ); const String *encoding; StringCopy ( &encoding, &str ); - + rc = decodeBase64 ( &decoded, encoding ); StringWhack ( encoding ); REQUIRE_RC ( rc ); std :: string expected ( "" ); std :: string result ( ( char * ) decoded . base, decoded . elem_count ); - + REQUIRE_EQ ( expected, result ); rc = KDataBufferWhack ( &decoded ); @@ -128,20 +130,20 @@ TEST_CASE ( KBase64_encodeBase64_rfc2 ) rc_t rc = 0; const String *encoded; const char *data = "f"; - + rc = encodeBase64 ( &encoded, data, strlen (data) ); - + REQUIRE_RC ( rc ); - + #if BASE64_PAD_ENCODING std :: string expected ( "Zg==" ); #else std :: string expected ( "Zg" ); #endif std :: string result ( encoded -> addr, encoded -> size ); - + REQUIRE_EQ ( expected, result ); - + StringWhack ( encoded ); } @@ -153,14 +155,14 @@ TEST_CASE ( KBase64_decodeBase64_rfc2 ) StringInitCString ( &str, "Zg==" ); const String *encoding; StringCopy ( &encoding, &str ); - + rc = decodeBase64 ( &decoded, encoding ); StringWhack ( encoding ); REQUIRE_RC ( rc ); std :: string expected ( "f" ); std :: string result ( ( char * ) decoded . base, decoded . elem_count ); - + REQUIRE_EQ ( expected, result ); rc = KDataBufferWhack ( &decoded ); @@ -173,20 +175,20 @@ TEST_CASE ( KBase64_encodeBase64_rfc3 ) rc_t rc = 0; const String *encoded; const char *data = "fo"; - + rc = encodeBase64 ( &encoded, data, strlen (data) ); - + REQUIRE_RC ( rc ); - + #if BASE64_PAD_ENCODING std :: string expected ( "Zm8=" ); #else std :: string expected ( "Zm8" ); #endif std :: string result ( encoded -> addr, encoded -> size ); - + REQUIRE_EQ ( expected, result ); - + StringWhack ( encoded ); } @@ -198,14 +200,14 @@ TEST_CASE ( KBase64_decodeBase64_rfc3 ) StringInitCString ( &str, "Zm8=" ); const String *encoding; StringCopy ( &encoding, &str ); - + rc = decodeBase64 ( &decoded, encoding ); StringWhack ( encoding ); REQUIRE_RC ( rc ); std :: string expected ( "fo" ); std :: string result ( ( char * ) decoded . base, decoded . elem_count ); - + REQUIRE_EQ ( expected, result ); rc = KDataBufferWhack ( &decoded ); @@ -218,16 +220,16 @@ TEST_CASE ( KBase64_encodeBase64_rfc4 ) rc_t rc = 0; const String *encoded; const char *data = "foo"; - + rc = encodeBase64 ( &encoded, data, strlen (data) ); - + REQUIRE_RC ( rc ); - + std :: string expected ( "Zm9v" ); std :: string result ( encoded -> addr, encoded -> size ); - + REQUIRE_EQ ( expected, result ); - + StringWhack ( encoded ); } @@ -239,14 +241,14 @@ TEST_CASE ( KBase64_decodeBase64_rfc4 ) StringInitCString ( &str, "Zm9v" ); const String *encoding; StringCopy ( &encoding, &str ); - + rc = decodeBase64 ( &decoded, encoding ); StringWhack ( encoding ); REQUIRE_RC ( rc ); std :: string expected ( "foo" ); std :: string result ( ( char * ) decoded . base, decoded . elem_count ); - + REQUIRE_EQ ( expected, result ); rc = KDataBufferWhack ( &decoded ); @@ -259,20 +261,20 @@ TEST_CASE ( KBase64_encodeBase64_rfc5 ) rc_t rc = 0; const String *encoded; const char *data = "foob"; - + rc = encodeBase64 ( &encoded, data, strlen (data) ); - + REQUIRE_RC ( rc ); - + #if BASE64_PAD_ENCODING std :: string expected ( "Zm9vYg==" ); #else std :: string expected ( "Zm9vYg" ); #endif std :: string result ( encoded -> addr, encoded -> size ); - + REQUIRE_EQ ( expected, result ); - + StringWhack ( encoded ); } @@ -284,14 +286,14 @@ TEST_CASE ( KBase64_decodeBase64_rfc5 ) StringInitCString ( &str, "Zm9vYg==" ); const String *encoding; StringCopy ( &encoding, &str ); - + rc = decodeBase64 ( &decoded, encoding ); StringWhack ( encoding ); REQUIRE_RC ( rc ); std :: string expected ( "foob" ); std :: string result ( ( char * ) decoded . base, decoded . elem_count ); - + REQUIRE_EQ ( expected, result ); rc = KDataBufferWhack ( &decoded ); @@ -304,20 +306,20 @@ TEST_CASE ( KBase64_encodeBase64_rfc6 ) rc_t rc = 0; const String *encoded; const char *data = "fooba"; - + rc = encodeBase64 ( &encoded, data, strlen (data) ); - + REQUIRE_RC ( rc ); - + #if BASE64_PAD_ENCODING std :: string expected ( "Zm9vYmE=" ); #else std :: string expected ( "Zm9vYmE" ); #endif std :: string result ( encoded -> addr, encoded -> size ); - + REQUIRE_EQ ( expected, result ); - + StringWhack ( encoded ); } @@ -329,14 +331,14 @@ TEST_CASE ( KBase64_decodeBase64_rfc6 ) StringInitCString ( &str, "Zm9vYmE=" ); const String *encoding; StringCopy ( &encoding, &str ); - + rc = decodeBase64 ( &decoded, encoding ); StringWhack ( encoding ); REQUIRE_RC ( rc ); std :: string expected ( "fooba" ); std :: string result ( ( char * ) decoded . base, decoded . elem_count ); - + REQUIRE_EQ ( expected, result ); rc = KDataBufferWhack ( &decoded ); @@ -349,16 +351,16 @@ TEST_CASE ( KBase64_encodeBase64_rfc7 ) rc_t rc = 0; const String *encoded; const char *data = "foobar"; - + rc = encodeBase64 ( &encoded, data, strlen (data) ); - + REQUIRE_RC ( rc ); - + std :: string expected ( "Zm9vYmFy" ); std :: string result ( encoded -> addr, encoded -> size ); - + REQUIRE_EQ ( expected, result ); - + StringWhack ( encoded ); } @@ -370,14 +372,14 @@ TEST_CASE ( KBase64_decodeBase64_rfc7 ) StringInitCString ( &str, "Zm9vYmFy" ); const String *encoding; StringCopy ( &encoding, &str ); - + rc = decodeBase64 ( &decoded, encoding ); StringWhack ( encoding ); REQUIRE_RC ( rc ); std :: string expected ( "foobar" ); std :: string result ( ( char * ) decoded . base, decoded . elem_count ); - + REQUIRE_EQ ( expected, result ); rc = KDataBufferWhack ( &decoded ); @@ -385,22 +387,8 @@ TEST_CASE ( KBase64_decodeBase64_rfc7 ) } //////////////////////////////////////////////////// Main -extern "C" { - -#include -#include - -ver_t CC KAppVersion(void) { return 0x1000000; } -rc_t CC UsageSummary(const char* progname) { return 0; } - -rc_t CC Usage(const Args* args) { return 0; } - -const char UsageDefaultName[] = "test-base64"; - -rc_t CC KMain(int argc, char* argv[]) +int main(int argc, char* argv[]) { KConfigDisableUserSettings(); - rc_t rc = KBase64TestSuite(argc, argv); - return rc; -} + return KBase64TestSuite(argc, argv); } diff --git a/test/klib/test-btree.cpp b/test/klib/test-btree.cpp index ccc4f6ac3..7c76418d6 100644 --- a/test/klib/test-btree.cpp +++ b/test/klib/test-btree.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -201,7 +203,7 @@ class BtreeFixture ret -> root = pb.get() == nullptr ? 0 : pb -> root; ret -> id = & m_id; ret -> key = key.c_str(); - ret -> key_size = key.size(); + ret -> key_size = (int32_t)key.size(); ret -> was_inserted = false; return ret; } @@ -246,7 +248,7 @@ class BtreeFixture { return true; } - return string( &((const char *)&node)[node.key_prefix], node.key_prefix_len ) == prefix; + return string( &((const char *)&node)[node.key_prefix], (size_t)node.key_prefix_len ) == prefix; } bool CheckWindow( const LeafNode & node, unsigned int index, uint16_t lower, uint16_t upper ) @@ -261,7 +263,7 @@ class BtreeFixture bool CheckKey( const LeafNode & node, unsigned int index, const string & key ) { - string actual ( &((const char *)&node)[node.ord[index].key], node.ord[index].ksize ); + string actual ( &((const char *)&node)[node.ord[index].key], (size_t)node.ord[index].ksize ); if ( actual != key ) { cerr << "CheckKey[" << index << "]: expected " << key << ", actual " << actual << " " << (int)((const char *)&node)[node.ord[index].key] << " " << node.ord[index].ksize << endl; @@ -462,7 +464,7 @@ FIXTURE_TEST_CASE( Split_LeftOfMedian, BtreeFixture ) REQUIRE( CheckWindow( * newNode, 'C', 0, 1 )); REQUIRE( CheckWindow( * newNode, 'C'+1, 1, 1 )); - REQUIRE_EQ( string(B), string((const char*)split.key, split.ksize)); + REQUIRE_EQ( string(B), string((const char*)split.key, (size_t)split.ksize)); REQUIRE_EQ( 0, (int)split.left ); REQUIRE_EQ( 4, (int)split.right ); } @@ -512,7 +514,7 @@ FIXTURE_TEST_CASE( Split_RightOfMedian, BtreeFixture ) REQUIRE( CheckWindow( * newNode, 'E', 1, 2 )); REQUIRE( CheckWindow( * newNode, 'E'+1, 2, 2 )); - REQUIRE_EQ( string(C), string((const char*)split.key, split.ksize)); + REQUIRE_EQ( string(C), string((const char*)split.key, (size_t)split.ksize)); REQUIRE_EQ( 0, (int)split.left ); REQUIRE_EQ( 4, (int)split.right ); } @@ -562,7 +564,7 @@ FIXTURE_TEST_CASE( Split_Median, BtreeFixture ) REQUIRE( CheckWindow( * newNode, 'E', 0, 1 )); REQUIRE( CheckWindow( * newNode, 'E'+1, 1, 1 )); - REQUIRE_EQ( string("D"), string((const char*)split.key, split.ksize)); + REQUIRE_EQ( string("D"), string((const char*)split.key, (size_t)split.ksize)); REQUIRE_EQ( 0, (int)split.left ); REQUIRE_EQ( 4, (int)split.right ); } @@ -626,22 +628,8 @@ FIXTURE_TEST_CASE( LotsaFixedSizeInserts, BtreeFixture ) } //////////////////////////////////////////////////// Main -extern "C" { - -#include -#include - -ver_t CC KAppVersion(void) { return 0x1000000; } -rc_t CC UsageSummary(const char* progname) { return 0; } - -rc_t CC Usage(const Args* args) { return 0; } - -const char UsageDefaultName[] = "test-btree"; - -rc_t CC KMain(int argc, char* argv[]) +int main(int argc, char* argv[]) { KConfigDisableUserSettings(); - rc_t rc = BtreeTestSuite(argc, argv); - return rc; -} + return BtreeTestSuite(argc, argv); } diff --git a/test/klib/test-data-buffer-print.c b/test/klib/test-data-buffer-print.c index b53b21fde..36e6cd0da 100644 --- a/test/klib/test-data-buffer-print.c +++ b/test/klib/test-data-buffer-print.c @@ -24,7 +24,6 @@ * */ -#include #include #include #include @@ -47,14 +46,14 @@ static rc_t run ( const char *progname ) { rc_t rc = 0; - + char const *const cicero = "Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit amet consectetur adipisci[ng]velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum[d] exercitationem ullam corporis suscipitlaboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui inea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?"; size_t const orig_length = strlen(cicero); int const replicount = (int)( (5000 + orig_length - 1) / orig_length ); /* allocation is in 4k chunks; pick a repeat count so that the buffer has to grow at least once */ size_t const final_length = (orig_length + 1) * replicount + 1; KDataBuffer buffer; int i; - + memset(&buffer, 0, sizeof buffer); for (i = 0; i < replicount; ++i) { rc = KDataBufferPrintf(&buffer, "%s", cicero); @@ -95,63 +94,7 @@ rc_t run ( const char *progname ) return rc; } - -/* Version EXTERN - * return 4-part version code: 0xMMmmrrrr, where - * MM = major release - * mm = minor release - * rrrr = bug-fix release - */ -ver_t CC KAppVersion ( void ) -{ - return 0; -} - - -/* Usage - * This function is called when the command line argument - * handling sees -? -h or --help - */ -rc_t CC UsageSummary ( const char *progname ) -{ - return KOutMsg ( - "\n" - "Usage:\n" - " %s [Options]\n" - "\n" - "Summary:\n" - " Simple test of printf.\n" - , progname ); -} - -const char UsageDefaultName[] = "time-data-buffer-print"; - -rc_t CC Usage ( const Args *args ) -{ - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionsStandard(); - - HelpVersion (fullpath, KAppVersion()); - - return rc; -} - - -/* KMain - */ -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args *args; rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0 ); diff --git a/test/klib/test-guid.cpp b/test/klib/test-guid.cpp index fc11d6d0c..6e7ee6936 100755 --- a/test/klib/test-guid.cpp +++ b/test/klib/test-guid.cpp @@ -52,11 +52,11 @@ static uint8_t fromxdigit( unsigned char ch ) if ( ch < '0' ) return '?'; if ( ch <= '9' ) - return ch - '0'; + return (uint8_t) ( ch - '0' ); if ( ch < 'a' ) return '?'; if ( ch <= 'f' ) - return ch - 'a' + 10; + return (uint8_t) ( ch - 'a' + 10 ); return '?'; } @@ -91,7 +91,7 @@ TEST_CASE(Make_Success) // 0b10xx, variant 1 in the 2 msb REQUIRE ( isxdigit ( buf[19] ) ); - REQUIRE_EQ ( 2, fromxdigit( buf[ 19 ] ) >> 2 ); + REQUIRE_EQ ( 2, fromxdigit( (unsigned char) buf[ 19 ] ) >> 2 ); REQUIRE ( isxdigit ( buf[20] ) ); REQUIRE ( isxdigit ( buf[21] ) ); @@ -114,15 +114,7 @@ TEST_CASE(Make_Success) } //////////////////////////////////////////////////// Main -extern "C" -{ -#ifdef WINDOWS -#define main wmain -#endif int main ( int argc, char *argv [] ) { - rc_t rc=GUIDTestSuite(argc, argv); - return rc; -} - + return GUIDTestSuite(argc, argv); } diff --git a/test/klib/test-hashfile.cpp b/test/klib/test-hashfile.cpp index b561052f9..3b3b99888 100644 --- a/test/klib/test-hashfile.cpp +++ b/test/klib/test-hashfile.cpp @@ -28,6 +28,7 @@ */ #include +#include #include #include @@ -64,13 +65,14 @@ #include #include #include +#include using namespace std; #define RANDS_SIZE 2000000 static uint64_t RANDS[RANDS_SIZE]; -static volatile bool KEEPRUNNING = true; +static atomic KEEPRUNNING{true}; static atomic64_t FINDCOUNT; static KDirectory* DIR = NULL; static KFile* BACKING = NULL; @@ -84,7 +86,7 @@ static __inline uint64_t fastrng(uint64_t* state0) const uint64_t rot = s0 >> 60; *state0 *= 12898287266413564321ULL; uint64_t xs = uint64_ror(s0, 18) + s0; - xs = uint64_ror(xs, rot); + xs = uint64_ror(xs, (uint8_t)rot); return xs; } @@ -231,9 +233,9 @@ TEST_CASE(Klib_hashfiledups) rc = KHashFileMake(&hmap, BACKING); REQUIRE_RC(rc); - uint64_t key1 = random(); + uint64_t key1 = (uint64_t)random(); uint64_t hash1 = KHash((const char*)&key1, sizeof(uint64_t)); - uint64_t key2 = random(); + uint64_t key2 = (uint64_t)random(); uint64_t hash2 = hash1; for (size_t i = 0; i != 100000; ++i) { rc = KHashFileAdd(hmap, (const char*)&key1, 8, hash1, @@ -254,7 +256,7 @@ TEST_CASE(Klib_hashfileMapDeletes) { rc_t rc; - uint64_t state = random(); + uint64_t state = (uint64_t)random(); KHashFile* hmap; rc = KHashFileMake(&hmap, BACKING); @@ -316,7 +318,7 @@ TEST_CASE(Klib_hashfileMapDeletes) static rc_t inserter(const KThread* thread, void* data) noexcept { rc_t rc; - uint64_t state = random(); + uint64_t state = (uint64_t)random(); while (KEEPRUNNING) { size_t idx = fastrng(&state) % RANDS_SIZE; uint64_t key = RANDS[idx]; @@ -337,7 +339,7 @@ static rc_t inserter(const KThread* thread, void* data) noexcept static rc_t deleter(const KThread* thread, void* data) noexcept { - uint64_t state = random(); + uint64_t state = (uint64_t)random(); while (KEEPRUNNING) { size_t idx = fastrng(&state) % RANDS_SIZE; uint64_t key = RANDS[idx]; @@ -350,7 +352,7 @@ static rc_t deleter(const KThread* thread, void* data) noexcept static rc_t finder(const KThread* thread, void* data) noexcept { - uint64_t state = random(); + uint64_t state = (uint64_t)random(); while (KEEPRUNNING) { size_t idx = fastrng(&state) % RANDS_SIZE; uint64_t key = RANDS[idx]; @@ -380,7 +382,7 @@ static rc_t finder(const KThread* thread, void* data) noexcept static rc_t notfinder(const KThread* thread, void* data) noexcept { - uint64_t state = random(); + uint64_t state = (uint64_t)random(); while (KEEPRUNNING) { uint64_t key = fastrng(&state); uint64_t val = 9; @@ -623,8 +625,8 @@ TEST_CASE(Klib_hashfilethreads) KEEPRUNNING = false; KSleepMs(1000); - for (long i = 0; i != VectorLength(&threads); ++i) { - KThread* thrd = (KThread*)VectorGet(&threads, i); + for (long i = 0; i != (long)VectorLength(&threads); ++i) { + KThread* thrd = (KThread*)VectorGet(&threads, (uint32_t)i); KThreadRelease(thrd); } VectorWhack(&threads, NULL, NULL); @@ -645,7 +647,7 @@ TEST_CASE(Klib_HashFileIterator) std::unordered_map map; for (int iter = 0; iter != 2; ++iter) { for (int i = 0; i != loops; ++i) { - key = random() % loops; + key = (uint32_t) ( random() % loops ); value = key + 1; auto pair = std::make_pair(key, value); @@ -662,7 +664,7 @@ TEST_CASE(Klib_HashFileIterator) } for (int i = 0; i != loops; ++i) { - key = random() % loops; + key = (uint32_t) ( random() % loops ); map.erase(key); @@ -678,7 +680,7 @@ TEST_CASE(Klib_HashFileIterator) } for (int i = 0; i != loops; ++i) { - key = random() % loops; + key = (uint32_t) ( random() % loops ); value = (uint32_t)random(); auto pair = std::make_pair(key, value); @@ -739,50 +741,37 @@ TEST_CASE(Klib_HashFileIterator) KHashFileDispose(hmap); } -extern "C" { - -#include -#include - -ver_t CC KAppVersion(void) { return 0x1000000; } -rc_t CC UsageSummary(const char* progname) { return 0; } - -rc_t CC Usage(const Args* args) { return 0; } - -const char UsageDefaultName[] = "test-hashfile"; - -rc_t CC KMain(int argc, char* argv[]) +int main(int argc, char* argv[]) { rc_t rc; - srandom(time(NULL)); - uint64_t state = random(); + srandom( (unsigned int) time(NULL)); + uint64_t state = (uint64_t)random(); for (size_t i = 0; i != RANDS_SIZE; ++i) { RANDS[i] = fastrng(&state); } rc = KDirectoryNativeDir(&DIR); - if (rc) return rc; + if (rc) return (int)rc; const char* fname = "test-hashfile.data"; rc = KDirectoryCreateFile(DIR, &BACKING, true, 0600, kcmInit, fname); - if (rc) return rc; + if (rc) return (int)rc; KConfigDisableUserSettings(); - rc = KHashFileTestSuite(argc, argv); - if (rc) return rc; + rc = (rc_t)KHashFileTestSuite(argc, argv); + if (rc) return (int)rc; rc = KDirectoryRemove(DIR, true, "%s", fname); #ifndef WINDOWS - if (rc) return rc; + if (rc) return (int)rc; #endif rc = KFileRelease(BACKING); - if (rc) return rc; + if (rc) return (int)rc; rc = KDirectoryRelease(DIR); - if (rc) return rc; + if (rc) return (int)rc; return 0; } -} diff --git a/test/klib/test-hashtable.cpp b/test/klib/test-hashtable.cpp index 50cd31a97..9a28c1c15 100644 --- a/test/klib/test-hashtable.cpp +++ b/test/klib/test-hashtable.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include @@ -958,7 +960,7 @@ TEST_CASE(Klib_hash_hamming) string_hash(foo1, strlen(foo1)), foo2, string_hash(foo2, strlen(foo2))); for (uint64_t i = 0; i != 10000000; i++) { - sprintf(key, "ABCD%lu", i); + snprintf(key, sizeof(key), "ABCD%lu", i); uint64_t hash = string_hash(key, strlen(key)); hash &= mask; hash_collisions[hash] = hash_collisions[hash] + 1; @@ -988,23 +990,9 @@ TEST_CASE(Klib_hash_hamming) #endif // BENCHMARK -extern "C" { - -#include -#include - -ver_t CC KAppVersion(void) { return 0x1000000; } -rc_t CC UsageSummary(const char* progname) { return 0; } - -rc_t CC Usage(const Args* args) { return 0; } - -const char UsageDefaultName[] = "test-hashtable"; - -rc_t CC KMain(int argc, char* argv[]) +int main(int argc, char* argv[]) { srandom(time(NULL)); KConfigDisableUserSettings(); - rc_t rc = KHashTableTestSuite(argc, argv); - return rc; -} + return KHashTableTestSuite(argc, argv); } diff --git a/test/klib/test-json-parser.cpp b/test/klib/test-json-parser.cpp index c11377ef6..b6a0a1736 100644 --- a/test/klib/test-json-parser.cpp +++ b/test/klib/test-json-parser.cpp @@ -40,27 +40,7 @@ using namespace std; -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "test-json-parser"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] json-file ... \n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { int failed = 0; if ( argc < 2 ) @@ -122,6 +102,3 @@ rc_t CC KMain ( int argc, char *argv [] ) } return failed == 0 ? 0 : 4; } - -} - diff --git a/test/klib/test-json.cpp b/test/klib/test-json.cpp index 11ff9a285..27d7c279a 100644 --- a/test/klib/test-json.cpp +++ b/test/klib/test-json.cpp @@ -950,15 +950,7 @@ FIXTURE_TEST_CASE(KJson_ToJsonString_PrettyPrint, KJsonFixture) } //////////////////////////////////////////////////// Main -extern "C" -{ -#ifdef WINDOWS -#define main wmain -#endif int main ( int argc, char *argv [] ) { - rc_t rc=KJsonTestSuite(argc, argv); - return rc; -} - + return KJsonTestSuite(argc, argv); } diff --git a/test/klib/test-klib.cpp b/test/klib/test-klib.cpp index 421b2619a..3c8328ce3 100644 --- a/test/klib/test-klib.cpp +++ b/test/klib/test-klib.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include #include /* is_user_admin() */ @@ -40,6 +42,8 @@ #include #include +#include + #include #include #include @@ -1078,7 +1082,7 @@ TEST_CASE(GetUnreadRCInfo_LogRC) #endif TEST_CASE(TimeRoundTrip) -{ +{ KTime_t t1 = KTimeStamp(); // UTC char str1[100]; KTimeIso8601(t1, str1, sizeof str1); @@ -1122,22 +1126,8 @@ TEST_CASE(KnowIfTheFunctionExistsAtCompileTime) { #endif //////////////////////////////////////////////////// Main -extern "C" { - -#include -#include - -ver_t CC KAppVersion(void) { return 0x1000000; } -rc_t CC UsageSummary(const char* progname) { return 0; } - -rc_t CC Usage(const Args* args) { return 0; } - -const char UsageDefaultName[] = "test-klib"; - -rc_t CC KMain(int argc, char* argv[]) +int main(int argc, char* argv[]) { - KConfigDisableUserSettings(); - rc_t rc = KlibTestSuite(argc, argv); - return rc; -} + VDB::Application app(argc, argv); + return KlibTestSuite(argc, app.getArgV()); } diff --git a/test/klib/test-log.cpp b/test/klib/test-log.cpp index 5e412c96d..0758cb601 100644 --- a/test/klib/test-log.cpp +++ b/test/klib/test-log.cpp @@ -339,15 +339,7 @@ TEST_CASE ( rcBufferrcInsufficientInprep_v_argsstring_vprintf ) { // KLogInit //////////////////////////////////////////////////// Main -extern "C" -{ -#ifdef WINDOWS -#define main wmain -#endif int main ( int argc, char *argv [] ) { - rc_t rc=KLogTestSuite(argc, argv); - return rc; -} - + return KLogTestSuite(argc, argv); } diff --git a/test/klib/test-out.cpp b/test/klib/test-out.cpp index 720c1d0bc..cbbc11b03 100644 --- a/test/klib/test-out.cpp +++ b/test/klib/test-out.cpp @@ -200,7 +200,7 @@ TEST_CASE(KOutMsgUriProvider) TEST_CASE(KOutMsgInvalidRC) { string const expected = string("INVALID,INVALID,INVALID,INVALID,INVALID)"); - rc_t invalid_rc = -1; + rc_t invalid_rc = (rc_t) - 1; string output; REQUIRE_RC(KOutHandlerSet(writerFn, &output)); REQUIRE_RC(KOutMsg("%R", invalid_rc)); @@ -209,15 +209,8 @@ TEST_CASE(KOutMsgInvalidRC) //////////////////////////////////////////////////// Main -extern "C" -{ -#ifdef WINDOWS -#define main wmain -#endif int main ( int argc, char *argv [] ) -{ - rc_t rc=KOutTestSuite(argc, argv); - return rc; -} - +{ + // NB do not use VdbApplication; we need VDB to be in an unitialized state (see the top 4 tests in this file) + return KOutTestSuite(argc, argv); } diff --git a/test/klib/test-pack.cpp b/test/klib/test-pack.cpp index 092bd8e1f..777786ac8 100644 --- a/test/klib/test-pack.cpp +++ b/test/klib/test-pack.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -70,7 +72,7 @@ class PackFixture THROW_ON_FALSE( (bitsz_t)packed == m_packedBits ); if ( debug ) { - int i = 0; + Buffer::size_type i = 0; bitsz_t bits = m_packedBits; while ( true ) { @@ -114,7 +116,7 @@ class PackFixture if ( debug ) { - int i = 0; + Buffer::size_type i = 0; bitsz_t bits = m_packedBits; while ( true ) { @@ -343,22 +345,8 @@ FIXTURE_TEST_CASE(Pack_fail, PackFixture) } //////////////////////////////////////////////////// Main -extern "C" { - -#include -#include - -ver_t CC KAppVersion(void) { return 0x1000000; } -rc_t CC UsageSummary(const char* progname) { return 0; } - -rc_t CC Usage(const Args* args) { return 0; } - -const char UsageDefaultName[] = "Test_KLIB_pack"; - -rc_t CC KMain(int argc, char* argv[]) +int main(int argc, char* argv[]) { KConfigDisableUserSettings(); - rc_t rc = KlibPackTestSuite(argc, argv); - return rc; -} + return KlibPackTestSuite(argc, argv); } diff --git a/test/klib/test-progress.cpp b/test/klib/test-progress.cpp index ed1a7b910..4ef987e46 100644 --- a/test/klib/test-progress.cpp +++ b/test/klib/test-progress.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -47,7 +49,7 @@ TEST_SUITE( ProgressbarTestSuite ); TEST_CASE ( Progress1 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar( &pb, 0 ) ); REQUIRE_RC( destroy_progressbar( pb ) ); } @@ -55,7 +57,7 @@ TEST_CASE ( Progress1 ) TEST_CASE ( Progress2 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar( &pb, 0 ) ); REQUIRE_RC( update_progressbar( pb, 75 ) ); REQUIRE_RC( destroy_progressbar( pb ) ); @@ -64,7 +66,7 @@ TEST_CASE ( Progress2 ) TEST_CASE ( Progress3 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar( &pb, 1 ) ); REQUIRE_RC( update_progressbar( pb, 780 ) ); REQUIRE_RC( destroy_progressbar( pb ) ); @@ -73,7 +75,7 @@ TEST_CASE ( Progress3 ) TEST_CASE ( Progress4 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar( &pb, 2 ) ); REQUIRE_RC( update_progressbar( pb, 7950 ) ); REQUIRE_RC( destroy_progressbar( pb ) ); @@ -82,7 +84,7 @@ TEST_CASE ( Progress4 ) TEST_CASE ( Progress5 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar_stderr( &pb, 0 ) ); REQUIRE_RC( update_progressbar( pb, 70 ) ); REQUIRE_RC( destroy_progressbar( pb ) ); @@ -91,7 +93,7 @@ TEST_CASE ( Progress5 ) TEST_CASE ( Progress6 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar_stderr( &pb, 1 ) ); REQUIRE_RC( update_progressbar( pb, 720 ) ); REQUIRE_RC( destroy_progressbar( pb ) ); @@ -100,7 +102,7 @@ TEST_CASE ( Progress6 ) TEST_CASE ( Progress7 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar_stderr( &pb, 2 ) ); REQUIRE_RC( update_progressbar( pb, 7300 ) ); REQUIRE_RC( destroy_progressbar( pb ) ); @@ -109,7 +111,7 @@ TEST_CASE ( Progress7 ) TEST_CASE ( Progress8 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar( &pb, 0 ) ); uint32_t x; for ( x = 0; x <= 100; ++x ) @@ -123,7 +125,7 @@ TEST_CASE ( Progress8 ) TEST_CASE ( Progress9 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar( &pb, 1 ) ); uint32_t x; for ( x = 0; x <= 1000; ++x ) @@ -137,7 +139,7 @@ TEST_CASE ( Progress9 ) TEST_CASE ( Progress10 ) { progressbar * pb; - + REQUIRE_RC( make_progressbar( &pb, 2 ) ); uint32_t x; for ( x = 0; x <= 10000; ++x ) @@ -149,33 +151,8 @@ TEST_CASE ( Progress10 ) } //////////////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-progressbar"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc = ProgressbarTestSuite( argc, argv ); - return rc; -} - + return ProgressbarTestSuite( argc, argv ); } diff --git a/test/klib/test-rcenum.cpp b/test/klib/test-rcenum.cpp index 79a85c657..d4d1e3766 100644 --- a/test/klib/test-rcenum.cpp +++ b/test/klib/test-rcenum.cpp @@ -35,9 +35,6 @@ #include #include -TEST_SUITE( KlibTestSuite ); - - TEST_SUITE( TestRCEnumSuite ); TEST_CASE( test ) @@ -321,10 +318,7 @@ TEST_CASE( test ) //////////////////////////////////////////////////////////////////////////////// } -extern "C" { - ver_t CC KAppVersion( void ) { return 0; } - rc_t CC KMain( int argc, char * argv[] ) - { - return TestRCEnumSuite( argc, argv ); - } +int main( int argc, char * argv[] ) +{ + return TestRCEnumSuite( argc, argv ); } diff --git a/test/klib/test-report.cpp b/test/klib/test-report.cpp index cafc34c6f..7dd885d4e 100644 --- a/test/klib/test-report.cpp +++ b/test/klib/test-report.cpp @@ -40,19 +40,11 @@ TEST_CASE(Report_InitFini) { char * argv[] = { (char*)"exe" }; ReportInit( 1, argv, (ver_t)0 ); - REQUIRE_RC( ReportFinalize(0 ) ); + REQUIRE_RC( ReportFinalize( 0 ) ); } //////////////////////////////////////////////////// Main -extern "C" -{ -#ifdef WINDOWS -#define main wmain -#endif int main ( int argc, char *argv [] ) { - rc_t rc=KReportTestSuite(argc, argv); - return rc; -} - + return KReportTestSuite(argc, argv); } diff --git a/test/klib/test-sha-32bit.cpp b/test/klib/test-sha-32bit.cpp index 834920df3..f9ada9a40 100755 --- a/test/klib/test-sha-32bit.cpp +++ b/test/klib/test-sha-32bit.cpp @@ -45,7 +45,7 @@ static std::string convertDigest(uint8_t const *digest, size_t size) char buf[16]; static char const *fmt = "%02X"; int n = snprintf(buf, 16, fmt, (int)digest[i]); - result.append(buf, n); + result.append(buf, (size_t) n); } return result; } @@ -94,15 +94,7 @@ TEST_CASE(SHA256_abc_NIST) } //////////////////////////////////////////////////// Main -extern "C" -{ -#ifdef WINDOWS -#define main wmain -#endif int main ( int argc, char *argv [] ) { - rc_t rc=SHATestSuite(argc, argv); - return rc; -} - + return SHATestSuite(argc, argv); } diff --git a/test/klib/test-symtab.cpp b/test/klib/test-symtab.cpp index e5126646a..93d4a59a8 100644 --- a/test/klib/test-symtab.cpp +++ b/test/klib/test-symtab.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -294,33 +296,8 @@ FIXTURE_TEST_CASE ( FindNext_Found, SymtabFixture ) } //////////////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-symtab"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=KSymtabTestSuite(argc, argv); - return rc; -} - + return KSymtabTestSuite(argc, argv); } diff --git a/test/klib/test-time.cpp b/test/klib/test-time.cpp index 55ea266f1..99184a596 100644 --- a/test/klib/test-time.cpp +++ b/test/klib/test-time.cpp @@ -80,8 +80,7 @@ TEST_CASE ( test ) { } -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char * argv [] ) - { return TestTimeSuite ( argc, argv ); } +int main( int argc, char * argv [] ) +{ + return TestTimeSuite ( argc, argv ); } diff --git a/test/klib/test-vnamelist.cpp b/test/klib/test-vnamelist.cpp index 5c89c9262..464d32132 100644 --- a/test/klib/test-vnamelist.cpp +++ b/test/klib/test-vnamelist.cpp @@ -26,9 +26,9 @@ #include #include // TEST_CASE -#include -#include -#include +#include +#include +#include #include #include @@ -63,7 +63,7 @@ static rc_t CC on_part( const String * part, void * data ) noexcept struct on_part_ctx * ctx = ( struct on_part_ctx * ) data; std::string p = std::string( part->addr, part->size ); std::string c = std::string( ctx->v[ ctx->idx ] ); - if ( p != c ) rc = -1; + if ( p != c ) rc = (rc_t) - 1; ctx->idx++; return rc; } @@ -75,10 +75,10 @@ rc_t test_String( const char * to_test, const char ** v, int count ) struct on_part_ctx ctx; ctx.v = v; ctx.idx = 0; - + StringInitCString( &s, to_test ); rc_t rc = foreach_String_part( &s, ':', on_part, &ctx ); - if ( rc == 0 && ctx.idx != count ) rc = -1; + if ( rc == 0 && ctx.idx != count ) rc = (rc_t)-1; return rc; } @@ -88,9 +88,9 @@ rc_t test_pchar( const char * to_test, const char ** v, int count ) struct on_part_ctx ctx; ctx.v = v; ctx.idx = 0; - + rc_t rc = foreach_Str_part( to_test, ':', on_part, &ctx ); - if ( rc == 0 && ctx.idx != count ) rc = -1; + if ( rc == 0 && ctx.idx != count ) rc = (rc_t)-1; return rc; } @@ -117,7 +117,7 @@ static const int n5 = 4; TEST_CASE( StringSplit ) { std::cout << "testing String-splitting by callback" << std::endl; - + rc_t rc = test_String( s1, t1, n1 ); if ( rc != 0 ) FAIL( "FAIL: foreach_String_part( #1 ) failed" ); @@ -182,14 +182,14 @@ rc_t check_list( const VNamelist * list, const char ** v, uint32_t count ) std::string s_item = std::string( item ); std::string s_cmp = std::string( v[ idx ] ); if ( s_item.compare( s_cmp ) != 0 ) - rc = -1; + rc = (rc_t)-1; } if ( rc == 0 ) { uint32_t lc; rc = VNameListCount ( list, &lc ); if ( rc == 0 && lc != count ) - rc = -1; + rc = (rc_t)-1; } } return rc; @@ -221,7 +221,7 @@ rc_t test_split_string( const char * to_test, const char ** v, uint32_t count ) TEST_CASE( SplitIntoVNamelist ) { std::cout << "testing String-splitting into existing VNamelist " << std::endl; - + rc_t rc = test_split_string( s1, t1, n1 ); if ( rc != 0 ) FAIL( "FAIL: test_split_string( #1 )" ); @@ -241,7 +241,7 @@ TEST_CASE( SplitIntoVNamelist ) rc = test_split_string( s5, t5, n5 ); if ( rc != 0 ) FAIL( "FAIL: test_split_string( #5 )" ); - + } @@ -257,7 +257,7 @@ rc_t test_make_from_string( const char * to_test, const char ** v, uint32_t coun rc = check_list( list, v, count ); VNamelistRelease ( list ); } - + if ( rc == 0 ) { rc = VNamelistFromStr( &list, to_test, ':' ); @@ -274,7 +274,7 @@ rc_t test_make_from_string( const char * to_test, const char ** v, uint32_t coun TEST_CASE( MakeVNamelistFromString ) { std::cout << "testing String-splitting into new VNamelist " << std::endl; - + rc_t rc = test_make_from_string( s1, t1, n1 ); if ( rc != 0 ) FAIL( "FAIL: test_make_from_string( #1 )" ); @@ -311,7 +311,7 @@ rc_t split_join_and_check( const char * to_test ) String S2; StringInitCString( &S2, to_test ); if ( !StringEqual( joined, &S2 ) ) - rc = -1; + rc = (rc_t)-1; StringWhack ( joined ); } VNamelistRelease ( list ); @@ -345,20 +345,7 @@ TEST_CASE( VNamelistJoining ) } //////////////////////////////////////////// Main -extern "C" +int main( int argc, char *argv [] ) { - -#include - -ver_t CC KAppVersion ( void ) { return 0x1000000; } -rc_t CC UsageSummary ( const char * progname ) { return 0; } -rc_t CC Usage ( const Args * args ) { return 0; } -const char UsageDefaultName[] = "test-VDB-3060"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc = T_VNamelist( argc, argv ); - return rc; -} - + return T_VNamelist( argc, argv ); } diff --git a/test/kns/CMakeLists.txt b/test/kns/CMakeLists.txt index a1aa2f59b..13289faac 100644 --- a/test/kns/CMakeLists.txt +++ b/test/kns/CMakeLists.txt @@ -24,39 +24,41 @@ add_compile_definitions( __mod__="test/kns" ) -AddExecutableTest( Test_KNS_allow_all_certificates "test_allow_all_certificates" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_dis_allow_all_certificates "test_dis_allow_all_certificates" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_google-proxy "test-google-proxy" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_test200for-whole-file "test200for-whole-file" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_dflt "knstest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( SlowTest_KNS_ipc "test-ipc" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_opt-bitmap "test-opt-bitmap" "${COMMON_LIBS_READ}" ) -AddExecutableTest( SlowTest_KNS_http "HttpFixture;httptest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_http-dropconn "http_dropconnection_test" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_http_request "HttpFixture;test-http-request" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_KNSManagerSingletonTest "KNSManagerSingletonTest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_connect "HttpFixture;test-connect" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_refresh-expired "HttpFixture;KStableHttpFile;test-refresh-expired-url" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_timeouts "test-timeouts" "${COMMON_LIBS_READ}" ) - -# TODO the following binaries are not unit tests (EXT_TOOLS), they should be started not as ctest - -BuildExecutableForTest( test-kns-mutual-authentication "test-mutual-authentication;gosha" "${COMMON_LIBS_READ}" ) -# add_test( NAME Test_KNS_mutual-authentication COMMAND test-kns-mutual-authentication WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) +set( LIBS "${COMMON_LIBS_READ}") -BuildExecutableForTest( test-kns-proxy-with-env "test-proxy-with-env" "${COMMON_LIBS_READ}" ) -# add_test( NAME Test_KNS_proxy-with-env COMMAND test-kns-proxy-with-env WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) +AddExecutableTest( Test_KNS_allow_all_certificates "test_allow_all_certificates" "${LIBS}" ) +AddExecutableTest( Test_KNS_dis_allow_all_certificates "test_dis_allow_all_certificates" "${LIBS}" ) +AddExecutableTest( Test_KNS_google-proxy "test-google-proxy" "${LIBS}" ) +AddExecutableTest( Test_KNS_test200for-whole-file "test200for-whole-file" "${LIBS}" ) +AddExecutableTest( Test_KNS_dflt "knstest" "${COMMON_LIBS_READ}" ) +AddExecutableTest( SlowTest_KNS_ipc "test-ipc" "${LIBS}" ) +AddExecutableTest( Test_KNS_opt-bitmap "test-opt-bitmap" "${LIBS}" ) +AddExecutableTest( SlowTest_KNS_http "HttpFixture;httptest" "${LIBS}" ) +AddExecutableTest( Test_KNS_http-dropconn "http_dropconnection_test" "${LIBS}" ) +AddExecutableTest( Test_KNS_http_request "HttpFixture;test-http-request" "${LIBS}" ) +AddExecutableTest( Test_KNS_KNSManagerSingletonTest "KNSManagerSingletonTest" "${LIBS}" ) +AddExecutableTest( Test_KNS_connect "HttpFixture;test-connect" "${LIBS}" ) +AddExecutableTest( Test_KNS_refresh-expired "HttpFixture;KStableHttpFile;test-refresh-expired-url" "${LIBS}" ) +AddExecutableTest( Test_KNS_timeouts "test-timeouts" "${LIBS}" ) if( SINGLE_CONFIG ) - BuildExecutableForTest( Test_KNS_proxy "test-proxy" "${COMMON_LIBS_READ}" ) + BuildExecutableForTest( Test_KNS_proxy "test-proxy" "${LIBS}" ) add_test( NAME Test_KNS_proxy COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test-proxy.sh ${CMAKE_TEST_OUTPUT_DIRECTORY}/Test_KNS_proxy WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) - BuildExecutableForTest( Test_KNS_proxy-with-scheme_dflt "test-proxy-with-scheme" "${COMMON_LIBS_READ}" ) + BuildExecutableForTest( Test_KNS_proxy-with-scheme_dflt "test-proxy-with-scheme" "${LIBS}" ) add_test( NAME Test_KNS_proxy-with-scheme_dflt COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test-proxy-with-scheme.sh ${CMAKE_TEST_OUTPUT_DIRECTORY}/Test_KNS_proxy-with-scheme_dflt WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) #set_tests_properties(Test_KNS_proxy-with-scheme PROPERTIES ENVIRONMENT http_proxy=) endif() -AddExecutableTest( Test_KNS_proxy-with-scheme_failure "test-proxy-with-scheme_failure" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KNS_aws-proxy "test-aws-proxy" "${COMMON_LIBS_READ}" ) +AddExecutableTest( Test_KNS_proxy-with-scheme_failure "test-proxy-with-scheme_failure" "${LIBS}" ) +AddExecutableTest( Test_KNS_aws-proxy "test-aws-proxy" "${LIBS}" ) + +# TODO the following binaries are not unit tests (EXT_TOOLS), they should not be started via ctest + +BuildExecutableForTest( test-kns-mutual-authentication "test-mutual-authentication;gosha" "${LIBS}" ) +# add_test( NAME Test_KNS_mutual-authentication COMMAND test-kns-mutual-authentication WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + +BuildExecutableForTest( test-kns-proxy-with-env "test-proxy-with-env" "${LIBS}" ) +# add_test( NAME Test_KNS_proxy-with-env COMMAND test-kns-proxy-with-env WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/test/kns/KNSManagerSingletonTest.cpp b/test/kns/KNSManagerSingletonTest.cpp index 875cb0b8a..e849a4a6c 100644 --- a/test/kns/KNSManagerSingletonTest.cpp +++ b/test/kns/KNSManagerSingletonTest.cpp @@ -41,15 +41,15 @@ TEST_CASE(VDB_2877) { KNSManager *mgr = NULL; KNSManager *mgr2 = NULL; - REQUIRE_EQ(mgr, mgr2); + REQUIRE_EQ(mgr, mgr2); - REQUIRE_RC(KNSManagerMake(&mgr)); - REQUIRE(mgr); - REQUIRE_NE(mgr, mgr2); + REQUIRE_RC(KNSManagerMake(&mgr)); + REQUIRE(mgr); + REQUIRE_NE(mgr, mgr2); VFSManager *vmgr = NULL; REQUIRE_RC(VFSManagerMake(&vmgr)); - REQUIRE(vmgr); + REQUIRE(vmgr); REQUIRE_RC(VFSManagerGetKNSMgr(vmgr, &mgr2)); @@ -64,13 +64,12 @@ TEST_CASE(VDB_2877) { RELEASE(VFSManager, vmgr); RELEASE(KNSManager, mgr); - REQUIRE_EQ(mgr, mgr2); + REQUIRE_EQ(mgr, mgr2); REQUIRE(!rc); } -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char *argv [] ) - { return KNSManagerSingletonTestSuite(argc, argv); } +int main( int argc, char *argv [] ) +{ + return KNSManagerSingletonTestSuite(argc, argv); } diff --git a/test/kns/TestProxy.hpp b/test/kns/TestProxy.hpp index 4bfaf8f1a..8caa765b4 100644 --- a/test/kns/TestProxy.hpp +++ b/test/kns/TestProxy.hpp @@ -133,7 +133,7 @@ class CKConfig { } while ( c ) { - rc_t rc = KConfigWriteString + rc = KConfigWriteString ( _self, c -> path . c_str (), c -> value . c_str () ); if ( rc != 0 ) { throw rc; @@ -227,7 +227,7 @@ class TestProxy : private ncbi::NK::TestCase { ( mgr, & aHost, aPort, & cnt ); REQUIRE ( i ); const String * hostname = NULL; - uint16_t port = ~ 0; + uint16_t port = (uint16_t)~0; bool proxy_default_port = true; bool proxy_ep = false; E * first = e; @@ -238,7 +238,7 @@ class TestProxy : private ncbi::NK::TestCase { E * prev = first; String host; StringInit ( & host, - e -> path. c_str (), e -> path. size (), e -> path. size () ); + e -> path. c_str (), e -> path. size (), (uint32_t)e -> path. size () ); REQUIRE ( KEndPointArgsIterator_Next ( i, & hostname, & port, & proxy_default_port, & proxy_ep, & crnt_proxy_idx, & last_proxy ) ); @@ -252,7 +252,7 @@ class TestProxy : private ncbi::NK::TestCase { break; } StringInit ( & host, e -> path. c_str (), - e -> path. size (), e -> path. size () ); + e -> path. size (), (uint32_t)e -> path. size () ); } if ( e == NULL ) REQUIRE_EQ ( std::string ( hostname -> addr ), @@ -265,7 +265,7 @@ class TestProxy : private ncbi::NK::TestCase { REQUIRE_EQ ( static_cast < int> ( port ), 3128 ); REQUIRE ( proxy_default_port ); - uint16_t port3 = ~ 0; + uint16_t port3 = (uint16_t)~ 0; REQUIRE ( KEndPointArgsIterator_Next ( i, & hostname, & port3, & proxy_default_port, & proxy_ep, & crnt_proxy_idx, & last_proxy ) ); @@ -297,7 +297,7 @@ class TestProxy : private ncbi::NK::TestCase { e = prev = first; if ( e ) StringInit ( & host, e -> path. c_str (), - e -> path. size (), e -> path. size () ); + e -> path. size (), (uint32_t)e -> path. size () ); if ( firstI ) { size_t cnt2 = 0; struct KEndPointArgsIterator * i2 = @@ -305,7 +305,7 @@ class TestProxy : private ncbi::NK::TestCase { & aHost, aPort, & cnt2 ); REQUIRE_EQ ( cnt , cnt2 ); const String * hostname2 = NULL; - uint16_t port2 = ~ 0; + uint16_t port2 = (uint16_t)~ 0; bool proxy_default_port2 = true; bool proxy_ep2 = false; REQUIRE ( KEndPointArgsIterator_Next ( i2, & hostname2, & port2, @@ -332,7 +332,7 @@ class TestProxy : private ncbi::NK::TestCase { break; } StringInit ( & host, e -> path. c_str (), - e -> path. size (), e -> path. size () ); + e -> path. size (), (uint32_t)e -> path. size () ); } if ( e == NULL ) REQUIRE_EQ ( std::string ( hostname2 -> addr ), diff --git a/test/kns/http-test.c b/test/kns/http-test.c index b7c3747b3..a56677078 100644 --- a/test/kns/http-test.c +++ b/test/kns/http-test.c @@ -369,64 +369,6 @@ rc_t PreHttpsTest ( void ) return rc; } -/* Version EXTERN - * return 4-part version code: 0xMMmmrrrr, where - * MM = major release - * mm = minor release - * rrrr = bug-fix release - */ -ver_t CC KAppVersion ( void ) -{ - return 0; -} - - -/* Usage - * This function is called when the command line argument - * handling sees -? -h or --help - */ -rc_t CC UsageSummary ( const char *progname ) -{ - /* return KOutMsg ( - "\n" - "Usage:\n" - " %s [Options]\n" - "\n" - "Summary:\n" - " Simple test of printf.\n" - , progname ); - */ - return 0; -} - -const char UsageDefaultName[] = "time-test"; - -rc_t CC Usage ( const Args *args ) -{ - /* - const char * progname = UsageDefaultName; - const char * fullpath = UsageDefaultName; - rc_t rc; - - if (args == NULL) - rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull); - else - rc = ArgsProgram (args, &fullpath, &progname); - - UsageSummary (progname); - - KOutMsg ("Options:\n"); - - HelpOptionsStandard(); - - HelpVersion (fullpath, KAppVersion()); - - return rc; - */ - return 0; -} - - static rc_t run ( const char *progname ) { @@ -439,9 +381,7 @@ rc_t run ( const char *progname ) return 1; } -/* KMain - */ -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args *args; rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0 ); @@ -452,6 +392,6 @@ rc_t CC KMain ( int argc, char *argv [] ) ArgsWhack ( args ); } - return rc; + return (int)rc; } diff --git a/test/kns/http_dropconnection_test.cpp b/test/kns/http_dropconnection_test.cpp index a0093818d..9232e877d 100644 --- a/test/kns/http_dropconnection_test.cpp +++ b/test/kns/http_dropconnection_test.cpp @@ -35,6 +35,8 @@ #include #include +#include + #include #include @@ -432,29 +434,7 @@ FIXTURE_TEST_CASE(GET_Read_Failed_Reconnect_Failed, HttpFixture) #endif //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-http-dropconn"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); @@ -462,8 +442,5 @@ rc_t CC KMain ( int argc, char *argv [] ) // (same as running the executable with "-l=message") // TestEnv::verbosity = LogLevel::e_message; - rc_t rc=HttpTestSuite(argc, argv); - return rc; -} - + return HttpTestSuite(argc, argv); } diff --git a/test/kns/httptest.cpp b/test/kns/httptest.cpp index dd1d18e82..aee305a6d 100644 --- a/test/kns/httptest.cpp +++ b/test/kns/httptest.cpp @@ -33,6 +33,7 @@ #include /* KSleep */ #include +#include #include #include @@ -187,7 +188,7 @@ struct ReadThreadData #ifdef ALL static rc_t CC read_thread_func( const KThread *self, void *data ) noexcept { - rc_t rc; + rc_t rc = 0; ReadThreadData * td = ( ReadThreadData * ) data; char buf[1024]; size_t num_read; @@ -195,7 +196,7 @@ static rc_t CC read_thread_func( const KThread *self, void *data ) noexcept for ( int i = 0; i < td->num_requests; ++i ) { - rc = KFileTimedRead ( td->kHttpFile, 0, buf, td->content_length, &num_read, NULL ); + rc = KFileTimedRead ( td->kHttpFile, 0, buf, (size_t) td->content_length, &num_read, NULL ); if ( rc != 0 || num_read == 0 ) { LOG(LogLevel::e_fatal_error, "read_thread_func: KFileTimedRead failed on kHttpFile\n"); @@ -444,7 +445,7 @@ class RetrierFixture : public HttpFixture throw logic_error ( "RetrierFixture::Configure KNSManagerMakeConfig failed" ); m_mgr -> maxNumberOfRetriesOnFailureForReliableURLs = max_retries; - m_mgr -> maxTotalWaitForReliableURLs_ms = max_total_wait; + m_mgr -> maxTotalWaitForReliableURLs_ms = (int32_t) max_total_wait; if ( KHttpRetrierInit ( & m_retrier, kfg_name, m_mgr ) != 0 ) throw logic_error ( "RetrierFixture::Configure KHttpRetrierInit failed" ); @@ -879,6 +880,7 @@ FIXTURE_TEST_CASE( KClientHttpResult_FormatMsg, HttpFixture) REQUIRE_RC ( KClientHttpResultFormatMsg ( rslt, & buffer, "->", "\n" ) ); REQUIRE_EQ ( expected, string ((char*)buffer.base) ); REQUIRE_RC ( KClientHttpResultRelease ( rslt ) ); + KDataBufferWhack( & buffer ); } #endif @@ -1037,29 +1039,7 @@ static rc_t argsHandler ( int argc, char * argv [] ) { return rc; } -extern "C" -{ - -#include -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-http"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { // make sure to use singleton, otherwise tests take forever and finally fail CloudMgrUseSingleton(true); @@ -1073,8 +1053,5 @@ rc_t CC KMain ( int argc, char *argv [] ) // (same as running the executable with "-l=message") // TestEnv::verbosity = LogLevel::e_message; - rc_t rc=HttpTestSuite(argc, argv); - return rc; -} - + return HttpTestSuite(argc, argv); } diff --git a/test/kns/knstest.cpp b/test/kns/knstest.cpp index 1caac1e34..71060c7ce 100644 --- a/test/kns/knstest.cpp +++ b/test/kns/knstest.cpp @@ -31,6 +31,7 @@ #include #include /* ArgsMakeAndHandle */ +#include #include #include @@ -39,6 +40,7 @@ #include #include +#include #include @@ -78,6 +80,7 @@ class SessionIdFixture : public KNSManagerFixture { const char * ua = nullptr; KNSManagerGetUserAgent( & ua ); +//cout << ua << endl; return string::npos != string( ua ) . find( str ); } @@ -100,12 +103,17 @@ FIXTURE_TEST_CASE(KNSManagerGetUserAgent_Null, SessionIdFixture) REQUIRE_RC_FAIL(KNSManagerGetUserAgent(nullptr)); } +static std::string get_baseName(std::string const &argv0) { + auto const sep_l = argv0.find_last_of("\\/"); + return sep_l == argv0.npos ? argv0 : argv0.substr(sep_l + 1); +} + FIXTURE_TEST_CASE(KNSManagerGetUserAgent_Default, SessionIdFixture) { const char * ua = nullptr; KNSManagerGetUserAgent(&ua); - const string ua_contains = "sra-toolkit Test_KNS_dflt.1.0.0 (phid=noc"; - //fprintf(stderr,"Got: '%s', expected '%s'\n", ua, ua_contains.data()); + auto const ua_contains = std::string{"sra-toolkit "} + get_baseName(GetTestSuite()->argv[0]) + std::string{".0.0.12 (phid=noc"}; + // fprintf(stderr,"Got: '%s', expected '%s'\n", ua, ua_contains.data()); REQUIRE_NE( string::npos, string(ua).find(ua_contains) ); // VDB-4896: no double quotes inside UA REQUIRE_EQ( string::npos, string(ua).find("\"") ); @@ -174,14 +182,18 @@ FIXTURE_TEST_CASE(KNSManagerSetUserAgentSuffix_Get, SessionIdFixture) REQUIRE_RC(KNSManagerGetUserAgentSuffix( & s )); REQUIRE_EQ( suffix, string( s ) ); REQUIRE( UserAgent_Contains( - "sra-toolkit Test_KNS_dflt.1.0.0suffix (phid=noc" ) ); + string{"sra-toolkit "} + + get_baseName(GetTestSuite()->argv[0]) + + string{".0.0.12suffix (phid=noc"} ) ); } FIXTURE_TEST_CASE(KNSManagerSetUserAgentSuffix_Restore, SessionIdFixture) { REQUIRE_RC(KNSManagerSetUserAgentSuffix("suffix1")); REQUIRE( UserAgent_Contains( - "sra-toolkit Test_KNS_dflt.1.0.0suffix1 (phid=noc" ) ); + string{"sra-toolkit "} + + get_baseName(GetTestSuite()->argv[0]) + + string{".0.0.12suffix1 (phid=noc"} ) ); REQUIRE_RC(KNSManagerSetUserAgentSuffix("")); const char * ua = nullptr; @@ -261,43 +273,27 @@ FIXTURE_TEST_CASE(KNSManagerSet_SessionAll, SessionIdFixture) // thread locality of session Ids FIXTURE_TEST_CASE(KNSManagerSet_ThreadLocal, SessionIdFixture) { - string s1, s2; + string s1; std::thread t1 ([&] { REQUIRE_RC(KNSManagerSetClientIP(m_mgr, "1.2.3.4")); REQUIRE_RC(KNSManagerSetSessionID(m_mgr, "sessId1")); REQUIRE_RC(KNSManagerSetPageHitID(m_mgr, "pageHitId2")); REQUIRE_RC(KNSManagerSetUserAgentSuffix("suffix1")); - std::this_thread::sleep_for (std::chrono::milliseconds(100)); - const char * ua = nullptr; - KNSManagerGetUserAgent(&ua); - s1 = ua; - }); - std::thread t2 ([&] - { - REQUIRE_RC(KNSManagerSetClientIP(m_mgr, "11.22.33.44")); - REQUIRE_RC(KNSManagerSetSessionID(m_mgr, "sessId2")); - REQUIRE_RC(KNSManagerSetPageHitID(m_mgr, "pageHitId2")); - REQUIRE_RC(KNSManagerSetUserAgentSuffix("suffix2")); std::this_thread::sleep_for (std::chrono::milliseconds(100)); const char * ua = nullptr; KNSManagerGetUserAgent(&ua); - s2 = ua; + s1 = ua; }); t1.join(); - t2.join(); REQUIRE(string::npos != s1.find(string(",") + enc64("cip=1.2.3.4,sid=sessId1,pagehit=pageHitId2"))); REQUIRE(string::npos != s1.find("suffix1")); - REQUIRE(string::npos != s2.find(string(",") - + enc64("cip=11.22.33.44,sid=sessId2,pagehit=pageHitId2"))); - REQUIRE(string::npos != s2.find("suffix2")); - - // the above threads did not change the main thread's session Ids + // the above thread did not change the main thread's session Ids const char * ua = nullptr; KNSManagerGetUserAgent(&ua); REQUIRE_EQ( original_ua, string(ua) ); @@ -335,26 +331,24 @@ static rc_t argsHandler(int argc, char * argv[]) { return rc; } -extern "C" +static void checkForSanitizers(char *argv0) { + auto const len = strlen(argv0); + if (len <= 5) return; -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; + auto const suffix = std::string{argv0 + len - 5}; + if (suffix == "_asan" || suffix == "_tsan") + argv0[len - 5] = '\0'; } -rc_t CC Usage ( const Args * args ) +int main(int argc, char* argv[]) { - return 0; -} -const char UsageDefaultName[] = "Test_KNS.1"; + VDB::Application app( argc, argv, 12 ); // we need custom version for some tests + if (!app) + { + return 1; + } -rc_t CC KMain ( int argc, char *argv [] ) -{ // make sure to use singleton, otherwise some tests fail KNSManagerUseSingleton(true); @@ -362,7 +356,5 @@ rc_t CC KMain ( int argc, char *argv [] ) KConfigDisableUserSettings(); - return KnsTestSuite(argc, argv); -} - + return KnsTestSuite(argc, app.getArgV()); } diff --git a/test/kns/test-aws-proxy.cpp b/test/kns/test-aws-proxy.cpp index b71562dcf..0c8d56504 100644 --- a/test/kns/test-aws-proxy.cpp +++ b/test/kns/test-aws-proxy.cpp @@ -94,16 +94,9 @@ TEST_CASE ( AwsProxyTest ) { REQUIRE_RC ( KNSManagerRelease ( mgr ) ); } -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - const char UsageDefaultName[] = "test-aws-proxy"; - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage(const struct Args * args) { return 0; } - - rc_t CC KMain ( int argc, char * argv [] ) { - if ( +int main( int argc, char * argv [] ) { + if ( 0 ) assert ( ! KDbgSetString ( "KNS" ) ); - KConfigDisableUserSettings (); - return AwsProxyTestSuite(argc, argv); - } + KConfigDisableUserSettings (); + return AwsProxyTestSuite(argc, argv); } diff --git a/test/kns/test-connect.cpp b/test/kns/test-connect.cpp index 94eeb9ece..dc8ae2098 100644 --- a/test/kns/test-connect.cpp +++ b/test/kns/test-connect.cpp @@ -30,10 +30,13 @@ #include +#include + #include #include #include +#include #include #include #include @@ -104,7 +107,7 @@ FIXTURE_TEST_CASE(Connect_OK, ConnectFixture) LogLevel::E l(LogLevel::e_error); l = LogLevel::e_warning; - for (auto i = 0; i < sizeof hh / sizeof hh[0]; ++i) { + for (auto i = 0; i < (int) ( sizeof hh / sizeof hh[0] ); ++i) { string& h(hh[i]); return_val = 1; /* epoll_wait: success */ LOG(l, "Trying " << h << "...\n"); @@ -188,30 +191,7 @@ static rc_t argsHandler(int argc, char * argv[]) { return rc; } -extern "C" -{ - -#include -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-connect"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); @@ -220,8 +200,5 @@ rc_t CC KMain ( int argc, char *argv [] ) KDbgSetModConds ( DBG_KNS, DBG_FLAG ( DBG_KNS_SOCKET ), DBG_FLAG ( DBG_KNS_SOCKET ) ); #endif - rc_t rc=KnsTestSuite(argc, argv); - return rc; -} - + return KnsTestSuite(argc, argv); } diff --git a/test/kns/test-google-proxy.cpp b/test/kns/test-google-proxy.cpp index fdacd4478..2898da816 100644 --- a/test/kns/test-google-proxy.cpp +++ b/test/kns/test-google-proxy.cpp @@ -27,6 +27,8 @@ #include /* KFileRelease */ #include /* KConfigMakeEmpty */ +#include // Args + #include /* KDbgSetString */ #include /* KNSManagerInitDNSEndpoint */ @@ -105,7 +107,7 @@ TEST_CASE ( GoogleProxyTest ) { if (http_proxy != NULL) { REQUIRE_RC ( KNSManagerMakeHttpFile ( mgr, & file, NULL, 0x01010000, - "https://www.nlm.nih.gov/" ) ); + "https://usa.gov/" ) ); char buffer [ 256 ] = ""; size_t num_read = 0; @@ -167,7 +169,6 @@ TEST_CASE ( KClientHttpRequestPOSTTest ) REQUIRE_RC ( KNSManagerRelease ( mgr ) ); } -#include // Args static rc_t argsHandler(int argc, char * argv[]) { Args * args = NULL; rc_t rc = ArgsMakeAndHandle(&args, argc, argv, 0, NULL, 0); @@ -175,32 +176,25 @@ static rc_t argsHandler(int argc, char * argv[]) { return rc; } -extern "C" { - const char UsageDefaultName[] = "test-google-proxy"; - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage(const struct Args * args) { return 0; } - - ver_t CC KAppVersion ( void ) { return 0; } - - rc_t CC KMain ( int argc, char * argv [] ) { if ( -0 ) assert ( ! KDbgSetString ( "KNS-DNS" ) ); if ( -0 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); if ( -0 ) assert ( ! KDbgSetString ( "KNS-PROXY" ) ); if ( -0 ) ncbi::NK::TestEnv::verbosity = ncbi::NK::LogLevel::E::e_all; +int main ( int argc, char * argv [] ) { + if ( 0 ) assert ( ! KDbgSetString ( "KNS-DNS" ) ); + if ( 0 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); + if ( 0 ) assert ( ! KDbgSetString ( "KNS-PROXY" ) ); + if ( 0 ) ncbi::NK::TestEnv::verbosity = ncbi::NK::LogLevel::E::e_all; #if _DEBUGGING - if ( 0 ) KStsLevelSet ( 5 ); + if ( 0 ) KStsLevelSet ( 5 ); #endif - rc_t rc = KConfigMakeEmpty ( & KFG ); + rc_t rc = KConfigMakeEmpty ( & KFG ); - if ( rc == 0 ) - rc = GoogleProxyTestSuite(argc, argv); + if ( rc == 0 ) + rc = (rc_t)GoogleProxyTestSuite(argc, argv); - rc_t r = KConfigRelease ( KFG ); - if ( r != 0 && rc == 0 ) - rc = r; + rc_t r = KConfigRelease ( KFG ); + if ( r != 0 && rc == 0 ) + rc = r; - return rc; - } + return (int)rc; } + diff --git a/test/kns/test-http-request.cpp b/test/kns/test-http-request.cpp index 4910abc4b..3d99f0c04 100644 --- a/test/kns/test-http-request.cpp +++ b/test/kns/test-http-request.cpp @@ -32,6 +32,9 @@ #include #include // string_printf #include // VDB_RELEASE_VERSION +#include + +#include #include #include @@ -559,29 +562,7 @@ static rc_t argsHandler ( int argc, char * argv [] ) { return rc; } -extern "C" -{ - -#include -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-http"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfig * kfg = NULL; rc_t rc = KConfigMake(&kfg, NULL); @@ -599,13 +580,11 @@ rc_t CC KMain ( int argc, char *argv [] ) // TestEnv::verbosity = LogLevel::e_message; if (rc == 0) - rc = HttpRequestVerifyURLSuite(argc, argv); + rc = (rc_t)HttpRequestVerifyURLSuite(argc, argv); rc_t r2 = KConfigRelease(kfg); if (rc == 0 && r2 != 0) rc = r2; - return rc; -} - + return (int)rc; } diff --git a/test/kns/test-ipc.cpp b/test/kns/test-ipc.cpp index 29e25a201..f8413b78c 100644 --- a/test/kns/test-ipc.cpp +++ b/test/kns/test-ipc.cpp @@ -32,6 +32,9 @@ #include #include +#include + +#include #include #include @@ -47,6 +50,8 @@ #include #include +#include +#include static rc_t argsHandler(int argc, char* argv[]); TEST_SUITE_WITH_ARGS_HANDLER(KnsIpcTestSuite, argsHandler); @@ -216,13 +221,18 @@ class SocketFixture : public EndpointFixture KThreadCancel(server); KThreadWait(server, nullptr); KThreadRelease(server); - KThreadRelease(server);/* for some reason KThread is initialized with refcout = 2 */ + KThreadRelease(server);/* for some reason this KThread is initialized with refcount = 2 */ if (listener) { /* shutdown the (possibly blocked) listener */ LOG(LogLevel::e_message, "server releasing the listener" << endl); KListenerRelease(listener); } + + for( auto t = workers.begin(); t != workers.end(); ++t ) + { + KThreadRelease( *t ); + } } } else @@ -267,9 +277,10 @@ class SocketFixture : public EndpointFixture THROW_ON_RC ( KSocketRelease ( socket ) ); LOG(LogLevel::e_message, "server detected connection, starting worker" << endl); - KThread* worker; - if (KThreadMake ( &worker, threadWorker == 0 ? DefaultWorkerThreadFn : threadWorker, stream) != 0 || worker == 0) + KThread * worker; + if (KThreadMake ( &worker, threadWorker.load() == 0 ? DefaultWorkerThreadFn : threadWorker.load(), stream) != 0 || worker == 0) throw logic_error ( "SocketFixture: KThreadMake failed" ); + workers.insert( worker); } } LOG(LogLevel::e_message, "server exiting" << endl); @@ -292,7 +303,7 @@ class SocketFixture : public EndpointFixture LOG(LogLevel::e_message, "worker " << (void*)self << " after KStreamRead(" << string(localBuf, num) << ")" << endl); for (size_t i = 0 ; i < num; ++i) - localBuf[i] = toupper(localBuf[i]); + localBuf[i] = (char)toupper(localBuf[i]); THROW_ON_RC ( KStreamWrite(stream, localBuf, num, &num) ); LOG(LogLevel::e_message, "worker " << (void*)self << " after KStreamWrite" << endl); @@ -316,7 +327,7 @@ class SocketFixture : public EndpointFixture throw; } LOG(LogLevel::e_message, "worker " << (void*)self << " exiting" << endl); - return KThreadRelease(self); + return 0; } void CloseClientStream(KStream* p_stream) @@ -325,8 +336,8 @@ class SocketFixture : public EndpointFixture { // signal to server to shut down the connection string done("done"); - size_t num; - THROW_ON_RC ( KStreamTimedWrite(p_stream, done.c_str(), done.length(), &num, nullptr) ); + size_t nm; + THROW_ON_RC ( KStreamTimedWrite(p_stream, done.c_str(), done.length(), &nm, nullptr) ); THROW_ON_RC ( KStreamRelease(p_stream) ); } } @@ -334,7 +345,7 @@ class SocketFixture : public EndpointFixture KStream* MakeStream( int32_t p_retryTimeout ) { timeout_t tm; - TimeoutInit ( & tm, p_retryTimeout ); + TimeoutInit ( & tm, (uint32_t)p_retryTimeout ); KSocket* socket; THROW_ON_RC ( KNSManagerMakeRetryConnection(m_mgr, &socket, &tm, nullptr, &ep) ); @@ -356,7 +367,8 @@ class SocketFixture : public EndpointFixture KListener* listener; // may be set by subclasses - WorkerThreadFn threadWorker; + atomic threadWorker; + set workers; // make thread safe? // for use in test cases size_t num; @@ -414,6 +426,7 @@ PROCESS_FIXTURE_TEST_CASE(IPCEndpoint_MultipleListeners, SocketFixture, 0, 100) CloseClientStream(stream2); } + PROCESS_FIXTURE_TEST_CASE(IPCEndpoint_ReadAll, SocketFixture, 0, 5) { // call ReadAll requesting more bytes than available, see it return only what is available string content = GetName(); @@ -491,7 +504,7 @@ class TimedReadSocketFixture : public SocketFixture LOG(LogLevel::e_message, "worker " << (void*)self << " after KStreamRead(" << string(localBuf, localNumRead) << ")" << endl); for (size_t i = 0 ; i < localNumRead; ++i) - localBuf[i] = toupper(localBuf[i]); + localBuf[i] = (char)toupper(localBuf[i]); // send outgoing message after a pause for SERVER_WRITE_DELAY_MS LOG(LogLevel::e_message, "worker " << (void*)self << " sleeping for " << SERVER_WRITE_DELAY_MS << " ms" << endl); @@ -521,7 +534,7 @@ class TimedReadSocketFixture : public SocketFixture throw; } LOG(LogLevel::e_message, "worker " << (void*)self << " exiting" << endl); - return KThreadRelease(self); + return 0; } // for use in test cases @@ -617,11 +630,11 @@ class TimedConnection_ReadSocketFixture : public TimedReadSocketFixture KStream* MakeStreamTimed( int32_t p_retryTimeout, int32_t p_readMillis, int32_t p_writeMillis ) { - timeout_t tm; - TimeoutInit ( & tm, p_retryTimeout ); + timeout_t t; + TimeoutInit ( & t, (uint32_t)p_retryTimeout ); KSocket* socket; - THROW_ON_RC ( KNSManagerMakeRetryTimedConnection(m_mgr, &socket, &tm, p_readMillis, p_writeMillis, nullptr, &ep) ); + THROW_ON_RC ( KNSManagerMakeRetryTimedConnection(m_mgr, &socket, &t, p_readMillis, p_writeMillis, nullptr, &ep) ); if (socket == 0) throw logic_error ( "MakeStreamTimed: KStreamRelease failed" ); @@ -650,6 +663,7 @@ PROCESS_FIXTURE_TEST_CASE(TimedConnection_Read_NULL_Timeout, TimedConnection_Rea TeardownClient(); } + PROCESS_FIXTURE_TEST_CASE(TimedConnection_TimedReadOverride_NULL_Timeout, TimedConnection_ReadSocketFixture, 0, 20) { // 2.1.1 wait indefinitely until the server responds string content = GetName(); @@ -685,6 +699,7 @@ PROCESS_FIXTURE_TEST_CASE(TimedConnection_Read_0_Timeout, TimedConnection_ReadSo TestEnv::SleepMs(SERVER_WRITE_DELAY_MS * 2); // let the server wake up to handle the 'done' message TeardownClient(); } + PROCESS_FIXTURE_TEST_CASE(TimedConnection_ReadOverride_0_Timeout, TimedConnection_ReadSocketFixture, 0, 20) { // 2.2.1 time out immediately when the server has not yet responded string content = GetName(); @@ -704,6 +719,7 @@ PROCESS_FIXTURE_TEST_CASE(TimedConnection_ReadOverride_0_Timeout, TimedConnectio TestEnv::SleepMs(SERVER_WRITE_DELAY_MS * 2); // let the server wake up to handle the 'done' message TeardownClient(); } + PROCESS_FIXTURE_TEST_CASE(TimedConnection_SettingsOverride_0_Timeout, TimedConnection_ReadSocketFixture, 0, 20) { // 2.2.2 time out immediately when the server has not yet responded REQUIRE_RC(KNSManagerSetConnectionTimeouts(m_mgr, 5000, 0, 0)); // override default setting (long time-out) to "no wait" @@ -741,6 +757,7 @@ PROCESS_FIXTURE_TEST_CASE(TimedConnection_Read_Short_Timeout, TimedConnection_Re TestEnv::SleepMs(SERVER_WRITE_DELAY_MS * 2); // let the server wake up to handle the 'done' message TeardownClient(); } + PROCESS_FIXTURE_TEST_CASE(TimedConnection_ReadOverride_Short_Timeout, TimedConnection_ReadSocketFixture, 0, 20) { // 2.3.1. time out when the server has not responded quickly enough string content = GetName(); @@ -775,6 +792,7 @@ PROCESS_FIXTURE_TEST_CASE(TimedConnection_Read_Long_Timeout, TimedConnection_Rea TeardownClient(); } + PROCESS_FIXTURE_TEST_CASE(TimedConnection_ReadOverride_Long_Timeout, TimedConnection_ReadSocketFixture, 0, 20) { // 2.4.1. wait enough time for the server to respond string content = GetName(); @@ -845,7 +863,7 @@ class TimedWriteSocketFixture : public SocketFixture char localBuf[MaxMessageSize]; size_t num; timeout_t tm; - tm.mS = p_timeoutMs; + tm.mS = (uint32_t)p_timeoutMs; THROW_ON_RC ( KStreamTimedRead(p_stream, localBuf, size == 0 ? sizeof(localBuf) : size, &num, p_timeoutMs == -1 ? nullptr : &tm) ); return string(localBuf, num); @@ -862,12 +880,12 @@ class TimedWriteSocketFixture : public SocketFixture { size_t num; timeout_t tm; - tm.mS = p_timeoutMs; + tm.mS = (uint32_t)p_timeoutMs; LOG(LogLevel::e_message, "WriteMessage, timeout=" << p_timeoutMs << "ms" << endl); return KStreamTimedWrite(p_stream, p_msg.c_str(), p_msg.size(), &num, p_timeoutMs == -1 ? nullptr : &tm); } - static volatile bool go; + static atomic go; static rc_t TimedWriteServerFn ( const KThread *self, void *data ) { // this function does not always exit, so using STL string in this function leads to occasional leaks. @@ -948,7 +966,7 @@ class TimedWriteSocketFixture : public SocketFixture throw; } LOG(LogLevel::e_message, (string(prefix) + " exiting\n")); - return KThreadRelease(self); + return 0; } // for use in test cases (=client code) @@ -957,21 +975,21 @@ class TimedWriteSocketFixture : public SocketFixture LOG(LogLevel::e_message, "flooding" << endl); char localBuf[MaxMessageSize]; memset(localBuf, 0xab, sizeof(localBuf)); // to keep valgrind happy - size_t num; + size_t nm; struct timeout_t tm; tm.mS = 0; /* do not wait */ while (true) { LOG(LogLevel::e_message, "writing " << MaxMessageSize << " bytes\n"); - rc_t rc = KStreamTimedWrite(m_data, localBuf, sizeof(localBuf), &num, &tm); + rc_t rc = KStreamTimedWrite(m_data, localBuf, sizeof(localBuf), &nm, &tm); if (rc != 0) { LOG(LogLevel::e_message, "KStreamWrite failed - flooding complete\n"); break; } - if (num != sizeof(localBuf)) + if (nm != sizeof(localBuf)) { - LOG(LogLevel::e_message, "written " << num << " bytes, expected " << sizeof(localBuf) << endl); + LOG(LogLevel::e_message, "written " << nm << " bytes, expected " << sizeof(localBuf) << endl); break; } } @@ -981,7 +999,7 @@ class TimedWriteSocketFixture : public SocketFixture KStream* m_control; }; -volatile bool TimedWriteSocketFixture::go = false; +atomic TimedWriteSocketFixture::go ( false ); // 1. flood the socket, see KStreamTimedWrite time out PROCESS_FIXTURE_TEST_CASE(TimedWrite_Short_Timeout, TimedWriteSocketFixture, 0, 20) @@ -1032,29 +1050,7 @@ static rc_t argsHandler(int argc, char * argv[]) { return rc; } -extern "C" -{ - -#include -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-kns"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); @@ -1073,8 +1069,5 @@ rc_t CC KMain ( int argc, char *argv [] ) KDirectoryCreateDir(dir, 0700, 0, "%s/.ncbi", getenv ( "HOME" )); KDirectoryRelease(dir); - rc_t rc=KnsIpcTestSuite(argc, argv); - return rc; -} - + return KnsIpcTestSuite(argc, argv); } diff --git a/test/kns/test-mutual-authentication.cpp b/test/kns/test-mutual-authentication.cpp index 94b634a12..db15cc5d2 100644 --- a/test/kns/test-mutual-authentication.cpp +++ b/test/kns/test-mutual-authentication.cpp @@ -24,7 +24,7 @@ #include -#include // KMain +#include #include /* KDirectoryRelease */ #include /* KFileRelease */ @@ -65,9 +65,11 @@ static rc_t KDirectory_Load(const KDirectory * cSelf, if (rc == 0) rc = KFileRead(file, 0, *buffer, s + 1, &num_read); - rc_t r2 = KFileRelease(file); - if (rc == 0 && r2 != 0) - rc = r2; + { + rc_t r2 = KFileRelease(file); + if (rc == 0 && r2 != 0) + rc = r2; + } if (cSelf == NULL) { rc_t r2 = KDirectoryRelease(self); @@ -181,7 +183,10 @@ rc_t CC Usage(const struct Args * args) { rc_t MutualConnection(const char * own_cert, const char * pk_key, const char * url, const char * host, uint32_t port); -rc_t CC KMain(int argc, char *argv[]) { +int main(int argc, char *argv[]) { + + VDB::Application app(argc, argv); + bool singleton = true; bool post = false; @@ -189,7 +194,7 @@ rc_t CC KMain(int argc, char *argv[]) { rc_t rc = ArgsMakeAndHandle( &args, argc, argv, 1, Options, sizeof Options / sizeof Options[0]); if (rc != 0) - return rc; + return (int)rc; uint32_t pcount = 0; uint32_t count = 0; @@ -241,7 +246,7 @@ rc_t CC KMain(int argc, char *argv[]) { if (rc == 0) rc = ArgsParamValue(args, 2, (const void **)&v3); if (rc == 0) - rc = MutualConnection(own_cert, pk_key, v, v2, atoi(v3)); + rc = MutualConnection(own_cert, pk_key, v, v2, (uint32_t)atoi(v3)); } free(own_cert); @@ -307,5 +312,5 @@ rc_t CC KMain(int argc, char *argv[]) { if (r2 != 0 && rc == 0) rc = r2; - return rc; + return (int)rc; } diff --git a/test/kns/test-opt-bitmap.cpp b/test/kns/test-opt-bitmap.cpp index 386ca8043..f7b9025e7 100644 --- a/test/kns/test-opt-bitmap.cpp +++ b/test/kns/test-opt-bitmap.cpp @@ -75,7 +75,7 @@ TEST_CASE(TestTelemetry) { // ENABLE SENDING TELEMETRY IN CONFIGURATION: IT IS IGNORED REQUIRE_RC(KConfigWriteString(kfg, "libs/kns/send-telemetry", "true")); - + #ifndef WINDOWS unsetenv("VDB_OPT_BITMAP"); REQUIRE_RC(KNSManagerGetUserAgent(&ua)); @@ -134,11 +134,7 @@ TEST_CASE(TestTelemetry) { REQUIRE_RC(KConfigRelease(kfg)); } -extern "C" { - ver_t CC KAppVersion(void) { return 0; } - - rc_t CC KMain(int argc, char *argv[]) { - KConfigDisableUserSettings(); - return KNS_opt_bitmapTestSuite(argc, argv); - } +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); + return KNS_opt_bitmapTestSuite(argc, argv); } diff --git a/test/kns/test-proxy-with-env.cpp b/test/kns/test-proxy-with-env.cpp index 6b1d179fa..70dcb24a2 100644 --- a/test/kns/test-proxy-with-env.cpp +++ b/test/kns/test-proxy-with-env.cpp @@ -54,9 +54,9 @@ TEST_CASE ( TEST_PROXY_FROM_ENV ) { ifstream myfile ( s . str () . c_str () ); string line; while ( getline ( myfile, line) ) { - istringstream s ( line ); + istringstream is ( line ); string path, value; - s >> path >> value; + is >> path >> value; if ( c == NULL ) { c = new C ( path, value ); } else { @@ -71,10 +71,10 @@ TEST_CASE ( TEST_PROXY_FROM_ENV ) { ifstream myfile ( s . str () . c_str () ); string line; while ( getline ( myfile, line) ) { - istringstream s ( line ); + istringstream is ( line ); string host; uint16_t port; - s >> host >> port; + is >> host >> port; if ( e == NULL ) { e = new E ( host, port ); } else { @@ -89,24 +89,20 @@ TEST_CASE ( TEST_PROXY_FROM_ENV ) { c = NULL; } -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - #define TODO -1 - rc_t CC KMain ( int argc, char * argv [] ) { +int main( int argc, char * argv [] ) { #if 0 const char name[] = "http_proxy"; char *e= getenv(name); ostringstream s; s << "getenv("< +#include // Args + +#include #include #include #include #include +#include #include #include #include @@ -530,10 +534,6 @@ FIXTURE_TEST_CASE( HttpRefreshTestSuite_HeadAsPost_ShortFile, CloudFixture ) //////////////////////////////////////////// Main -#include // Args -#include -#include - static rc_t argsHandler ( int argc, char * argv [] ) { Args * args = NULL; rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0, NULL, 0 ); @@ -541,32 +541,25 @@ static rc_t argsHandler ( int argc, char * argv [] ) { return rc; } -extern "C" { - const char UsageDefaultName[] = "test-refresh-expired"; - rc_t CC UsageSummary ( const char * progname) { return 0; } - rc_t CC Usage ( const struct Args * args ) { return 0; } - ver_t CC KAppVersion ( void ) { return 0; } - - rc_t CC KMain ( int argc, char * argv [] ) - { - //if ( 1 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); - KConfigDisableUserSettings (); +int main( int argc, char * argv [] ) +{ + //if ( 1 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); + KConfigDisableUserSettings (); - rc_t rc = KConfigMakeEmpty ( & kfg ); - // turn off certificate validation to download from storage.googleapis.com - if ( rc == 0 ) - rc = KConfigWriteString ( kfg, "/tls/allow-all-certs", "true" ); + rc_t rc = KConfigMakeEmpty ( & kfg ); + // turn off certificate validation to download from storage.googleapis.com + if ( rc == 0 ) + rc = KConfigWriteString ( kfg, "/tls/allow-all-certs", "true" ); - // in order to run in a cloud, give permission to submit computing environment - if (rc == 0) - rc = KConfigWriteString(kfg, "/libs/cloud/report_instance_identity", "true"); + // in order to run in a cloud, give permission to submit computing environment + if (rc == 0) + rc = KConfigWriteString(kfg, "/libs/cloud/report_instance_identity", "true"); - if ( rc == 0 ) - rc = HttpRefreshTestSuite ( argc, argv ); + if ( rc == 0 ) + rc = (rc_t)HttpRefreshTestSuite ( argc, argv ); - RELEASE ( KConfig, kfg ); + RELEASE ( KConfig, kfg ); - return rc; - } + return (int)rc; } diff --git a/test/kns/test-timeouts.cpp b/test/kns/test-timeouts.cpp index 5806877a3..3d7ca79ee 100644 --- a/test/kns/test-timeouts.cpp +++ b/test/kns/test-timeouts.cpp @@ -374,14 +374,7 @@ TEST_CASE ( TestTimeouts ) { REQUIRE_RC(KConfigRelease(kfg)); } -extern "C" { - const char UsageDefaultName[] = "test-timeouts"; - rc_t CC UsageSummary ( const char * progname) { return 0; } - rc_t CC Usage ( const struct Args * args ) { return 0; } - ver_t CC KAppVersion ( void ) { return 0; } - - rc_t CC KMain ( int argc, char * argv [] ) { - KConfigDisableUserSettings (); - return TEST_TIMEOUTS( argc, argv ); - } +int main( int argc, char * argv [] ) { + KConfigDisableUserSettings (); + return TEST_TIMEOUTS( argc, argv ); } diff --git a/test/kns/test200for-whole-file.cpp b/test/kns/test200for-whole-file.cpp index c4c413197..5a707be77 100644 --- a/test/kns/test200for-whole-file.cpp +++ b/test/kns/test200for-whole-file.cpp @@ -119,27 +119,21 @@ TEST_CASE ( Test_200 ) { REQUIRE_RC ( KNSManagerRelease ( mgr ) ); } -extern "C" { - const char UsageDefaultName[] = "test200for-whole-file"; - rc_t CC UsageSummary ( const char * progname) { return 0; } - rc_t CC Usage ( const struct Args * args ) { return 0; } - ver_t CC KAppVersion ( void ) { return 0; } +int main( int argc, char * argv [] ) { + if ( 0 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); + KConfigDisableUserSettings (); - rc_t CC KMain ( int argc, char * argv [] ) { if ( -0 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); - KConfigDisableUserSettings (); + KConfig * kfg = NULL; + rc_t rc = KConfigMakeEmpty ( & kfg ); - KConfig * kfg = NULL; - rc_t rc = KConfigMakeEmpty ( & kfg ); - // turn off certificate validation to download from storage.googleapis.com - if ( rc == 0 ) - rc = KConfigWriteString ( kfg, "/tls/allow-all-certs", "true" ); + // turn off certificate validation to download from storage.googleapis.com + if ( rc == 0 ) + rc = KConfigWriteString ( kfg, "/tls/allow-all-certs", "true" ); - if ( rc == 0 ) - rc = T200FOR_WHOLE_FILE ( argc, argv ); + if ( rc == 0 ) + rc = (rc_t)T200FOR_WHOLE_FILE ( argc, argv ); - RELEASE ( KConfig, kfg ); + RELEASE ( KConfig, kfg ); - return rc; - } + return (int)rc; } diff --git a/test/kns/test_allow_all_certificates.cpp b/test/kns/test_allow_all_certificates.cpp index 52ebf27b3..996941bb6 100644 --- a/test/kns/test_allow_all_certificates.cpp +++ b/test/kns/test_allow_all_certificates.cpp @@ -123,20 +123,12 @@ KOutMsg ( "##[3] OK : Conf (false ) + SetAllow ( false ) = false\n" ); RELEASE ( KConfig, kfg ); } -extern "C" { - const char UsageDefaultName[] = "test200for-whole-file"; - rc_t CC UsageSummary ( const char * progname) { return 0; } - rc_t CC Usage ( const struct Args * args ) { return 0; } - ver_t CC KAppVersion ( void ) { return 0; } +int main( int argc, char * argv [] ) { + if ( 0 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); + + KConfigDisableUserSettings (); - rc_t CC KMain ( int argc, char * argv [] ) { if ( -0 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); - KConfigDisableUserSettings (); + // turn off certificate validation to download from storage.googleapis.com - // turn off certificate validation to download from storage.googleapis.com - - rc_t rc = ALLOW_ALL_CERTS ( argc, argv ); - - return rc; - } + return ALLOW_ALL_CERTS ( argc, argv ); } diff --git a/test/kns/test_dis_allow_all_certificates.cpp b/test/kns/test_dis_allow_all_certificates.cpp index fd425d498..583176f8a 100644 --- a/test/kns/test_dis_allow_all_certificates.cpp +++ b/test/kns/test_dis_allow_all_certificates.cpp @@ -129,20 +129,12 @@ KOutMsg ( "##[6] OK : Conf (true ) + SetAllow ( true ) = true\n" ); RELEASE ( KConfig, kfg ); } -extern "C" { - const char UsageDefaultName[] = "test200for-whole-file"; - rc_t CC UsageSummary ( const char * progname) { return 0; } - rc_t CC Usage ( const struct Args * args ) { return 0; } - ver_t CC KAppVersion ( void ) { return 0; } +int main( int argc, char * argv [] ) { + if ( 0 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); - rc_t CC KMain ( int argc, char * argv [] ) { if ( -0 ) assert ( ! KDbgSetString ( "KNS-HTTP" ) ); - KConfigDisableUserSettings (); + KConfigDisableUserSettings (); - // turn off certificate validation to download from storage.googleapis.com + // turn off certificate validation to download from storage.googleapis.com - rc_t rc = ALLOW_ALL_CERTS ( argc, argv ); - - return rc; - } + return ALLOW_ALL_CERTS ( argc, argv ); } diff --git a/test/kproc/kproctest.cpp b/test/kproc/kproctest.cpp index 24b74f3f2..5c74daf6c 100644 --- a/test/kproc/kproctest.cpp +++ b/test/kproc/kproctest.cpp @@ -30,11 +30,13 @@ #include +#include + #include #include #include -#include +#include #include #include @@ -45,6 +47,8 @@ #include #include +#include +#include #include // mamset @@ -62,94 +66,112 @@ TEST_CASE( KLock_NULL ) REQUIRE_RC_FAIL(KLockMake(NULL)); } +static KLock *makeLock() +{ + KLock *lock = nullptr; + if (KLockMake(&lock) != 0) + throw logic_error("KLockMake failed"); + return lock; +} + class KLockFixture { public: KLockFixture() - : threadRc(0), - thread(0), - lock(0) - { - if (KLockMake(&lock) != 0) - throw logic_error("KLockFixture: KLockMake failed"); - } + : thread(0) + , lock(makeLock()) + , threadWaiting(false) + {} + ~KLockFixture() { if (thread != 0 && KThreadRelease(thread) != 0) cerr << "~KLockFixture: KThreadRelease failed" << endl; - if (KLockRelease((const KLock*)lock) != 0) + if (KLockRelease(const_cast(lock)) != 0) cerr << "~KLockFixture: KLockRelease failed" << endl; } - + protected: - class Thread { - public: - // danger - this should be an extern "C" function - // with CC calling convention on Windows - static rc_t KLock_ThreadFn ( const KThread *thread, void *data ) noexcept + rc_t runThread() { + LOG(LogLevel::e_message, "KLockFixture::runThread: acquiring lock, set threadWaiting to true" << endl); + threadWaiting = true; + + while (KLockAcquire(lock) != 0) { - KLockFixture* self = (KLockFixture*)data; - - LOG(LogLevel::e_message, "KLock_ThreadFn acquiring lock, set threadWaiting to 1" << endl); - atomic32_set ( & self->threadWaiting, 1 ); - - while (KLockAcquire(self->lock) != 0) - { - TestEnv::SleepMs(1); - } - LOG(LogLevel::e_message, "KLock_ThreadFn: lock acquired" << endl); - - atomic32_set ( & self->threadWaiting, 0 ); - LOG(LogLevel::e_message, "KLock_ThreadFn: set threadWaiting to 0" << endl); - - self->threadRc = KLockUnlock(self->lock); - LOG(LogLevel::e_message, "KLock_Timed_ThreadFn: exiting" << endl); - return 0; + TestEnv::SleepMs(1); } - }; + LOG(LogLevel::e_message, "KLockFixture::runThread: lock acquired" << endl); + + threadWaiting = false; + LOG(LogLevel::e_message, "KLockFixture::runThread: set threadWaiting to false" << endl); + + auto const rc = KLockUnlock(lock); + + LOG(LogLevel::e_message, "KLockFixture::runThread: exiting" << endl); + return rc; + } + + static rc_t ThreadFn ( KThread const *const thread, void *const data ) noexcept { + return reinterpret_cast(data)->runThread(); + } + rc_t startThread() { + return KThreadMake(&thread, ThreadFn, reinterpret_cast(this)); + } + rc_t StartThread() { - atomic32_set ( & threadWaiting, 0 ); - LOG(LogLevel::e_message, "StartThread: set threadWaiting to 0" << endl); + threadWaiting = false; + LOG(LogLevel::e_message, "KLockFixture::StartThread: set threadWaiting to false" << endl); - threadRc = 0; - rc_t rc = KThreadMake(&thread, Thread::KLock_ThreadFn, this); - while (threadRc == 0 && !atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - LOG(LogLevel::e_message, "StartThread: threadWaiting == 1" << endl); - return rc; + auto const rc = startThread(); + if (rc) return rc; + + do { TestEnv::SleepMs(1); } while (!threadWaiting); + + LOG(LogLevel::e_message, "KLockFixture::StartThread: threadWaiting == true" << endl); + return 0; } + std::pair waitThread() const { + rc_t threadRc = 0, rc = KThreadWait(thread, &threadRc); + return {rc, threadRc}; + } + public: - rc_t threadRc; KThread* thread; - volatile atomic32_t threadWaiting; - timeout_t tm; - KLock* lock; + KLock *lock; + atomic_bool threadWaiting; }; FIXTURE_TEST_CASE(KLock_Acquire, KLockFixture) { - // lock + // lock REQUIRE_RC(KLockAcquire(lock)); // start a thread that tries to lock, see it wait for the lock to become available - REQUIRE_RC(StartThread()); // makes sure threadWaiting == 1 - + REQUIRE_RC(StartThread()); + REQUIRE(threadWaiting); + // unlock, see the thread finish REQUIRE_RC(KLockUnlock(lock)); - while (atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - REQUIRE_RC(threadRc); - LOG(LogLevel::e_message, "KLock_Acquire: done" << endl); + auto const rcs = waitThread(); + REQUIRE_RC(rcs.first); + REQUIRE(!threadWaiting); + REQUIRE_RC(rcs.second); + LOG(LogLevel::e_message, "KLock_Acquire: done" << endl); } ///////////////////////// KTimedLock + +static KTimedLock *makeTimedLock() +{ + KTimedLock *lock = nullptr; + if (KTimedLockMake(&lock) != 0) + throw logic_error("KLockMake failed"); + return lock; +} + TEST_CASE( KTimedLock_NULL ) { REQUIRE_RC_FAIL(KTimedLockMake(NULL)); @@ -159,136 +181,131 @@ class KTimedLockFixture { public: KTimedLockFixture() - : threadRc(0), - thread(0), - lock(0) - { - if (KTimedLockMake(&lock) != 0) - throw logic_error("KLockFixture: KLockMake failed"); - } + : thread(0) + , lock(makeTimedLock()) + , threadWaiting(false) + {} + ~KTimedLockFixture() { if (thread != 0 && KThreadRelease(thread) != 0) cerr << "~KLockFixture: KThreadRelease failed" << endl; - if (KLockRelease((const KLock*)lock) != 0) + if (KLockRelease((KLock const *)lock) != 0) cerr << "~KLockFixture: KLockRelease failed" << endl; } - + protected: - class Thread { - public: - // danger - this should be an extern "C" function - // with CC calling convention on Windows - static rc_t KLock_Timed_ThreadFn ( const KThread *thread, void *data ) noexcept - { - KTimedLockFixture* self = (KTimedLockFixture*)data; + rc_t acquireLock() const { + auto ltm = tm; ///< make a copy + return KTimedLockAcquire(lock, <m); ///< modify the local copy, no sync needed; + } + + rc_t unlock() const { + return KTimedLockUnlock(lock); + } + + rc_t runThread() { + LOG(LogLevel::e_message, "KTimedLockFixture::runThread: acquiring lock, set threadWaiting to true, timeout = " << tm.mS << "ms" << endl); + threadWaiting = true; + + auto rc = acquireLock(); + if (rc == 0) + LOG(LogLevel::e_message, "KTimedLockFixture::runThread: lock acquired" << endl); + else + LOG(LogLevel::e_message, "KTimedLockFixture::runThread: lock acquire failed" << endl); + + LOG(LogLevel::e_message, "KTimedLockFixture::runThread: set threadWaiting to false" << endl); + threadWaiting = false; + + if (rc == 0) + rc = unlock(); - LOG(LogLevel::e_message, "KLock_Timed_ThreadFn acquiring lock, set threadWaiting to 1, timeout = " << self->tm.mS << "ms" << endl); - atomic32_set ( & self->threadWaiting, 1 ); + LOG(LogLevel::e_message, "KTimedLockFixture::runThread: exiting" << endl); - self->threadRc = KTimedLockAcquire(self->lock, &self->tm); - if (self->threadRc == 0) - LOG(LogLevel::e_message, "KLock_Timed_ThreadFn: lock acquired" << endl); - else - LOG(LogLevel::e_message, "KLock_Timed_ThreadFn: lock acquire failed" << endl); - - LOG(LogLevel::e_message, "KLock_Timed_ThreadFn: set threadWaiting to 0" << endl); - - if (self->threadRc == 0) - self->threadRc = KTimedLockUnlock(self->lock); - LOG(LogLevel::e_message, "KLock_Timed_ThreadFn: exiting" << endl); - atomic32_set ( & self->threadWaiting, 0 ); - return 0; - } - }; + return rc; + } + static rc_t KLock_Timed_ThreadFn ( const KThread *thread, void *data ) noexcept { + return reinterpret_cast(data)->runThread(); + } + + rc_t startThread() { + return KThreadMake(&thread, KLock_Timed_ThreadFn, this); + } + rc_t StartThread(size_t timeout) { - rc_t rc = TimeoutInit( &tm, timeout ); - if ( rc == 0) - { - atomic32_set ( & threadWaiting, 0 ); - LOG(LogLevel::e_message, "StartTimedThread: set threadWaiting to 0" << endl); - - threadRc = 0; - rc = KThreadMake(&thread, Thread::KLock_Timed_ThreadFn, this); - while (threadRc == 0 && !atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - LOG(LogLevel::e_message, "StartTimedThread: threadWaiting == 1" << endl); - } - return rc; + auto rc = TimeoutInit( &tm, (uint32_t)timeout ); + if (rc) return rc; + + threadWaiting = false; + LOG(LogLevel::e_message, "KTimedLockFixture::StartThread: set threadWaiting to false" << endl); + + rc = startThread(); + if (rc) return rc; + + do { TestEnv::SleepMs(1); } while (!threadWaiting); + + LOG(LogLevel::e_message, "KTimedLockFixture::StartThread: threadWaiting == true" << endl); + return 0; + } + + std::pair waitThread() const { + rc_t threadRc = 0, rc = KThreadWait(thread, &threadRc); + return {rc, threadRc}; } -public: - rc_t threadRc; +public: KThread* thread; - volatile atomic32_t threadWaiting; + KTimedLock *lock; + atomic_bool threadWaiting; timeout_t tm; - KTimedLock* lock; }; FIXTURE_TEST_CASE(KTimedLock_Acquire, KTimedLockFixture) { - // lock + // lock REQUIRE_RC(KTimedLockAcquire(lock, NULL)); - + // start a thread that tries to lock - LOG(LogLevel::e_message, "TEST_KLock_TimedAcquire: starting thread" << endl); - REQUIRE_RC(StartThread(1000));// makes sure threadWaiting == 1 + LOG(LogLevel::e_message, "TEST_KLock_TimedAcquire: starting thread" << endl); + REQUIRE_RC(StartThread(1000)); + REQUIRE(threadWaiting); // unlock, see the thread finish - LOG(LogLevel::e_message, "TEST_KLock_TimedAcquire: unlocking" << endl); + LOG(LogLevel::e_message, "TEST_KLock_TimedAcquire: unlocking" << endl); REQUIRE_RC(KTimedLockUnlock(lock)); - - // wait for the thread to finish - while (atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - REQUIRE_RC(threadRc); - LOG(LogLevel::e_message, "TEST_KLock_TimedAcquire: done" << endl); -} + auto const rcs = waitThread(); + REQUIRE_RC(rcs.first); + REQUIRE(!threadWaiting); + REQUIRE_RC(rcs.second); -#ifdef WINDOWS -FIXTURE_TEST_CASE(KTimedLock_Acquire_Busy, KTimedLockFixture) -{ - // lock - REQUIRE_RC(KTimedLockAcquire(lock, NULL)); - - // start a thread that tries to lock, see it error out - REQUIRE_RC(StartThread(100));// makes sure threadWaiting == 1 - - // do not unlock, wait for the thread to finish - while (atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - REQUIRE_EQ(threadRc, RC(rcPS, rcLock, rcLocking, rcLock, rcBusy)); - - REQUIRE_RC(KTimedLockUnlock(lock)); + LOG(LogLevel::e_message, "TEST_KLock_TimedAcquire: done" << endl); } -#else + FIXTURE_TEST_CASE(KTimedLock_Acquire_Timeout, KTimedLockFixture) { - // lock + // lock REQUIRE_RC(KTimedLockAcquire(lock, NULL)); // start a thread that tries to lock, see it time out - REQUIRE_RC(StartThread(100));// makes sure threadWaiting == 1 + REQUIRE_RC(StartThread(100)); + REQUIRE(threadWaiting); // do not unlock, wait for the thread to finish - while (atomic32_read(&threadWaiting)) - { - TestEnv::SleepMs(1); - } - REQUIRE_EQ(threadRc, RC(rcPS, rcLock, rcLocking, rcTimeout, rcExhausted)); // timed out + auto const rcs = waitThread(); + REQUIRE_RC(rcs.first); + REQUIRE(!threadWaiting); + +#ifdef WINDOWS + REQUIRE_EQ(rcs.second, SILENT_RC(rcPS, rcLock, rcLocking, rcLock, rcBusy)); +#else + REQUIRE_EQ(rcs.second, SILENT_RC(rcPS, rcLock, rcLocking, rcTimeout, rcExhausted)); +#endif REQUIRE_RC(KTimedLockUnlock(lock)); } -#endif ///////////////////////// KRWLock TEST_CASE( KRWLock_NULL ) @@ -296,113 +313,139 @@ TEST_CASE( KRWLock_NULL ) REQUIRE_RC_FAIL(KRWLockMake(NULL)); } +static KRWLock *makeKRWLock() { + KRWLock *lock = nullptr; + if (KRWLockMake(&lock) != 0) + throw logic_error("KLockFixture: KLockMake failed"); + return lock; +}; + class KRWLockFixture { public: KRWLockFixture() - : threadRc(0), - thread(0), - lock(0) - { - atomic32_set ( & threadWaiting, 0 ); - - if (KRWLockMake(&lock) != 0) - throw logic_error("KLockFixture: KLockMake failed"); - } + : thread(0) + , lock(makeKRWLock()) + , threadWaiting(false) + {} + ~KRWLockFixture() { if (thread != 0 && KThreadRelease(thread) != 0) cerr << "~KRWLockFixture: KThreadRelease failed" << endl; - if (KRWLockRelease((const KRWLock*)lock) != 0) + if (KRWLockRelease(const_cast(lock)) != 0) cerr << "~KRWLockFixture: KLockRelease failed" << endl; } - + protected: - class Thread { - public: - static rc_t KRWLock_Reader_ThreadFn ( const KThread *thread, void *data ) - { - KRWLockFixture* self = (KRWLockFixture*)data; - atomic32_set( & self->threadWaiting, true ); - - while (KRWLockAcquireShared(self->lock) != 0) - { - TestEnv::SleepMs(1); - } - self->threadRc = KRWLockUnlock(self->lock); - atomic32_set( & self->threadWaiting, false ); - return 0; - } - static rc_t KRWLock_Writer_ThreadFn ( const KThread *thread, void *data ) noexcept - { - KRWLockFixture* self = (KRWLockFixture*)data; - atomic32_set( & self->threadWaiting, true ); - - LOG(LogLevel::e_message, "KRWLock_Writer_ThreadFn: calling KRWLockAcquireExcl\n"); - self->threadRc = KRWLockAcquireExcl(self->lock); - LOG(LogLevel::e_message, "KRWLock_Writer_ThreadFn: out of KRWLockAcquireExcl\n"); - if (self->threadRc == 0) - { - LOG(LogLevel::e_message, "KRWLock_Writer_ThreadFn: calling KRWLockUnlock\n"); - self->threadRc = KRWLockUnlock(self->lock); - } - atomic32_set( & self->threadWaiting, false ); - return 0; - } - static rc_t KRWLock_ReaderTimed_ThreadFn ( const KThread *thread, void *data ) + rc_t runReaderThread() { + threadWaiting = true; + + while (KRWLockAcquireShared(lock) != 0) { - KRWLockFixture* self = (KRWLockFixture*)data; - atomic32_set( & self->threadWaiting, true ); - - self->threadRc = KRWLockTimedAcquireShared(self->lock, &self->tm); - if (self->threadRc == 0) - self->threadRc = KRWLockUnlock(self->lock); - atomic32_set( & self->threadWaiting, false ); - return 0; + TestEnv::SleepMs(1); } - static rc_t KRWLock_WriterTimed_ThreadFn ( const KThread *thread, void *data ) noexcept + auto const rc = KRWLockUnlock(lock); + threadWaiting = false; + return rc; + } + static rc_t Reader_ThreadFn ( const KThread *thread, void *data ) + { + return reinterpret_cast(data)->runReaderThread(); + } + rc_t startReaderThread() { + return KThreadMake(&thread, Reader_ThreadFn, reinterpret_cast(this)); + } + + rc_t runWriterThread() { + threadWaiting = true; + + LOG(LogLevel::e_message, "KRWLockFixture::runWriterThread: calling KRWLockAcquireExcl\n"); + auto rc = KRWLockAcquireExcl(lock); + LOG(LogLevel::e_message, "KRWLockFixture::runWriterThread: out of KRWLockAcquireExcl\n"); + if (rc == 0) { - KRWLockFixture* self = (KRWLockFixture*)data; - atomic32_set( & self->threadWaiting, true ); - - self->threadRc = KRWLockTimedAcquireExcl(self->lock, &self->tm); - if (self->threadRc == 0) - self->threadRc = KRWLockUnlock(self->lock); - atomic32_set( & self->threadWaiting, false ); - return 0; + LOG(LogLevel::e_message, "KRWLockFixture::runWriterThread: calling KRWLockUnlock\n"); + rc = KRWLockUnlock(lock); } - }; + threadWaiting = false; + return rc; + } + static rc_t Writer_ThreadFn ( const KThread *thread, void *data ) + { + return reinterpret_cast(data)->runWriterThread(); + } + rc_t startWriterThread() { + return KThreadMake(&thread, Writer_ThreadFn, reinterpret_cast(this)); + } - rc_t StartThread(bool writer) + rc_t runReaderTimedThread() { + threadWaiting = true; + + auto ltm = tm; + auto rc = KRWLockTimedAcquireShared(lock, <m); + if (rc == 0) + rc = KRWLockUnlock(lock); + + threadWaiting = false; + return rc; + } + static rc_t ReaderTimed_ThreadFn ( const KThread *thread, void *data ) { - threadRc = 0; - rc_t rc = KThreadMake(&thread, writer ? Thread::KRWLock_Writer_ThreadFn : Thread::KRWLock_Reader_ThreadFn, this); - while (!atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } + return reinterpret_cast(data)->runReaderTimedThread(); + } + rc_t startReaderTimedThread() { + return KThreadMake(&thread, ReaderTimed_ThreadFn, reinterpret_cast(this)); + } + + rc_t runWriterTimedThread() { + threadWaiting = true; + + auto ltm = tm; + auto rc = KRWLockTimedAcquireExcl(lock, <m); + if (rc == 0) + rc = KRWLockUnlock(lock); + + threadWaiting = false; return rc; } + static rc_t WriterTimed_ThreadFn ( const KThread *thread, void *data ) noexcept + { + return reinterpret_cast(data)->runWriterTimedThread(); + } + rc_t startWriterTimedThread() { + return KThreadMake(&thread, WriterTimed_ThreadFn, reinterpret_cast(this)); + } + + rc_t StartThread(bool writer) + { + auto const rc = writer ? startWriterThread() : startReaderThread(); + if (rc) return rc; + do { TestEnv::SleepMs(1); } while (!threadWaiting); + return 0; + } + rc_t StartThread(bool writer, size_t timeout) { - rc_t rc = TimeoutInit( &tm, timeout ); - if ( rc == 0) - { - threadRc = 0; - rc = KThreadMake(&thread, writer ? Thread::KRWLock_WriterTimed_ThreadFn : Thread::KRWLock_ReaderTimed_ThreadFn, this); - while (!atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - } - return rc; + auto rc = TimeoutInit( &tm, (uint32_t)timeout ); + if (rc) return rc; + + rc = writer ? startWriterTimedThread() : startReaderTimedThread(); + if (rc) return rc; + + do { TestEnv::SleepMs(1); } while (!threadWaiting); + return 0; + } + + std::pair waitThread() const { + rc_t threadRc = 0, rc = KThreadWait(thread, &threadRc); + return {rc, threadRc}; } - volatile atomic32_t threadWaiting; - rc_t threadRc; KThread* thread; + KRWLock *lock; timeout_t tm; - KRWLock* lock; + atomic_bool threadWaiting; }; FIXTURE_TEST_CASE( KRWLock_ManyReaders, KRWLockFixture ) @@ -425,7 +468,7 @@ FIXTURE_TEST_CASE( KRWLock_OneWriter, KRWLockFixture ) //REQUIRE_RC_FAIL(KRWLockAcquireExcl(lock)); //REQUIRE_RC_FAIL(KRWLockAcquireShared(lock)); //TODO: try to acquire from a different thread - + REQUIRE_RC(KRWLockUnlock(lock)); // now, can lock again @@ -435,100 +478,90 @@ FIXTURE_TEST_CASE( KRWLock_OneWriter, KRWLockFixture ) FIXTURE_TEST_CASE( KRWLock_WriterWaitsForReader, KRWLockFixture ) { - LOG(LogLevel::e_message, "KRWLock_WriterWaitsForReader: calling KRWLockAcquireShared\n"); + LOG(LogLevel::e_message, "KRWLock_WriterWaitsForReader: calling KRWLockAcquireShared\n"); REQUIRE_RC(KRWLockAcquireShared(lock)); - + // start a thread that tries to write-lock, see it wait - LOG(LogLevel::e_message, "KRWLock_WriterWaitsForReader: starting thread\n"); + LOG(LogLevel::e_message, "KRWLock_WriterWaitsForReader: starting thread\n"); REQUIRE_RC(StartThread(true)); - - REQUIRE(atomic32_read ( & threadWaiting )); - LOG(LogLevel::e_message, "KRWLock_WriterWaitsForReader: calling KRWLockUnlock\n"); + REQUIRE(threadWaiting); + + LOG(LogLevel::e_message, "KRWLock_WriterWaitsForReader: calling KRWLockUnlock\n"); REQUIRE_RC(KRWLockUnlock(lock)); // let the thread finish - while (atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - REQUIRE(!atomic32_read ( & threadWaiting )); + do { TestEnv::SleepMs(1); } while (threadWaiting); + REQUIRE(!threadWaiting); } FIXTURE_TEST_CASE(KWRLock_Reader_TimedAcquire, KRWLockFixture) { - // lock + // lock REQUIRE_RC(KRWLockAcquireExcl(lock)); - + // start a thread that tries to lock REQUIRE_RC(StartThread(false, 1000)); - + // see the thread wait - REQUIRE(atomic32_read ( & threadWaiting )); - + REQUIRE(threadWaiting); + // unlock, see the thread finish REQUIRE_RC(KRWLockUnlock(lock)); - while (atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - REQUIRE_RC(threadRc); + + auto const rcs = waitThread(); + REQUIRE_RC(rcs.first); + REQUIRE_RC(rcs.second); } FIXTURE_TEST_CASE(KWRLock_Reader_TimedAcquire_Timeout, KRWLockFixture) { - // lock + // lock REQUIRE_RC(KRWLockAcquireExcl(lock)); - + // start a thread that tries to lock, see it time out REQUIRE_RC(StartThread(false, 500)); // see the thread time out - while (atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - rc_t req_rc = RC ( rcPS, rcRWLock, rcLocking, rcTimeout, rcExhausted ); - REQUIRE_EQ(threadRc, req_rc); // timed out - + auto const rcs = waitThread(); + REQUIRE_RC(rcs.first); + REQUIRE_EQ(rcs.second, SILENT_RC ( rcPS, rcRWLock, rcLocking, rcTimeout, rcExhausted )); // timed out + REQUIRE_RC(KRWLockUnlock(lock)); } FIXTURE_TEST_CASE(KWRLock_Writer_TimedAcquire, KRWLockFixture) { - // read-lock + // read-lock REQUIRE_RC(KRWLockAcquireShared(lock)); - + // start a thread that tries to write-lock and see it wait REQUIRE_RC(StartThread(true, 1000)); - + // see the thread wait TestEnv::SleepMs(300); - REQUIRE(atomic32_read (&threadWaiting)); - + REQUIRE(threadWaiting); + // unlock, see the thread finish REQUIRE_RC(KRWLockUnlock(lock)); - while (atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - REQUIRE_RC(threadRc); + + auto const rcs = waitThread(); + REQUIRE_RC(rcs.first); + REQUIRE_RC(rcs.second); } FIXTURE_TEST_CASE(KWRLock_Writer_TimedAcquire_Timeout, KRWLockFixture) { - // read-lock + // read-lock REQUIRE_RC(KRWLockAcquireShared(lock)); - + // start a thread that tries to write-lock, see it time out REQUIRE_RC(StartThread(true, 500)); - + // see the thread time out - while (atomic32_read (&threadWaiting)) - { - TestEnv::SleepMs(1); - } - REQUIRE_EQ(threadRc, RC ( rcPS, rcRWLock, rcLocking, rcTimeout, rcExhausted )); // timed out - + auto const rcs = waitThread(); + REQUIRE_RC(rcs.first); + REQUIRE_EQ(rcs.second, SILENT_RC ( rcPS, rcRWLock, rcLocking, rcTimeout, rcExhausted )); // timed out + REQUIRE_RC(KRWLockUnlock(lock)); } @@ -548,8 +581,7 @@ class KConditionFixture { public: KConditionFixture() - : threadRc(0), - thread(0), + : thread(0), lock(0), is_signaled(false), do_broadcast(false) @@ -563,7 +595,8 @@ class KConditionFixture { if (thread != 0) { - if (KThreadWait(thread, NULL) != 0) + rc_t threadRc = 0; + if (KThreadWait(thread, &threadRc) != 0) cerr << "~KConditionFixture: KThreadWait failed" << endl; if (threadRc != 0) cerr << "~KConditionFixture: thread failed, threadRc != 0" << endl; @@ -577,44 +610,39 @@ class KConditionFixture } protected: - class Thread { - public: - // danger - this should be an extern "C" function - // with CC calling convention on Windows - static rc_t KCondition_ThreadFn ( const KThread *thread, void *data ) noexcept - { - KConditionFixture* self = (KConditionFixture*)data; - - LOG(LogLevel::e_message, "KCondition_ThreadFn: sleeping" << endl); - TestEnv::SleepMs(300); - LOG(LogLevel::e_message, "KCondition_ThreadFn: signaling condition" << endl); - self->is_signaled = true; - if (!self->do_broadcast) - self->threadRc = KConditionSignal(self->cond); - else - self->threadRc = KConditionBroadcast(self->cond); - - LOG(LogLevel::e_message, "KCondition_ThreadFn: exiting" << endl); - return 0; - } - }; + rc_t runThread() { + LOG(LogLevel::e_message, "KConditionFixture::runThread: sleeping" << endl); + TestEnv::SleepMs(300); + + LOG(LogLevel::e_message, "KConditionFixture::runThread: signaling condition" << endl); + is_signaled = true; + + auto const rc = do_broadcast ? KConditionBroadcast(cond) : KConditionSignal(cond); + + LOG(LogLevel::e_message, "KConditionFixture::runThread: exiting" << endl); + + return rc; + } + static rc_t ThreadFn ( const KThread *thread, void *data ) noexcept + { + return reinterpret_cast(data)->runThread(); + } + rc_t startThread() { + return KThreadMake(&thread, ThreadFn, reinterpret_cast(this)); + } rc_t StartThread() { LOG(LogLevel::e_message, "StartThread: starting thread" << endl); - - threadRc = 0; - rc_t rc = KThreadMake(&thread, Thread::KCondition_ThreadFn, this); - return rc; + return startThread(); } public: - rc_t threadRc; KThread* thread; - timeout_t tm; KLock* lock; KCondition* cond; - bool is_signaled; + atomic_bool is_signaled; + timeout_t tm; bool do_broadcast; }; @@ -623,7 +651,7 @@ FIXTURE_TEST_CASE( KCondition_TimedWait_Timeout, KConditionFixture ) REQUIRE_RC(KLockAcquire(lock)); REQUIRE_RC(TimeoutInit(&tm, 100)); REQUIRE_RC(KConditionSignal(cond)); // signaling before waiting should not do anything - REQUIRE_EQ(KConditionTimedWait(cond, lock, &tm), RC ( rcPS, rcCondition, rcWaiting, rcTimeout, rcExhausted )); // timed out + REQUIRE_EQ(KConditionTimedWait(cond, lock, &tm), SILENT_RC ( rcPS, rcCondition, rcWaiting, rcTimeout, rcExhausted )); // timed out REQUIRE_RC(KLockUnlock(lock)); } @@ -683,29 +711,29 @@ TEST_CASE(KQueueSimpleTest) { { // pushed 3 > capacity (failure) - popped 2 (ok) for (uint64_t i = 1; i < 3; ++i) { - void *item = (void*)i; - REQUIRE_RC(KQueuePush(queue, item, & tm)); + void *it = (void*)i; + REQUIRE_RC(KQueuePush(queue, it, & tm)); } REQUIRE_RC_FAIL(KQueuePush(queue, item, & tm)); for (uint64_t i = 1; i < 3; ++i) { uint64_t j = 0; - void *item = 0; - REQUIRE_RC(KQueuePop(queue, &item, & tm)); - j = (uint64_t)item; + void *it = 0; + REQUIRE_RC(KQueuePop(queue, &it, & tm)); + j = (uint64_t)it; REQUIRE_EQ(i, j); } } { // pushed 2 = capacity (ok) - popped 3 >capacity (failure) for (uint64_t i = 1; i < 3; ++i) { - void *item = (void*)i; - REQUIRE_RC(KQueuePush(queue, item, & tm)); + void *it = (void*)i; + REQUIRE_RC(KQueuePush(queue, it, & tm)); } for (uint64_t i = 1; i < 3; ++i) { uint64_t j = 0; - void *item = 0; - REQUIRE_RC(KQueuePop(queue, &item, & tm)); - j = (uint64_t)item; + void *it = 0; + REQUIRE_RC(KQueuePop(queue, &it, & tm)); + j = (uint64_t)it; REQUIRE_EQ(i, j); } REQUIRE_RC_FAIL(KQueuePop(queue, &item, & tm)); @@ -734,7 +762,7 @@ class KQueueFixture threadRcs = (rc_t*)calloc(nThreads, sizeof(*threadRcs)); if (threadRcs == NULL) throw logic_error("KQueueFixture: threadRcs calloc failed"); - if (KQueueMake(&queue, nThreads) != 0) + if (KQueueMake(&queue, (uint32_t)nThreads) != 0) throw logic_error("KQueueFixture: KQueueMake failed"); } ~KQueueFixture() @@ -762,7 +790,7 @@ class KQueueFixture size_t max_tid; uint32_t timeout_ms; bool is_reader; - bool finish; // will stop generating events and seal the queue once detected + atomic_bool finish; // will stop generating events and seal the queue once detected bool allow_timeout; // if set, we won't treat timeout as an error }; @@ -843,7 +871,7 @@ class KQueueFixture throw logic_error("StartThread: cannot start new thread, fixture is already sealed"); rc_t rc; - int tid = nStartedThreads++; + int tid = (int) (nStartedThreads++); ThreadData* td; td = &threadsData[tid]; @@ -981,29 +1009,6 @@ FIXTURE_TEST_CASE(KQueue_Single_Reader_Multi_Writer_Seal, KQueueFixture) //TODO: KBarrier (is it used anywhere? is there a Windows implementation?) //////////////////////////////////////////// Main -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -rc_t CC UsageSummary ( const char * progname ) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - - -const char UsageDefaultName[] = "test-kproc"; - static rc_t argsHandler(int argc, char* argv[]) { Args* args = NULL; rc_t rc = ArgsMakeAndHandle(&args, argc, argv, 0, NULL, 0); @@ -1011,14 +1016,11 @@ static rc_t argsHandler(int argc, char* argv[]) { return rc; } -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { // this makes messages from the test code appear // (same as running the executable with "-l=message") //TestEnv::verbosity = LogLevel::e_message; - - rc_t rc = KProcTestSuite( argc, argv ); - return rc; -} + return KProcTestSuite( argc, argv ); } diff --git a/test/krypto/CMakeLists.txt b/test/krypto/CMakeLists.txt index b27706de1..13e5312da 100644 --- a/test/krypto/CMakeLists.txt +++ b/test/krypto/CMakeLists.txt @@ -24,20 +24,17 @@ add_compile_definitions( __mod__="test/krypto" ) -if( WIN32 ) - set( ADDITIONAL_LIBS Crypt32 ) -else() - set( ADDITIONAL_LIBS "" ) -endif() +set( LIBS "${COMMON_LIBS_READ}") -BuildExecutableForTest( SlowTest_KRYPTO_cipher_speed "test-cipher-speed" "kryptotest;${COMMON_LIBS_READ}" ) +BuildExecutableForTest( SlowTest_KRYPTO_cipher_speed "test-cipher-speed" "kryptotest;${LIBS}" ) add_test( NAME SlowTest_KRYPTO_cipher_speed COMMAND SlowTest_KRYPTO_cipher_speed -t 10 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) -AddExecutableTest( Test_KRYPTO_modes "test-modes" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KRYPTO_encdec "test-encdec;test-cmn" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KRYPTO_reenc "test-reenc;test-cmn" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KRYPTO_rsa-aes-hmac "test-rsa-aes-hmac" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KRYPTO_hash-in-pwd "test-hash-in-pwd" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_KRYPTO_aes-ciphers "test-aes-ciphers" "kryptotest;${COMMON_LIBS_READ}" ) +AddExecutableTest( Test_KRYPTO_modes "test-modes" "${LIBS}" ) +AddExecutableTest( Test_KRYPTO_encdec "test-encdec;test-cmn" "${LIBS}" ) +AddExecutableTest( Test_KRYPTO_reenc "test-reenc;test-cmn" "${LIBS}" ) +AddExecutableTest( Test_KRYPTO_rsa-aes-hmac "test-rsa-aes-hmac" "${LIBS}" ) +AddExecutableTest( Test_KRYPTO_hash-in-pwd "test-hash-in-pwd" "${LIBS}" ) +AddExecutableTest( Test_KRYPTO_aes-ciphers "test-aes-ciphers" "kryptotest;${LIBS}" ) -AddExecutableTest( SlowTest_KRYPTO_krypto-slow "test-krypto-slow;test-cmn" "${COMMON_LIBS_READ}" ) +# uses a lot of disk space; migrated to asm-trace with its own version of test-cmn.[hc] +#AddExecutableTest( SlowTest_KRYPTO_krypto-slow "test-krypto-slow;test-cmn" "${LIBS}" ) diff --git a/test/krypto/test-aes-ciphers.c b/test/krypto/test-aes-ciphers.c index d8fcd469b..1c9034f4c 100644 --- a/test/krypto/test-aes-ciphers.c +++ b/test/krypto/test-aes-ciphers.c @@ -35,7 +35,7 @@ */ #define COMPARE_EQ_INV_CIPHER 1 -#include +#include #include #include @@ -270,8 +270,8 @@ bool CipherExample (KCipher * cipher) { uint8_t cipher_text [16]; rc_t rc; - bool passed_key; - bool passed_block; + bool passed_key = false; + bool passed_block = false; memset (cipher_text, 0, sizeof cipher_text); @@ -513,10 +513,10 @@ bool ExampleVector (KCipher * cipher, const example_vectors * ev) uint8_t plain_text [16]; uint32_t Nk; rc_t rc; - bool passed_enckey; - bool passed_deckey; - bool passed_enc; - bool passed_dec; + bool passed_enckey = false; + bool passed_deckey = false; + bool passed_enc = false; + bool passed_dec = false; switch (ev->key_enc.rounds) { @@ -735,12 +735,6 @@ rc_t run () } -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - - const char UsageDefaultName[] = "test-aes_ciphers"; rc_t CC Usage (const Args * args) { @@ -755,16 +749,12 @@ rc_t CC Usage (const Args * args) UsageDefaultName); } - -ver_t CC KAppVersion (void) -{ - return 0; -} -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args * args; rc_t rc; + SetUsage( Usage ); rc = ArgsMakeAndHandle (&args, argc, argv, 0); if (rc == 0) @@ -781,5 +771,7 @@ rc_t CC KMain ( int argc, char *argv [] ) STSMSG (0, ("Passed %d tests out of 28 possible\n", test_count)); if (rc) LOGERR (klogErr, rc, "Exiting with a failure status"); - exit (error_count); + + ArgsRelease( args ); + return error_count; } diff --git a/test/krypto/test-cipher-speed.c b/test/krypto/test-cipher-speed.c index b0433977f..e6b369fb2 100644 --- a/test/krypto/test-cipher-speed.c +++ b/test/krypto/test-cipher-speed.c @@ -23,7 +23,7 @@ * =========================================================================== * */ -#include +#include #include #include @@ -48,17 +48,17 @@ #define OPTION_TIMER "timer" #define ALIAS_TIMER "t" -const char * timer_usage[] = +const char * timer_usage[] = { "time per function in seconds", "Default is 5 seconds", NULL }; -OptDef Options[] = +OptDef Options[] = { { OPTION_TIMER, ALIAS_TIMER, NULL, timer_usage, 1, true, false } }; struct KBlockCipher; -const char * cipher_subtypes[] = +const char * cipher_subtypes[] = { "byte", "vector", @@ -71,7 +71,7 @@ const char * cipher_subtypes[] = }; -const char * cipher_types[] = +const char * cipher_types[] = { "null", "AES" @@ -79,7 +79,7 @@ const char * cipher_types[] = /* "AES cipher" */ }; -rc_t ((* make_functions[4])(KCipher **, kcipher_type)) = +rc_t ((* make_functions[4])(KCipher **, kcipher_type)) = { KCipherTestByteMake, KCipherTestVecMake, @@ -97,7 +97,7 @@ void random_cipher_block () unsigned ix; srand (1); - + for (ix = 0; ix < sizeof cipher_block; ++ix) cipher_block[ix] = (char)rand(); } @@ -135,7 +135,7 @@ rc_t set_encrypt_key_function_128 (KCipher * cipher) /* just getting some random data - value shouldn't matter much */ if (++ix > sizeof cipher_block - 16) ix = 0; - + memmove (user_key, cipher_block + ix, sizeof user_key); return KCipherSetEncryptKey (cipher, user_key, 16); } @@ -174,7 +174,7 @@ rc_t set_decrypt_key_function_128 (KCipher * cipher) /* just getting some random data - value shouldn't matter much */ if (++ix > sizeof cipher_block - 16) ix = 0; - + memmove (user_key, cipher_block + ix, sizeof user_key); return KCipherSetDecryptKey (cipher, user_key, 16); } @@ -213,7 +213,7 @@ rc_t encrypt_function (KCipher * cipher) /* just getting some random data - value shouldn't matter much */ if (++ix > sizeof cipher_block - 16) ix = 0; - + return KCipherEncrypt (cipher, cipher_block + ix, cipher_block + ix); } @@ -225,7 +225,7 @@ rc_t decrypt_function (KCipher * cipher) /* just getting some random data - value shouldn't matter much */ if (++ix > sizeof cipher_block - 16) ix = 0; - + return KCipherDecrypt (cipher, cipher_block + ix, cipher_block + ix); } @@ -237,7 +237,7 @@ rc_t ecb_encrypt_function (KCipher * cipher) /* just getting some random data - value shouldn't matter much */ if (++ix > sizeof cipher_block - 16) ix = 0; - + return KCipherEncryptECB (cipher, cipher_block, cipher_block, sizeof (cipher_block) / 16); } @@ -249,7 +249,7 @@ rc_t ecb_decrypt_function (KCipher * cipher) /* just getting some random data - value shouldn't matter much */ if (++ix > sizeof cipher_block - 16) ix = 0; - + return KCipherDecryptECB (cipher, cipher_block, cipher_block, sizeof (cipher_block) / 16); } @@ -261,7 +261,7 @@ rc_t cbc_encrypt_function (KCipher * cipher) /* just getting some random data - value shouldn't matter much */ if (++ix > sizeof cipher_block - 16) ix = 0; - + return KCipherEncryptCBC (cipher, cipher_block, cipher_block, sizeof (cipher_block) / 16); } @@ -273,7 +273,7 @@ rc_t cbc_decrypt_function (KCipher * cipher) /* just getting some random data - value shouldn't matter much */ if (++ix > sizeof cipher_block - 16) ix = 0; - + return KCipherDecryptCBC (cipher, cipher_block, cipher_block, sizeof (cipher_block) / 16); } @@ -479,7 +479,7 @@ rc_t run_one (KCipher * ciphers[16], clock_t timer, unsigned ix) else { - KStsMsg ("ecb_decrypt_function\n"); + KStsMsg ("ecb_decrypt_function\n"); rc = function_timer(ecb_decrypt_function, ciphers, ecb_decrypt_256+ix, timer); if (rc) KStsMsg ("failed to run ecb_decrypt_function\n"); @@ -862,18 +862,14 @@ rc_t CC Usage (const Args * args) return rc; } - -ver_t CC KAppVersion (void) -{ - return 0; -} - - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args * args; rc_t rc; + SetUsageSummary( UsageSummary ); + SetUsage( Usage ); + rc = KStsHandlerSetStdErr(); if (rc == 0) { diff --git a/test/krypto/test-csprng.c b/test/krypto/test-csprng.c index d0281a436..3b7380aaa 100644 --- a/test/krypto/test-csprng.c +++ b/test/krypto/test-csprng.c @@ -66,7 +66,7 @@ rc_t run() uint32_t ix; OUTMSG (("KCSPRng with no seed\n")); - + for (ix = 0; ix < 10; ++ix) { uint8_t buff [8]; @@ -103,7 +103,7 @@ rc_t run() else { OUTMSG (("KCSPRng with seed\n")); - + for (ix = 0; ix < 10; ++ix) { uint8_t buff [8]; @@ -156,9 +156,9 @@ rc_t run() buff[4], buff[5], buff[6], buff[7])); } } - } + } } - } + } KRngRelease (rng); } } @@ -201,16 +201,14 @@ rc_t CC Usage (const Args * args) return rc; } - -ver_t CC KAppVersion (void) -{ - return 0; -} -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args * args; rc_t rc; + SetUsageSummary( UsageSummary ); + SetUsage( Usage ); + rc = ArgsMakeAndHandle (&args, argc, argv, 0); if (rc == 0) { @@ -226,5 +224,5 @@ rc_t CC KMain ( int argc, char *argv [] ) LOGERR (klogErr, rc, "Exiting status"); else STSMSG (0, ("Exiting status (%R)\n", rc)); - return rc; + return (int)rc; } diff --git a/test/krypto/test-encdec.cpp b/test/krypto/test-encdec.cpp index e0ffa832d..1906dccf1 100644 --- a/test/krypto/test-encdec.cpp +++ b/test/krypto/test-encdec.cpp @@ -51,25 +51,25 @@ TEST_CASE(KEncryptDecrypt) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char enc_file_path_fmt [] = TMP_FOLDER "/enc_file%llu"; KFile * enc_file, * pt_file; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + uint64_t file_sizes_n_32k[] = { 0, 1, 2, 10, 46, 51 }; int8_t file_size_variants[] = { -2, -1, 0, 1, 2 }; - + const uint8_t* file_fillers[] = { (const uint8_t *)"\0", (const uint8_t *)"\1\2\3\0" }; size_t file_fillers_sizes[] = { 1, 4 }; - + assert( sizeof file_fillers / sizeof file_fillers[0] == sizeof file_fillers_sizes / sizeof file_fillers_sizes[0] ); - + for (size_t filler_index = 0; filler_index < sizeof file_fillers / sizeof file_fillers[0]; ++filler_index ) { printf("filler pattern: "); @@ -86,49 +86,49 @@ TEST_CASE(KEncryptDecrypt) { continue; } - + uint64_t file_size = file_sizes_n_32k[i] * BLOCK_32K_SIZE + file_size_variants[j]; - + char file_path[1024]; - sprintf(file_path, enc_file_path_fmt, ( long long unsigned int ) file_size); - + snprintf(file_path, sizeof(file_path), enc_file_path_fmt, ( long long unsigned int ) file_size); + printf("encrypting/decrypting file %s, size: %llu, i: %zu, j: %zu\n", file_path, ( long long unsigned int ) file_size, i, j); - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_ReadWrite, &key, &enc_file ) ); - + // write file REQUIRE_RC ( TFillFile( enc_file, file_fillers[filler_index], file_fillers_sizes[filler_index], file_size ) ); - + uint64_t size_data_actual; REQUIRE_RC ( KFileSize ( enc_file, &size_data_actual ) ); - + // check content size REQUIRE ( file_size == size_data_actual ); - + REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // check raw file size and checksums REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); - + uint64_t size_raw; REQUIRE_RC ( KFileSize ( pt_file, &size_raw ) ); REQUIRE ( size_raw == TEncSizeFromPtSize(size_data_actual) ); - + REQUIRE_RC ( KEncFileValidate( pt_file ) ); - + REQUIRE_RC ( KFileRelease ( pt_file ) ); - + // check file content REQUIRE_RC ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) ); - + REQUIRE_RC ( TCheckFileContent( enc_file, file_fillers[filler_index], file_fillers_sizes[filler_index] ) ); - + REQUIRE_RC ( KFileRelease ( enc_file ) ); } } } - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } @@ -138,16 +138,16 @@ TEST_CASE(KDecryptZeroRawSize) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/zero_size_file_to_dec"; KFile * enc_file, * pt_file; - + uint64_t file_size; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); // create file @@ -155,11 +155,11 @@ TEST_CASE(KDecryptZeroRawSize) REQUIRE_RC ( KFileSize ( pt_file, &file_size ) ); REQUIRE ( file_size == 0 ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + LOGMSG ( klogWarn, "Expect errors after this line:" ); REQUIRE ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) == RC( rcKrypto, rcFile, rcConstructing, rcSize, rcIncorrect ) ); LOGMSG ( klogWarn, "No more errors are expected" ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } @@ -169,33 +169,33 @@ TEST_CASE(KDecryptZeroContentSizeRW) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/zero_content_rw_file_to_dec"; KFile * enc_file, * pt_file; - + uint64_t file_size; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_ReadWrite, &key, &enc_file ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // check raw size REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); REQUIRE_RC ( KFileSize ( pt_file, &file_size ) ); REQUIRE ( file_size == sizeof(KEncFileHeader) + sizeof(KEncFileFooter) ); REQUIRE_RC ( KEncFileValidate( pt_file ) ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + // check enc open REQUIRE_RC ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } @@ -205,16 +205,16 @@ TEST_CASE(KDecryptZeroContentSizeWOnly) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/zero_content_w_file_to_dec"; KFile * enc_file, * pt_file; - + uint64_t file_size; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, "temp" #if defined(__APPLE__) @@ -222,22 +222,22 @@ TEST_CASE(KDecryptZeroContentSizeWOnly) #else "linux"); #endif - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key, &enc_file ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // check raw size REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); REQUIRE_RC ( KFileSize ( pt_file, &file_size ) ); REQUIRE ( file_size == sizeof(KEncFileHeader) + sizeof(KEncFileFooter) ); REQUIRE_RC ( KEncFileValidate( pt_file ) ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + // check enc open REQUIRE_RC ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } @@ -248,30 +248,30 @@ TEST_CASE(KDectryptOnlyHeader) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/file_only_header"; KFile * enc_file, * pt_file; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, (const uint8_t *)"\0\1", 2, 500 ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // truncate it to header size REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_ReadWrite, &pt_file ) ); REQUIRE_RC ( KFileSetSize ( pt_file, sizeof(KEncFileHeader) ) ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + LOGMSG ( klogWarn, "Expect errors after this line:" ); REQUIRE ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) == RC( rcKrypto, rcFile, rcConstructing, rcSize, rcIncorrect ) ); LOGMSG ( klogWarn, "No more errors are expected" ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } @@ -281,32 +281,32 @@ TEST_CASE(KDectryptWithoutFooter) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/file_no_footer"; KFile * enc_file, * pt_file; - + uint64_t file_size; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, (const uint8_t *)"\0\1", 2, 500 ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // truncate footer REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_ReadWrite, &pt_file ) ); REQUIRE_RC ( KFileSize ( pt_file, &file_size ) ); REQUIRE_RC ( KFileSetSize ( pt_file, file_size - sizeof(KEncFileFooter) ) ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + LOGMSG ( klogWarn, "Expect errors after this line:" ); REQUIRE ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) == RC( rcKrypto, rcFile, rcConstructing, rcSize, rcIncorrect ) ); LOGMSG ( klogWarn, "No more errors are expected" ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } @@ -316,26 +316,26 @@ TEST_CASE(KDectryptCorruptHeader) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/file_corrupt_header"; KFile * enc_file, * pt_file; - + const size_t buffer_size = sizeof(KEncFileHeader); size_t num_written; uint8_t buffer[buffer_size]; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, (const uint8_t *)"\0\1", 2, 500 ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // corrupt header REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_ReadWrite, &pt_file ) ); REQUIRE_RC ( KFileReadAll ( pt_file, 0, buffer, buffer_size, &num_written ) ); @@ -343,11 +343,11 @@ TEST_CASE(KDectryptCorruptHeader) REQUIRE_RC ( KFileWriteAll ( pt_file, 0, buffer, buffer_size, &num_written ) ); assert(buffer_size == num_written); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + LOGMSG ( klogWarn, "Expect errors after this line:" ); REQUIRE ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) == RC( rcFS, rcFile, rcConstructing, rcHeader, rcInvalid ) ); LOGMSG ( klogWarn, "No more errors are expected" ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } @@ -357,7 +357,7 @@ TEST_CASE(KDectryptCorruptFooterCrc) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/file_corrupt_footer_crc"; KFile * enc_file, * pt_file; @@ -366,18 +366,18 @@ TEST_CASE(KDectryptCorruptFooterCrc) const size_t buffer_size = sizeof(KEncFileFooter); size_t num_written, num_read; uint8_t buffer[buffer_size]; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, (const uint8_t *)"\0\1", 2, 500 ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // corrupt footer REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_ReadWrite, &pt_file ) ); REQUIRE_RC ( KFileSize ( pt_file, &file_size ) ); @@ -387,13 +387,13 @@ TEST_CASE(KDectryptCorruptFooterCrc) REQUIRE_RC ( KFileWriteAll ( pt_file, file_size - buffer_size, buffer, buffer_size, &num_written ) ); assert(buffer_size == num_written); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); LOGMSG ( klogWarn, "Expect errors after this line:" ); REQUIRE ( KEncFileValidate( pt_file ) == RC(rcKrypto, rcFile, rcValidating, rcChecksum, rcCorrupt) ); LOGMSG ( klogWarn, "No more errors are expected" ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); @@ -404,27 +404,27 @@ TEST_CASE(KDectryptCorruptFooterBlockCount) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/file_corrupt_footer_block_count"; KFile * enc_file, * pt_file; - + uint64_t file_size; const size_t buffer_size = sizeof(KEncFileFooter); size_t num_written, num_read; uint8_t buffer[buffer_size]; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, (const uint8_t *)"\0\1", 2, 500 ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // corrupt footer REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_ReadWrite, &pt_file ) ); REQUIRE_RC ( KFileSize ( pt_file, &file_size ) ); @@ -434,13 +434,13 @@ TEST_CASE(KDectryptCorruptFooterBlockCount) REQUIRE_RC ( KFileWriteAll ( pt_file, file_size - buffer_size, buffer, buffer_size, &num_written ) ); assert(buffer_size == num_written); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); LOGMSG ( klogWarn, "Expect errors after this line:" ); REQUIRE ( KEncFileValidate( pt_file ) == RC(rcKrypto, rcFile, rcValidating, rcSize, rcIncorrect) ); LOGMSG ( klogWarn, "No more errors are expected" ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); @@ -451,27 +451,27 @@ TEST_CASE(KDectryptCorruptBlockStruct) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/file_corrupt_block_struct"; KFile * enc_file, * pt_file; - + uint64_t file_size; const size_t buffer_size = sizeof(KEncFileBlock); size_t num_written, num_read; uint8_t buffer[buffer_size]; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, (const uint8_t *)"\0\1", 2, 500 ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // corrupt block struct REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_ReadWrite, &pt_file ) ); REQUIRE_RC ( KFileSize ( pt_file, &file_size ) ); @@ -481,13 +481,13 @@ TEST_CASE(KDectryptCorruptBlockStruct) REQUIRE_RC ( KFileWriteAll ( pt_file, file_size - sizeof(KEncFileFooter) - buffer_size, buffer, buffer_size, &num_written ) ); assert(buffer_size == num_written); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); LOGMSG ( klogWarn, "Expect errors after this line:" ); REQUIRE ( KEncFileValidate( pt_file ) == RC(rcKrypto, rcFile, rcValidating, rcChecksum, rcCorrupt) ); LOGMSG ( klogWarn, "No more errors are expected" ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); @@ -498,27 +498,27 @@ TEST_CASE(KDectryptCorruptBlockData) const char pw [] = "first pw"; KKey key; REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - + const char file_path [] = TMP_FOLDER "/file_corrupt_block_data"; KFile * enc_file, * pt_file; - + uint64_t file_size; const size_t buffer_size = sizeof(KEncFileBlock); size_t num_written, num_read; uint8_t buffer[buffer_size]; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, (const uint8_t *)"\0\1", 2, 500 ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + // corrupt block struct REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_ReadWrite, &pt_file ) ); REQUIRE_RC ( KFileSize ( pt_file, &file_size ) ); @@ -534,7 +534,7 @@ TEST_CASE(KDectryptCorruptBlockData) REQUIRE ( KEncFileValidate( pt_file ) == RC(rcKrypto, rcFile, rcValidating, rcChecksum, rcCorrupt) ); LOGMSG ( klogWarn, "No more errors are expected" ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); @@ -548,28 +548,28 @@ TEST_CASE(KDectryptInvalidKey) KKey key1, key2; REQUIRE_RC (KKeyInitUpdate (&key1, kkeyAES128, pw1, strlen (pw1))); REQUIRE_RC (KKeyInitUpdate (&key2, kkeyAES128, pw2, strlen (pw2))); - + const char file_path [] = TMP_FOLDER "/enc_file_invalid_key"; KFile * enc_file; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key1, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, (const uint8_t *)"\0\1", 2, 500 ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + REQUIRE_RC ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key2, &enc_file ) ); LOGMSG ( klogWarn, "Expect errors after this line:" ); REQUIRE ( TCheckFileContent( enc_file, (const uint8_t *)"\0\1", 2 ) == RC( rcKrypto, rcFile, rcValidating, rcEncryption, rcCorrupt ) ); LOGMSG ( klogWarn, "No more errors are expected" ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); @@ -577,31 +577,8 @@ TEST_CASE(KDectryptInvalidKey) //////////////////////////////////////////// Main -extern "C" +int main( int argc, char *argv [] ) { - - ver_t CC KAppVersion ( void ) - { - return 0x1000000; - } - - rc_t CC UsageSummary (const char * prog_name) - { - return 0; - } - - rc_t CC Usage ( const Args * args) - { - return 0; - } - - const char UsageDefaultName[] = "test-encdec"; - - rc_t CC KMain ( int argc, char *argv [] ) - { - KConfigDisableUserSettings(); - rc_t rc=KEncDecTestSuite(argc, argv); - return rc; - } - + KConfigDisableUserSettings(); + return KEncDecTestSuite(argc, argv); } diff --git a/test/krypto/test-hash-in-pwd.cpp b/test/krypto/test-hash-in-pwd.cpp index 86d949b43..ade8e0423 100644 --- a/test/krypto/test-hash-in-pwd.cpp +++ b/test/krypto/test-hash-in-pwd.cpp @@ -30,7 +30,7 @@ #include /* VFSManagerRelease */ #include /* VFSManagerMakeFromKfg */ - + #include /* TEST_SUITE_WITH_ARGS_HANDLER */ static rc_t argsHandler(int argc, char * argv[]) { @@ -98,21 +98,10 @@ TEST_CASE(TestFile) { REQUIRE_RC(KConfigRelease(kfg)); } -const char UsageDefaultName[] = "test-hash-in-pwd"; -rc_t CC UsageSummary(const char * progname) { return 0; } -rc_t CC Usage(const Args * args) { return 0; } - -extern "C" { - - ver_t CC KAppVersion(void) { return 0; } - - int KMain(int argc, char *argv[]) { - KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg - - rc_t rc = TestHashInPwd(argc, argv); - return rc; - } +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg + return TestHashInPwd(argc, argv); } /******************************************************************************/ diff --git a/test/krypto/test-krypto-slow.cpp b/test/krypto/test-krypto-slow.cpp deleted file mode 100644 index 5b15437ef..000000000 --- a/test/krypto/test-krypto-slow.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/*=========================================================================== - * - * PUBLIC DOMAIN NOTICE - * National Center for Biotechnology Information - * - * This software/database is a "United States Government Work" under the - * terms of the United States Copyright Act. It was written as part of - * the author's official duties as a United States Government employee and - * thus cannot be copyrighted. This software/database is freely available - * to the public for use. The National Library of Medicine and the U.S. - * Government have not placed any restriction on its use or reproduction. - * - * Although all reasonable efforts have been taken to ensure the accuracy - * and reliability of the software and data, the NLM and the U.S. - * Government do not and cannot warrant the performance or results that - * may be obtained by using this software or data. The NLM and the U.S. - * Government disclaim all warranties, express or implied, including - * warranties of performance, merchantability or fitness for any particular - * purpose. - * - * Please cite the author in any work or product based on this material. - * - * =========================================================================== - * - */ - -/** - * Unit tests for KReencTestSuite - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "test-cmn.hpp" - -#include -#include - -TEST_SUITE(KKryptoSlowTestSuite); - -// check for file sizes which can only fit into 64-bit -TEST_CASE(KReencryptBigSparseFile) -{ - rc_t rc; - bool space_exhausted = false; - - const char pw2 [] = "second pw"; - KKey key_reenc; - REQUIRE_RC (KKeyInitUpdate (&key_reenc, kkeyAES128, pw2, strlen (pw2))); - - const char file_path [] = TMP_FOLDER "/big_file"; - - const char file_path_reenc [] = TMP_FOLDER "/big_file_reenc"; - - KFile * pt_file, *reenc_file, * reenc_pt_file; - - uint64_t file_size = 5LL * 1024 * 1024 * 1024; - uint64_t pt_size, reenc_size; - - struct KDirectory * current_dir; - REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - - // just in case if it still there - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - - // create file - REQUIRE_RC ( TCreatePtFile( current_dir, file_path, TFileOpenMode_Write, &pt_file ) ); - REQUIRE_RC ( KFileSetSize( pt_file, file_size ) ); - REQUIRE_RC ( KFileRelease ( pt_file ) ); - - REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); - REQUIRE_RC ( KEncryptFileMakeRead( (const KFile **)&reenc_file, (const KFile *)pt_file, &key_reenc ) ); - - REQUIRE_RC ( KFileSize ( pt_file, &pt_size ) ); - REQUIRE_RC ( KFileSize ( reenc_file, &reenc_size ) ); - - REQUIRE ( reenc_size == TEncSizeFromPtSize(pt_size) ); - - REQUIRE_RC ( TCreatePtFile( current_dir, file_path_reenc, TFileOpenMode_Write, &reenc_pt_file ) ); - - rc = TCopyFile( reenc_pt_file, reenc_file ); - if (rc != 0 && GetRCObject(rc) == static_cast ( rcStorage ) - && GetRCState(rc) == rcExhausted) - { - space_exhausted = true; - printf("WARNING! Test failed due to absence of free FS space - SKIPPING\n"); - } - else - { - REQUIRE_RC ( rc ); - } - - REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); - REQUIRE_RC ( KFileRelease ( reenc_file ) ); - REQUIRE_RC ( KFileRelease ( pt_file ) ); - - if ( !space_exhausted ) - { - // check file content - REQUIRE_RC ( TOpenEncFile( current_dir, file_path_reenc, TFileOpenMode_Read, &key_reenc, &reenc_file ) ); - - REQUIRE_RC ( TCheckFileContent( reenc_file, (const uint8_t *)"\0", 1 ) ); - - REQUIRE_RC ( KFileRelease ( reenc_file ) ); - } - - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); -} - -TEST_CASE(KReencrypt4GbMarginsSparseFiles) -{ - rc_t rc; - bool space_exhausted = false; - - const char pw2 [] = "second pw"; - KKey key_reenc; - REQUIRE_RC (KKeyInitUpdate (&key_reenc, kkeyAES128, pw2, strlen (pw2))); - - const char file_path [] = TMP_FOLDER "/big_4gb_file"; - - const char file_path_reenc [] = TMP_FOLDER "/big_4gb_file_reenc"; - - KFile * pt_file, *reenc_file, * reenc_pt_file; - - uint64_t file_size = 4LL * 1024 * 1024 * 1024; - uint64_t pt_size, reenc_size; - - struct KDirectory * current_dir; - REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - - int8_t size_variants[] = { -1, 1 }; - for (size_t i = 0; i < sizeof size_variants / sizeof size_variants[0]; ++i ) - { - // just in case if it still there - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - - // create file - REQUIRE_RC ( TCreatePtFile( current_dir, file_path, TFileOpenMode_Write, &pt_file ) ); - REQUIRE_RC ( KFileSetSize( pt_file, file_size + size_variants[i] ) ); - REQUIRE_RC ( KFileRelease ( pt_file ) ); - - REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); - REQUIRE_RC ( KEncryptFileMakeRead( (const KFile **)&reenc_file, (const KFile *)pt_file, &key_reenc ) ); - - REQUIRE_RC ( KFileSize ( pt_file, &pt_size ) ); - REQUIRE_RC ( KFileSize ( reenc_file, &reenc_size ) ); - - REQUIRE ( file_size + size_variants[i] == pt_size ); - REQUIRE ( reenc_size == TEncSizeFromPtSize(pt_size) ); - - REQUIRE_RC ( TCreatePtFile( current_dir, file_path_reenc, TFileOpenMode_Write, &reenc_pt_file ) ); - rc = TCopyFile( reenc_pt_file, reenc_file ); - if (rc != 0 && GetRCObject(rc) == static_cast ( rcStorage ) - && GetRCState(rc) == rcExhausted) - { - space_exhausted = true; - printf("WARNING! Test failed due to absence of free FS space - SKIPPING\n"); - } - else - { - REQUIRE_RC ( rc ); - } - - REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); - REQUIRE_RC ( KFileRelease ( reenc_file ) ); - REQUIRE_RC ( KFileRelease ( pt_file ) ); - - if ( !space_exhausted ) - { - // check file content - REQUIRE_RC ( TOpenEncFile( current_dir, file_path_reenc, TFileOpenMode_Read, &key_reenc, &reenc_file ) ); - - REQUIRE_RC ( TCheckFileContent( reenc_file, (const uint8_t *)"\0", 1 ) ); - - REQUIRE_RC ( KFileRelease ( reenc_file ) ); - } - - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - if ( space_exhausted ) - { - break; - } - } - REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); -} - -TEST_CASE(KEncDecBigFile) -{ - if ( getenv ( "NOT_VERY_SLOW" ) ) { - TEST_MESSAGE ( "SKIPPING VERY SLOW " << GetName () ); - return; - } - - rc_t rc; - bool space_exhausted = false; - - const char pw [] = "first pw"; - KKey key; - REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - - const char file_path [] = TMP_FOLDER "/enc_big_file"; - - KFile * enc_file, * pt_file; - - uint64_t file_size = 5LL * 1024 * 1024 * 1024; - - struct KDirectory * current_dir; - REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - - // just in case if it still there - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - - // create file - REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_ReadWrite, &key, &enc_file ) ); - - // write file - rc = TFillFile( enc_file, (const uint8_t *)"\1\5", 2, file_size ); - if (rc != 0 && GetRCObject(rc) == static_cast ( rcStorage ) - && GetRCState(rc) == rcExhausted) - { - space_exhausted = true; - printf("WARNING! Test failed due to absence of free FS space - SKIPPING\n"); - } - else - { - REQUIRE_RC ( rc ); - } - - uint64_t size_data_actual; - if ( !space_exhausted ) - { - REQUIRE_RC ( KFileSize ( enc_file, &size_data_actual ) ); - - // check content size - REQUIRE ( file_size == size_data_actual ); - } - rc = KFileRelease ( enc_file ); - if (!space_exhausted ) - { - // we write file footer when closing file, which may fail too - if (rc != 0 && GetRCObject(rc) == static_cast ( rcStorage ) - && GetRCState(rc) == rcExhausted) - { - space_exhausted = true; - printf("WARNING! Test failed due to absence of free FS space - SKIPPING\n"); - } - else - { - REQUIRE_RC ( rc ); - } - } - - if ( !space_exhausted ) - { - // check plaintext file size and checksums - REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); - - uint64_t size_pt; - REQUIRE_RC ( KFileSize ( pt_file, &size_pt ) ); - REQUIRE ( size_pt == TEncSizeFromPtSize(size_data_actual) ); - - REQUIRE_RC ( KEncFileValidate( pt_file ) ); - - REQUIRE_RC ( KFileRelease ( pt_file ) ); - - // check file content - REQUIRE_RC ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) ); - - REQUIRE_RC ( TCheckFileContent( enc_file, (const uint8_t *)"\1\5", 2 ) ); - - REQUIRE_RC ( KFileRelease ( enc_file ) ); - } - - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); -} - -TEST_CASE(KEncDec4GbMarginsFiles) -{ - if ( getenv ( "NOT_VERY_SLOW" ) ) { - TEST_MESSAGE ( "SKIPPING VERY SLOW " << GetName () ); - return; - } - - rc_t rc; - bool space_exhausted = false; - - const char pw [] = "first pw"; - KKey key; - REQUIRE_RC (KKeyInitUpdate (&key, kkeyAES128, pw, strlen (pw))); - - const char file_path [] = TMP_FOLDER "/enc_4gb_file"; - - KFile * enc_file, * pt_file; - - uint64_t file_size = 4LL * 1024 * 1024 * 1024; - - struct KDirectory * current_dir; - REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - - int8_t size_variants[] = { -1, 1 }; - for (size_t i = 0; i < sizeof size_variants / sizeof size_variants[0]; ++i ) - { - // just in case if it still there - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - - // create file - REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_ReadWrite, &key, &enc_file ) ); - - // write file - rc = TFillFile( enc_file, (const uint8_t *)"\4\3", 2, file_size ); - if (rc != 0 && GetRCObject(rc) == static_cast ( rcStorage ) - && GetRCState(rc) == rcExhausted) - { - space_exhausted = true; - printf("WARNING! Test failed due to absence of free FS space - SKIPPING\n"); - } - else - { - REQUIRE_RC ( rc ); - } - - uint64_t size_data_actual; - if ( !space_exhausted ) - { - REQUIRE_RC ( KFileSize ( enc_file, &size_data_actual ) ); - - // check content size - REQUIRE ( file_size == size_data_actual ); - } - rc = KFileRelease ( enc_file ); - if ( !space_exhausted ) - { - if (rc != 0 && - GetRCObject(rc) == static_cast ( rcStorage ) && - GetRCState(rc) == rcExhausted) - { - // we write file footer when closing file, which may fail too - space_exhausted = true; - printf("WARNING! Test failed due to absence of free FS space - SKIPPING\n"); - } - else - { - REQUIRE_RC ( rc ); - } - } - - if ( !space_exhausted ) - { - // check plaintext file size and checksums - REQUIRE_RC ( TOpenPtFile ( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); - - uint64_t size_pt; - REQUIRE_RC ( KFileSize ( pt_file, &size_pt ) ); - REQUIRE ( size_pt == TEncSizeFromPtSize(size_data_actual) ); - - REQUIRE_RC ( KEncFileValidate( pt_file ) ); - - REQUIRE_RC ( KFileRelease ( pt_file ) ); - - // check file content - REQUIRE_RC ( TOpenEncFile( current_dir, file_path, TFileOpenMode_Read, &key, &enc_file ) ); - - REQUIRE_RC ( TCheckFileContent( enc_file, (const uint8_t *)"\4\3", 2 ) ); - - REQUIRE_RC ( KFileRelease ( enc_file ) ); - } - - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - if ( space_exhausted ) - { - break; - } - } - - REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); -} - -//////////////////////////////////////////// Main - -extern "C" -{ - - ver_t CC KAppVersion ( void ) - { - return 0x1000000; - } - - rc_t CC UsageSummary (const char * prog_name) - { - return 0; - } - - rc_t CC Usage ( const Args * args) - { - return 0; - } - - const char UsageDefaultName[] = "test-krypto-slow"; - - rc_t CC KMain ( int argc, char *argv [] ) - { - KConfigDisableUserSettings(); - ncbi::NK::TestEnv::SetVerbosity(ncbi::NK::LogLevel::e_all); - rc_t rc=KKryptoSlowTestSuite(argc, argv); - return rc; - } - -} diff --git a/test/krypto/test-modes.c b/test/krypto/test-modes.c index 1ab5a908f..cdc3d5bb7 100644 --- a/test/krypto/test-modes.c +++ b/test/krypto/test-modes.c @@ -24,7 +24,6 @@ * */ -#include #include #include @@ -139,8 +138,8 @@ uint8_t AES_ECB_192_cipher[4][16] = 0xfb, 0x16, 0x69, 0x16, 0x03, 0xc1, 0x8e, 0x0e } }; - -uint8_t AES_ECB_256_key[32] = + +uint8_t AES_ECB_256_key[32] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, @@ -148,7 +147,7 @@ uint8_t AES_ECB_256_key[32] = 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 }; -uint8_t AES_ECB_256_test[4][16] = +uint8_t AES_ECB_256_test[4][16] = { { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, @@ -158,7 +157,7 @@ uint8_t AES_ECB_256_test[4][16] = 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51 }, - { + { 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef }, @@ -168,7 +167,7 @@ uint8_t AES_ECB_256_test[4][16] = } }; -uint8_t AES_ECB_256_cipher[4][16] = +uint8_t AES_ECB_256_cipher[4][16] = { { 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c, @@ -304,7 +303,7 @@ uint8_t AES_CBC_192_cipher[4][16] = 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8 }, { - 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4, + 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4, 0xe5, 0xe7, 0x38, 0x76, 0x3f, 0x69, 0x14, 0x5a }, { @@ -485,7 +484,7 @@ uint8_t AES_CFB_192_test[4][16] = 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51 }, { - 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, + 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef }, { @@ -914,15 +913,15 @@ uint8_t AES_CTR_256_cipher[4][16] = 0x60, 0x1e, 0xc3, 0x13, 0x77, 0x57, 0x89, 0xa5, 0xb7, 0xa7, 0xf5, 0x04, 0xbb, 0xf3, 0xd2, 0x28 }, - { + { 0xf4, 0x43, 0xe3, 0xca, 0x4d, 0x62, 0xb5, 0x9a, 0xca, 0x84, 0xe9, 0x90, 0xca, 0xca, 0xf5, 0xc5 }, - { + { 0x2b, 0x09, 0x30, 0xda, 0xa2, 0x3d, 0xe9, 0x4c, 0xe8, 0x70, 0x17, 0xba, 0x2d, 0x84, 0x98, 0x8d }, - { + { 0xdf, 0xc9, 0xc5, 0x8d, 0xb6, 0x7a, 0xad, 0xa6, 0x13, 0xc2, 0xdd, 0x08, 0x45, 0x79, 0x41, 0xa6 } @@ -976,7 +975,7 @@ rc_t run () } } } - } + } /* AES ECB 192 */ KOutMsg ("AES ECB 192\n"); @@ -1013,7 +1012,7 @@ rc_t run () } } } - } + } /* AES ECB 256 */ KOutMsg ("AES ECB 256\n"); @@ -1050,7 +1049,7 @@ rc_t run () } } } - } + } /* AES CBC 128 */ @@ -1096,7 +1095,7 @@ rc_t run () } } } - } + } /* AES CBC 192 */ KOutMsg ("AES CBC 192\n"); @@ -1141,7 +1140,7 @@ rc_t run () } } } - } + } /* AES CBC 256 */ KOutMsg ("AES CBC 256\n"); @@ -1186,7 +1185,7 @@ rc_t run () } } } - } + } KCipherRelease (cipher); } @@ -1206,38 +1205,14 @@ rc_t CC UsageSummary (const char * progname) " Test the KXTocDir type.\n", progname); } -const char UsageDefaultName[] = "test-modes"; -rc_t CC Usage (const Args * args) -{ - return 0; -} -/* { */ -/* const char * progname = UsageDefaultName; */ -/* const char * fullpath = UsageDefaultName; */ -/* rc_t rc = 0; */ -/* rc = ArgsProgram (args, &fullpath, &progname); */ -/* if (rc == 0) */ -/* { */ -/* assert (args); */ -/* summary (UsageDefaultName); */ -/* HelpOptionsStandard (); */ -/* } */ -/* return rc; */ -/* } */ - -/* MINIUSAGE(def_name) */ - - -ver_t CC KAppVersion (void) -{ - return 0; -} -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { Args * args; rc_t rc; + SetUsageSummary( UsageSummary ); + rc = ArgsMakeAndHandle (&args, argc, argv, 0); if (rc == 0) { @@ -1249,13 +1224,13 @@ rc_t CC KMain ( int argc, char *argv [] ) { rc = RC(rcKrypto, rcBuffer, rcValidating, rcEncryption, rcIncorrect); } - + if (rc) LOGERR (klogErr, rc, "Exiting status"); else STSMSG (klogLevelMax, ("Exiting okay\n")); - return rc; + return (int)rc; } diff --git a/test/krypto/test-reenc.cpp b/test/krypto/test-reenc.cpp index c9e3011d2..9f137161a 100644 --- a/test/krypto/test-reenc.cpp +++ b/test/krypto/test-reenc.cpp @@ -52,29 +52,29 @@ TEST_CASE(KReEncryptEncFile) KKey key_enc, key_reenc; REQUIRE_RC (KKeyInitUpdate (&key_enc, kkeyAES128, pw1, strlen (pw1))); REQUIRE_RC (KKeyInitUpdate (&key_reenc, kkeyAES256, pw2, strlen (pw2))); - + const char enc_file_path_fmt [] = TMP_FOLDER "/file_enc%llu"; const char reenc_file_path_fmt [] = TMP_FOLDER "/file_reenc%llu"; KFile * enc_file, * reenc_file, * reenc_pt_file, * enc_pt_file; - + uint64_t enc_pt_size, reenc_size; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + uint64_t file_sizes_n_32k[] = { 0, 1, 2, 10, 46, 51 }; int8_t file_size_variants[] = { -2, -1, 0, 1, 2 }; - + const uint8_t* file_fillers[] = { (const uint8_t *)"\3\5\1\7" }; size_t file_fillers_sizes[] = { 4 }; - + assert( sizeof file_fillers / sizeof file_fillers[0] == sizeof file_fillers_sizes / sizeof file_fillers_sizes[0] ); - + for (size_t filler_index = 0; filler_index < sizeof file_fillers / sizeof file_fillers[0]; ++filler_index ) { printf("filler pattern: "); @@ -91,52 +91,52 @@ TEST_CASE(KReEncryptEncFile) { continue; } - + uint64_t file_size = file_sizes_n_32k[i] * BLOCK_32K_SIZE + file_size_variants[j]; - + char file_path[1024]; char file_path_reenc[1024]; - - sprintf(file_path, enc_file_path_fmt, ( long long unsigned int ) file_size); - sprintf(file_path_reenc, reenc_file_path_fmt, ( long long unsigned int ) file_size); - + + snprintf(file_path, sizeof(file_path), enc_file_path_fmt, ( long long unsigned int ) file_size); + snprintf(file_path_reenc, sizeof(file_path_reenc), reenc_file_path_fmt, ( long long unsigned int ) file_size); + printf("reencrypting encrypted file %s, size: %llu, i: %zu, j: %zu\n", file_path, ( long long unsigned int ) file_size, i, j); - + // create file REQUIRE_RC ( TCreateEncFile( current_dir, file_path, TFileOpenMode_Write, &key_enc, &enc_file ) ); REQUIRE_RC ( TFillFile( enc_file, file_fillers[filler_index], file_fillers_sizes[filler_index], file_size ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &enc_pt_file ) ); REQUIRE_RC ( KReencFileMakeRead( (const KFile **)&reenc_file, (const KFile *)enc_pt_file, &key_enc, &key_reenc ) ); - + REQUIRE_RC ( KFileSize ( enc_pt_file, &enc_pt_size ) ); REQUIRE_RC ( KFileSize ( reenc_file, &reenc_size ) ); - + REQUIRE ( reenc_size == enc_pt_size ) ; - + REQUIRE_RC ( TCreatePtFile( current_dir, file_path_reenc, TFileOpenMode_Write, &reenc_pt_file ) ); REQUIRE_RC ( TCopyFile( reenc_pt_file, reenc_file ) ); - + REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); REQUIRE_RC ( KFileRelease ( reenc_file ) ); REQUIRE_RC ( KFileRelease ( enc_pt_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, file_path_reenc, TFileOpenMode_Read, &reenc_pt_file ) ); REQUIRE_RC ( KEncFileValidate( reenc_pt_file ) ); REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); - + // check file content REQUIRE_RC ( TOpenEncFile( current_dir, file_path_reenc, TFileOpenMode_Read, &key_reenc, &reenc_file ) ); - + REQUIRE_RC ( TCheckFileContent( reenc_file, file_fillers[filler_index], file_fillers_sizes[filler_index] ) ); - + REQUIRE_RC ( KFileRelease ( reenc_file ) ); - + } } } - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); @@ -147,29 +147,29 @@ TEST_CASE(KReEncryptPtFile) const char pw2 [] = "second pw"; KKey key_reenc; REQUIRE_RC (KKeyInitUpdate (&key_reenc, kkeyAES256, pw2, strlen (pw2))); - + const char file_path_fmt [] = TMP_FOLDER "/file%llu"; const char reenc_file_path_fmt [] = TMP_FOLDER "/file_reenc%llu"; KFile * pt_file, *reenc_file, * reenc_pt_file; - + uint64_t pt_size, reenc_size; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + uint64_t file_sizes_n_32k[] = { 0, 1, 2, 10, 46, 51 }; int8_t file_size_variants[] = { -2, -1, 0, 1, 2 }; - + const uint8_t* file_fillers[] = { (const uint8_t *)"\1\5\3\7" }; size_t file_fillers_sizes[] = { 4 }; - + assert( sizeof file_fillers / sizeof file_fillers[0] == sizeof file_fillers_sizes / sizeof file_fillers_sizes[0] ); - + for (size_t filler_index = 0; filler_index < sizeof file_fillers / sizeof file_fillers[0]; ++filler_index ) { printf("filler pattern: "); @@ -186,49 +186,49 @@ TEST_CASE(KReEncryptPtFile) { continue; } - + uint64_t file_size = file_sizes_n_32k[i] * BLOCK_32K_SIZE + file_size_variants[j]; - + char file_path[1024]; char file_path_reenc[1024]; - - sprintf(file_path, file_path_fmt, ( long long unsigned int ) file_size); - sprintf(file_path_reenc, reenc_file_path_fmt, ( long long unsigned int ) file_size); - + + snprintf(file_path, sizeof(file_path), file_path_fmt, ( long long unsigned int ) file_size); + snprintf(file_path_reenc, sizeof(file_path_reenc), reenc_file_path_fmt, ( long long unsigned int ) file_size); + printf("reencrypting NOT encrypted file %s, size: %llu, i: %zu, j: %zu\n", file_path, ( long long unsigned int ) file_size, i, j); - + // create file REQUIRE_RC ( TCreatePtFile( current_dir, file_path, TFileOpenMode_Write, &pt_file ) ); REQUIRE_RC ( TFillFile( pt_file, file_fillers[filler_index], file_fillers_sizes[filler_index], file_size ) ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, file_path, TFileOpenMode_Read, &pt_file ) ); REQUIRE_RC ( KEncryptFileMakeRead( (const KFile **)&reenc_file, (const KFile *)pt_file, &key_reenc ) ); - + REQUIRE_RC ( KFileSize ( pt_file, &pt_size ) ); REQUIRE_RC ( KFileSize ( reenc_file, &reenc_size ) ); - + REQUIRE ( file_size == pt_size ); REQUIRE ( reenc_size == TEncSizeFromPtSize(pt_size) ); - + REQUIRE_RC ( TCreatePtFile( current_dir, file_path_reenc, TFileOpenMode_Write, &reenc_pt_file ) ); REQUIRE_RC ( TCopyFile( reenc_pt_file, reenc_file ) ); - + REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); REQUIRE_RC ( KFileRelease ( reenc_file ) ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + // check file content REQUIRE_RC ( TOpenEncFile( current_dir, file_path_reenc, TFileOpenMode_Read, &key_reenc, &reenc_file ) ); - + REQUIRE_RC ( TCheckFileContent( reenc_file, file_fillers[filler_index], file_fillers_sizes[filler_index] ) ); - + REQUIRE_RC ( KFileRelease ( reenc_file ) ); - + } } } - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); @@ -241,52 +241,53 @@ TEST_CASE(KReencryptZeroContentSizeEncFile) KKey key_enc, key_reenc; REQUIRE_RC (KKeyInitUpdate (&key_enc, kkeyAES128, pw1, strlen (pw1))); REQUIRE_RC (KKeyInitUpdate (&key_reenc, kkeyAES256, pw2, strlen (pw2))); - + const char enc_file_path [] = TMP_FOLDER "/zero_content_file_to_reenc"; const char reenc_file_path [] = TMP_FOLDER "/reenc_zero_content_file"; KFile * enc_file, * enc_pt_file, * reenc_file, * reenc_pt_file; - + uint64_t enc_pt_size, reenc_size; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + KDirectoryRemove ( current_dir, true, enc_file_path ); + KDirectoryRemove ( current_dir, true, reenc_file_path ); + // create file REQUIRE_RC ( TCreateEncFile( current_dir, enc_file_path, TFileOpenMode_Write, &key_enc, &enc_file ) ); REQUIRE_RC ( KFileRelease ( enc_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, enc_file_path, TFileOpenMode_Read, &enc_pt_file ) ); REQUIRE_RC ( KReencFileMakeRead( (const KFile **)&reenc_file, (const KFile *)enc_pt_file, &key_enc, &key_reenc ) ); - + REQUIRE_RC ( KFileSize ( enc_pt_file, &enc_pt_size ) ); REQUIRE_RC ( KFileSize ( reenc_file, &reenc_size ) ); - + REQUIRE ( reenc_size == enc_pt_size ) ; - + REQUIRE_RC ( TCreatePtFile( current_dir, reenc_file_path, TFileOpenMode_Write, &reenc_pt_file ) ); REQUIRE_RC ( TCopyFile( reenc_pt_file, reenc_file ) ); - + REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); REQUIRE_RC ( KFileRelease ( reenc_file ) ); REQUIRE_RC ( KFileRelease ( enc_pt_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, reenc_file_path, TFileOpenMode_Read, &reenc_pt_file ) ); REQUIRE_RC ( KEncFileValidate( reenc_pt_file ) ); REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); - + // check file content REQUIRE_RC ( TOpenEncFile( current_dir, reenc_file_path, TFileOpenMode_Read, &key_reenc, &reenc_file ) ); REQUIRE_RC ( KFileSize ( reenc_file, &reenc_size ) ); REQUIRE ( reenc_size == 0 ); REQUIRE_RC ( KFileRelease ( reenc_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } @@ -295,82 +296,60 @@ TEST_CASE(KReencryptZeroContentSizePtFile) const char pw2 [] = "second pw"; KKey key_reenc; REQUIRE_RC (KKeyInitUpdate (&key_reenc, kkeyAES256, pw2, strlen (pw2))); - + const char pt_file_path [] = TMP_FOLDER "/zero_content_file_to_reenc_pt"; const char reenc_file_path [] = TMP_FOLDER "/reenc_zero_content_file_pt"; KFile * pt_file, * reenc_file, * reenc_pt_file; - + uint64_t pt_size, reenc_size; - + struct KDirectory * current_dir; REQUIRE_RC ( KDirectoryNativeDir ( ¤t_dir ) ); - + // just in case if it still there - KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + KDirectoryRemove ( current_dir, true, pt_file_path ); + KDirectoryRemove ( current_dir, true, reenc_file_path ); + // create file REQUIRE_RC ( TCreatePtFile( current_dir, pt_file_path, TFileOpenMode_Write, &pt_file ) ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, pt_file_path, TFileOpenMode_Read, &pt_file ) ); REQUIRE_RC ( KEncryptFileMakeRead( (const KFile **)&reenc_file, (const KFile *)pt_file, &key_reenc ) ); - + REQUIRE_RC ( KFileSize ( pt_file, &pt_size ) ); REQUIRE_RC ( KFileSize ( reenc_file, &reenc_size ) ); - + REQUIRE ( reenc_size == pt_size + sizeof(KEncFileHeader) + sizeof(KEncFileFooter) ) ; - + REQUIRE_RC ( TCreatePtFile( current_dir, reenc_file_path, TFileOpenMode_Write, &reenc_pt_file ) ); REQUIRE_RC ( TCopyFile( reenc_pt_file, reenc_file ) ); - + REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); REQUIRE_RC ( KFileRelease ( reenc_file ) ); REQUIRE_RC ( KFileRelease ( pt_file ) ); - + REQUIRE_RC ( TOpenPtFile( current_dir, reenc_file_path, TFileOpenMode_Read, &reenc_pt_file ) ); REQUIRE_RC ( KEncFileValidate( reenc_pt_file ) ); REQUIRE_RC ( KFileRelease ( reenc_pt_file ) ); - + // check file content REQUIRE_RC ( TOpenEncFile( current_dir, reenc_file_path, TFileOpenMode_Read, &key_reenc, &reenc_file ) ); REQUIRE_RC ( KFileSize ( reenc_file, &reenc_size ) ); REQUIRE ( reenc_size == 0 ); REQUIRE_RC ( KFileRelease ( reenc_file ) ); - + KDirectoryRemove ( current_dir, true, TMP_FOLDER ); - + REQUIRE_RC ( KDirectoryRelease ( current_dir ) ); } //////////////////////////////////////////// Main -extern "C" +int main( int argc, char *argv [] ) { - - ver_t CC KAppVersion ( void ) - { - return 0x1000000; - } - - rc_t CC UsageSummary (const char * prog_name) - { - return 0; - } - - rc_t CC Usage ( const Args * args) - { - return 0; - } - - const char UsageDefaultName[] = "test-reenc"; - - rc_t CC KMain ( int argc, char *argv [] ) - { - KConfigDisableUserSettings(); - rc_t rc=KReencTestSuite(argc, argv); - return rc; - } - + KConfigDisableUserSettings(); + return KReencTestSuite(argc, argv); } diff --git a/test/krypto/test-rsa-aes-hmac.cpp b/test/krypto/test-rsa-aes-hmac.cpp index 9ab35bd3d..0b387215a 100644 --- a/test/krypto/test-rsa-aes-hmac.cpp +++ b/test/krypto/test-rsa-aes-hmac.cpp @@ -190,12 +190,12 @@ rc_t makePDK ( const char * path, const char * pdk_base64 ) ; } #endif - + KFileRelease ( pdk_file ); } KDirectoryRelease ( wd ); } - + KDataBufferWhack ( & decoded ); } @@ -219,14 +219,14 @@ void whackPDK ( const char * path ) KDirectoryRelease ( wd ); } } - + TEST_SUITE ( KRsaAesHmacTestSuite ); TEST_CASE ( KEncryptDecryptRoundTrip ) { // prepare the parameters - + // parameter 1 - the output buffer // documentation says: // pointer to a ZEROED KDataBuffer that will receive encrypted result. @@ -283,7 +283,7 @@ TEST_CASE ( KEncryptDecryptRoundTrip ) // to decrypt the file designated by "zpdk". "zpwd_size" should be // the total size of the BUFFER, not the size of the password itself. // The buffer will be wiped after first use regardless of success or failure. - // + // // constant PDK_password is given above. char zpwd [ 256 ]; :: strcpy ( zpwd, PDK_password ); @@ -308,7 +308,7 @@ TEST_CASE ( KEncryptDecryptRoundTrip ) TEST_CASE ( KEncryptOneWayForNCBI ) { // prepare the parameters - + // parameter 1 - the output buffer // documentation says: // pointer to a ZEROED KDataBuffer that will receive encrypted result. @@ -394,7 +394,7 @@ TEST_CASE ( KEncryptAlteredPubKeyDecryptRoundTrip ) size_t min_size = ( size_t ) pt_prime . elem_count; if ( min_size > pt_size ) min_size = pt_size; - + REQUIRE_NE ( :: memcmp ( ( const void * ) pt_orig, pt_prime . base, min_size ), 0 ); } @@ -408,7 +408,7 @@ TEST_CASE ( KEncryptAlteredPubKeyDecryptRoundTrip ) TEST_CASE ( KEncryptAlteredPrivKeyDecryptRoundTrip ) { // prepare the parameters - + KDataBuffer ct; :: memset ( & ct, 0, sizeof ct ); @@ -454,7 +454,7 @@ TEST_CASE ( KEncryptAlteredPrivKeyDecryptRoundTrip ) old = '+'; } pdk_base64 [ 250 ] = old; - + const char zpdk [] = "./test-rsa-aes-hmac.pdk"; REQUIRE_RC ( makePDK ( zpdk, pdk_base64 ) ); @@ -475,7 +475,7 @@ TEST_CASE ( KEncryptAlteredPrivKeyDecryptRoundTrip ) size_t min_size = ( size_t ) pt_prime . elem_count; if ( min_size > pt_size ) min_size = pt_size; - + REQUIRE_NE ( :: memcmp ( ( const void * ) pt_orig, pt_prime . base, min_size ), 0 ); } @@ -489,7 +489,7 @@ TEST_CASE ( KEncryptAlteredPrivKeyDecryptRoundTrip ) TEST_CASE ( KEncryptAlteredAESKeyDecryptRoundTrip ) { // prepare the parameters - + KDataBuffer ct; :: memset ( & ct, 0, sizeof ct ); @@ -526,7 +526,7 @@ TEST_CASE ( KEncryptAlteredAESKeyDecryptRoundTrip ) KDataBuffer pt_prime; :: memset ( & pt_prime, 0, sizeof pt_prime ); - + const char zpdk [] = "./test-rsa-aes-hmac.pdk"; REQUIRE_RC ( makePDK ( zpdk ) ); @@ -547,7 +547,7 @@ TEST_CASE ( KEncryptAlteredAESKeyDecryptRoundTrip ) size_t min_size = ( size_t ) pt_prime . elem_count; if ( min_size > pt_size ) min_size = pt_size; - + REQUIRE_NE ( :: memcmp ( ( const void * ) pt_orig, pt_prime . base, min_size ), 0 ); } @@ -561,7 +561,7 @@ TEST_CASE ( KEncryptAlteredAESKeyDecryptRoundTrip ) TEST_CASE ( KEncryptAlteredIVDecryptRoundTrip ) { // prepare the parameters - + KDataBuffer ct; :: memset ( & ct, 0, sizeof ct ); @@ -599,7 +599,7 @@ TEST_CASE ( KEncryptAlteredIVDecryptRoundTrip ) KDataBuffer pt_prime; :: memset ( & pt_prime, 0, sizeof pt_prime ); - + const char zpdk [] = "./test-rsa-aes-hmac.pdk"; REQUIRE_RC ( makePDK ( zpdk ) ); @@ -620,7 +620,7 @@ TEST_CASE ( KEncryptAlteredIVDecryptRoundTrip ) size_t min_size = ( size_t ) pt_prime . elem_count; if ( min_size > pt_size ) min_size = pt_size; - + REQUIRE_NE ( :: memcmp ( ( const void * ) pt_orig, pt_prime . base, min_size ), 0 ); } @@ -634,7 +634,7 @@ TEST_CASE ( KEncryptAlteredIVDecryptRoundTrip ) TEST_CASE ( KEncryptAlteredHMACDecryptRoundTrip ) { // prepare the parameters - + KDataBuffer ct; :: memset ( & ct, 0, sizeof ct ); @@ -671,7 +671,7 @@ TEST_CASE ( KEncryptAlteredHMACDecryptRoundTrip ) KDataBuffer pt_prime; :: memset ( & pt_prime, 0, sizeof pt_prime ); - + const char zpdk [] = "./test-rsa-aes-hmac.pdk"; REQUIRE_RC ( makePDK ( zpdk ) ); @@ -692,7 +692,7 @@ TEST_CASE ( KEncryptAlteredHMACDecryptRoundTrip ) size_t min_size = ( size_t ) pt_prime . elem_count; if ( min_size > pt_size ) min_size = pt_size; - + REQUIRE_NE ( :: memcmp ( ( const void * ) pt_orig, pt_prime . base, min_size ), 0 ); } @@ -706,7 +706,7 @@ TEST_CASE ( KEncryptAlteredHMACDecryptRoundTrip ) TEST_CASE ( KEncryptAlteredCTDecryptRoundTrip ) { // prepare the parameters - + KDataBuffer ct; :: memset ( & ct, 0, sizeof ct ); @@ -737,7 +737,7 @@ TEST_CASE ( KEncryptAlteredCTDecryptRoundTrip ) // limit offset into the ct size_t offset = rsa_aes_size + iv_size; offset = min ( offset, ct_size ); - + // isolate desired block within ct size_t block_size = ct_size - offset; @@ -749,7 +749,7 @@ TEST_CASE ( KEncryptAlteredCTDecryptRoundTrip ) KDataBuffer pt_prime; :: memset ( & pt_prime, 0, sizeof pt_prime ); - + const char zpdk [] = "./test-rsa-aes-hmac.pdk"; REQUIRE_RC ( makePDK ( zpdk ) ); @@ -770,7 +770,7 @@ TEST_CASE ( KEncryptAlteredCTDecryptRoundTrip ) size_t min_size = ( size_t ) pt_prime . elem_count; if ( min_size > pt_size ) min_size = pt_size; - + REQUIRE_NE ( :: memcmp ( ( const void * ) pt_orig, pt_prime . base, min_size ), 0 ); } @@ -784,7 +784,7 @@ TEST_CASE ( KEncryptAlteredCTDecryptRoundTrip ) TEST_CASE ( KEncryptTruncatedResultDecryptRoundTrip ) { // prepare the parameters - + KDataBuffer ct; :: memset ( & ct, 0, sizeof ct ); @@ -808,7 +808,7 @@ TEST_CASE ( KEncryptTruncatedResultDecryptRoundTrip ) KDataBuffer pt_prime; :: memset ( & pt_prime, 0, sizeof pt_prime ); - + const char zpdk [] = "./test-rsa-aes-hmac.pdk"; REQUIRE_RC ( makePDK ( zpdk ) ); @@ -829,7 +829,7 @@ TEST_CASE ( KEncryptTruncatedResultDecryptRoundTrip ) size_t min_size = ( size_t ) pt_prime . elem_count; if ( min_size > pt_size ) min_size = pt_size; - + REQUIRE_NE ( :: memcmp ( ( const void * ) pt_orig, pt_prime . base, min_size ), 0 ); } @@ -843,7 +843,7 @@ TEST_CASE ( KEncryptTruncatedResultDecryptRoundTrip ) TEST_CASE ( KEncryptExtendedResultDecryptRoundTrip ) { // prepare the parameters - + KDataBuffer ct; :: memset ( & ct, 0, sizeof ct ); @@ -867,7 +867,7 @@ TEST_CASE ( KEncryptExtendedResultDecryptRoundTrip ) KDataBuffer pt_prime; :: memset ( & pt_prime, 0, sizeof pt_prime ); - + const char zpdk [] = "./test-rsa-aes-hmac.pdk"; REQUIRE_RC ( makePDK ( zpdk ) ); @@ -888,7 +888,7 @@ TEST_CASE ( KEncryptExtendedResultDecryptRoundTrip ) size_t min_size = ( size_t ) pt_prime . elem_count; if ( min_size > pt_size ) min_size = pt_size; - + REQUIRE_NE ( :: memcmp ( ( const void * ) pt_orig, pt_prime . base, min_size ), 0 ); } @@ -901,30 +901,8 @@ TEST_CASE ( KEncryptExtendedResultDecryptRoundTrip ) //////////////////////////////////////////// Main -extern "C" +int main( int argc, char *argv [] ) { - - ver_t CC KAppVersion ( void ) - { - return 0x1000000; - } - - rc_t CC UsageSummary (const char * prog_name) - { - return 0; - } - - rc_t CC Usage ( const Args * args) - { - return 0; - } - - const char UsageDefaultName[] = "test-rsa-aes-hmac"; - - rc_t CC KMain ( int argc, char *argv [] ) - { - KConfigDisableUserSettings (); - return KRsaAesHmacTestSuite ( argc, argv ); - } - + KConfigDisableUserSettings (); + return KRsaAesHmacTestSuite ( argc, argv ); } diff --git a/test/ktst/ktsttest.cpp b/test/ktst/ktsttest.cpp index a8669c569..01e4b8d5a 100755 --- a/test/ktst/ktsttest.cpp +++ b/test/ktst/ktsttest.cpp @@ -43,13 +43,13 @@ static rc_t argsHandler(int argc, char* argv[]); TEST_SUITE_WITH_ARGS_HANDLER(KtstTestSuite, argsHandler); static -rc_t +rc_t RcSuccess() { return 0; } static -rc_t +rc_t RcFail() { return 1; @@ -72,7 +72,7 @@ TEST_CASE(Requires) CHECK_CLOSE(1.0, 2.0, 1.99); REQUIRE_CLOSE(1.0, -1.0, 2.01); - CHECK_EQUAL(1, 1); + CHECK_EQUAL(1, 1); CHECK_EQ(2.0, 2.0); REQUIRE_EQUAL(-1, -1); REQUIRE_EQ(-11.0f, -11.0f); @@ -131,7 +131,7 @@ PROCESS_TEST_CASE(ChildProcessAbort, SIGFPE, 0) } PROCESS_TEST_CASE(ChildProcessTimeout, TestEnv::TEST_CASE_TIMED_OUT, 1) -{ +{ TEST_MESSAGE("ChildProcessTimeout: sleeping in the child process"); TestEnv::Sleep(2); TEST_MESSAGE("ChildProcessTimeout: did not time out!!"); @@ -139,7 +139,7 @@ PROCESS_TEST_CASE(ChildProcessTimeout, TestEnv::TEST_CASE_TIMED_OUT, 1) } static bool argHandlerCalled = false; -static rc_t argsHandler(int argc, char* argv[]) +static rc_t argsHandler(int argc, char* argv[]) { argHandlerCalled = true; return 0; @@ -207,32 +207,7 @@ TEST_CASE ( SharedSucceedInBlock ) { //TODO: test REQUIRE_THROW, THROW_ON_RC //////////////////////////////////////////// Main -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) +int main ( int argc, char *argv [] ) { - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - - -const char UsageDefaultName[] = "test-kfg"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc=KtstTestSuite(argc, argv); - return rc; -} - + return KtstTestSuite(argc, argv); } diff --git a/test/ncbi-vdb/CMakeLists.txt b/test/ncbi-vdb/CMakeLists.txt index 645acff7d..04e868b2d 100644 --- a/test/ncbi-vdb/CMakeLists.txt +++ b/test/ncbi-vdb/CMakeLists.txt @@ -25,23 +25,28 @@ if( WIN32 ) add_executable( test-link-md test-link ) MSVS_DLLRuntime( test-link-md ) - target_link_libraries( test-link-md ktst-md ncbi-vdb-shared-md kapp-md Ws2_32 ${MBEDTLS_LIBS} ) + target_link_libraries( test-link-md ktst-md ncbi-vdb-shared-md Ws2_32 ${MBEDTLS_LIBS} ) + target_link_options( test-link-md PRIVATE "/ENTRY:mainCRTStartup" ) add_executable( test-link-mt test-link ) MSVS_StaticRuntime( test-link-mt ) - target_link_libraries( test-link-mt ktst kapp ncbi-vdb-shared Ws2_32 ${MBEDTLS_LIBS} ) + target_link_libraries( test-link-mt ktst ncbi-vdb-shared Ws2_32 ${MBEDTLS_LIBS} ) + target_link_options( test-link-mt PRIVATE "/ENTRY:mainCRTStartup" ) add_executable( test-wlink-md test-wlink ) MSVS_DLLRuntime( test-wlink-md ) - target_link_libraries( test-wlink-md ktst-md ncbi-wvdb-shared-md kapp-md Ws2_32 ${MBEDTLS_LIBS} ) + target_link_libraries( test-wlink-md ktst-md ncbi-wvdb-shared-md Ws2_32 ${MBEDTLS_LIBS} ) + target_link_options( test-wlink-md PRIVATE "/ENTRY:mainCRTStartup" ) add_executable( test-wlink-mt test-wlink ) MSVS_StaticRuntime( test-wlink-mt ) - target_link_libraries( test-wlink-mt ktst kapp ncbi-wvdb-shared Ws2_32 ${MBEDTLS_LIBS} ) + target_link_libraries( test-wlink-mt ktst ncbi-wvdb-shared Ws2_32 ${MBEDTLS_LIBS} ) + target_link_options( test-wlink-mt PRIVATE "/ENTRY:mainCRTStartup" ) + elseif( NOT HAVE_MBEDTLS_F ) if ( CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$" OR CMAKE_C_COMPILER_ID MATCHES "^(Apple)?Clang$") message("ncbi-vdb: ignoring so_check check test for clang") - elseif() + else() add_test( NAME Test_NCBI_VDB_vdb COMMAND ./so_check.sh ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libncbi-vdb.so WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_test( NAME Test_NCBI_VDB_wvdb COMMAND ./so_check.sh ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libncbi-wvdb.so WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/test/ncbi-vdb/so_check.sh b/test/ncbi-vdb/so_check.sh index d88fde8de..b2ea65fef 100755 --- a/test/ncbi-vdb/so_check.sh +++ b/test/ncbi-vdb/so_check.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/bin/sh -K=$(nm $1 | grep " U " | grep -v GLIBC | grep -v " U xml"); -if [ "$K" != "" ]; +K=$(nm $1 | grep " U " | grep -v GLIBC | grep -v " U xml " | grep -v @CXXABI_); +if [ "$K" != "" ] then echo "Error: $1 contains unresolved external references:\n $K" && exit 1; -fi \ No newline at end of file +fi diff --git a/test/ncbi-vdb/test-link.cpp b/test/ncbi-vdb/test-link.cpp index c26407694..aad635f48 100644 --- a/test/ncbi-vdb/test-link.cpp +++ b/test/ncbi-vdb/test-link.cpp @@ -24,33 +24,12 @@ //////////////////////////////////////////// Main -extern "C" -{ - -#include #include -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-link"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); return 0; } -} diff --git a/test/ncbi-vdb/test-wlink.cpp b/test/ncbi-vdb/test-wlink.cpp index ed07948dc..e0d0b9a6d 100644 --- a/test/ncbi-vdb/test-wlink.cpp +++ b/test/ncbi-vdb/test-wlink.cpp @@ -24,30 +24,10 @@ //////////////////////////////////////////// Main -extern "C" -{ - -#include #include #include -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-wlink"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); KDBManager *p; @@ -59,5 +39,3 @@ rc_t CC KMain ( int argc, char *argv [] ) return 0; } - -} diff --git a/test/schema/AST_Fixture.cpp b/test/schema/AST_Fixture.cpp index d3045b294..c75410e4d 100644 --- a/test/schema/AST_Fixture.cpp +++ b/test/schema/AST_Fixture.cpp @@ -47,8 +47,7 @@ AST_Fixture :: AST_Fixture() m_parseTree ( 0 ), m_builder ( 0 ), m_ast ( 0 ), - m_schema ( 0 ), - m_newParse ( true ) + m_schema ( 0 ) { HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); VSchema * intrinsic; @@ -202,49 +201,42 @@ AST_Fixture :: MakeFqn ( const char* p_text ) // p_text = (ident:)+ident AST * AST_Fixture :: MakeAst ( const char* p_source ) { - if ( m_newParse ) - { - HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); - - if ( ! m_parser . ParseString ( ctx, p_source, m_debugParse ) ) - { - throw std :: logic_error ( string ( "AST_Fixture::MakeAst : ParseString() failed: " ) + m_parser . GetErrors () . GetMessageText ( 0 ) ); - } - if ( m_parseTree != 0 ) - { - ParseTree :: Destroy ( m_parseTree ); - } - m_parseTree = m_parser . MoveParseTree (); - if ( m_parseTree == 0 ) - { - throw std :: logic_error ( "AST_Fixture::MakeAst : MoveParseTree() returned 0" ); - } - if ( m_printTree ) - { - PrintTree ( * m_parseTree ); - } - if ( m_ast != 0 ) - { - AST :: Destroy ( m_ast ); - } - m_ast = m_builder -> Build ( ctx, * m_parseTree, "", m_debugAst ); - if ( m_builder -> GetErrorCount() != 0) - { - throw std :: logic_error ( string ( "AST_Fixture::MakeAst : ASTBuilder::Build() failed: " ) + string ( m_builder -> GetErrorMessage ( 0 ) ) ); - } - else if ( m_ast == 0 ) - { - throw std :: logic_error ( "AST_Fixture::MakeAst : ASTBuilder::Build() failed, no message!" ); - } + HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); - if ( FAILED () ) - { - throw std :: logic_error ( WHAT() ); - } + if ( ! m_parser . ParseString ( ctx, p_source, m_debugParse ) ) + { + throw std :: logic_error ( string ( "AST_Fixture::MakeAst : ParseString() failed: " ) + m_parser . GetErrors () . GetMessageText ( 0 ) ); } - else if ( ! OldParse ( p_source ) ) + if ( m_parseTree != 0 ) { - throw std :: logic_error ( "AST_Table_Fixture::ParseTable : OldParse() failed" ); + ParseTree :: Destroy ( m_parseTree ); + } + m_parseTree = m_parser . MoveParseTree (); + if ( m_parseTree == 0 ) + { + throw std :: logic_error ( "AST_Fixture::MakeAst : MoveParseTree() returned 0" ); + } + if ( m_printTree ) + { + PrintTree ( * m_parseTree ); + } + if ( m_ast != 0 ) + { + AST :: Destroy ( m_ast ); + } + m_ast = m_builder -> Build ( ctx, * m_parseTree, "", m_debugAst ); + if ( m_builder -> GetErrorCount() != 0) + { + throw std :: logic_error ( string ( "AST_Fixture::MakeAst : ASTBuilder::Build() failed: " ) + string ( m_builder -> GetErrorMessage ( 0 ) ) ); + } + else if ( m_ast == 0 ) + { + throw std :: logic_error ( "AST_Fixture::MakeAst : ASTBuilder::Build() failed, no message!" ); + } + + if ( FAILED () ) + { + throw std :: logic_error ( WHAT() ); } return m_ast; @@ -253,51 +245,44 @@ AST_Fixture :: MakeAst ( const char* p_source ) void AST_Fixture :: VerifyErrorMessage ( const char* p_source, const char* p_expectedError, uint32_t p_line, uint32_t p_column ) { - if ( m_newParse ) - { - HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); - - if ( ! m_parser . ParseString ( ctx, p_source ) ) - { - throw std :: logic_error ( "AST_Fixture::VerifyErrorMessage : ParseString() failed" ); - } - m_parseTree = m_parser . MoveParseTree (); - if ( m_parseTree == 0 ) - { - throw std :: logic_error ( "AST_Fixture::VerifyErrorMessage : MoveParseTree() returned 0" ); - } - ParseTree :: Destroy ( m_builder -> Build ( ctx, * m_parseTree ) ); - if ( m_builder -> GetErrorCount() == 0 ) - { - throw std :: logic_error ( "AST_Fixture::VerifyErrorMessage : no error" ); - } - const ErrorReport :: Error * err = m_builder -> GetErrors () . GetError ( 0 ); - if ( string ( err -> m_message ) != string ( p_expectedError ) ) - { - throw std :: logic_error ( "AST_Fixture::VerifyErrorMessage : expected '" + string ( p_expectedError ) + - "', received '" + string ( m_builder -> GetErrorMessage ( 0 ) ) + "'" ); - } - if ( p_line != 0 && p_line != err -> m_line ) - { - ostringstream out; - out << "AST_Fixture::VerifyErrorMessage : expected line " << p_line << ", received " << err -> m_line; - throw std :: logic_error ( out . str () ); - } - if ( p_column != 0 && p_column != err -> m_column ) - { - ostringstream out; - out << "AST_Fixture::VerifyErrorMessage : expected column " << p_column << ", received " << err -> m_column; - throw std :: logic_error ( out . str () ); - } + HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); - if ( FAILED () ) - { - throw std :: logic_error ( WHAT() ); - } + if ( ! m_parser . ParseString ( ctx, p_source ) ) + { + throw std :: logic_error ( "AST_Fixture::VerifyErrorMessage : ParseString() failed" ); + } + m_parseTree = m_parser . MoveParseTree (); + if ( m_parseTree == 0 ) + { + throw std :: logic_error ( "AST_Fixture::VerifyErrorMessage : MoveParseTree() returned 0" ); + } + ParseTree :: Destroy ( m_builder -> Build ( ctx, * m_parseTree ) ); + if ( m_builder -> GetErrorCount() == 0 ) + { + throw std :: logic_error ( "AST_Fixture::VerifyErrorMessage : no error" ); + } + const ErrorReport :: Error * err = m_builder -> GetErrors () . GetError ( 0 ); + if ( string ( err -> m_message ) != string ( p_expectedError ) ) + { + throw std :: logic_error ( "AST_Fixture::VerifyErrorMessage : expected '" + string ( p_expectedError ) + + "', received '" + string ( m_builder -> GetErrorMessage ( 0 ) ) + "'" ); + } + if ( p_line != 0 && p_line != err -> m_line ) + { + ostringstream out; + out << "AST_Fixture::VerifyErrorMessage : expected line " << p_line << ", received " << err -> m_line; + throw std :: logic_error ( out . str () ); + } + if ( p_column != 0 && p_column != err -> m_column ) + { + ostringstream out; + out << "AST_Fixture::VerifyErrorMessage : expected column " << p_column << ", received " << err -> m_column; + throw std :: logic_error ( out . str () ); } - else if ( OldParse ( p_source ) ) + + if ( FAILED () ) { - throw std :: logic_error ( "AST_Function_Fixture::VerifyErrorMessage : no error" ); + throw std :: logic_error ( WHAT() ); } } @@ -306,23 +291,14 @@ AST_Fixture :: VerifySymbol ( const char* p_name, uint32_t p_type ) { HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); const KSymbol* sym = 0; - if ( m_newParse ) - { - AST_FQN * ast = MakeFqn ( p_name ); - sym = m_builder -> Resolve ( ctx, * ast ); - if ( sym != 0 && ToCppString ( sym -> name ) != - ast -> GetChild ( ast -> ChildrenCount() - 1 ) -> GetTokenValue () ) - { - throw std :: logic_error ( "AST_Fixture::VerifySymbol : object name mismatch" ); - } - AST :: Destroy ( ast ); - } - else // old parser + AST_FQN * ast = MakeFqn ( p_name ); + sym = m_builder -> Resolve ( ctx, * ast ); + if ( sym != 0 && ToCppString ( sym -> name ) != + ast -> GetChild ( ast -> ChildrenCount() - 1 ) -> GetTokenValue () ) { - String name; - StringInitCString ( & name, p_name ); - sym = ( const KSymbol* ) BSTreeFind ( & m_schema -> scope, & name, KSymbolCmp ); + throw std :: logic_error ( "AST_Fixture::VerifySymbol : object name mismatch" ); } + AST :: Destroy ( ast ); if ( sym == 0 ) { @@ -369,29 +345,6 @@ AST_Fixture :: VerifyDatatype ( const char* p_name, const char* p_baseName, uint return ret; } -bool -AST_Fixture :: OldParse ( const char* p_source ) -{ - const VDBManager *mgr; - if ( VDBManagerMakeRead ( & mgr, 0 ) != 0 ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : VDBManagerMakeRead() failed" ); - } - if ( VDBManagerMakeSchema ( mgr, & m_schema ) != 0 ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : VDBManagerMakeSchema() failed" ); - } - // expect an error, do not need to see it - KWrtHandler* h = KLogLibHandlerGet (); - //KLogLibHandlerSet ( NULL, NULL ); - bool ret = VSchemaParseText ( m_schema, 0, p_source, string_size ( p_source ) ) == 0; - KLogLibHandlerSet ( h -> writer, h -> data ); - - VDBManagerRelease ( mgr ); - - return ret; -} - void AST_Fixture :: CreateFile ( const char * p_name, const char * p_content ) { diff --git a/test/schema/AST_Fixture.hpp b/test/schema/AST_Fixture.hpp index eadf82d50..a5544c97c 100644 --- a/test/schema/AST_Fixture.hpp +++ b/test/schema/AST_Fixture.hpp @@ -88,9 +88,7 @@ class AST_Fixture static AST_FQN * MakeFqn ( const char* p_text ); // p_text = (ident:)+ident - bool OldParse ( const char* p_source ); - - const VSchema * GetSchema () const { return m_newParse ? m_builder -> GetSchema () : m_schema; } + const VSchema * GetSchema () const { return m_builder -> GetSchema (); } uint32_t Version ( uint32_t p_major, uint32_t p_minor = 0, uint32_t p_release = 0 ) { @@ -119,8 +117,6 @@ class AST_Fixture AST* m_ast; VSchema * m_schema; - bool m_newParse; - }; // convernience wrapper for Vector ( a KVector of void * ) diff --git a/test/schema/CMakeLists.txt b/test/schema/CMakeLists.txt index 3305a9c49..21b16dbbe 100644 --- a/test/schema/CMakeLists.txt +++ b/test/schema/CMakeLists.txt @@ -27,24 +27,26 @@ add_compile_definitions( __mod__="test/schema" ) file( MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/actual ) # TODO remove ./actual dir after tests pass (add_test POST?) #set( CMAKE_DISABLE_SOURCE_CHANGES ON ) # Cannot use with bison -AddExecutableTest( Test_SCHEMA_wb-schema-lex "wb-test-schema-lex" "${COMMON_LIBS_READ};schema" ) -AddExecutableTest( Test_SCHEMA_wb-schema-parser "wb-test-schema-parser" "${COMMON_LIBS_READ};schema" ) -AddExecutableTest( Test_SCHEMA_wb-schema-ast "wb-test-schema-ast;AST_Fixture" "${COMMON_LIBS_READ};schema" ) -AddExecutableTest( Test_SCHEMA_wb-test-schema-func "wb-test-schema-func;AST_Fixture" "${COMMON_LIBS_READ};schema" ) -AddExecutableTest( Test_SCHEMA_wb-test-schema-table "wb-test-schema-table;AST_Fixture" "${COMMON_LIBS_READ};schema" ) -AddExecutableTest( Test_SCHEMA_wb-test-schema-db "wb-test-schema-db;AST_Fixture" "${COMMON_LIBS_READ};schema" ) -AddExecutableTest( Test_SCHEMA_wb-test-schema-view "wb-test-schema-view;AST_Fixture" "${COMMON_LIBS_READ};schema" ) +set( LIBS "${COMMON_LIBS_READ}" schema ) + +AddExecutableTest( Test_SCHEMA_wb-schema-lex "wb-test-schema-lex" "${LIBS}" ) +AddExecutableTest( Test_SCHEMA_wb-schema-parser "wb-test-schema-parser" "${LIBS}" ) +AddExecutableTest( Test_SCHEMA_wb-schema-ast "wb-test-schema-ast;AST_Fixture" "${LIBS}" ) +AddExecutableTest( Test_SCHEMA_wb-test-schema-func "wb-test-schema-func;AST_Fixture" "${LIBS}" ) +AddExecutableTest( Test_SCHEMA_wb-test-schema-table "wb-test-schema-table;AST_Fixture" "${LIBS}" ) +AddExecutableTest( Test_SCHEMA_wb-test-schema-db "wb-test-schema-db;AST_Fixture" "${LIBS}" ) +AddExecutableTest( Test_SCHEMA_wb-test-schema-view "wb-test-schema-view;AST_Fixture" "${LIBS}" ) # TODO the following binaries are not unit tests (INT_TOOLS), they should be started not as ctest if( SINGLE_CONFIG ) - BuildExecutableForTest( Test_SCHEMA_schema-scan "test-schema-scan" "${COMMON_LIBS_READ};schema" ) + BuildExecutableForTest( Test_SCHEMA_schema-scan "test-schema-scan" "${LIBS}" ) add_test( NAME Test_SCHEMA_schema-scan COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test-schema-scan.sh ${CMAKE_TEST_OUTPUT_DIRECTORY}/Test_SCHEMA_schema-scan ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) - BuildExecutableForTest( Test_SCHEMA_schema-parse "test-schema-parse" "${COMMON_LIBS_READ};schema" ) + BuildExecutableForTest( Test_SCHEMA_schema-parse "test-schema-parse" "${LIBS}" ) add_test( NAME Test_SCHEMA_schema-parse COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test-schema-parse.sh ${CMAKE_TEST_OUTPUT_DIRECTORY}/Test_SCHEMA_schema-parse ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) - BuildExecutableForTest( Test_SCHEMA_schema-diff "test-schema-diff" "${COMMON_LIBS_READ};schema" ) + BuildExecutableForTest( Test_SCHEMA_schema-diff "test-schema-diff" "${LIBS}" ) add_test( NAME Test_SCHEMA_schema-diff COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test-schema-diff.sh ${CMAKE_TEST_OUTPUT_DIRECTORY}/Test_SCHEMA_schema-diff ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() diff --git a/test/schema/test-schema-diff.cpp b/test/schema/test-schema-diff.cpp index c0aeae005..56852c26b 100644 --- a/test/schema/test-schema-diff.cpp +++ b/test/schema/test-schema-diff.cpp @@ -71,30 +71,10 @@ DumpSchema ( const VSchema * p_schema, ostream & p_out ) } } -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "test-schema-diff"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] schema-file ... \n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - + int failed = 0; if ( argc < 2 ) { @@ -308,5 +288,3 @@ rc_t CC KMain ( int argc, char *argv [] ) return failed == 0 ? 0 : 4; } -} - diff --git a/test/schema/test-schema-parse.cpp b/test/schema/test-schema-parse.cpp index 3f631e826..79e12ec1d 100644 --- a/test/schema/test-schema-parse.cpp +++ b/test/schema/test-schema-parse.cpp @@ -91,27 +91,7 @@ MatchStrings ( const string& p_source, const string p_print ) return true; } -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "test-schema-parse"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] schema-file ... \n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); int failed = 0; @@ -162,5 +142,3 @@ rc_t CC KMain ( int argc, char *argv [] ) return failed == 0 ? 0 : 4; } -} - diff --git a/test/schema/test-schema-scan.cpp b/test/schema/test-schema-scan.cpp index 03aa1bbb4..05d20095a 100644 --- a/test/schema/test-schema-scan.cpp +++ b/test/schema/test-schema-scan.cpp @@ -50,26 +50,6 @@ typedef struct ErrorReport ErrorReport; #include #include -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "test-schema-scan"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] schema-file\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - static bool MatchStrings ( const string& p_source, const string p_print ) @@ -98,7 +78,7 @@ MatchStrings ( const string& p_source, const string p_print ) return true; } -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { int failed = 0; if ( argc < 2 ) @@ -156,6 +136,3 @@ rc_t CC KMain ( int argc, char *argv [] ) } return failed == 0 ? 0 : 4; } - -} - diff --git a/test/schema/wb-test-schema-ast.cpp b/test/schema/wb-test-schema-ast.cpp index 7da43ae9e..ac3e65818 100644 --- a/test/schema/wb-test-schema-ast.cpp +++ b/test/schema/wb-test-schema-ast.cpp @@ -326,21 +326,18 @@ FIXTURE_TEST_CASE(Typedef_FQN_OneScalar, AST_Fixture) FIXTURE_TEST_CASE(LocationInErrorMessages, AST_Fixture) { - if ( m_newParse ) - { - HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); - REQUIRE ( m_parser . ParseString ( ctx, "\n\ntypedef a:zz t;" ) ); - m_parseTree = m_parser . MoveParseTree (); - REQUIRE_NOT_NULL ( m_parseTree ); - ParseTree :: Destroy ( m_builder -> Build ( ctx, * m_parseTree ) ); - const ErrorReport & errors = m_builder -> GetErrors (); - REQUIRE_EQ ( 1u, errors . GetCount () ); - const ErrorReport :: Error * err = errors . GetError ( 0 ); - REQUIRE_EQ ( string ( "Undeclared identifier: 'zz'" ), string ( err -> m_message ) ); - REQUIRE_EQ ( 3u, err -> m_line ); - REQUIRE_EQ ( 11u, err -> m_column ); - REQUIRE_EQ ( string ( "" ), string ( err -> m_file ) ); - } + HYBRID_FUNC_ENTRY( rcSRA, rcSchema, rcParsing ); + REQUIRE ( m_parser . ParseString ( ctx, "\n\ntypedef a:zz t;" ) ); + m_parseTree = m_parser . MoveParseTree (); + REQUIRE_NOT_NULL ( m_parseTree ); + ParseTree :: Destroy ( m_builder -> Build ( ctx, * m_parseTree ) ); + const ErrorReport & errors = m_builder -> GetErrors (); + REQUIRE_EQ ( 1u, errors . GetCount () ); + const ErrorReport :: Error * err = errors . GetError ( 0 ); + REQUIRE_EQ ( string ( "Undeclared identifier: 'zz'" ), string ( err -> m_message ) ); + REQUIRE_EQ ( 3u, err -> m_line ); + REQUIRE_EQ ( 11u, err -> m_column ); + REQUIRE_EQ ( string ( "" ), string ( err -> m_file ) ); } FIXTURE_TEST_CASE(Resolve_UndefinedNameInNamespace, AST_Fixture) @@ -530,8 +527,6 @@ class ConstFixture : public AST_Fixture public: ConstFixture () { - // uncomment to run all const tests through the old parser - //m_newParse = false; } const SExpression * VerifyConst ( const char * p_input, const char * p_id, uint32_t p_type ) @@ -948,12 +943,8 @@ FIXTURE_TEST_CASE(FuncCall_FactoryParams, AST_Fixture) FIXTURE_TEST_CASE(FuncCall_FunctionAsFactoryParam, AST_Fixture) { - if ( m_newParse ) - { - VerifyErrorMessage ( "function U8 g(); function U8 f (); table t#1 { column U8 i = f (); } ", - "Function expressions are not yet implemented", 1, 73 ); - } - // the old parser accepts but errors out at run time + VerifyErrorMessage ( "function U8 g(); function U8 f (); table t#1 { column U8 i = f (); } ", + "Function expressions are not yet implemented", 1, 73 ); } FIXTURE_TEST_CASE(FuncCall_BadFactoryParam, AST_Fixture) @@ -1122,34 +1113,7 @@ FIXTURE_TEST_CASE(CondExpr, AST_Fixture) //TODO: eCondExpr //////////////////////////////////////////// Main -#include -#include -#include - -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "wb-test-schema-ast"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] -o path\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { return SchemaASTTestSuite(argc, argv); } - -} - diff --git a/test/schema/wb-test-schema-db.cpp b/test/schema/wb-test-schema-db.cpp index 3be9e1e22..e27739178 100644 --- a/test/schema/wb-test-schema-db.cpp +++ b/test/schema/wb-test-schema-db.cpp @@ -320,34 +320,7 @@ FIXTURE_TEST_CASE(DB_ViewOnAliasMemberOnAnotherViewAliasMember, AST_Db_Fixture) //TODO: SViewAliasMemberDump //////////////////////////////////////////// Main -#include -#include -#include - -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "wb-test-schema-db"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] -o path\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { return SchemaDbTestSuite(argc, argv); } - -} - diff --git a/test/schema/wb-test-schema-func.cpp b/test/schema/wb-test-schema-func.cpp index fa3afa9a0..111c0c28c 100644 --- a/test/schema/wb-test-schema-func.cpp +++ b/test/schema/wb-test-schema-func.cpp @@ -113,37 +113,25 @@ class AST_Function_Fixture : public AST_Fixture FunctionAccess ParseFunction ( const char * p_source, const char * p_name, uint32_t p_idx = 0, uint32_t p_type = eFunction ) { - const SFunction* ret = 0; MakeAst ( p_source ); - if ( m_newParse ) + const KSymbol* sym = VerifySymbol ( p_name, p_type ); + + // for functions, sym points to an entry in the overloads table (schema->fname) + const SNameOverload* name = static_cast < const SNameOverload* > ( sym -> u . obj ); + if ( 1u != VectorLength ( & name -> items ) ) { - const KSymbol* sym = VerifySymbol ( p_name, p_type ); - - // for functions, sym points to an entry in the overloads table (schema->fname) - const SNameOverload* name = static_cast < const SNameOverload* > ( sym -> u . obj ); - if ( 1u != VectorLength ( & name -> items ) ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : too many overloads" ); - } - ret = static_cast < const SFunction* > ( VectorGet ( & name -> items, 0 ) ); - if ( ret -> name == 0 ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : NULL name" ); - } - if ( string ( p_name ) != ToCppString ( ret -> name -> name ) ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : wrong name" ); - } + throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : too many overloads" ); } - else + const SFunction* ret = static_cast < const SFunction* > ( VectorGet ( & name -> items, 0 ) ); + if ( ret -> name == 0 ) { - ret = static_cast < const SFunction* > ( VectorGet ( & m_schema -> func, p_idx ) ); - - if ( string ( p_name ) != ToCppString ( ret -> name -> name ) ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : wrong name" ); - } + throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : NULL name" ); } + if ( string ( p_name ) != ToCppString ( ret -> name -> name ) ) + { + throw std :: logic_error ( "AST_Function_Fixture::ParseFunction : wrong name" ); + } + return FunctionAccess ( ret ); } @@ -290,12 +278,9 @@ FIXTURE_TEST_CASE(Func_Redeclared_DiffMajor, AST_Function_Fixture) } FIXTURE_TEST_CASE(Func_Redeclared_HigherMinor, AST_Function_Fixture) -{ // higner minor is used - if ( m_newParse ) // the old parser fails here! - { - FunctionAccess fn = ParseFunction ( "function U8 f#1();function U16 f#1.2();", "f" ); - REQUIRE_EQ ( U16_id, fn . ReturnType () -> fd . td . type_id ); // 2nd decl used - } +{ // higher minor is used + FunctionAccess fn = ParseFunction ( "function U8 f#1();function U16 f#1.2();", "f" ); + REQUIRE_EQ ( U16_id, fn . ReturnType () -> fd . td . type_id ); // 2nd decl used } FIXTURE_TEST_CASE(Func_NoChangingReleaseNumberForSimpleFunctions, AST_Function_Fixture) @@ -783,32 +768,22 @@ class PhysicalAccess PhysicalAccess AST_Function_Fixture :: ParsePhysical ( const char * p_source, const char * p_name ) { - const SPhysical* ret = 0; - if ( m_newParse ) - { - MakeAst ( p_source ); - const KSymbol* sym = VerifySymbol ( p_name, ePhysical ); + MakeAst ( p_source ); + const KSymbol* sym = VerifySymbol ( p_name, ePhysical ); - // for physical functions, sym points to an entry in the overloads table (schema->pname) - const SNameOverload* name = static_cast < const SNameOverload* > ( sym -> u . obj ); - if ( 0 == VectorLength ( & name -> items ) ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParsePhysical : no overloads" ); - } - ret = static_cast < const SPhysical* > ( VectorGet ( & name -> items, 0 ) ); - if ( string ( p_name ) != ToCppString ( ret -> name -> name ) ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParsePhysical : wrong name" ); - } + // for physical functions, sym points to an entry in the overloads table (schema->pname) + const SNameOverload* name = static_cast < const SNameOverload* > ( sym -> u . obj ); + if ( 0 == VectorLength ( & name -> items ) ) + { + throw std :: logic_error ( "AST_Function_Fixture::ParsePhysical : no overloads" ); } - else if ( OldParse ( p_source ) ) + + const SPhysical* ret = static_cast < const SPhysical* > ( VectorGet ( & name -> items, 0 ) ); + if ( string ( p_name ) != ToCppString ( ret -> name -> name ) ) { - ret = static_cast < const SPhysical* > ( VectorGet ( & m_schema -> phys, 0 ) ); - if ( string ( p_name ) != ToCppString ( ret -> name -> name ) ) - { - throw std :: logic_error ( "AST_Function_Fixture::ParsePhysical : wrong name" ); - } + throw std :: logic_error ( "AST_Function_Fixture::ParsePhysical : wrong name" ); } + return PhysicalAccess ( ret ); } @@ -857,12 +832,9 @@ FIXTURE_TEST_CASE(Func_Physical_OverloadOlderMajorVersion, AST_Function_Fixture) FIXTURE_TEST_CASE(Func_Physical_OverloadNewerVersion, AST_Function_Fixture) { - if ( m_newParse ) // the old parser fails here! - { - PhysicalAccess fn = ParsePhysical ( "physical U8 f#1.2 = { return 1; } physical U16 f#1.3 = { return 2; }", "f" ); - REQUIRE_NOT_NULL ( fn . ReturnType () ); - REQUIRE_EQ ( U16_id, fn . ReturnType () -> fd . td . type_id ); // 2nd version chosen - } + PhysicalAccess fn = ParsePhysical ( "physical U8 f#1.2 = { return 1; } physical U16 f#1.3 = { return 2; }", "f" ); + REQUIRE_NOT_NULL ( fn . ReturnType () ); + REQUIRE_EQ ( U16_id, fn . ReturnType () -> fd . td . type_id ); // 2nd version chosen } FIXTURE_TEST_CASE(Func_Physical_Decode, AST_Function_Fixture) @@ -944,34 +916,7 @@ FIXTURE_TEST_CASE(Func_Physical_SchemaParams, AST_Function_Fixture) } //////////////////////////////////////////// Main -#include -#include -#include - -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "wb-test-schema-func"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] -o path\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { return SchemaFuncTestSuite(argc, argv); } - -} - diff --git a/test/schema/wb-test-schema-lex.cpp b/test/schema/wb-test-schema-lex.cpp index 4eadbba2c..b9740761b 100644 --- a/test/schema/wb-test-schema-lex.cpp +++ b/test/schema/wb-test-schema-lex.cpp @@ -31,6 +31,9 @@ #include #include +#include +#include +#include #include "../../libs/schema/SchemaScanner.hpp" @@ -289,34 +292,8 @@ TEST_CASE ( Version_2_0 ) } //////////////////////////////////////////// Main -#include -#include -#include -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "wb-test-schema-lex"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] -o path\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { return SchemaLexTestSuite(argc, argv); } - -} - diff --git a/test/schema/wb-test-schema-parser.cpp b/test/schema/wb-test-schema-parser.cpp index 83c78d939..31873256e 100644 --- a/test/schema/wb-test-schema-parser.cpp +++ b/test/schema/wb-test-schema-parser.cpp @@ -156,15 +156,15 @@ TEST_CASE(ParseTree_Location) REQUIRE_EQ ( 0u, source -> GetLocation() . m_column ); // add a real token, make sure its location is used as the tree's location - SchemaToken st1 = { KW_view, "view", 4, 0, 0, "file", 1, 2 }; - source -> AddChild ( ctx, ParseTree :: Make ( ctx, st1 ) ); + SchemaToken st_1 = { KW_view, "view", 4, 0, 0, "file", 1, 2 }; + source -> AddChild ( ctx, ParseTree :: Make ( ctx, st_1 ) ); REQUIRE_EQ ( string ( "file" ), string ( source -> GetLocation() . m_file ) ); // first real token REQUIRE_EQ ( 1u, source -> GetLocation() . m_line ); REQUIRE_EQ ( 2u, source -> GetLocation() . m_column ); // add more real tokens, make sure the location does not change - SchemaToken st2 = { KW_view, "view", 4, 0, 0, "file", 2, 3 }; - source -> AddChild ( ctx, ParseTree :: Make ( ctx, st2 ) ); + SchemaToken st_2 = { KW_view, "view", 4, 0, 0, "file", 2, 3 }; + source -> AddChild ( ctx, ParseTree :: Make ( ctx, st_2 ) ); REQUIRE_EQ ( 1u, source -> GetLocation() . m_line ); REQUIRE_EQ ( 2u, source -> GetLocation() . m_column ); @@ -787,34 +787,8 @@ TEST_CASE ( View_JoinExpressionLikePhysicalIdent ) } //////////////////////////////////////////// Main -#include -#include -#include - -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "wb-test-schema-parser"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] -o path\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { return SchemaParserTestSuite(argc, argv); } - -} - diff --git a/test/schema/wb-test-schema-table.cpp b/test/schema/wb-test-schema-table.cpp index d60b85ae4..64b119eef 100644 --- a/test/schema/wb-test-schema-table.cpp +++ b/test/schema/wb-test-schema-table.cpp @@ -887,15 +887,12 @@ FIXTURE_TEST_CASE(Table_ColumnDecl_SymConstAsSchemaArg, AST_Table_Fixture) FIXTURE_TEST_CASE(Table_ColumnDecl_NonUintSymConstAsSchemaArg, AST_Table_Fixture) { // schema constant arguments must be uint - if ( m_newParse ) // old parser does not check this condition, only mentions it in a comment - { - VerifyErrorMessage ( - "physical < U8 C > U8 ph #1 = { return C; }\n" - "const I8 c1 = 1; \n" - "table t#1 { column < c1 > ph#1 c; }", - "Schema argument constant has to be an unsigned integer scalar: 'c1'", - 3, 22 ); - } + VerifyErrorMessage ( + "physical < U8 C > U8 ph #1 = { return C; }\n" + "const I8 c1 = 1; \n" + "table t#1 { column < c1 > ph#1 c; }", + "Schema argument constant has to be an unsigned integer scalar: 'c1'", + 3, 22 ); } FIXTURE_TEST_CASE(Table_ColumnDecl_BadSchemaArg, AST_Table_Fixture) @@ -1174,14 +1171,6 @@ FIXTURE_TEST_CASE(Table_PhysicalColumn_Inherited, AST_Table_Fixture) REQUIRE_EQ ( ( uint32_t ) eConstExpr, c -> expr -> var ); } -/* only for 1.1, not used anywhere - and broken. -FIXTURE_TEST_CASE(Table_DefaultView, AST_Table_Fixture) -{ - m_newParse = false; - TableAccess t = ParseTable ( "version 1.1; table t#1 { default view \"V\"; }", "t" ); -} -*/ - FIXTURE_TEST_CASE(Table_Untyped, AST_Table_Fixture) { TableAccess t = ParseTable ( "function __untyped f(); table t#1 { __untyped = f(); }", "t" ); @@ -1200,34 +1189,7 @@ FIXTURE_TEST_CASE(Table_segfault, AST_Table_Fixture) } //////////////////////////////////////////// Main -#include -#include -#include - -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "wb-test-schema-table"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] -o path\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { return SchemaTableTestSuite(argc, argv); } - -} - diff --git a/test/schema/wb-test-schema-view.cpp b/test/schema/wb-test-schema-view.cpp index 81db09564..b1c893191 100644 --- a/test/schema/wb-test-schema-view.cpp +++ b/test/schema/wb-test-schema-view.cpp @@ -943,34 +943,8 @@ FIXTURE_TEST_CASE(View_ColumnDecl_Context_Inherited, AST_View_Fixture) //TODO: SViewMark //////////////////////////////////////////// Main -#include -#include -#include - -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} - -const char UsageDefaultName[] = "wb-test-schema-view"; - -rc_t CC UsageSummary (const char * progname) -{ - return KOutMsg ( "Usage:\n" "\t%s [options] -o path\n\n", progname ); -} - -rc_t CC Usage( const Args* args ) -{ - return 0; -} - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { return SchemaViewTestSuite(argc, argv); } -} - diff --git a/test/sraxf/CMakeLists.txt b/test/sraxf/CMakeLists.txt index 3f2a3afe7..d30468c6b 100644 --- a/test/sraxf/CMakeLists.txt +++ b/test/sraxf/CMakeLists.txt @@ -24,7 +24,9 @@ add_compile_definitions( __mod__="test/sraxf" ) -AddExecutableTest( Test_SRAXF_format_spot_name "test-format_spot_name" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_SRAXF_fix_read_seg "fix_read_seg-test" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_SRAXF_syn_quality "test_syn_quality" "${COMMON_LIBS_READ}" ) +set( LIBS "${COMMON_LIBS_READ}") + +AddExecutableTest( Test_SRAXF_format_spot_name "test-format_spot_name" "${LIBS}" ) +AddExecutableTest( Test_SRAXF_fix_read_seg "fix_read_seg-test" "${LIBS}" ) +AddExecutableTest( Test_SRAXF_syn_quality "test_syn_quality" "${LIBS}" ) AddExecutableTest( Test_SRAXF_spot_check "test_spot-check.c" "" ) diff --git a/test/sraxf/fix_read_seg-test.cpp b/test/sraxf/fix_read_seg-test.cpp index 561d41d76..483ba653c 100644 --- a/test/sraxf/fix_read_seg-test.cpp +++ b/test/sraxf/fix_read_seg-test.cpp @@ -1,20 +1,41 @@ +/*=========================================================================== + * + * PUBLIC DOMAIN NOTICE + * National Center for Biotechnology Information + * + * This software/database is a "United States Government Work" under the + * terms of the United States Copyright Act. It was written as part of + * the author's official duties as a United States Government employee and + * thus cannot be copyrighted. This software/database is freely available + * to the public for use. The National Library of Medicine and the U.S. + * Government have not placed any restriction on its use or reproduction. + * + * Although all reasonable efforts have been taken to ensure the accuracy + * and reliability of the software and data, the NLM and the U.S. + * Government do not and cannot warrant the performance or results that + * may be obtained by using this software or data. The NLM and the U.S. + * Government disclaim all warranties, express or implied, including + * warranties of performance, merchantability or fitness for any particular + * purpose. + * + * Please cite the author in any work or product based on this material. + * + * =========================================================================== + * + */ + #include /* uint16_t */ #include #include #include /* TEST_SUITE */ -#include /* KAppVersion */ +#include #include /* lround on Windows, uint16_t */ #include /* memset */ #include "../../libs/sraxf/fix_read_seg_impl.h" -ver_t CC KAppVersion ( void ) { return 0; } -rc_t CC Usage ( const Args * args ) { return 0; } -const char UsageDefaultName[] = ""; -rc_t UsageSummary (const char * progname) { return 0; } - TEST_SUITE(FixReadSegTestSuite); TEST_CASE(_0_reads) { @@ -127,5 +148,5 @@ TEST_CASE(total_lt_spotlen_read_2) { CHECK_EQ(dst[3], (uint32_t)8); } -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { return FixReadSegTestSuite(argc, argv); } diff --git a/test/sraxf/test-format_spot_name.cpp b/test/sraxf/test-format_spot_name.cpp index 37cdf2bef..30d4903a7 100644 --- a/test/sraxf/test-format_spot_name.cpp +++ b/test/sraxf/test-format_spot_name.cpp @@ -74,21 +74,10 @@ TEST_CASE(TestFormatSpotName) { // VDB-4097 REQUIRE_RC(VDBManagerRelease(mgr)); } -const char UsageDefaultName[] = "test-format-spot-name"; -rc_t CC UsageSummary(const char * progname) { return 0; } -rc_t CC Usage(const Args * args) { return 0; } - -extern "C" { - - ver_t CC KAppVersion(void) { return 0; } - - int KMain(int argc, char *argv[]) { - KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg - - rc_t rc = FormatSpotNameSuite(argc, argv); - return rc; - } +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg + return FormatSpotNameSuite(argc, argv); } /******************************************************************************/ diff --git a/test/sraxf/test_spot-check.c b/test/sraxf/test_spot-check.c index 2ac649568..bbf87c9f3 100644 --- a/test/sraxf/test_spot-check.c +++ b/test/sraxf/test_spot-check.c @@ -190,9 +190,6 @@ static void check_check_quality() { check_check_quality9(&self); } -#ifdef WINDOWS -#define main wmain -#endif int main(int argc, char *argv[]) { check_check_quality(); } diff --git a/test/sraxf/test_syn_quality.cpp b/test/sraxf/test_syn_quality.cpp index 6e053bffb..9873216ba 100644 --- a/test/sraxf/test_syn_quality.cpp +++ b/test/sraxf/test_syn_quality.cpp @@ -25,7 +25,7 @@ */ #include /* TEST_SUITE */ -#include /* KAppVersion */ +#include /* KAppVersion */ #include #include @@ -34,7 +34,7 @@ #include /***************************************************************************** - This test + This test *****************************************************************************/ extern "C" { @@ -42,11 +42,6 @@ extern "C" { #include "../../libs/sraxf/syn_quality.c" } -ver_t CC KAppVersion( void ) { return 0; } -rc_t CC Usage( const Args * args ) { return 0; } -const char UsageDefaultName[] = ""; -rc_t UsageSummary( const char * progname ) { return 0; } - TEST_SUITE( SynQualityTestSuite ); TEST_CASE( NoInput ) { @@ -71,7 +66,7 @@ TEST_CASE( TwoRead_Fail ) { REQUIRE(UnitTest_2Read_Fail() == 0); } -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { return SynQualityTestSuite( argc, argv ); } diff --git a/test/vdb/CMakeLists.txt b/test/vdb/CMakeLists.txt index 02dcd76d9..c63c479dd 100644 --- a/test/vdb/CMakeLists.txt +++ b/test/vdb/CMakeLists.txt @@ -30,27 +30,30 @@ else() set( ADDITIONAL_LIBS "" ) endif() -AddExecutableTest( SlowTest_VDB_vdb "test-vdb" "${COMMON_LIBS_READ}" ) +set( LIBS_READ "${COMMON_LIBS_READ}") +set( LIBS_WRITE "${COMMON_LIBS_WRITE}" "${ADDITIONAL_LIBS}") -AddExecutableTest( Test_VDB_wvdb "test-wvdb" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) +AddExecutableTest( SlowTest_VDB_vdb "test-vdb" "${LIBS_READ}" ) + +AddExecutableTest( Test_VDB_wvdb "test-wvdb" "${LIBS_WRITE}" ) set_tests_properties(Test_VDB_wvdb PROPERTIES ENVIRONMENT VDB_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/kfg/empty) AddExecutableTest( - SlowTest_VDB_dependencies_dflt "test-dependencies_dflt" "${COMMON_LIBS_READ}" ) + SlowTest_VDB_dependencies_dflt "test-dependencies_dflt" "${LIBS_READ}" ) AddExecutableTest( - Test_VDB_dependencies_404first "Test_VDB_dependencies_404first" "${COMMON_LIBS_READ}" ) + Test_VDB_dependencies_404first "Test_VDB_dependencies_404first" "${LIBS_READ}" ) AddExecutableTest( - Test_VDB_dependencies_wgs "Test_VDB_dependencies_wgs" "${COMMON_LIBS_READ}" ) + Test_VDB_dependencies_wgs "Test_VDB_dependencies_wgs" "${LIBS_READ}" ) BuildExecutableForTest( test-VDBManagerGetObjVersion - "test-VDBManagerGetObjVersion" "${COMMON_LIBS_READ}" ) + "test-VDBManagerGetObjVersion" "${LIBS_READ}" ) add_test( NAME Test_VDBManagerGetObjVersion COMMAND test-VDBManagerGetObjVersion WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../vfs ) -AddExecutableTest( Test_VDB_sparse_col_rw "test-sparse-col" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) +AddExecutableTest( Test_VDB_sparse_col_rw "test-sparse-col" "${LIBS_WRITE}" ) set_tests_properties( Test_VDB_sparse_col_rw PROPERTIES FIXTURES_SETUP SPARSE_COL ) -AddExecutableTest( Test_VDB_sparse_col_rd "test-sparse-col" "${COMMON_LIBS_READ}" ) +AddExecutableTest( Test_VDB_sparse_col_rd "test-sparse-col" "${LIBS_READ}" ) target_compile_definitions(Test_VDB_sparse_col_rd PUBLIC READ_ONLY) set_tests_properties(Test_VDB_sparse_col_rd PROPERTIES FIXTURES_REQUIRED SPARSE_COL ) if( RUN_SANITIZER_TESTS ) @@ -60,25 +63,27 @@ if( RUN_SANITIZER_TESTS ) set_tests_properties(Test_VDB_sparse_col_rd_tsan PROPERTIES FIXTURES_REQUIRED SPARSE_COL) endif() -AddExecutableTest( Test_VDB_blob_val "test-blob-val" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VDB_VDB-3060 "test-VDB-3060" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VDB_VDB-3061 "test-VDB-3061" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VDB_bytecode "test-bytecode" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) -AddExecutableTest( Test_VDB_database_cmn "test-database-cmn" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) -AddExecutableTest( Test_VDB_view "test-view" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS};schema" ) -AddExecutableTest( Test_VDB_wtablecursor "test-wtablecursor" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) -AddExecutableTest( Test_VDB_view_cursor "test-view-cursor" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS};schema" ) -AddExecutableTest( Test_VDB_VDB-4156 "test-VDB-4156" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) -AddExecutableTest( Test_VDB_META_CMP_COPY "test-vdb-meta-cmp-copy" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) -AddExecutableTest( Test_VDB_schema_priv "Test-VDB_schema_priv" "${COMMON_LIBS_READ};${ADDITIONAL_LIBS}" ) -AddExecutableTest( Test_VDB_link "test-link" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VDB_text "test-textvdb" "${COMMON_LIBS_READ};kdbtext" ) -AddExecutableTest( Test_VDB_linker "test-linker" "${COMMON_LIBS_WRITE}" ) +AddExecutableTest( Test_VDB_blob_val "test-blob-val" "${LIBS_READ}" ) +AddExecutableTest( Test_VDB_VDB-3060 "test-VDB-3060" "${LIBS_READ}" ) +AddExecutableTest( Test_VDB_VDB-3061 "test-VDB-3061" "${LIBS_READ}" ) +AddExecutableTest( Test_VDB_bytecode "test-bytecode" "${LIBS_WRITE}" ) +AddExecutableTest( Test_VDB_database_cmn "test-database-cmn" "${LIBS_WRITE}" ) +AddExecutableTest( Test_VDB_view "test-view" "${LIBS_WRITE};schema" ) +AddExecutableTest( Test_VDB_wtablecursor "test-wtablecursor" "${LIBS_WRITE}" ) +AddExecutableTest( Test_VDB_view_cursor "test-view-cursor" "${LIBS_WRITE};schema" ) +AddExecutableTest( Test_VDB_VDB-4156 "test-VDB-4156" "${LIBS_WRITE}" ) +AddExecutableTest( Test_VDB_NodeDrop "test-VDB-NodeDrop" "${LIBS_WRITE}" ) +AddExecutableTest( Test_VDB_META_CMP_COPY "test-vdb-meta-cmp-copy" "${LIBS_WRITE}" ) +AddExecutableTest( Test_VDB_schema_priv "Test-VDB_schema_priv" "${LIBS_READ}" ) +AddExecutableTest( Test_VDB_TooBigMeta "test-VDB-TooBigMeta" "${LIBS_WRITE}" ) +AddExecutableTest( Test_VDB_link "test-link" "${LIBS_READ}" ) +AddExecutableTest( Test_VDB_text "test-textvdb" "${LIBS_READ};kdbtext" ) +AddExecutableTest( Test_VDB_linker "test-linker" "${LIBS_WRITE}" ) # Slow tests -AddExecutableTest( SlowTest_VDB_tablecursor "test-tablecursor" "${COMMON_LIBS_READ}" ) -AddExecutableTest( SlowTest_VDB_vdb-slow "test-vdb-slow" "${COMMON_LIBS_READ}" ) -AddExecutableTest( SlowTest_VDB_wvdb-slow "test-wvdb-slow" "${COMMON_LIBS_WRITE};${ADDITIONAL_LIBS}" ) +AddExecutableTest( SlowTest_VDB_tablecursor "test-tablecursor" "${LIBS_READ}" ) +AddExecutableTest( SlowTest_VDB_vdb-slow "test-vdb-slow" "${LIBS_READ}" ) +AddExecutableTest( SlowTest_VDB_wvdb-slow "test-wvdb-slow" "${LIBS_WRITE}" ) # TODO: make sure runs are not cached in the user repository when running tests diff --git a/test/vdb/Test-VDB_schema_priv.cpp b/test/vdb/Test-VDB_schema_priv.cpp index 864608f98..b8e8ade0d 100644 --- a/test/vdb/Test-VDB_schema_priv.cpp +++ b/test/vdb/Test-VDB_schema_priv.cpp @@ -41,7 +41,7 @@ static rc_t argsHandler(int argc, char *argv[]) { } TEST_SUITE_WITH_ARGS_HANDLER(SchemaPrivSuite, argsHandler) -static void OnDb(void *item, void *data) { +static void OnDb(void *item, void *data) noexcept { assert(item && data); const struct SDatabase *self(static_cast(item)); rc_t *aRc = static_cast(data); @@ -90,7 +90,7 @@ static void OnDb(void *item, void *data) { *aRc = rc; } -static void OnTbl(void *item, void *data) { +static void OnTbl(void *item, void *data) noexcept { assert(item && data); const struct STable *self(static_cast(item)); rc_t *aRc = static_cast(data); @@ -113,23 +113,31 @@ static void OnTbl(void *item, void *data) { *aRc = 20; return; } + #ifdef SHOW_RESULTS else std::cerr << "TABLE-NAME: " << std::string(sn->name->name->addr, sn->name->name->size) << std::endl; #endif + + KSymbolNameWhack( sn ); +} + +static void WhackTbl(void *item, void *data) noexcept +{ + } TEST_CASE(TestSchemaPriv) { const VDBManager *m(NULL); REQUIRE_RC(VDBManagerMakeRead(&m, NULL)); - + const VDatabase *db(NULL); REQUIRE_RC(VDBManagerOpenDBRead(m, &db, NULL, "db/VDB-3418.sra")); - + const VSchema *schema(NULL); REQUIRE_RC(VDatabaseOpenSchema(db, &schema)); - + // VSchemaGetDb const Vector *v(NULL); REQUIRE_RC(VSchemaGetDb(schema, &v)); @@ -150,23 +158,17 @@ TEST_CASE(TestSchemaPriv) { REQUIRE_RC(VSchemaGetTbl(schema, &v)); REQUIRE_NOT_NULL(v); VectorForEach(v, false, OnTbl, &rc); - + REQUIRE_RC(rc); - + REQUIRE_RC(VSchemaRelease(schema)); - + REQUIRE_RC(VDatabaseRelease(db)); - + REQUIRE_RC(VDBManagerRelease(m)); } -extern "C" { - rc_t CC KMain(int argc, char *argv[]) { - KConfigDisableUserSettings(); - return SchemaPrivSuite(argc, argv); - } - ver_t CC KAppVersion(void) { return 0; } - const char UsageDefaultName[]("Test_VDB_schema_priv"); - rc_t CC Usage(const Args *args) { return 0; } - rc_t CC UsageSummary(const char *progname) { return 0; } +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); + return SchemaPrivSuite(argc, argv); } diff --git a/test/vdb/Test_VDB_dependencies_404first.cpp b/test/vdb/Test_VDB_dependencies_404first.cpp index 855d3f87a..b23a87627 100644 --- a/test/vdb/Test_VDB_dependencies_404first.cpp +++ b/test/vdb/Test_VDB_dependencies_404first.cpp @@ -69,14 +69,7 @@ TEST_CASE(Test_VDB_dependencies_404first) { REQUIRE_RC(rc); } -extern "C" { - ver_t CC KAppVersion(void) { return 0x1000000; } - rc_t CC Usage(const Args *args) { return 0; } - const char UsageDefaultName[]("Test_VDB_dependencies_404first"); - rc_t CC UsageSummary(const char *progname) { return 0; } - - rc_t CC KMain(int argc, char *argv[]) { - KConfigDisableUserSettings(); - return Test_VDB_dependencies_404firstSuite(argc, argv); - } +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); + return Test_VDB_dependencies_404firstSuite(argc, argv); } diff --git a/test/vdb/Test_VDB_dependencies_wgs.cpp b/test/vdb/Test_VDB_dependencies_wgs.cpp index ab09692f0..245de9262 100644 --- a/test/vdb/Test_VDB_dependencies_wgs.cpp +++ b/test/vdb/Test_VDB_dependencies_wgs.cpp @@ -54,7 +54,7 @@ TEST_CASE(Test_VDB_dependencies_wgs) { REQUIRE_RC(VDBManagerOpenDBRead(m, &b, NULL, "ERR3091357")); const VDBDependencies *d = NULL; - /* The following has to make a single SDL call for + /* The following has to make a single SDL call for multiple WGS refseqs that are resolved to the same URL */ REQUIRE_RC(VDatabaseListDependencies(b, &d, false)); REQUIRE_RC(VDBDependenciesRelease(d)); @@ -65,14 +65,7 @@ TEST_CASE(Test_VDB_dependencies_wgs) { } #endif -extern "C" { - ver_t CC KAppVersion(void) { return 0x1000000; } - rc_t CC Usage(const Args *args) { return 0; } - const char UsageDefaultName[]("Test_VDB_dependencies_wgs"); - rc_t CC UsageSummary(const char *progname) { return 0; } - - rc_t CC KMain(int argc, char *argv[]) { - KConfigDisableUserSettings(); - return Test_VDB_dependencies_wgsSuite(argc, argv); - } +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); + return Test_VDB_dependencies_wgsSuite(argc, argv); } diff --git a/test/vdb/WVDB_Fixture.hpp b/test/vdb/WVDB_Fixture.hpp index 9a2dea657..ff3d43b47 100644 --- a/test/vdb/WVDB_Fixture.hpp +++ b/test/vdb/WVDB_Fixture.hpp @@ -63,7 +63,7 @@ class WVDB_Fixture { THROW_ON_RC ( VDBManagerMakeUpdate ( & m_mgr, NULL ) ); } - ~WVDB_Fixture() + virtual ~WVDB_Fixture() { if ( m_db != 0 ) { @@ -214,10 +214,10 @@ class WVDB_Fixture static std :: string DumpSchema(VSchema & p_schema, bool compact = true) { - auto FlushSchema = [](void *fd, const void * buffer, size_t size) -> rc_t + auto FlushSchema = [](void *fd, const void * buffer, size_t size) noexcept -> rc_t { std :: ostream & out = *static_cast < std :: ostream * > (fd); - out.write(static_cast < const char * > (buffer), size); + out.write(static_cast < const char * > (buffer), (std::streamsize)size); out.flush(); return 0; }; @@ -229,7 +229,7 @@ class WVDB_Fixture free_intrinsic = true; } std :: ostringstream out; - bool failed = VSchemaDump( & p_schema, compact ? sdmCompact : sdmPrint, 0, FlushSchema, &out); + bool failed = VSchemaDump( & p_schema, compact ? sdmCompact : sdmPrint, 0, FlushSchema, &out) != 0; if ( free_intrinsic ) { VSchemaRelease( p_schema.dad ); diff --git a/test/vdb/check-user-agent-header-in-thread.cpp b/test/vdb/check-user-agent-header-in-thread.cpp index e98a1335e..03ed95cd3 100644 --- a/test/vdb/check-user-agent-header-in-thread.cpp +++ b/test/vdb/check-user-agent-header-in-thread.cpp @@ -58,8 +58,9 @@ void CheckRc(rc_t rc, const char* code, const char* file, int line) size_t error_len; RCExplain(rc, buffer1, sizeof(buffer1), &error_len); char buffer2[8192]; - unsigned len = sprintf(buffer2, "%s:%d: %s failed: %#x: %s\n", + int len = snprintf(buffer2, sizeof(buffer2), "%s:%d: %s failed: %#x: %s\n", file, line, code, rc, buffer1); + assert(0 < len && len < sizeof(buffer2)); write(2, buffer2, len); exit(1); } diff --git a/test/vdb/test-VDB-3060.cpp b/test/vdb/test-VDB-3060.cpp index 4fb1e7d7e..9d094849d 100644 --- a/test/vdb/test-VDB-3060.cpp +++ b/test/vdb/test-VDB-3060.cpp @@ -30,11 +30,11 @@ #include // TEST_CASE #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -94,10 +94,10 @@ TEST_CASE( GetCacheRoot_1 ) rc = VPathMakeString ( vpath, &spath ); if ( rc != 0 ) FAIL( "FAIL: VPathMakeString( vpath, &spatch ) failed" ); - + original_value = std::string( spath->addr, spath->size ); std::cout << "original value: " << original_value << std::endl; - + if ( spath != NULL ) StringWhack( spath ); @@ -121,11 +121,11 @@ TEST_CASE( SetCacheRoot_1 ) rc = VFSManagerMakePath ( vfs_mgr, &vpath, other_path ); if ( rc != 0 ) FAIL( "FAIL: VFSManagerMakePath() failed" ); - + rc = VDBManagerSetCacheRoot( NULL, vpath ); if ( rc == 0 ) FAIL( "FAIL: VDBManagerSetCacheRoot( NULL, vpath ) succeed" ); - + rc = VDBManagerSetCacheRoot( vdb_mgr, vpath ); if ( rc != 0 ) FAIL( "FAIL: VDBManagerSetCacheRoot( mgr, vpath ) failed" ); @@ -152,7 +152,7 @@ TEST_CASE( GetCacheRoot_2 ) rc = VPathMakeString ( vpath, &spath ); if ( rc != 0 ) FAIL( "FAIL: VPathMakeString( vpath, &spatch ) failed" ); - + std::string s1 = std::string( spath->addr, spath->size ); std::string s2 = std::string( other_path ); std::cout << "after setting different value: " << s1; @@ -163,7 +163,7 @@ TEST_CASE( GetCacheRoot_2 ) std::cout << " - we did not expected this!" << std::endl; FAIL( "FAIL: unexpected value after setting a new cache-root" ); } - + if ( spath != NULL ) StringWhack( spath ); @@ -181,7 +181,7 @@ TEST_CASE( SetCacheRoot_2 ) rc_t rc = VFSManagerMakePath ( vfs_mgr, &vpath, original_value.c_str() ); if ( rc != 0 ) FAIL( "FAIL: VFSManagerMakePath() failed" ); - + rc = VDBManagerSetCacheRoot( vdb_mgr, vpath ); if ( rc != 0 ) FAIL( "FAIL: VDBManagerSetCacheRoot( mgr, vpath ) failed" ); @@ -207,13 +207,13 @@ TEST_CASE( GetCacheRoot_3 ) rc = VPathMakeString ( vpath, &spath ); if ( rc != 0 ) FAIL( "FAIL: VPathMakeString( vpath, &spath ) failed" ); - + std::string s = std::string( spath->addr, spath->size ); std::cout << "reverted to original value of: " << s << std::endl; if ( s != original_value ) FAIL( "FAIL: did not restore original value" ); - + if ( spath != NULL ) StringWhack( spath ); @@ -230,7 +230,7 @@ TEST_CASE( two_managers ) String const * spath1 = NULL; String const * spath2 = NULL; rc_t rc; - + rc = VFSManagerMakePath ( vfs_mgr, &vpath_new, "something_different" ); if ( rc != 0 ) FAIL( "FAIL: VFSManagerMakePath( vpath_new ) failed" ); @@ -265,10 +265,10 @@ TEST_CASE( two_managers ) FAIL( "FAIL: cache-root values do not match" ); else std::cout << "cache-root values are the same" << std::endl; - + if ( spath1 != NULL ) StringWhack( spath1 ); if ( spath2 != NULL ) StringWhack( spath2 ); - if ( vpath_new != NULL ) VPathRelease( vpath_new ); + if ( vpath_new != NULL ) VPathRelease( vpath_new ); if ( vpath1 != NULL ) VPathRelease( vpath1 ); if ( vpath2 != NULL ) VPathRelease( vpath2 ); if ( vdb_mgr2 != NULL ) VDBManagerRelease ( vdb_mgr2 ); @@ -287,12 +287,12 @@ TEST_CASE( root_tmp ) rc = KDBManagerGetVFSManager( kdb_mgr, &vfs_mgr_1 ); if ( rc != 0 ) FAIL( "FAIL: KDBManagerGetVFSManager() failed" ); - + VPath * vpath = NULL; rc = VFSManagerMakeSysPath( vfs_mgr_1, &vpath, "/tmp1" ); if ( rc != 0 ) FAIL( "FAIL: VFSManagerMakeSysPath() failed" ); - + rc = VDBManagerSetCacheRoot( vdb_mgr, vpath ); if ( rc != 0 ) FAIL( "FAIL: VDBManagerSetCacheRoot( mgr, vpath ) failed" ); @@ -363,7 +363,7 @@ rc_t prepare_test( const char * sub ) if ( rc == 0 ) rc = string_printf ( new_home_buffer, sizeof new_home_buffer, &num_writ, "HOME=%s", new_home ); if ( rc == 0 ) - rc = putenv( new_home_buffer ); + rc = (rc_t)putenv( new_home_buffer ); if ( rc == 0 ) rc = create_test_config( org_home ); return rc; @@ -382,17 +382,7 @@ void finish_test() } //////////////////////////////////////////// Main -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) { return 0x1000000; } -rc_t CC UsageSummary ( const char * progname ) { return 0; } -rc_t CC Usage ( const Args * args ) { return 0; } -const char UsageDefaultName[] = "test-VDB-3060"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { rc_t rc = prepare_test( HomeSub ); if ( rc == 0 ) @@ -400,12 +390,10 @@ rc_t CC KMain ( int argc, char *argv [] ) rc = make_global_managers(); if ( rc == 0 ) { - rc = VDB_3060( argc, argv ); + rc = (rc_t)VDB_3060( argc, argv ); release_global_managers(); } } finish_test(); - return rc; -} - + return (int)rc; } diff --git a/test/vdb/test-VDB-3061.cpp b/test/vdb/test-VDB-3061.cpp index f4c223aa8..7da8fae04 100644 --- a/test/vdb/test-VDB-3061.cpp +++ b/test/vdb/test-VDB-3061.cpp @@ -28,13 +28,13 @@ #include // TEST_CASE #include #include -#include -#include +#include +#include #include -#include +#include #include -#include -#include +#include +#include #include #include @@ -55,7 +55,7 @@ static rc_t create_cache_file( KDirectory * dir, const char * path, const char * if ( rc == 0 ) { KFileRelease( f ); - + KTime_t date = KTimeStamp() - age_in_seconds; rc = KDirectorySetDate ( dir, false, date, "%s/ncbi/%s/%s", path, sub, name ); } @@ -104,7 +104,7 @@ static void clear_out( const char * path ) TEST_CASE( CLEAR_CACHE_1 ) { REQUIRE_RC( KOutMsg( "running: CLEAR_CACHE_1\n" ) ); - + /* create a repository-structure equivalent to the config-values, with 3 files in it */ KDirectory * dir; REQUIRE_RC( KDirectoryNativeDir( &dir ) ); @@ -112,7 +112,7 @@ TEST_CASE( CLEAR_CACHE_1 ) REQUIRE_RC( create_repo_dirs( dir, new_home, "dbGaP-2956", 4, 0 ) ); /* 4 days old */ REQUIRE_RC( create_repo_dirs( dir, new_home, "dbGaP-4831", 5, -5 ) ); /* 5 days - 5 seconds old */ REQUIRE_RC( KDirectoryRelease ( dir ) ); - + /* we run the new function VDBManagerDeleteCacheOlderThan() with a 5-day threshold */ const VDBManager * vdb_mgr; REQUIRE_RC( VDBManagerMakeRead( &vdb_mgr, NULL ) ); @@ -128,7 +128,7 @@ TEST_CASE( CLEAR_CACHE_1 ) uint32_t pt3 = KDirectoryPathType( dir, "%s/ncbi/dbGaP-4831/sra/file1.txt", new_home ); REQUIRE_EQ( pt3, (uint32_t)kptFile ); REQUIRE_RC( KDirectoryRelease ( dir ) ); - + REQUIRE_RC( KOutMsg( "done: CLEAR_CACHE_1\n" ) ); } @@ -246,7 +246,7 @@ static rc_t prepare_test( KConfig **cfg, const char * sub ) rc = string_printf ( new_home_buffer, sizeof new_home_buffer, &num_writ, "USERPROFILE=%s", new_home ); #endif if ( rc == 0 ) - rc = putenv( new_home_buffer ); + rc = (rc_t)putenv( new_home_buffer ); if ( rc == 0 ) rc = create_test_config( cfg, new_home ); return rc; @@ -270,26 +270,14 @@ void finish_test( const char * sub ) } //////////////////////////////////////////// Main -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) { return 0x1000000; } -rc_t CC UsageSummary ( const char * progname ) { return 0; } -rc_t CC Usage ( const Args * args ) { return 0; } -const char UsageDefaultName[] = "test-VDB-3060"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); KConfig *cfg; rc_t rc = prepare_test( &cfg, HomeSub ); if ( rc == 0 ) - rc = VDB_3061( argc, argv ); + rc = (rc_t)VDB_3061( argc, argv ); finish_test( HomeSub ); KConfigRelease ( cfg ); - return rc; -} - + return (int)rc; } diff --git a/test/vdb/test-VDB-3305.cpp b/test/vdb/test-VDB-3305.cpp index 29cb9743f..a0b661085 100644 --- a/test/vdb/test-VDB-3305.cpp +++ b/test/vdb/test-VDB-3305.cpp @@ -30,11 +30,11 @@ #include // TEST_CASE #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -79,7 +79,7 @@ TEST_CASE( SetCacheRoot_1 ) rc_t rc = VFSManagerMakePath( vfs_mgr, &vpath, other_path ); if ( rc != 0 ) FAIL( "FAIL: VFSManagerMakePath() failed" ); - + rc = VDBManagerSetCacheRoot( vdb_mgr, vpath ); if ( rc != 0 ) FAIL( "FAIL: VDBManagerSetCacheRoot( mgr, vpath ) failed" ); @@ -111,7 +111,7 @@ rc_t prepare_test( const char * sub ) if ( rc == 0 ) { KOutMsg( "%s\n", new_home ); - + rc = KDirectoryCreateDir( dir, 0775, ( kcmInit | kcmParents ) , "%s/.ncbi", new_home ); KDirectoryRelease( dir ); } @@ -132,17 +132,7 @@ void finish_test( void ) } //////////////////////////////////////////// Main -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) { return 0x1000000; } -rc_t CC UsageSummary ( const char * progname ) { return 0; } -rc_t CC Usage ( const Args * args ) { return 0; } -const char UsageDefaultName[] = "test-VDB-3305"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { rc_t rc = prepare_test( HomeSub ); if ( rc == 0 ) @@ -150,12 +140,10 @@ rc_t CC KMain ( int argc, char *argv [] ) rc = make_global_managers(); if ( rc == 0 ) { - rc = VDB_3305( argc, argv ); + rc = (rc_t)VDB_3305( argc, argv ); release_global_managers(); } } //finish_test(); - return rc; -} - + return (int)rc; } diff --git a/test/vdb/test-VDB-3418.cpp b/test/vdb/test-VDB-3418.cpp index 6e0c95ceb..0a902db01 100644 --- a/test/vdb/test-VDB-3418.cpp +++ b/test/vdb/test-VDB-3418.cpp @@ -30,11 +30,11 @@ #include // TEST_CASE #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -93,7 +93,7 @@ struct Cursor { uint32_t count = 0; uint32_t boff = 0; uint32_t elem_bits = 0; - + if (VCursorCellDataDirect(curs, row, column[col].first, &elem_bits, &base, &boff, &count)) throw std::runtime_error("VCursorCellDataDirect"); if (sizeof(T) * 8 != elem_bits) throw std::logic_error("element size"); if (boff) throw std::logic_error("bit aligned data"); @@ -163,17 +163,7 @@ TEST_CASE( CheckSEQUENCE ) } //////////////////////////////////////////// Main -extern "C" +int main(int argc, char *argv[]) { -#include - - ver_t CC KAppVersion ( void ) { return 0x1000000; } - rc_t CC UsageSummary ( const char * progname ) { return 0; } - rc_t CC Usage ( const Args * args ) { return 0; } - const char UsageDefaultName[] = "test-VDB-3418"; - - rc_t CC KMain(int argc, char *argv[]) - { - return VDB_3418(argc, argv); - } + return VDB_3418(argc, argv); } diff --git a/test/vdb/test-VDB-4156.cpp b/test/vdb/test-VDB-4156.cpp index a5a5960a8..891859717 100644 --- a/test/vdb/test-VDB-4156.cpp +++ b/test/vdb/test-VDB-4156.cpp @@ -92,32 +92,7 @@ FIXTURE_TEST_CASE ( DumpToKMDataNode, WVDB_Fixture) } //////////////////////////////////////////// Main -extern "C" +int main ( int argc, char *argv [] ) { - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-wvdb"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc=KDBVDBTestSuite(argc, argv); - return rc; -} - + return KDBVDBTestSuite(argc, argv); } diff --git a/test/vdb/test-VDB-NodeDrop.cpp b/test/vdb/test-VDB-NodeDrop.cpp new file mode 100644 index 000000000..f80f2da17 --- /dev/null +++ b/test/vdb/test-VDB-NodeDrop.cpp @@ -0,0 +1,130 @@ +// =========================================================================== +// +// PUBLIC DOMAIN NOTICE +// National Center for Biotechnology Information +// +// This software/database is a "United States Government Work" under the +// terms of the United States Copyright Act. It was written as part of +// the author's official duties as a United States Government employee and +// thus cannot be copyrighted. This software/database is freely available +// to the public for use. The National Library of Medicine and the U.S. +// Government have not placed any restriction on its use or reproduction. +// +// Although all reasonable efforts have been taken to ensure the accuracy +// and reliability of the software and data, the NLM and the U.S. +// Government do not and cannot warrant the performance or results that +// may be obtained by using this software or data. The NLM and the U.S. +// Government disclaim all warranties, express or implied, including +// warranties of performance, merchantability or fitness for any particular +// purpose. +// +// Please cite the author in any work or product based on this material. +// +// =========================================================================== + + +#include +#include + +#include + +#include <../libs/vdb/schema-priv.h> +#include <../libs/vdb/schema-parse.h> +#include <../libs/vdb/dbmgr-priv.h> + +#include +#include +#include +#include + +#include "WVDB_Fixture.hpp" + +#include + +#include +#include + +using namespace std; + +TEST_SUITE( KDBNodeDropTestSuite ) + +const string DName = "NodeDrop"; + +FIXTURE_TEST_CASE (NodeDropTest, WVDB_Fixture) +{ + m_databaseName = ScratchDir + DName; + RemoveDatabase(); + + KDirectory * Dir; + REQUIRE_RC ( KDirectoryNativeDir ( & Dir ) ); + + KDBManager * Mgr; + REQUIRE_RC ( KDBManagerMakeUpdate ( & Mgr, Dir ) ); + + KDatabase * Db; + REQUIRE_RC ( KDBManagerCreateDB ( Mgr, & Db, kcmInit, "%s", m_databaseName . c_str () ) ); + + KMetadata * Md; + REQUIRE_RC ( KDatabaseOpenMetadataUpdate ( Db, & Md ) ); + + KMDataNode * Node; + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "A/B/C")); + REQUIRE_RC(KMDataNodeWriteCString(Node, "1")); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "D/E/F")); + REQUIRE_RC(KMDataNodeWriteCString(Node, "2")); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "GG/H/I")); + REQUIRE_RC(KMDataNodeWriteCString(Node, "3")); + REQUIRE_RC(KMDataNodeRelease(Node)); + + // delete top level node + const KMDataNode* rNode; + REQUIRE_RC(KMetadataOpenNodeRead(Md, &rNode, "A")); + REQUIRE_RC(KMDataNodeRelease(rNode)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, NULL)); + REQUIRE_RC(KMDataNodeDropChild(Node,"A")); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_EQ(GetRCState(KMetadataOpenNodeRead(Md, &rNode, "A")), rcNotFound); + + // delete lower level node + REQUIRE_RC(KMetadataOpenNodeRead(Md, &rNode, "D/E")); + REQUIRE_RC(KMDataNodeRelease(rNode)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, NULL)); + REQUIRE_RC(KMDataNodeDropChild(Node, "D/E")); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_EQ(GetRCState(KMetadataOpenNodeRead(Md, &rNode, "D/E")), + rcNotFound); + REQUIRE_RC(KMetadataOpenNodeRead(Md, &rNode, "D")); + REQUIRE_RC(KMDataNodeRelease(rNode)); + + // ignore slashes + REQUIRE_RC(KMetadataOpenNodeRead(Md, &rNode, "GG")); + REQUIRE_RC(KMDataNodeRelease(rNode)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, NULL)); + REQUIRE_RC(KMDataNodeDropChild(Node, "//GG//")); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_EQ(GetRCState(KMetadataOpenNodeRead(Md, &rNode, "GG")), rcNotFound); + + REQUIRE_RC ( KMetadataRelease ( Md ) ); + REQUIRE_RC ( KDatabaseRelease ( Db ) ); + REQUIRE_RC ( KDBManagerRelease ( Mgr ) ); + REQUIRE_RC ( KDirectoryRelease ( Dir ) ); + + RemoveDatabase(); +} + +//////////////////////////////////////////// Main +int main ( int argc, char *argv [] ) +{ + return KDBNodeDropTestSuite(argc, argv); +} diff --git a/test/vdb/test-VDB-TooBigMeta.cpp b/test/vdb/test-VDB-TooBigMeta.cpp new file mode 100644 index 000000000..1148a1944 --- /dev/null +++ b/test/vdb/test-VDB-TooBigMeta.cpp @@ -0,0 +1,124 @@ +// =========================================================================== +// +// PUBLIC DOMAIN NOTICE +// National Center for Biotechnology Information +// +// This software/database is a "United States Government Work" under the +// terms of the United States Copyright Act. It was written as part of +// the author's official duties as a United States Government employee and +// thus cannot be copyrighted. This software/database is freely available +// to the public for use. The National Library of Medicine and the U.S. +// Government have not placed any restriction on its use or reproduction. +// +// Although all reasonable efforts have been taken to ensure the accuracy +// and reliability of the software and data, the NLM and the U.S. +// Government do not and cannot warrant the performance or results that +// may be obtained by using this software or data. The NLM and the U.S. +// Government disclaim all warranties, express or implied, including +// warranties of performance, merchantability or fitness for any particular +// purpose. +// +// Please cite the author in any work or product based on this material. +// +// =========================================================================== + + +#include +#include + +#include + +#include <../libs/vdb/schema-priv.h> +#include <../libs/vdb/schema-parse.h> +#include <../libs/vdb/dbmgr-priv.h> + +#include +#include +#include +#include + +#include "WVDB_Fixture.hpp" + +#include + +#include +#include + +using namespace std; + +TEST_SUITE(TooBigMetaTestSuite) + +const string DName = "TooBigMeta"; + +FIXTURE_TEST_CASE (TooBigMetaTest, WVDB_Fixture) +{ + m_databaseName = ScratchDir + DName; + RemoveDatabase(); + + KDirectory * Dir; + REQUIRE_RC ( KDirectoryNativeDir ( & Dir ) ); + + KDBManager * Mgr; + REQUIRE_RC ( KDBManagerMakeUpdate ( & Mgr, Dir ) ); + + KDatabase * Db; + REQUIRE_RC ( KDBManagerCreateDB ( Mgr, & Db, kcmInit, "%s", m_databaseName . c_str () ) ); + + KMetadata * Md; + REQUIRE_RC ( KDatabaseOpenMetadataUpdate ( Db, & Md ) ); + + size_t size(8193); + void* buffer(malloc(size)); + REQUIRE(buffer); + + // Created metadata will overflow buffer in WMetadataFlush. + // It will be flushed to disk + // and check that we will be able to load Metadata will not be performed. + KMDataNode * Node; + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "A")); + REQUIRE_RC(KMDataNodeWrite(Node, buffer, size)); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "B")); + REQUIRE_RC(KMDataNodeWrite(Node, buffer, size)); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "C")); + REQUIRE_RC(KMDataNodeWrite(Node, buffer, size)); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "D")); + REQUIRE_RC(KMDataNodeWrite(Node, buffer, size)); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "E")); + REQUIRE_RC(KMDataNodeWrite(Node, buffer, size)); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "F")); + REQUIRE_RC(KMDataNodeWrite(Node, buffer, size)); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "G")); + REQUIRE_RC(KMDataNodeWrite(Node, buffer, size)); + REQUIRE_RC(KMDataNodeRelease(Node)); + + REQUIRE_RC(KMetadataOpenNodeUpdate(Md, &Node, "H")); + REQUIRE_RC(KMDataNodeWrite(Node, buffer, size)); + REQUIRE_RC(KMDataNodeRelease(Node)); + + free(buffer); + + REQUIRE_RC ( KMetadataRelease ( Md ) ); + REQUIRE_RC ( KDatabaseRelease ( Db ) ); + REQUIRE_RC ( KDBManagerRelease ( Mgr ) ); + REQUIRE_RC ( KDirectoryRelease ( Dir ) ); + + RemoveDatabase(); +} + +//////////////////////////////////////////// Main +int main ( int argc, char *argv [] ) +{ + return TooBigMetaTestSuite(argc, argv); +} diff --git a/test/vdb/test-VDBManagerGetObjVersion.cpp b/test/vdb/test-VDBManagerGetObjVersion.cpp index a41ee147a..189f1675c 100644 --- a/test/vdb/test-VDBManagerGetObjVersion.cpp +++ b/test/vdb/test-VDBManagerGetObjVersion.cpp @@ -24,6 +24,7 @@ * ========================================================================== */ #include // ArgsWhack +#include // ArgsWhack #include /* KConfigDisableUserSettings */ #include /* KDbgSetString */ #include /* TEST_SUITE_WITH_ARGS_HANDLER */ @@ -93,18 +94,12 @@ TEST_CASE(Test_VDBManagerGetObjVersion) { REQUIRE_RC(VDBManagerRelease(m)); } -extern "C" { - ver_t CC KAppVersion(void) { return 0; } - const char UsageDefaultName[]("Test_VDBManagerGetObjVersion"); - rc_t CC UsageSummary(const char *progname) { return 0; } - rc_t CC Usage(const Args *args) { return 0; } +int main(int argc, char *argv[]) { + VDB::Application app(argc, argv); + if (0) + KDbgSetString("VFS"); - rc_t CC KMain(int argc, char *argv[]) { - if (0) - KDbgSetString("VFS"); + KConfigDisableUserSettings(); - KConfigDisableUserSettings(); - - return Test_VDBManagerGetObjVersionSuite(argc, argv); - } + return Test_VDBManagerGetObjVersionSuite(argc, argv); } diff --git a/test/vdb/test-blob-val.cpp b/test/vdb/test-blob-val.cpp index 552e513ba..eb0ddd013 100644 --- a/test/vdb/test-blob-val.cpp +++ b/test/vdb/test-blob-val.cpp @@ -24,10 +24,12 @@ #include +#include + #include // VDBManager -#include -#include -#include +#include +#include +#include #include /* VSchemaRelease */ #include @@ -155,33 +157,8 @@ FIXTURE_TEST_CASE ( BlobValidationEnabled, VDB_Fixture) //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-blob-val"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=BlobValidationTestSuite(argc, argv); - return rc; -} - + return BlobValidationTestSuite(argc, argv); } diff --git a/test/vdb/test-bytecode.cpp b/test/vdb/test-bytecode.cpp index a6e0dde57..d9d698196 100644 --- a/test/vdb/test-bytecode.cpp +++ b/test/vdb/test-bytecode.cpp @@ -24,6 +24,8 @@ #include "WVDB_Fixture.hpp" +#include + #include #include #include @@ -525,33 +527,8 @@ FIXTURE_TEST_CASE ( FunctionProdCallLegacyBlobFunc, ByteCodeFixture ) // bcReturn - remove ? //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-bytecode"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=ByteCodeTestSuite(argc, argv); - return rc; -} - + return ByteCodeTestSuite(argc, argv); } diff --git a/test/vdb/test-database-cmn.cpp b/test/vdb/test-database-cmn.cpp index 6bd91d694..c76d99e8c 100644 --- a/test/vdb/test-database-cmn.cpp +++ b/test/vdb/test-database-cmn.cpp @@ -149,13 +149,7 @@ FIXTURE_TEST_CASE(BAD_NUM_GAP_FULL, Fixture) { } #endif -extern "C" { - ver_t CC KAppVersion(void) { return 0; } - const char UsageDefaultName[] = "test-database-cmn"; - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage(const Args * args) { return 0; } - rc_t CC KMain(int argc, char * argv[]) { - KConfigDisableUserSettings(); - return DatabaseCmnTestSuite(argc, argv); - } +int main(int argc, char * argv[]) { + KConfigDisableUserSettings(); + return DatabaseCmnTestSuite(argc, argv); } diff --git a/test/vdb/test-dependencies_dflt.cpp b/test/vdb/test-dependencies_dflt.cpp index 905793984..67d6b986e 100644 --- a/test/vdb/test-dependencies_dflt.cpp +++ b/test/vdb/test-dependencies_dflt.cpp @@ -475,13 +475,8 @@ static rc_t argsHandler(int argc, char* argv[]) { return rc; } -extern "C" { - ver_t CC KAppVersion(void) { return 0x1000000; } - const char UsageDefaultName[] = "test-dependencies"; - rc_t CC UsageSummary(const char *progname) { return 0; } - rc_t CC Usage(const Args *args) { return 0; } - rc_t CC KMain(int argc, char *argv[]) { - KConfigDisableUserSettings(); +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); if ( 0) assert(!KDbgSetString("KFS-FILE")); @@ -489,6 +484,5 @@ if ( if( 0) assert(!KDbgSetString("VFS")); - return rc_t(TestDependenciesSuite(argc, argv)); - } + return TestDependenciesSuite(argc, argv); } diff --git a/test/vdb/test-link.c b/test/vdb/test-link.c index 8dbdb7370..52d1f9c26 100644 --- a/test/vdb/test-link.c +++ b/test/vdb/test-link.c @@ -65,25 +65,7 @@ TestVdb ( const char * p_acc, const char * p_columns[]) return 0; } -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-link"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { const char * columns [] = { "READ_LEN", NULL }; rc_t rc; @@ -99,6 +81,6 @@ rc_t CC KMain ( int argc, char *argv [] ) string_printf ( msg, sizeof msg, NULL, "Link test failed, rc = %R", rc ); printf("%s\n", msg); } - return rc; + return (int)rc; } diff --git a/test/vdb/test-linker.cpp b/test/vdb/test-linker.cpp index c2174c2d4..f2d413ba7 100644 --- a/test/vdb/test-linker.cpp +++ b/test/vdb/test-linker.cpp @@ -24,6 +24,8 @@ #include "WVDB_Fixture.hpp" +#include + #include using namespace std; @@ -197,32 +199,7 @@ FIXTURE_TEST_CASE ( OverrideIntrinsic, TestLinkerFicture ) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) +int main ( int argc, char *argv [] ) { - return 0; -} - -const char UsageDefaultName[] = "test-linker"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc=LinkerTestSuite(argc, argv); - return rc; -} - + return LinkerTestSuite(argc, argv); } diff --git a/test/vdb/test-sparse-col.cpp b/test/vdb/test-sparse-col.cpp index e422d8ace..5f931285e 100644 --- a/test/vdb/test-sparse-col.cpp +++ b/test/vdb/test-sparse-col.cpp @@ -24,6 +24,8 @@ #include +#include + #include // VDBManager #include #include @@ -191,7 +193,7 @@ class VDB_Fixture "%s", m_databaseName . c_str () ) ); } - catch (std::logic_error & e) + catch (std::logic_error &) { VDBManagerRelease ( mgr ); throw; @@ -341,33 +343,8 @@ FIXTURE_TEST_CASE ( SparseColEmpty, VDB_Fixture) //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-sparse-col"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=SparseColTestSuite(argc, argv); - return rc; -} - + return SparseColTestSuite(argc, argv); } diff --git a/test/vdb/test-tablecursor.cpp b/test/vdb/test-tablecursor.cpp index 7952adcee..8a0aedad1 100644 --- a/test/vdb/test-tablecursor.cpp +++ b/test/vdb/test-tablecursor.cpp @@ -29,6 +29,10 @@ #include #include +#include + +#include + #include #include #include @@ -645,7 +649,7 @@ FIXTURE_TEST_CASE( VTableCursor_InstallTrigger, TableCursorFixture ) REQUIRE_RC_FAIL ( VCursorInstallTrigger ( (VCursor*)m_cur, & prod ) ); // write side only } -void CC incrementUint32 ( BSTNode *n, void *data ) +void CC incrementUint32 ( BSTNode *n, void *data ) noexcept { uint32_t * count = reinterpret_cast ( data ); ++ * count; @@ -677,10 +681,6 @@ FIXTURE_TEST_CASE( VTableCursor_ListReadableColumns, TableCursorFixture ) } //////////////////////////////////////////// Main -#include - -#include - static rc_t argsHandler ( int argc, char * argv [] ) { Args * args = NULL; rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0, NULL, 0 ); @@ -688,30 +688,8 @@ static rc_t argsHandler ( int argc, char * argv [] ) { return rc; } -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-tablecursor"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=VdbTableCursorTestSuite_Read(argc, argv); - return rc; -} - + return VdbTableCursorTestSuite_Read(argc, argv); } diff --git a/test/vdb/test-textvdb.cpp b/test/vdb/test-textvdb.cpp index dcc235c9a..c47ddd715 100644 --- a/test/vdb/test-textvdb.cpp +++ b/test/vdb/test-textvdb.cpp @@ -247,31 +247,7 @@ FIXTURE_TEST_CASE( VdbMgr_Read_I8, TextVdbReadFixture ) } //////////////////////////////////////////// Main -extern "C" +int main( int argc, char *argv [] ) { - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-vdb"; - -rc_t CC KMain ( int argc, char *argv [] ) -{ - rc_t rc=VdbTextSuite(argc, argv); - return rc; -} - + return VdbTextSuite(argc, argv); } diff --git a/test/vdb/test-vdb-meta-cmp-copy.cpp b/test/vdb/test-vdb-meta-cmp-copy.cpp index d5fc54aeb..b91f91825 100644 --- a/test/vdb/test-vdb-meta-cmp-copy.cpp +++ b/test/vdb/test-vdb-meta-cmp-copy.cpp @@ -58,7 +58,7 @@ rc_t write_some_data( VTable * t, bool full ) { const uint32_t data32[ 5 ] = { 10, 20, 30, 40, 50 }; for ( uint32_t i = 0; 0 == rc && i < 10; ++i ) { rc = VCursorOpenRow( c ); - uint32_t n = full ? 5 : 4; + uint32_t n = full ? 5u : 4u; if ( 0 == rc ) { rc = VCursorWrite( c, col_ids_1[ 0 ], 8, data8, 0, n ); } if ( 0 == rc ) { rc = VCursorWrite( c, col_ids_1[ 1 ], 32, data32, 0, n ); } if ( 0 == rc ) { rc = VCursorCommitRow( c ); } @@ -90,16 +90,16 @@ rc_t append_some_metadata( VTable * t ) { class Test_Meta_Fixture { public: - typedef std::map< std::string, const VTable * > t_tables; + typedef std::map< std::string, const VTable * > t_tables; typedef std::map< std::string, const VDatabase * > t_dbs; - + KDirectory * dir; VDBManager * mgr; VSchema * schema; bool remove_in_destructor; t_tables tables; t_dbs dbs; - + Test_Meta_Fixture() : dir( nullptr ), mgr( nullptr ), schema( nullptr ), remove_in_destructor( true ) { if ( 0 != KDirectoryNativeDir( &dir ) ) { @@ -126,7 +126,7 @@ class Test_Meta_Fixture { throw std :: logic_error ( "Test_Meta_Fixture: VDatabaseCreateTable failed" ); } } - tables . insert( { name, tbl } ); + tables . insert( { name, tbl } ); return tbl; } @@ -136,7 +136,7 @@ class Test_Meta_Fixture { name.c_str() ) ) { throw std :: logic_error ( "Test_Meta_Fixture: VDBManagerCreateDB failed" ); } - dbs . insert( { name, db } ); + dbs . insert( { name, db } ); return db; } @@ -151,7 +151,7 @@ class Test_Meta_Fixture { throw std :: logic_error ( "Test_Meta_Fixture: VDatabaseOpenTableRead failed" ); } } - tables . insert( { name, tbl } ); + tables . insert( { name, tbl } ); return tbl; } @@ -160,7 +160,7 @@ class Test_Meta_Fixture { if ( 0 != VDBManagerOpenDBRead( mgr, &db, nullptr, name . c_str() ) ) { throw std :: logic_error ( "Test_Meta_Fixture: VDBManagerOpenDBRead failed" ); } - dbs . insert( { name, db } ); + dbs . insert( { name, db } ); return db; } @@ -175,7 +175,7 @@ class Test_Meta_Fixture { throw std :: logic_error ( "Test_Meta_Fixture: VDatabaseOpenTableRead failed" ); } } - tables . insert( { name, tbl } ); + tables . insert( { name, tbl } ); return tbl; } @@ -184,7 +184,7 @@ class Test_Meta_Fixture { if ( 0 != VDBManagerOpenDBUpdate( mgr, &db, nullptr, name . c_str() ) ) { throw std :: logic_error ( "Test_Meta_Fixture: VDBManagerOpenDBUpdate failed" ); } - dbs . insert( { name, db } ); + dbs . insert( { name, db } ); return db; } @@ -240,7 +240,7 @@ FIXTURE_TEST_CASE( Compare_Table_Meta_Equal, Test_Meta_Fixture ) { /* * very important: we cannot compare tables that are still open after * beeing written into them. - * + * * these tables have to be closed, then reopened in read-only mode! * --- the write_some_data() - function does that... */ @@ -273,7 +273,7 @@ FIXTURE_TEST_CASE( Compare_Table_Meta_Not_Equal, Test_Meta_Fixture ) { // // very important: we cannot compare tables that are still open after // beeing written into them. - // + // // these tables have to be closed, then reopened in read-only mode! // --- the write_some_data() - function does that... @@ -458,11 +458,7 @@ FIXTURE_TEST_CASE( Copy_DB_Meta, Test_Meta_Fixture ) { } //////////////////////////////////////////// Main -extern "C" { - #include - ver_t CC KAppVersion( void ) { return 0x1000000; } - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage( const Args * args ) { return 0; } - const char UsageDefaultName[] = "test-vdb-meta-cmp-copy"; - rc_t CC KMain( int argc, char *argv [] ) { return VDB_META_CMP_COPY_Suite( argc, argv ); } +int main( int argc, char *argv [] ) +{ + return VDB_META_CMP_COPY_Suite( argc, argv ); } diff --git a/test/vdb/test-vdb-slow.cpp b/test/vdb/test-vdb-slow.cpp index 9dae62641..075794dba 100644 --- a/test/vdb/test-vdb-slow.cpp +++ b/test/vdb/test-vdb-slow.cpp @@ -26,6 +26,7 @@ #include // TEST_CASE #include +#include // #include // #include @@ -62,8 +63,6 @@ FIXTURE_TEST_CASE(TestReadBitsDirect_vs_CellDataDirect, VDB_Fixture) REQUIRE_EQ( remaining_count_ReadBits, remaining_count_CellData ); } //////////////////////////////////////////// Main -#include - static rc_t argsHandler ( int argc, char * argv [] ) { Args * args = NULL; rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0, NULL, 0 ); @@ -71,30 +70,8 @@ static rc_t argsHandler ( int argc, char * argv [] ) { return rc; } -extern "C" -{ - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-vdb"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=VdbSlowTestSuite(argc, argv); - return rc; -} - + return VdbSlowTestSuite(argc, argv); } diff --git a/test/vdb/test-vdb.cpp b/test/vdb/test-vdb.cpp index e5e17f12c..c1f1905e5 100644 --- a/test/vdb/test-vdb.cpp +++ b/test/vdb/test-vdb.cpp @@ -493,10 +493,10 @@ FIXTURE_TEST_CASE ( V2ParserError, VDB_Fixture ) REQUIRE_RC ( VTableRelease ( tbl ) ); } -rc_t CC FlushSchema(void *fd, const void * buffer, size_t size) +rc_t CC FlushSchema(void *fd, const void * buffer, size_t size) noexcept { ostream & out = *static_cast < ostream * > (fd); - out.write(static_cast < const char * > (buffer), size); + out.write(static_cast < const char * > (buffer), (streamsize)size); out.flush(); return 0; } @@ -565,32 +565,8 @@ TEST_CASE(KDBRManager_MakeReadWithVFSManager) }; //////////////////////////////////////////// Main -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-vdb"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=VdbTestSuite(argc, argv); - return rc; -} - + return VdbTestSuite(argc, argv); } diff --git a/test/vdb/test-view-cursor.cpp b/test/vdb/test-view-cursor.cpp index ff33ddd1e..5f6bfd8cf 100644 --- a/test/vdb/test-view-cursor.cpp +++ b/test/vdb/test-view-cursor.cpp @@ -24,6 +24,8 @@ #include // TEST_CASE +#include + #include #include #include @@ -618,33 +620,8 @@ FIXTURE_TEST_CASE( ViewCursor_Join_NullKey, ViewOnTableCursorFixture ) #include "test-view-on-view-cursor.cpp" //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-view-cursor"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=ViewCursorTestSuite(argc, argv); - return rc; -} - + return ViewCursorTestSuite(argc, argv); } diff --git a/test/vdb/test-view-vt.cpp b/test/vdb/test-view-vt.cpp index 361c10759..4c9b1ab2f 100644 --- a/test/vdb/test-view-vt.cpp +++ b/test/vdb/test-view-vt.cpp @@ -25,7 +25,6 @@ // this file is included into test-view-cursor.cpp ///////////////////////////// View-attached VCursor, tests covering virtual table functions - FIXTURE_TEST_CASE ( ViewCursor_AddRef, ViewOnTableCursorFixture ) { CreateCursor ( GetName(), ViewOnTableName ); @@ -230,7 +229,6 @@ FIXTURE_TEST_CASE( ViewCursor_IdRange_SameAsPrimaryTable, ViewOnTableCursorFixtu "{ column INSDC:SRA:spotid_t spot_id = t . SPOT_ID; }"; // the view's id range is t's row_id range - REQUIRE_RC ( VDBManagerMakeUpdate ( & m_mgr, NULL ) ); const VDatabase * db; REQUIRE_RC ( VDBManagerOpenDBRead ( m_mgr, & db, NULL, "SRR1063272" ) ); VSchema * schema = NULL; @@ -576,10 +574,10 @@ FIXTURE_TEST_CASE ( ViewCursor_CelLData, ViewOnTableCursorFixture ) FIXTURE_TEST_CASE ( ViewCursor_CellDataDirect_CursorNotOpen, ViewOnTableCursorFixture ) { CreateCursorAddColumn ( GetName(), ViewOnTableName, ViewColumnName ); - uint32_t m_elemBits = 0; - uint32_t m_boff; - uint32_t m_rowLen; - REQUIRE_RC_FAIL ( VCursorCellDataDirect ( m_cur, 2, m_columnIdx, & m_elemBits, & m_base, & m_boff, & m_rowLen ) ); + uint32_t elemBits = 0; + uint32_t boff; + uint32_t rowLen; + REQUIRE_RC_FAIL ( VCursorCellDataDirect ( m_cur, 2, m_columnIdx, & elemBits, & m_base, & boff, & rowLen ) ); } FIXTURE_TEST_CASE ( ViewCursor_CelLDataDirect, ViewOnTableCursorFixture ) { @@ -646,7 +644,7 @@ FIXTURE_TEST_CASE ( ViewCursor_SetUserData_NoDestructor, ViewOnTableCursorFixtur } static void * UserDestroyCalledWith = 0; -static void CC UserDestroy(void* p_param) +static void CC UserDestroy(void* p_param) noexcept { UserDestroyCalledWith = p_param; } diff --git a/test/vdb/test-view.cpp b/test/vdb/test-view.cpp index 9361063af..2aa073638 100644 --- a/test/vdb/test-view.cpp +++ b/test/vdb/test-view.cpp @@ -24,6 +24,8 @@ #include "WVDB_Fixture.hpp" +#include + #include #include @@ -68,7 +70,6 @@ const string CompactSchemaText = FIXTURE_TEST_CASE ( ViewAlias_DumpSchema_Compact, WVDB_v2_Fixture ) { - REQUIRE_RC ( VDBManagerMakeUpdate ( & m_mgr, NULL ) ); REQUIRE_RC ( VDBManagerMakeSchema ( m_mgr, & m_schema ) ); ParseSchema ( m_schema, CompactSchemaText ); string d = DumpSchema( * m_schema ); @@ -105,7 +106,6 @@ FIXTURE_TEST_CASE ( ViewAlias_DumpSchema_Full, WVDB_v2_Fixture ) "}\n" ; - REQUIRE_RC ( VDBManagerMakeUpdate ( & m_mgr, NULL ) ); REQUIRE_RC ( VDBManagerMakeSchema ( m_mgr, & m_schema ) ); ParseSchema ( m_schema, FullSchemaText ); string d = DumpSchema( * m_schema, false ); @@ -986,33 +986,8 @@ FIXTURE_TEST_CASE(VDatabaseMemberType_Inherited, ViewFixture) //TODO: break these tests out to test-database.c //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-view"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=ViewTestSuite(argc, argv); - return rc; -} - + return ViewTestSuite(argc, argv); } diff --git a/test/vdb/test-wtablecursor.cpp b/test/vdb/test-wtablecursor.cpp index 2b8d3375a..45d96060f 100644 --- a/test/vdb/test-wtablecursor.cpp +++ b/test/vdb/test-wtablecursor.cpp @@ -24,6 +24,8 @@ #include +#include + #include #include @@ -601,34 +603,8 @@ FIXTURE_TEST_CASE( VTableCursor_ListReadableColumns, TableCursorFixture ) } //////////////////////////////////////////// Main -#include - -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-wtablecursor"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=VdbTableCursorTestSuite_Write(argc, argv); - return rc; -} - + return VdbTableCursorTestSuite_Write(argc, argv); } diff --git a/test/vdb/test-wvdb-slow.cpp b/test/vdb/test-wvdb-slow.cpp index b9343f124..c9bbbde9c 100644 --- a/test/vdb/test-wvdb-slow.cpp +++ b/test/vdb/test-wvdb-slow.cpp @@ -26,10 +26,15 @@ #define NOMINMAX 1 #include "WVDB_Fixture.hpp" +#include + using namespace std; TEST_SUITE( WVdbSlowTestSuite ); +// on hosts with less memory or lower quota these tests get the process killed +#ifdef TEAMCITY_SH + FIXTURE_TEST_CASE ( VCursorCommit_BufferOverflow, WVDB_Fixture ) { // VDB-4341 m_databaseName = ScratchDir + GetName(); @@ -105,6 +110,10 @@ FIXTURE_TEST_CASE ( VCursorCommit_BufferOverflow, WVDB_Fixture ) FIXTURE_TEST_CASE ( VCursor_PageMapOverflow, WVDB_Fixture ) { // VDB-4897 + //NB: this test case consumes a lot of memory; + // if this process gets killed by the kernel, + // consider a host with more memory + m_databaseName = ScratchDir + GetName(); RemoveDatabase(); @@ -139,34 +148,11 @@ if ( i % 1000000 == 0 ) cout << i/1000000 < -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-wvdb"; +#endif -rc_t CC KMain ( int argc, char *argv [] ) +//////////////////////////////////////////// Main +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=WVdbSlowTestSuite(argc, argv); - return rc; -} - + return WVdbSlowTestSuite(argc, argv); } diff --git a/test/vdb/test-wvdb.cpp b/test/vdb/test-wvdb.cpp index bff86312c..a81b8c95b 100644 --- a/test/vdb/test-wvdb.cpp +++ b/test/vdb/test-wvdb.cpp @@ -52,7 +52,6 @@ #include - #include "WVDB_Fixture.hpp" using namespace std; @@ -702,7 +701,6 @@ FIXTURE_TEST_CASE ( VSchema_Version2_Fail, WVDB_Fixture ) string schemaText = "version 2; table table1 #1.0.0 { column ascii column1; };" "database root_database #1 { table table1 #1 TABLE1; } ; " "view V#1 < table1 t > {};"; - REQUIRE_RC ( VDBManagerMakeUpdate ( & m_mgr, NULL ) ); REQUIRE_RC ( VDBManagerMakeSchema ( m_mgr, & m_schema ) ); // this is expected to log "expected 'include, typedef, typeset, fmtdef, function, schema, database or table' but found 'view'" @@ -864,7 +862,7 @@ FIXTURE_TEST_CASE ( VCursor_Use_cut_ToAccessArrayElement, WVDB_Fixture ) } FIXTURE_TEST_CASE ( KDBManager_Leak, WVDB_Fixture ) -{ // use valgrind to detect the leak +{ // use valgrind or asan to detect the leak string schemaText = "table table1 #1.0.0 { column ascii column1; };" "database root_database #1 { table table1 #1 TABLE1; } ;"; @@ -982,33 +980,9 @@ FIXTURE_TEST_CASE ( BlobChecksumOFF, WVDB_Fixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "test-wvdb"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=WVdbTestSuite(argc, argv); - return rc; + return WVdbTestSuite(argc, argv); } -} diff --git a/test/vfs/CMakeLists.txt b/test/vfs/CMakeLists.txt index d1bb19e13..458a2768e 100644 --- a/test/vfs/CMakeLists.txt +++ b/test/vfs/CMakeLists.txt @@ -24,29 +24,32 @@ add_compile_definitions( __mod__="test/vfs" ) -AddExecutableTest( Test_VFS_attached-vdbcache "test-attached-vdbcache" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_log-names-error "test-log-names-error" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_redirect-rejected-names-cgi-http-to-https "redirect-rejected-names-cgi-http-to-https.cpp" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_resolver-with-log "test-resolver-with-log" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_sdl-response "test-sdl-response" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_services "test-services" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_SraDesc "test-SraDesc" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_cache_sdl "test_VFS_cache_sdl" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_caching "test-caching" "${COMMON_LIBS_READ}" ) -# AddExecutableTest( Test_VFS_names-30 "test-names-30" "${COMMON_LIBS_READ}" ) -AddExecutableTest(Test_VFS_no-nm-cgi "Test_VFS_no-nm-cgi" "${COMMON_LIBS_READ}") +set( LIBS "${COMMON_LIBS_READ}") + +AddExecutableTest( Test_VFS_attached-vdbcache "test-attached-vdbcache" "${LIBS}" ) +AddExecutableTest( Test_VFS_log-names-error "test-log-names-error" "${LIBS}" ) +AddExecutableTest( Test_VFS_redirect-rejected-names-cgi-http-to-https "redirect-rejected-names-cgi-http-to-https.cpp" "${LIBS}" ) +AddExecutableTest( Test_VFS_resolver-with-log "test-resolver-with-log" "${LIBS}" ) +AddExecutableTest( Test_VFS_sdl-response "test-sdl-response" "${LIBS}" ) +AddExecutableTest( Test_VFS_services "test-services" "${LIBS}" ) +AddExecutableTest( Test_VFS_SraDesc "test-SraDesc" "${LIBS}" ) +AddExecutableTest( Test_VFS_cache_sdl "test_VFS_cache_sdl" "${LIBS}" ) +AddExecutableTest( Test_VFS_caching "test-caching" "${LIBS}" ) +# AddExecutableTest( Test_VFS_names-30 "test-names-30" "${LIBS}" ) +AddExecutableTest(Test_VFS_no-nm-cgi "Test_VFS_no-nm-cgi" "${LIBS}") AddExecutableTest( - Test_VFS_vfs_resolve "test-vfs-resolve" "${COMMON_LIBS_READ}") -AddExecutableTest( Test_VFS_path "pathtest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_path-c "path-test" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_perm "test-perm" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_resolve "test-resolve" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_resolver_dflt "Test_VFS_resolver_dflt" "${COMMON_LIBS_READ}" ) + Test_VFS_vfs_resolve "test-vfs-resolve" "${LIBS}") +AddExecutableTest( Test_VFS_path "pathtest" "${LIBS}" ) +AddExecutableTest( Test_VFS_path-c "path-test" "${LIBS}" ) +AddExecutableTest( Test_VFS_read_observer "test-read_observer" "${LIBS}" ) +AddExecutableTest( Test_VFS_perm "test-perm" "${LIBS}" ) +AddExecutableTest( Test_VFS_resolve "test-resolve" "${LIBS}" ) +AddExecutableTest( Test_VFS_resolver_dflt "Test_VFS_resolver_dflt" "${LIBS}" ) AddExecutableTest( - Test_VFS_VPATH_open-read-read test-vpath-open-read "${COMMON_LIBS_READ}" ) + Test_VFS_VPATH_open-read-read test-vpath-open-read "${LIBS}" ) AddExecutableTest( - Test_VFS_VPATH_open-read-update test-vpath-open-read-update "${COMMON_LIBS_READ}" + Test_VFS_VPATH_open-read-update test-vpath-open-read-update "${LIBS}" ) AddExecutableTest( Test_VFS_VPATH_open-update-read test-vpath-open-update-read "${COMMON_LIBS_WRITE}" @@ -55,7 +58,7 @@ AddExecutableTest( Test_VFS_VPATH_open-update-update test-vpath-open-update-update "${COMMON_LIBS_WRITE}" ) -AddExecutableTest( Test_VFS_vfsmanager "managertest" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_json-response "test-json-response" "${COMMON_LIBS_READ}" ) -# AddExecutableTest( Test_VFS_resolver4 "test-resolver4" "${COMMON_LIBS_READ}" ) -AddExecutableTest( Test_VFS_resolve-qual "test-resolve-qual" "${COMMON_LIBS_READ}" ) +AddExecutableTest( Test_VFS_vfsmanager "managertest" "${LIBS}" ) +AddExecutableTest( Test_VFS_json-response "test-json-response" "${LIBS}" ) +# AddExecutableTest( Test_VFS_resolver4 "test-resolver4" "${LIBS}" ) +AddExecutableTest( Test_VFS_resolve-qual "test-resolve-qual" "${LIBS}" ) diff --git a/test/vfs/Test_VFS_no-nm-cgi.cpp b/test/vfs/Test_VFS_no-nm-cgi.cpp index ed9a88607..939592f97 100644 --- a/test/vfs/Test_VFS_no-nm-cgi.cpp +++ b/test/vfs/Test_VFS_no-nm-cgi.cpp @@ -237,21 +237,17 @@ FIXTURE_TEST_CASE(ResolverSucceedsWithCustomSdl, Fixture) { } #endif -extern "C" { - ver_t CC KAppVersion(void) { return 0; } - - rc_t CC KMain(int argc, char* argv[]) { - putenv((char*)"NCBI_VDB_NO_ETC_NCBI_KFG=1"); // ignore /etc/ncbi +int main(int argc, char* argv[]) { + putenv((char*)"NCBI_VDB_NO_ETC_NCBI_KFG=1"); // ignore /etc/ncbi #ifndef NEED_TO_TRACK_DOWN_CONFIG_REFCOUNT - // Currently make sure we start with an emty config when we create it here. - putenv((char*)"VDB_CONFIG=redirect-rejected-names-cgi-http-to-https"); + // Currently make sure we start with an emty config when we create it here. + putenv((char*)"VDB_CONFIG=redirect-rejected-names-cgi-http-to-https"); #endif - unsetenv("VDB_ROOT"); // Ignore it. Probably it's not needed. - KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg + unsetenv("VDB_ROOT"); // Ignore it. Probably it's not needed. + KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg - if (PRINT_SDL) - KDbgSetString("VFS"); + if (PRINT_SDL) + KDbgSetString("VFS"); - return Resolver3TestSuite(argc, argv); - } + return Resolver3TestSuite(argc, argv); } diff --git a/test/vfs/Test_VFS_resolver_dflt.cpp b/test/vfs/Test_VFS_resolver_dflt.cpp index 6ec2d5efd..b51a908e1 100644 --- a/test/vfs/Test_VFS_resolver_dflt.cpp +++ b/test/vfs/Test_VFS_resolver_dflt.cpp @@ -32,6 +32,7 @@ #include /* KDbgSetString */ #include +#include #include @@ -183,7 +184,7 @@ FIXTURE_TEST_CASE ( VDB_2936_resolve_local_WGS_with_version, ResolverFixture ) REQUIRE_RC(VPathEqual(local, pc2, ¬equal)); REQUIRE(notequal == 0); REQUIRE_RC(VPathRelease(pc2)); - + try { String path; @@ -508,53 +509,28 @@ FIXTURE_TEST_CASE(noqual_vdbcache, ResolverFixture) { //////////////////////////////////////////// Main -extern "C" +static void clear_recorded_errors ( void ) { - -#include -#include - - ver_t CC KAppVersion ( void ) - { - return 0x1000000; - } - - rc_t CC UsageSummary (const char * progname) - { - return 0; - } - - rc_t CC Usage ( const Args * args ) + rc_t rc; + const char * filename; + const char * funcname; + uint32_t line_nr; + while ( GetUnreadRCInfo ( &rc, &filename, &funcname, &line_nr ) ) { - return 0; - } - - const char UsageDefaultName[] = "test-resolver"; - - static void clear_recorded_errors ( void ) - { - rc_t rc; - const char * filename; - const char * funcname; - uint32_t line_nr; - while ( GetUnreadRCInfo ( &rc, &filename, &funcname, &line_nr ) ) - { - } } +} - rc_t CC KMain ( int argc, char *argv [] ) - { - putenv((char*)"NCBI_VDB_NO_CACHE_SDL_RESPONSE=1"); +int main( int argc, char *argv [] ) +{ + putenv((char*)"NCBI_VDB_NO_CACHE_SDL_RESPONSE=1"); - if ( + if ( 0) assert(!KDbgSetString("VFS")); - KConfigDisableUserSettings (); - rc_t rc = VResolverTestSuite ( argc, argv ); + KConfigDisableUserSettings (); + int rc = VResolverTestSuite ( argc, argv ); - clear_recorded_errors(); - - return rc; - } + clear_recorded_errors(); + return rc; } diff --git a/test/vfs/managertest.cpp b/test/vfs/managertest.cpp index 51777219a..888710907 100644 --- a/test/vfs/managertest.cpp +++ b/test/vfs/managertest.cpp @@ -68,7 +68,7 @@ class BaseMgrFixture static const int BufSize = 1024; protected: - BaseMgrFixture(const char* password) + BaseMgrFixture(const char* p_password) : wd ( 0 ) , mgr ( 0 ) , vpath(0) @@ -76,28 +76,28 @@ class BaseMgrFixture , num_writ ( 0 ) { if (KDirectoryNativeDir ( &wd ) != 0) - throw logic_error("MgrFixture: KDirectoryNativeDir failed"); - + throw logic_error("MgrFixture: KDirectoryNativeDir failed"); + if (VFSManagerMake(&mgr) != 0 || mgr == 0) - throw logic_error("MgrFixture: VFSManagerMake failed"); - - // stick a reference to our pwfile into the VFSManager's configuration + throw logic_error("MgrFixture: VFSManagerMake failed"); + + // stick a reference to our pwfile into the VFSManager's configuration // (no easy way to do that through putenv that would work on Windows dynamic since // vfs.dll would have its own copy of environment) const KConfig* kfg = VFSManagerGetConfig(mgr); if (!kfg) - throw logic_error("MgrFixture: VFSManagerGetConfig failed"); + throw logic_error("MgrFixture: VFSManagerGetConfig failed"); KConfigNode* node; if (KConfigOpenNodeUpdate((KConfig*)kfg, &node, KFG_KRYPTO_PWFILE) != 0) - throw logic_error("MgrFixture: KConfigOpenNodeUpdate failed"); - + throw logic_error("MgrFixture: KConfigOpenNodeUpdate failed"); + if (KConfigNodeWrite(node, pwFileName, strlen(pwFileName)) != 0) - throw logic_error("MgrFixture: KConfigNodeWrite failed"); + throw logic_error("MgrFixture: KConfigNodeWrite failed"); if (KConfigNodeRelease(node) != 0) - throw logic_error("MgrFixture: KConfigNodeRelease failed"); + throw logic_error("MgrFixture: KConfigNodeRelease failed"); // make sure pwfile contains the correct password (some tests might update it) - CreateFile(pwFileName, password); + CreateFile(pwFileName, p_password); } ~BaseMgrFixture() { @@ -110,23 +110,23 @@ class BaseMgrFixture if (KDirectoryRelease(wd) != 0) cerr << "~MgrFixture: KDirectoryRelease failed" << endl; } - + void CreateFile(const string& name, const string& content) { KFile* f; if (KDirectoryCreateFile(wd, &f, false, 0660, kcmInit, name.c_str()) != 0) - throw logic_error("CreateFile: KDirectoryCreateFile failed"); + throw logic_error("CreateFile: KDirectoryCreateFile failed"); if (KFileWrite(f, 0, content.c_str(), content.size(), &num_writ) != 0 || num_writ != content.size()) - throw logic_error("CreateFile: KDirectoryOpenFileWrite failed"); + throw logic_error("CreateFile: KDirectoryOpenFileWrite failed"); if (KFileWrite(f, content.size(), "\n", 1, &num_writ) != 0 || num_writ != 1) - throw logic_error("CreateFile: KDirectoryOpenFileWrite failed"); + throw logic_error("CreateFile: KDirectoryOpenFileWrite failed"); if (KFileRelease(f) != 0) - throw logic_error("CreateFile: KFileRelease failed"); + throw logic_error("CreateFile: KFileRelease failed"); } string ReadContent(const KFile* file) { if (KFileReadAll ( file, 0, buf, BufSize, &num_read ) != 0) - throw logic_error("ReadContent: KFileReadAll failed"); + throw logic_error("ReadContent: KFileReadAll failed"); return string(buf, num_read); } @@ -176,11 +176,11 @@ string protectedFileContent = "contents of a single-file object"; FIXTURE_TEST_CASE(OpenFileRead_Decrypt, MgrFixture) { REQUIRE_RC(VFSManagerMakePath ( mgr, &vpath, "./ncbi/protected1/SRR999997.ncbi_enc")); // an encrypted copy of ./ncbi/protected1/SRR999997 - + // read contents of an encrypted file const KFile *f; - REQUIRE_RC(VFSManagerOpenFileReadDecrypt (mgr, &f, vpath)); - + REQUIRE_RC(VFSManagerOpenFileReadDecrypt (mgr, &f, vpath)); + REQUIRE_EQ(protectedFileContent, ReadContent(f)); REQUIRE_RC(KFileRelease(f)); @@ -188,24 +188,24 @@ FIXTURE_TEST_CASE(OpenFileRead_Decrypt, MgrFixture) FIXTURE_TEST_CASE(OpenDirRead_Decrypt, MgrFixture) { REQUIRE_RC(VFSManagerMakePath ( mgr, &vpath, "./ncbi_enc")); // this is an encrypted kar archive of directory ./ncbi - + const KDirectory *dir; - REQUIRE_RC(VFSManagerOpenDirectoryReadDirectoryRelativeDecrypt (mgr, wd, &dir, vpath)); - + REQUIRE_RC(VFSManagerOpenDirectoryReadDirectoryRelativeDecrypt (mgr, wd, &dir, vpath)); + // read contents of a file inside an encrypted archive const KFile *f; KDirectoryOpenFileRead(dir, &f, "protected1/SRR999997"); REQUIRE_EQ(protectedFileContent, ReadContent(f)); REQUIRE_RC(KFileRelease(f)); - + REQUIRE_RC(KDirectoryRelease(dir)); } FIXTURE_TEST_CASE(CreateFile_Encrypt, MgrFixture) { string uri = string("ncbi-file:") + GetName() + "?enc&pwfile=pwfile"; - REQUIRE_RC(VFSManagerMakePath ( mgr, &vpath, uri.c_str())); - + REQUIRE_RC(VFSManagerMakePath ( mgr, &vpath, uri.c_str())); + // create with encryption KFile* f; REQUIRE_RC(VFSManagerCreateFile(mgr, &f, false, 0660, kcmInit, vpath)); @@ -213,17 +213,17 @@ FIXTURE_TEST_CASE(CreateFile_Encrypt, MgrFixture) REQUIRE_RC(KFileWrite(f, 0, content.c_str(), content.size(), &num_writ)); REQUIRE_EQ(content.size(), num_writ); REQUIRE_RC(KFileRelease(f)); - + // open as unencrypted - should fail KDirectoryOpenFileRead(wd, (const KFile**)&f, GetName()); REQUIRE_NE(content, ReadContent(f)); REQUIRE_RC(KFileRelease(f)); - + // open as encrypted - REQUIRE_RC(VFSManagerOpenFileReadDecrypt (mgr, (const KFile**)&f, vpath)); + REQUIRE_RC(VFSManagerOpenFileReadDecrypt (mgr, (const KFile**)&f, vpath)); REQUIRE_EQ(content, ReadContent(f)); REQUIRE_RC(KFileRelease(f)); - + REQUIRE_RC(KDirectoryRemove(wd, true, GetName())); } @@ -233,14 +233,14 @@ FIXTURE_TEST_CASE(OpenFileWriteFile_Encrypt_NotEncrypted, MgrFixture) CreateFile(GetName(), "garbage"); string uri = string("ncbi-file:") + GetName() + "?enc&pwfile=pwfile"; - REQUIRE_RC(VFSManagerMakePath ( mgr, &vpath, uri.c_str())); + REQUIRE_RC(VFSManagerMakePath ( mgr, &vpath, uri.c_str())); // open as encrypted - fail KFile* f; // this will output an error message from KEncFileMakeIntValidSize: LOG(ncbi::NK::LogLevel::e_error, "Expecting an err. message from KEncFileMakeIntValidSize...\n"); - REQUIRE_RC_FAIL(VFSManagerOpenFileWrite(mgr, &f, false, vpath)); + REQUIRE_RC_FAIL(VFSManagerOpenFileWrite(mgr, &f, false, vpath)); REQUIRE_RC(KFileRelease(f)); REQUIRE_RC(KDirectoryRemove(wd, true, GetName())); @@ -249,7 +249,7 @@ FIXTURE_TEST_CASE(OpenFileWriteFile_Encrypt_NotEncrypted, MgrFixture) FIXTURE_TEST_CASE(OpenFileWriteFile_Encrypt, MgrFixture) { // open an encrypted file for encypted writing string uri = string("ncbi-file:") + GetName() + "?enc&pwfile=pwfile"; - REQUIRE_RC(VFSManagerMakePath ( mgr, &vpath, uri.c_str())); + REQUIRE_RC(VFSManagerMakePath ( mgr, &vpath, uri.c_str())); // create encrypted KFile* f; @@ -265,14 +265,14 @@ FIXTURE_TEST_CASE(OpenFileWriteFile_Encrypt, MgrFixture) REQUIRE_RC(KFileWrite(f, 0, content.c_str(), content.size(), &num_writ)); REQUIRE_EQ(content.size(), num_writ); REQUIRE_RC(KFileRelease(f)); - + // open as unencrypted - fail KDirectoryOpenFileRead(wd, (const KFile**)&f, GetName()); REQUIRE_NE(content, ReadContent(f)); REQUIRE_RC(KFileRelease(f)); - + // open as encrypted - REQUIRE_RC(VFSManagerOpenFileReadDecrypt (mgr, (const KFile**)&f, vpath)); + REQUIRE_RC(VFSManagerOpenFileReadDecrypt (mgr, (const KFile**)&f, vpath)); REQUIRE_EQ(content, ReadContent(f)); REQUIRE_RC(KFileRelease(f)); @@ -308,12 +308,12 @@ FIXTURE_TEST_CASE(UpdateKryptoPassword_NoOutput, MgrFixture) { string newPwd("new_pwd1"); rc_t rc = VFSManagerUpdateKryptoPassword(mgr, newPwd.c_str(), newPwd.size(), 0, 0); -// directory permissions are not looked at on Windows -#if !WINDOWS +// directory permissions are not looked at on Windows +#if !WINDOWS REQUIRE_EQ(rc, RC(rcVFS, rcEncryptionKey, rcUpdating, rcDirectory, rcExcessive)); #else REQUIRE_EQ(rc, (rc_t)0); -#endif +#endif REQUIRE_RC(VFSManagerGetKryptoPassword(mgr, buf, BufSize, &num_read)); REQUIRE_EQ(newPwd, string(buf, num_read)); @@ -324,14 +324,14 @@ FIXTURE_TEST_CASE(UpdateKryptoPassword_Output, MgrFixture) // VFSManagerUpdateKryptoPassword returns the directory containing the password file, // to help instruct user to chmod if permissions are too lax rc_t rc = VFSManagerUpdateKryptoPassword(mgr, newPwd.c_str(), newPwd.size(), buf, BufSize); -// directory permissions are not looked at on Windows -#if !WINDOWS +// directory permissions are not looked at on Windows +#if !WINDOWS REQUIRE_EQ(rc, RC(rcVFS, rcEncryptionKey, rcUpdating, rcDirectory, rcExcessive)); #else REQUIRE_EQ(rc, (rc_t)0); -#endif +#endif REQUIRE_EQ(string("."), string(buf)); - + REQUIRE_RC(VFSManagerGetKryptoPassword(mgr, buf, BufSize, &num_read)); REQUIRE_EQ(newPwd, string(buf, num_read)); } @@ -342,11 +342,11 @@ FIXTURE_TEST_CASE(UpdateKryptoPassword_Output, MgrFixture) // Object Id / Object name bindings // -class ObjIdBindingFixture : public MgrFixture +class ObjIdBindingFixture : public MgrFixture { public: static char bindings[1024]; - + ObjIdBindingFixture() { } @@ -361,7 +361,7 @@ class ObjIdBindingFixture : public MgrFixture { string bFile = string("./") + bindingsFileName; if (string_copy(bindings, sizeof(bindings), bFile.c_str(), bFile.length()) != bFile.length()) - throw logic_error("ObjIdBindingFixture::SetUp: string_copy failed"); + throw logic_error("ObjIdBindingFixture::SetUp: string_copy failed"); VFSManagerSetBindingsFile(mgr, bindings); KDirectoryRemove(wd, true, bindings); } @@ -369,7 +369,7 @@ class ObjIdBindingFixture : public MgrFixture { rc_t rc = VFSManagerRegisterObject(mgr, id, p); if (VPathRelease(p) != 0) - throw logic_error("ObjIdBindingFixture::Register: VPathRelease failed"); + throw logic_error("ObjIdBindingFixture::Register: VPathRelease failed"); return rc; } rc_t Register(uint32_t id, const char* uri) @@ -386,17 +386,17 @@ class ObjIdBindingFixture : public MgrFixture if (rc == 0) { if (vp == 0) - throw logic_error("ObjIdBindingFixture::GetById: VFSManagerGetObject returned NULL"); - + throw logic_error("ObjIdBindingFixture::GetById: VFSManagerGetObject returned NULL"); + const String* p; if (VPathMakeString(vp, &p) != 0 || p == 0) - throw logic_error("ObjIdBindingFixture::GetById: VPathMakeString failed"); - + throw logic_error("ObjIdBindingFixture::GetById: VPathMakeString failed"); + uri = string(p->addr, p->size); - + free((void*)p); if (VPathRelease(vp) != 0) - throw logic_error("ObjIdBindingFixture::GetById: VPathRelease failed"); + throw logic_error("ObjIdBindingFixture::GetById: VPathRelease failed"); } return rc; } @@ -404,10 +404,10 @@ class ObjIdBindingFixture : public MgrFixture { VPath* p; if (VFSManagerMakePath(mgr, &p, uri.c_str()) != 0) - throw logic_error("ObjIdBindingFixture::GetByUri: VFSManagerMakePath failed"); + throw logic_error("ObjIdBindingFixture::GetByUri: VFSManagerMakePath failed"); rc_t rc = VFSManagerGetObjectId(mgr, p, &id); if (VPathRelease(p) != 0) - throw logic_error("ObjIdBindingFixture::GetById: VPathRelease failed"); + throw logic_error("ObjIdBindingFixture::GetById: VPathRelease failed"); return rc; } }; @@ -417,7 +417,7 @@ char ObjIdBindingFixture::bindings[]; FIXTURE_TEST_CASE(ObjIdRegister, ObjIdBindingFixture) { SetUp(GetName()); - + // REQUIRE_RC(Register(1, "ncbi-acc:acc1")); REQUIRE_RC(Register(1, "ncbi-acc:acc1?tic=1")); REQUIRE_RC(Register(2, "ncbi-file:acc2?tic=22")); @@ -425,7 +425,7 @@ FIXTURE_TEST_CASE(ObjIdRegister, ObjIdBindingFixture) FIXTURE_TEST_CASE(ObjIdRegister_Found_Same, ObjIdBindingFixture) { SetUp(GetName()); - + REQUIRE_RC(Register(1, "ncbi-acc:acc1?tic=1")); REQUIRE_RC(Register(2, "ncbi-file:acc2?tic=22")); REQUIRE_RC(Register(1, "ncbi-acc:acc1?tic=1")); // same name, no problem @@ -433,7 +433,7 @@ FIXTURE_TEST_CASE(ObjIdRegister_Found_Same, ObjIdBindingFixture) FIXTURE_TEST_CASE(ObjIdRegister_Found_Different, ObjIdBindingFixture) { SetUp(GetName()); - + REQUIRE_RC(Register(1, "ncbi-acc:acc1?tic=1")); REQUIRE_RC(Register(2, "ncbi-file:acc2?tic=22")); REQUIRE_RC_FAIL(Register(1, "ncbi-acc:acc11?tic=1")); // name differs @@ -441,74 +441,74 @@ FIXTURE_TEST_CASE(ObjIdRegister_Found_Different, ObjIdBindingFixture) FIXTURE_TEST_CASE(ObjIdById_Found, ObjIdBindingFixture) { SetUp(GetName()); - + REQUIRE_RC(Register(123, "ncbi-file:acc123?tic=3")); REQUIRE_RC(Register(12, "ncbi-acc:acc12?tic=2")); REQUIRE_RC(Register(1, "ncbi-acc:acc1?tic=1")); - + string uri; - + REQUIRE_RC(GetById(123, uri)); REQUIRE_EQ(uri, string("ncbi-file:acc123?tic=3")); - + REQUIRE_RC(GetById(12, uri)); REQUIRE_EQ(uri, string("ncbi-acc:acc12?tic=2")); - + REQUIRE_RC(GetById(1, uri)); REQUIRE_EQ(uri, string("ncbi-acc:acc1?tic=1")); } FIXTURE_TEST_CASE(ObjIdById_NotFound, ObjIdBindingFixture) { SetUp(GetName()); - + REQUIRE_RC(Register(100, "ncbi-acc:acc1?tic=1")); REQUIRE_RC(Register(200, "ncbi-file:acc2?tic=1")); - + string uri; - + REQUIRE_RC_FAIL(GetById(100200, uri)); } FIXTURE_TEST_CASE(ObjId_DefaultLocation, ObjIdBindingFixture) { VFSManagerSetBindingsFile(mgr, NULL); REQUIRE_RC_FAIL(VFSManagerGetObject(mgr, 1, &vpath)); // this will fail but set VFSManagerBindings to default - const char* bindings = VFSManagerGetBindingsFile(mgr); - REQUIRE_NOT_NULL(bindings); - + const char* binds = VFSManagerGetBindingsFile(mgr); + REQUIRE_NOT_NULL(binds); + // verify default location String* home; REQUIRE_RC(KConfigReadString(VFSManagerGetConfig(mgr), "NCBI_HOME", &home)); REQUIRE_NOT_NULL(home); - REQUIRE_EQ(string(bindings), string(home->addr, home->size) + "/objid.mapping"); + REQUIRE_EQ(string(binds), string(home->addr, home->size) + "/objid.mapping"); StringWhack(home); } FIXTURE_TEST_CASE(ObjIdByName_Found, ObjIdBindingFixture) { SetUp(GetName()); - + REQUIRE_RC(Register(11, "ncbi-acc:acc11?tic=3")); REQUIRE_RC(Register(21, "ncbi-file:acc21?tic=22")); REQUIRE_RC(Register(1, "ncbi-acc:acc1?tic=1")); - + uint32_t id; - + REQUIRE_RC(GetByUri(string("ncbi-acc:acc11?tic=3"), id)); REQUIRE_EQ((uint32_t)11, id); REQUIRE_RC(GetByUri(string("ncbi-file:acc21?tic=22"), id)); REQUIRE_EQ((uint32_t)21, id); - + REQUIRE_RC(GetByUri(string("ncbi-acc:acc1?tic=1"), id)); REQUIRE_EQ((uint32_t)1, id); } FIXTURE_TEST_CASE(ObjIdByName_NotFound, ObjIdBindingFixture) { SetUp(GetName()); - + REQUIRE_RC(Register(1, "ncbi-acc:acc1?tic=1")); REQUIRE_RC(Register(2, "ncbi-file:acc2?tic=2")); - + uint32_t id; REQUIRE_RC_FAIL(GetByUri(string("ncbi-acc:acc2?tic=1"), id)); } @@ -625,31 +625,9 @@ FIXTURE_TEST_CASE(TestVFSManagerCheckAd, MgrFixture) { #endif //////////////////////////////////////////// Main -extern "C" -{ - -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-manager"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=VManagerTestSuite(argc, argv); - return rc; + return VManagerTestSuite(argc, argv); } -} diff --git a/test/vfs/observer-test.hpp b/test/vfs/observer-test.hpp new file mode 100644 index 000000000..1c898849f --- /dev/null +++ b/test/vfs/observer-test.hpp @@ -0,0 +1,292 @@ +/*============================================================================== +* +* PUBLIC DOMAIN NOTICE +* National Center for Biotechnology Information +* +* This software/database is a "United States Government Work" under the +* terms of the United States Copyright Act. It was written as part of +* the author's official duties as a United States Government employee and +* thus cannot be copyrighted. This software/database is freely available +* to the public for use. The National Library of Medicine and the U.S. +* Government have not placed any restriction on its use or reproduction. +* +* Although all reasonable efforts have been taken to ensure the accuracy +* and reliability of the software and data, the NLM and the U.S. +* Government do not and cannot warrant the performance or results that +* may be obtained by using this software or data. The NLM and the U.S. +* Government disclaim all warranties, express or implied, including +* warranties of performance, merchantability or fitness for any particular +* purpose. +* +* Please cite the author in any work or product based on this material. +* +* ============================================================================== +* Common code for KFileMD5ReadObserver tests +*/ + +#include /* KFileMakeBzip2ForWrite */ +#include /* KDirectoryRelease */ +#include /* KFileRelease */ +#include /* KFileMakeGzipForWrite */ +#include /* KFileMakeMD5ReadObserver */ + +#include // RC +#include // TimeoutInit +#include /* VFSManagerRelease */ +#include /* VPathRelease */ + +#include /* TEST_SUITE */ + +#define FREE(ptr) do { free((void*)ptr); ptr = nullptr; } while (false) + +#define RELEASE(type, obj) do { REQUIRE_RC(type##Release(obj)); \ + obj = nullptr; } while (false) + +#define ERR_HEAD "The file was not read to the end; it was read to byte " + +const char SRC_FILE[]("../vdb/db/VDB-3418.sra"); +const char *DST_FILE(nullptr); + +typedef enum { + ePlain, + eBz2, + eGzip, + eHttp, +} EType; + +class ObserverTest:protected ncbi::NK::TestCase { + static VFSManager *s_mgr; + static const VPath *s_path; + static std::string s_digest; + static KDirectory *s_cwd; + static EType s_type; + + TestCase *_dad; + +public: + const KFileMD5ReadObserver *md5; + const KFile *file; + uint64_t size; + bool sizeUnknown; + char *buf; + const char *error; + uint8_t digest[16]; + struct timeout_t tm; + + ObserverTest(TestCase *dad, const std::string &name) + : TestCase(name) + , _dad(dad) + , md5(NULL) + , file(nullptr) + , size(0) + , sizeUnknown(false) + , buf(NULL) + , error(nullptr) + { + memset(digest, 0, sizeof digest); + TimeoutInit(&tm, 300000); + } + + ~ObserverTest() { + free(buf); + + assert(_dad); + _dad->ErrorCounterAdd(GetErrorCounter()); + } + + static rc_t Begin(EType type = ePlain) { /* prepare input test file */ + rc_t rc(0); + + rc = KDirectoryNativeDir(&s_cwd); + + s_type = type; + + if (type == ePlain) + return rc; + + else if (s_type == eHttp) { + rc = VFSManagerMake(&s_mgr); + if (rc != 0) { + std::cerr << "cannot VFSManagerMake\n"; + return rc; + } + rc = VFSManagerResolveRemote(s_mgr, "SRR053325", &s_path, nullptr); + if (rc != 0) { + std::cerr << "cannot resolve SRR053325\n"; + return rc; + } + + const uint8_t *md5(VPathGetMd5(s_path)); + if (md5 == nullptr) { + std::cerr << "cannot resolve SRR053325\n"; + return RC(rcFS, rcFile, rcReading, rcString, rcNull); + } + + char digest[64] = ""; + int size(64), total(0); + for (int i = 0; i < 16; ++i) { + int len + = snprintf(&digest[total], size - total, "%02x", md5[i]); + assert(len == 2); + total += len; + } + digest[total] = '\0'; + s_digest = digest; + + return rc; + } + + else { + const KFile *input(nullptr); + if (rc == 0) + rc = KDirectoryOpenFileRead(s_cwd, &input, "%s", SRC_FILE); + + if (type == eBz2) + DST_FILE = "VDB-3418.sra.bz2"; + else if (type == eGzip) + DST_FILE = "VDB-3418.sra.gz"; + else { assert(0); return rc; } + + KFile *f(nullptr); + if (rc == 0) + rc = KDirectoryCreateFile(s_cwd, &f, + false, 0644, kcmInit, "%s", DST_FILE); + + KFile *output(nullptr); + if (rc == 0) { + if (type == eBz2) + rc = KFileMakeBzip2ForWrite(&output, f); + else if (type == eGzip) + rc = KFileMakeGzipForWrite(&output, f); + else { assert(0); return rc; } + } + KFileRelease(f); f = nullptr; + + uint64_t fileSize(0); + if (rc == 0) + rc = KFileSize(input, &fileSize); + void *inputBuffer(nullptr); + if (rc == 0) { + inputBuffer = malloc(fileSize); + if (inputBuffer == nullptr) + rc = RC(rcFS, rcFile, rcCreating, rcMemory, rcExhausted); + } + + size_t actual(0); + if (rc == 0) + rc = KFileReadAll(input, 0, inputBuffer, fileSize, &actual); + if (rc == 0 && actual != fileSize) + rc = RC(rcFS, rcFile, rcCreating, rcSize, rcUnequal); + KFileRelease(input); input = nullptr; + + if (rc == 0) + rc = KFileWrite(output, 0, inputBuffer, fileSize, NULL); + + free(inputBuffer); inputBuffer = nullptr; + KFileRelease(output); output = nullptr; + + return rc; + } + } + + static rc_t End() { + rc_t rc(0); + + if (DST_FILE != nullptr) + rc = KDirectoryRemove(s_cwd, false, "%s", DST_FILE); + + KDirectoryRelease(s_cwd); s_cwd = nullptr; + VFSManagerRelease(s_mgr); s_mgr = nullptr; + VPathRelease(s_path); s_path = nullptr; + + return rc; + } + + void Start(bool failures = false // test how functions react + ) // to invalid arguments + { + if (s_type == ePlain) + REQUIRE_RC(KDirectoryOpenFileRead(s_cwd, &file, SRC_FILE)); + else if (s_type == eHttp) + REQUIRE_RC(VFSManagerOpenFileRead(s_mgr, &file, s_path)); + else { + const KFile *f(nullptr); + REQUIRE_RC(KDirectoryOpenFileRead(s_cwd, &f, DST_FILE)); + if (s_type == eBz2) + REQUIRE_RC(KFileMakeBzip2ForRead(&file, f)); + else if (s_type == eGzip) + REQUIRE_RC(KFileMakeGzipForRead(&file, f)); + else + REQUIRE_EQ(0, ~0); + RELEASE(KFile, f); + } + + if (failures) { + REQUIRE_RC_FAIL(KFileMakeMD5ReadObserver(file, nullptr)); + REQUIRE_RC_FAIL(KFileMakeMD5ReadObserver(nullptr, &md5)); + REQUIRE_NULL(md5); + } + + REQUIRE_RC(KFileMakeMD5ReadObserver(file, &md5)); + + rc_t rc(KFileSize(file, &size)); + if (rc != 0) { + sizeUnknown = true; + size = 12887839; + } + buf = reinterpret_cast(malloc(size + 1)); + REQUIRE(buf); + } + + void Finish(const std::string &aError = "", // if not empty + // - is an error message, expect failure + bool failures = false) // the same as in Start() + { + bool success = aError == ""; + + RELEASE(KFile, file); + + if (failures) { + REQUIRE_RC_FAIL(KFileMD5ReadObserverGetDigest(nullptr, digest, + &error)); + REQUIRE_NULL(error); + if (success) + REQUIRE_RC(KFileMD5ReadObserverGetDigest(md5, digest, nullptr)); + else + REQUIRE_RC_FAIL( + KFileMD5ReadObserverGetDigest(md5, digest, nullptr)); + } + + if (success) { + REQUIRE_RC(KFileMD5ReadObserverGetDigest(md5, digest, &error)); + REQUIRE_NULL(error); + REQUIRE(digest[0] != '\0'); + + int total = 0; + for (int i = 0; i < 16; ++i) { + int len + = snprintf(&buf[total], size - total, "%02x", digest[i]); + assert(len == 2); + total += len; + } + buf[total] = '\0'; + REQUIRE_EQ(std::string(buf), s_digest); + } + else { + REQUIRE_RC_FAIL( + KFileMD5ReadObserverGetDigest(md5, digest, &error)); + REQUIRE_NOT_NULL(error); + REQUIRE(digest[0] == '\0'); + REQUIRE_EQ(std::string(error), aError); + FREE(error); + } + + RELEASE(KFileMD5ReadObserver, md5); + } +}; + +VFSManager *ObserverTest::s_mgr(nullptr); +const VPath *ObserverTest::s_path(nullptr); +std::string ObserverTest::s_digest("7d66f3f346db0f916a8c723d40087b6c"); +KDirectory *ObserverTest::s_cwd(nullptr); +EType ObserverTest::s_type(ePlain); diff --git a/test/vfs/path-test.c b/test/vfs/path-test.c index 9b2ea2954..296af82df 100644 --- a/test/vfs/path-test.c +++ b/test/vfs/path-test.c @@ -38,7 +38,6 @@ #include #include -#include static const char *VPathGetAccTypeStr ( const VPath * self ) @@ -72,19 +71,19 @@ const char *VPathGetAccTypeStr ( const VPath * self ) case 0x039: if ( ( (self -> acc_code >> 4) & 0xF ) == 0 ) return " ( appSRA )"; - + { const char pileup_ext[] = ".pileup"; size_t pileup_ext_size = sizeof( pileup_ext ) / sizeof( pileup_ext[0] ) - 1; size_t path_size = self -> path . size; - - + + if ( path_size > pileup_ext_size && memcmp(&self -> path . addr[path_size - pileup_ext_size], pileup_ext, pileup_ext_size) == 0) { return " ( appSRAPileup )"; } } - + return " ( appAny )"; case 0x042: @@ -246,7 +245,7 @@ rc_t ParseUrlTest ( const VFSManager * vfs ) { rc_t rc; size_t i; - + static const char *test_urls [] = { /* accessions */ @@ -333,8 +332,8 @@ rc_t ParseUrlTest ( const VFSManager * vfs ) "/path/10315_3#63.bam" }; const size_t num_urls = sizeof test_urls / sizeof test_urls [ 0 ]; - - static const char *fail_url [] = + + static const char *fail_url [] = { /*:/*/ /*0*/ "http:/library/index.html", @@ -358,12 +357,12 @@ rc_t ParseUrlTest ( const VFSManager * vfs ) /*8*/ "ftp://www.abc.com", /*9*/ "https:#bad", - - + + }; const size_t num_fail_urls = sizeof fail_url / sizeof fail_url [ 0 ]; - - static const char *sys_path [] = + + static const char *sys_path [] = { #if WINDOWS "C:\\Program Files\\Wonderful\\Bob-o-matic", @@ -372,14 +371,14 @@ rc_t ParseUrlTest ( const VFSManager * vfs ) "SRR000123" }; const size_t num_sys_paths = sizeof sys_path / sizeof sys_path [ 0 ]; - + for ( i = 0; i < num_urls; ++ i ) { VPath *vpath; - + String url; StringInitCString ( & url, test_urls [ i ] ); - + rc = VFSManagerMakePath ( vfs, & vpath, "%S", & url ); if ( rc == 0 ) { @@ -399,15 +398,15 @@ rc_t ParseUrlTest ( const VFSManager * vfs ) return rc; } } - - + + for ( i = 0; i < num_fail_urls; ++ i ) { VPath *vpath; - + String url; StringInitCString ( & url, fail_url [ i ] ); - + rc = VFSManagerMakePath ( vfs, & vpath, "%S", & url ); if ( rc != 0 ) { @@ -430,10 +429,10 @@ rc_t ParseUrlTest ( const VFSManager * vfs ) size_t num_read; char buffer [ 4096 ]; - + String sys; StringInitCString ( & sys, sys_path [ i ] ); - + rc = VFSManagerMakeSysPath ( vfs, & vpath, sys_path [ i ] ); if ( rc == 0 ) { @@ -458,7 +457,7 @@ rc_t ParseUrlTest ( const VFSManager * vfs ) return rc; } } - + return 0; } @@ -502,7 +501,7 @@ rc_t ModifyPathTest ( const VFSManager * vfs ) }; const size_t num_urls = sizeof test_urls / sizeof test_urls [ 0 ]; - static const char *fail_url [] = + static const char *fail_url [] = { /* host */ "http://www.abc.com", @@ -519,14 +518,14 @@ rc_t ModifyPathTest ( const VFSManager * vfs ) NULL }; const size_t num_ext = sizeof test_ext / sizeof test_ext [ 0 ]; - + for ( i = 0; i < num_urls; ++ i ) { VPath * orig; - + String url; StringInitCString ( & url, test_urls [ i ] ); - + rc = VFSManagerMakePath ( vfs, & orig, "%S", & url ); if ( rc == 0 ) { @@ -554,14 +553,14 @@ rc_t ModifyPathTest ( const VFSManager * vfs ) VPathRelease ( orig ); } } - + for ( i = 0; i < num_fail_urls; ++ i ) { VPath * orig; - + String url; StringInitCString ( & url, fail_url [ i ] ); - + rc = VFSManagerMakePath ( vfs, & orig, "%S", & url ); if ( rc == 0 ) { @@ -628,7 +627,7 @@ rc_t ExtractAccessionTest ( const VFSManager * vfs ) }; const size_t num_urls = sizeof test_urls / sizeof test_urls [ 0 ]; - static const char *fail_url [] = + static const char *fail_url [] = { /* urls */ "http://www.abc.com/library/index.html", @@ -644,7 +643,7 @@ rc_t ExtractAccessionTest ( const VFSManager * vfs ) "/path/10315_3#63.bam" }; const size_t num_fail_urls = sizeof fail_url / sizeof fail_url [ 0 ]; - + for ( i = 0; i < num_urls; ++ i ) { VPath * orig; @@ -710,36 +709,6 @@ rc_t ExtractAccessionTest ( const VFSManager * vfs ) return 0; } - -/* Version EXTERN - * return 4-part version code: 0xMMmmrrrr, where - * MM = major release - * mm = minor release - * rrrr = bug-fix release - */ -ver_t CC KAppVersion ( void ) -{ - return 0; -} - - -/* Usage - * This function is called when the command line argument - * handling sees -? -h or --help - */ -rc_t CC UsageSummary ( const char *progname ) -{ - return 0; -} - -const char UsageDefaultName[] = "path-test"; - -rc_t CC Usage ( const Args *args ) -{ - return 0; -} - - static rc_t run ( const char *progname ) { @@ -757,9 +726,7 @@ rc_t run ( const char *progname ) return rc; } -/* KMain - */ -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { Args *args; rc_t rc = ArgsMakeAndHandle ( & args, argc, argv, 0 ); @@ -770,5 +737,5 @@ rc_t CC KMain ( int argc, char *argv [] ) ArgsWhack ( args ); } - return rc; + return (int)rc; } diff --git a/test/vfs/pathtest.cpp b/test/vfs/pathtest.cpp index cbd5b2281..4ac02962e 100644 --- a/test/vfs/pathtest.cpp +++ b/test/vfs/pathtest.cpp @@ -31,6 +31,8 @@ #include "../../libs/vfs/path-priv.h" +#include + #include #include @@ -99,7 +101,7 @@ class PathFixture static const int BufSize = 1024; char buf[BufSize]; - size_t num_read; + size_t num_read = 0; }; class ExtractAccessionOrOID : protected ncbi::NK::TestCase { @@ -129,7 +131,7 @@ class ExtractAccessionOrOID : protected ncbi::NK::TestCase { { VPath * path = NULL; VPath * acc_or_oid = NULL; - REQUIRE_RC(VFSManagerMakeOidPath(vfs, &path, name)); + REQUIRE_RC(VFSManagerMakeOidPath(vfs, &path, (uint32_t)name)); REQUIRE_EQ(path->path_type, path_type); REQUIRE_RC(VFSManagerExtractAccessionOrOID(vfs, &acc_or_oid, path)); REQUIRE_EQ(VPathGetQuality(acc_or_oid), q); @@ -366,7 +368,6 @@ FIXTURE_TEST_CASE(NAME_SERVER_PROTECTED_HTTP, PathFixture) { REQUIRE(VPathFromUri(path)); REQUIRE(!VPathIsHighlyReliable(path)); - size_t num_read = 0; { const string e(URL "?tic=" TIC); char buffer[4096] = ""; @@ -564,8 +565,8 @@ FIXTURE_TEST_CASE(ExtractAccessionOrOID_Quality_PathType, PathFixture) { REQUIRE_RC(VPathRelease(path)); - ExtractAccessionOrOID e(this, "SRR01", - vfs, srr, vpNameOrAccession, eQualLast); + //ExtractAccessionOrOID e(this, "SRR01", + // vfs, srr, vpNameOrAccession, eQualLast); { REQUIRE_RC(VPathMakeFmt(&path, "1?")); REQUIRE_EQ(path->path_type, (uint8_t)vpName); @@ -877,7 +878,6 @@ FIXTURE_TEST_CASE(NAME_SERVER_PROTECTED_FASP, PathFixture) { { const string e(URL "?tic=" TIC); char buffer[4096] = ""; - size_t num_read = 0; REQUIRE_RC(VPathReadUri(path, buffer, sizeof buffer, &num_read)); REQUIRE_EQ(num_read, e.size()); REQUIRE_EQ(string(buffer), e); @@ -1080,7 +1080,6 @@ FIXTURE_TEST_CASE(Http_, PathFixture) #define SRC "http://u@h.d:9/d/f" REQUIRE_RC(VFSManagerMakePath ( vfs, &path, SRC)); char buffer[4096] = ""; - size_t num_read = 0; REQUIRE_RC(VPathReadUri(path, buffer, sizeof buffer, &num_read)); REQUIRE_EQ(num_read, sizeof SRC - 1); REQUIRE_EQ(string(buffer), string(SRC)); @@ -1092,7 +1091,6 @@ FIXTURE_TEST_CASE(Fasp_, PathFixture) #define SRC "fasp://u@hst.com:dir/file" REQUIRE_RC(VFSManagerMakePath ( vfs, &path, SRC)); char buffer[4096] = ""; - size_t num_read = 0; REQUIRE_RC(VPathReadUri(path, buffer, sizeof buffer, &num_read)); REQUIRE_EQ(num_read, sizeof SRC - 1); REQUIRE_EQ(string(buffer), string(SRC)); @@ -1109,7 +1107,6 @@ FIXTURE_TEST_CASE(F_asp_, PathFixture) #define SRC "fasp://u@hst.com:a-dir/file" REQUIRE_RC(VFSManagerMakePath ( vfs, &path, SRC)); char buffer[4096] = ""; - size_t num_read = 0; REQUIRE_RC(VPathReadUri(path, buffer, sizeof buffer, &num_read)); REQUIRE_EQ(num_read, sizeof SRC - 1); REQUIRE_EQ(string(buffer), string(SRC)); @@ -1126,7 +1123,6 @@ FIXTURE_TEST_CASE(Fasp1G_, PathFixture) #define SRC "fasp://u@ftp.gov:1G" REQUIRE_RC(VFSManagerMakePath ( vfs, &path, SRC)); char buffer[4096] = ""; - size_t num_read = 0; REQUIRE_RC(VPathReadUri(path, buffer, sizeof buffer, &num_read)); REQUIRE_EQ(num_read, sizeof SRC - 1); REQUIRE_EQ(string(buffer), string(SRC)); @@ -1148,27 +1144,6 @@ FIXTURE_TEST_CASE(Pileup, PathFixture) #endif //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} -const char UsageDefaultName[] = "test-path"; - static void clear_recorded_errors( void ) { rc_t rc; @@ -1180,11 +1155,9 @@ static void clear_recorded_errors( void ) } } -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { - rc_t rc=VPathTestSuite(argc, argv); + int rc=VPathTestSuite(argc, argv); clear_recorded_errors(); return rc; } - -} diff --git a/test/vfs/redirect-rejected-names-cgi-http-to-https.cpp b/test/vfs/redirect-rejected-names-cgi-http-to-https.cpp index b99f669d3..63de1ee4a 100644 --- a/test/vfs/redirect-rejected-names-cgi-http-to-https.cpp +++ b/test/vfs/redirect-rejected-names-cgi-http-to-https.cpp @@ -172,7 +172,7 @@ TEST_CASE(TEST) { Test ( "Called over HTTPS to Gov: got 200", this, e200, "https to Gov", "https://" RESOLVER_CGI_HEAD "GoV/Traces/names/names.cgi" ); -#if NOW_NAMES_CGI_ALWAYS_RETURNS_403_WHEN_ASKED_FOR_HTTP +#if NOW_NAMES_CGI_ALWAYS_RETURNS_403_WHEN_ASKED_FOR_HTTP Test ( "Called over HTTP: fail after 403 - not retrying non-government sites", this, e403, "HTTP, not government", @@ -218,18 +218,13 @@ static bool out_of_ncbi() { return rc != 0; } -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC UsageSummary ( const char * progname) { return 0; } - rc_t CC Usage ( const struct Args * args ) { return 0; } - const char UsageDefaultName[] = "redirect-rejected-names-cgi-http-to-https"; - rc_t CC KMain ( int argc, char *argv [] ) { - if ( 0 ) assert ( ! KDbgSetString ( "VFS" ) ); - KConfigDisableUserSettings (); - if ( out_of_ncbi() ) { - std::cerr << "Disabled outside of NCBI\n"; - return 0; - } - return VResolverTestSuite ( argc, argv ); +int main ( int argc, char *argv [] ) +{ + if ( 0 ) assert ( ! KDbgSetString ( "VFS" ) ); + KConfigDisableUserSettings (); + if ( out_of_ncbi() ) { + std::cerr << "Disabled outside of NCBI\n"; + return 0; } + return VResolverTestSuite ( argc, argv ); } diff --git a/test/vfs/test-SraDesc.cpp b/test/vfs/test-SraDesc.cpp index 5955c186c..4779d17be 100644 --- a/test/vfs/test-SraDesc.cpp +++ b/test/vfs/test-SraDesc.cpp @@ -33,7 +33,7 @@ #include /* string_printf */ -#include /* KMain */ +#include TEST_SUITE(SraDescTestSuite); @@ -241,10 +241,7 @@ FIXTURE_TEST_CASE(LoalObsoleteQualityTest, SraDescTestFixture) { } #endif -extern "C" { - ver_t CC KAppVersion(void) { return 0; } - rc_t CC KMain(int argc, char * argv[]) { - KConfigDisableUserSettings(); - return SraDescTestSuite(argc, argv); - } +int main(int argc, char * argv[]) { + KConfigDisableUserSettings(); + return SraDescTestSuite(argc, argv); } diff --git a/test/vfs/test-attached-vdbcache.cpp b/test/vfs/test-attached-vdbcache.cpp index ca10bbefd..297236480 100644 --- a/test/vfs/test-attached-vdbcache.cpp +++ b/test/vfs/test-attached-vdbcache.cpp @@ -29,7 +29,7 @@ #include /* KDbgSetString */ #include /* KNSManagerMakeLocal */ #include /* KNSManagerRelease */ -#include /* KMain */ +#include #include /* VPathRelease */ #include /* KServiceMakeWithMgr */ @@ -288,16 +288,10 @@ TEST_CASE(MultipleVdbcache) { } #endif -extern "C" { - const char UsageDefaultName[] = "test-resolve"; - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage(const struct Args * args) { return 0; } - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char * argv [] ) { +int main ( int argc, char * argv [] ) { #if 0 - KDbgSetString ( "VFS" ); + KDbgSetString ( "VFS" ); #endif - KConfigDisableUserSettings (); - return TestVdbcache(argc, argv); - } + KConfigDisableUserSettings (); + return TestVdbcache(argc, argv); } diff --git a/test/vfs/test-caching-test.cpp b/test/vfs/test-caching-test.cpp index 298203f1a..873b868f4 100644 --- a/test/vfs/test-caching-test.cpp +++ b/test/vfs/test-caching-test.cpp @@ -636,15 +636,10 @@ TEST_CASE ( REFSEQ_APP_CACHE_DISABLE ) { #endif //////////////////////////////////////////////////////////////////////////////// -extern "C" { - ver_t CC KAppVersion ( void ) { - return 0; - } - rc_t CC KMain ( int argc, char * argv [] ) { - setenv("HOME", ".", 1); - KConfigDisableUserSettings (); +int main ( int argc, char * argv [] ) { + setenv("HOME", ".", 1); + KConfigDisableUserSettings (); if ( 0 ) assert ( ! KDbgSetString ( "VFS" ) ); - return CachingSuite ( argc, argv ); - } + return CachingSuite ( argc, argv ); } diff --git a/test/vfs/test-caching.cpp b/test/vfs/test-caching.cpp index ee9b20178..cccae8902 100644 --- a/test/vfs/test-caching.cpp +++ b/test/vfs/test-caching.cpp @@ -632,15 +632,11 @@ TEST_CASE ( REFSEQ_APP_CACHE_DISABLE ) { //////////////////////////////////////////////////////////////////////////////// -extern "C" { - ver_t CC KAppVersion ( void ) { - return 0; - } - rc_t CC KMain ( int argc, char * argv [] ) { - setenv("HOME", ".", 1); - KConfigDisableUserSettings (); -if ( +int main ( int argc, char * argv [] ) { + setenv("HOME", ".", 1); + KConfigDisableUserSettings (); + if ( 0 ) assert ( ! KDbgSetString ( "VFS" ) ); - return CachingSuite ( argc, argv ); - } + + return CachingSuite ( argc, argv ); } diff --git a/test/vfs/test-json-response.cpp b/test/vfs/test-json-response.cpp index b16563b93..a3f6f0496 100644 --- a/test/vfs/test-json-response.cpp +++ b/test/vfs/test-json-response.cpp @@ -380,12 +380,9 @@ TEST_CASE(testLive) { TEST_SUITE ( TestResolver4 ) -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char * argv [] ) { - if ( +int main ( int argc, char * argv [] ) { + if ( 0 ) - assert ( ! KDbgSetString ( "VFS-JSON" ) ); + assert ( ! KDbgSetString ( "VFS-JSON" ) ); return TestResolver4 ( argc, argv ); - } } diff --git a/test/vfs/test-log-names-error.cpp b/test/vfs/test-log-names-error.cpp index 59ca32534..562b5287d 100644 --- a/test/vfs/test-log-names-error.cpp +++ b/test/vfs/test-log-names-error.cpp @@ -24,7 +24,7 @@ #include /* KConfigMakeLocal */ -#include /* KMain */ +#include #include /* KDbgSetString */ @@ -188,15 +188,11 @@ FIXTURE_TEST_CASE(TestEnableInConfig, Fixture) { } #endif -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } +int main( int argc, char * argv [] ) { + KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg - rc_t CC KMain ( int argc, char * argv [] ) { - KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg - - if ( + if ( 0) assert(!KDbgSetString("VFS")); - return TestLogNames( argc, argv ); - } + return TestLogNames( argc, argv ); } diff --git a/test/vfs/test-names-30.cpp b/test/vfs/test-names-30.cpp index 648e758e9..225ebc9f4 100644 --- a/test/vfs/test-names-30.cpp +++ b/test/vfs/test-names-30.cpp @@ -34,7 +34,7 @@ #include #include /* CONST_STRING */ #include /* KTimeMakeTime */ -#include /* KMain */ +#include #include /* VPath */ #include /* KSrvResponse */ #include /* KServiceTestNamesExecuteExt */ @@ -509,29 +509,23 @@ if ( 1 ) NULL, NULL ) ); } -extern "C" { - const char UsageDefaultName[] = "test-names-30"; - rc_t CC UsageSummary ( const char * progname) { return 0; } - rc_t CC Usage ( const struct Args * args ) { return 0; } - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char * argv [] ) { - if ( +int main ( int argc, char * argv [] ) { + if ( 0 ) assert ( ! KDbgSetString ( "VFS" ) ); - KConfigDisableUserSettings (); + KConfigDisableUserSettings (); - rc_t rc = KConfigMake ( & KFG, NULL ); - if ( rc == 0 ) - rc = KConfigWriteString ( KFG, - "repository/remote/main/CGI/resolver-cgi", RESOLVER_CGI ); + rc_t rc = KConfigMake ( & KFG, NULL ); + if ( rc == 0 ) + rc = KConfigWriteString ( KFG, + "repository/remote/main/CGI/resolver-cgi", RESOLVER_CGI ); - if ( + if ( 0) ncbi::NK::TestEnv::SetVerbosity(ncbi::NK::LogLevel::e_all); - rc = Names3_0_TestSuite ( argc, argv ); + rc = (rc_t)Names3_0_TestSuite ( argc, argv ); - RELEASE ( KConfig, KFG ); + RELEASE ( KConfig, KFG ); - return rc; - } + return (int)rc; } diff --git a/test/vfs/test-perm.cpp b/test/vfs/test-perm.cpp index 1e5527989..12d95f585 100644 --- a/test/vfs/test-perm.cpp +++ b/test/vfs/test-perm.cpp @@ -83,7 +83,7 @@ TEST_CASE(TestJwtKartValidateString) { memset(&s, 0, sizeof s); REQUIRE_RC_FAIL(JwtKartValidateString(&s, NULL)); - size_t os = ~0; + size_t os = ~0u; /* too big cart is invalid */ size_t size = 20 * 1024 * 1024; @@ -91,7 +91,7 @@ TEST_CASE(TestJwtKartValidateString) { REQUIRE_NOT_NULL(buffer); REQUIRE_NOT_NULL(memset(buffer, 'a', size)); buffer[5] = buffer[9] = '.'; - StringInit(&s, buffer, size, size); + StringInit(&s, buffer, size, (uint32_t)size); REQUIRE_RC_FAIL(JwtKartValidateString(&s, &os)); REQUIRE_EQ(os, (size_t)0); free(buffer); @@ -102,7 +102,7 @@ TEST_CASE(TestJwtKartValidateString) { REQUIRE_NOT_NULL(buffer); REQUIRE_NOT_NULL(memset(buffer, 'A', size)); buffer[5] = buffer[9] = '.'; - StringInit(&s, buffer, size, size); + StringInit(&s, buffer, size, (uint32_t)size); REQUIRE_RC(JwtKartValidateString(&s, NULL)); free(buffer); @@ -116,7 +116,7 @@ TEST_CASE(TestJwtKartValidateString) { "SV5e3TJj7SmXMlvNOJMlWD76rYoitWU82uA_S6mXXkTTxNd2KfmeEsj7g1djc1M7yUkQRET46eIp1q" "bk6gOAiiF5AL8eC8-SOLGrxqmdF8AU52_L31_pwA"; size = strlen(b); - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC(JwtKartValidateString(&s, NULL)); } @@ -129,7 +129,7 @@ TEST_CASE(TestJwtKartValidateStringWhite) { "\r"; size_t size = sizeof b1 - 1; String s; - StringInit(&s, b1, size, size); + StringInit(&s, b1, size, (uint32_t)size); REQUIRE_RC(JwtKartValidateString(&s, NULL)); /* check valid characters */ @@ -147,12 +147,12 @@ TEST_CASE(TestJwtKartValidateStringWhite) { /* check second section */ const char * b = "abcdefghijklmnopqrstuvwxyz." "ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789-_\n\r\n\n\r\r"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC(JwtKartValidateString(&s, NULL)); b = "abcdefghijklmnopqrstuvwxyz." "ABCDEFGHIJKL NOPQRSTUVWXYZ.0123456789-_\n\r\n\n\r\r"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC_FAIL(JwtKartValidateString(&s, NULL)); /* check third section */ @@ -162,14 +162,14 @@ TEST_CASE(TestJwtKartValidateStringWhite) { b = "abcdefghijklmnopqrstuvwxyz." "ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789-_\n\r\n\n\r\r"; - StringInit(&s, b, size, size); - size_t os = ~0; + StringInit(&s, b, size, (uint32_t)size); + size_t os = ~0u; REQUIRE_RC(JwtKartValidateString(&s, &os)); REQUIRE_EQ(os, es); b = "abcdefghijklmnopqrstuvwxyz." "ABCDEFGHIJKLMNOPQRSTUVWXYZ.01234 6789-_\n\r\n\n\r\r"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC_FAIL(JwtKartValidateString(&s, NULL)); } @@ -179,66 +179,55 @@ TEST_CASE(TestJwtKartValidateStringWhiteSections) { const char * b = "1234567810123.567820123456.8301234567840"; size_t size = strlen(b); String s; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC(JwtKartValidateString(&s, &os)); REQUIRE_EQ(os, size); /* 1 dot */ b = "12345678101234567820123456.8301234567840"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC_FAIL(JwtKartValidateString(&s, NULL)); /* 3 dots */ b = "1234567810123.567820123456.830123.567840"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC_FAIL(JwtKartValidateString(&s, NULL)); /* first section empty */ b = ".2345678101234567820123456.8301234567840"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC_FAIL(JwtKartValidateString(&s, NULL)); /* first section size is min */ b = "1.345678101234567820123456.8301234567840"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC(JwtKartValidateString(&s, NULL)); /* second section empty */ b = "1234567810123456782012345..8301234567840"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC_FAIL(JwtKartValidateString(&s, NULL)); /* second section size is min */ b = "123456781012345678201234.6.8301234567840"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC(JwtKartValidateString(&s, NULL)); /* third section empty */ b = "1234567810123.5678201234567830123456784."; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC_FAIL(JwtKartValidateString(&s, NULL)); /* third section size is min */ b = "1234567810123.567820123456783012345678.0"; - StringInit(&s, b, size, size); + StringInit(&s, b, size, (uint32_t)size); REQUIRE_RC(JwtKartValidateString(&s, NULL)); } -const char UsageDefaultName[] = "test"; -rc_t CC UsageSummary(const char * progname) { return 0; } -rc_t CC Usage(const Args * args) { return 0; } - -extern "C" { - - ver_t CC KAppVersion(void) { return 0; } - - int KMain(int argc, char *argv[]) { - KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg - - rc_t rc = TestPermSuite(argc, argv); - return rc; - } +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg + return TestPermSuite(argc, argv); } /******************************************************************************/ diff --git a/test/vfs/test-read_observer.cpp b/test/vfs/test-read_observer.cpp new file mode 100644 index 000000000..05cd49cc8 --- /dev/null +++ b/test/vfs/test-read_observer.cpp @@ -0,0 +1,467 @@ +/*============================================================================== +* +* PUBLIC DOMAIN NOTICE +* National Center for Biotechnology Information +* +* This software/database is a "United States Government Work" under the +* terms of the United States Copyright Act. It was written as part of +* the author's official duties as a United States Government employee and +* thus cannot be copyrighted. This software/database is freely available +* to the public for use. The National Library of Medicine and the U.S. +* Government have not placed any restriction on its use or reproduction. +* +* Although all reasonable efforts have been taken to ensure the accuracy +* and reliability of the software and data, the NLM and the U.S. +* Government do not and cannot warrant the performance or results that +* may be obtained by using this software or data. The NLM and the U.S. +* Government disclaim all warranties, express or implied, including +* warranties of performance, merchantability or fitness for any particular +* purpose. +* +* Please cite the author in any work or product based on this material. +* +* ============================================================================== +* Tests of KFileMD5ReadObserver for HTTP file +*/ + +#include "observer-test.hpp" // ObserverTest + +#include /* KConfigDisableUserSettings */ + +TEST_SUITE(ReadObserverTestSuite) + +using std::string; + +//////////////////////////////////////////////////////////////////////////////// +// KFileReadAll + +TEST_CASE(ReadAllExactly) { + ObserverTest t(this, "ReadAllExactly"); + t.Start(true); + size_t num_read(0), sz(t.size); + uint64_t pos(0); + // request exactly all file; EOF is detected by file size + for (; pos < t.size; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); + t.Finish("", true); +} + +TEST_CASE(ReadAllExactlyPlus1) { + ObserverTest t(this, "ReadAllExactlyPlus1"); + t.Start(); + size_t num_read(0), sz(t.size + 1); + uint64_t pos(0); + // request all file + 1 byte + // will read one byte less than requested; + // EOF can be detected by last read that returns 0 bytes + for (; pos < t.size; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadAllSkip0) { + ObserverTest t(this, "ReadAllSkip0"); + t.Start(true); + size_t num_read(0), sz(t.size); + uint64_t pos(1); + for (; pos < t.size; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); + // the first byte was not read + t.Finish(ERR_HEAD "0 of 31838.", true); +} + +TEST_CASE(ReadAllSkip1) { + ObserverTest t(this, "ReadAllSkip1"); + t.Start(); + size_t num_read(0), sz(t.size); + REQUIRE_RC(KFileReadAll(t.file, 0, t.buf, 1, &num_read)); +// REQUIRE_RC(KFileReadAll(t.file, 1, t.buf, 1, &num_read)); + uint64_t pos(2); + for (; pos < t.size; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); + // the second byte was not read + t.Finish(ERR_HEAD "1 of 31838."); +} + +TEST_CASE(ReadAllSkipLast) { + ObserverTest t(this, "ReadAllSkipLast"); + t.Start(); + size_t num_read(0), sz(t.size - 1); + uint64_t pos(0); + for (; pos < t.size - 1; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); +// REQUIRE_RC(KFileReadAll(t.file, t.size - 1, t.buf, 1, &num_read)); + // the last byte was not read + t.Finish(ERR_HEAD "31837 " + "of 31838."); +} + +TEST_CASE(ReadAllTwice) { + ObserverTest t(this, "ReadAllTwice"); + t.Start(); + size_t num_read(0), sz(10000); + uint64_t pos(0); + for (; pos < 10000; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); + // this call will request the part that was already completely read + for (pos = 1, sz = 5000; pos < 5000; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); + for (pos = 5000, sz = t.size - 5000; + pos < t.size; pos += num_read, sz -= num_read) + { REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); } + t.Finish(); +} + +TEST_CASE(ReadAllTwicePartially) { + ObserverTest t(this, "ReadAllTwicePartially"); + t.Start(); + size_t num_read(0), sz(20000); + uint64_t pos(0); + for (; pos < 20000; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); + for (pos = 2000, sz = t.size - 2000; + pos < t.size; pos += num_read, sz -= num_read) + { REQUIRE_RC(KFileReadAll(t.file, pos, t.buf, sz, &num_read)); } + // this call requested the part that was already read and new data + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileRead + +TEST_CASE(Read) { + ObserverTest t(this, "Read"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 2, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadSkip0) { + ObserverTest t(this, "ReadSkip0"); + t.Start(); + size_t num_read(0); + uint64_t pos(1); +// REQUIRE_RC(KFileRead(t.file, 0, t.buf, 1, &num_read)); + for (pos = 1; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 2, &num_read)); + t.Finish(ERR_HEAD "0 of 31838."); +} + +TEST_CASE(ReadSkip1) { + ObserverTest t(this, "ReadSkip1"); + t.Start(); + size_t num_read(0); + uint64_t pos(0); + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1, &num_read)); + pos += num_read; +// REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1, &num_read)); pos += num_read; + for (++pos; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, t.size / 3, &num_read)); + t.Finish(ERR_HEAD "1 of 31838."); +} + +TEST_CASE(ReadTwice) { + ObserverTest t(this, "ReadTwice"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 20000; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 2000, &num_read)); + for (pos = 1; num_read > 0 && pos < 10000; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 1000, &num_read)); + for (pos = 20000; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 20000, &num_read)); + t.Finish(); +} + +TEST_CASE(ReadTwicePartially) { + ObserverTest t(this, "ReadTwicePartially"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 20000; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 10000, &num_read)); + for (pos = 10000; num_read > 0; pos += num_read) + REQUIRE_RC(KFileRead(t.file, pos, t.buf, 20000, &num_read)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedRead + +TEST_CASE(TimedRead) { + ObserverTest t(this, "TimedRead"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 10000, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadSkip0) { + ObserverTest t(this, "TimedReadSkip0"); + t.Start(true); + size_t num_read(0); + uint64_t pos(1); + //REQUIRE_RC(KFileRead(t.file, 0, t.buf, 1, &num_read)); + for (pos = 1; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 10000, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0 of 31838."); +} + +TEST_CASE(TimedReadSkip1) { + ObserverTest t(this, "TimedReadSkip1"); + t.Start(); + size_t num_read(0); + uint64_t pos(0); + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 1, &num_read, &t.tm)); + pos += num_read; +//REQUIRE_RC(KFileTimedRead(t.file, pos,t.buf,1,&num_read,&t.tm));pos+=num_read; + for (++pos; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 10000, &num_read, &t.tm)); + t.Finish(ERR_HEAD "1 of 31838."); +} + +TEST_CASE(TimedReadTwice) { + ObserverTest t(this, "TimedReadTwice"); + t.Start(true); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 20000; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 2000, &num_read, &t.tm)); + for (pos = 1; num_read > 0 && pos < 10000; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 1000, &num_read, &t.tm)); + for (pos = 20000; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 20000, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadTwicePartially) { + ObserverTest t(this, "TimedReadTwicePartially"); + t.Start(); + size_t num_read(1); + uint64_t pos(0); + for (pos = 0; num_read > 0 && pos < 20000; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 10000, &num_read, &t.tm)); + for (pos = 10000; num_read > 0; pos += num_read) + REQUIRE_RC(KFileTimedRead(t.file, pos, t.buf, 20000, &num_read, &t.tm)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedReadAll + +TEST_CASE(TimedReadAllExactly) { + ObserverTest t(this, "TimedReadAllExactly"); + t.Start(); + size_t num_read(0), sz(t.size); + uint64_t pos(0); + for (; pos < t.size; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadAllExactlyPlus1) { + ObserverTest t(this, "TimedReadAllExactlyPlus1"); + t.Start(); + size_t num_read(0), sz(t.size + 1); + uint64_t pos(0); + for (; pos < t.size; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadAllSkip0) { + ObserverTest t(this, "TimedReadAllSkip0"); + t.Start(true); + size_t num_read(0), sz(t.size); + //REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, 1, &num_read, &t.tm)); + uint64_t pos(1); + for (; pos < t.size; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + t.Finish(ERR_HEAD "0 of 31838."); +} + +TEST_CASE(TimedReadAllSkip1) { + ObserverTest t(this, "TimedReadAllSkip1"); + t.Start(true); + size_t num_read(0), sz(t.size);; + REQUIRE_RC(KFileTimedReadAll(t.file, 0, t.buf, 1, &num_read, &t.tm)); +// REQUIRE_RC(KFileTimedReadAll(t.file, 1, t.buf, 1, &num_read, &t.tm)); + uint64_t pos(2); + for (; pos < t.size; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + t.Finish(ERR_HEAD "1 of 31838."); +} + +TEST_CASE(TimedReadAllSkipLast) { + ObserverTest t(this, "TimedReadAllSkipLast"); + t.Start(); + size_t num_read(0), sz(t.size - 1); + uint64_t pos(0); + for (; pos < t.size - 1; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); +//REQUIRE_RC(KFileTimedReadAll(t.file, t.size - 1, t.buf, 1, &num_read, &t.tm)); + t.Finish(ERR_HEAD "31837 " + "of 31838."); +} + +TEST_CASE(TimedReadAllTwice) { + ObserverTest t(this, "TimedReadAllTwice"); + t.Start(); + size_t num_read(0), sz(10000); + uint64_t pos(0); + for (; pos < 10000; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + for (pos = 1, sz = 5000; pos < 5000; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + for (pos = 5000, sz = t.size - 5000; + pos < t.size; pos += num_read, sz -= num_read) + { + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + } + t.Finish(); +} + +TEST_CASE(TimedReadAllTwicePartially) { + ObserverTest t(this, "TimedReadAllTwicePartially"); + t.Start(); + size_t num_read(0), sz(20000); + uint64_t pos(0); + for (; pos < 20000; pos += num_read, sz -= num_read) + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + for (pos = 2000, sz = t.size - 2000; + pos < t.size; pos += num_read, sz -= num_read) + { + REQUIRE_RC(KFileTimedReadAll(t.file, pos, t.buf, sz, &num_read, &t.tm)); + } + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileReadExactly + +TEST_CASE(ReadExactly) { + ObserverTest t(this, "ReadExactly"); + t.Start(); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, t.size)); + t.Finish(); +} + +TEST_CASE(ReadExactlySkip0) { + ObserverTest t(this, "ReadExactlySkip0"); + t.Start(); +// REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1)); + REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, t.size - 1)); + t.Finish(ERR_HEAD "0 of 31838."); +} + +TEST_CASE(ReadExactlySkip1) { + ObserverTest t(this, "ReadExactlySkip1"); + t.Start(); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 1)); +// REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, 1)); + REQUIRE_RC(KFileReadExactly(t.file, 2, t.buf, t.size - 2)); + t.Finish(ERR_HEAD "1 of 31838."); +} + +TEST_CASE(ReadExactlySkipLast) { + ObserverTest t(this, "ReadExactlySkipLast"); + t.Start(); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, t.size - 1)); +// REQUIRE_RC(KFileReadExactly(t.file, t.size - 1, t.buf, 1)); + t.Finish(ERR_HEAD "31837 " + "of 31838."); +} + +TEST_CASE(ReadExactlyTwice) { + ObserverTest t(this, "ReadExactlyTwice"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 20000)); + REQUIRE_RC(KFileReadExactly(t.file, 1, t.buf, 10000)); + REQUIRE_RC(KFileReadExactly(t.file, 20000, t.buf, t.size - 20000)); + t.Finish(); +} + +TEST_CASE(ReadExactlyTwicePartially) { + ObserverTest t(this, "ReadExactlyTwicePartially"); + t.Start(true); + REQUIRE_RC(KFileReadExactly(t.file, 0, t.buf, 20000)); + REQUIRE_RC(KFileReadExactly(t.file, 10000, t.buf, t.size - 10000)); + t.Finish(); +} + +//////////////////////////////////////////////////////////////////////////////// +// KFileTimedReadExactly + +TEST_CASE(TimedReadExactly) { + ObserverTest t(this, "TimedReadExactly"); + t.Start(); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, t.size, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadExactlySkip0) { + ObserverTest t(this, "TimedReadExactlySkip0"); + t.Start(); +// REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, t.size - 1, &t.tm)); + t.Finish(ERR_HEAD "0 of 31838."); +} + +TEST_CASE(TimedReadExactlySkip1) { + ObserverTest t(this, "ReadExactlySkip1"); + t.Start(); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 1, &t.tm)); +// REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, 1, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 2, t.buf, t.size - 2, &t.tm)); + t.Finish(ERR_HEAD "1 of 31838."); +} + +TEST_CASE(TimedReadExactlySkipLast) { + ObserverTest t(this, "TimedReadExactlySkipLast"); + t.Start(); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, t.size - 1, &t.tm)); +// REQUIRE_RC(KFileTimedReadExactly(t.file, t.size - 1, t.buf, 1, &t.tm)); + t.Finish(ERR_HEAD "31837 " + "of 31838."); +} + +TEST_CASE(TimedReadExactlyTwice) { + ObserverTest t(this, "TimedReadExactlyTwice"); + t.Start(true); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 20000, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 1, t.buf, 10000, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 20000, + t.buf, t.size - 20000, &t.tm)); + t.Finish(); +} + +TEST_CASE(TimedReadExactlyTwicePartially) { + ObserverTest t(this, "TimedReadExactlyTwicePartially"); + t.Start(); + REQUIRE_RC(KFileTimedReadExactly(t.file, 0, t.buf, 20000, &t.tm)); + REQUIRE_RC(KFileTimedReadExactly(t.file, 999, t.buf, t.size - 999, &t.tm)); + t.Finish(); +} + +int main(int argc, char *argv[]) { + KConfigDisableUserSettings(); + + rc_t rc(ObserverTest::Begin(eHttp)); + + if (rc == 0) + rc = ReadObserverTestSuite(argc, argv); + + rc_t r2(ObserverTest::End()); + if (rc == 0 && r2 != 0) + rc = r2; + + return (rc == 0) ? 0 : IF_EXITCODE(rc, 3); +} + +/******************************************************************************/ diff --git a/test/vfs/test-resolve-qual.cpp b/test/vfs/test-resolve-qual.cpp index da56d2b77..5287f350b 100644 --- a/test/vfs/test-resolve-qual.cpp +++ b/test/vfs/test-resolve-qual.cpp @@ -35,7 +35,7 @@ #include /* KNSManagerSetAdCaching */ #include /* KNSManagerMake */ -#include /* KMain */ +#include #include /* VDBManagerGetQuality */ @@ -220,54 +220,54 @@ class TRQHelper : protected ncbi::NK::TestCase { REQUIRE_NULL(run); } - void PathEquals(const VPath * path, const std::string & e) { + void PathEquals(const VPath * p_path, const std::string & e) { String expPath; StringInitCString(&expPath, e.c_str()); const String * str = NULL; - REQUIRE_RC(VPathMakeString(path, &str)); + REQUIRE_RC(VPathMakeString(p_path, &str)); REQUIRE(StringEqual(str, &expPath)); free(const_cast (str)); } - void PathNOT_Equals(const VPath * path, const std::string & e) { + void PathNOT_Equals(const VPath * p_path, const std::string & e) { String expPath; StringInitCString(&expPath, e.c_str()); const String * str = NULL; - REQUIRE_RC(VPathMakeString(path, &str)); + REQUIRE_RC(VPathMakeString(p_path, &str)); REQUIRE(!StringEqual(str, &expPath)); free(const_cast (str)); } - void VdbcacheNotChecked(const VPath * path = NULL) { - if (path == NULL) - path = this->path; + void VdbcacheNotChecked(const VPath * p_path = NULL) { + if (p_path == NULL) + p_path = this->path; const VPath * vdbcache = NULL; bool vdbcacheChecked = false; - REQUIRE_RC(VPathGetVdbcache(path, &vdbcache, &vdbcacheChecked)); + REQUIRE_RC(VPathGetVdbcache(p_path, &vdbcache, &vdbcacheChecked)); REQUIRE(!vdbcacheChecked); REQUIRE_NULL(vdbcache); } void VdbcacheEquals(const std::string & e = "", - const VPath * path = NULL) + const VPath * p_path = NULL) { - if (path == NULL) - path = this->path; + if (p_path == NULL) + p_path = this->path; - if (path == NULL) + if (p_path == NULL) return; const VPath * vdbcache = NULL; bool vdbcacheChecked = false; - REQUIRE_RC(VPathGetVdbcache(path, &vdbcache, &vdbcacheChecked)); + REQUIRE_RC(VPathGetVdbcache(p_path, &vdbcache, &vdbcacheChecked)); REQUIRE(vdbcacheChecked); @@ -322,24 +322,21 @@ class TRQHelper : protected ncbi::NK::TestCase { #include "test-resolve-qual-1.hpp" #include "test-resolve-qual-2.hpp" #endif -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char * argv [] ) { - rc_t rc = 0; - if ( +int main( int argc, char * argv [] ) { + rc_t rc = 0; + if ( 1) VFSManagerLogNamesServiceErrors(0, false); - if ( + if ( 0) - rc = KDbgSetString("VFS"); - KConfigDisableUserSettings(); + rc = KDbgSetString("VFS"); + KConfigDisableUserSettings(); #ifndef USE_SERVICES_CACHE - return rc; + return (int)rc; #else - if ( rc == 0 ) - rc = TestResolveQualSuite(argc, argv); - return rc; + if ( rc == 0 ) + rc = (rc_t)TestResolveQualSuite(argc, argv); + return (int)rc; #endif - } } /* TODO: check the case when run is found locally in several places; diff --git a/test/vfs/test-resolve.cpp b/test/vfs/test-resolve.cpp index 3a6ddc182..d19013cb5 100644 --- a/test/vfs/test-resolve.cpp +++ b/test/vfs/test-resolve.cpp @@ -30,7 +30,7 @@ #include /* KDbgSetString */ #include /* KNSManagerMakeLocal */ #include /* KNSManagerRelease */ -#include /* KMain */ +#include #include /* VPathRelease */ #include /* KServiceMakeWithMgr */ @@ -177,16 +177,10 @@ TEST_CASE(Protected) { x.Release(); } -extern "C" { - const char UsageDefaultName[] = "test-resolve"; - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage(const struct Args * args) { return 0; } - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char * argv [] ) { +int main( int argc, char * argv [] ) { #if 0 - KDbgSetString ( "VFS" ); + KDbgSetString ( "VFS" ); #endif - KConfigDisableUserSettings (); - return TestResolveSuite(argc, argv); - } + KConfigDisableUserSettings (); + return TestResolveSuite(argc, argv); } diff --git a/test/vfs/test-resolver-with-log.cpp b/test/vfs/test-resolver-with-log.cpp index 4860b0af0..7bd152cfc 100644 --- a/test/vfs/test-resolver-with-log.cpp +++ b/test/vfs/test-resolver-with-log.cpp @@ -29,7 +29,7 @@ #include /* KConfigDisableUserSettings */ #include /* KDbgSetString */ #include /* CONST_STRING */ -#include /* KMain */ +#include #include /* VFSManagerRelease */ #include /* VFSManagerMakeFromKfg */ #include /* VPathRelease */ @@ -190,36 +190,32 @@ FIXTURE_TEST_CASE ( ZZZZ99, Fixture ) { free ( const_cast < String * > ( uri ) ); } -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - - rc_t CC KMain ( int argc, char * argv [] ) { +int main( int argc, char * argv [] ) { #if _DEBUGGING - KDbgSetString ( "VFS" ); + KDbgSetString ( "VFS" ); #endif - KConfigDisableUserSettings (); + KConfigDisableUserSettings (); - rc_t rc = KConfigMake ( & KFG, NULL ); - if ( rc == 0 ) - rc = KConfigWriteString ( KFG, - "repository/remote/main/SDL.2/resolver-cgi", SDL_CGI ); - if ( rc == 0 ) - rc = KConfigWriteString ( KFG, - "repository/user/main/public/root", "/TMP" ); - if ( rc == 0 ) - rc = KConfigWriteString ( KFG, - "repository/user/main/public/apps/wgs/volumes/wgsFlat", "wgs" ); + rc_t rc = KConfigMake ( & KFG, NULL ); + if ( rc == 0 ) + rc = KConfigWriteString ( KFG, + "repository/remote/main/SDL.2/resolver-cgi", SDL_CGI ); + if ( rc == 0 ) + rc = KConfigWriteString ( KFG, + "repository/user/main/public/root", "/TMP" ); + if ( rc == 0 ) + rc = KConfigWriteString ( KFG, + "repository/user/main/public/apps/wgs/volumes/wgsFlat", "wgs" ); - std::cerr << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n"; + std::cerr << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n"; - putenv((char*)"NCBI_VDB_NO_CACHE_SDL_RESPONSE=1"); + putenv((char*)"NCBI_VDB_NO_CACHE_SDL_RESPONSE=1"); - if ( rc == 0 ) - rc = VResolverWithLogTestSuite ( argc, argv ); + if ( rc == 0 ) + rc = (rc_t)VResolverWithLogTestSuite ( argc, argv ); - RELEASE ( KConfig, KFG ); + RELEASE ( KConfig, KFG ); - return rc; - } + return (int)rc; } diff --git a/test/vfs/test-resolver4.cpp b/test/vfs/test-resolver4.cpp index 406d7d34d..0426f6093 100644 --- a/test/vfs/test-resolver4.cpp +++ b/test/vfs/test-resolver4.cpp @@ -204,14 +204,11 @@ TEST_CASE ( Test ) { } #endif -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char * argv [] ) { - KConfigDisableUserSettings (); +int main ( int argc, char * argv [] ) { + KConfigDisableUserSettings (); if ( 0 ) assert ( ! KDbgSetString ( "VFS-JSON" ) ); if ( 0 ) assert ( ! KDbgSetString ( "VFS" ) ); - return TestResolver4 ( argc, argv ); - } + return TestResolver4 ( argc, argv ); } diff --git a/test/vfs/test-sdl-response.cpp b/test/vfs/test-sdl-response.cpp index 6cafb65ad..b1b44fd80 100644 --- a/test/vfs/test-sdl-response.cpp +++ b/test/vfs/test-sdl-response.cpp @@ -394,14 +394,14 @@ TEST_CASE(invalidMsg) { #ifdef ALL TEST_CASE(expired) { Response4 * response = NULL; - + std::cerr << "vvvvvvvvvvvvvv expect to see error message vvvvvvvvvvvvvvv\n"; REQUIRE_RC(Response4MakeSdl(&response, "{" " \"status\": 440," " \"message\" : \"Claims have expired\"" "}")); - + rc_t rc = 0; REQUIRE_RC(Response4GetRc(response, &rc)); REQUIRE_RC_FAIL(rc); @@ -429,18 +429,13 @@ TEST_CASE(expiredNsg) { } #endif -TEST_SUITE ( TestResolverSdl ) - -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } - rc_t CC KMain ( int argc, char * argv [] ) { - if ( +int main( int argc, char * argv [] ) { + if ( 0 ) - assert ( ! KDbgSetString ( "VFS" ) ); - if ( + assert ( ! KDbgSetString ( "VFS" ) ); + if ( 0 ) - assert ( ! KDbgSetString ( "VFS-JSON" ) ); + assert ( ! KDbgSetString ( "VFS-JSON" ) ); KConfigDisableUserSettings(); return TestSdlResolver( argc, argv ); - } } diff --git a/test/vfs/test-services.cpp b/test/vfs/test-services.cpp index 762b01986..bc0196451 100644 --- a/test/vfs/test-services.cpp +++ b/test/vfs/test-services.cpp @@ -34,7 +34,7 @@ #include /* KDbgSetString */ -#include /* KMain */ +#include #include /* VFSManagerRelease */ #include /* VFSManagerMakeLocal */ @@ -339,16 +339,12 @@ TEST_CASE(TestKSrvResponseGetLocationCacheInADLeak) { } #endif -extern "C" { - ver_t CC KAppVersion ( void ) { return 0; } +int main( int argc, char * argv [] ) { + KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg - rc_t CC KMain ( int argc, char * argv [] ) { - KConfigDisableUserSettings(); // ignore ~/.ncbi/user-settings.mkfg - - if ( + if ( 0) assert(!KDbgSetString("VFS")); - setenv ( "NCBI_VDB_QUALITY", "R", 1 ); - return TestServices ( argc, argv ); - } + setenv ( "NCBI_VDB_QUALITY", "R", 1 ); + return TestServices ( argc, argv ); } diff --git a/test/vfs/test-vfs-resolve.cpp b/test/vfs/test-vfs-resolve.cpp index 9bdc0ce99..04bf0acd0 100644 --- a/test/vfs/test-vfs-resolve.cpp +++ b/test/vfs/test-vfs-resolve.cpp @@ -27,7 +27,7 @@ #include /* ArgsMakeAndHandle */ #include /* KConfigDisableUserSettings */ #include /* KDbgSetString */ -#include /* KMain */ +#include #include /* VFSManagerRelease */ #include /* VPathRelease */ @@ -292,14 +292,14 @@ FIXTURE_TEST_CASE(ResolveTestRemote, Fixture) { REQUIRE_NULL(cache); REQUIRE_RC(VPathEqual(outP, remote, ¬equal)); REQUIRE(notequal == 0); - REQUIRE_RC(VPathRelease(out)); + REQUIRE_RC(VPathRelease(remote)); REQUIRE_RC(VFSManagerResolveVPathAll(mgr, p, &out, &remote, &cache)); REQUIRE_NULL(out); REQUIRE_NULL(cache); REQUIRE_RC(VPathEqual(outP, remote, ¬equal)); REQUIRE(notequal == 0); - REQUIRE_RC(VPathRelease(out)); + REQUIRE_RC(VPathRelease(remote)); REQUIRE_RC(VPathRelease(outP)); REQUIRE_RC(VPathRelease(p)); @@ -440,17 +440,11 @@ FIXTURE_TEST_CASE(ResolveTestLocalPath, Fixture) { REQUIRE_RC(VPathRelease(p)); } -extern "C" { - const char UsageDefaultName[] = "vfs-test-resolve"; - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage(const struct Args * args) { return 0; } - ver_t CC KAppVersion(void) { return 0; } - rc_t CC KMain(int argc, char * argv[]) { - putenv((char*)"NCBI_VDB_NO_CACHE_SDL_RESPONSE=1"); +int main(int argc, char * argv[]) { + putenv((char*)"NCBI_VDB_NO_CACHE_SDL_RESPONSE=1"); #if 0 - KDbgSetString("VFS"); + KDbgSetString("VFS"); #endif - KConfigDisableUserSettings(); - return TestResolveSuite(argc, argv); - } + KConfigDisableUserSettings(); + return TestResolveSuite(argc, argv); } diff --git a/test/vfs/test-vpath-open.hpp b/test/vfs/test-vpath-open.hpp index e3862db81..e8d29128a 100644 --- a/test/vfs/test-vpath-open.hpp +++ b/test/vfs/test-vpath-open.hpp @@ -37,7 +37,7 @@ #include /* VFSManagerRelease */ #include /* VPathGetDirectory */ #include /* VRevolverRelease */ -#include /* KMain */ +#include #include "../../libs/vfs/path-priv.h" /* VPathSetDirectory */ #include /* PATH_MAX */ #ifndef PATH_MAX @@ -479,7 +479,7 @@ FIXTURE_TEST_CASE(TestKDBManagerOpenTable_FUNC_VPath, Fixture) { REQUIRE_RC(KDBManagerOpenTable_FUNC_VPath(kdb, &t, pathR)); REQUIRE_RC(Compare(pathR, tbRPath)); REQUIRE_RC(KTableRelease(t)); - + // open remote table as table: cached dir REQUIRE_RC(KDBManagerOpenTable_FUNC_VPath(kdb, &t, pathR)); REQUIRE_RC(Compare(pathR, tbRPath)); @@ -587,7 +587,7 @@ FIXTURE_TEST_CASE(TestKDBManagerPathTypeVP, Fixture) { REQUIRE_RC(LegacyVPathMake(&pathL, AccTPath)); REQUIRE_RC(VPathGetDirectory(pathL, &dirLoc)); REQUIRE_NULL(dirLoc); - + REQUIRE(KDBManagerPathTypeVP(kdb, pathL) == kptTable); REQUIRE_RC(Compare(pathL, tbLPath)); @@ -597,7 +597,7 @@ FIXTURE_TEST_CASE(TestKDBManagerPathTypeVP, Fixture) { REQUIRE_RC_FAIL(VPathGetDirectory(pathL, 0)); REQUIRE_RC_FAIL(VPathGetDirectory(0, &dirLoc)); - + // PathType of an sra file: cached dir REQUIRE(KDBManagerPathTypeVP(kdb, pathL) == kptTable); REQUIRE_RC(Compare(pathL, tbLPath, &dirLoc)); @@ -634,7 +634,7 @@ FIXTURE_TEST_CASE(TestKDBManagerPathTypeVP, Fixture) { // remote DB VPath * pathDb(0); REQUIRE_RC(LegacyVPathMake(&pathDb, AccDR)); - + // PathType of a remote DB REQUIRE(KDBManagerPathTypeVP(kdb, pathDb) == kptDatabase); REQUIRE_RC(Compare(pathDb, dbRPath)); @@ -723,16 +723,16 @@ and use of VDBManagerOpenDBReadVPath. FIXTURE_TEST_CASE(TestVDBManagerOpenDB_FUNC_VPath, Fixture) { VPath * pathL(0); REQUIRE_RC(LegacyVPathMake(&pathL, AccTPath)); - + const KDirectory * dirLoc(0); REQUIRE_RC(VPathGetDirectory(pathL, &dirLoc)); REQUIRE_NULL(dirLoc); - + const VDatabase * d(0); // try to open sra file table as DB REQUIRE_RC_FAIL(VDBManagerOpenDB_FUNC_VPath(vdb, &d, 0, pathL)); REQUIRE_RC(Compare(pathL, tbLPath, &dirLoc)); - + // try to open sra file table as DB: cached dir REQUIRE_RC_FAIL(VDBManagerOpenDB_FUNC_VPath(vdb, &d, 0, pathL)); REQUIRE_RC(Compare(pathL, tbLPath)); @@ -749,14 +749,14 @@ FIXTURE_TEST_CASE(TestVDBManagerOpenDB_FUNC_VPath, Fixture) { // open remote run table as DB: cached dir REQUIRE_RC_FAIL(VDBManagerOpenDB_FUNC_VPath(vdb, &d, 0, pathR)); REQUIRE_RC(Compare(pathR, tbRPath)); - + // Set sra file's directory for remote run REQUIRE_RC(VPathSetDirectory(pathR, dirLoc)); const VTable * t(0); REQUIRE_RC(VDBManagerOpenTable_FUNC_VPath(vdb, &t, 0, pathR)); REQUIRE_RC(Compare(pathR, tbLPath)); REQUIRE_RC(VTableRelease(t)); - + REQUIRE(KDBManagerPathTypeVP(kdb, pathR) == kptTable); REQUIRE_RC(Compare(pathR, tbLPath)); /**/ @@ -836,18 +836,18 @@ FIXTURE_TEST_CASE(TestVDBManagerOpenTable_FUNC_VPath, Fixture) { REQUIRE_RC(VDBManagerOpenTable_FUNC_VPath(vdb, &t, 0, pathL)); REQUIRE_RC(Compare(pathL, tbLPath)); - REQUIRE_RC(VTableRelease(t)); - + REQUIRE_RC(VTableRelease(t)); + // open sra file table as table: cached dir REQUIRE_RC(VDBManagerOpenTable_FUNC_VPath(vdb, &t, 0, pathL)); REQUIRE_RC(Compare(pathL, tbLPath, &dirLoc)); REQUIRE_RC(VTableRelease(t)); - - REQUIRE_RC(VPathRelease(pathL)); + + REQUIRE_RC(VPathRelease(pathL)); VPath * pathR(0); REQUIRE_RC(LegacyVPathMake(&pathR, AccTR)); - + // open remote run table as table REQUIRE_RC(VDBManagerOpenTable_FUNC_VPath(vdb, &t, 0, pathR)); REQUIRE_RC(Compare(pathR, tbRPath)); @@ -877,7 +877,7 @@ FIXTURE_TEST_CASE(TestVDBManagerOpenTable_FUNC_VPath, Fixture) { REQUIRE_RC(KDirectoryRelease(dirLoc)); VPath * path(0); - + //////////////////////////////////////////////////////////////////////////// REQUIRE_RC(LegacyVPathMake(&path, AccTL)); @@ -943,7 +943,7 @@ FIXTURE_TEST_CASE(TestVDBManagerPathType, Fixture) { VPath * pathL(0); REQUIRE_RC(LegacyVPathMake(&pathL, AccTPath)); - + REQUIRE(VDBManagerPathTypeVP(0, pathL) == kptBadPath); const KDirectory * dirLoc(0); REQUIRE_RC(VPathGetDirectory(pathL, &dirLoc)); @@ -975,7 +975,7 @@ FIXTURE_TEST_CASE(TestVDBManagerPathType, Fixture) { REQUIRE_RC(KDirectoryRelease(dirLoc)); REQUIRE_RC(VPathRelease(pathL)); - + // reuse path for VDBManagerOpenTable_FUNC_VPath const VTable * vt(0); REQUIRE_RC(VDBManagerOpenTable_FUNC_VPath(vdb, &vt, 0, pathR)); @@ -991,7 +991,7 @@ FIXTURE_TEST_CASE(TestVDBManagerPathType, Fixture) { REQUIRE_RC(KTableRelease(kt)); REQUIRE_RC(VPathRelease(pathR)); - + VPath * path(0); //////////////////////////////////////////////////////////////////////////// @@ -1048,17 +1048,11 @@ FIXTURE_TEST_CASE(TestVDBManagerPathType, Fixture) { } #endif -extern "C" { - ver_t CC KAppVersion(void) { return 0; } - const char UsageDefaultName[] = "test-vpath-open"; - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage(const struct Args * args) { return 0; } - rc_t CC KMain(int argc, char * argv[]) { +int main(int argc, char * argv[]) { #if 0 - KDbgSetString("VFS"); + KDbgSetString("VFS"); #endif - return TestVpathOpenSuite(argc, argv); - } + return TestVpathOpenSuite(argc, argv); } /* diff --git a/test/vfs/test_VFS_cache_sdl.cpp b/test/vfs/test_VFS_cache_sdl.cpp index d7097147a..980279de8 100644 --- a/test/vfs/test_VFS_cache_sdl.cpp +++ b/test/vfs/test_VFS_cache_sdl.cpp @@ -38,7 +38,7 @@ #include // KThread -#include /* KMain */ +#include #include /* VPathGetDirectory */ #include /* VFSManager */ @@ -49,7 +49,8 @@ #include "../../libs/vdb/dbmgr-priv.h" // VDBManagerWhackStatic #include "../../libs/vfs/manager-priv.h" // VFSManagerSdlCacheEmpty -#include +#include +#include #include /* PATH_MAX */ #ifndef PATH_MAX @@ -130,10 +131,10 @@ class CachingFixture { } rc_t RemoteEquals(const char * path_str) const { - char path[4096](""); - rc_t rc(VPathReadUri(remote, path, sizeof path, NULL)); + char p[4096](""); + rc_t rc(VPathReadUri(remote, p, sizeof p, NULL)); if (rc == 0) - if (strcmp(path, path_str) != 0) + if (strcmp(p, path_str) != 0) rc = 115; return rc; @@ -190,17 +191,20 @@ FIXTURE_TEST_CASE(CountCaching, CachingFixture) { REQUIRE_NOT_NULL(remote); REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 1); - const KDirectory * dir(0); - REQUIRE_RC(VPathGetDirectory(query, &dir)); - REQUIRE_NULL(dir); - const KDBManager * kdb(0); - REQUIRE_RC(KDBManagerMakeReadWithVFSManager(&kdb, 0, mgr)); - REQUIRE(KDBManagerPathTypeVPath(kdb, query) == kptTable); - REQUIRE_RC(VPathGetDirectory(query, &dir)); - REQUIRE_NOT_NULL(dir); - REQUIRE_RC(VPathGetDirectory(query, &dir)); - REQUIRE_RC(KDirectoryRelease(dir)); - REQUIRE_RC(KDBManagerRelease(kdb)); + { + const KDirectory * dir(0); + REQUIRE_RC(VPathGetDirectory(query, &dir)); + REQUIRE_NULL(dir); + + const KDBManager * kdb(0); + REQUIRE_RC(KDBManagerMakeReadWithVFSManager(&kdb, 0, mgr)); + REQUIRE(KDBManagerPathTypeVPath(kdb, query) == kptTable); + REQUIRE_RC(VPathGetDirectory(query, &dir)); + REQUIRE_NOT_NULL(dir); + + REQUIRE_RC(KDirectoryRelease(dir)); + REQUIRE_RC(KDBManagerRelease(kdb)); + } REQUIRE_RC(QueryRemote(acc2)); REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 2); @@ -275,10 +279,10 @@ FIXTURE_TEST_CASE(ExpirationNotCaching, NotCachingFixture) { string json(MkSdlJson(acc, "http://a1/", 99)); // will expire in 99 seconds putenv((char*)json.c_str()); - + REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 0); REQUIRE_NULL(remote); - + REQUIRE_RC(QueryRemote(acc)); REQUIRE_RC(RemoteEquals("http://a1/")); REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 0); @@ -303,11 +307,11 @@ FIXTURE_TEST_CASE(ExpirationCaching, CachingFixture) { REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 0); REQUIRE_NULL(remote); - + REQUIRE_RC(QueryRemote(acc)); // not expired REQUIRE_RC(RemoteEquals("https://sra-pub-run-odp.s3.amazonaws.com/sra/SRR053325/SRR053325")); - + REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 1); json = MkSdlJson(acc, "https://ncbi.nlm.nih.gov/sos5/sra/SRR000/SRR000002"); putenv((char*)json.c_str()); @@ -349,14 +353,14 @@ FIXTURE_TEST_CASE(WgsNotCaching, NotCachingFixture) { REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 0); REQUIRE_NULL(remote); - + REQUIRE_RC(QueryRemote(acc)); REQUIRE_RC(RemoteEquals("http://a1/")); - + // use 2 SDL calls for the same WGS file when not caching REQUIRE_RC(QueryRemote(acc2)); REQUIRE_RC(RemoteEquals("http://a2/")); - + REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 0); } @@ -383,14 +387,16 @@ FIXTURE_TEST_CASE(WgsCaching, CachingFixture) { REQUIRE(VFSManagerSdlCacheCount(mgr, NULL) == 1); } -static rc_t DefaultWorkerThreadFn(const KThread * self, void * data) { +std::mutex mtx; +static rc_t DefaultWorkerThreadFn(const KThread * self, void * data) noexcept { CachingFixture * f((CachingFixture*)data); assert(f); rc_t rc(0); - for (int i = 0; i < 50 && rc == 0; ++i) { const VPath * remote(NULL); + + mtx.lock(); rc = VResolverRemote(f->resolver, 0, f->query, &remote); // if (rc != 0) int i = 0; @@ -399,11 +405,13 @@ static rc_t DefaultWorkerThreadFn(const KThread * self, void * data) { rc = VPathReadUri(remote, path, sizeof path, NULL); rc_t r2(VPathRelease(remote)); + mtx.unlock(); + remote = NULL; if (r2 != 0 && rc == 0) rc = r2; - ESdlCacheState state(eSCSEmpty); + uint32_t state(eSCSEmpty); VFSManagerSdlCacheCount(f->mgr, &state); if (state > eSCSFound) VFSManagerSdlCacheClear(f->mgr); @@ -468,15 +476,8 @@ FIXTURE_TEST_CASE(ThreadsNotCaching, NotCachingFixture) { } #endif -extern "C" { - const char UsageDefaultName[] = "Test_VFS_cache_sdl"; - rc_t CC UsageSummary(const char * progname) { return 0; } - rc_t CC Usage(const struct Args * args) { return 0; } - ver_t CC KAppVersion(void) { return 0; } - - rc_t CC KMain(int argc, char * argv[]) { +int main(int argc, char * argv[]) { if(0) { KDbgSetString("VFS"); } - KConfigDisableUserSettings(); - return Test_VFS_cache_sdlSuite(argc, argv); - } + KConfigDisableUserSettings(); + return Test_VFS_cache_sdlSuite(argc, argv); } diff --git a/test/vxf/VDB-2915.cpp b/test/vxf/VDB-2915.cpp index fe4276a98..e1ce0b29a 100644 --- a/test/vxf/VDB-2915.cpp +++ b/test/vxf/VDB-2915.cpp @@ -125,25 +125,25 @@ class WVDB_Fixture , m_tableName( "RANDOM_DATA" ), m_table( 0 ), m_cursor( 0 ) { THROW_ON_RC( KDirectoryNativeDir( &_wd ) ); - + const KDirectory * dir = NULL; THROW_ON_RC ( KDirectoryOpenDirRead ( _wd, &dir, false, "local_config" ) ); - + THROW_ON_RC( KConfigMake ( &_cfg, dir ) ); - + KConfigPrint( _cfg, 0 ); /* for test */ THROW_ON_RC( KDirectoryRelease( dir ) ); } - + ~WVDB_Fixture() { if ( m_cursor ) { VCursorRelease( m_cursor ); } if ( m_table ) { VTableRelease( m_table ); } if ( m_remove ) { RemoveTable(); } KConfigRelease( _cfg ); - KDirectoryRelease( _wd ); + KDirectoryRelease( _wd ); } void RemoveTable() @@ -160,11 +160,11 @@ class WVDB_Fixture struct VFSManager * vfs_mgr; THROW_ON_RC( VFSManagerMakeFromKfg ( &vfs_mgr, _cfg ) ); - + VDBManager * mgr; THROW_ON_RC ( VDBManagerMakeUpdateWithVFSManager ( &mgr, _wd, vfs_mgr ) ); - + VSchema *schema; THROW_ON_RC( VDBManagerMakeSchema ( mgr, &schema ) ); THROW_ON_RC( VSchemaParseText( schema, NULL, p_schemaText.c_str(), p_schemaText.size() ) ); @@ -193,7 +193,7 @@ class WVDB_Fixture THROW_ON_RC( VTableCreateCursorRead( m_table, ( const VCursor ** )&m_cursor ) ); THROW_ON_RC( VDBManagerRelease( mgr ) ); } - + bool m_remove; string m_tableName; VTable * m_table; @@ -208,7 +208,7 @@ class WVDB_Fixture FIXTURE_TEST_CASE ( LOAD_RANDOM_DATA, WVDB_Fixture ) { RemoveTable(); - + string schemaText = "version 1;" "include 'vdb/vdb.vschema';" "table A_TABLE #1.0" @@ -221,9 +221,9 @@ FIXTURE_TEST_CASE ( LOAD_RANDOM_DATA, WVDB_Fixture ) " column U32 RU3;" " column < U64 > izip_encoding CU4;" " column U64 RU4;" - + " column < I8 > izip_encoding CI1;" - " column I8 RI1;" + " column I8 RI1;" " column < I16 > izip_encoding CI2;" " column I16 RI2;" " column < I32 > izip_encoding CI3;" @@ -233,9 +233,9 @@ FIXTURE_TEST_CASE ( LOAD_RANDOM_DATA, WVDB_Fixture ) "};"; REQUIRE_RC( KOutMsg( "creating table '%s'\n", m_tableName.c_str() ) ); - + MakeTable ( schemaText, "A_TABLE" ); - + uint32_t cu1, cu2, cu3 /*, cu4 */; uint32_t ru1, ru2, ru3 /*, ru4 */; @@ -263,19 +263,19 @@ FIXTURE_TEST_CASE ( LOAD_RANDOM_DATA, WVDB_Fixture ) REQUIRE_RC ( VCursorOpen ( m_cursor ) ); srand( 123456 ); - + size_t i, j; for ( i = 1; i <= 512; ++i ) { REQUIRE_RC ( VCursorOpenRow ( m_cursor ) ); - + { uint8_t b[ 1024 ]; - for ( j = 0; j < 1024; ++j ) b[ j ] = rand() & 0xFF; + for ( j = 0; j < 1024; ++j ) b[ j ] = (uint8_t) ( rand() & 0xFF ); REQUIRE_RC ( VCursorWrite ( m_cursor, cu1, 8, b, 0, 1024 ) ); REQUIRE_RC ( VCursorWrite ( m_cursor, ru1, 8, b, 0, 1024 ) ); } - + { int8_t b[ 1024 ]; for ( j = 0; j < 1024; ++j ) b[ j ] = rand() & 0xFF; @@ -285,7 +285,7 @@ FIXTURE_TEST_CASE ( LOAD_RANDOM_DATA, WVDB_Fixture ) { uint16_t b[ 1024 ]; - for ( j = 0; j < 1024; ++j ) b[ j ] = rand() & 0xFFFF; + for ( j = 0; j < 1024; ++j ) b[ j ] = (uint16_t)( rand() & 0xFFFF ); REQUIRE_RC ( VCursorWrite ( m_cursor, cu2, 16, b, 0, 1024 ) ); REQUIRE_RC ( VCursorWrite ( m_cursor, ru2, 16, b, 0, 1024 ) ); } @@ -299,11 +299,11 @@ FIXTURE_TEST_CASE ( LOAD_RANDOM_DATA, WVDB_Fixture ) { uint32_t b[ 1024 ]; - for ( j = 0; j < 1024; ++j ) b[ j ] = rand(); + for ( j = 0; j < 1024; ++j ) b[ j ] = (uint32_t) rand(); REQUIRE_RC ( VCursorWrite ( m_cursor, cu3, 32, b, 0, 1024 ) ); REQUIRE_RC ( VCursorWrite ( m_cursor, ru3, 32, b, 0, 1024 ) ); } - + { int32_t b[ 1024 ]; for ( j = 0; j < 1024; ++j ) b[ j ] = rand_int32(); @@ -326,7 +326,7 @@ FIXTURE_TEST_CASE ( LOAD_RANDOM_DATA, WVDB_Fixture ) REQUIRE_RC ( VCursorWrite ( m_cursor, ri4, 64, b, 0, 1024 ) ); } */ - + REQUIRE_RC ( VCursorCommitRow ( m_cursor ) ); REQUIRE_RC ( VCursorCloseRow ( m_cursor ) ); } @@ -338,7 +338,7 @@ FIXTURE_TEST_CASE ( CHECK_RANDOM_DATA, WVDB_Fixture ) OpenTable(); REQUIRE_RC( KOutMsg( "verify table '%s'\n", m_tableName.c_str() ) ); - + uint32_t cu1, cu2, cu3 /*, cu4 */; uint32_t ru1, ru2, ru3 /*, ru4 */; REQUIRE_RC ( VCursorAddColumn ( m_cursor, &cu1, "%s", "CU1" ) ); @@ -362,7 +362,7 @@ FIXTURE_TEST_CASE ( CHECK_RANDOM_DATA, WVDB_Fixture ) /* REQUIRE_RC ( VCursorAddColumn ( m_cursor, &ri4, "%s", "RI4" ) ); */ REQUIRE_RC ( VCursorOpen ( m_cursor ) ); - + for ( int64_t i = 1; i <= 512; ++i ) { uint32_t c_bits, r_bits, c_boff, r_boff, c_len, r_len; @@ -393,7 +393,7 @@ FIXTURE_TEST_CASE ( CHECK_RANDOM_DATA, WVDB_Fixture ) REQUIRE_EQ ( r_len, ( uint32_t )1024 ); REQUIRE ( std::equal( c, c + 1024, r ) ); } - + { uint16_t * c; uint16_t * r; @@ -407,7 +407,7 @@ FIXTURE_TEST_CASE ( CHECK_RANDOM_DATA, WVDB_Fixture ) REQUIRE_EQ ( r_len, ( uint32_t )1024 ); REQUIRE ( std::equal( c, c + 1024, r ) ); } - + { int16_t * c; int16_t * r; @@ -480,29 +480,14 @@ FIXTURE_TEST_CASE ( CHECK_RANDOM_DATA, WVDB_Fixture ) } */ } - + m_remove = true; } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) { return 0x1000000; } -rc_t CC UsageSummary ( const char * progname ) { return 0; } -rc_t CC Usage ( const Args * args ){ return 0; } - -const char UsageDefaultName[] = "vdb_2915_testwb-test-vxf"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc = VDB_2915_TEST_SUITE( argc, argv ); - return rc; -} - + return VDB_2915_TEST_SUITE( argc, argv ); } diff --git a/test/vxf/wb-test-vxf.cpp b/test/vxf/wb-test-vxf.cpp index 6711998b2..5b77130ac 100644 --- a/test/vxf/wb-test-vxf.cpp +++ b/test/vxf/wb-test-vxf.cpp @@ -26,6 +26,8 @@ #include +#include + TEST_SUITE(VxfTestSuite); #include "wb-irzip-impl.h" @@ -65,15 +67,15 @@ class EncoderFixture FIXTURE_TEST_CASE(IRZIP_u64_assert1, EncoderFixture) { uint64_t y[]={ - UINT64_C(353878216), - UINT64_C(353878152), - UINT64_C(353877873), - UINT64_C(353877162), - UINT64_C(353876785), - UINT64_C(353875727), - UINT64_C(353874605), - UINT64_C(353873979), - UINT64_C(353873604), + UINT64_C(353878216), + UINT64_C(353878152), + UINT64_C(353877873), + UINT64_C(353877162), + UINT64_C(353876785), + UINT64_C(353875727), + UINT64_C(353874605), + UINT64_C(353873979), + UINT64_C(353873604), UINT64_C(353872503) }; uint64_t decoded[ARR_SIZE(y)]; @@ -86,15 +88,15 @@ FIXTURE_TEST_CASE(IRZIP_u64_assert1, EncoderFixture) FIXTURE_TEST_CASE(IRZIP_u64_assert2, EncoderFixture) { uint64_t y[]={ - UINT64_C(353878216), - UINT64_C(353878152), - UINT64_C( 0), - UINT64_C( 0), - UINT64_C( 0), - UINT64_C( 0), - UINT64_C( 0), - UINT64_C( 0), - UINT64_C( 0), + UINT64_C(353878216), + UINT64_C(353878152), + UINT64_C( 0), + UINT64_C( 0), + UINT64_C( 0), + UINT64_C( 0), + UINT64_C( 0), + UINT64_C( 0), + UINT64_C( 0), UINT64_C( 0) }; uint64_t decoded[ARR_SIZE(y)]; @@ -107,15 +109,15 @@ FIXTURE_TEST_CASE(IRZIP_u64_assert2, EncoderFixture) FIXTURE_TEST_CASE(IRZIP_u32_assert1, EncoderFixture) { uint32_t y[]={ - 78216, - 78152, - 77873, - 77162, - 76785, - 75727, - 74605, - 73979, - 73604, + 78216, + 78152, + 77873, + 77162, + 76785, + 75727, + 74605, + 73979, + 73604, 72503 }; uint32_t decoded[ARR_SIZE(y)]; @@ -128,15 +130,15 @@ FIXTURE_TEST_CASE(IRZIP_u32_assert1, EncoderFixture) FIXTURE_TEST_CASE(IRZIP_u32_assert2, EncoderFixture) { uint32_t y[]={ - 78216, - 78152, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + 78216, + 78152, + 0, + 0, + 0, + 0, + 0, + 0, + 0, 0 }; uint32_t decoded[ARR_SIZE(y)]; @@ -197,15 +199,15 @@ FIXTURE_TEST_CASE(IRZIP_u64_assert4, EncoderFixture) FIXTURE_TEST_CASE(IRZIP_i64_assert1, EncoderFixture) { int64_t y[]={ - INT64_C( 353878216), - INT64_C(-353878152), - INT64_C( 353877873), - INT64_C(-353877162), - INT64_C(-353876785), - INT64_C( 353875727), - INT64_C(-353874605), - INT64_C( 353873979), - INT64_C(-353873604), + INT64_C( 353878216), + INT64_C(-353878152), + INT64_C( 353877873), + INT64_C(-353877162), + INT64_C(-353876785), + INT64_C( 353875727), + INT64_C(-353874605), + INT64_C( 353873979), + INT64_C(-353873604), INT64_C( 353872503) }; int64_t decoded[ARR_SIZE(y)]; @@ -218,15 +220,15 @@ FIXTURE_TEST_CASE(IRZIP_i64_assert1, EncoderFixture) FIXTURE_TEST_CASE(IRZIP_i32_assert1, EncoderFixture) { int32_t y[]={ - 78216, - 78152, - -77873, - -77162, - -76785, - 75727, - 74605, - -73979, - -73604, + 78216, + 78152, + -77873, + -77162, + -76785, + 75727, + 74605, + -73979, + -73604, 72503 }; int32_t decoded[ARR_SIZE(y)]; @@ -236,33 +238,8 @@ FIXTURE_TEST_CASE(IRZIP_i32_assert1, EncoderFixture) } //////////////////////////////////////////// Main -extern "C" -{ - -#include -#include - -ver_t CC KAppVersion ( void ) -{ - return 0x1000000; -} -rc_t CC UsageSummary (const char * progname) -{ - return 0; -} - -rc_t CC Usage ( const Args * args ) -{ - return 0; -} - -const char UsageDefaultName[] = "wb-test-vxf"; - -rc_t CC KMain ( int argc, char *argv [] ) +int main ( int argc, char *argv [] ) { KConfigDisableUserSettings(); - rc_t rc=VxfTestSuite(argc, argv); - return rc; -} - + return VxfTestSuite(argc, argv); }