From: Anibal Limon <anibal@limonsoftware.com>
To: yocto-patches@lists.yoctoproject.org
Cc: randy.macleod@windriver.com, changqing.li@windriver.com,
Anibal Limon <anibal@limonsoftware.com>
Subject: [ptest-runner 2/2] utils.c: run_ptests improve error handling on ptests iteration
Date: Mon, 6 May 2024 09:40:42 -0600 [thread overview]
Message-ID: <20240506154042.3395390-2-anibal@limonsoftware.com> (raw)
In-Reply-To: <20240506154042.3395390-1-anibal@limonsoftware.com>
If error on setup a new ptest use goto to clean properly and stop
the loop.
Signed-off-by: Anibal Limon <anibal@limonsoftware.com>
---
utils.c | 51 ++++++++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git a/utils.c b/utils.c
index 3a35313..6cf7705 100644
--- a/utils.c
+++ b/utils.c
@@ -350,7 +350,6 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
struct ptest_list *p;
-
if (opts.xml_filename) {
xh = xml_create(ptest_list_length(head), opts.xml_filename);
if (!xh)
@@ -362,43 +361,37 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
fprintf(fp, "START: %s\n", progname);
PTEST_LIST_ITERATE_START(head, p)
+ char ptest_dir[PATH_MAX] = {'\0'};
int pipefd_stdout[2] = {-1, -1};
int pipefd_stderr[2] = {-1, -1};
int pty[2] = {-1, -1};
+ strcpy(ptest_dir, p->run_ptest);
+ dirname(ptest_dir);
+
if (pipe2(pipefd_stdout, 0) == -1) {
+ fprintf(fp, "ERROR: pipe2() failed with: %s.\n", strerror(errno));
rc = -1;
- break;
+ goto ptest_list_fail1;
}
+
if (pipe2(pipefd_stderr, 0) == -1) {
- close(pipefd_stdout[PIPE_READ]);
- close(pipefd_stdout[PIPE_WRITE]);
+ fprintf(fp, "ERROR: pipe2() failed with: %s.\n", strerror(errno));
rc = -1;
- break;
+ goto ptest_list_fail2;
}
if (openpty(&pty[0], &pty[1], NULL, NULL, NULL) < 0) {
fprintf(fp, "ERROR: openpty() failed with: %s.\n", strerror(errno));
- close(pipefd_stderr[PIPE_READ]);
- close(pipefd_stderr[PIPE_WRITE]);
- close(pipefd_stdout[PIPE_READ]);
- close(pipefd_stdout[PIPE_WRITE]);
rc = -1;
- break;
- }
-
- char *ptest_dir = strdup(p->run_ptest);
- if (ptest_dir == NULL) {
- rc = -1;
- break;
+ goto ptest_list_fail3;
}
- dirname(ptest_dir);
pid_t child = fork();
if (child == -1) {
fprintf(fp, "ERROR: Fork %s\n", strerror(errno));
rc = -1;
- break;
+ goto ptest_list_fail4;
} else if (child == 0) {
/* Close read ends of the pipe */
do_close(&pipefd_stdout[PIPE_READ]);
@@ -424,7 +417,6 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
} else {
run_child(p->run_ptest, pipefd_stdout[PIPE_WRITE], pipefd_stderr[PIPE_WRITE]);
}
-
} else {
bool timedout = false;
char stime[GET_STIME_BUF_SIZE];
@@ -551,22 +543,31 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
fprintf(fp, "END: %s\n", ptest_dir);
fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, end_time));
}
- free(ptest_dir);
- do_close(&pipefd_stdout[PIPE_READ]);
- do_close(&pipefd_stdout[PIPE_WRITE]);
+
+ptest_list_fail4:
+ do_close(&pty[0]);
+ do_close(&pty[1]);
+
+ptest_list_fail3:
do_close(&pipefd_stderr[PIPE_READ]);
do_close(&pipefd_stderr[PIPE_WRITE]);
+ptest_list_fail2:
+ do_close(&pipefd_stdout[PIPE_READ]);
+ do_close(&pipefd_stdout[PIPE_WRITE]);
+ptest_list_fail1:
fflush(fp);
fflush(fp_stderr);
+ if (rc == -1) {
+ fprintf(fp_stderr, "run_ptests fails: %s", strerror(errno));
+ break;
+ }
+
PTEST_LIST_ITERATE_END
fprintf(fp, "STOP: %s\n", progname);
} while (0);
- if (rc == -1)
- fprintf(fp_stderr, "run_ptests fails: %s", strerror(errno));
-
if (opts.xml_filename)
xml_finish(xh);
--
2.43.0
prev parent reply other threads:[~2024-05-06 15:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-06 15:40 [ptest-runner 1/2] utils.c: run-ptests improve pseudo-terminal handling Anibal Limon
2024-05-06 15:40 ` Anibal Limon [this message]
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=20240506154042.3395390-2-anibal@limonsoftware.com \
--to=anibal@limonsoftware.com \
--cc=changqing.li@windriver.com \
--cc=randy.macleod@windriver.com \
--cc=yocto-patches@lists.yoctoproject.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.