From 1f8931f73274163f27ba38aea378ea50488ba557 Mon Sep 17 00:00:00 2001 From: David Steele Date: Sat, 3 Nov 2018 16:34:04 -0400 Subject: [PATCH] Improve single test run performance. Improve on 7794ab50 by including the build flag files directly into the Makefile as dependencies (even though they are not includes). This simplifies some of the rsync logic and allows make to do what it does best. Also split build flag files into test, harness, and build to reduce rebuilds. Test flags are used to build test.c, harness flags are used to build the rest of the files in the test harness, and build flags are used for the files that are not directly involved in testing. --- test/Vagrantfile | 2 +- test/define.yaml | 23 ++- test/lib/pgBackRestTest/Common/BuildTest.pm | 72 ++++++-- test/lib/pgBackRestTest/Common/DefineTest.pm | 5 +- test/lib/pgBackRestTest/Common/JobTest.pm | 184 +++++++++++-------- test/lib/pgBackRestTest/Common/ListTest.pm | 3 + test/src/module/common/debugOnTest.c | 8 +- test/src/module/common/errorTest.c | 5 +- test/src/module/common/exitTest.c | 4 +- 9 files changed, 186 insertions(+), 120 deletions(-) diff --git a/test/Vagrantfile b/test/Vagrantfile index 87532c779..89e88e225 100644 --- a/test/Vagrantfile +++ b/test/Vagrantfile @@ -60,7 +60,7 @@ Vagrant.configure(2) do |config| #--------------------------------------------------------------------------------------------------------------------------- echo 'Install Build Tools' && date - apt-get install -y devscripts build-essential lintian git txt2man debhelper libssl-dev zlib1g-dev lcov cloc + apt-get install -y devscripts build-essential lintian git txt2man debhelper libssl-dev zlib1g-dev libperl-dev lcov cloc #--------------------------------------------------------------------------------------------------------------------------- echo 'Install AWS CLI' && date diff --git a/test/define.yaml b/test/define.yaml index 468926182..0ee170974 100644 --- a/test/define.yaml +++ b/test/define.yaml @@ -13,7 +13,8 @@ # full - the module/test provides full coverage for the code module # partial - the module/test provides partial coverage for the code module # noCode - the code module should not contain any coverable code. If it does an error will be thrown. -# * define - defines for C testing +# * 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 # * perlReq - is Perl required for this C test? # @@ -36,7 +37,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: error total: 8 - define: -DNO_ERROR -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT + define-test: -DNO_ERROR -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT coverage: common/error: full @@ -45,7 +46,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: assert-on total: 2 - define: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT + define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT coverage: common/assert: noCode @@ -53,7 +54,8 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: assert-off total: 2 - define: -DNDEBUG -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT + define: -DNDEBUG + define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT debugUnitSuppress: true coverage: @@ -62,7 +64,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: stack-trace total: 4 - define: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT + define-test: -DNO_LOG -DNO_STACK_TRACE -DNO_MEM_CONTEXT coverage: common/stackTrace: full @@ -70,7 +72,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: mem-context total: 7 - define: -DNO_MEM_CONTEXT -DNO_LOG + define-test: -DNO_MEM_CONTEXT -DNO_LOG coverage: common/memContext: full @@ -78,7 +80,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: time total: 2 - define: -DNO_ERROR -DNO_LOG + define-test: -DNO_ERROR -DNO_LOG coverage: common/time: full @@ -86,7 +88,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: fork total: 1 - define: -DNO_LOG + define-test: -DNO_LOG coverage: common/fork: full @@ -94,7 +96,7 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: log total: 5 - define: -DNO_LOG + define-test: -DNO_LOG coverage: common/log: full @@ -102,7 +104,8 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: debug-off total: 2 - define: -DNDEBUG -DNO_LOG + define: -DNDEBUG + define-test: -DNO_LOG debugUnitSuppress: true coverage: diff --git a/test/lib/pgBackRestTest/Common/BuildTest.pm b/test/lib/pgBackRestTest/Common/BuildTest.pm index 51641c4ad..19f9b20c6 100644 --- a/test/lib/pgBackRestTest/Common/BuildTest.pm +++ b/test/lib/pgBackRestTest/Common/BuildTest.pm @@ -17,6 +17,35 @@ use Exporter qw(import); use pgBackRest::Common::Log; +#################################################################################################################################### +# Save contents to a file if the file is missing or the contents are different. This saves write IO and prevents the timestamp from +# changing. +#################################################################################################################################### +sub buildPutDiffers +{ + my $oStorage = shift; + my $strFile = shift; + my $strContents = shift; + + # Attempt to load the file + my $bSave = true; + my $oFile = $oStorage->openRead($strFile, {bIgnoreMissing => true}); + + # If file was found see if the content is the same + if (defined($oFile) && ${$oStorage->get($oFile)} eq $strContents) + { + $bSave = false; + } + + # Save if the contents are different or missing + if ($bSave) + { + $oStorage->put($strFile, $strContents); + } +} + +push @EXPORT, qw(buildPutDiffers); + #################################################################################################################################### # Find last modification time in a list of directories, with optional filters #################################################################################################################################### @@ -69,7 +98,7 @@ sub buildDependencyTree # Only process non-auto files if ($strFile =~ /^[A-Za-z0-9\/]+\.(c|h)$/) { - buildDependencyTreeSub($oStorage, $rhDependencyTree, $strFile); + buildDependencyTreeSub($oStorage, $rhDependencyTree, $strFile, undef, ['src', 'libc']); } } @@ -83,17 +112,34 @@ sub buildDependencyTreeSub my $oStorage = shift; my $rhDependencyTree = shift; my $strFile = shift; + my $strBasePath = shift; + my $rstryPath = shift; if (!defined($rhDependencyTree->{$strFile})) { $rhDependencyTree->{$strFile} = {}; # Load file contents - my $rstrContent = $oStorage->get($oStorage->openRead("src/${strFile}", {bIgnoreMissing => true})); + my $rstrContent; + + foreach my $strPath (@{$rstryPath}) + { + $rstrContent = $oStorage->get( + $oStorage->openRead( + (defined($strBasePath) ? "${strBasePath}/" : '') . ($strPath ne '' ? "${strPath}/" : '') . "${strFile}", + {bIgnoreMissing => true})); + + if (defined($rstrContent)) + { + $rhDependencyTree->{$strFile}{path} = $strPath; + last; + } + } if (!defined($rstrContent)) { - $rstrContent = $oStorage->get("libc/${strFile}"); + confess &log(ERROR, + "unable to find ${strFile} in " . $oStorage->pathGet($strBasePath) . " + [" . join(', ', @{$rstryPath}) . "]"); } # Process includes @@ -104,7 +150,7 @@ sub buildDependencyTreeSub $strInclude = (split('"', $strInclude))[1]; $rhInclude->{$strInclude} = true; - buildDependencyTreeSub($oStorage, $rhDependencyTree, $strInclude); + buildDependencyTreeSub($oStorage, $rhDependencyTree, $strInclude, $strBasePath, $rstryPath); foreach my $strIncludeSub (@{$rhDependencyTree->{$strInclude}{include}}) { @@ -114,23 +160,11 @@ sub buildDependencyTreeSub my @stryInclude = sort(keys(%{$rhInclude})); $rhDependencyTree->{$strFile}{include} = \@stryInclude; - - # Find header files that map to C files -- these are required to compile this file - foreach my $strInclude (@stryInclude) - { - if ($strInclude =~ /^[A-Za-z0-9\/]+\.h$/) - { - my $strObject = substr($strInclude, 0, length($strInclude) - 1) . 'c'; - - if ($oStorage->exists("src/${strObject}")) - { - push(@{$rhDependencyTree->{$strFile}{object}}, $strObject); - } - } - } } } +push @EXPORT, qw(buildDependencyTreeSub); + #################################################################################################################################### # Build Makefile object compile rules #################################################################################################################################### @@ -223,7 +257,7 @@ sub buildMakefile push @EXPORT, qw(buildMakefile); #################################################################################################################################### -# Update a Makefile with object compile rules +# Load the C library and check pointer size #################################################################################################################################### sub buildLoadLibC { diff --git a/test/lib/pgBackRestTest/Common/DefineTest.pm b/test/lib/pgBackRestTest/Common/DefineTest.pm index b97447203..17011b82e 100644 --- a/test/lib/pgBackRestTest/Common/DefineTest.pm +++ b/test/lib/pgBackRestTest/Common/DefineTest.pm @@ -49,6 +49,8 @@ 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_DEBUG_UNIT_SUPPRESS => 'debugUnitSuppress'; push @EXPORT, qw(TESTDEF_DEBUG_UNIT_SUPPRESS); use constant TESTDEF_INDIVIDUAL => 'individual'; @@ -119,7 +121,8 @@ sub testDefLoad push(@stryModuleTest, $strTest); # Resolve variables that can be set in the module or the test - foreach my $strVar (TESTDEF_DEFINE, TESTDEF_DEBUG_UNIT_SUPPRESS, TESTDEF_DB, TESTDEF_PERL_REQ, TESTDEF_VM) + foreach my $strVar ( + TESTDEF_DEFINE, TESTDEF_DEFINE_TEST, TESTDEF_DEBUG_UNIT_SUPPRESS, TESTDEF_DB, TESTDEF_PERL_REQ, TESTDEF_VM) { $hTestDefHash->{$strModule}{$strTest}{$strVar} = coalesce( $hModuleTest->{$strVar}, $hModule->{$strVar}, $strVar eq TESTDEF_VM ? undef : false); diff --git a/test/lib/pgBackRestTest/Common/JobTest.pm b/test/lib/pgBackRestTest/Common/JobTest.pm index 6d6cd83ed..b706df048 100644 --- a/test/lib/pgBackRestTest/Common/JobTest.pm +++ b/test/lib/pgBackRestTest/Common/JobTest.pm @@ -24,6 +24,7 @@ use pgBackRest::Common::Log; use pgBackRest::Common::String; use pgBackRest::Version; +use pgBackRestTest::Common::BuildTest; use pgBackRestTest::Common::ContainerTest; use pgBackRestTest::Common::DefineTest; use pgBackRestTest::Common::ExecuteTest; @@ -32,9 +33,8 @@ use pgBackRestTest::Common::RunTest; use pgBackRestTest::Common::VmTest; #################################################################################################################################### -# Build flags from the last build. When the build flags change test files must be rebuilt +# Has the C build directory been initialized yet? #################################################################################################################################### -my $rhBuildFlags = undef; my $rhBuildInit = undef; #################################################################################################################################### @@ -202,44 +202,20 @@ sub run # If testing C code copy source files to the test directory if ($self->{oTest}->{&TEST_C}) { - # If no tests have been run on this VM init build flags + # If this is the first build, then rsync files if (!$rhBuildInit->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}}) - { - # Attempt to load build flags off from file - my $oFile = $self->{oStorageTest}->openRead("$self->{strGCovPath}/buildflags", {bIgnoreMissing => true}); - - # If the file was not found then we don't know what the flags were set to, so rebuild - if (!defined($oFile)) - { - $rhBuildFlags->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}} = 'REBUILD-REQUIRED'; - } - # Else load the build flags - else - { - $rhBuildFlags->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}} = ${$self->{oStorageTest}->get($oFile)}; - } - } - - # If any of the build flags have changed then we'll need to rebuild from scratch - my $bFlagsChanged = - $rhBuildFlags->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}} ne $self->{oTest}->{&TEST_CDEF}; - - # If flags changed or this is the first build, then rsync files - if ($bFlagsChanged || !$rhBuildInit->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}}) { executeTest( - 'rsync -rt' . ($bFlagsChanged ? ' --delete' : '') . - " --exclude=test.c $self->{strBackRestBase}/src/ $self->{strGCovPath} && " . + 'rsync -rt --delete --exclude=*.o --exclude=test.c --exclude=test.gcno --exclude=LibC.h --exclude=xs' . + " --exclude=test --exclude=buildflags --exclude=testflags --exclude=harnessflags" . + " $self->{strBackRestBase}/src/ $self->{strGCovPath} && " . "rsync -t $self->{strBackRestBase}/libc/LibC.h $self->{strGCovPath} && " . - "rsync -rt $self->{strBackRestBase}/libc/xs/ $self->{strGCovPath}/xs && " . - "rsync -rt --exclude=test.c $self->{strBackRestBase}/test/src/ $self->{strGCovPath}"); + "rsync -rt --delete $self->{strBackRestBase}/libc/xs/ $self->{strGCovPath}/xs && " . + "rsync -rt --delete --exclude=*.o $self->{strBackRestBase}/test/src/ $self->{strGCovPath}/test"); } - # Set build flags and save them to a file + # Build directory has been initialized $rhBuildInit->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}} = true; - $rhBuildFlags->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}} = $self->{oTest}->{&TEST_CDEF}; - $self->{oStorageTest}->put( - "$self->{strGCovPath}/buildflags", $rhBuildFlags->{$self->{oTest}->{&TEST_VM}}{$self->{iVmIdx}}); } # If testing Perl code (or C code that calls Perl code) install bin and Perl C Library @@ -270,9 +246,9 @@ sub run "cd $self->{strGCovPath} && " . "make -s 2>&1 &&" . ($self->{oTest}->{&TEST_VM} ne VM_CO6 && $self->{bValgrindUnit}? - " valgrind -q --gen-suppressions=all --suppressions=$self->{strBackRestBase}/test/src/valgrind.suppress" . + " valgrind -q --gen-suppressions=all --suppressions=$self->{strGCovPath}/test/valgrind.suppress" . " --leak-check=full --leak-resolution=high --error-exitcode=25" : '') . - " ./test 2>&1'"; + " ./test.bin 2>&1'"; } else { @@ -318,15 +294,16 @@ sub run next if $strFile =~ /test\.c$/; if (!defined($hTestCoverage->{substr($strFile, 0, length($strFile) - 2)}) && - $strFile !~ /^module\/[^\/]*\/.*Test\.c$/) + $strFile !~ /^test\/module\/[^\/]*\/.*Test\.c$/) { push(@stryCFile, "${strFile}"); } } # Generate list of C files to include for testing + my $strTestDepend = ''; my $strTestFile = - "module/$self->{oTest}->{&TEST_MODULE}/" . testRunName($self->{oTest}->{&TEST_NAME}, false) . 'Test.c'; + "test/module/$self->{oTest}->{&TEST_MODULE}/" . testRunName($self->{oTest}->{&TEST_NAME}, false) . 'Test.c'; my $strCInclude; foreach my $strFile (sort(keys(%{$hTestCoverage}))) @@ -353,12 +330,26 @@ sub run } $strCInclude .= (defined($strCInclude) ? "\n" : '') . "#include \"${strCIncludeFile}\""; + $strTestDepend .= " ${strCIncludeFile}"; } # Update C test file with test module - my $strTestC = ${$self->{oStorageTest}->get("$self->{strBackRestBase}/test/src/test.c")}; + my $strTestC = ${$self->{oStorageTest}->get("$self->{strGCovPath}/test/test.c")}; $strTestC =~ s/\{\[C\_INCLUDE\]\}/$strCInclude/g; $strTestC =~ s/\{\[C\_TEST\_INCLUDE\]\}/\#include \"$strTestFile\"/g; + $strTestDepend .= " ${strTestFile}"; + + # Build dependencies for the test file + my $rhDependencyTree = {}; + buildDependencyTreeSub( + $self->{oStorageTest}, $rhDependencyTree, $strTestFile, $self->{strGCovPath}, ['', 'test']); + + foreach my $strDepend (@{$rhDependencyTree->{$strTestFile}{include}}) + { + $strTestDepend .= + ' ' . ($rhDependencyTree->{$strDepend}{path} ne '' ? $rhDependencyTree->{$strDepend}{path} . '/' : '') . + $strDepend; + } # Set globals $strTestC =~ s/\{\[C\_TEST\_PATH\]\}/$strVmTestPath/g; @@ -387,62 +378,93 @@ sub run } $strTestC =~ s/\{\[C\_TEST\_LIST\]\}/$strTestInit/g; + buildPutDiffers($self->{oStorageTest}, "$self->{strGCovPath}/test.c", $strTestC); - # Save C test file but don't overwrite the file if it exists and has the same content. This prevents unneeded - # recompiles of the test code. - my $bSave = true; - my $oFile = $self->{oStorageTest}->openRead("$self->{strGCovPath}/test.c", {bIgnoreMissing => true}); + # Flags that are common to all builds + my $strCommonFlags = + '-I. -Itest -std=c99 -fPIC -g -Wno-clobbered `perl -MExtUtils::Embed -e ccopts`' + . ($self->{bProfile} ? " -pg" : '') . + ($self->{oTest}->{&TEST_DEBUG_UNIT_SUPPRESS} ? '' : " -DDEBUG_UNIT") . + (vmWithBackTrace($self->{oTest}->{&TEST_VM}) && $self->{bBackTrace} ? ' -DWITH_BACKTRACE' : '') . + ($self->{oTest}->{&TEST_CDEF} ? " $self->{oTest}->{&TEST_CDEF}" : '') . + ($self->{bDebug} ? '' : " -DNDEBUG"); - if (defined($oFile) && ${$self->{oStorageTest}->get($oFile)} eq $strTestC) - { - $bSave = false; - } + # Flags used to buid harness files + my $strHarnessFlags = + '-O0' . ($self->{oTest}->{&TEST_VM} ne VM_U12 ? ' -ftree-coalesce-vars' : '') . + ($self->{oTest}->{&TEST_CTESTDEF} ? " $self->{oTest}->{&TEST_CTESTDEF}" : ''); - if ($bSave) - { - $self->{oStorageTest}->put("$self->{strGCovPath}/test.c", $strTestC); - } + buildPutDiffers($self->{oStorageTest}, "$self->{strGCovPath}/harnessflags", "${strCommonFlags} ${strHarnessFlags}"); + + # Flags used to buid test.c + my $strTestFlags = + '-Werror -Wfatal-errors -Wall -Wextra -Wwrite-strings -Wswitch-enum -Wconversion -Wformat=2' . + ' -Wformat-nonliteral -Wstrict-prototypes -Wpointer-arith -Wvla' . + ($self->{oTest}->{&TEST_VM} eq VM_U16 || $self->{oTest}->{&TEST_VM} eq VM_U18 ? + ' -Wformat-signedness' : '') . + ($self->{oTest}->{&TEST_VM} eq VM_U18 ? + ' -Wduplicated-branches -Wduplicated-cond' : '') . + # This warning appears to be broken on U12/CO6 even though the functionality is fine + ($self->{oTest}->{&TEST_VM} eq VM_U12 || $self->{oTest}->{&TEST_VM} eq VM_CO6 ? + ' -Wno-missing-field-initializers' : '') . + ' -O0' . ($self->{oTest}->{&TEST_VM} ne VM_U12 ? ' -ftree-coalesce-vars' : '') . + (vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? + ' -fprofile-arcs -ftest-coverage' : '') . + ($self->{oTest}->{&TEST_CTESTDEF} ? " $self->{oTest}->{&TEST_CTESTDEF}" : ''); + + buildPutDiffers( + $self->{oStorageTest}, "$self->{strGCovPath}/testflags", "${strCommonFlags} ${strTestFlags}"); + + # Flags used to buid all other files + my $strBuildFlags = + ($self->{bOptimize} ? '-O2' : '-O0' . ($self->{oTest}->{&TEST_VM} ne VM_U12 ? ' -ftree-coalesce-vars' : '')); + + buildPutDiffers($self->{oStorageTest}, "$self->{strGCovPath}/buildflags", "${strCommonFlags} ${strBuildFlags}"); # Build the Makefile my $strMakefile = "CC=gcc\n" . - "CFLAGS=-I. -std=c99 -fPIC -g" . ($self->{bProfile} ? " -pg" : '') . "\\\n" . - " -Werror -Wfatal-errors -Wall -Wextra -Wwrite-strings -Wno-clobbered -Wswitch-enum -Wconversion \\\n" . - ($self->{oTest}->{&TEST_VM} eq VM_U16 || $self->{oTest}->{&TEST_VM} eq VM_U18 ? - " -Wformat-signedness \\\n" : '') . - ($self->{oTest}->{&TEST_VM} eq VM_U18 ? - " -Wduplicated-branches -Wduplicated-cond \\\n" : '') . - # This warning appears to be broken on U12 even though the functionality is fine - ($self->{oTest}->{&TEST_VM} eq VM_U12 || $self->{oTest}->{&TEST_VM} eq VM_CO6 ? - " -Wno-missing-field-initializers \\\n" : '') . - # ($self->{oTest}->{&TEST_VM} ne VM_CO6 && $self->{oTest}->{&TEST_VM} ne VM_U12 && - # $self->{oTest}->{&TEST_MODULE} ne 'perl' && $self->{oTest}->{&TEST_NAME} ne 'exec' ? - # " -Wpedantic \\\n" : '') . - " -Wformat=2 -Wformat-nonliteral -Wstrict-prototypes -Wpointer-arith -Wvla \\\n" . - " `perl -MExtUtils::Embed -e ccopts`\n" . - "LDFLAGS=-lcrypto -lz" . (vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? " -lgcov" : '') . + "COMMONFLAGS=${strCommonFlags}\n" . + "BUILDFLAGS=${strBuildFlags}\n" . + "HARNESSFLAGS=${strHarnessFlags}\n" . + "TESTFLAGS=${strTestFlags}\n" . + "LDFLAGS=-lcrypto -lssl -lz" . + (vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? " -lgcov" : '') . (vmWithBackTrace($self->{oTest}->{&TEST_VM}) && $self->{bBackTrace} ? ' -lbacktrace' : '') . " `perl -MExtUtils::Embed -e ldopts`\n" . - 'TESTFLAGS=' . ($self->{oTest}->{&TEST_DEBUG_UNIT_SUPPRESS} ? '' : "-DDEBUG_UNIT") . - (vmWithBackTrace($self->{oTest}->{&TEST_VM}) && $self->{bBackTrace} ? ' -DWITH_BACKTRACE' : '') . - ($self->{oTest}->{&TEST_CDEF} ? " $self->{oTest}->{&TEST_CDEF}" : '') . - ($self->{bDebug} ? '' : " -DNDEBUG") . "\n" . - "\nSRCS=" . join(' ', @stryCFile) . "\n" . + "SRCS=" . join(' ', @stryCFile) . "\n" . "OBJS=\$(SRCS:.c=.o)\n" . "\n" . "test: \$(OBJS) test.o\n" . - "\t\$(CC) -o test \$(OBJS) test.o" . ($self->{bProfile} ? " -pg" : '') . " \$(LDFLAGS)\n" . + "\t\$(CC) -o test.bin \$(OBJS) test.o" . ($self->{bProfile} ? " -pg" : '') . " \$(LDFLAGS)\n" . "\n" . - "test.o: test.c\n" . - "\t\$(CC) \$(CFLAGS) \$(TESTFLAGS) -O0" . - ($self->{oTest}->{&TEST_VM} ne VM_U12 ? ' -ftree-coalesce-vars' : '') . - (vmCoverageC($self->{oTest}->{&TEST_VM}) && $self->{bCoverageUnit} ? - ' -fprofile-arcs -ftest-coverage' : '') . - " -c test.c\n" . - "\n" . - ".c.o:\n" . - "\t\$(CC) \$(CFLAGS) \$(TESTFLAGS) " . ($self->{bOptimize} ? '-O2' : '-O0') . " -c \$< -o \$@\n"; + "test.o: testflags test.c${strTestDepend}\n" . + "\t\$(CC) \$(COMMONFLAGS) \$(TESTFLAGS) -c test.c\n"; + + # Build C file dependencies + foreach my $strCFile (@stryCFile) + { + buildDependencyTreeSub( + $self->{oStorageTest}, $rhDependencyTree, $strCFile, $self->{strGCovPath}, ['', 'test']); + + $strMakefile .= + "\n" . substr($strCFile, 0, length($strCFile) - 2) . ".o:" . + ($strCFile =~ /^test\// ? " harnessflags" : " buildflags") . " $strCFile"; + + foreach my $strDepend (@{$rhDependencyTree->{$strCFile}{include}}) + { + $strMakefile .= + ' ' . ($rhDependencyTree->{$strDepend}{path} ne '' ? $rhDependencyTree->{$strDepend}{path} . '/' : '') . + $strDepend; + } + + $strMakefile .= + "\n" . + "\t\$(CC) \$(COMMONFLAGS)" . + ($strCFile =~ /^test\// ? " \$(HARNESSFLAGS)" : " \$(BUILDFLAGS)") . + " -c $strCFile -o " . substr($strCFile, 0, length($strCFile) - 2) . ".o\n"; + } $self->{oStorageTest}->put($self->{strGCovPath} . "/Makefile", $strMakefile); } @@ -531,7 +553,7 @@ sub end "module/$self->{oTest}->{&TEST_MODULE}/" . testRunName($self->{oTest}->{&TEST_NAME}, false) . 'Test'); # Generate coverage reports for the modules - my $strLCovExe = "lcov --config-file=$self->{strBackRestBase}/test/src/lcov.conf"; + my $strLCovExe = "lcov --config-file=$self->{strGCovPath}/test/lcov.conf"; my $strLCovOut = $self->{strGCovPath} . '/test.lcov'; my $strLCovOutTmp = $self->{strGCovPath} . '/test.tmp.lcov'; diff --git a/test/lib/pgBackRestTest/Common/ListTest.pm b/test/lib/pgBackRestTest/Common/ListTest.pm index 6d8c7a9dc..9daaa7637 100644 --- a/test/lib/pgBackRestTest/Common/ListTest.pm +++ b/test/lib/pgBackRestTest/Common/ListTest.pm @@ -28,6 +28,8 @@ use constant TEST_C => 'c'; push @EXPORT, qw(TEST_C); use constant TEST_CDEF => 'cdef'; push @EXPORT, qw(TEST_CDEF); +use constant TEST_CTESTDEF => 'ctestdef'; + push @EXPORT, qw(TEST_CTESTDEF); use constant TEST_CONTAINER => 'container'; push @EXPORT, qw(TEST_CONTAINER); use constant TEST_DEBUG_UNIT_SUPPRESS => TESTDEF_DEBUG_UNIT_SUPPRESS; @@ -151,6 +153,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_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/module/common/debugOnTest.c b/test/src/module/common/debugOnTest.c index aedae7f09..b89b434bb 100644 --- a/test/src/module/common/debugOnTest.c +++ b/test/src/module/common/debugOnTest.c @@ -115,11 +115,11 @@ testRun(void) testFunction1(99, false, 1.17, 0755); harnessLogResult( - "P00 DEBUG: module/common/debugOnTest::testFunction1: (paramInt: 99, paramBool: false, paramDouble: 1.17" + "P00 DEBUG: test/module/common/debugOnTest::testFunction1: (paramInt: 99, paramBool: false, paramDouble: 1.17" ", paramMode: 0755)\n" - "P00 TRACE: module/common/debugOnTest::testFunction2: (void)\n" - "P00 TRACE: module/common/debugOnTest::testFunction2: => void\n" - "P00 DEBUG: module/common/debugOnTest::testFunction1: => 1"); + "P00 TRACE: test/module/common/debugOnTest::testFunction2: (void)\n" + "P00 TRACE: test/module/common/debugOnTest::testFunction2: => void\n" + "P00 DEBUG: test/module/common/debugOnTest::testFunction1: => 1"); harnessLogLevelReset(); // ------------------------------------------------------------------------------------------------------------------------- diff --git a/test/src/module/common/errorTest.c b/test/src/module/common/errorTest.c index 32e3f3279..7d89396a9 100644 --- a/test/src/module/common/errorTest.c +++ b/test/src/module/common/errorTest.c @@ -183,11 +183,12 @@ testRun(void) CATCH(AssertError) { assert(errorCode() == AssertError.code); - assert(strcmp(errorFileName(), "module/common/errorTest.c") == 0); + assert(strcmp(errorFileName(), "test/module/common/errorTest.c") == 0); assert(strcmp(errorFunctionName(), "testTryRecurse") == 0); assert(errorFileLine() == 29); assert( - strcmp(errorStackTrace(), "module/common/errorTest:testTryRecurse:29:(test build required for parameters)") == 0); + strcmp(errorStackTrace(), + "test/module/common/errorTest:testTryRecurse:29:(test build required for parameters)") == 0); assert(strcmp(errorMessage(), "too many nested try blocks") == 0); assert(strcmp(errorName(), AssertError.name) == 0); assert(errorType() == &AssertError); diff --git a/test/src/module/common/exitTest.c b/test/src/module/common/exitTest.c index 6bd992b1e..4632bee83 100644 --- a/test/src/module/common/exitTest.c +++ b/test/src/module/common/exitTest.c @@ -85,7 +85,7 @@ testRun(void) harnessLogResultRegExp( "P00 ERROR\\: \\[122\\]\\: test debug error message\n" " STACK TRACE\\:\n" - " module\\/common\\/exitTest\\:testRun\\:.*\n" + " test\\/module\\/common\\/exitTest\\:testRun\\:.*\n" " test\\:main\\:.*\n"); } TRY_END(); @@ -103,7 +103,7 @@ testRun(void) harnessLogResultRegExp( "P00 ASSERT\\: \\[025\\]\\: test assert message\n" " STACK TRACE\\:\n" - " module/common/exitTest\\:testRun\\:.*\n" + " test/module/common/exitTest\\:testRun\\:.*\n" " test\\:main\\:.*\n"); } TRY_END();