1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-04 03:49:14 +02:00
pgbackrest/test/src/test.c

133 lines
4.2 KiB
C
Raw Normal View History

2017-10-12 18:55:48 +02:00
/***********************************************************************************************************************************
C Test Wrapper
This wrapper runs the the C unit tests.
***********************************************************************************************************************************/
/***********************************************************************************************************************************
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
***********************************************************************************************************************************/
#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
#ifndef NO_ERROR
#include "common/debug.h"
#include "common/error.h"
#endif
#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
#include "common/harnessLog.h"
void harnessLogLevelDefaultSet(LogLevel logLevel);
2018-01-16 20:52:20 +02:00
#endif
#ifndef NO_MEM_CONTEXT
#include "common/memContext.h"
#endif
2017-10-12 18:55:48 +02:00
{[C_TEST_INCLUDE]}
/***********************************************************************************************************************************
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
main(int argListSize, const char *argList[])
2017-10-12 18:55:48 +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);
// Ignore SIGPIPE and check for EPIPE errors on write() instead
signal(SIGPIPE, SIG_IGN);
2017-12-23 05:36:01 +02:00
// Set globals
testExeSet(argList[0]);
2017-12-23 05:36:01 +02:00
testPathSet("{[C_TEST_PATH]}");
testRepoPathSet("{[C_TEST_REPO_PATH]}");
testExpectPathSet("{[C_TEST_EXPECT_PATH]}");
2017-12-23 05:36:01 +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]}
#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);
#ifndef NO_ERROR
}
CATCH_ANY()
{
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);
result = errorCode();
}
#ifndef NO_MEM_CONTEXT
FINALLY()
{
memContextFree(memContextTop());
}
#endif
TRY_END();
#endif
FUNCTION_HARNESS_RESULT(INT, result);
2017-10-12 18:55:48 +02:00
}