Commit 4834ce9d authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-5.9-rc1' of...

Merge tag 'linux-kselftest-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest updates form Shuah Khan:

 - TAP output reporting related fixes from Paolo Bonzini and Kees Cook.

   These fixes make it skip reporting consistent with TAP format.

 - Cleanup fixes to framework run_tests from Yauheni Kaliuta

* tag 'linux-kselftest-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (23 commits)
  selftests/harness: Limit step counter reporting
  selftests/seccomp: Check ENOSYS under tracing
  selftests/seccomp: Refactor to use fixture variants
  selftests/harness: Clean up kern-doc for fixtures
  selftests: kmod: Add module address visibility test
  Replace HTTP links with HTTPS ones: KMOD KERNEL MODULE LOADER - USERMODE HELPER
  selftests: fix condition in run_tests
  selftests: do not use .ONESHELL
  selftests: pidfd: skip test if unshare fails with EPERM
  selftests: pidfd: do not use ksft_exit_skip after ksft_set_plan
  selftests/harness: Report skip reason
  selftests/harness: Display signed values correctly
  selftests/harness: Refactor XFAIL into SKIP
  selftests/harness: Switch to TAP output
  selftests: Add header documentation and helpers
  selftests/binderfs: Fix harness API usage
  selftests: Remove unneeded selftest API headers
  selftests/clone3: Reorder reporting output
  selftests: sync_test: do not use ksft_exit_skip after ksft_set_plan
  selftests: sigaltstack: do not use ksft_exit_skip after ksft_set_plan
  ...
parents 53e5504b 850d0cc6
......@@ -47,7 +47,7 @@ void child(int cpu)
_exit(0);
}
bool run_test(int cpu)
int run_test(int cpu)
{
int status;
pid_t pid = fork();
......@@ -55,7 +55,7 @@ bool run_test(int cpu)
if (pid < 0) {
ksft_print_msg("fork() failed: %s\n", strerror(errno));
return false;
return KSFT_FAIL;
}
if (pid == 0)
child(cpu);
......@@ -63,67 +63,68 @@ bool run_test(int cpu)
wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) {
ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
return false;
return KSFT_FAIL;
}
if (!WIFSTOPPED(status)) {
ksft_print_msg("child did not stop: %s\n", strerror(errno));
return false;
return KSFT_FAIL;
}
if (WSTOPSIG(status) != SIGSTOP) {
ksft_print_msg("child did not stop with SIGSTOP: %s\n",
strerror(errno));
return false;
return KSFT_FAIL;
}
if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) {
if (errno == EIO) {
ksft_exit_skip(
ksft_print_msg(
"ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n",
strerror(errno));
return KSFT_SKIP;
}
ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n",
strerror(errno));
return false;
return KSFT_FAIL;
}
wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) {
ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
return false;
return KSFT_FAIL;
}
if (WIFEXITED(status)) {
ksft_print_msg("child did not single-step: %s\n",
strerror(errno));
return false;
return KSFT_FAIL;
}
if (!WIFSTOPPED(status)) {
ksft_print_msg("child did not stop: %s\n", strerror(errno));
return false;
return KSFT_FAIL;
}
if (WSTOPSIG(status) != SIGTRAP) {
ksft_print_msg("child did not stop with SIGTRAP: %s\n",
strerror(errno));
return false;
return KSFT_FAIL;
}
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n",
strerror(errno));
return false;
return KSFT_FAIL;
}
wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) {
ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
return false;
return KSFT_FAIL;
}
if (!WIFEXITED(status)) {
ksft_print_msg("child did not exit after PTRACE_CONT: %s\n",
strerror(errno));
return false;
return KSFT_FAIL;
}
return true;
return KSFT_PASS;
}
void suspend(void)
......@@ -183,32 +184,38 @@ int main(int argc, char **argv)
}
}
err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus);
if (err < 0)
ksft_exit_fail_msg("sched_getaffinity() failed\n");
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
if (!CPU_ISSET(cpu, &available_cpus))
continue;
tests++;
}
ksft_set_plan(tests);
if (do_suspend)
suspend();
err = sched_getaffinity(0, sizeof(available_cpus), &available_cpus);
if (err < 0)
ksft_exit_fail_msg("sched_getaffinity() failed\n");
ksft_set_plan(tests);
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
bool test_success;
int test_success;
if (!CPU_ISSET(cpu, &available_cpus))
continue;
test_success = run_test(cpu);
if (test_success) {
switch (test_success) {
case KSFT_PASS:
ksft_test_result_pass("CPU %d\n", cpu);
} else {
break;
case KSFT_SKIP:
ksft_test_result_skip("CPU %d\n", cpu);
break;
case KSFT_FAIL:
ksft_test_result_fail("CPU %d\n", cpu);
succeeded = false;
break;
}
}
......
......@@ -131,9 +131,9 @@ int main(int argc, char *argv[])
uid_t uid = getuid();
test_clone3_supported();
ksft_print_header();
ksft_set_plan(17);
test_clone3_supported();
/* Just a simple clone3() should return 0.*/
test_clone3(0, 0, 0, CLONE3_ARGS_NO_TEST);
......
......@@ -119,9 +119,8 @@ static void test_clone3_clear_sighand(void)
int main(int argc, char **argv)
{
ksft_print_header();
test_clone3_supported();
ksft_set_plan(1);
test_clone3_supported();
test_clone3_clear_sighand();
......
......@@ -157,8 +157,8 @@ int main(int argc, char *argv[])
pid_t set_tid[MAX_PID_NS_LEVEL * 2];
ksft_print_header();
test_clone3_supported();
ksft_set_plan(29);
test_clone3_supported();
if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0)
ksft_exit_fail_msg("pipe() failed\n");
......
......@@ -130,7 +130,7 @@ test_reqs()
if [[ $KMOD_VERSION -le 19 ]]; then
echo "$0: You need at least kmod 20" >&2
echo "kmod <= 19 is buggy, for details see:" >&2
echo "http://git.kernel.org/cgit/utils/kernel/kmod/kmod.git/commit/libkmod/libkmod-module.c?id=fd44a98ae2eb5eb32161088954ab21e58e19dfc4" >&2
echo "https://git.kernel.org/cgit/utils/kernel/kmod/kmod.git/commit/libkmod/libkmod-module.c?id=fd44a98ae2eb5eb32161088954ab21e58e19dfc4" >&2
exit $ksft_skip
fi
......
/* SPDX-License-Identifier: GPL-2.0 */
/*
* kselftest.h: kselftest framework return codes to include from
* selftests.
* kselftest.h: low-level kselftest framework to include from
* selftest programs. When possible, please use
* kselftest_harness.h instead.
*
* Copyright (c) 2014 Shuah Khan <shuahkh@osg.samsung.com>
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
*
* Using this API consists of first counting how many tests your code
* has to run, and then starting up the reporting:
*
* ksft_print_header();
* ksft_set_plan(total_number_of_tests);
*
* For each test, report any progress, debugging, etc with:
*
* ksft_print_msg(fmt, ...);
*
* and finally report the pass/fail/skip/xfail state of the test with one of:
*
* ksft_test_result(condition, fmt, ...);
* ksft_test_result_pass(fmt, ...);
* ksft_test_result_fail(fmt, ...);
* ksft_test_result_skip(fmt, ...);
* ksft_test_result_xfail(fmt, ...);
* ksft_test_result_error(fmt, ...);
*
* When all tests are finished, clean up and exit the program with one of:
*
* ksft_exit(condition);
* ksft_exit_pass();
* ksft_exit_fail();
*
* If the program wants to report details on why the entire program has
* failed, it can instead exit with a message (this is usually done when
* the program is aborting before finishing all tests):
*
* ksft_exit_fail_msg(fmt, ...);
*
*/
#ifndef __KSELFTEST_H
#define __KSELFTEST_H
......@@ -74,7 +106,7 @@ static inline void ksft_print_cnts(void)
if (ksft_plan != ksft_test_num())
printf("# Planned tests != run tests (%u != %u)\n",
ksft_plan, ksft_test_num());
printf("# Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n",
printf("# Totals: pass:%d fail:%d xfail:%d xpass:%d skip:%d error:%d\n",
ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
......@@ -120,6 +152,32 @@ static inline void ksft_test_result_fail(const char *msg, ...)
va_end(args);
}
/**
* ksft_test_result() - Report test success based on truth of condition
*
* @condition: if true, report test success, otherwise failure.
*/
#define ksft_test_result(condition, fmt, ...) do { \
if (!!(condition)) \
ksft_test_result_pass(fmt, ##__VA_ARGS__);\
else \
ksft_test_result_fail(fmt, ##__VA_ARGS__);\
} while (0)
static inline void ksft_test_result_xfail(const char *msg, ...)
{
int saved_errno = errno;
va_list args;
ksft_cnt.ksft_xfail++;
va_start(args, msg);
printf("ok %d # XFAIL ", ksft_test_num());
errno = saved_errno;
vprintf(msg, args);
va_end(args);
}
static inline void ksft_test_result_skip(const char *msg, ...)
{
int saved_errno = errno;
......@@ -128,12 +186,13 @@ static inline void ksft_test_result_skip(const char *msg, ...)
ksft_cnt.ksft_xskip++;
va_start(args, msg);
printf("not ok %d # SKIP ", ksft_test_num());
printf("ok %d # SKIP ", ksft_test_num());
errno = saved_errno;
vprintf(msg, args);
va_end(args);
}
/* TODO: how does "error" differ from "fail" or "skip"? */
static inline void ksft_test_result_error(const char *msg, ...)
{
int saved_errno = errno;
......@@ -156,11 +215,22 @@ static inline int ksft_exit_pass(void)
static inline int ksft_exit_fail(void)
{
printf("Bail out!\n");
ksft_print_cnts();
exit(KSFT_FAIL);
}
/**
* ksft_exit() - Exit selftest based on truth of condition
*
* @condition: if true, exit self test with success, otherwise fail.
*/
#define ksft_exit(condition) do { \
if (!!(condition)) \
ksft_exit_pass(); \
else \
ksft_exit_fail(); \
} while (0)
static inline int ksft_exit_fail_msg(const char *msg, ...)
{
int saved_errno = errno;
......@@ -190,18 +260,30 @@ static inline int ksft_exit_xpass(void)
static inline int ksft_exit_skip(const char *msg, ...)
{
if (msg) {
int saved_errno = errno;
va_list args;
int saved_errno = errno;
va_list args;
va_start(args, msg);
va_start(args, msg);
printf("not ok %d # SKIP ", 1 + ksft_test_num());
/*
* FIXME: several tests misuse ksft_exit_skip so produce
* something sensible if some tests have already been run
* or a plan has been printed. Those tests should use
* ksft_test_result_skip or ksft_exit_fail_msg instead.
*/
if (ksft_plan || ksft_test_num()) {
ksft_cnt.ksft_xskip++;
printf("ok %d # SKIP ", 1 + ksft_test_num());
} else {
printf("1..0 # SKIP ");
}
if (msg) {
errno = saved_errno;
vprintf(msg, args);
va_end(args);
} else {
ksft_print_cnts();
}
if (ksft_test_num())
ksft_print_cnts();
exit(KSFT_SKIP);
}
......
......@@ -77,7 +77,7 @@ run_one()
echo "ok $test_num $TEST_HDR_MSG") ||
(rc=$?; \
if [ $rc -eq $skip_rc ]; then \
echo "not ok $test_num $TEST_HDR_MSG # SKIP"
echo "ok $test_num $TEST_HDR_MSG # SKIP"
elif [ $rc -eq $timeout_rc ]; then \
echo "#"
echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT"
......
This diff is collapsed.
......@@ -59,9 +59,8 @@ else
all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
endif
.ONESHELL:
define RUN_TESTS
@BASE_DIR="$(selfdir)"; \
BASE_DIR="$(selfdir)"; \
. $(selfdir)/kselftest/runner.sh; \
if [ "X$(summary)" != "X" ]; then \
per_test_logging=1; \
......@@ -71,22 +70,21 @@ endef
run_tests: all
ifdef building_out_of_srctree
@if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
@rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
@if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \
fi
@if [ "X$(TEST_PROGS)" != "X" ]; then
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
else
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
@if [ "X$(TEST_PROGS)" != "X" ]; then \
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS)) ; \
else \
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \
fi
else
$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
@$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
endif
define INSTALL_SINGLE_RULE
$(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH))
$(if $(INSTALL_LIST),@echo rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/)
$(if $(INSTALL_LIST),@rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/)
$(if $(INSTALL_LIST),rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/)
endef
define INSTALL_RULE
......
......@@ -11,7 +11,6 @@
#include <syscall.h>
#include <sys/wait.h>
#include "../kselftest.h"
#include "../kselftest_harness.h"
#include "../pidfd/pidfd.h"
......
......@@ -18,7 +18,6 @@
#include <linux/kcmp.h>
#include "pidfd.h"
#include "../kselftest.h"
#include "../kselftest_harness.h"
/*
......
......@@ -20,7 +20,6 @@
#include "pidfd.h"
#include "../clone3/clone3_selftests.h"
#include "../kselftest.h"
#include "../kselftest_harness.h"
enum {
......
......@@ -8,6 +8,7 @@
#include <sched.h>
#include <signal.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <syscall.h>
......@@ -27,6 +28,8 @@
#define MAX_EVENTS 5
static bool have_pidfd_send_signal;
static pid_t pidfd_clone(int flags, int *pidfd, int (*fn)(void *))
{
size_t stack_size = 1024;
......@@ -56,6 +59,13 @@ static int test_pidfd_send_signal_simple_success(void)
int pidfd, ret;
const char *test_name = "pidfd_send_signal send SIGUSR1";
if (!have_pidfd_send_signal) {
ksft_test_result_skip(
"%s test: pidfd_send_signal() syscall not supported\n",
test_name);
return 0;
}
pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC);
if (pidfd < 0)
ksft_exit_fail_msg(
......@@ -86,6 +96,13 @@ static int test_pidfd_send_signal_exited_fail(void)
pid_t pid;
const char *test_name = "pidfd_send_signal signal exited process";
if (!have_pidfd_send_signal) {
ksft_test_result_skip(
"%s test: pidfd_send_signal() syscall not supported\n",
test_name);
return 0;
}
pid = fork();
if (pid < 0)
ksft_exit_fail_msg("%s test: Failed to create new process\n",
......@@ -137,16 +154,34 @@ static int test_pidfd_send_signal_recycled_pid_fail(void)
pid_t pid1;
const char *test_name = "pidfd_send_signal signal recycled pid";
if (!have_pidfd_send_signal) {
ksft_test_result_skip(
"%s test: pidfd_send_signal() syscall not supported\n",
test_name);
return 0;
}
ret = unshare(CLONE_NEWPID);
if (ret < 0)
if (ret < 0) {
if (errno == EPERM) {
ksft_test_result_skip("%s test: Unsharing pid namespace not permitted\n",
test_name);
return 0;
}
ksft_exit_fail_msg("%s test: Failed to unshare pid namespace\n",
test_name);
}
ret = unshare(CLONE_NEWNS);
if (ret < 0)
ksft_exit_fail_msg(
"%s test: Failed to unshare mount namespace\n",
test_name);
if (ret < 0) {
if (errno == EPERM) {
ksft_test_result_skip("%s test: Unsharing mount namespace not permitted\n",
test_name);
return 0;
}
ksft_exit_fail_msg("%s test: Failed to unshare mount namespace\n",
test_name);
}
ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
if (ret < 0)
......@@ -325,15 +360,17 @@ static int test_pidfd_send_signal_syscall_support(void)
ret = sys_pidfd_send_signal(pidfd, 0, NULL, 0);
if (ret < 0) {
if (errno == ENOSYS)
ksft_exit_skip(
if (errno == ENOSYS) {
ksft_test_result_skip(
"%s test: pidfd_send_signal() syscall not supported\n",
test_name);
return 0;
}
ksft_exit_fail_msg("%s test: Failed to send signal\n",
test_name);
}
have_pidfd_send_signal = true;
close(pidfd);
ksft_test_result_pass(
"%s test: pidfd_send_signal() syscall is supported. Tests can be executed\n",
......@@ -521,7 +558,7 @@ static void test_pidfd_poll_leader_exit(int use_waitpid)
int main(int argc, char **argv)
{
ksft_print_header();
ksft_set_plan(4);
ksft_set_plan(8);
test_pidfd_poll_exec(0);
test_pidfd_poll_exec(1);
......
......@@ -71,7 +71,7 @@ void my_usr1(int sig, siginfo_t *si, void *u)
swapcontext(&sc, &uc);
ksft_print_msg("%s\n", p->msg);
if (!p->flag) {
ksft_exit_skip("[RUN]\tAborting\n");
ksft_exit_fail_msg("[RUN]\tAborting\n");
exit(EXIT_FAILURE);
}
}
......@@ -144,7 +144,7 @@ int main(void)
err = sigaltstack(&stk, NULL);
if (err) {
if (errno == EINVAL) {
ksft_exit_skip(
ksft_test_result_skip(
"[NOTE]\tThe running kernel doesn't support SS_AUTODISARM\n");
/*
* If test cases for the !SS_AUTODISARM variant were
......
......@@ -86,9 +86,9 @@ int main(void)
int err;
ksft_print_header();
ksft_set_plan(3 + 7);
sync_api_supported();
ksft_set_plan(3 + 7);
ksft_print_msg("[RUN]\tTesting sync framework\n");
......
......@@ -19,7 +19,6 @@
#include <sys/wait.h>
#include <unistd.h>
#include "../kselftest.h"
#include "../kselftest_harness.h"
#define __DEV_FULL "/sys/devices/virtual/mem/full/uevent"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment