Skip to contentSkip to conversation

lib/igt_core: Rework extra options conflicts handling

PATCH In review Arkadiusz Hiler 3 participants 4 messages May 16, 2019 – May 23, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/igt_core: Rework extra options conflicts handling

This started simple, as a fixup for a warning:
In file included from ../lib/drmtest.h:39,

                   from ../lib/igt_core.c:60:
  ../lib/igt_core.c: In function ‘common_init’:
  ../lib/igt_core.h:891:24: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
    891 | #define igt_warn(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_WARN, f)
        |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../lib/igt_core.c:704:4: note: in expansion of macro ‘igt_warn’
    704 |    igt_warn("Conflicting long and short option values between --%s and -%s\n",
        |    ^~~~~~~~

../lib/igt_core.c:704:73: note: format string is defined here
704 | igt_warn("Conflicting long and short option values between --%s and -%s\n",
| ^~

But it ended up doing the following things:
1. Promote all igt_warns to _critical and assert afterwards.
2. Use for loop instead of a while-doing-for's-job.
3. Streamline calculation of the option list sizes.
4. Add checks for long option names.
5. Log about "'val' representation" instead of confusing "value".
6. Log correct things so we won't %s on a NULL.
7. Write tests to confirm that it works.

---
 lib/igt_core.c                   | 72 +++++++++++++----------
 lib/tests/igt_conflicting_args.c | 99 ++++++++++++++++++++++++++++++++
 lib/tests/meson.build            |  1 +
 3 files changed, 141 insertions(+), 31 deletions(-)
 create mode 100644 lib/tests/igt_conflicting_args.c
lib/igt_core.c +41 -31
index d5d4fce2..6bbc805c 100644
@@ -666,12 +666,12 @@ static int common_init(int *argc, char **argv,
 {
 	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},
-		{"help-description", 0, 0, OPT_DESCRIPTION},
-		{"debug", optional_argument, 0, OPT_DEBUG},
-		{"interactive-debug", optional_argument, 0, OPT_INTERACTIVE_DEBUG},
-		{"help", 0, 0, OPT_HELP},
+		{"list-subtests",     no_argument,       NULL, OPT_LIST_SUBTESTS},
+		{"run-subtest",       required_argument, NULL, OPT_RUN_SUBTEST},
+		{"help-description",  no_argument,       NULL, OPT_DESCRIPTION},
+		{"debug",             optional_argument, NULL, OPT_DEBUG},
+		{"interactive-debug", optional_argument, NULL, OPT_INTERACTIVE_DEBUG},
+		{"help",              no_argument,       NULL, OPT_HELP},
 		{0, 0, 0, 0}
 	};
 	char *short_opts;
@@ -687,48 +687,58 @@ static int common_init(int *argc, char **argv,
 	if (strrchr(command_str, '/'))
 		command_str = strrchr(command_str, '/') + 1;
 
-	/* 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) {
+	/* Check for conflicts and calculate space for passed-in extra long options */
+	for  (extra_opt_count = 0; extra_long_opts && extra_long_opts[extra_opt_count].name; extra_opt_count++) {
+		char *conflicting_char;
 
 		/* 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,
+		for (i = 0; long_options[i].name; i++) {
+			if (0 == strcmp(extra_long_opts[extra_opt_count].name, long_options[i].name)) {
+				igt_critical("Conflicting extra long option defined --%s\n", long_options[i].name);
+				assert(0);
+
+			}
+
+			if (extra_long_opts[extra_opt_count].val == long_options[i].val) {
+				igt_critical("Conflicting long option 'val' representation between --%s and --%s\n",
+					 extra_long_opts[extra_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);
+				assert(0);
+			}
 		}
 
-
-		all_opt_count++;
+		/* check for conflicts with standard short options */
+		if (extra_long_opts[extra_opt_count].val != ':'
+		    && (conflicting_char = strchr(std_short_opts, extra_long_opts[extra_opt_count].val))) {
+			igt_critical("Conflicting long and short option 'val' representation between --%s and -%c\n",
+				 extra_long_opts[extra_opt_count].name,
+				 *conflicting_char);
+			assert(0);
+		}
 	}
-	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]);
+		if (strchr(std_short_opts, extra_short_opts[i])) {
+			igt_critical("Conflicting short option: -%c\n", std_short_opts[i]);
+			assert(0);
+		}
 
 		/* 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]);
+		for (x = 0; long_options[x].name; x++) {
+			if (long_options[x].val == extra_short_opts[i]) {
+				igt_critical("Conflicting short option and long option 'val' representation: --%s and -%c\n",
+					     long_options[x].name, extra_short_opts[i]);
+				assert(0);
+			}
+		}
 	}
 
-	all_opt_count += ARRAY_SIZE(long_options);
+	all_opt_count = extra_opt_count + ARRAY_SIZE(long_options);
 
 	combined_opts = malloc(all_opt_count * sizeof(*combined_opts));
 	if (extra_opt_count > 0)
lib/tests/igt_conflicting_args.c new file +99 -0

99 lines not on this page · raw message

lib/tests/meson.build +1 -0
index 74efce39..9950bd59 100644
@@ -2,6 +2,7 @@ lib_tests = [
 	'igt_assert',
 	'igt_can_fail',
 	'igt_can_fail_simple',
+	'igt_conflicting_args',
 	'igt_exit_handler',
 	'igt_fork',
 	'igt_fork_helper',
Signature · 6 lines
2.21.0

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

[igt-dev] ✓ Fi.CI.BAT: success for lib/igt_core: Rework extra options conflicts handling

== Series Details ==

== Series Details ==

Series: lib/igt_core: Rework extra options conflicts handling
URL : https://patchwork.freedesktop.org/series/60715/
State : success

== Summary ==

CI Bug Log - changes from IGT_4994 -> IGTPW_2989
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/60715/revisions/1/mbox/

Known issues
------------

Here are the changes found in IGTPW_2989 that come from known issues:

### IGT changes ###

#### Possible fixes ####

* igt@gem_basic@bad-close:
- {fi-icl-u3}: [INCOMPLETE][1] ([fdo#107713]) -> [PASS][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/fi-icl-u3/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/fi-icl-u3/igt@[email protected]

* igt@gem_cpu_reloc@basic:
- fi-icl-u2: [INCOMPLETE][3] ([fdo#107713] / [fdo#110246]) -> [PASS][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/fi-icl-u2/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/fi-icl-u2/igt@[email protected]

* igt@gem_exec_suspend@basic-s4-devices:
- fi-blb-e6850: [INCOMPLETE][5] ([fdo#107718]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/fi-blb-e6850/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/fi-blb-e6850/igt@[email protected]

#### Warnings ####

* igt@i915_selftest@live_hangcheck:
- fi-apl-guc: [DMESG-FAIL][7] ([fdo#110620]) -> [FAIL][8] ([fdo#110623])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/fi-apl-guc/igt@i915_selftest@live_hangcheck.html
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/fi-apl-guc/igt@i915_selftest@live_hangcheck.html

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#107718]: https://bugs.freedesktop.org/show_bug.cgi?id=107718
[fdo#110246]: https://bugs.freedesktop.org/show_bug.cgi?id=110246
[fdo#110620]: https://bugs.freedesktop.org/show_bug.cgi?id=110620
[fdo#110623]: https://bugs.freedesktop.org/show_bug.cgi?id=110623

Participating hosts (52 -> 45)
------------------------------

Missing (7): fi-kbl-soraka fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-byt-clapper fi-bdw-samus

Build changes
-------------

* IGT: IGT_4994 -> IGTPW_2989

CI_DRM_6090: df27ebbc9ec0d8ae42e8cf3d7a3b29fd6baf4940 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_2989: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/
IGT_4994: 555019f862c35f1619627761d6da21385be40920 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#2 lore raw

[igt-dev] ✓ Fi.CI.IGT: success for lib/igt_core: Rework extra options conflicts handling

In reply to Arkadiusz Hiler
== Series Details ==

== Series Details ==

Series: lib/igt_core: Rework extra options conflicts handling
URL : https://patchwork.freedesktop.org/series/60715/
State : success

== Summary ==

CI Bug Log - changes from IGT_4994_full -> IGTPW_2989_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/60715/revisions/1/mbox/

Known issues
------------

Here are the changes found in IGTPW_2989_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_eio@unwedge-stress:
- shard-snb: [PASS][1] -> [FAIL][2] ([fdo#109661])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-snb6/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-snb2/igt@[email protected]

* igt@gem_tiled_swapping@non-threaded:
- shard-glk: [PASS][3] -> [DMESG-WARN][4] ([fdo#108686])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-glk5/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-glk5/igt@[email protected]

* igt@i915_pm_rps@reset:
- shard-apl: [PASS][5] -> [FAIL][6] ([fdo#102250])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-apl7/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-apl3/igt@[email protected]
- shard-iclb: [PASS][7] -> [FAIL][8] ([fdo#102250] / [fdo#108059])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-iclb8/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-iclb6/igt@[email protected]

* igt@i915_suspend@fence-restore-untiled:
- shard-kbl: [PASS][9] -> [DMESG-WARN][10] ([fdo#108566])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-kbl2/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-kbl7/igt@[email protected]

* igt@i915_suspend@forcewake:
- shard-apl: [PASS][11] -> [DMESG-WARN][12] ([fdo#108566]) +1 similar issue
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-apl3/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-apl1/igt@[email protected]

* igt@kms_cursor_legacy@cursor-vs-flip-atomic:
- shard-hsw: [PASS][13] -> [FAIL][14] ([fdo#103355])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-hsw4/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-hsw1/igt@[email protected]

* igt@kms_dp_dsc@basic-dsc-enable-edp:
- shard-iclb: [PASS][15] -> [SKIP][16] ([fdo#109349])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-iclb2/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-iclb1/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-pwrite:
- shard-iclb: [PASS][17] -> [FAIL][18] ([fdo#103167]) +1 similar issue
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-iclb4/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-pwrite.html
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-iclb6/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-pwrite.html

* igt@kms_plane_lowres@pipe-a-tiling-y:
- shard-iclb: [PASS][19] -> [FAIL][20] ([fdo#103166])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-iclb7/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-iclb6/igt@[email protected]

* igt@kms_psr@psr2_sprite_plane_onoff:
- shard-iclb: [PASS][21] -> [SKIP][22] ([fdo#109441])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-iclb2/igt@kms_psr@psr2_sprite_plane_onoff.html
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-iclb6/igt@kms_psr@psr2_sprite_plane_onoff.html

* igt@kms_rotation_crc@multiplane-rotation-cropping-top:
- shard-kbl: [PASS][23] -> [FAIL][24] ([fdo#109016])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-kbl2/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-kbl7/igt@[email protected]

* igt@kms_universal_plane@universal-plane-pipe-a-functional:
- shard-apl: [PASS][25] -> [FAIL][26] ([fdo#110037])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-apl2/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-apl5/igt@[email protected]
- shard-kbl: [PASS][27] -> [FAIL][28] ([fdo#110037])
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-kbl6/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-kbl3/igt@[email protected]

* igt@perf@short-reads:
- shard-kbl: [PASS][29] -> [FAIL][30] ([fdo#103183])
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-kbl2/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-kbl2/igt@[email protected]

#### Possible fixes ####

* igt@i915_pm_rc6_residency@rc6-accuracy:
- shard-snb: [SKIP][31] ([fdo#109271]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-snb5/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-snb5/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-pri-indfb-multidraw:
- shard-iclb: [FAIL][33] ([fdo#103167]) -> [PASS][34] +2 similar issues
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-iclb1/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-iclb1/igt@[email protected]

* igt@kms_setmode@basic:
- shard-kbl: [FAIL][35] ([fdo#99912]) -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-kbl4/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-kbl6/igt@[email protected]

* igt@kms_sysfs_edid_timing:
- shard-iclb: [FAIL][37] ([fdo#100047]) -> [PASS][38]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-iclb3/igt@kms_sysfs_edid_timing.html
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-iclb5/igt@kms_sysfs_edid_timing.html

* igt@kms_vblank@pipe-c-ts-continuation-suspend:
- shard-apl: [DMESG-WARN][39] ([fdo#108566]) -> [PASS][40] +6 similar issues
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-apl3/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-apl1/igt@[email protected]

* igt@perf_pmu@rc6-runtime-pm-long:
- shard-apl: [FAIL][41] ([fdo#105010]) -> [PASS][42]
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-apl5/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-apl8/igt@[email protected]
- shard-kbl: [FAIL][43] ([fdo#105010]) -> [PASS][44]
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-kbl6/igt@[email protected]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-kbl6/igt@[email protected]

#### Warnings ####

* igt@gem_mmap_gtt@forked-big-copy-odd:
- shard-iclb: [TIMEOUT][45] ([fdo#109673]) -> [INCOMPLETE][46] ([fdo#107713] / [fdo#109100])
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/IGT_4994/shard-iclb5/igt@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/shard-iclb2/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#100047]: https://bugs.freedesktop.org/show_bug.cgi?id=100047
[fdo#102250]: https://bugs.freedesktop.org/show_bug.cgi?id=102250
[fdo#103166]: https://bugs.freedesktop.org/show_bug.cgi?id=103166
[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103183]: https://bugs.freedesktop.org/show_bug.cgi?id=103183
[fdo#103355]: https://bugs.freedesktop.org/show_bug.cgi?id=103355
[fdo#105010]: https://bugs.freedesktop.org/show_bug.cgi?id=105010
[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#108059]: https://bugs.freedesktop.org/show_bug.cgi?id=108059
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#108686]: https://bugs.freedesktop.org/show_bug.cgi?id=108686
[fdo#109016]: https://bugs.freedesktop.org/show_bug.cgi?id=109016
[fdo#109100]: https://bugs.freedesktop.org/show_bug.cgi?id=109100
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109349]: https://bugs.freedesktop.org/show_bug.cgi?id=109349
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#109661]: https://bugs.freedesktop.org/show_bug.cgi?id=109661
[fdo#109673]: https://bugs.freedesktop.org/show_bug.cgi?id=109673
[fdo#110037]: https://bugs.freedesktop.org/show_bug.cgi?id=110037
[fdo#99912]: https://bugs.freedesktop.org/show_bug.cgi?id=99912

Participating hosts (7 -> 6)
------------------------------

Missing (1): shard-skl

Build changes
-------------

* IGT: IGT_4994 -> IGTPW_2989

CI_DRM_6090: df27ebbc9ec0d8ae42e8cf3d7a3b29fd6baf4940 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_2989: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/
IGT_4994: 555019f862c35f1619627761d6da21385be40920 @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_2989/
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

Reviewed-by on v1 1/1
#3 lore raw
In reply to Arkadiusz Hiler
Quoted 72 lines · Arkadiusz Hiler

This started simple, as a fixup for a warning:
In file included from ../lib/drmtest.h:39,

                   from ../lib/igt_core.c:60:
  ../lib/igt_core.c: In function ‘common_init’:
  ../lib/igt_core.h:891:24: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
    891 | #define igt_warn(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_WARN, f)
        |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ../lib/igt_core.c:704:4: note: in expansion of macro ‘igt_warn’
    704 |    igt_warn("Conflicting long and short option values between --%s and -%s\n",
        |    ^~~~~~~~

../lib/igt_core.c:704:73: note: format string is defined here
704 | igt_warn("Conflicting long and short option values between --%s and -%s\n",
| ^~

But it ended up doing the following things:
1. Promote all igt_warns to _critical and assert afterwards.
2. Use for loop instead of a while-doing-for's-job.
3. Streamline calculation of the option list sizes.
4. Add checks for long option names.
5. Log about "'val' representation" instead of confusing "value".
6. Log correct things so we won't %s on a NULL.
7. Write tests to confirm that it works.

---
 lib/igt_core.c                   | 72 +++++++++++++----------
 lib/tests/igt_conflicting_args.c | 99 ++++++++++++++++++++++++++++++++
 lib/tests/meson.build            |  1 +
 3 files changed, 141 insertions(+), 31 deletions(-)
 create mode 100644 lib/tests/igt_conflicting_args.c
lib/igt_core.c +10 -13
index d5d4fce2..6bbc805c 100644
@@ -666,12 +666,12 @@ static int common_init(int *argc, char **argv,
 {
 	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},
-		{"help-description", 0, 0, OPT_DESCRIPTION},
-		{"debug", optional_argument, 0, OPT_DEBUG},
-		{"interactive-debug", optional_argument, 0, OPT_INTERACTIVE_DEBUG},
-		{"help", 0, 0, OPT_HELP},
+		{"list-subtests",     no_argument,       NULL, OPT_LIST_SUBTESTS},
+		{"run-subtest",       required_argument, NULL, OPT_RUN_SUBTEST},
+		{"help-description",  no_argument,       NULL, OPT_DESCRIPTION},
+		{"debug",             optional_argument, NULL, OPT_DEBUG},
+		{"interactive-debug", optional_argument, NULL, OPT_INTERACTIVE_DEBUG},
+		{"help",              no_argument,       NULL, OPT_HELP},
 		{0, 0, 0, 0}
 	};
 	char *short_opts;
@@ -687,48 +687,58 @@ static int common_init(int *argc, char **argv,
 	if (strrchr(command_str, '/'))
 		command_str = strrchr(command_str, '/') + 1;
 
-	/* 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) {
+	/* Check for conflicts and calculate space for passed-in extra long options */
+	for  (extra_opt_count = 0; extra_long_opts && extra_long_opts[extra_opt_count].name; extra_opt_count++) {
+		char *conflicting_char;
 
 		/* 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,
+		for (i = 0; long_options[i].name; i++) {

lib/igt_core.c static int common_init(int *argc, char **argv, · line 705

Quoted 10 lines
lib/igt_core.c +9 -0
+			if (0 == strcmp(extra_long_opts[extra_opt_count].name, long_options[i].name)) {
+				igt_critical("Conflicting extra long option defined --%s\n", long_options[i].name);
+				assert(0);
+
+			}
+
+			if (extra_long_opts[extra_opt_count].val == long_options[i].val) {
+				igt_critical("Conflicting long option 'val' representation between --%s and --%s\n",
+					 extra_long_opts[extra_opt_count].name,
 					 long_options[i].name);

Indentation here looks funky.

Quoted 9 lines
lib/igt_core.c +2 -7
-
-		/* 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);
+				assert(0);
+			}

lib/igt_core.c static int common_init(int *argc, char **argv, · line 715

Quoted 10 lines
lib/igt_core.c +6 -2
 		}
 
-
-		all_opt_count++;
+		/* check for conflicts with standard short options */
+		if (extra_long_opts[extra_opt_count].val != ':'
+		    && (conflicting_char = strchr(std_short_opts, extra_long_opts[extra_opt_count].val))) {
+			igt_critical("Conflicting long and short option 'val' representation between --%s and -%c\n",
+				 extra_long_opts[extra_opt_count].name,
+				 *conflicting_char);

Indentation funky here as well.

Otherwise LGTM. Thanks for doing this, this is a great help in my upcoming series that touches testdisplay among other things...

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev