Skip to content

Commit f23c792

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Cleanup benchmark argument parsing
Benchmark argument is handled by custom argument parsing code which is more complicated than it needs to be. Process benchmark argument within the normal getopt() handling and drop unnecessary ben_ind and has_ben variables. When -b is given, terminate the argument processing as -b consumes all remaining arguments. Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: "Wieczor-Retman, Maciej" <maciej.wieczor-retman@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 149ff72 commit f23c792

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,27 +169,34 @@ static void run_cat_test(int cpu_no, int no_of_bits)
169169

170170
int main(int argc, char **argv)
171171
{
172-
bool has_ben = false, mbm_test = true, mba_test = true, cmt_test = true;
173-
int c, cpu_no = 1, argc_new = argc, i, no_of_bits = 0;
174-
const char *benchmark_cmd[BENCHMARK_ARGS];
175-
int ben_ind, tests = 0;
172+
bool mbm_test = true, mba_test = true, cmt_test = true;
173+
const char *benchmark_cmd[BENCHMARK_ARGS] = {};
174+
int c, cpu_no = 1, i, no_of_bits = 0;
176175
char *span_str = NULL;
177176
bool cat_test = true;
177+
int tests = 0;
178178
int ret;
179179

180-
for (i = 0; i < argc; i++) {
181-
if (strcmp(argv[i], "-b") == 0) {
182-
ben_ind = i + 1;
183-
argc_new = ben_ind - 1;
184-
has_ben = true;
185-
break;
186-
}
187-
}
188-
189-
while ((c = getopt(argc_new, argv, "ht:b:n:p:")) != -1) {
180+
while ((c = getopt(argc, argv, "ht:b:n:p:")) != -1) {
190181
char *token;
191182

192183
switch (c) {
184+
case 'b':
185+
/*
186+
* First move optind back to the (first) optarg and
187+
* then build the benchmark command using the
188+
* remaining arguments.
189+
*/
190+
optind--;
191+
if (argc - optind >= BENCHMARK_ARGS)
192+
ksft_exit_fail_msg("Too long benchmark command");
193+
194+
/* Extract benchmark command from command line. */
195+
for (i = 0; i < argc - optind; i++)
196+
benchmark_cmd[i] = argv[i + optind];
197+
benchmark_cmd[i] = NULL;
198+
199+
goto last_arg;
193200
case 't':
194201
token = strtok(optarg, ",");
195202

@@ -238,6 +245,7 @@ int main(int argc, char **argv)
238245
return -1;
239246
}
240247
}
248+
last_arg:
241249

242250
ksft_print_header();
243251

@@ -257,15 +265,7 @@ int main(int argc, char **argv)
257265

258266
filter_dmesg();
259267

260-
if (has_ben) {
261-
if (argc - ben_ind >= BENCHMARK_ARGS)
262-
ksft_exit_fail_msg("Too long benchmark command.\n");
263-
264-
/* Extract benchmark command from command line. */
265-
for (i = 0; i < argc - ben_ind; i++)
266-
benchmark_cmd[i] = argv[i + ben_ind];
267-
benchmark_cmd[i] = NULL;
268-
} else {
268+
if (!benchmark_cmd[0]) {
269269
/* If no benchmark is given by "-b" argument, use fill_buf. */
270270
benchmark_cmd[0] = "fill_buf";
271271
ret = asprintf(&span_str, "%u", DEFAULT_SPAN);

0 commit comments

Comments
 (0)