From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Wood Subject: [PATCH i-g-t] lib: check test options for conflicts Date: Mon, 28 Jul 2014 16:18:39 +0100 Message-ID: <1406560719-22394-1-git-send-email-thomas.wood@intel.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: 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) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org 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, -- 1.9.3