2017-10-12 18:55:48 +02:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
C Test Wrapper
|
|
|
|
|
|
|
|
This wrapper runs the the C unit tests.
|
|
|
|
***********************************************************************************************************************************/
|
2019-01-06 15:52:59 +02:00
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
C files to be tested
|
|
|
|
|
|
|
|
The files are included directly so the test can see and manipulate variables and functions in the module without the need to extern.
|
|
|
|
If a .c file does not exist for a module then the header file will be included instead. They are included first so they won't see
|
|
|
|
the includes which are required for the test code.
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
{[C_INCLUDE]}
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
The test code is included directly so it can freely interact with the included C files
|
|
|
|
***********************************************************************************************************************************/
|
2019-01-06 17:42:44 +02:00
|
|
|
#include <signal.h>
|
2017-10-12 18:55:48 +02:00
|
|
|
#include <stdio.h>
|
2018-01-16 20:52:20 +02:00
|
|
|
#include <stdlib.h>
|
2017-10-12 18:55:48 +02:00
|
|
|
#include <string.h>
|
2018-01-16 20:52:20 +02:00
|
|
|
#include <sys/stat.h>
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2017-12-23 01:36:36 +02:00
|
|
|
#ifndef NO_ERROR
|
2018-05-18 17:57:32 +02:00
|
|
|
#include "common/debug.h"
|
2017-12-23 01:36:36 +02:00
|
|
|
#include "common/error.h"
|
|
|
|
#endif
|
|
|
|
|
2018-05-18 17:57:32 +02:00
|
|
|
#include "common/harnessDebug.h"
|
2017-10-12 18:55:48 +02:00
|
|
|
#include "common/harnessTest.h"
|
|
|
|
|
2018-01-16 20:52:20 +02:00
|
|
|
#ifndef NO_LOG
|
2018-07-21 00:51:42 +02:00
|
|
|
#include "common/harnessLog.h"
|
2018-07-21 01:03:46 +02:00
|
|
|
void harnessLogLevelDefaultSet(LogLevel logLevel);
|
2018-01-16 20:52:20 +02:00
|
|
|
#endif
|
|
|
|
|
2017-12-23 01:36:36 +02:00
|
|
|
#ifndef NO_MEM_CONTEXT
|
|
|
|
#include "common/memContext.h"
|
|
|
|
#endif
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
{[C_TEST_INCLUDE]}
|
|
|
|
|
2018-05-18 17:57:32 +02:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Include assert.h here since it is not generally used by tests
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#include <assert.h>
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
main - run the tests
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
int
|
2018-05-18 17:57:32 +02:00
|
|
|
main(int argListSize, const char *argList[])
|
2017-10-12 18:55:48 +02:00
|
|
|
{
|
2018-05-18 17:57:32 +02:00
|
|
|
// Basic sanity test on input parameters
|
|
|
|
if (argListSize == 0 || argList[0] == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "at least one argument expected");
|
|
|
|
fflush(stderr);
|
|
|
|
exit(25);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize stack trace for the harness
|
|
|
|
FUNCTION_HARNESS_INIT(argList[0]);
|
|
|
|
|
|
|
|
FUNCTION_HARNESS_BEGIN();
|
|
|
|
FUNCTION_HARNESS_PARAM(INT, argListSize);
|
|
|
|
FUNCTION_HARNESS_PARAM(CHARPY, argList);
|
|
|
|
FUNCTION_HARNESS_END();
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
2018-01-16 20:52:20 +02:00
|
|
|
// Set neutral umask for testing
|
|
|
|
umask(0000);
|
|
|
|
|
2019-01-06 17:42:44 +02:00
|
|
|
// Ignore SIGPIPE and check for EPIPE errors on write() instead
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
2017-12-23 05:36:01 +02:00
|
|
|
// Set globals
|
2018-05-18 17:57:32 +02:00
|
|
|
testExeSet(argList[0]);
|
2017-12-23 05:36:01 +02:00
|
|
|
testPathSet("{[C_TEST_PATH]}");
|
2018-11-20 22:48:56 +02:00
|
|
|
testRepoPathSet("{[C_TEST_REPO_PATH]}");
|
2018-09-16 21:58:46 +02:00
|
|
|
testExpectPathSet("{[C_TEST_EXPECT_PATH]}");
|
2017-12-23 05:36:01 +02:00
|
|
|
|
2018-07-21 01:03:46 +02:00
|
|
|
// Set default test log level
|
|
|
|
#ifndef NO_LOG
|
|
|
|
harnessLogLevelDefaultSet({[C_LOG_LEVEL_TEST]});
|
|
|
|
#endif
|
|
|
|
|
2017-10-12 18:55:48 +02:00
|
|
|
// Initialize tests
|
|
|
|
// run, selected
|
|
|
|
{[C_TEST_LIST]}
|
|
|
|
|
2017-12-23 01:36:36 +02:00
|
|
|
#ifndef NO_ERROR
|
|
|
|
TRY_BEGIN()
|
|
|
|
{
|
|
|
|
#endif
|
2018-01-16 20:52:20 +02:00
|
|
|
// Run the tests
|
|
|
|
testRun();
|
|
|
|
|
|
|
|
// End test run and make sure all tests completed
|
|
|
|
testComplete();
|
2017-10-12 18:55:48 +02:00
|
|
|
|
2018-01-16 20:52:20 +02:00
|
|
|
printf("\nTESTS COMPLETED SUCCESSFULLY\n");
|
|
|
|
fflush(stdout);
|
2017-12-23 01:36:36 +02:00
|
|
|
#ifndef NO_ERROR
|
|
|
|
}
|
|
|
|
CATCH_ANY()
|
|
|
|
{
|
2018-05-18 17:57:32 +02:00
|
|
|
fprintf(
|
|
|
|
stderr,
|
|
|
|
"\nTEST FAILED WITH %s:\n\n"
|
|
|
|
"--------------------------------------------------------------------------------\n"
|
|
|
|
"%s\n"
|
|
|
|
"--------------------------------------------------------------------------------\n"
|
|
|
|
"\nTHROWN AT:\n%s\n",
|
|
|
|
errorName(), errorMessage(), errorStackTrace());
|
|
|
|
|
2018-01-16 20:52:20 +02:00
|
|
|
fflush(stderr);
|
2018-05-18 17:57:32 +02:00
|
|
|
result = errorCode();
|
2017-12-23 01:36:36 +02:00
|
|
|
}
|
|
|
|
#ifndef NO_MEM_CONTEXT
|
|
|
|
FINALLY()
|
|
|
|
{
|
|
|
|
memContextFree(memContextTop());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
TRY_END();
|
|
|
|
#endif
|
2018-05-18 17:57:32 +02:00
|
|
|
|
|
|
|
FUNCTION_HARNESS_RESULT(INT, result);
|
2017-10-12 18:55:48 +02:00
|
|
|
}
|