From: Martin Doucha <mdoucha@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/3] Add tst_validate_children() helper function
Date: Wed, 14 Sep 2022 15:43:31 +0200 [thread overview]
Message-ID: <20220914134333.13562-2-mdoucha@suse.cz> (raw)
In-Reply-To: <20220914134333.13562-1-mdoucha@suse.cz>
The function waits for given number of child processes and validates
that they have all exited without error.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
Changes since v1:
- Moved tst_validate_children_() to lib/tst_status.c
- Simplified the code using tst_strstatus()
include/tst_test.h | 8 ++++++++
lib/tst_status.c | 20 ++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/include/tst_test.h b/include/tst_test.h
index ac52f268c..69e649651 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -362,6 +362,14 @@ void tst_set_max_runtime(int max_runtime);
*/
char *tst_get_tmpdir(void);
+/*
+ * Validates exit status of child processes
+ */
+int tst_validate_children_(const char *file, const int lineno,
+ unsigned int count);
+#define tst_validate_children(child_count) \
+ tst_validate_children_(__FILE__, __LINE__, (child_count))
+
#ifndef TST_NO_DEFAULT_MAIN
static struct tst_test test;
diff --git a/lib/tst_status.c b/lib/tst_status.c
index 9124faaa3..5d03871f3 100644
--- a/lib/tst_status.c
+++ b/lib/tst_status.c
@@ -49,3 +49,23 @@ const char *tst_strstatus(int status)
return invalid(status);
}
+
+int tst_validate_children_(const char *file, const int lineno,
+ unsigned int count)
+{
+ unsigned int i;
+ int status;
+ pid_t pid;
+
+ for (i = 0; i < count; i++) {
+ pid = SAFE_WAITPID(-1, &status, 0);
+
+ if (!WIFEXITED(status) || WEXITSTATUS(status)) {
+ tst_res_(file, lineno, TFAIL, "Child %d: %s", pid,
+ tst_strstatus(status));
+ return 1;
+ }
+ }
+
+ return 0;
+}
--
2.37.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-09-14 13:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-14 13:43 [LTP] [PATCH v2 0/3] Fix ADSP074 timeouts Martin Doucha
2022-09-14 13:43 ` Martin Doucha [this message]
2022-09-14 13:43 ` [LTP] [PATCH v2 2/3] Make io_read() runtime-aware Martin Doucha
2022-09-14 13:43 ` [LTP] [PATCH v2 3/3] dio_sparse: Fix child exit code Martin Doucha
2022-09-15 8:52 ` [LTP] [PATCH v2 0/3] Fix ADSP074 timeouts Cyril Hrubis
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=20220914134333.13562-2-mdoucha@suse.cz \
--to=mdoucha@suse.cz \
--cc=ltp@lists.linux.it \
/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.