improve xkvmgr and testsuite for scheduler
This commit is contained in:
parent
2ee87d4ee6
commit
598d381379
10 changed files with 327 additions and 64 deletions
82
src/scheduler/testsuite/test.c
Normal file
82
src/scheduler/testsuite/test.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
#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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue