diff options
author | Thomas Wood <thomas.wood@intel.com> | 2015-02-18 16:19:59 +0000 |
---|---|---|
committer | Thomas Wood <thomas.wood@intel.com> | 2015-02-25 16:48:25 +0000 |
commit | 8fb19782f82f25249aaed0ff0e5fa6601dbb0e9d (patch) | |
tree | 803568509acd7bfc35f9596cf3db1a59937c2ed4 /lib | |
parent | 55cc132b3219fbbf8c5705c674ef0f9a9b53d593 (diff) |
lib: remove handled option arguments from argv
Remove options from argv that have been handled by getopt to allow
additional non-option parameters to be processed in the test application.
This fixes issues when using options such as --debug with tests that accept
additional non-option parameters.
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/igt_core.c | 13 | ||||
-rw-r--r-- | lib/igt_core.h | 12 | ||||
-rw-r--r-- | lib/tests/igt_list_only.c | 3 | ||||
-rw-r--r-- | lib/tests/igt_no_exit.c | 3 | ||||
-rw-r--r-- | lib/tests/igt_no_exit_list_only.c | 3 | ||||
-rw-r--r-- | lib/tests/igt_no_subtest.c | 3 | ||||
-rw-r--r-- | lib/tests/igt_simulation.c | 15 |
7 files changed, 33 insertions, 19 deletions
diff --git a/lib/igt_core.c b/lib/igt_core.c index afecdf1b..75b98f62 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -487,7 +487,7 @@ static void oom_adjust_for_doom(void) low_mem_killer_disable(true); } -static int common_init(int argc, char **argv, +static int common_init(int *argc, char **argv, const char *extra_short_opts, struct option *extra_long_opts, const char *help_str, @@ -582,7 +582,7 @@ static int common_init(int argc, char **argv, std_short_opts); assert(ret >= 0); - while ((c = getopt_long(argc, argv, short_opts, combined_opts, + while ((c = getopt_long(*argc, argv, short_opts, combined_opts, &option_index)) != -1) { switch(c) { case OPT_INTERACTIVE_DEBUG: @@ -655,6 +655,11 @@ out: if (!test_with_subtests) gettime(&subtest_time); + for (i = 0; (optind + i) < *argc; i++) + argv[i + 1] = argv[optind + i]; + + *argc = *argc - optind + 1; + return ret; } @@ -678,7 +683,7 @@ out: * * Returns: Forwards any option parsing errors from getopt_long. */ -int igt_subtest_init_parse_opts(int argc, char **argv, +int igt_subtest_init_parse_opts(int *argc, char **argv, const char *extra_short_opts, struct option *extra_long_opts, const char *help_str, @@ -707,7 +712,7 @@ enum igt_log_level igt_log_level = IGT_LOG_INFO; * This initializes a simple test without any support for subtests and allows * an arbitrary set of additional options. */ -void igt_simple_init_parse_opts(int argc, char **argv, +void igt_simple_init_parse_opts(int *argc, char **argv, const char *extra_short_opts, struct option *extra_long_opts, const char *help_str, diff --git a/lib/igt_core.h b/lib/igt_core.h index 88b47bfd..e1833cf4 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -110,7 +110,7 @@ typedef int (*igt_opt_handler_t)(int opt, int opt_index); #ifndef __GTK_DOC_IGNORE__ /* gtkdoc wants to document this forward decl */ struct option; #endif -int igt_subtest_init_parse_opts(int argc, char **argv, +int igt_subtest_init_parse_opts(int *argc, char **argv, const char *extra_short_opts, struct option *extra_long_opts, const char *help_str, @@ -130,7 +130,7 @@ int igt_subtest_init_parse_opts(int argc, char **argv, * #igt_main block instead of stitching the test's main() function together * manually. */ -#define igt_subtest_init(argc, argv) igt_subtest_init_parse_opts(argc, argv, NULL, NULL, NULL, NULL); +#define igt_subtest_init(argc, argv) igt_subtest_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL); bool __igt_run_subtest(const char *subtest_name); #define __igt_tokencat2(x, y) x ## y @@ -195,14 +195,14 @@ bool igt_only_list_subtests(void); #define igt_main \ static void igt_tokencat(__real_main, __LINE__)(void); \ int main(int argc, char **argv) { \ - igt_subtest_init_parse_opts(argc, argv, NULL, NULL, NULL, NULL); \ + igt_subtest_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL); \ igt_tokencat(__real_main, __LINE__)(); \ igt_exit(); \ } \ static void igt_tokencat(__real_main, __LINE__)(void) \ -void igt_simple_init_parse_opts(int argc, char **argv, +void igt_simple_init_parse_opts(int *argc, char **argv, const char *extra_short_opts, struct option *extra_long_opts, const char *help_str, @@ -219,7 +219,7 @@ void igt_simple_init_parse_opts(int argc, char **argv, * #igt_simple_main block instead of stitching the test's main() function together * manually. */ -#define igt_simple_init(argc, argv) igt_simple_init_parse_opts(argc, argv, NULL, NULL, NULL, NULL); +#define igt_simple_init(argc, argv) igt_simple_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL); /** * igt_simple_main: @@ -231,7 +231,7 @@ void igt_simple_init_parse_opts(int argc, char **argv, #define igt_simple_main \ static void igt_tokencat(__real_main, __LINE__)(void); \ int main(int argc, char **argv) { \ - igt_simple_init_parse_opts(argc, argv, NULL, NULL, NULL, NULL); \ + igt_simple_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL); \ igt_tokencat(__real_main, __LINE__)(); \ igt_exit(); \ } \ diff --git a/lib/tests/igt_list_only.c b/lib/tests/igt_list_only.c index d3ea8c27..65fa9da6 100644 --- a/lib/tests/igt_list_only.c +++ b/lib/tests/igt_list_only.c @@ -32,8 +32,9 @@ int main(int argc, char **argv) char prog[] = "igt_list_only"; char arg[] = "--list-subtests"; char *fake_argv[] = {prog, arg}; + int fake_argc = 2; - igt_subtest_init(2, fake_argv); + igt_subtest_init(fake_argc, fake_argv); igt_subtest("A") ; diff --git a/lib/tests/igt_no_exit.c b/lib/tests/igt_no_exit.c index ba3fae0a..dc89b830 100644 --- a/lib/tests/igt_no_exit.c +++ b/lib/tests/igt_no_exit.c @@ -31,8 +31,9 @@ int main(int argc, char **argv) { char prog[] = "igt_no_exit"; char *fake_argv[] = {prog}; + int fake_argc = 1; - igt_subtest_init(1, fake_argv); + igt_subtest_init(fake_argc, fake_argv); igt_subtest("A") ; diff --git a/lib/tests/igt_no_exit_list_only.c b/lib/tests/igt_no_exit_list_only.c index 3b232be7..add3fc25 100644 --- a/lib/tests/igt_no_exit_list_only.c +++ b/lib/tests/igt_no_exit_list_only.c @@ -32,8 +32,9 @@ int main(int argc, char **argv) char prog[] = "igt_list_only"; char arg[] = "--list-subtests"; char *fake_argv[] = {prog, arg}; + int fake_argc = 2; - igt_subtest_init(2, fake_argv); + igt_subtest_init(fake_argc, fake_argv); igt_subtest("A") ; diff --git a/lib/tests/igt_no_subtest.c b/lib/tests/igt_no_subtest.c index 47f15fce..1ae62cfd 100644 --- a/lib/tests/igt_no_subtest.c +++ b/lib/tests/igt_no_subtest.c @@ -31,8 +31,9 @@ int main(int argc, char **argv) { char prog[] = "igt_no_exit"; char *fake_argv[] = {prog}; + int fake_argc = 1; - igt_subtest_init(1, fake_argv); + igt_subtest_init(fake_argc, fake_argv); igt_exit(); } diff --git a/lib/tests/igt_simulation.c b/lib/tests/igt_simulation.c index e5889590..32830ba7 100644 --- a/lib/tests/igt_simulation.c +++ b/lib/tests/igt_simulation.c @@ -55,22 +55,27 @@ char *argv_run[] = { test }; static int do_fork(void) { int pid, status; + int argc; switch (pid = fork()) { case -1: internal_assert(0); case 0: if (simple) { - igt_simple_init(1, argv_run); + argc = 1; + igt_simple_init(argc, argv_run); igt_skip_on_simulation(); igt_exit(); } else { - if (list_subtests) - igt_subtest_init(2, argv_list); - else - igt_subtest_init(1, argv_run); + if (list_subtests) { + argc = 2; + igt_subtest_init(argc, argv_list); + } else { + argc = 1; + igt_subtest_init(argc, argv_run); + } if (in_fixture) { igt_fixture |