From patchwork Mon Jul 28 15:18:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 4635211 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 555C2C0338 for ; Mon, 28 Jul 2014 15:18:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 747AA20155 for ; Mon, 28 Jul 2014 15:18:44 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8A5AA20109 for ; Mon, 28 Jul 2014 15:18:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2CA976E0C7; Mon, 28 Jul 2014 08:18:43 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by gabe.freedesktop.org (Postfix) with ESMTP id 717F96E0C7 for ; Mon, 28 Jul 2014 08:18:42 -0700 (PDT) Received: by mail-wg0-f45.google.com with SMTP id x12so7462772wgg.4 for ; Mon, 28 Jul 2014 08:18:41 -0700 (PDT) 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=eSfe/MmNTw8bhJ1jLgFqRktVE66TF8stxJYJBOvKYoU=; b=Ko/TEccVoWuxe2+1ZCwYB2y+QgDYAMEH3ZaSSQ1LGyJMk50YP8McbXXpCsrUxqhAWe rRYFTNdQ9tJ+KbvWYzGkGT+nTvdXw2Jyv/t2lDtz4RMW32lYPCYn+MiLPg4GoZyvvE3V Kvhy/WT0HhBO2bjeZ2jKHetEbQWSQj17SSfgZPoy0gjeGK+2IRwPSPApEwO8pSt+qxSN jRXuoBl191mulpdzmMep/2l8Wa4Uie7TI6ArCSsTYcizv3xzfAyM0tD/aJ8sasdTKTih yBiH2myXUt+ZDkow2Cz3Z0uYPPH1WxRZ8IGKbTlIGSZSOqFA61H1W2GCl7vXq2G+jqiZ k+Tg== X-Gm-Message-State: ALoCoQkd1WTMNDk/C/3cpxxDr1n1S6vwVRVZkDUkwMKuuJ3lOrsaXht2fmk43ltaYf2UMR/TNa5m X-Received: by 10.194.236.35 with SMTP id ur3mr13070258wjc.127.1406560721305; Mon, 28 Jul 2014 08:18:41 -0700 (PDT) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id au7sm50179670wjc.41.2014.07.28.08.18.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jul 2014 08:18:40 -0700 (PDT) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Mon, 28 Jul 2014 16:18:39 +0100 Message-Id: <1406560719-22394-1-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: Subject: [Intel-gfx] [PATCH i-g-t] lib: check test options for conflicts X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 Check any test specific options for conflicts with the standard set of options. Signed-off-by: Thomas Wood --- lib/igt_core.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/igt_core.c b/lib/igt_core.c index 0e254e3..f4761ca 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -325,14 +325,16 @@ static int common_init(int argc, char **argv, const char *help_str, igt_opt_handler_t extra_opt_handler) { - int c, option_index = 0; + int c, option_index = 0, i, x; static struct option long_options[] = { {"list-subtests", 0, 0, OPT_LIST_SUBTESTS}, {"run-subtest", 1, 0, OPT_RUN_SUBTEST}, {"debug", 0, 0, OPT_DEBUG}, {"help", 0, 0, OPT_HELP}, + {0, 0, 0, 0} }; char *short_opts; + const char *std_short_opts = "h"; struct option *combined_opts; int extra_opt_count; int all_opt_count; @@ -356,10 +358,45 @@ static int common_init(int argc, char **argv, /* First calculate space for all passed-in extra long options */ all_opt_count = 0; - while (extra_long_opts && extra_long_opts[all_opt_count].name) + while (extra_long_opts && extra_long_opts[all_opt_count].name) { + + /* check for conflicts with standard long option values */ + for (i = 0; long_options[i].name; i++) + if (extra_long_opts[all_opt_count].val == long_options[i].val) + igt_warn("Conflicting long option values between --%s and --%s\n", + extra_long_opts[all_opt_count].name, + long_options[i].name); + + /* check for conflicts with short options */ + if (extra_long_opts[all_opt_count].val != ':' + && strchr(std_short_opts, extra_long_opts[all_opt_count].val)) { + igt_warn("Conflicting long and short option values between --%s and -%s\n", + extra_long_opts[all_opt_count].name, + long_options[i].name); + } + + all_opt_count++; + } extra_opt_count = all_opt_count; + /* check for conflicts in extra short options*/ + for (i = 0; extra_short_opts && extra_short_opts[i]; i++) { + + if (extra_short_opts[i] == ':') + continue; + + /* check for conflicts with standard short options */ + if (strchr(std_short_opts, extra_short_opts[i])) + igt_warn("Conflicting short option: -%c\n", std_short_opts[i]); + + /* check for conflicts with standard long option values */ + for (x = 0; long_options[x].name; x++) + if (long_options[x].val == extra_short_opts[i]) + igt_warn("Conflicting short option and long option value: --%s and -%c\n", + long_options[x].name, extra_short_opts[i]); + } + all_opt_count += ARRAY_SIZE(long_options); combined_opts = malloc(all_opt_count * sizeof(*combined_opts)); @@ -370,8 +407,9 @@ static int common_init(int argc, char **argv, memcpy(&combined_opts[extra_opt_count], long_options, ARRAY_SIZE(long_options) * sizeof(*combined_opts)); - ret = asprintf(&short_opts, "%sh", - extra_short_opts ? extra_short_opts : ""); + ret = asprintf(&short_opts, "%s%s", + extra_short_opts ? extra_short_opts : "", + std_short_opts); assert(ret >= 0); while ((c = getopt_long(argc, argv, short_opts, combined_opts,