Commit 41585bbe authored by Adrian Reber's avatar Adrian Reber Committed by Christian Brauner
Browse files

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: default avatarAdrian Reber <areber@redhat.com>
Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20191115123621.142252-2-areber@redhat.com


Signed-off-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 49cb2fc4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
clone3
clone3_clear_sighand
clone3_set_tid
+1 −1
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
CFLAGS += -g -I../../../../usr/include/

TEST_GEN_PROGS := clone3 clone3_clear_sighand
TEST_GEN_PROGS := clone3 clone3_clear_sighand clone3_set_tid

include ../lib.mk
+2 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <sched.h>

#include "../kselftest.h"
#include "clone3_selftests.h"

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

static pid_t raw_clone(struct clone_args *args, size_t size)
{
	return syscall(__NR_clone3, args, size);
}

static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode)
{
	struct clone_args args = {
@@ -83,7 +79,7 @@ static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode)

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

	pid = raw_clone((struct clone_args *)&args_ext, size);
	pid = sys_clone3((struct clone_args *)&args_ext, size);
	if (pid < 0) {
		ksft_print_msg("%s - Failed to create new process\n",
				strerror(errno));
+1 −19
Original line number Diff line number Diff line
@@ -14,30 +14,12 @@
#include <sys/wait.h>

#include "../kselftest.h"
#include "clone3_selftests.h"

#ifndef CLONE_CLEAR_SIGHAND
#define CLONE_CLEAR_SIGHAND 0x100000000ULL
#endif

#ifndef __NR_clone3
#define __NR_clone3 -1
struct clone_args {
	__aligned_u64 flags;
	__aligned_u64 pidfd;
	__aligned_u64 child_tid;
	__aligned_u64 parent_tid;
	__aligned_u64 exit_signal;
	__aligned_u64 stack;
	__aligned_u64 stack_size;
	__aligned_u64 tls;
};
#endif

static pid_t sys_clone3(struct clone_args *args, size_t size)
{
	return syscall(__NR_clone3, args, size);
}

static void test_clone3_supported(void)
{
	pid_t pid;
+35 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef _CLONE3_SELFTESTS_H
#define _CLONE3_SELFTESTS_H

#define _GNU_SOURCE
#include <sched.h>
#include <stdint.h>
#include <syscall.h>
#include <linux/types.h>

#define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr)))

#ifndef __NR_clone3
#define __NR_clone3 -1
struct clone_args {
	__aligned_u64 flags;
	__aligned_u64 pidfd;
	__aligned_u64 child_tid;
	__aligned_u64 parent_tid;
	__aligned_u64 exit_signal;
	__aligned_u64 stack;
	__aligned_u64 stack_size;
	__aligned_u64 tls;
	__aligned_u64 set_tid;
	__aligned_u64 set_tid_size;
};
#endif

static pid_t sys_clone3(struct clone_args *args, size_t size)
{
	return syscall(__NR_clone3, args, size);
}

#endif /* _CLONE3_SELFTESTS_H */
Loading