History log of /linux-master/tools/testing/selftests/clone3/clone3.c
Revision Date Author Comments
# 34dce23f 17-Oct-2023 Mark Brown <broonie@kernel.org>

selftests/clone3: Report descriptive test names

The clone3() selftests currently report test results in a format that does
not mesh entirely well with automation. They log output for each test such
as:

# [1382411] Trying clone3() with flags 0 (size 0)
# I am the parent (1382411). My child's pid is 1382412
# I am the child, my PID is 1382412
# [1382411] clone3() with flags says: 0 expected 0
ok 1 [1382411] Result (0) matches expectation (0)

This is not ideal for automated parsers since the text after the "ok 1" is
treated as the test name when comparing runs by a lot of automation (tests
routinely get renumbered due to things like new tests being added based on
logical groupings). The PID means that the test names will frequently vary
and the rest of the name being a description of results means several tests
have identical text there.

Address this by refactoring things so that we have a static descriptive
name for each test which we use when logging passes, failures and skips
and since we now have a stable name for the test to hand log that before
starting the test to address the common issue reading logs where the test
name is only printed after any diagnostics. The result is:

# Running test 'simple clone3()'
# [1562777] Trying clone3() with flags 0 (size 0)
# I am the parent (1562777). My child's pid is 1562778
# I am the child, my PID is 1562778
# [1562777] clone3() with flags says: 0 expected 0
ok 1 simple clone3()

In order to handle skips a bit more neatly this is done in a moderately
invasive fashion where we move from a sequence of function calls to having
an array of test parameters. This hopefully also makes it a little easier
to see what the tests are doing when looking at both the source and the
logs.

Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>


# fc7f04dc 11-Jul-2023 Tiezhu Yang <yangtiezhu@loongson.cn>

selftests/clone3: Fix broken test under !CONFIG_TIME_NS

When execute the following command to test clone3 under !CONFIG_TIME_NS:

# make headers && cd tools/testing/selftests/clone3 && make && ./clone3

we can see the following error info:

# [7538] Trying clone3() with flags 0x80 (size 0)
# Invalid argument - Failed to create new process
# [7538] clone3() with flags says: -22 expected 0
not ok 18 [7538] Result (-22) is different than expected (0)
...
# Totals: pass:18 fail:1 xfail:0 xpass:0 skip:0 error:0

This is because if CONFIG_TIME_NS is not set, but the flag
CLONE_NEWTIME (0x80) is used to clone a time namespace, it
will return -EINVAL in copy_time_ns().

If kernel does not support CONFIG_TIME_NS, /proc/self/ns/time
will be not exist, and then we should skip clone3() test with
CLONE_NEWTIME.

With this patch under !CONFIG_TIME_NS:

# make headers && cd tools/testing/selftests/clone3 && make && ./clone3
...
# Time namespaces are not supported
ok 18 # SKIP Skipping clone3() with CLONE_NEWTIME
...
# Totals: pass:18 fail:0 xfail:0 xpass:0 skip:1 error:0

Link: https://lkml.kernel.org/r/1689066814-13295-1-git-send-email-yangtiezhu@loongson.cn
Fixes: 515bddf0ec41 ("selftests/clone3: test clone3 with CLONE_NEWTIME")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>


# c4f461a1 04-May-2023 Tobias Klauser <tklauser@distanz.ch>

selftests/clone3: test clone3 with exit signal in flags

Verify that calling clone3 with an exit signal (SIGCHLD) in flags will
fail.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>


# d95debbd 14-Mar-2023 Tobias Klauser <tklauser@distanz.ch>

selftests/clone3: fix number of tests in ksft_set_plan

Commit 515bddf0ec41 ("selftests/clone3: test clone3 with CLONE_NEWTIME")
added an additional test, so the number passed to ksft_set_plan needs to
be bumped accordingly.

Also use ksft_finished() to print results and exit. This will catch future
mismatches between ksft_set_plan() and the number of tests being run.

Fixes: 515bddf0ec41 ("selftests/clone3: test clone3 with CLONE_NEWTIME")
Cc: Christian Brauner <brauner@kernel.org>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>


# 515bddf0 08-Mar-2023 Tobias Klauser <tklauser@distanz.ch>

selftests/clone3: test clone3 with CLONE_NEWTIME

Verify that clone3 can be called successfully with CLONE_NEWTIME in
flags.

Cc: Andrey Vagin <avagin@openvz.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>


# e2aa5e65 27-Jan-2022 Axel Rasmussen <axelrasmussen@google.com>

selftests: fixup build warnings in pidfd / clone3 tests

These are some trivial fixups, which were needed to build the tests with
clang and -Werror. The following issues are fixed:

- Remove various unused variables.
- In child_poll_leader_exit_test, clang isn't smart enough to realize
syscall(SYS_exit, 0) won't return, so it complains we never return
from a non-void function. Add an extra exit(0) to appease it.
- In test_pidfd_poll_leader_exit, ret may be branched on despite being
uninitialized, if we have !use_waitpid. Initialize it to zero to get
the right behavior in that case.

Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
Acked-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>


# a531b0c2 03-Nov-2021 Anders Roxell <anders.roxell@linaro.org>

selftests: clone3: clone3: add case CLONE3_ARGS_NO_TEST

Building selftests/clone3 with clang warns about enumeration not handled
in switch case:

clone3.c:54:10: warning: enumeration value 'CLONE3_ARGS_NO_TEST' not handled in switch [-Wswitch]
switch (test_mode) {
^

Add the missing switch case with a comment.

Fixes: 17a810699c18 ("selftests: add tests for clone3()")
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>


# e953aeaa 12-Sep-2020 Kees Cook <keescook@chromium.org>

selftests/clone3: Avoid OS-defined clone_args

As the UAPI headers start to appear in distros, we need to avoid
outdated versions of struct clone_args to be able to test modern
features, named "struct __clone_args". Additionally update the struct
size macro names to match UAPI names.

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/lkml/20200921075432.u4gis3s2o5qrsb5g@wittgenstein/
Signed-off-by: Kees Cook <keescook@chromium.org>


# 51ad5b54 22-Jun-2020 Kees Cook <keescook@chromium.org>

selftests/clone3: Reorder reporting output

Selftest output reporting was happening before the TAP headers and plan
had been emitted. Move the first test reports later.

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>


# 11fde161 18-Nov-2019 Christian Brauner <christian.brauner@ubuntu.com>

selftests/clone3: skip if clone3() is ENOSYS

If the clone3() syscall is not implemented we should skip the tests.

Fixes: 41585bbeeef9 ("selftests: add tests for clone3() with *set_tid")
Fixes: 17a810699c18 ("selftests: add tests for clone3()")
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>


# 41585bbe 15-Nov-2019 Adrian Reber <areber@redhat.com>

selftests: add tests for clone3() with *set_tid

This tests clone3() with *set_tid to see if all desired PIDs are working
as expected. The tests are trying multiple invalid input parameters as
well as creating processes while specifying a certain PID in multiple
PID namespaces at the same time.

Additionally this moves common clone3() test code into clone3_selftests.h.

Signed-off-by: Adrian Reber <areber@redhat.com>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20191115123621.142252-2-areber@redhat.com
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>


# 17a81069 12-Nov-2019 Adrian Reber <areber@redhat.com>

selftests: add tests for clone3()

This adds tests for clone3() with different values and sizes
of struct clone_args.

This selftest was initially part of of the clone3() with PID selftest.
After that patch was almost merged Eugene sent out a couple of patches
to fix problems with these test.

This commit now only contains the clone3() selftest after the LPC
decision to rework clone3() with PID to allow setting the PID in
multiple PID namespaces including all of Eugene's patches.

Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
Signed-off-by: Adrian Reber <areber@redhat.com>
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20191112095851.811884-1-areber@redhat.com
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>