Commit 625cdba3 authored by Chris Müller's avatar Chris Müller
Browse files

rearrange some structs and functions in unittest.c

parent 983d367a
......@@ -13,12 +13,13 @@
#include <getopt.h>
#define COLOR(condition, color, string) (condition ? color string CRY_NORMAL : string)
// Internal helper functions
static void print_usage(FILE* stream, const char* programm, int exit_code);
static int monitor_testprocess(pid_t worker_pid, unsigned int timeout);
static void print_verbose_testprocess_status(const char* desc, int return_code, suseconds_t time);
static void print_testprocess_status(int return_code);
static void print_usage(FILE* stream, const char* programm, int exit_code);
#define COLOR(condition, color, string) (condition ? color string CRY_NORMAL : string)
// Current Errorfile
static char* Testlog = 0;
......@@ -29,14 +30,6 @@ static int Repeat = 1;
static int Verbose = 0;
static const char* Filter = 0;
static struct option Option[] = {
{"help", no_argument, 0, 'h'},
{"colors", no_argument, 0, 'c'},
{"verbose", no_argument, 0, 'v'},
{"repeat", optional_argument, 0, 'r'},
{"filter", optional_argument, 0, 'f'}
};
// Statistics
static int TestCaseNumber = 0;
static int SegfaultNumber = 0;
......@@ -44,33 +37,43 @@ static int TimeoutNumber = 0;
static int FailureNumber = 0;
static int SkippedNumber = 0;
void
cry_unittest_initialize(int argc, char** argv)
{
int ch = 0;
time_t current_time = time(0);
struct tm* time_struct = localtime(&current_time);
while( (ch = getopt_long(argc, argv, "vhcr:f:", Option, 0)) != -1 ) {
static struct option options[] = {
{"help", no_argument, 0, 'h'},
{"colors", no_argument, 0, 'c'},
{"verbose", no_argument, 0, 'v'},
{"repeat", optional_argument, 0, 'r'},
{"filter", optional_argument, 0, 'f'}
};
while( (ch = getopt_long(argc, argv, "vhcr:f:", options, 0)) != -1 ) {
switch(ch) {
case 'h':
print_usage(stdout, argv[0], EXIT_SUCCESS);
case 'c':
Colors = 1;
break;
case 'r':
Repeat = atoi(optarg);
break;
case 'f':
Filter = optarg;
break;
case 'v':
Verbose = 1;
break;
case '?':
print_usage(stderr, argv[0], EXIT_FAILURE);
default:
abort();
case 'h':
print_usage(stdout, argv[0], EXIT_SUCCESS);
case 'c':
Colors = 1;
break;
case 'r':
Repeat = atoi(optarg);
break;
case 'f':
Filter = optarg;
break;
case 'v':
Verbose = 1;
break;
case '?':
print_usage(stderr, argv[0], EXIT_FAILURE);
default:
abort();
}
}
......@@ -83,18 +86,7 @@ cry_unittest_initialize(int argc, char** argv)
}
}
void
print_usage(FILE* stream, const char* programm, int exit_code)
{
fprintf(stream, "Usage: %s options\n", programm);
fprintf(stream,
" -h --help Display this usage information for your testcase.\n"
" -c --colors Enable color support for test output.\n"
" -v --verbose Show more details about the testing progress.\n"
" -r --repeat INT Set number of repeats for each testcase.\n"
" -f --filter REGEX Set a regular expression filter for all testcases.\n");
exit(exit_code);
}
void cry_unittest_finalize(void)
{
......@@ -117,10 +109,11 @@ void cry_unittest_finalize(void)
printf("\n");
fclose(log);
cry_free(Testlog);
}
void
cry_unittest_run(const char* desc, cry_modulechecker handler, const_pointer data, unsigned int timeout)
{
......@@ -158,6 +151,21 @@ cry_unittest_run(const char* desc, cry_modulechecker handler, const_pointer data
}
}
void
print_usage(FILE* stream, const char* programm, int exit_code)
{
fprintf(stream, "Usage: %s options\n", programm);
fprintf(stream,
" -h --help Display this usage information for your testcase.\n"
" -c --colors Enable color support for test output.\n"
" -v --verbose Show more details about the testing progress.\n"
" -r --repeat INT Set number of repeats for each testcase.\n"
" -f --filter REGEX Set a regular expression filter for all testcases.\n");
exit(exit_code);
}
int
......@@ -176,7 +184,6 @@ monitor_testprocess(pid_t worker_pid, unsigned int timeout)
return SIGINT;
} else
return SIGILL;
} else {
sleep(timeout);
kill(worker_pid, SIGINT);
......@@ -213,6 +220,8 @@ print_verbose_testprocess_status(const char* desc, int return_code, suseconds_t
printf("\n");
}
void
print_testprocess_status(int return_code)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment