82 lines
1.8 KiB
C
82 lines
1.8 KiB
C
#include <argp.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unity/unity.h>
|
|
|
|
void setUp() { return; }
|
|
|
|
void tearDown(void)
|
|
{
|
|
printf("\n-----------------------------------------------------\n");
|
|
return;
|
|
}
|
|
|
|
static char doc[] = "sched_test";
|
|
static char args_doc[] = "";
|
|
|
|
#define MAX_TESTS (256)
|
|
|
|
struct arguments {
|
|
int ntests;
|
|
char* tests[MAX_TESTS];
|
|
};
|
|
|
|
static struct argp_option options[] = {
|
|
{ "run", 't', "STR", 0, "run test" },
|
|
{ 0 }
|
|
};
|
|
|
|
static error_t parse_opt(int key, char* arg, struct argp_state* state)
|
|
{
|
|
struct arguments* arguments = state->input;
|
|
|
|
switch (key) {
|
|
case 't':
|
|
if (arguments->ntests >= MAX_TESTS) {
|
|
fprintf(stderr, "Too many tests\n");
|
|
exit(-1);
|
|
}
|
|
arguments->tests[arguments->ntests] = arg;
|
|
arguments->ntests++;
|
|
break;
|
|
default:
|
|
return ARGP_ERR_UNKNOWN;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct argp argp = { options, parse_opt, args_doc, doc };
|
|
struct arguments arguments;
|
|
|
|
static int check_test(struct arguments* args, char* x)
|
|
{
|
|
int i;
|
|
|
|
if (args->ntests == 0) {
|
|
return 1;
|
|
}
|
|
for (i = 0; i < args->ntests; i++) {
|
|
if (strcmp(x, args->tests[i]) == 0) {
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#define TEST(x) \
|
|
do { \
|
|
if (check_test(&arguments, #x)) { \
|
|
x(); \
|
|
} \
|
|
} while (0)
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
|
|
|
UNITY_BEGIN();
|
|
|
|
return UNITY_END();
|
|
}
|