test-runner: Fix parsing of command line
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 1 Mar 2022 23:26:14 +0000 (15:26 -0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:53 +0000 (14:55 +0530)
Instead of parsing the command line, which can contain a shell script,
run using /bin/sh so it allows more complex command line to be tested:

sudo tools/test-runner -l -d -k <pathto/bzImage> --
'client/bluetoothctl power on && sleep 2 && client/bluetoothctl power
off'

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
tools/test-runner.c

index 49fe825..6b94e9c 100755 (executable)
@@ -719,25 +719,7 @@ start_next:
                argv[0] = (char *) test_table[idx];
                argv[1] = "-q";
                argv[2] = NULL;
-       } else {
-               while (1) {
-                       char *ptr;
-
-                       ptr = strchr(cmdname, ' ');
-                       if (!ptr) {
-                               argv[pos++] = cmdname;
-                               break;
-                       }
-
-                       *ptr = '\0';
-                       argv[pos++] = cmdname;
-                       if (pos > 8)
-                               break;
-
-                       cmdname = ptr + 1;
-               }
-
-               argv[pos] = NULL;
+               cmdname = NULL;
        }
 
        pos = 0;
@@ -746,7 +728,7 @@ start_next:
                envp[pos++] = home;
        envp[pos] = NULL;
 
-       printf("Running command %s\n", argv[0]);
+       printf("Running command %s\n", cmdname ? cmdname : argv[0]);
 
        pid = fork();
        if (pid < 0) {
@@ -761,7 +743,11 @@ start_next:
                                perror("Failed to change directory");
                }
 
-               execve(argv[0], argv, envp);
+               if (!cmdname)
+                       execve(argv[0], argv, envp);
+               else
+                       execl("/bin/sh", "sh", "-c", cmdname, NULL);
+
                exit(EXIT_SUCCESS);
        }