Skip to content

Commit 41585bb

Browse files
adrianreberChristian Brauner
authored andcommitted
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>
1 parent 49cb2fc commit 41585bb

6 files changed

Lines changed: 421 additions & 26 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
clone3
22
clone3_clear_sighand
3+
clone3_set_tid
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: GPL-2.0
22
CFLAGS += -g -I../../../../usr/include/
33

4-
TEST_GEN_PROGS := clone3 clone3_clear_sighand
4+
TEST_GEN_PROGS := clone3 clone3_clear_sighand clone3_set_tid
55

66
include ../lib.mk

tools/testing/selftests/clone3/clone3.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <sched.h>
1919

2020
#include "../kselftest.h"
21+
#include "clone3_selftests.h"
2122

2223
/*
2324
* Different sizes of struct clone_args
@@ -35,11 +36,6 @@ enum test_mode {
3536
CLONE3_ARGS_INVAL_EXIT_SIGNAL_NSIG,
3637
};
3738

38-
static pid_t raw_clone(struct clone_args *args, size_t size)
39-
{
40-
return syscall(__NR_clone3, args, size);
41-
}
42-
4339
static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode)
4440
{
4541
struct clone_args args = {
@@ -83,7 +79,7 @@ static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode)
8379

8480
memcpy(&args_ext.args, &args, sizeof(struct clone_args));
8581

86-
pid = raw_clone((struct clone_args *)&args_ext, size);
82+
pid = sys_clone3((struct clone_args *)&args_ext, size);
8783
if (pid < 0) {
8884
ksft_print_msg("%s - Failed to create new process\n",
8985
strerror(errno));

tools/testing/selftests/clone3/clone3_clear_sighand.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,12 @@
1414
#include <sys/wait.h>
1515

1616
#include "../kselftest.h"
17+
#include "clone3_selftests.h"
1718

1819
#ifndef CLONE_CLEAR_SIGHAND
1920
#define CLONE_CLEAR_SIGHAND 0x100000000ULL
2021
#endif
2122

22-
#ifndef __NR_clone3
23-
#define __NR_clone3 -1
24-
struct clone_args {
25-
__aligned_u64 flags;
26-
__aligned_u64 pidfd;
27-
__aligned_u64 child_tid;
28-
__aligned_u64 parent_tid;
29-
__aligned_u64 exit_signal;
30-
__aligned_u64 stack;
31-
__aligned_u64 stack_size;
32-
__aligned_u64 tls;
33-
};
34-
#endif
35-
36-
static pid_t sys_clone3(struct clone_args *args, size_t size)
37-
{
38-
return syscall(__NR_clone3, args, size);
39-
}
40-
4123
static void test_clone3_supported(void)
4224
{
4325
pid_t pid;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef _CLONE3_SELFTESTS_H
4+
#define _CLONE3_SELFTESTS_H
5+
6+
#define _GNU_SOURCE
7+
#include <sched.h>
8+
#include <stdint.h>
9+
#include <syscall.h>
10+
#include <linux/types.h>
11+
12+
#define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr)))
13+
14+
#ifndef __NR_clone3
15+
#define __NR_clone3 -1
16+
struct clone_args {
17+
__aligned_u64 flags;
18+
__aligned_u64 pidfd;
19+
__aligned_u64 child_tid;
20+
__aligned_u64 parent_tid;
21+
__aligned_u64 exit_signal;
22+
__aligned_u64 stack;
23+
__aligned_u64 stack_size;
24+
__aligned_u64 tls;
25+
__aligned_u64 set_tid;
26+
__aligned_u64 set_tid_size;
27+
};
28+
#endif
29+
30+
static pid_t sys_clone3(struct clone_args *args, size_t size)
31+
{
32+
return syscall(__NR_clone3, args, size);
33+
}
34+
35+
#endif /* _CLONE3_SELFTESTS_H */

0 commit comments

Comments
 (0)