1 /*
2 * Copyright © 2019 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 /*
25 * DESCRIPTION: Make sure that IGT framework complains when test try to define
26 * conflicting options.
27 */
28
29 #include <signal.h>
30 #include <sys/wait.h>
31 #include <errno.h>
32
33 #include "drmtest.h"
34 #include "igt_core.h"
35 #include "igt_tests_common.h"
36
37 static struct option long_options[2];
38 static const char *short_options;
39
opt_handler(int option,int option_index,void * input)40 static int opt_handler(int option, int option_index, void *input)
41 {
42
43 return 0;
44 }
45
do_fork(void)46 static int do_fork(void)
47 {
48 char test_name[] = "test";
49
50 char *argv[] = { test_name };
51 int argc = ARRAY_SIZE(argv);
52
53 pid_t pid = fork();
54 internal_assert(pid != -1);
55
56 if (pid) {
57 int status;
58 while (waitpid(pid, &status, 0) == -1 && errno == EINTR)
59 ;
60
61 return status;
62 }
63
64
65 igt_subtest_init_parse_opts(&argc, argv, short_options, long_options,
66 "", opt_handler, NULL);
67 igt_subtest("dummy") {}
68 igt_exit();
69 }
70
main(int argc,char ** argv)71 int main(int argc, char **argv)
72 {
73 /* no conflict */
74 long_options[0] = (struct option) { "iterations", required_argument, NULL, 'i'};
75 short_options = "";
76 internal_assert_wexited(do_fork(), 0);
77
78 /* conflict on short option */
79 long_options[0] = (struct option) { "iterations", required_argument, NULL, 'i'};
80 short_options = "h";
81 internal_assert_wsignaled(do_fork(), SIGABRT);
82
83 /* conflict on long option name */
84 long_options[0] = (struct option) { "help", required_argument, NULL, 'i'};
85 short_options = "";
86 internal_assert_wsignaled(do_fork(), SIGABRT);
87
88 /* conflict on long option 'val' representation vs short option */
89 long_options[0] = (struct option) { "iterations", required_argument, NULL, 'h'};
90 short_options = "";
91 internal_assert_wsignaled(do_fork(), SIGABRT);
92
93 /* conflict on long option 'val' representations */
94 long_options[0] = (struct option) { "iterations", required_argument, NULL, 500};
95 short_options = "";
96 internal_assert_wsignaled(do_fork(), SIGABRT);
97
98 return 0;
99 }
100