142 lines
3.5 KiB
C
142 lines
3.5 KiB
C
#include <stdlib.h>
|
|
#include <getopt.h>
|
|
#include <stdio.h>
|
|
#include <check.h>
|
|
#include <getopt.h>
|
|
|
|
|
|
typedef Suite *(*suite_func)(void);
|
|
|
|
extern Suite *bitvec_suite(void);
|
|
extern Suite *bcd_suite(void);
|
|
extern Suite *hex_suite(void);
|
|
extern Suite *container_of_suite(void);
|
|
extern Suite *read_file_suite(void);
|
|
extern Suite *pack_suite(void);
|
|
extern Suite *logging_suite(void);
|
|
extern Suite *threadqueue_suite(void);
|
|
extern Suite *buffer_suite(void);
|
|
extern Suite *clock_suite(void);
|
|
extern Suite *seq_suite(void);
|
|
extern Suite *sat_math_suite(void);
|
|
extern Suite *timers_suite(void);
|
|
extern Suite *mbuf_suite(void);
|
|
extern Suite *human_bytesz_suite(void);
|
|
extern Suite *dbuf_suite(void);
|
|
extern Suite *sprintb_suite(void);
|
|
extern Suite *strv_suite(void);
|
|
extern Suite *ratelimit_suite(void);
|
|
extern Suite *htable_suite(void);
|
|
extern Suite *heapsort_suite(void);
|
|
extern Suite *dstr_suite(void);
|
|
extern Suite *val_str_suite(void);
|
|
extern Suite *ticket_lock_suite(void);
|
|
extern Suite *restart_counter_suite(void);
|
|
extern Suite *iomux_suite(void);
|
|
extern Suite *iomux_signal_suite(void);
|
|
|
|
static suite_func suites[] = {
|
|
bitvec_suite,
|
|
bcd_suite,
|
|
hex_suite,
|
|
container_of_suite,
|
|
read_file_suite,
|
|
pack_suite,
|
|
logging_suite,
|
|
buffer_suite,
|
|
seq_suite,
|
|
sat_math_suite,
|
|
timers_suite,
|
|
mbuf_suite,
|
|
human_bytesz_suite,
|
|
dbuf_suite,
|
|
sprintb_suite,
|
|
strv_suite,
|
|
ratelimit_suite,
|
|
htable_suite,
|
|
clock_suite,
|
|
threadqueue_suite,
|
|
heapsort_suite,
|
|
dstr_suite,
|
|
val_str_suite,
|
|
ticket_lock_suite,
|
|
restart_counter_suite,
|
|
iomux_suite,
|
|
iomux_signal_suite
|
|
|
|
};
|
|
|
|
void
|
|
usage(const char *progname)
|
|
{
|
|
printf("Usage: %s [-h] [-k testcase] [-x]\n", progname);
|
|
puts("\t-h This help");
|
|
puts("\t-k testcase Run the given testcase");
|
|
puts("\t-x Ouput results in XML to the file result.xml");
|
|
}
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
int xml_output = 0;
|
|
int c;
|
|
const char *test_case = NULL;
|
|
|
|
while ((c = getopt(argc, argv, "xk:h")) != -1) {
|
|
switch (c) {
|
|
case 'x':
|
|
xml_output = 1;
|
|
break;
|
|
case 'k':
|
|
test_case = optarg;
|
|
break;
|
|
default:
|
|
printf("Unknown option %c\n", c);
|
|
/*fallthrough*/
|
|
case 'h':
|
|
usage(argv[0]);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
int number_run;
|
|
int number_failed = 0;
|
|
size_t i;
|
|
|
|
SRunner *sr = srunner_create (NULL);
|
|
if (xml_output)
|
|
srunner_set_xml(sr, "result.xml");
|
|
|
|
//set the environment variable CK_FORK=no which means don't fork().
|
|
//anything else means to fork()
|
|
srunner_set_fork_status(sr, CK_FORK_GETENV);
|
|
|
|
|
|
for(i = 0; i < sizeof suites/sizeof suites[0]; i++) {
|
|
srunner_add_suite(sr, suites[i]());
|
|
}
|
|
|
|
if (test_case == NULL) {
|
|
srunner_run_all (sr, CK_VERBOSE);
|
|
} else {
|
|
#if CHECK_MAJOR_VERSION == 0 && CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION <= 8
|
|
printf("Sorry, this libcheck version does not support running individual test cases");
|
|
return 3;
|
|
#else
|
|
printf("Running %s only\n", test_case);
|
|
srunner_run(sr, NULL, test_case, CK_VERBOSE);
|
|
#endif
|
|
}
|
|
number_run = srunner_ntests_run(sr);
|
|
number_failed = srunner_ntests_failed (sr);
|
|
srunner_free (sr);
|
|
|
|
if (!number_run)
|
|
puts("ERROR: no tests were run");
|
|
if (number_failed)
|
|
printf("ERROR: %d tests failed\n", number_failed);
|
|
|
|
return (number_failed != 0) ;
|
|
}
|