1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-05-22 10:15:16 +02:00

Allow -DDEBUG_UNIT to be suppressed to test how debug macros behave.

This commit is contained in:
David Steele
2018-04-07 19:44:00 -04:00
parent 82751b3b51
commit b77b425096
7 changed files with 27 additions and 6 deletions
+4
View File
@@ -102,6 +102,10 @@
<release-item> <release-item>
<p>Improve logic for smart builds to include version changes.</p> <p>Improve logic for smart builds to include version changes.</p>
</release-item> </release-item>
<release-item>
<p>Allow <code>-DDEBUG_UNIT</code> to be suppressed to test how debug macros behave.</p>
</release-item>
</release-development-list> </release-development-list>
</release-test-list> </release-test-list>
</release> </release>
+7 -2
View File
@@ -46,6 +46,9 @@ use constant TESTDEF_C => 'c';
# #defines for C testing # #defines for C testing
use constant TESTDEF_CDEF => 'cdef'; use constant TESTDEF_CDEF => 'cdef';
push @EXPORT, qw(TESTDEF_CDEF); push @EXPORT, qw(TESTDEF_CDEF);
# Don't define DEBUG_UNIT for unit tests -- this is used to test unit test debugging macros
use constant TESTDEF_DEBUG_UNIT_SUPPRESS => 'debug-unit-supress';
push @EXPORT, qw(TESTDEF_DEBUG_UNIT_SUPPRESS);
# Determines if each run in a test will be run in a new container # Determines if each run in a test will be run in a new container
use constant TESTDEF_INDIVIDUAL => 'individual'; use constant TESTDEF_INDIVIDUAL => 'individual';
push @EXPORT, qw(TESTDEF_INDIVIDUAL); push @EXPORT, qw(TESTDEF_INDIVIDUAL);
@@ -139,6 +142,7 @@ my $oTestDef =
&TESTDEF_TOTAL => 2, &TESTDEF_TOTAL => 2,
&TESTDEF_C => true, &TESTDEF_C => true,
&TESTDEF_CDEF => '-DNDEBUG -DNO_LOG', &TESTDEF_CDEF => '-DNDEBUG -DNO_LOG',
&TESTDEF_DEBUG_UNIT_SUPPRESS => true,
&TESTDEF_COVERAGE => &TESTDEF_COVERAGE =>
{ {
@@ -182,6 +186,7 @@ my $oTestDef =
&TESTDEF_TOTAL => 2, &TESTDEF_TOTAL => 2,
&TESTDEF_C => true, &TESTDEF_C => true,
&TESTDEF_CDEF => '-DNDEBUG -DNO_LOG', &TESTDEF_CDEF => '-DNDEBUG -DNO_LOG',
&TESTDEF_DEBUG_UNIT_SUPPRESS => true,
&TESTDEF_COVERAGE => &TESTDEF_COVERAGE =>
{ {
@@ -962,8 +967,8 @@ foreach my $hModule (@{$oTestDef->{&TESTDEF_MODULE}})
# 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_C, TESTDEF_CDEF, TESTDEF_CONTAINER, TESTDEF_EXPECT, TESTDEF_DB, TESTDEF_INDIVIDUAL, TESTDEF_PERL_REQ, TESTDEF_C, TESTDEF_CDEF, TESTDEF_CONTAINER, TESTDEF_DEBUG_UNIT_SUPPRESS, TESTDEF_EXPECT, TESTDEF_DB, TESTDEF_INDIVIDUAL,
TESTDEF_VM) TESTDEF_PERL_REQ, TESTDEF_VM)
{ {
$hTestDefHash->{$strModule}{$strTest}{$strVar} = coalesce( $hTestDefHash->{$strModule}{$strTest}{$strVar} = coalesce(
$hModuleTest->{$strVar}, $hModule->{$strVar}, $strVar eq TESTDEF_VM ? undef : false); $hModuleTest->{$strVar}, $hModule->{$strVar}, $strVar eq TESTDEF_VM ? undef : false);
+2 -1
View File
@@ -351,7 +351,8 @@ sub run
" `perl -MExtUtils::Embed -e ccopts`\n" . " `perl -MExtUtils::Embed -e ccopts`\n" .
"LDFLAGS=-lcrypto" . (vmCoverage($self->{oTest}->{&TEST_VM}) ? " -lgcov" : '') . "LDFLAGS=-lcrypto" . (vmCoverage($self->{oTest}->{&TEST_VM}) ? " -lgcov" : '') .
" `perl -MExtUtils::Embed -e ldopts`\n" . " `perl -MExtUtils::Embed -e ldopts`\n" .
'TESTFLAGS=-DDEBUG_UNIT' . ($self->{oTest}->{&TEST_CDEF} ? " $self->{oTest}->{&TEST_CDEF}" : '') . 'TESTFLAGS=' . ($self->{oTest}->{&TEST_DEBUG_UNIT_SUPPRESS} ? '' : "-DDEBUG_UNIT ") .
($self->{oTest}->{&TEST_CDEF} ? "$self->{oTest}->{&TEST_CDEF}" : '') .
"\n" . "\n" .
"\nSRCS=" . join(' ', @stryCFile) . "\n" . "\nSRCS=" . join(' ', @stryCFile) . "\n" .
"OBJS=\$(SRCS:.c=.o)\n" . "OBJS=\$(SRCS:.c=.o)\n" .
@@ -30,6 +30,8 @@ use constant TEST_CDEF => 'cdef';
push @EXPORT, qw(TEST_CDEF); push @EXPORT, qw(TEST_CDEF);
use constant TEST_CONTAINER => 'container'; use constant TEST_CONTAINER => 'container';
push @EXPORT, qw(TEST_CONTAINER); push @EXPORT, qw(TEST_CONTAINER);
use constant TEST_DEBUG_UNIT_SUPPRESS => TESTDEF_DEBUG_UNIT_SUPPRESS;
push @EXPORT, qw(TEST_DEBUG_UNIT_SUPPRESS);
use constant TEST_MODULE => 'module'; use constant TEST_MODULE => 'module';
push @EXPORT, qw(TEST_MODULE); push @EXPORT, qw(TEST_MODULE);
use constant TEST_NAME => 'test'; use constant TEST_NAME => 'test';
@@ -147,6 +149,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_CDEF}, &TEST_CDEF => $hTest->{&TESTDEF_CDEF},
&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},
&TEST_PGSQL_BIN => $strPgSqlBin, &TEST_PGSQL_BIN => $strPgSqlBin,
+8
View File
@@ -19,6 +19,14 @@ void testComplete();
const char *testPath(); const char *testPath();
void testPathSet(const char *testPathParam); void testPathSet(const char *testPathParam);
/***********************************************************************************************************************************
Convert a macro to a string -- handy for testing debug macros
***********************************************************************************************************************************/
#define MACRO_TO_STR_INNER(macro) \
#macro
#define MACRO_TO_STR(macro) \
MACRO_TO_STR_INNER(macro)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Maximum size of a formatted result in the TEST_RESULT macro. Strings don't count as they are output directly, so this only applies Maximum size of a formatted result in the TEST_RESULT macro. Strings don't count as they are output directly, so this only applies
to the formatting of bools, ints, floats, etc. This should be plenty of room for any of those types. to the formatting of bools, ints, floats, etc. This should be plenty of room for any of those types.
+2 -2
View File
@@ -23,7 +23,7 @@ testRun()
// ----------------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("DEBUG_UNIT_EXTERN")) if (testBegin("DEBUG_UNIT_EXTERN"))
{ {
const char *debugUnitExtern = "" DEBUG_UNIT_EXTERN ""; const char *debugUnitExtern = MACRO_TO_STR(DEBUG_UNIT_EXTERN);
TEST_RESULT_STR(debugUnitExtern, "", "DEBUG_UNIT_EXTERN is static"); TEST_RESULT_STR(debugUnitExtern, "static", "DEBUG_UNIT_EXTERN is static");
} }
} }
+1 -1
View File
@@ -23,7 +23,7 @@ testRun()
// ----------------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("DEBUG_UNIT_EXTERN")) if (testBegin("DEBUG_UNIT_EXTERN"))
{ {
const char *debugUnitExtern = "" DEBUG_UNIT_EXTERN ""; const char *debugUnitExtern = MACRO_TO_STR(DEBUG_UNIT_EXTERN);
TEST_RESULT_STR(debugUnitExtern, "", "DEBUG_UNIT_EXTERN is blank (extern)"); TEST_RESULT_STR(debugUnitExtern, "", "DEBUG_UNIT_EXTERN is blank (extern)");
} }
} }