1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-10-30 23:37:45 +02:00

Make unit test builds incremental based on coverage in prior tests.

When building tests only include files covered by the current test or by prior tests. This increases performance (less compilation and linking) and also helps detect cross-dependencies in the code. Since there are currently cross-dependencies the depend option is used to document them and allow compilation. The idea is to resolve them incrementally over time.

Add the harness option to include harness modules when the minimum requirements for compilation are met.

Add the feature option to indicate which features are now available in the harness (based on source modules already tested). This allows conditional compilation in harness modules when some features are not yet available.
This commit is contained in:
David Steele
2021-01-27 10:57:42 -05:00
parent 73a8e91868
commit 87eb081a8f
15 changed files with 390 additions and 238 deletions

View File

@@ -10,7 +10,6 @@
# Most options can be set for modules and tests (test option will override module option if both are set): # 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 # * 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 - 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 # * 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? # * binReq - is the pgbackrest binary required for this test?
# * containerReq - is this test required to run in a container? # * 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 # * 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 # 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). # 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 # * total - total runs in the test
# * vm - VMs that the test will be run on # * vm - VMs that the test will be run on
# * include - modules to include directly into test.c (all files in coverage are automatically included) # * include - modules to include directly into test.c (all files in coverage are automatically included)
@@ -37,107 +43,67 @@ unit:
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: error - name: error
total: 8 total: 8
define-test: -DNO_ERROR -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT feature: error
coverage: coverage:
- common/error - common/error
- common/error.auto: noCode - common/error.auto: noCode
# ---------------------------------------------------------------------------------------------------------------------------- depend:
- name: assert-on - common/debug
total: 1 - common/type/convert
define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT - common/memContext
- common/stackTrace
coverage: - common/type/buffer
- common/assert: noCode - common/type/keyValue
- common/type/list
# ---------------------------------------------------------------------------------------------------------------------------- - common/type/string
- name: assert-off - common/type/stringList
total: 1 - common/type/variant
define: -DNDEBUG - common/type/variantList
define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT
debugUnitSuppress: true
coverage:
- common/assert: noCode
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: stack-trace - name: stack-trace
total: 4 total: 4
define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT
coverage: coverage:
- common/stackTrace - common/stackTrace
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: mem-context - name: assert-off
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
total: 1 total: 1
define-test: -DNO_LOG define: -DNDEBUG
debugUnitSuppress: true
coverage: coverage:
- common/fork - common/assert: noCode
# ----------------------------------------------------------------------------------------------------------------------------
- name: log
total: 5
define-test: -DNO_LOG
coverage:
- common/log
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: debug-off - name: debug-off
total: 2 total: 2
define: -DNDEBUG define: -DNDEBUG
define-test: -DNO_LOG
debugUnitSuppress: true debugUnitSuppress: true
coverage: coverage:
- common/debug - common/debug
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: debug-on - name: assert-on
total: 4
coverage:
- common/debug
# ----------------------------------------------------------------------------------------------------------------------------
- name: lock
total: 2
coverage:
- common/lock
# ----------------------------------------------------------------------------------------------------------------------------
- name: exit
total: 3
coverage:
- common/exit
# ----------------------------------------------------------------------------------------------------------------------------
- name: wait
total: 1 total: 1
coverage: coverage:
- common/wait - common/assert: noCode
# ----------------------------------------------------------------------------------------------------------------------------
- name: mem-context
total: 7
feature: memContext
coverage:
- common/memContext
depend:
- common/type/convert
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: type-convert - name: type-convert
@@ -147,11 +113,20 @@ unit:
- common/type/convert - common/type/convert
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: type-object - name: time
total: 1 total: 3
coverage: coverage:
- common/type/object: noCode - common/time
# ----------------------------------------------------------------------------------------------------------------------------
- name: type-string
total: 26
feature: string
coverage:
- common/type/string
- common/type/stringList
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: type-list - name: type-list
@@ -160,14 +135,6 @@ unit:
coverage: coverage:
- common/type/list - common/type/list
# ----------------------------------------------------------------------------------------------------------------------------
- name: type-string
total: 26
coverage:
- common/type/string
- common/type/stringList
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: type-buffer - name: type-buffer
total: 6 total: 6
@@ -184,11 +151,49 @@ unit:
- common/type/variantList - 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 total: 1
coverage: 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 - name: type-mcv
@@ -221,6 +226,7 @@ unit:
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: stat - name: stat
total: 1 total: 1
feature: STAT
coverage: coverage:
- common/stat - common/stat
@@ -251,9 +257,29 @@ unit:
- common/io/read - common/io/read
- common/io/write - 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 - name: io-tls
total: 5 total: 5
feature: SOCKET
harness: server
coverage: coverage:
- common/io/client - common/io/client
@@ -281,6 +307,36 @@ unit:
- common/io/http/response - common/io/http/response
- common/io/http/session - 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 - name: compress
total: 5 total: 5
@@ -301,43 +357,60 @@ unit:
- common/compress/helper - common/compress/helper
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: crypto - name: exit
total: 3 total: 3
harness: config
coverage: coverage:
- common/crypto/cipherBlock - common/exit
- common/crypto/common
- common/crypto/hash depend:
- common/crypto/md5.vendor - 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 - name: lock
total: 1 total: 2
coverage: coverage:
- common/exec - common/lock
# ----------------------------------------------------------------------------------------------------------------------------
- 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
# ******************************************************************************************************************************** # ********************************************************************************************************************************
- name: postgres - name: postgres
@@ -346,6 +419,7 @@ unit:
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: client - name: client
total: 1 total: 1
harness: pq
coverage: coverage:
- postgres/client - postgres/client
@@ -403,6 +477,21 @@ unit:
- name: storage - name: storage
test: 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 - name: azure
total: 3 total: 3
@@ -429,19 +518,6 @@ unit:
include: include:
- storage/storage - 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 - name: remote
total: 9 total: 9
@@ -502,6 +578,7 @@ unit:
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: info - name: info
total: 3 total: 3
harness: info
coverage: coverage:
- info/info - info/info
@@ -520,13 +597,6 @@ unit:
coverage: coverage:
- info/infoArchive - info/infoArchive
# ----------------------------------------------------------------------------------------------------------------------------
- name: info-backup
total: 3
coverage:
- info/infoBackup
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: manifest - name: manifest
total: 6 total: 6
@@ -534,6 +604,16 @@ unit:
coverage: coverage:
- info/manifest - info/manifest
depend:
- command/backup/common
# ----------------------------------------------------------------------------------------------------------------------------
- name: info-backup
total: 3
coverage:
- info/infoBackup
# ******************************************************************************************************************************** # ********************************************************************************************************************************
- name: db - name: db
@@ -553,6 +633,15 @@ unit:
- name: command - name: command
test: test:
# ----------------------------------------------------------------------------------------------------------------------------
- name: control
total: 3
coverage:
- command/control/common
- command/control/start
- command/control/stop
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: archive-common - name: archive-common
total: 9 total: 9
@@ -583,28 +672,17 @@ unit:
- command/archive/push/push - command/archive/push/push
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: backup-common - name: stanza
total: 3 total: 4
coverage: coverage:
- command/backup/common - command/stanza/common
- command/backup/pageChecksum - command/stanza/create
- command/stanza/upgrade
- command/stanza/delete
# ---------------------------------------------------------------------------------------------------------------------------- depend:
- name: backup - command/check/common
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: check - name: check
@@ -622,15 +700,6 @@ unit:
coverage: coverage:
- command/command - command/command
# ----------------------------------------------------------------------------------------------------------------------------
- name: control
total: 3
coverage:
- command/control/common
- command/control/start
- command/control/stop
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: expire - name: expire
total: 8 total: 8
@@ -656,13 +725,6 @@ unit:
coverage: coverage:
- command/info/info - command/info/info
# ----------------------------------------------------------------------------------------------------------------------------
- name: local
total: 1
coverage:
- command/local/local
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: remote - name: remote
total: 1 total: 1
@@ -686,14 +748,28 @@ unit:
- info/manifest - info/manifest
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: stanza - name: backup-common
total: 4 total: 3
coverage: coverage:
- command/stanza/common - command/backup/common
- command/stanza/create - command/backup/pageChecksum
- 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
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: repo - name: repo
@@ -720,6 +796,13 @@ unit:
- command/verify/protocol - command/verify/protocol
- command/verify/verify - command/verify/verify
# ----------------------------------------------------------------------------------------------------------------------------
- name: local
total: 1
coverage:
- command/local/local
# ********************************************************************************************************************************** # **********************************************************************************************************************************
# Integration tests # Integration tests
# #

View File

@@ -39,22 +39,27 @@ use constant TESTDEF_TEST => 'test';
use constant TESTDEF_DB => 'db'; use constant TESTDEF_DB => 'db';
push @EXPORT, qw(TESTDEF_DB); push @EXPORT, qw(TESTDEF_DB);
use constant TESTDEF_DEPEND => 'depend';
use constant TESTDEF_CONTAINER => 'container'; use constant TESTDEF_CONTAINER => 'container';
push @EXPORT, qw(TESTDEF_CONTAINER); push @EXPORT, qw(TESTDEF_CONTAINER);
use constant TESTDEF_CONTAINER_REQUIRED => 'containerReq'; use constant TESTDEF_CONTAINER_REQUIRED => 'containerReq';
push @EXPORT, qw(TESTDEF_CONTAINER_REQUIRED); push @EXPORT, qw(TESTDEF_CONTAINER_REQUIRED);
use constant TESTDEF_COVERAGE => 'coverage'; use constant TESTDEF_COVERAGE => 'coverage';
push @EXPORT, qw(TESTDEF_COVERAGE); push @EXPORT, qw(TESTDEF_COVERAGE);
use constant TESTDEF_CORE => 'core';
push @EXPORT, qw(TESTDEF_CORE);
use constant TESTDEF_EXPECT => 'expect'; use constant TESTDEF_EXPECT => 'expect';
push @EXPORT, qw(TESTDEF_EXPECT); push @EXPORT, qw(TESTDEF_EXPECT);
use constant TESTDEF_C => 'c'; use constant TESTDEF_C => 'c';
push @EXPORT, qw(TESTDEF_C); push @EXPORT, qw(TESTDEF_C);
use constant TESTDEF_DEFINE => 'define'; use constant TESTDEF_DEFINE => 'define';
push @EXPORT, qw(TESTDEF_DEFINE); push @EXPORT, qw(TESTDEF_DEFINE);
use constant TESTDEF_DEFINE_TEST => 'define-test'; use constant TESTDEF_FEATURE => 'feature';
push @EXPORT, qw(TESTDEF_DEFINE_TEST); push @EXPORT, qw(TESTDEF_FEATURE);
use constant TESTDEF_DEBUG_UNIT_SUPPRESS => 'debugUnitSuppress'; use constant TESTDEF_DEBUG_UNIT_SUPPRESS => 'debugUnitSuppress';
push @EXPORT, qw(TESTDEF_DEBUG_UNIT_SUPPRESS); push @EXPORT, qw(TESTDEF_DEBUG_UNIT_SUPPRESS);
use constant TESTDEF_HARNESS => 'harness';
push @EXPORT, qw(TESTDEF_HARNESS);
use constant TESTDEF_INCLUDE => 'include'; use constant TESTDEF_INCLUDE => 'include';
push @EXPORT, qw(TESTDEF_INCLUDE); push @EXPORT, qw(TESTDEF_INCLUDE);
use constant TESTDEF_INDIVIDUAL => 'individual'; use constant TESTDEF_INDIVIDUAL => 'individual';
@@ -92,6 +97,15 @@ sub testDefLoad
my $hTestDef = Load($strDefineYaml); 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 # Iterate each test type
foreach my $strModuleType (TESTDEF_UNIT, TESTDEF_INTEGRATION, TESTDEF_PERFORMANCE) 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 # Resolve variables that can be set in the module or the test
foreach my $strVar ( 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) TESTDEF_CONTAINER_REQUIRED)
{ {
$hTestDefHash->{$strModule}{$strTest}{$strVar} = coalesce( $hTestDefHash->{$strModule}{$strTest}{$strVar} = coalesce(
@@ -148,6 +162,41 @@ sub testDefLoad
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_CONTAINER} = $bContainer; $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_CONTAINER} = $bContainer;
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_INDIVIDUAL} = $bIndividual; $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 # Set test count
$hTestDefHash->{$strModule}{$strTest}{&TESTDEF_TOTAL} = $hModuleTest->{&TESTDEF_TOTAL}; $hTestDefHash->{$strModule}{$strTest}{&TESTDEF_TOTAL} = $hModuleTest->{&TESTDEF_TOTAL};
@@ -190,10 +239,21 @@ sub testDefLoad
# Add to coverage list # Add to coverage list
push(@{$hCoverageList->{$strCodeModule}}, {strModule=> $strModule, strTest => $strTest}); 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 # 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; $hModuleTest->{$strModule} = \@stryModuleTest;

View File

@@ -343,38 +343,33 @@ sub run
# Generate list of harness files # Generate list of harness files
# ------------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------------
my $hTest = (testDefModuleTest($self->{oTest}->{&TEST_MODULE}, $self->{oTest}->{&TEST_NAME}));
my $strRepoCopyTestSrcHarnessPath = $strRepoCopyTestSrcPath . '/common'; 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 push(@stryHarnessFile, "common/harness" . ucfirst($strFile));
next if $strFile eq '.' || $strFile =~ /\.h$/;
push(@stryHarnessFile, "common/" . substr($strFile, 0, length($strFile) - 2));
} }
# Generate list of core files (files to be tested/included in this unit will be excluded) # 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 $hTestCoverage = $hTest->{&TESTDEF_COVERAGE};
my @stryCoreFile; 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) # Skip all files except .c files (including .auto.c and .vendor.c)
next if $strFile !~ /(?<!\.auto)\.c$/ || $strFile !~ /(?<!\.vendor)\.c$/; next if $strFile !~ /(?<!\.auto)$/ || $strFile !~ /(?<!\.vendor)$/;
# ??? Skip main for now until the function can be renamed to allow unit testing # Skip if no C file exists
next if $strFile =~ /main\.c$/; next if !$self->{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" . "\n" .
"SRCS = test.c \\\n" . "SRCS = test.c \\\n" .
"\t" . join('.c ', @stryHarnessFile) . ".c \\\n" . "\t" . join('.c ', @stryHarnessFile) . ".c \\\n" .
"\t" . join('.c ', @stryCoreFile) . ".c\n" . (@stryCoreFile > 0 ? "\t" . join('.c ', @stryCoreFile) . ".c\n" : '').
"\n" . "\n" .
".build/test.o: CFLAGS += \$(CFLAGS_TEST)\n" . ".build/test.o: CFLAGS += \$(CFLAGS_TEST)\n" .
"\n" . "\n" .

View File

@@ -171,7 +171,7 @@ sub testListGet
&TEST_VM => $strTestOS, &TEST_VM => $strTestOS,
&TEST_C => coalesce($hTest->{&TESTDEF_C}, $hModule->{&TESTDEF_C}, false), &TEST_C => coalesce($hTest->{&TESTDEF_C}, $hModule->{&TESTDEF_C}, false),
&TEST_CDEF => $hTest->{&TESTDEF_DEFINE}, &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_DEBUG_UNIT_SUPPRESS => $hTest->{&TEST_DEBUG_UNIT_SUPPRESS},
&TEST_CONTAINER => defined($hTest->{&TESTDEF_CONTAINER}) ? &TEST_CONTAINER => defined($hTest->{&TESTDEF_CONTAINER}) ?
$hTest->{&TESTDEF_CONTAINER} : $hModule->{&TESTDEF_CONTAINER}, $hTest->{&TESTDEF_CONTAINER} : $hModule->{&TESTDEF_CONTAINER},

View File

@@ -37,7 +37,7 @@ harnessCfgLoadRaw(unsigned int argListSize, const char *argList[])
// Set dry-run mode for storage and logging // Set dry-run mode for storage and logging
storageHelperDryRunInit(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun)); storageHelperDryRunInit(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun));
#ifndef NO_LOG #ifdef HRN_FEATURE_STORAGE
harnessLogDryRunSet(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun)); harnessLogDryRunSet(cfgOptionValid(cfgOptDryRun) && cfgOptionBool(cfgOptDryRun));
#endif #endif

View File

@@ -4,22 +4,7 @@ C Debug Harness
#ifndef TEST_COMMON_HARNESS_DEBUG_H #ifndef TEST_COMMON_HARNESS_DEBUG_H
#define TEST_COMMON_HARNESS_DEBUG_H #define TEST_COMMON_HARNESS_DEBUG_H
#ifdef NO_STACK_TRACE #ifdef HRN_FEATURE_DEBUG
#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
#include "common/debug.h" #include "common/debug.h"
#ifdef WITH_BACKTRACE #ifdef WITH_BACKTRACE
@@ -75,6 +60,21 @@ C Debug Harness
#define FUNCTION_HARNESS_RESULT_VOID() \ #define FUNCTION_HARNESS_RESULT_VOID() \
STACK_TRACE_POP(false); 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
#endif #endif

View File

@@ -38,8 +38,6 @@ There should not be any code outside the HARNESS_FORK_CHILD_BEGIN/END() and HARN
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <common/fork.h>
#include <common/harnessLog.h> #include <common/harnessLog.h>
/*********************************************************************************************************************************** /***********************************************************************************************************************************
@@ -137,7 +135,7 @@ Create a child process
"unable to create write pipe for child process %u", HARNESS_FORK_PROCESS_TOTAL()); \ "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) \ if (HARNESS_FORK_PROCESS_ID(HARNESS_FORK_PROCESS_TOTAL()) == 0) \
{ \ { \

View File

@@ -15,8 +15,6 @@ Log Test Harness
#include "common/harnessDebug.h" #include "common/harnessDebug.h"
#include "common/harnessTest.h" #include "common/harnessTest.h"
#ifndef NO_LOG
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Expose log internal data for unit testing/debugging Expose log internal data for unit testing/debugging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@@ -436,5 +434,3 @@ harnessLogFinal(void)
FUNCTION_HARNESS_RESULT_VOID(); FUNCTION_HARNESS_RESULT_VOID();
} }
#endif

View File

@@ -27,7 +27,7 @@ void harnessLogLevelReset(void);
void harnessLogLevelSet(LogLevel logLevel); void harnessLogLevelSet(LogLevel logLevel);
// Set the process id used for logging. Ignore the request if the logging module is not active yet. // 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); void hrnLogProcessIdSet(unsigned int processId);
#else #else
#define hrnLogProcessIdSet(processId) #define hrnLogProcessIdSet(processId)

View File

@@ -61,7 +61,7 @@ static struct HarnessTestLocal
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Extern functions Extern functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#ifndef NO_LOG #ifdef HRN_FEATURE_LOG
void harnessLogInit(void); void harnessLogInit(void);
void harnessLogFinal(void); void harnessLogFinal(void);
#endif #endif
@@ -161,7 +161,7 @@ testBegin(const char *name)
if (testList[testRun - 1].selected) if (testList[testRun - 1].selected)
{ {
#ifndef NO_LOG #ifdef HRN_FEATURE_LOG
if (!testFirst) if (!testFirst)
{ {
// Make sure there is nothing untested left in the log // Make sure there is nothing untested left in the log
@@ -208,7 +208,7 @@ testBegin(const char *name)
testRunSub = 1; testRunSub = 1;
timeMSecBegin = testTimeMSec(); timeMSecBegin = testTimeMSec();
#ifndef NO_LOG #ifdef HRN_FEATURE_LOG
// Initialize logging // Initialize logging
harnessLogInit(); harnessLogInit();
#endif #endif
@@ -229,7 +229,7 @@ hrnComplete(void)
{ {
FUNCTION_HARNESS_VOID(); FUNCTION_HARNESS_VOID();
#ifndef NO_LOG #ifdef HRN_FEATURE_LOG
// Make sure there is nothing untested left in the log // Make sure there is nothing untested left in the log
harnessLogFinal(); harnessLogFinal();
#endif #endif
@@ -646,6 +646,8 @@ void hrnTestResultPtr(const void *actual, const void *expected, HarnessTestResul
hrnTestResultEnd(); hrnTestResultEnd();
} }
#ifdef HRN_FEATURE_STRING
void void
hrnTestResultStringList(const StringList *actual, const void *expected, HarnessTestResultOperation operation) 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); hrnTestResultZ(strZ(strCatZ(strLstJoin(actual, "\n"), "\n")), expected, operation);
} }
#endif
void hrnTestResultUInt64(uint64_t actual, uint64_t expected, HarnessTestResultOperation operation) void hrnTestResultUInt64(uint64_t actual, uint64_t expected, HarnessTestResultOperation operation)
{ {
ASSERT(harnessTestLocal.result.running); ASSERT(harnessTestLocal.result.running);

View File

@@ -6,11 +6,11 @@ C Test Harness
#include <inttypes.h> #include <inttypes.h>
#include "common/harnessTest.intern.h"
#include "common/debug.h" #include "common/debug.h"
#include "common/error.h" #include "common/error.h"
#include "common/harnessTest.intern.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Constants Constants
***********************************************************************************************************************************/ ***********************************************************************************************************************************/

View File

@@ -6,7 +6,9 @@ C Test Harness Internal
#include <stdbool.h> #include <stdbool.h>
#ifdef HRN_FEATURE_STRING
#include "common/type/stringList.h" #include "common/type/stringList.h"
#endif
#include "common/harnessTest.h" #include "common/harnessTest.h"
@@ -44,7 +46,11 @@ void hrnTestResultBool(int actual, int expected);
void hrnTestResultDouble(double actual, double expected); void hrnTestResultDouble(double actual, double expected);
void hrnTestResultInt64(int64_t actual, int64_t expected, HarnessTestResultOperation operation); void hrnTestResultInt64(int64_t actual, int64_t expected, HarnessTestResultOperation operation);
void hrnTestResultPtr(const void *actual, const void *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); void hrnTestResultStringList(const StringList *actual, const void *expected, HarnessTestResultOperation operation);
#endif
void hrnTestResultUInt64(uint64_t actual, uint64_t expected, HarnessTestResultOperation operation); void hrnTestResultUInt64(uint64_t actual, uint64_t expected, HarnessTestResultOperation operation);
void hrnTestResultUInt64Int64(uint64_t actual, int64_t expected, HarnessTestResultOperation operation); void hrnTestResultUInt64Int64(uint64_t actual, int64_t expected, HarnessTestResultOperation operation);
void hrnTestResultZ(const char *actual, const char *expected, HarnessTestResultOperation operation); void hrnTestResultZ(const char *actual, const char *expected, HarnessTestResultOperation operation);

View File

@@ -18,6 +18,9 @@ testRun(void)
{ {
FUNCTION_HARNESS_VOID(); FUNCTION_HARNESS_VOID();
// Initialize socket options
sckInit(false, true, 2, 5, 5);
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("Socket Common")) if (testBegin("Socket Common"))
{ {

View File

@@ -17,6 +17,8 @@ testRun(void)
const String *statTlsClient = STRDEF("tls.client"); const String *statTlsClient = STRDEF("tls.client");
const String *statHttpSession = STRDEF("http.session"); 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_UINT(lstSize(statLocalData.stat), 0, "stat list is empty");
TEST_RESULT_VOID(statInc(statTlsClient), "inc tls.client"); TEST_RESULT_VOID(statInc(statTlsClient), "inc tls.client");

View File

@@ -22,11 +22,14 @@ The test code is included directly so it can freely interact with the included C
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifndef NO_ERROR #ifdef HRN_FEATURE_ERROR
#include "common/debug.h"
#include "common/error.h" #include "common/error.h"
#endif #endif
#ifdef HRN_FEATURE_DEBUG
#include "common/debug.h"
#endif
// Path where the test is running // Path where the test is running
#define TEST_PATH "{[C_TEST_PATH]}" #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/harnessDebug.h"
#include "common/harnessTest.intern.h" #include "common/harnessTest.intern.h"
#ifndef NO_LOG #ifdef HRN_FEATURE_LOG
#include "common/harnessLog.h" #include "common/harnessLog.h"
void harnessLogLevelDefaultSet(LogLevel logLevel); void harnessLogLevelDefaultSet(LogLevel logLevel);
#endif #endif
#ifndef NO_MEM_CONTEXT #ifdef HRN_FEATURE_MEMCONTEXT
#include "common/memContext.h" #include "common/memContext.h"
#endif #endif
@@ -54,7 +57,7 @@ Includes that are not generally used by tests
#include "common/io/socket/common.h" #include "common/io/socket/common.h"
#ifndef NO_STAT #ifdef HRN_FEATURE_STAT
#include "common/stat.h" #include "common/stat.h"
#endif #endif
@@ -83,12 +86,14 @@ main(int argListSize, const char *argList[])
int result = 0; int result = 0;
// Initialize statistics // Initialize statistics
#ifndef NO_STAT #ifdef HRN_FEATURE_STAT
statInit(); statInit();
#endif #endif
// Use aggressive keep-alive settings for testing // Use aggressive keep-alive settings for testing
#ifdef HRN_FEATURE_SOCKET
sckInit(false, true, 2, 5, 5); sckInit(false, true, 2, 5, 5);
#endif
// Set neutral umask for testing // Set neutral umask for testing
umask(0000); umask(0000);
@@ -112,7 +117,7 @@ main(int argListSize, const char *argList[])
"{[C_TEST_REPO_PATH]}"); // Path with a copy of the repository "{[C_TEST_REPO_PATH]}"); // Path with a copy of the repository
// Set default test log level // Set default test log level
#ifndef NO_LOG #ifdef HRN_FEATURE_LOG
harnessLogLevelDefaultSet({[C_LOG_LEVEL_TEST]}); harnessLogLevelDefaultSet({[C_LOG_LEVEL_TEST]});
#endif #endif
@@ -120,7 +125,7 @@ main(int argListSize, const char *argList[])
// run, selected // run, selected
{[C_TEST_LIST]} {[C_TEST_LIST]}
#ifndef NO_ERROR #ifdef HRN_FEATURE_ERROR
TRY_BEGIN() TRY_BEGIN()
{ {
TRY_BEGIN() TRY_BEGIN()
@@ -128,7 +133,7 @@ main(int argListSize, const char *argList[])
#endif #endif
// Run the tests // Run the tests
testRun(); testRun();
#ifndef NO_ERROR #ifdef HRN_FEATURE_ERROR
} }
CATCH_ANY() CATCH_ANY()
{ {
@@ -149,7 +154,7 @@ main(int argListSize, const char *argList[])
printf("\nTESTS COMPLETED SUCCESSFULLY\n"); printf("\nTESTS COMPLETED SUCCESSFULLY\n");
fflush(stdout); fflush(stdout);
#ifndef NO_ERROR #ifdef HRN_FEATURE_ERROR
} }
CATCH_ANY() CATCH_ANY()
{ {
@@ -171,7 +176,7 @@ main(int argListSize, const char *argList[])
fflush(stderr); fflush(stderr);
result = errorCode(); result = errorCode();
} }
#ifndef NO_MEM_CONTEXT #ifdef HRN_FEATURE_MEMCONTEXT
FINALLY() FINALLY()
{ {
memContextFree(memContextTop()); memContextFree(memContextTop());