You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-09-16 09:06:18 +02:00
Cleanup output to stderr in unit tests.
The unit tests were ignoring stderr but nothing being output there was important. Now a test will fail if there is anything on stderr. This makes it easier to work with -fsanitize, which outputs to stderr.
This commit is contained in:
@@ -722,12 +722,14 @@ sub run
|
|||||||
'') .
|
'') .
|
||||||
$self->{strMakeCmd} . " -j $self->{iBuildMax} -s 2>&1 && \\\n" .
|
$self->{strMakeCmd} . " -j $self->{iBuildMax} -s 2>&1 && \\\n" .
|
||||||
"rm ${strBuildProcessingFile} && \\\n" .
|
"rm ${strBuildProcessingFile} && \\\n" .
|
||||||
|
# Allow stderr to be copied to stderr and stdout
|
||||||
|
"exec 3>&1 && \\\n" .
|
||||||
# Test with valgrind when requested
|
# Test with valgrind when requested
|
||||||
($self->{bValgrindUnit} && $self->{oTest}->{&TEST_TYPE} ne TESTDEF_PERFORMANCE ?
|
($self->{bValgrindUnit} && $self->{oTest}->{&TEST_TYPE} ne TESTDEF_PERFORMANCE ?
|
||||||
'valgrind -q --gen-suppressions=all' .
|
'valgrind -q --gen-suppressions=all' .
|
||||||
($self->{oStorageTest}->exists($strValgrindSuppress) ? " --suppressions=${strValgrindSuppress}" : '') .
|
($self->{oStorageTest}->exists($strValgrindSuppress) ? " --suppressions=${strValgrindSuppress}" : '') .
|
||||||
" --exit-on-first-error=yes --leak-check=full --leak-resolution=high --error-exitcode=25" . ' ' : '') .
|
" --exit-on-first-error=yes --leak-check=full --leak-resolution=high --error-exitcode=25" . ' ' : '') .
|
||||||
"./test.bin 2>&1" .
|
"./test.bin 2>&1 1>&3 | tee /dev/stderr" .
|
||||||
($self->{oTest}->{&TEST_VM} ne VM_NONE ? "'" : '');
|
($self->{oTest}->{&TEST_VM} ne VM_NONE ? "'" : '');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -833,20 +835,20 @@ sub end
|
|||||||
my $fTestElapsedTime = ceil((gettimeofday() - $self->{oProcess}{start_time}) * 100) / 100;
|
my $fTestElapsedTime = ceil((gettimeofday() - $self->{oProcess}{start_time}) * 100) / 100;
|
||||||
|
|
||||||
# Output error
|
# Output error
|
||||||
if ($iExitStatus != 0)
|
if ($iExitStatus != 0 || (defined($oExecDone->{strErrorLog}) && $oExecDone->{strErrorLog} ne ''))
|
||||||
{
|
{
|
||||||
# Get stdout
|
# Get stdout
|
||||||
my $strOutput = trim($oExecDone->{strOutLog}) ? "STDOUT:\n" . trim($oExecDone->{strOutLog}) : '';
|
my $strOutput = trim($oExecDone->{strOutLog}) ? "STDOUT:\n" . trim($oExecDone->{strOutLog}) : '';
|
||||||
|
|
||||||
# Get stderr
|
# Get stderr
|
||||||
if (trim($oExecDone->{strSuppressedErrorLog}) ne '')
|
if (defined($oExecDone->{strErrorLog}) && trim($oExecDone->{strErrorLog}) ne '')
|
||||||
{
|
{
|
||||||
if ($strOutput ne '')
|
if ($strOutput ne '')
|
||||||
{
|
{
|
||||||
$strOutput .= "\n";
|
$strOutput .= "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$strOutput .= "STDERR:\n" . trim($oExecDone->{strSuppressedErrorLog});
|
$strOutput .= "STDERR:\n" . trim($oExecDone->{strErrorLog});
|
||||||
}
|
}
|
||||||
|
|
||||||
# If no stdout or stderr output something rather than a blank line
|
# If no stdout or stderr output something rather than a blank line
|
||||||
|
@@ -131,6 +131,14 @@ testBegin(const char *name)
|
|||||||
// Make sure there is nothing untested left in the log
|
// Make sure there is nothing untested left in the log
|
||||||
harnessLogFinal();
|
harnessLogFinal();
|
||||||
|
|
||||||
|
// It is possible the test left the cwd in a weird place
|
||||||
|
if (chdir(testPath()) != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: unable to chdir to test path '%s'\n", testPath());
|
||||||
|
fflush(stderr);
|
||||||
|
exit(255);
|
||||||
|
}
|
||||||
|
|
||||||
// Clear out the test directory so the next test starts clean
|
// Clear out the test directory so the next test starts clean
|
||||||
char buffer[2048];
|
char buffer[2048];
|
||||||
snprintf(
|
snprintf(
|
||||||
|
@@ -130,6 +130,7 @@ testRun(void)
|
|||||||
StringList *argList = strLstNew();
|
StringList *argList = strLstNew();
|
||||||
hrnCfgArgRawZ(argList, cfgOptConfig, TEST_PATH "/pgbackrest.conf");
|
hrnCfgArgRawZ(argList, cfgOptConfig, TEST_PATH "/pgbackrest.conf");
|
||||||
hrnCfgArgRawFmt(argList, cfgOptTlsServerPort, "%u", hrnServerPort(0));
|
hrnCfgArgRawFmt(argList, cfgOptTlsServerPort, "%u", hrnServerPort(0));
|
||||||
|
hrnCfgArgRawZ(argList, cfgOptLogLevelStderr, CFGOPTVAL_ARCHIVE_MODE_OFF_Z);
|
||||||
HRN_CFG_LOAD(cfgCmdServer, argList);
|
HRN_CFG_LOAD(cfgCmdServer, argList);
|
||||||
|
|
||||||
// Init exit signal handlers
|
// Init exit signal handlers
|
||||||
|
@@ -99,7 +99,7 @@ testSuite(CompressType type, const char *decompressCmd)
|
|||||||
TEST_TITLE("compressed output can be decompressed with command-line tool");
|
TEST_TITLE("compressed output can be decompressed with command-line tool");
|
||||||
|
|
||||||
storagePutP(storageNewWriteP(storageTest, STRDEF("test.cmp")), compressed);
|
storagePutP(storageNewWriteP(storageTest, STRDEF("test.cmp")), compressed);
|
||||||
HRN_SYSTEM_FMT("%s " TEST_PATH "/test.cmp > " TEST_PATH "/test.out", decompressCmd);
|
HRN_SYSTEM_FMT("%s " TEST_PATH "/test.cmp > " TEST_PATH "/test.out 2> /dev/null", decompressCmd);
|
||||||
TEST_RESULT_BOOL(bufEq(decompressed, storageGetP(storageNewReadP(storageTest, STRDEF("test.out")))), true, "check output");
|
TEST_RESULT_BOOL(bufEq(decompressed, storageGetP(storageNewReadP(storageTest, STRDEF("test.out")))), true, "check output");
|
||||||
|
|
||||||
TEST_RESULT_BOOL(
|
TEST_RESULT_BOOL(
|
||||||
|
@@ -403,6 +403,9 @@ testRun(void)
|
|||||||
{
|
{
|
||||||
HRN_FORK_CHILD_BEGIN(.expectedExitStatus = UnhandledError.code)
|
HRN_FORK_CHILD_BEGIN(.expectedExitStatus = UnhandledError.code)
|
||||||
{
|
{
|
||||||
|
// Redirect stderr to stdout (we do not care about the output here since coverage will tell us we hit the code)
|
||||||
|
stderr = stdout;
|
||||||
|
|
||||||
THROW(TestChildError, "does not get caught!");
|
THROW(TestChildError, "does not get caught!");
|
||||||
}
|
}
|
||||||
HRN_FORK_CHILD_END();
|
HRN_FORK_CHILD_END();
|
||||||
|
@@ -544,6 +544,7 @@ testRun(void)
|
|||||||
hrnCfgArgRawZ(argList, cfgOptLockPath, HRN_PATH "/lock");
|
hrnCfgArgRawZ(argList, cfgOptLockPath, HRN_PATH "/lock");
|
||||||
hrnCfgArgRawZ(argList, cfgOptLogPath, "/bogus");
|
hrnCfgArgRawZ(argList, cfgOptLogPath, "/bogus");
|
||||||
hrnCfgArgRawZ(argList, cfgOptLogLevelFile, "info");
|
hrnCfgArgRawZ(argList, cfgOptLogLevelFile, "info");
|
||||||
|
hrnCfgArgRawZ(argList, cfgOptLogLevelStderr, CFGOPTVAL_ARCHIVE_MODE_OFF_Z);
|
||||||
strLstAddZ(argList, CFGCMD_BACKUP);
|
strLstAddZ(argList, CFGCMD_BACKUP);
|
||||||
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for backup");
|
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config for backup");
|
||||||
lockRelease(true);
|
lockRelease(true);
|
||||||
@@ -563,6 +564,7 @@ testRun(void)
|
|||||||
strLstAddZ(argList, PROJECT_BIN);
|
strLstAddZ(argList, PROJECT_BIN);
|
||||||
hrnCfgArgRawZ(argList, cfgOptStanza, "db");
|
hrnCfgArgRawZ(argList, cfgOptStanza, "db");
|
||||||
hrnCfgArgRawZ(argList, cfgOptLockPath, HRN_PATH "/lock");
|
hrnCfgArgRawZ(argList, cfgOptLockPath, HRN_PATH "/lock");
|
||||||
|
hrnCfgArgRawZ(argList, cfgOptLogLevelStderr, CFGOPTVAL_ARCHIVE_MODE_OFF_Z);
|
||||||
strLstAddZ(argList, CFGCMD_EXPIRE);
|
strLstAddZ(argList, CFGCMD_EXPIRE);
|
||||||
|
|
||||||
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config");
|
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config");
|
||||||
|
Reference in New Issue
Block a user