2018-01-17 09:15:51 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Exit Routines
|
|
|
|
***********************************************************************************************************************************/
|
2018-04-12 20:42:26 -04:00
|
|
|
#include "common/error.h"
|
2018-05-18 11:57:32 -04:00
|
|
|
#include "common/log.h"
|
2018-01-17 09:15:51 -05:00
|
|
|
#include "config/config.h"
|
2020-08-24 14:51:08 -04:00
|
|
|
#include "version.h"
|
2018-01-17 09:15:51 -05:00
|
|
|
|
2020-08-24 14:51:08 -04:00
|
|
|
#include "common/harnessConfig.h"
|
2018-05-06 08:56:42 -04:00
|
|
|
#include "common/harnessFork.h"
|
|
|
|
|
2018-01-17 09:15:51 -05:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Run
|
|
|
|
***********************************************************************************************************************************/
|
2018-01-31 18:22:25 -05:00
|
|
|
void
|
2018-08-03 19:19:14 -04:00
|
|
|
testRun(void)
|
2018-01-17 09:15:51 -05:00
|
|
|
{
|
2018-05-18 11:57:32 -04:00
|
|
|
FUNCTION_HARNESS_VOID();
|
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("exitSignalName()"))
|
|
|
|
{
|
2019-12-26 18:08:27 -07:00
|
|
|
TEST_RESULT_Z(exitSignalName(signalTypeHup), "HUP", "SIGHUP name");
|
|
|
|
TEST_RESULT_Z(exitSignalName(signalTypeInt), "INT", "SIGINT name");
|
|
|
|
TEST_RESULT_Z(exitSignalName(signalTypeTerm), "TERM", "SIGTERM name");
|
2018-04-12 20:42:26 -04:00
|
|
|
TEST_ERROR(exitSignalName(signalTypeNone), AssertError, "no name for signal none");
|
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("exitInit() and exitOnSignal()"))
|
|
|
|
{
|
2020-10-20 14:54:28 -04:00
|
|
|
harnessCfgLoad(cfgCmdHelp, strLstNew());
|
2020-01-23 14:15:58 -07:00
|
|
|
|
2018-05-06 08:56:42 -04:00
|
|
|
HARNESS_FORK_BEGIN()
|
2018-04-12 20:42:26 -04:00
|
|
|
{
|
2019-02-27 18:07:16 +02:00
|
|
|
HARNESS_FORK_CHILD_BEGIN(errorTypeCode(&TermError), false)
|
2018-05-06 08:56:42 -04:00
|
|
|
{
|
|
|
|
exitInit();
|
|
|
|
raise(SIGTERM);
|
|
|
|
}
|
2019-05-11 14:51:51 -04:00
|
|
|
HARNESS_FORK_CHILD_END(); // {uncoverable - signal is raised in block}
|
2018-04-12 20:42:26 -04:00
|
|
|
}
|
2018-05-06 08:56:42 -04:00
|
|
|
HARNESS_FORK_END();
|
2018-04-12 20:42:26 -04:00
|
|
|
}
|
|
|
|
|
2018-01-17 09:15:51 -05:00
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("exitSafe()"))
|
|
|
|
{
|
2020-10-20 14:54:28 -04:00
|
|
|
harnessCfgLoad(cfgCmdHelp, strLstNew());
|
2020-01-15 12:24:58 -07:00
|
|
|
cfgCommandSet(cfgCmdNone, cfgCmdRoleDefault);
|
2018-04-12 20:42:26 -04:00
|
|
|
|
|
|
|
TEST_RESULT_INT(exitSafe(0, false, signalTypeNone), 0, "exit with no command")
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2020-10-20 14:54:28 -04:00
|
|
|
StringList *argList = strLstNew();
|
|
|
|
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
|
|
|
hrnCfgArgRawNegate(argList, cfgOptLogTimestamp);
|
|
|
|
harnessCfgLoad(cfgCmdArchivePush, argList);
|
2018-01-17 09:15:51 -05:00
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
TEST_RESULT_INT(exitSafe(0, false, signalTypeNone), 0, "exit with no error")
|
2018-07-20 18:51:42 -04:00
|
|
|
harnessLogResult("P00 INFO: archive-push command end: completed successfully");
|
2018-01-17 09:15:51 -05:00
|
|
|
|
2018-09-04 21:46:41 -04:00
|
|
|
TEST_RESULT_INT(exitSafe(1, false, signalTypeNone), 1, "exit with no error")
|
|
|
|
harnessLogResult("P00 INFO: archive-push command end: completed successfully");
|
|
|
|
|
2018-01-17 09:15:51 -05:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TRY_BEGIN()
|
|
|
|
{
|
|
|
|
THROW(RuntimeError, "test error message");
|
|
|
|
}
|
|
|
|
CATCH_ANY()
|
|
|
|
{
|
2018-04-12 20:42:26 -04:00
|
|
|
exitSafe(0, true, signalTypeNone);
|
2018-07-20 18:51:42 -04:00
|
|
|
harnessLogResult(
|
2018-02-08 16:11:47 -05:00
|
|
|
"P00 ERROR: [122]: test error message\n"
|
|
|
|
"P00 INFO: archive-push command end: aborted with exception [122]");
|
2018-01-17 09:15:51 -05:00
|
|
|
}
|
|
|
|
TRY_END();
|
2018-04-12 20:42:26 -04:00
|
|
|
|
2018-05-18 11:57:32 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
2020-10-20 14:54:28 -04:00
|
|
|
argList = strLstNew();
|
2020-08-24 14:51:08 -04:00
|
|
|
strLstAddZ(argList, PROJECT_BIN);
|
|
|
|
strLstAddZ(argList, "--" CFGOPT_STANZA "=test");
|
|
|
|
strLstAddZ(argList, "--" CFGOPT_PROCESS_MAX "=4");
|
|
|
|
strLstAddZ(argList, CFGCMD_ARCHIVE_PUSH ":" CONFIG_COMMAND_ROLE_ASYNC);
|
|
|
|
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
|
|
|
|
|
2018-07-20 18:51:42 -04:00
|
|
|
harnessLogLevelSet(logLevelDebug);
|
2018-05-18 11:57:32 -04:00
|
|
|
|
|
|
|
TRY_BEGIN()
|
|
|
|
{
|
|
|
|
THROW(RuntimeError, "test debug error message");
|
|
|
|
}
|
|
|
|
CATCH_ANY()
|
|
|
|
{
|
|
|
|
exitSafe(0, true, signalTypeNone);
|
2020-08-24 14:51:08 -04:00
|
|
|
harnessLogResult(
|
|
|
|
"P00 DEBUG: common/exit::exitSafe: (result: 0, error: true, signalType: 0)\n"
|
|
|
|
"P00 ERROR: [122]: test debug error message\n"
|
|
|
|
" --------------------------------------------------------------------\n"
|
|
|
|
" If SUBMITTING AN ISSUE please provide the following information:\n"
|
|
|
|
" \n"
|
|
|
|
" version: " PROJECT_VERSION "\n"
|
|
|
|
" command: archive-push:async\n"
|
2020-11-23 12:41:54 -05:00
|
|
|
" options: --exec-id=1-test --process-max=4 --stanza=test\n"
|
2020-08-24 14:51:08 -04:00
|
|
|
" \n"
|
|
|
|
" stack trace:\n"
|
2020-10-20 14:54:28 -04:00
|
|
|
" test/module/common/exitTest:testRun:92:(void)\n"
|
2020-08-24 14:51:08 -04:00
|
|
|
" test:main:(argListSize: 1, argList: (char *[]))\n"
|
|
|
|
" --------------------------------------------------------------------\n"
|
|
|
|
"P00 INFO: archive-push:async command end: aborted with exception [122]\n"
|
|
|
|
"P00 DEBUG: common/lock::lockRelease: (failOnNoLock: false)\n"
|
|
|
|
"P00 DEBUG: common/lock::lockRelease: => false\n"
|
|
|
|
"P00 DEBUG: common/exit::exitSafe: => 122");
|
2018-05-18 11:57:32 -04:00
|
|
|
}
|
|
|
|
TRY_END();
|
|
|
|
|
2018-07-20 19:03:46 -04:00
|
|
|
harnessLogLevelReset();
|
2018-05-18 11:57:32 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TRY_BEGIN()
|
|
|
|
{
|
|
|
|
THROW(AssertError, "test assert message");
|
|
|
|
}
|
|
|
|
CATCH_ANY()
|
|
|
|
{
|
|
|
|
exitSafe(0, true, signalTypeNone);
|
2020-08-24 14:51:08 -04:00
|
|
|
harnessLogResult(
|
|
|
|
"P00 ASSERT: [025]: test assert message\n"
|
|
|
|
" --------------------------------------------------------------------\n"
|
|
|
|
" If SUBMITTING AN ISSUE please provide the following information:\n"
|
|
|
|
" \n"
|
|
|
|
" version: " PROJECT_VERSION "\n"
|
|
|
|
" command: archive-push:async\n"
|
2020-11-23 12:41:54 -05:00
|
|
|
" options: --exec-id=1-test --process-max=4 --stanza=test\n"
|
2020-08-24 14:51:08 -04:00
|
|
|
" \n"
|
|
|
|
" stack trace:\n"
|
2020-10-20 14:54:28 -04:00
|
|
|
" test/module/common/exitTest:testRun:123:(void)\n"
|
2020-08-24 14:51:08 -04:00
|
|
|
" test:main:(argListSize: 1, argList: (char *[]))\n"
|
|
|
|
" --------------------------------------------------------------------\n"
|
|
|
|
"P00 INFO: archive-push:async command end: aborted with exception [025]");
|
2018-05-18 11:57:32 -04:00
|
|
|
}
|
|
|
|
TRY_END();
|
|
|
|
|
2018-04-12 20:42:26 -04:00
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_RESULT_INT(
|
|
|
|
exitSafe(errorTypeCode(&TermError), false, signalTypeNone), errorTypeCode(&TermError), "exit on term with no signal");
|
2020-08-24 14:51:08 -04:00
|
|
|
harnessLogResult("P00 INFO: archive-push:async command end: terminated on signal from child process");
|
2018-04-12 20:42:26 -04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------------------------------------------------------
|
|
|
|
TEST_RESULT_INT(
|
|
|
|
exitSafe(errorTypeCode(&TermError), false, signalTypeTerm), errorTypeCode(&TermError), "exit on term with SIGTERM");
|
2020-08-24 14:51:08 -04:00
|
|
|
harnessLogResult("P00 INFO: archive-push:async command end: terminated on signal [SIGTERM]");
|
2018-01-17 09:15:51 -05:00
|
|
|
}
|
2018-05-18 11:57:32 -04:00
|
|
|
|
|
|
|
FUNCTION_HARNESS_RESULT_VOID();
|
2018-01-17 09:15:51 -05:00
|
|
|
}
|