From patchwork Wed Feb 18 17:06:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 5845461 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AE6A1BF440 for ; Wed, 18 Feb 2015 17:06:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 80F712012E for ; Wed, 18 Feb 2015 17:06:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1710920154 for ; Wed, 18 Feb 2015 17:06:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 48F486E084; Wed, 18 Feb 2015 09:06:24 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-we0-f169.google.com (mail-we0-f169.google.com [74.125.82.169]) by gabe.freedesktop.org (Postfix) with ESMTP id B6AD46E078 for ; Wed, 18 Feb 2015 09:06:21 -0800 (PST) Received: by wesx3 with SMTP id x3so2395521wes.7 for ; Wed, 18 Feb 2015 09:06:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=c5e/0j6yNyAqrzw71iKmKmKxwJBTi9JsTLQPgqJ1Fno=; b=gceQmR6B7jVv2SXxNf30bO6C2YmXwTZzOiSCBWGgZjKu35vNv73knjzMZcKwzjEjLV ixSBeno8yhgxvJx8LXm9Yxfgg8sJ/RJ18IdC92h0pJJnSBqoWBo7izc28CaFBlBEVsoa MxwVhhagL5SPiMBbKNLWudcFiJE8w+eQplY0PL73VlSe4MBJxgDK+AUN+/qj7fOe5Pgh nIN8tT3CD1xZew0j5VjseCkvTPN+JINzBFu7zTpOsKyoXBygNWXL/u2MjiZcJt2gqa6G Nx8kKKGqfHJ/I9ocTtjOjzppTGFjfVKSmOLm782YX84SUFg8ZZRPgxE8xWh96wJl5T80 aV2w== X-Gm-Message-State: ALoCoQnnt86t6ZdtEFq+IrAGjOHlsleh7QWj/z6VML42+rFjW7ziG4I9xk62UMs5DtqzO4b5RFGT X-Received: by 10.194.120.40 with SMTP id kz8mr349781wjb.21.1424279180951; Wed, 18 Feb 2015 09:06:20 -0800 (PST) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id ub1sm33474610wjc.43.2015.02.18.09.06.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Feb 2015 09:06:20 -0800 (PST) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Wed, 18 Feb 2015 17:06:15 +0000 Message-Id: <1424279176-5000-3-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1424279176-5000-1-git-send-email-thomas.wood@intel.com> References: <1424279176-5000-1-git-send-email-thomas.wood@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 3/4] lib: remove handled option arguments from argv X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- lib/igt_core.c | 13 +++++++++---- lib/igt_core.h | 12 ++++++------ lib/tests/igt_list_only.c | 3 ++- lib/tests/igt_no_exit.c | 3 ++- lib/tests/igt_no_exit_list_only.c | 3 ++- lib/tests/igt_no_subtest.c | 3 ++- lib/tests/igt_simulation.c | 15 ++++++++++----- tests/gem_ctx_basic.c | 2 +- tests/gem_render_copy.c | 2 +- tests/gem_seqno_wrap.c | 2 +- tests/gem_stress.c | 2 +- tests/kms_psr_sink_crc.c | 2 +- tests/kms_setmode.c | 2 +- tests/pm_rpm.c | 2 +- 14 files changed, 40 insertions(+), 26 deletions(-) diff --git a/lib/igt_core.c b/lib/igt_core.c index afecdf1..75b98f6 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 88b47bf..e1833cf 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 d3ea8c2..65fa9da 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 ba3fae0..dc89b83 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 3b232be..add3fc2 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 47f15fc..1ae62cf 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 e588959..32830ba 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 diff --git a/tests/gem_ctx_basic.c b/tests/gem_ctx_basic.c index 2d866b3..4301b34 100644 --- a/tests/gem_ctx_basic.c +++ b/tests/gem_ctx_basic.c @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) { int i; - igt_simple_init_parse_opts(argc, argv, "i:c:n:mu", NULL, NULL, + igt_simple_init_parse_opts(&argc, argv, "i:c:n:mu", NULL, NULL, opt_handler); fd = drm_open_any_render(); diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c index 6348eee..df1ac88 100644 --- a/tests/gem_render_copy.c +++ b/tests/gem_render_copy.c @@ -141,7 +141,7 @@ int main(int argc, char **argv) igt_render_copyfunc_t render_copy = NULL; int opt_dump_aub = igt_aub_dump_enabled(); - igt_simple_init_parse_opts(argc, argv, "da", NULL, NULL, opt_handler); + igt_simple_init_parse_opts(&argc, argv, "da", NULL, NULL, opt_handler); igt_fixture { data.drm_fd = drm_open_any_render(); diff --git a/tests/gem_seqno_wrap.c b/tests/gem_seqno_wrap.c index d07ec96..ba58ebd 100644 --- a/tests/gem_seqno_wrap.c +++ b/tests/gem_seqno_wrap.c @@ -503,7 +503,7 @@ int main(int argc, char **argv) options.prewrap_space = 21; options.buffers = 10; - igt_simple_init_parse_opts(argc, argv, "n:bvt:dp:ri:", long_options, + igt_simple_init_parse_opts(&argc, argv, "n:bvt:dp:ri:", long_options, help, parse_options); card_index = drm_get_card(); diff --git a/tests/gem_stress.c b/tests/gem_stress.c index f687b2d..cb951af 100644 --- a/tests/gem_stress.c +++ b/tests/gem_stress.c @@ -854,7 +854,7 @@ int main(int argc, char **argv) options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size); options.check_render_cpyfn = 0; - igt_simple_init_parse_opts(argc, argv,"ds:g:c:t:rbuxmo:fp:", + igt_simple_init_parse_opts(&argc, argv,"ds:g:c:t:rbuxmo:fp:", long_options, NULL, parse_options); drm_fd = drm_open_any(); diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c index 98b60cf..9256640 100644 --- a/tests/kms_psr_sink_crc.c +++ b/tests/kms_psr_sink_crc.c @@ -489,7 +489,7 @@ int main(int argc, char *argv[]) data_t data = {}; enum operations op; - igt_subtest_init_parse_opts(argc, argv, "", long_options, + igt_subtest_init_parse_opts(&argc, argv, "", long_options, help_str, opt_handler); igt_skip_on_simulation(); diff --git a/tests/kms_setmode.c b/tests/kms_setmode.c index f13871e..8e6afbf 100644 --- a/tests/kms_setmode.c +++ b/tests/kms_setmode.c @@ -699,7 +699,7 @@ int main(int argc, char **argv) int i; int ret; - ret = igt_subtest_init_parse_opts(argc, argv, "dt:", NULL, help_str, + ret = igt_subtest_init_parse_opts(&argc, argv, "dt:", NULL, help_str, opt_handler); if (ret < 0) return ret == -1 ? 0 : ret; diff --git a/tests/pm_rpm.c b/tests/pm_rpm.c index 84254b7..c2847d0 100644 --- a/tests/pm_rpm.c +++ b/tests/pm_rpm.c @@ -1811,7 +1811,7 @@ int main(int argc, char *argv[]) { 0, 0, 0, 0 } }; - igt_subtest_init_parse_opts(argc, argv, "", long_options, + igt_subtest_init_parse_opts(&argc, argv, "", long_options, help_str, opt_handler); /* Skip instead of failing in case the machine is not prepared to reach