public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Thomas Wood <thomas.wood@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t] lib: check test options for conflicts
Date: Mon, 28 Jul 2014 16:18:39 +0100	[thread overview]
Message-ID: <1406560719-22394-1-git-send-email-thomas.wood@intel.com> (raw)
In-Reply-To: <CANkqdn1-WphpceWtFeFW4ZDxw=xdAn+c6+CeugStyDdp048MdQ@mail.gmail.com>

Check any test specific options for conflicts with the standard set of
options.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
---
 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

  reply	other threads:[~2014-07-28 15:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-23 10:57 [PATCH i-g-t 0/8] command line parsing Thomas Wood
2014-07-23 10:57 ` [PATCH i-g-t 1/8] lib: warn when attempting to run an unknown subtest Thomas Wood
2014-07-24  9:49   ` Gore, Tim
2014-07-23 10:57 ` [PATCH i-g-t 2/8] tests: remove unused getopt header includes Thomas Wood
2014-07-24  9:50   ` Gore, Tim
2014-07-23 10:57 ` [PATCH i-g-t 3/8] lib: move option parsing into common_init Thomas Wood
2014-07-23 12:13   ` Daniel Vetter
2014-07-23 12:15     ` Daniel Vetter
2014-07-24  9:52   ` Gore, Tim
2014-07-23 10:57 ` [PATCH i-g-t 4/8] lib: add igt_simple_init_parse_opts Thomas Wood
2014-07-24  9:54   ` Gore, Tim
2014-07-23 10:57 ` [PATCH i-g-t 5/8] lib: don't ignore unknown options in multi-tests Thomas Wood
2014-07-24  9:55   ` Gore, Tim
2014-07-23 10:57 ` [PATCH i-g-t 6/8] tests: convert simple tests to use igt_simple_init_parse_opts Thomas Wood
2014-07-24 10:17   ` Gore, Tim
2014-07-25 16:08     ` [PATCH i-g-t] lib: avoid getopt value conflicts with tests Thomas Wood
2014-07-25 16:57       ` Paulo Zanoni
2014-07-28  9:38         ` Thomas Wood
2014-07-28 15:18           ` Thomas Wood [this message]
2014-07-23 10:57 ` [PATCH i-g-t 7/8] lib: always warn about unknown options Thomas Wood
2014-07-24 10:33   ` Gore, Tim
2014-07-23 10:57 ` [PATCH i-g-t 8/8] lib: add a command line option to enable debug output in tests Thomas Wood
2014-07-24 10:37   ` Gore, Tim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406560719-22394-1-git-send-email-thomas.wood@intel.com \
    --to=thomas.wood@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox