From: Gustavo Sousa <gustavo.sousa@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH i-g-t v3 2/6] runner: Make it easier to extend argv
Date: Thu, 25 Jul 2024 11:19:35 -0300 [thread overview]
Message-ID: <20240725142028.51735-3-gustavo.sousa@intel.com> (raw)
In-Reply-To: <20240725142028.51735-1-gustavo.sousa@intel.com>
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)
Signed-off-by: Gustavo Sousa <gustavo.sousa@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.45.2
next prev parent reply other threads:[~2024-07-25 14:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-25 14:19 [PATCH i-g-t v3 0/6] Add support for hook script Gustavo Sousa
2024-07-25 14:19 ` [PATCH i-g-t v3 1/6] igt_hook: Add feature Gustavo Sousa
2024-08-12 13:52 ` Lucas De Marchi
2024-07-25 14:19 ` Gustavo Sousa [this message]
2024-08-12 13:54 ` [PATCH i-g-t v3 2/6] runner: Make it easier to extend argv Lucas De Marchi
2024-07-25 14:19 ` [PATCH i-g-t v3 3/6] runner: Add option --hook Gustavo Sousa
2024-08-12 13:55 ` Lucas De Marchi
2024-07-25 14:19 ` [PATCH i-g-t v3 4/6] igt_hook: Implement and use set_fake_argv() in test Gustavo Sousa
2024-08-12 13:58 ` Lucas De Marchi
2024-07-25 14:19 ` [PATCH i-g-t v3 5/6] igt_hook: Allow multiple hook descriptors Gustavo Sousa
2024-08-12 14:01 ` Lucas De Marchi
2024-07-25 14:19 ` [PATCH i-g-t v3 6/6] runner: Allow multiple --hook options Gustavo Sousa
2024-08-12 14:06 ` Lucas De Marchi
2024-07-25 18:05 ` ✓ CI.xeBAT: success for Add support for hook script (rev3) Patchwork
2024-07-25 18:11 ` ✓ Fi.CI.BAT: " Patchwork
2024-07-25 22:49 ` ✗ CI.xeFULL: failure " Patchwork
2024-07-26 11:36 ` ✗ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240725142028.51735-3-gustavo.sousa@intel.com \
--to=gustavo.sousa@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=lucas.demarchi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox