From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/3] lib/tst_test.c: Kill all children on timeout
Date: Tue, 7 Jun 2016 14:45:07 +0200 [thread overview]
Message-ID: <20160607124506.GA4236@rei.lan> (raw)
* Run actuall test in a separate process group
* Deliver SIGKILL to all children on timeout
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
lib/newlib_tests/.gitignore | 1 +
lib/newlib_tests/test13.c | 37 +++++++++++++++++++++++++++++++++++++
lib/tst_test.c | 6 ++++--
3 files changed, 42 insertions(+), 2 deletions(-)
create mode 100644 lib/newlib_tests/test13.c
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index dccf4c8..ea19310 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -10,3 +10,4 @@ test09
test10
test11
test12
+test13
diff --git a/lib/newlib_tests/test13.c b/lib/newlib_tests/test13.c
new file mode 100644
index 0000000..7ad5172
--- /dev/null
+++ b/lib/newlib_tests/test13.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Linux Test Project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/*
+ * Test for timeout & children.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+ SAFE_FORK();
+ SAFE_FORK();
+ SAFE_FORK();
+
+ tst_res(TINFO, "Pausing process pid %i", getpid());
+ pause();
+}
+
+static struct tst_test test = {
+ .tid = "test13",
+ .timeout = 1,
+ .forks_child = 1,
+ .test_all = do_test,
+};
diff --git a/lib/tst_test.c b/lib/tst_test.c
index eef54e4..9122f57 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -660,7 +660,7 @@ static unsigned int timeout = 300;
static void alarm_handler(int sig LTP_ATTRIBUTE_UNUSED)
{
- kill(test_pid, SIGKILL);
+ kill(-test_pid, SIGKILL);
}
static void heartbeat_handler(int sig LTP_ATTRIBUTE_UNUSED)
@@ -702,8 +702,10 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
if (test_pid < 0)
tst_brk(TBROK | TERRNO, "fork()");
- if (!test_pid)
+ if (!test_pid) {
+ SAFE_SETPGID(0, 0);
testrun();
+ }
SAFE_WAITPID(test_pid, &status, 0);
--
2.7.3
--
Cyril Hrubis
chrubis@suse.cz
next reply other threads:[~2016-06-07 12:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 12:45 Cyril Hrubis [this message]
2016-06-08 8:23 ` [LTP] [PATCH 3/3] lib/tst_test.c: Kill all children on timeout Jan Stancek
2016-06-08 9:48 ` 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=20160607124506.GA4236@rei.lan \
--to=chrubis@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.