* [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit()
@ 2019-11-18 6:47 Andrei Vagin
2019-11-18 6:47 ` [PATCH 2/3] selftests/clone3: report a correct number of fails Andrei Vagin
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andrei Vagin @ 2019-11-18 6:47 UTC (permalink / raw)
To: Christian Brauner; +Cc: Adrian Reber, linux-kernel, Andrei Vagin
Buffers have to be flushed before clone3() to avoid double messages in
the log.
Signed-off-by: Andrei Vagin <avagin@gmail.com>
---
tools/testing/selftests/clone3/clone3_selftests.h | 2 ++
tools/testing/selftests/clone3/clone3_set_tid.c | 15 +++++++++++----
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/clone3/clone3_selftests.h b/tools/testing/selftests/clone3/clone3_selftests.h
index e5a62dfef67a..c8899e773c8e 100644
--- a/tools/testing/selftests/clone3/clone3_selftests.h
+++ b/tools/testing/selftests/clone3/clone3_selftests.h
@@ -29,6 +29,8 @@ struct clone_args {
static pid_t sys_clone3(struct clone_args *args, size_t size)
{
+ fflush(stdout);
+ fflush(stderr);
return syscall(__NR_clone3, args, size);
}
diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c
index 3480e1c46983..e93369dcfe3b 100644
--- a/tools/testing/selftests/clone3/clone3_set_tid.c
+++ b/tools/testing/selftests/clone3/clone3_set_tid.c
@@ -30,6 +30,13 @@
static int pipe_1[2];
static int pipe_2[2];
+static void child_exit(int ret)
+{
+ fflush(stdout);
+ fflush(stderr);
+ _exit(ret);
+}
+
static int call_clone3_set_tid(pid_t *set_tid,
size_t set_tid_size,
int flags,
@@ -84,8 +91,8 @@ static int call_clone3_set_tid(pid_t *set_tid,
}
if (set_tid[0] != getpid())
- _exit(EXIT_FAILURE);
- _exit(exit_code);
+ child_exit(EXIT_FAILURE);
+ child_exit(exit_code);
}
if (expected_pid == 0 || expected_pid == pid) {
@@ -249,7 +256,7 @@ int main(int argc, char *argv[])
pid = fork();
if (pid == 0) {
ksft_print_msg("Child has PID %d\n", getpid());
- _exit(EXIT_SUCCESS);
+ child_exit(EXIT_SUCCESS);
}
if (waitpid(pid, &status, 0) < 0)
ksft_exit_fail_msg("Waiting for child %d failed", pid);
@@ -309,7 +316,7 @@ int main(int argc, char *argv[])
*/
test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, 0, 42, true);
- _exit(ksft_cnt.ksft_pass);
+ child_exit(ksft_cnt.ksft_pass);
}
close(pipe_1[1]);
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] selftests/clone3: report a correct number of fails
2019-11-18 6:47 [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit() Andrei Vagin
@ 2019-11-18 6:47 ` Andrei Vagin
2019-11-18 7:38 ` Christian Brauner
2019-11-18 6:47 ` [PATCH 3/3] selftests/clone3: check that all pids are released on error paths Andrei Vagin
2019-11-18 7:37 ` [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit() Christian Brauner
2 siblings, 1 reply; 7+ messages in thread
From: Andrei Vagin @ 2019-11-18 6:47 UTC (permalink / raw)
To: Christian Brauner; +Cc: Adrian Reber, linux-kernel, Andrei Vagin
In clone3_set_tid, a few test cases are running in a child process. And
right now, if one of these test cases fails, the whole test will exit
with the success status.
Signed-off-by: Andrei Vagin <avagin@gmail.com>
---
tools/testing/selftests/clone3/clone3_set_tid.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c
index e93369dcfe3b..9c19bae03661 100644
--- a/tools/testing/selftests/clone3/clone3_set_tid.c
+++ b/tools/testing/selftests/clone3/clone3_set_tid.c
@@ -316,7 +316,7 @@ int main(int argc, char *argv[])
*/
test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, 0, 42, true);
- child_exit(ksft_cnt.ksft_pass);
+ child_exit(ksft_cnt.ksft_fail);
}
close(pipe_1[1]);
@@ -366,12 +366,8 @@ int main(int argc, char *argv[])
if (!WIFEXITED(status))
ksft_test_result_fail("Child error\n");
- if (WEXITSTATUS(status))
- /*
- * Update the number of total tests with the tests from the
- * child processes.
- */
- ksft_cnt.ksft_pass = WEXITSTATUS(status);
+ ksft_cnt.ksft_pass += 4 - (ksft_cnt.ksft_fail - WEXITSTATUS(status));
+ ksft_cnt.ksft_fail = WEXITSTATUS(status);
if (ns3 == pid && ns2 == 42 && ns1 == 1)
ksft_test_result_pass(
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] selftests/clone3: check that all pids are released on error paths
2019-11-18 6:47 [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit() Andrei Vagin
2019-11-18 6:47 ` [PATCH 2/3] selftests/clone3: report a correct number of fails Andrei Vagin
@ 2019-11-18 6:47 ` Andrei Vagin
2019-11-18 7:38 ` Christian Brauner
2019-11-18 7:37 ` [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit() Christian Brauner
2 siblings, 1 reply; 7+ messages in thread
From: Andrei Vagin @ 2019-11-18 6:47 UTC (permalink / raw)
To: Christian Brauner; +Cc: Adrian Reber, linux-kernel, Andrei Vagin
This is a regression test case for an issue when pids have not been
released on error paths.
Signed-off-by: Andrei Vagin <avagin@gmail.com>
---
tools/testing/selftests/clone3/clone3_set_tid.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/clone3/clone3_set_tid.c b/tools/testing/selftests/clone3/clone3_set_tid.c
index 9c19bae03661..c6309f5d7d88 100644
--- a/tools/testing/selftests/clone3/clone3_set_tid.c
+++ b/tools/testing/selftests/clone3/clone3_set_tid.c
@@ -160,7 +160,7 @@ int main(int argc, char *argv[])
ksft_exit_fail_msg("pipe() failed\n");
ksft_print_header();
- ksft_set_plan(27);
+ ksft_set_plan(29);
f = fopen("/proc/sys/kernel/pid_max", "r");
if (f == NULL)
@@ -290,6 +290,18 @@ int main(int argc, char *argv[])
/* Let's create a PID 1 */
ns_pid = fork();
if (ns_pid == 0) {
+ /*
+ * This and the next test cases check that all pid-s are
+ * released on error paths.
+ */
+ set_tid[0] = 43;
+ set_tid[1] = -1;
+ test_clone3_set_tid(set_tid, 2, 0, -EINVAL, 0, 0);
+
+ set_tid[0] = 43;
+ set_tid[1] = pid;
+ test_clone3_set_tid(set_tid, 2, 0, 0, 43, 0);
+
ksft_print_msg("Child in PID namespace has PID %d\n", getpid());
set_tid[0] = 2;
test_clone3_set_tid(set_tid, 1, 0, 0, 2, 0);
@@ -366,7 +378,7 @@ int main(int argc, char *argv[])
if (!WIFEXITED(status))
ksft_test_result_fail("Child error\n");
- ksft_cnt.ksft_pass += 4 - (ksft_cnt.ksft_fail - WEXITSTATUS(status));
+ ksft_cnt.ksft_pass += 6 - (ksft_cnt.ksft_fail - WEXITSTATUS(status));
ksft_cnt.ksft_fail = WEXITSTATUS(status);
if (ns3 == pid && ns2 == 42 && ns1 == 1)
--
2.23.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit()
2019-11-18 6:47 [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit() Andrei Vagin
2019-11-18 6:47 ` [PATCH 2/3] selftests/clone3: report a correct number of fails Andrei Vagin
2019-11-18 6:47 ` [PATCH 3/3] selftests/clone3: check that all pids are released on error paths Andrei Vagin
@ 2019-11-18 7:37 ` Christian Brauner
2019-11-18 8:24 ` Christian Brauner
2 siblings, 1 reply; 7+ messages in thread
From: Christian Brauner @ 2019-11-18 7:37 UTC (permalink / raw)
To: Andrei Vagin; +Cc: Adrian Reber, linux-kernel
On Sun, Nov 17, 2019 at 10:47:48PM -0800, Andrei Vagin wrote:
> Buffers have to be flushed before clone3() to avoid double messages in
> the log.
>
> Signed-off-by: Andrei Vagin <avagin@gmail.com>
Thanks, Andrei!
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] selftests/clone3: report a correct number of fails
2019-11-18 6:47 ` [PATCH 2/3] selftests/clone3: report a correct number of fails Andrei Vagin
@ 2019-11-18 7:38 ` Christian Brauner
0 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2019-11-18 7:38 UTC (permalink / raw)
To: Andrei Vagin; +Cc: Adrian Reber, linux-kernel
On Sun, Nov 17, 2019 at 10:47:49PM -0800, Andrei Vagin wrote:
> In clone3_set_tid, a few test cases are running in a child process. And
> right now, if one of these test cases fails, the whole test will exit
> with the success status.
>
> Signed-off-by: Andrei Vagin <avagin@gmail.com>
Thanks, Andrei! Applied.
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] selftests/clone3: check that all pids are released on error paths
2019-11-18 6:47 ` [PATCH 3/3] selftests/clone3: check that all pids are released on error paths Andrei Vagin
@ 2019-11-18 7:38 ` Christian Brauner
0 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2019-11-18 7:38 UTC (permalink / raw)
To: Andrei Vagin; +Cc: Adrian Reber, linux-kernel
On Sun, Nov 17, 2019 at 10:47:50PM -0800, Andrei Vagin wrote:
> This is a regression test case for an issue when pids have not been
> released on error paths.
>
> Signed-off-by: Andrei Vagin <avagin@gmail.com>
Good idea. Thanks, Andrei! Applied.
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit()
2019-11-18 7:37 ` [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit() Christian Brauner
@ 2019-11-18 8:24 ` Christian Brauner
0 siblings, 0 replies; 7+ messages in thread
From: Christian Brauner @ 2019-11-18 8:24 UTC (permalink / raw)
To: Andrei Vagin; +Cc: Adrian Reber, linux-kernel
On Mon, Nov 18, 2019 at 08:37:47AM +0100, Christian Brauner wrote:
> On Sun, Nov 17, 2019 at 10:47:48PM -0800, Andrei Vagin wrote:
> > Buffers have to be flushed before clone3() to avoid double messages in
> > the log.
> >
> > Signed-off-by: Andrei Vagin <avagin@gmail.com>
>
> Thanks, Andrei!
> Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
I pushed another small change on top of your changes which takes care to
skip clone3() tests whenever the syscall is not supported:
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=pidfd&id=11fde161ab37f2938504bf896b48afbd18ea71cd
Christian
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-11-18 8:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-18 6:47 [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit() Andrei Vagin
2019-11-18 6:47 ` [PATCH 2/3] selftests/clone3: report a correct number of fails Andrei Vagin
2019-11-18 7:38 ` Christian Brauner
2019-11-18 6:47 ` [PATCH 3/3] selftests/clone3: check that all pids are released on error paths Andrei Vagin
2019-11-18 7:38 ` Christian Brauner
2019-11-18 7:37 ` [PATCH 1/3] selftests/clone3: flush stdout and stderr before clone3() and _exit() Christian Brauner
2019-11-18 8:24 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).