[PATCH i-g-t v4 2/6] runner: Make it easier to extend argv
Gustavo Sousa
gustavo.sousa at intel.com
Wed Aug 14 20:47:57 UTC 2024
In an upcoming change, we will be adding the option to forward the
--hook option to the test cases, which will require updating
execute_test_process() to add the option when asked by the user.
The current implementation makes that task not quite straightforward:
filling of argv is already dependent on stuff like entry->subtest_count
and dynbegin; if we want to keep on using constant indices, we would
need several conditional branches for adding arguments for --hook.
Let us change the current implementation to use a dynamic vector, to
make it easier to extend argv with more stuff as needed.
v2:
- Squash the logic from patch "runner: Use dynamic vector for test
argv" directly instead of using the original logic, which used a
statically sized array. (Lucas)
Reviewed-by: Lucas De Marchi <lucas.demarchi at intel.com>
Signed-off-by: Gustavo Sousa <gustavo.sousa at intel.com>
---
runner/executor.c | 54 +++++++++++++++++++++++++++++------------------
1 file changed, 34 insertions(+), 20 deletions(-)
diff --git a/runner/executor.c b/runner/executor.c
index 4b374d2235b2..a135cd46b849 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -31,6 +31,7 @@
#include "igt_aux.h"
#include "igt_core.h"
#include "igt_taints.h"
+#include "igt_vec.h"
#include "executor.h"
#include "output_strings.h"
#include "runnercomms.h"
@@ -1506,7 +1507,8 @@ execute_test_process(int outfd, int errfd, int socketfd,
struct settings *settings,
struct job_list_entry *entry)
{
- char *argv[6] = {};
+ struct igt_vec arg_vec;
+ char *arg;
size_t rootlen;
dup2(outfd, STDOUT_FILENO);
@@ -1514,32 +1516,31 @@ execute_test_process(int outfd, int errfd, int socketfd,
setpgid(0, 0);
+ igt_vec_init(&arg_vec, sizeof(char *));
+
rootlen = strlen(settings->test_root);
- argv[0] = malloc(rootlen + strlen(entry->binary) + 2);
- strcpy(argv[0], settings->test_root);
- argv[0][rootlen] = '/';
- strcpy(argv[0] + rootlen + 1, entry->binary);
+ arg = malloc(rootlen + strlen(entry->binary) + 2);
+ strcpy(arg, settings->test_root);
+ arg[rootlen] = '/';
+ strcpy(arg + rootlen + 1, entry->binary);
+ igt_vec_push(&arg_vec, &arg);
if (entry->subtest_count) {
size_t argsize;
const char *dynbegin;
size_t i;
- argv[1] = strdup("--run-subtest");
+ arg = strdup("--run-subtest");
+ igt_vec_push(&arg_vec, &arg);
if ((dynbegin = strchr(entry->subtests[0], '@')) != NULL)
argsize = dynbegin - entry->subtests[0];
else
argsize = strlen(entry->subtests[0]);
- argv[2] = malloc(argsize + 1);
- memcpy(argv[2], entry->subtests[0], argsize);
- argv[2][argsize] = '\0';
-
- if (dynbegin) {
- argv[3] = strdup("--dynamic-subtest");
- argv[4] = strdup(dynbegin + 1);
- }
+ arg = malloc(argsize + 1);
+ memcpy(arg, entry->subtests[0], argsize);
+ arg[argsize] = '\0';
for (i = 1; i < entry->subtest_count; i++) {
char *sub = entry->subtests[i];
@@ -1547,22 +1548,35 @@ execute_test_process(int outfd, int errfd, int socketfd,
assert(dynbegin == NULL);
- argv[2] = realloc(argv[2], argsize + sublen + 2);
- argv[2][argsize] = ',';
- strcpy(argv[2] + argsize + 1, sub);
+ arg = realloc(arg, argsize + sublen + 2);
+ arg[argsize] = ',';
+ strcpy(arg + argsize + 1, sub);
argsize += sublen + 1;
}
+
+ igt_vec_push(&arg_vec, &arg);
+
+ if (dynbegin) {
+ arg = strdup("--dynamic-subtest");
+ igt_vec_push(&arg_vec, &arg);
+ arg = strdup(dynbegin + 1);
+ igt_vec_push(&arg_vec, &arg);
+ }
}
+ arg = NULL;
+ igt_vec_push(&arg_vec, &arg);
+
if (socketfd >= 0) {
struct runnerpacket *packet;
- packet = runnerpacket_exec(argv);
+ packet = runnerpacket_exec(arg_vec.elems);
write(socketfd, packet, packet->size);
}
- execv(argv[0], argv);
- fprintf(stderr, "Cannot execute %s\n", argv[0]);
+ arg = *((char **)igt_vec_elem(&arg_vec, 0));
+ execv(arg, arg_vec.elems);
+ fprintf(stderr, "Cannot execute %s\n", arg);
exit(IGT_EXIT_INVALID);
}
--
2.46.0
More information about the igt-dev
mailing list