From 7b6be113ea58b18113cbe0c8996d96480bd0d3c1 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 7 May 2008 10:56:36 +0200 Subject: [PATCH] Add commandline options support for testcases. This adds a simple possibility to run the test not in the fork mode. --- tests/CMakeLists.txt | 2 +- tests/cmdline.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ tests/support.h | 11 +++++++- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 tests/cmdline.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 67a0a83b1..f4772b786 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,7 +10,7 @@ include_directories( ) # create test library -add_library(${SUPPORT_LIBRARY} STATIC support.c) +add_library(${SUPPORT_LIBRARY} STATIC support.c cmdline.c) target_link_libraries(${SUPPORT_LIBRARY} ${CHECK_LIBRARIES} ${CSYNC_LIBRARY} ${CSTDLIB_LIBRARY}) set(TEST_TARGET_LIBRARIES ${SUPPORT_LIBRARY}) diff --git a/tests/cmdline.c b/tests/cmdline.c new file mode 100644 index 000000000..1f606ee04 --- /dev/null +++ b/tests/cmdline.c @@ -0,0 +1,60 @@ +#include + +#include "support.h" + +const char *argp_program_version = "check test 0.1"; +const char *argp_program_bug_address = ""; + +static char **cmdline; + +/* Program documentation. */ +static char doc[] = "check test"; + +/* The options we understand. */ +static struct argp_option options[] = { + { + .name = "no-fork", + .key = 'n', + .arg = NULL, + .flags = 0, + .doc = "Don't fork the testcases", + .group = 0 + }, + {NULL, 0, NULL, 0, NULL, 0} +}; + +/* Parse a single option. */ +static error_t parse_opt (int key, char *arg, struct argp_state *state) { + /* Get the input argument from argp_parse, which we + * know is a pointer to our arguments structure. + */ + struct argument_s *arguments = state->input; + + switch (key) { + case 'n': + arguments->nofork = 1; + break; + case ARGP_KEY_ARG: + /* End processing here. */ + cmdline = &state->argv [state->next - 1]; + state->next = state->argc; + break; + default: + return ARGP_ERR_UNKNOWN; + } + + return 0; +} + +/* Our argp parser. */ +/* static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; */ +static struct argp argp = {options, parse_opt, NULL, doc, NULL, NULL, NULL}; + +void cmdline_parse(int argc, char **argv, struct argument_s *arguments) { + /* + * Parse our arguments; every option seen by parse_opt will + * be reflected in arguments. + */ + argp_parse(&argp, argc, argv, 0, 0, arguments); +} + diff --git a/tests/support.h b/tests/support.h index fa10387d2..f9f6af629 100644 --- a/tests/support.h +++ b/tests/support.h @@ -7,11 +7,20 @@ #include "csync_private.h" +/* Used by main to communicate with parse_opt. */ +struct argument_s { + char *args[2]; /* SOURCE and DESTINATION */ + int nofork; +}; + +void cmdline_parse(int argc, char **argv, struct argument_s *arguments); + /* create_case() with timeout of 30seconds (default) */ void create_case(Suite *s, const char *name, TFun function); /* create_case() with timeout of 30seconds (default) and fixture */ -void create_case_fixture(Suite *s, const char *name, TFun function, void (*setup)(void), void (*teardown)(void)); +void create_case_fixture(Suite *s, const char *name, TFun function, + void (*setup)(void), void (*teardown)(void)); /* * create_case_timeout() allow to specific a specific timeout - intended for