diff --git a/test/define.yaml b/test/define.yaml index 9809a476b..a447f0e62 100644 --- a/test/define.yaml +++ b/test/define.yaml @@ -10,7 +10,6 @@ # Most options can be set for modules and tests (test option will override module option if both are set): # * db - determines if the test will be run against multiple db versions # * define - defines for C code (will also be applied to the test harness) -# * define-test - defines for the test harness # * debugUnitSuppress - don't define DEBUG_UNIT for unit tests -- this is used to test unit test debugging macros # * binReq - is the pgbackrest binary required for this test? # * containerReq - is this test required to run in a container? @@ -19,6 +18,13 @@ # * coverage - a list of code modules that the test provides coverage for. A code module may be covered by multiple tests. That # means you must run all the tests by providing the --run option multiple times to get full coverage on the code module. If # a code module contains only data it should be marked noCode (e.g. - help/help.auto.c: noCode). +# * feature - Defines a feature that is now available in the harness. For example, the "error" feature defines HRN_FEATURE_ERROR +# used to automatically check for errors in later tests. The common/error test is not able to access this error handling +# because it is used to implement the error handling, so it must do error testing in a more primitive way. +# * harness - Adds a harness module that contains functions to aid in testing. For example, the "log" harness includes the +# common/harnessLog module to aid in expect log testing. +# * depend - Source modules that this test depends on that have not already been included in prior tests via coverage. Ideally +# this option would never be used because it is essentially documenting cross-dependencies in the code. # * total - total runs in the test # * vm - VMs that the test will be run on # * include - modules to include directly into test.c (all files in coverage are automatically included) @@ -37,107 +43,67 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: error total: 8 - define-test: -DNO_ERROR -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT + feature: error coverage: - common/error - common/error.auto: noCode - # ---------------------------------------------------------------------------------------------------------------------------- - - name: assert-on - total: 1 - define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT - - coverage: - - common/assert: noCode - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: assert-off - total: 1 - define: -DNDEBUG - define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT - debugUnitSuppress: true - - coverage: - - common/assert: noCode + depend: + - common/debug + - common/type/convert + - common/memContext + - common/stackTrace + - common/type/buffer + - common/type/keyValue + - common/type/list + - common/type/string + - common/type/stringList + - common/type/variant + - common/type/variantList # ---------------------------------------------------------------------------------------------------------------------------- - name: stack-trace total: 4 - define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT coverage: - common/stackTrace # ---------------------------------------------------------------------------------------------------------------------------- - - name: mem-context - total: 7 - define-test: -DNO_MEM_CONTEXT -DNO_LOG -DNO_STAT - - coverage: - - common/memContext - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: time - total: 3 - define-test: -DNO_ERROR -DNO_LOG - - coverage: - - common/time - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: fork + - name: assert-off total: 1 - define-test: -DNO_LOG + define: -DNDEBUG + debugUnitSuppress: true coverage: - - common/fork - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: log - total: 5 - define-test: -DNO_LOG - - coverage: - - common/log + - common/assert: noCode # ---------------------------------------------------------------------------------------------------------------------------- - name: debug-off total: 2 define: -DNDEBUG - define-test: -DNO_LOG debugUnitSuppress: true coverage: - common/debug # ---------------------------------------------------------------------------------------------------------------------------- - - name: debug-on - total: 4 - - coverage: - - common/debug - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: lock - total: 2 - - coverage: - - common/lock - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: exit - total: 3 - - coverage: - - common/exit - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: wait + - name: assert-on total: 1 coverage: - - common/wait + - common/assert: noCode + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: mem-context + total: 7 + feature: memContext + + coverage: + - common/memContext + + depend: + - common/type/convert # ---------------------------------------------------------------------------------------------------------------------------- - name: type-convert @@ -147,11 +113,20 @@ unit: - common/type/convert # ---------------------------------------------------------------------------------------------------------------------------- - - name: type-object - total: 1 + - name: time + total: 3 coverage: - - common/type/object: noCode + - common/time + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: type-string + total: 26 + feature: string + + coverage: + - common/type/string + - common/type/stringList # ---------------------------------------------------------------------------------------------------------------------------- - name: type-list @@ -160,14 +135,6 @@ unit: coverage: - common/type/list - # ---------------------------------------------------------------------------------------------------------------------------- - - name: type-string - total: 26 - - coverage: - - common/type/string - - common/type/stringList - # ---------------------------------------------------------------------------------------------------------------------------- - name: type-buffer total: 6 @@ -184,11 +151,49 @@ unit: - common/type/variantList # ---------------------------------------------------------------------------------------------------------------------------- - - name: type-pack + - name: reg-exp + total: 3 + + coverage: + - common/regExp + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: log + total: 5 + feature: log + harness: log + + coverage: + - common/log + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: debug-on + total: 4 + feature: debug + + coverage: + - common/debug + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: fork total: 1 coverage: - - common/type/pack + - common/fork + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: wait + total: 1 + + coverage: + - common/wait + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: type-object + total: 1 + + coverage: + - common/type/object: noCode # ---------------------------------------------------------------------------------------------------------------------------- - name: type-mcv @@ -221,6 +226,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: stat total: 1 + feature: STAT coverage: - common/stat @@ -251,9 +257,29 @@ unit: - common/io/read - common/io/write + # ---------------------------------------------------------------------------------------------------------------------------- + - name: type-pack + total: 1 + harness: pack + + coverage: + - common/type/pack + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: crypto + total: 3 + + coverage: + - common/crypto/cipherBlock + - common/crypto/common + - common/crypto/hash + - common/crypto/md5.vendor + # ---------------------------------------------------------------------------------------------------------------------------- - name: io-tls total: 5 + feature: SOCKET + harness: server coverage: - common/io/client @@ -281,6 +307,36 @@ unit: - common/io/http/response - common/io/http/session + # ---------------------------------------------------------------------------------------------------------------------------- + - name: exec + total: 1 + + coverage: + - common/exec + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: encode + total: 1 + + coverage: + - common/encode + - common/encode/base64 + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: ini + total: 4 + + coverage: + - common/ini + + depend: + - storage/posix/read + - storage/posix/storage + - storage/posix/write + - storage/read + - storage/storage + - storage/write + # ---------------------------------------------------------------------------------------------------------------------------- - name: compress total: 5 @@ -301,43 +357,60 @@ unit: - common/compress/helper # ---------------------------------------------------------------------------------------------------------------------------- - - name: crypto + - name: exit total: 3 + harness: config coverage: - - common/crypto/cipherBlock - - common/crypto/common - - common/crypto/hash - - common/crypto/md5.vendor + - common/exit + + depend: + - command/backup/pageChecksum + - common/lock + - config/config + - config/parse + - config/exec + - config/load + - config/protocol + - command/command + - postgres/interface + - postgres/interface/page + - postgres/interface/v083 + - postgres/interface/v084 + - postgres/interface/v090 + - postgres/interface/v091 + - postgres/interface/v092 + - postgres/interface/v093 + - postgres/interface/v094 + - postgres/interface/v095 + - postgres/interface/v096 + - postgres/interface/v100 + - postgres/interface/v110 + - postgres/interface/v120 + - postgres/interface/v130 + - protocol/client + - protocol/command + - protocol/helper + - protocol/server + - storage/azure/read + - storage/azure/storage + - storage/azure/write + - storage/cifs/storage + - storage/helper + - storage/remote/read + - storage/remote/protocol + - storage/remote/storage + - storage/remote/write + - storage/s3/read + - storage/s3/storage + - storage/s3/write # ---------------------------------------------------------------------------------------------------------------------------- - - name: exec - total: 1 + - name: lock + total: 2 coverage: - - common/exec - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: encode - total: 1 - - coverage: - - common/encode - - common/encode/base64 - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: reg-exp - total: 3 - - coverage: - - common/regExp - - # ---------------------------------------------------------------------------------------------------------------------------- - - name: ini - total: 4 - - coverage: - - common/ini + - common/lock # ******************************************************************************************************************************** - name: postgres @@ -346,6 +419,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: client total: 1 + harness: pq coverage: - postgres/client @@ -403,6 +477,21 @@ unit: - name: storage test: + # ---------------------------------------------------------------------------------------------------------------------------- + - name: posix + total: 21 + feature: STORAGE + harness: storage + + coverage: + - storage/posix/read + - storage/posix/storage + - storage/posix/write + - storage/helper + - storage/read + - storage/storage + - storage/write + # ---------------------------------------------------------------------------------------------------------------------------- - name: azure total: 3 @@ -429,19 +518,6 @@ unit: include: - storage/storage - # ---------------------------------------------------------------------------------------------------------------------------- - - name: posix - total: 21 - - coverage: - - storage/posix/read - - storage/posix/storage - - storage/posix/write - - storage/helper - - storage/read - - storage/storage - - storage/write - # ---------------------------------------------------------------------------------------------------------------------------- - name: remote total: 9 @@ -502,6 +578,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: info total: 3 + harness: info coverage: - info/info @@ -520,13 +597,6 @@ unit: coverage: - info/infoArchive - # ---------------------------------------------------------------------------------------------------------------------------- - - name: info-backup - total: 3 - - coverage: - - info/infoBackup - # ---------------------------------------------------------------------------------------------------------------------------- - name: manifest total: 6 @@ -534,6 +604,16 @@ unit: coverage: - info/manifest + depend: + - command/backup/common + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: info-backup + total: 3 + + coverage: + - info/infoBackup + # ******************************************************************************************************************************** - name: db @@ -553,6 +633,15 @@ unit: - name: command test: + # ---------------------------------------------------------------------------------------------------------------------------- + - name: control + total: 3 + + coverage: + - command/control/common + - command/control/start + - command/control/stop + # ---------------------------------------------------------------------------------------------------------------------------- - name: archive-common total: 9 @@ -583,28 +672,17 @@ unit: - command/archive/push/push # ---------------------------------------------------------------------------------------------------------------------------- - - name: backup-common - total: 3 + - name: stanza + total: 4 coverage: - - command/backup/common - - command/backup/pageChecksum + - command/stanza/common + - command/stanza/create + - command/stanza/upgrade + - command/stanza/delete - # ---------------------------------------------------------------------------------------------------------------------------- - - name: backup - total: 10 - binReq: true - - coverage: - - command/backup/backup - - command/backup/common - - command/backup/file - - command/backup/protocol - - include: - - info/info - - info/manifest - - storage/storage + depend: + - command/check/common # ---------------------------------------------------------------------------------------------------------------------------- - name: check @@ -622,15 +700,6 @@ unit: coverage: - command/command - # ---------------------------------------------------------------------------------------------------------------------------- - - name: control - total: 3 - - coverage: - - command/control/common - - command/control/start - - command/control/stop - # ---------------------------------------------------------------------------------------------------------------------------- - name: expire total: 8 @@ -656,13 +725,6 @@ unit: coverage: - command/info/info - # ---------------------------------------------------------------------------------------------------------------------------- - - name: local - total: 1 - - coverage: - - command/local/local - # ---------------------------------------------------------------------------------------------------------------------------- - name: remote total: 1 @@ -686,14 +748,28 @@ unit: - info/manifest # ---------------------------------------------------------------------------------------------------------------------------- - - name: stanza - total: 4 + - name: backup-common + total: 3 coverage: - - command/stanza/common - - command/stanza/create - - command/stanza/upgrade - - command/stanza/delete + - command/backup/common + - command/backup/pageChecksum + + # ---------------------------------------------------------------------------------------------------------------------------- + - name: backup + total: 10 + binReq: true + + coverage: + - command/backup/backup + - command/backup/common + - command/backup/file + - command/backup/protocol + + include: + - info/info + - info/manifest + - storage/storage # ---------------------------------------------------------------------------------------------------------------------------- - name: repo @@ -720,6 +796,13 @@ unit: - command/verify/protocol - command/verify/verify + # ---------------------------------------------------------------------------------------------------------------------------- + - name: local + total: 1 + + coverage: + - command/local/local + # ********************************************************************************************************************************** # Integration tests # diff --git a/test/lib/pgBackRestTest/Common/DefineTest.pm b/test/lib/pgBackRestTest/Common/DefineTest.pm index a69c2c30c..798027d95 100644 --- a/test/lib/pgBackRestTest/Common/DefineTest.pm +++ b/test/lib/pgBackRestTest/Common/DefineTest.pm @@ -39,22 +39,27 @@ use constant TESTDEF_TEST => 'test'; use constant TESTDEF_DB => 'db'; push @EXPORT, qw(TESTDEF_DB); +use constant TESTDEF_DEPEND => 'depend'; use constant TESTDEF_CONTAINER => 'container'; push @EXPORT, qw(TESTDEF_CONTAINER); use constant TESTDEF_CONTAINER_REQUIRED => 'containerReq'; push @EXPORT, qw(TESTDEF_CONTAINER_REQUIRED); use constant TESTDEF_COVERAGE => 'coverage'; push @EXPORT, qw(TESTDEF_COVERAGE); +use constant TESTDEF_CORE => 'core'; + push @EXPORT, qw(TESTDEF_CORE); use constant TESTDEF_EXPECT => 'expect'; push @EXPORT, qw(TESTDEF_EXPECT); use constant TESTDEF_C => 'c'; push @EXPORT, qw(TESTDEF_C); use constant TESTDEF_DEFINE => 'define'; push @EXPORT, qw(TESTDEF_DEFINE); -use constant TESTDEF_DEFINE_TEST => 'define-test'; - push @EXPORT, qw(TESTDEF_DEFINE_TEST); +use constant TESTDEF_FEATURE => 'feature'; + push @EXPORT, qw(TESTDEF_FEATURE); use constant TESTDEF_DEBUG_UNIT_SUPPRESS => 'debugUnitSuppress'; push @EXPORT, qw(TESTDEF_DEBUG_UNIT_SUPPRESS); +use constant TESTDEF_HARNESS => 'harness'; + push @EXPORT, qw(TESTDEF_HARNESS); use constant TESTDEF_INCLUDE => 'include'; push @EXPORT, qw(TESTDEF_INCLUDE); use constant TESTDEF_INDIVIDUAL => 'individual'; @@ -92,6 +97,15 @@ sub testDefLoad my $hTestDef = Load($strDefineYaml); + # Keep a list of all harnesses added so far. These will make up the harness list for subsequent tests. + my @stryHarnessFile = (); + + # Keep a list of all modules added for coverage so far. These will make up the core list for subsequent tests. + my @stryCoreFile = (); + + # Keep a list of modules that are test before this one so we know what is available + my $strTestDefine = ''; + # Iterate each test type foreach my $strModuleType (TESTDEF_UNIT, TESTDEF_INTEGRATION, TESTDEF_PERFORMANCE) { @@ -126,7 +140,7 @@ sub testDefLoad # Resolve variables that can be set in the module or the test foreach my $strVar ( - TESTDEF_DEFINE, TESTDEF_DEFINE_TEST, TESTDEF_DEBUG_UNIT_SUPPRESS, TESTDEF_DB, TESTDEF_BIN_REQ, TESTDEF_VM, + TESTDEF_DEFINE, TESTDEF_DEBUG_UNIT_SUPPRESS, TESTDEF_DB, TESTDEF_BIN_REQ, TESTDEF_VM, TESTDEF_CONTAINER_REQUIRED) { $hTestDefHash->{$strModule}{$strTest}{$strVar} = coalesce( @@ -148,6 +162,41 @@ sub testDefLoad $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_CONTAINER} = $bContainer; $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INDIVIDUAL} = $bIndividual; + if (!$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INTEGRATION}) + { + # Add depends to core files + if (defined($hModuleTest->{&TESTDEF_DEPEND})) + { + foreach my $strDepend (@{$hModuleTest->{&TESTDEF_DEPEND}}) + { + if (!grep(/$strDepend/i, @stryCoreFile)) + { + push(@stryCoreFile, $strDepend); + } + } + } + + # Add core files + push(@{$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_CORE}}, @stryCoreFile); + + # Add harness files + if (defined($hModuleTest->{&TESTDEF_HARNESS})) + { + push(@stryHarnessFile, $hModuleTest->{&TESTDEF_HARNESS}); + } + + push(@{$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_HARNESS}}, @stryHarnessFile); + + # Add test defines + $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_FEATURE} = $strTestDefine; + + if (defined($hModuleTest->{&TESTDEF_FEATURE})) + { + $strTestDefine .= + ($strTestDefine eq '' ? '' : ' ') . "-DHRN_FEATURE_" . uc($hModuleTest->{&TESTDEF_FEATURE}); + } + } + # Set test count $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_TOTAL} = $hModuleTest->{&TESTDEF_TOTAL}; @@ -190,10 +239,21 @@ sub testDefLoad # Add to coverage list push(@{$hCoverageList->{$strCodeModule}}, {strModule=> $strModule, strTest => $strTest}); + + # Check if this module is already in the core list + if (!$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INTEGRATION} && !grep(/^$strCodeModule$/i, @stryCoreFile)) + { + push(@stryCoreFile, $strCodeModule); + } } # Set include list - $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INCLUDE} = $hModuleTest->{&TESTDEF_INCLUDE}; + @{$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INCLUDE}} = (); + + if (defined($hModuleTest->{&TESTDEF_INCLUDE})) + { + push(@{$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INCLUDE}}, @{$hModuleTest->{&TESTDEF_INCLUDE}}); + } } $hModuleTest->{$strModule} = \@stryModuleTest; diff --git a/test/lib/pgBackRestTest/Common/JobTest.pm b/test/lib/pgBackRestTest/Common/JobTest.pm index 67a5ee540..c7b6a03aa 100644 --- a/test/lib/pgBackRestTest/Common/JobTest.pm +++ b/test/lib/pgBackRestTest/Common/JobTest.pm @@ -343,38 +343,33 @@ sub run # Generate list of harness files # ------------------------------------------------------------------------------------------------------------------ + my $hTest = (testDefModuleTest($self->{oTest}->{&TEST_MODULE}, $self->{oTest}->{&TEST_NAME})); my $strRepoCopyTestSrcHarnessPath = $strRepoCopyTestSrcPath . '/common'; - my @stryHarnessFile; + my @stryHarnessFile = ('common/harnessTest'); - foreach my $strFile (sort(keys(%{$self->{oStorageTest}->manifest($strRepoCopyTestSrcHarnessPath)}))) + foreach my $strFile (@{$hTest->{&TESTDEF_HARNESS}}) { - # Skip . and header files - next if $strFile eq '.' || $strFile =~ /\.h$/; - - push(@stryHarnessFile, "common/" . substr($strFile, 0, length($strFile) - 2)); + push(@stryHarnessFile, "common/harness" . ucfirst($strFile)); } # Generate list of core files (files to be tested/included in this unit will be excluded) # ------------------------------------------------------------------------------------------------------------------ - my $hTest = (testDefModuleTest($self->{oTest}->{&TEST_MODULE}, $self->{oTest}->{&TEST_NAME})); my $hTestCoverage = $hTest->{&TESTDEF_COVERAGE}; my @stryCoreFile; - foreach my $strFile (sort(keys(%{$self->{oStorageTest}->manifest($strRepoCopySrcPath)}))) + foreach my $strFile (@{$hTest->{&TESTDEF_CORE}}) { - my $strFileNoExt = substr($strFile, 0, length($strFile) - 2); - # Skip all files except .c files (including .auto.c and .vendor.c) - next if $strFile !~ /(?{oStorageTest}->exists("${strRepoCopySrcPath}/${strFile}.c"); - if (!defined($hTestCoverage->{$strFileNoExt}) && !grep(/^$strFileNoExt$/, @{$hTest->{&TESTDEF_INCLUDE}})) + if (!defined($hTestCoverage->{$strFile}) && !grep(/^$strFile$/, @{$hTest->{&TESTDEF_INCLUDE}})) { - push(@stryCoreFile, "${strFileNoExt}"); + push(@stryCoreFile, $strFile); } } @@ -386,7 +381,7 @@ sub run "\n" . "SRCS = test.c \\\n" . "\t" . join('.c ', @stryHarnessFile) . ".c \\\n" . - "\t" . join('.c ', @stryCoreFile) . ".c\n" . + (@stryCoreFile > 0 ? "\t" . join('.c ', @stryCoreFile) . ".c\n" : ''). "\n" . ".build/test.o: CFLAGS += \$(CFLAGS_TEST)\n" . "\n" . diff --git a/test/lib/pgBackRestTest/Common/ListTest.pm b/test/lib/pgBackRestTest/Common/ListTest.pm index 958b8c0e7..d548fb9ac 100644 --- a/test/lib/pgBackRestTest/Common/ListTest.pm +++ b/test/lib/pgBackRestTest/Common/ListTest.pm @@ -171,7 +171,7 @@ sub testListGet &TEST_VM => $strTestOS, &TEST_C => coalesce($hTest->{&TESTDEF_C}, $hModule->{&TESTDEF_C}, false), &TEST_CDEF => $hTest->{&TESTDEF_DEFINE}, - &TEST_CTESTDEF => $hTest->{&TESTDEF_DEFINE_TEST}, + &TEST_CTESTDEF => $hTest->{&TESTDEF_FEATURE}, &TEST_DEBUG_UNIT_SUPPRESS => $hTest->{&TEST_DEBUG_UNIT_SUPPRESS}, &TEST_CONTAINER => defined($hTest->{&TESTDEF_CONTAINER}) ? $hTest->{&TESTDEF_CONTAINER} : $hModule->{&TESTDEF_CONTAINER}, diff --git a/test/src/common/harnessConfig.c b/test/src/common/harnessConfig.c index e5d7a4f4f..8943a69fb 100644 --- a/test/src/common/harnessConfig.c +++ b/test/src/common/harnessConfig.c @@ -37,7 +37,7 @@ harnessCfgLoadRaw(unsigned int argListSize, const char *argList[]) // Set dry-run mode for storage and logging storageHelperDryRunInit(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun)); -#ifndef NO_LOG +#ifdef HRN_FEATURE_STORAGE harnessLogDryRunSet(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun)); #endif diff --git a/test/src/common/harnessDebug.h b/test/src/common/harnessDebug.h index f9ddb5aad..0a3168ce5 100644 --- a/test/src/common/harnessDebug.h +++ b/test/src/common/harnessDebug.h @@ -4,22 +4,7 @@ C Debug Harness #ifndef TEST_COMMON_HARNESS_DEBUG_H #define TEST_COMMON_HARNESS_DEBUG_H -#ifdef NO_STACK_TRACE - #define FUNCTION_HARNESS_INIT(exe) - #define FUNCTION_HARNESS_STACK_TRACE_LINE_SET(lineNo) - #define FUNCTION_HARNESS_BEGIN() - #define FUNCTION_HARNESS_PARAM(typeMacroPrefix, param) - #define FUNCTION_HARNESS_PARAM_P(typeMacroPrefix, param) - #define FUNCTION_HARNESS_PARAM_PP(typeMacroPrefix, param) - #define FUNCTION_HARNESS_END() - #define FUNCTION_HARNESS_VOID() - #define FUNCTION_HARNESS_ASSERT(condition) - - #define FUNCTION_HARNESS_RESULT(typeMacroPrefix, result) \ - return result - - #define FUNCTION_HARNESS_RESULT_VOID(); -#else +#ifdef HRN_FEATURE_DEBUG #include "common/debug.h" #ifdef WITH_BACKTRACE @@ -75,6 +60,21 @@ C Debug Harness #define FUNCTION_HARNESS_RESULT_VOID() \ STACK_TRACE_POP(false); +#else + #define FUNCTION_HARNESS_INIT(exe) + #define FUNCTION_HARNESS_STACK_TRACE_LINE_SET(lineNo) + #define FUNCTION_HARNESS_BEGIN() + #define FUNCTION_HARNESS_PARAM(typeMacroPrefix, param) + #define FUNCTION_HARNESS_PARAM_P(typeMacroPrefix, param) + #define FUNCTION_HARNESS_PARAM_PP(typeMacroPrefix, param) + #define FUNCTION_HARNESS_END() + #define FUNCTION_HARNESS_VOID() + #define FUNCTION_HARNESS_ASSERT(condition) + + #define FUNCTION_HARNESS_RESULT(typeMacroPrefix, result) \ + return result + + #define FUNCTION_HARNESS_RESULT_VOID(); #endif #endif diff --git a/test/src/common/harnessFork.h b/test/src/common/harnessFork.h index bd89ece64..91e785c7e 100644 --- a/test/src/common/harnessFork.h +++ b/test/src/common/harnessFork.h @@ -38,8 +38,6 @@ There should not be any code outside the HARNESS_FORK_CHILD_BEGIN/END() and HARN #include #include -#include - #include /*********************************************************************************************************************************** @@ -137,7 +135,7 @@ Create a child process "unable to create write pipe for child process %u", HARNESS_FORK_PROCESS_TOTAL()); \ } \ \ - HARNESS_FORK_PROCESS_ID(HARNESS_FORK_PROCESS_TOTAL()) = forkSafe(); \ + HARNESS_FORK_PROCESS_ID(HARNESS_FORK_PROCESS_TOTAL()) = fork(); \ \ if (HARNESS_FORK_PROCESS_ID(HARNESS_FORK_PROCESS_TOTAL()) == 0) \ { \ diff --git a/test/src/common/harnessLog.c b/test/src/common/harnessLog.c index a61c0c1f6..19699be11 100644 --- a/test/src/common/harnessLog.c +++ b/test/src/common/harnessLog.c @@ -15,8 +15,6 @@ Log Test Harness #include "common/harnessDebug.h" #include "common/harnessTest.h" -#ifndef NO_LOG - /*********************************************************************************************************************************** Expose log internal data for unit testing/debugging ***********************************************************************************************************************************/ @@ -436,5 +434,3 @@ harnessLogFinal(void) FUNCTION_HARNESS_RESULT_VOID(); } - -#endif diff --git a/test/src/common/harnessLog.h b/test/src/common/harnessLog.h index bfc9cad99..89d2db4ba 100644 --- a/test/src/common/harnessLog.h +++ b/test/src/common/harnessLog.h @@ -27,7 +27,7 @@ void harnessLogLevelReset(void); void harnessLogLevelSet(LogLevel logLevel); // Set the process id used for logging. Ignore the request if the logging module is not active yet. -#ifndef NO_LOG +#ifdef HRN_FEATURE_LOG void hrnLogProcessIdSet(unsigned int processId); #else #define hrnLogProcessIdSet(processId) diff --git a/test/src/common/harnessTest.c b/test/src/common/harnessTest.c index 375e2757a..cc3d1decb 100644 --- a/test/src/common/harnessTest.c +++ b/test/src/common/harnessTest.c @@ -61,7 +61,7 @@ static struct HarnessTestLocal /*********************************************************************************************************************************** Extern functions ***********************************************************************************************************************************/ -#ifndef NO_LOG +#ifdef HRN_FEATURE_LOG void harnessLogInit(void); void harnessLogFinal(void); #endif @@ -161,7 +161,7 @@ testBegin(const char *name) if (testList[testRun - 1].selected) { -#ifndef NO_LOG +#ifdef HRN_FEATURE_LOG if (!testFirst) { // Make sure there is nothing untested left in the log @@ -208,7 +208,7 @@ testBegin(const char *name) testRunSub = 1; timeMSecBegin = testTimeMSec(); -#ifndef NO_LOG +#ifdef HRN_FEATURE_LOG // Initialize logging harnessLogInit(); #endif @@ -229,7 +229,7 @@ hrnComplete(void) { FUNCTION_HARNESS_VOID(); -#ifndef NO_LOG +#ifdef HRN_FEATURE_LOG // Make sure there is nothing untested left in the log harnessLogFinal(); #endif @@ -646,6 +646,8 @@ void hrnTestResultPtr(const void *actual, const void *expected, HarnessTestResul hrnTestResultEnd(); } +#ifdef HRN_FEATURE_STRING + void hrnTestResultStringList(const StringList *actual, const void *expected, HarnessTestResultOperation operation) { @@ -659,6 +661,8 @@ hrnTestResultStringList(const StringList *actual, const void *expected, HarnessT hrnTestResultZ(strZ(strCatZ(strLstJoin(actual, "\n"), "\n")), expected, operation); } +#endif + void hrnTestResultUInt64(uint64_t actual, uint64_t expected, HarnessTestResultOperation operation) { ASSERT(harnessTestLocal.result.running); diff --git a/test/src/common/harnessTest.h b/test/src/common/harnessTest.h index da252455f..4aab6d2b9 100644 --- a/test/src/common/harnessTest.h +++ b/test/src/common/harnessTest.h @@ -6,11 +6,11 @@ C Test Harness #include -#include "common/harnessTest.intern.h" - #include "common/debug.h" #include "common/error.h" +#include "common/harnessTest.intern.h" + /*********************************************************************************************************************************** Constants ***********************************************************************************************************************************/ diff --git a/test/src/common/harnessTest.intern.h b/test/src/common/harnessTest.intern.h index 233d89102..d8a0b70f4 100644 --- a/test/src/common/harnessTest.intern.h +++ b/test/src/common/harnessTest.intern.h @@ -6,7 +6,9 @@ C Test Harness Internal #include +#ifdef HRN_FEATURE_STRING #include "common/type/stringList.h" +#endif #include "common/harnessTest.h" @@ -44,7 +46,11 @@ void hrnTestResultBool(int actual, int expected); void hrnTestResultDouble(double actual, double expected); void hrnTestResultInt64(int64_t actual, int64_t expected, HarnessTestResultOperation operation); void hrnTestResultPtr(const void *actual, const void *expected, HarnessTestResultOperation operation); + +#ifdef HRN_FEATURE_STRING void hrnTestResultStringList(const StringList *actual, const void *expected, HarnessTestResultOperation operation); +#endif + void hrnTestResultUInt64(uint64_t actual, uint64_t expected, HarnessTestResultOperation operation); void hrnTestResultUInt64Int64(uint64_t actual, int64_t expected, HarnessTestResultOperation operation); void hrnTestResultZ(const char *actual, const char *expected, HarnessTestResultOperation operation); diff --git a/test/src/module/common/ioTlsTest.c b/test/src/module/common/ioTlsTest.c index 4e6533fa1..e33204ee5 100644 --- a/test/src/module/common/ioTlsTest.c +++ b/test/src/module/common/ioTlsTest.c @@ -18,6 +18,9 @@ testRun(void) { FUNCTION_HARNESS_VOID(); + // Initialize socket options + sckInit(false, true, 2, 5, 5); + // ***************************************************************************************************************************** if (testBegin("Socket Common")) { diff --git a/test/src/module/common/statTest.c b/test/src/module/common/statTest.c index a9ef4a872..898135aca 100644 --- a/test/src/module/common/statTest.c +++ b/test/src/module/common/statTest.c @@ -17,6 +17,8 @@ testRun(void) const String *statTlsClient = STRDEF("tls.client"); const String *statHttpSession = STRDEF("http.session"); + TEST_RESULT_VOID(statInit(), "init stats"); + TEST_RESULT_UINT(lstSize(statLocalData.stat), 0, "stat list is empty"); TEST_RESULT_VOID(statInc(statTlsClient), "inc tls.client"); diff --git a/test/src/test.c b/test/src/test.c index a19e16b0c..73f8880a1 100644 --- a/test/src/test.c +++ b/test/src/test.c @@ -22,11 +22,14 @@ The test code is included directly so it can freely interact with the included C #include #include -#ifndef NO_ERROR - #include "common/debug.h" +#ifdef HRN_FEATURE_ERROR #include "common/error.h" #endif +#ifdef HRN_FEATURE_DEBUG + #include "common/debug.h" +#endif + // Path where the test is running #define TEST_PATH "{[C_TEST_PATH]}" @@ -36,12 +39,12 @@ The test code is included directly so it can freely interact with the included C #include "common/harnessDebug.h" #include "common/harnessTest.intern.h" -#ifndef NO_LOG +#ifdef HRN_FEATURE_LOG #include "common/harnessLog.h" void harnessLogLevelDefaultSet(LogLevel logLevel); #endif -#ifndef NO_MEM_CONTEXT +#ifdef HRN_FEATURE_MEMCONTEXT #include "common/memContext.h" #endif @@ -54,7 +57,7 @@ Includes that are not generally used by tests #include "common/io/socket/common.h" -#ifndef NO_STAT +#ifdef HRN_FEATURE_STAT #include "common/stat.h" #endif @@ -83,12 +86,14 @@ main(int argListSize, const char *argList[]) int result = 0; // Initialize statistics -#ifndef NO_STAT +#ifdef HRN_FEATURE_STAT statInit(); #endif // Use aggressive keep-alive settings for testing +#ifdef HRN_FEATURE_SOCKET sckInit(false, true, 2, 5, 5); +#endif // Set neutral umask for testing umask(0000); @@ -112,7 +117,7 @@ main(int argListSize, const char *argList[]) "{[C_TEST_REPO_PATH]}"); // Path with a copy of the repository // Set default test log level -#ifndef NO_LOG +#ifdef HRN_FEATURE_LOG harnessLogLevelDefaultSet({[C_LOG_LEVEL_TEST]}); #endif @@ -120,7 +125,7 @@ main(int argListSize, const char *argList[]) // run, selected {[C_TEST_LIST]} -#ifndef NO_ERROR +#ifdef HRN_FEATURE_ERROR TRY_BEGIN() { TRY_BEGIN() @@ -128,7 +133,7 @@ main(int argListSize, const char *argList[]) #endif // Run the tests testRun(); -#ifndef NO_ERROR +#ifdef HRN_FEATURE_ERROR } CATCH_ANY() { @@ -149,7 +154,7 @@ main(int argListSize, const char *argList[]) printf("\nTESTS COMPLETED SUCCESSFULLY\n"); fflush(stdout); -#ifndef NO_ERROR +#ifdef HRN_FEATURE_ERROR } CATCH_ANY() { @@ -171,7 +176,7 @@ main(int argListSize, const char *argList[]) fflush(stderr); result = errorCode(); } -#ifndef NO_MEM_CONTEXT +#ifdef HRN_FEATURE_MEMCONTEXT FINALLY() { memContextFree(memContextTop());