From 8f17199d16bcdb29516d34514f95d1a117f6bd26 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 13 Sep 2024 09:58:17 -0400 Subject: Implement multiprocessing pool(s) * Adds --cpu-limit and --parallel-fail-fast arguments * Adds disable, parallel, and setup_script keys to [test] blocks --- src/template_func_proto.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/template_func_proto.c') diff --git a/src/template_func_proto.c b/src/template_func_proto.c index 3cf66e4..ebb595e 100644 --- a/src/template_func_proto.c +++ b/src/template_func_proto.c @@ -109,4 +109,41 @@ int get_basetemp_dir_entrypoint(void *frame, void *data_out) { sprintf(*output, "%s/truth-%s-%s", ctx->storage.tmpdir, name, ctx->info.release_name); return result; +} + +int tox_run_entrypoint(void *frame, void *data_out) { + char **output = (char **) data_out; + struct tplfunc_frame *f = (struct tplfunc_frame *) frame; + const struct Delivery *ctx = (const struct Delivery *) f->data_in; + + // Apply workaround for tox positional arguments + char *toxconf = NULL; + if (!access("tox.ini", F_OK)) { + if (!fix_tox_conf("tox.ini", &toxconf)) { + msg(STASIS_MSG_L3, "Fixing tox positional arguments\n"); + *output = calloc(STASIS_BUFSIZ, sizeof(**output)); + if (!*output) { + return -1; + } + char *basetemp_path = NULL; + if (get_basetemp_dir_entrypoint(f, &basetemp_path)) { + return -2; + } + char *jxml_path = NULL; + if (get_junitxml_file_entrypoint(f, &jxml_path)) { + return -3; + } + const char *tox_target = f->argv[0].t_char_ptr; + const char *pytest_args = f->argv[1].t_char_ptr; + if (isempty(toxconf) || !strcmp(toxconf, "/")) { + SYSERROR("Unsafe toxconf path: '%s'", toxconf); + return -4; + } + snprintf(*output, STASIS_BUFSIZ - 1, "\npip install tox && (tox -e py%s%s -c %s --root . -- --basetemp=\"%s\" --junitxml=\"%s\" %s ; rm -f '%s')\n", ctx->meta.python_compact, tox_target, toxconf, basetemp_path, jxml_path, pytest_args ? pytest_args : "", toxconf); + + guard_free(jxml_path); + guard_free(basetemp_path); + } + } + return 0; } \ No newline at end of file -- cgit From d76321976cfe42bb03b5e7e48ac9f6d95d97b14a Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 20 Sep 2024 08:42:33 -0400 Subject: Die if the current working directory cannot be determined --- src/template_func_proto.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/template_func_proto.c') diff --git a/src/template_func_proto.c b/src/template_func_proto.c index ebb595e..9f1283f 100644 --- a/src/template_func_proto.c +++ b/src/template_func_proto.c @@ -74,7 +74,10 @@ int get_junitxml_file_entrypoint(void *frame, void *data_out) { const struct Delivery *ctx = (const struct Delivery *) f->data_in; char cwd[PATH_MAX] = {0}; - getcwd(cwd, PATH_MAX - 1); + if (!getcwd(cwd, PATH_MAX - 1)) { + SYSERROR("unable to determine current working directory: %s", strerror(errno)); + return -1; + } char nametmp[PATH_MAX] = {0}; strcpy(nametmp, cwd); char *name = path_basename(nametmp); @@ -96,7 +99,10 @@ int get_basetemp_dir_entrypoint(void *frame, void *data_out) { const struct Delivery *ctx = (const struct Delivery *) f->data_in; char cwd[PATH_MAX] = {0}; - getcwd(cwd, PATH_MAX - 1); + if (!getcwd(cwd, PATH_MAX - 1)) { + SYSERROR("unable to determine current working directory: %s", strerror(errno)); + return -1; + } char nametmp[PATH_MAX] = {0}; strcpy(nametmp, cwd); char *name = path_basename(nametmp); -- cgit From d1642b3514f23be90e8292fce4569990c813d8eb Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 30 Sep 2024 11:54:34 -0400 Subject: Fix leaking of basetemp_path and jxml_path on error * Reported by @kmacdonald-stsci --- src/template_func_proto.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/template_func_proto.c') diff --git a/src/template_func_proto.c b/src/template_func_proto.c index 9f1283f..9c325bb 100644 --- a/src/template_func_proto.c +++ b/src/template_func_proto.c @@ -137,12 +137,15 @@ int tox_run_entrypoint(void *frame, void *data_out) { } char *jxml_path = NULL; if (get_junitxml_file_entrypoint(f, &jxml_path)) { + guard_free(basetemp_path); return -3; } const char *tox_target = f->argv[0].t_char_ptr; const char *pytest_args = f->argv[1].t_char_ptr; if (isempty(toxconf) || !strcmp(toxconf, "/")) { SYSERROR("Unsafe toxconf path: '%s'", toxconf); + guard_free(basetemp_path); + guard_free(jxml_path); return -4; } snprintf(*output, STASIS_BUFSIZ - 1, "\npip install tox && (tox -e py%s%s -c %s --root . -- --basetemp=\"%s\" --junitxml=\"%s\" %s ; rm -f '%s')\n", ctx->meta.python_compact, tox_target, toxconf, basetemp_path, jxml_path, pytest_args ? pytest_args : "", toxconf); -- cgit