Commit 4b95dc87 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux_kselftest-next-6.10-rc1' of...

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

Pull kselftest updates from Shuah Khan:

 - make framework and tests reporting KTAP compliant

 - make ktap_helpers and power_supply test POSIX compliant

 - add ksft_exit_fail_perror() to include errono in string form

 - avoid clang reporting false positive static analysis errors about
   functions that exit and never return. ksft_exit* functions are marked
   __noreturn to address this problem

 - add mechanism for reporting a KSFT_ result code

 - fix build warnings related missing headers and unused variables

 - fix clang build failures

 - cleanups to resctrl test

 - add host arch for LLVM builds

* tag 'linux_kselftest-next-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (44 commits)
  selftests/sgx: Include KHDR_INCLUDES in Makefile
  selftests: Compile kselftest headers with -D_GNU_SOURCE
  selftests/resctrl: fix clang build warnings related to abs(), labs() calls
  selftests/ftrace: Fix checkbashisms errors
  selftests/ftrace: Fix BTFARG testcase to check fprobe is enabled correctly
  selftests/capabilities: fix warn_unused_result build warnings
  selftests: filesystems: add missing stddef header
  selftests: kselftest_deps: fix l5_test() empty variable
  selftests: default to host arch for LLVM builds
  selftests/resctrl: fix clang build failure: use LOCAL_HDRS
  selftests/binderfs: use the Makefile's rules, not Make's implicit rules
  Documentation: kselftest: fix codeblock
  selftests: kselftest: Make ksft_exit functions return void instead of int
  selftests: x86: ksft_exit_pass() does not return
  selftests: timers: ksft_exit functions do not return
  selftests: sync: ksft_exit_pass() does not return
  selftests/resctrl: ksft_exit_skip() does not return
  selftests: pidfd: ksft_exit functions do not return
  selftests/mm: ksft_exit functions do not return
  selftests: membarrier: ksft_exit_pass() does not return
  ...
parents 896d3fce 2c3b8f8f
......@@ -183,7 +183,7 @@ expected time it takes to run a test. If you have control over the systems
which will run the tests you can configure a test runner on those systems to
use a greater or lower timeout on the command line as with the `-o` or
the `--override-timeout` argument. For example to use 165 seconds instead
one would use:
one would use::
$ ./run_kselftest.sh --override-timeout 165
......
......@@ -161,11 +161,11 @@ ifneq ($(KBUILD_OUTPUT),)
# $(realpath ...) resolves symlinks
abs_objtree := $(realpath $(abs_objtree))
BUILD := $(abs_objtree)/kselftest
KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
KHDR_INCLUDES := -D_GNU_SOURCE -isystem ${abs_objtree}/usr/include
else
BUILD := $(CURDIR)
abs_srctree := $(shell cd $(top_srcdir) && pwd)
KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
KHDR_INCLUDES := -D_GNU_SOURCE -isystem ${abs_srctree}/usr/include
DEFAULT_INSTALL_HDR_PATH := 1
endif
......
......@@ -82,7 +82,7 @@ static bool create_and_enter_ns(uid_t inner_uid)
{
uid_t outer_uid;
gid_t outer_gid;
int i;
int i, ret;
bool have_outer_privilege;
outer_uid = getuid();
......@@ -97,7 +97,10 @@ static bool create_and_enter_ns(uid_t inner_uid)
ksft_exit_fail_msg("setresuid - %s\n", strerror(errno));
// Re-enable effective caps
capng_get_caps_process();
ret = capng_get_caps_process();
if (ret == -1)
ksft_exit_fail_msg("capng_get_caps_process failed\n");
for (i = 0; i < CAP_LAST_CAP; i++)
if (capng_have_capability(CAPNG_PERMITTED, i))
capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, i);
......@@ -207,6 +210,7 @@ static void exec_validate_cap(bool eff, bool perm, bool inh, bool ambient)
static int do_tests(int uid, const char *our_path)
{
int ret;
bool have_outer_privilege = create_and_enter_ns(uid);
int ourpath_fd = open(our_path, O_RDONLY | O_DIRECTORY);
......@@ -250,7 +254,9 @@ static int do_tests(int uid, const char *our_path)
ksft_exit_fail_msg("chmod - %s\n", strerror(errno));
}
capng_get_caps_process();
ret = capng_get_caps_process();
if (ret == -1)
ksft_exit_fail_msg("capng_get_caps_process failed\n");
/* Make sure that i starts out clear */
capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE);
......
......@@ -28,6 +28,7 @@ static bool bool_arg(char **argv, int i)
int main(int argc, char **argv)
{
const char *atsec = "";
int ret;
/*
* Be careful just in case a setgid or setcapped copy of this
......@@ -44,7 +45,11 @@ int main(int argc, char **argv)
atsec = " (AT_SECURE is not set)";
#endif
capng_get_caps_process();
ret = capng_get_caps_process();
if (ret == -1) {
ksft_print_msg("capng_get_caps_process failed\n");
return 1;
}
if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 1)) {
ksft_print_msg("Wrong effective state%s\n", atsec);
......
......@@ -95,9 +95,14 @@ static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode)
getpid(), pid);
if (waitpid(-1, &status, __WALL) < 0) {
ksft_print_msg("Child returned %s\n", strerror(errno));
ksft_print_msg("waitpid() returned %s\n", strerror(errno));
return -errno;
}
if (!WIFEXITED(status)) {
ksft_print_msg("Child did not exit normally, status 0x%x\n",
status);
return EXIT_FAILURE;
}
if (WEXITSTATUS(status))
return WEXITSTATUS(status);
......
......@@ -120,5 +120,5 @@ int main(int argc, char **argv)
test_clone3_clear_sighand();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -114,7 +114,8 @@ static int call_clone3_set_tid(pid_t *set_tid,
return WEXITSTATUS(status);
}
static void test_clone3_set_tid(pid_t *set_tid,
static void test_clone3_set_tid(const char *desc,
pid_t *set_tid,
size_t set_tid_size,
int flags,
int expected,
......@@ -129,17 +130,13 @@ static void test_clone3_set_tid(pid_t *set_tid,
ret = call_clone3_set_tid(set_tid, set_tid_size, flags, expected_pid,
wait_for_it);
ksft_print_msg(
"[%d] clone3() with CLONE_SET_TID %d says :%d - expected %d\n",
"[%d] clone3() with CLONE_SET_TID %d says: %d - expected %d\n",
getpid(), set_tid[0], ret, expected);
if (ret != expected)
ksft_test_result_fail(
"[%d] Result (%d) is different than expected (%d)\n",
getpid(), ret, expected);
else
ksft_test_result_pass(
"[%d] Result (%d) matches expectation (%d)\n",
getpid(), ret, expected);
ksft_test_result(ret == expected, "%s with %zu TIDs and flags 0x%x\n",
desc, set_tid_size, flags);
}
int main(int argc, char *argv[])
{
FILE *f;
......@@ -172,73 +169,91 @@ int main(int argc, char *argv[])
/* Try invalid settings */
memset(&set_tid, 0, sizeof(set_tid));
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL + 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid("invalid size, 0 TID",
set_tid, MAX_PID_NS_LEVEL + 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 2, 0, -EINVAL, 0, 0);
test_clone3_set_tid("invalid size, 0 TID",
set_tid, MAX_PID_NS_LEVEL * 2, 0, -EINVAL, 0, 0);
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 2 + 1, 0,
-EINVAL, 0, 0);
test_clone3_set_tid("invalid size, 0 TID",
set_tid, MAX_PID_NS_LEVEL * 2 + 1, 0,
-EINVAL, 0, 0);
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 42, 0, -EINVAL, 0, 0);
test_clone3_set_tid("invalid size, 0 TID",
set_tid, MAX_PID_NS_LEVEL * 42, 0, -EINVAL, 0, 0);
/*
* This can actually work if this test running in a MAX_PID_NS_LEVEL - 1
* nested PID namespace.
*/
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL - 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid("invalid size, 0 TID",
set_tid, MAX_PID_NS_LEVEL - 1, 0, -EINVAL, 0, 0);
memset(&set_tid, 0xff, sizeof(set_tid));
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL + 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid("invalid size, TID all 1s",
set_tid, MAX_PID_NS_LEVEL + 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 2, 0, -EINVAL, 0, 0);
test_clone3_set_tid("invalid size, TID all 1s",
set_tid, MAX_PID_NS_LEVEL * 2, 0, -EINVAL, 0, 0);
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 2 + 1, 0,
-EINVAL, 0, 0);
test_clone3_set_tid("invalid size, TID all 1s",
set_tid, MAX_PID_NS_LEVEL * 2 + 1, 0,
-EINVAL, 0, 0);
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL * 42, 0, -EINVAL, 0, 0);
test_clone3_set_tid("invalid size, TID all 1s",
set_tid, MAX_PID_NS_LEVEL * 42, 0, -EINVAL, 0, 0);
/*
* This can actually work if this test running in a MAX_PID_NS_LEVEL - 1
* nested PID namespace.
*/
test_clone3_set_tid(set_tid, MAX_PID_NS_LEVEL - 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid("invalid size, TID all 1s",
set_tid, MAX_PID_NS_LEVEL - 1, 0, -EINVAL, 0, 0);
memset(&set_tid, 0, sizeof(set_tid));
/* Try with an invalid PID */
set_tid[0] = 0;
test_clone3_set_tid(set_tid, 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid("valid size, 0 TID",
set_tid, 1, 0, -EINVAL, 0, 0);
set_tid[0] = -1;
test_clone3_set_tid(set_tid, 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid("valid size, -1 TID",
set_tid, 1, 0, -EINVAL, 0, 0);
/* Claim that the set_tid array actually contains 2 elements. */
test_clone3_set_tid(set_tid, 2, 0, -EINVAL, 0, 0);
test_clone3_set_tid("2 TIDs, -1 and 0",
set_tid, 2, 0, -EINVAL, 0, 0);
/* Try it in a new PID namespace */
if (uid == 0)
test_clone3_set_tid(set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
test_clone3_set_tid("valid size, -1 TID",
set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
else
ksft_test_result_skip("Clone3() with set_tid requires root\n");
/* Try with a valid PID (1) this should return -EEXIST. */
set_tid[0] = 1;
if (uid == 0)
test_clone3_set_tid(set_tid, 1, 0, -EEXIST, 0, 0);
test_clone3_set_tid("duplicate PID 1",
set_tid, 1, 0, -EEXIST, 0, 0);
else
ksft_test_result_skip("Clone3() with set_tid requires root\n");
/* Try it in a new PID namespace */
if (uid == 0)
test_clone3_set_tid(set_tid, 1, CLONE_NEWPID, 0, 0, 0);
test_clone3_set_tid("duplicate PID 1",
set_tid, 1, CLONE_NEWPID, 0, 0, 0);
else
ksft_test_result_skip("Clone3() with set_tid requires root\n");
/* pid_max should fail everywhere */
set_tid[0] = pid_max;
test_clone3_set_tid(set_tid, 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid("set TID to maximum",
set_tid, 1, 0, -EINVAL, 0, 0);
if (uid == 0)
test_clone3_set_tid(set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
test_clone3_set_tid("set TID to maximum",
set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
else
ksft_test_result_skip("Clone3() with set_tid requires root\n");
......@@ -262,10 +277,12 @@ int main(int argc, char *argv[])
/* After the child has finished, its PID should be free. */
set_tid[0] = pid;
test_clone3_set_tid(set_tid, 1, 0, 0, 0, 0);
test_clone3_set_tid("reallocate child TID",
set_tid, 1, 0, 0, 0, 0);
/* This should fail as there is no PID 1 in that namespace */
test_clone3_set_tid(set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
test_clone3_set_tid("duplicate child TID",
set_tid, 1, CLONE_NEWPID, -EINVAL, 0, 0);
/*
* Creating a process with PID 1 in the newly created most nested
......@@ -274,7 +291,8 @@ int main(int argc, char *argv[])
*/
set_tid[0] = 1;
set_tid[1] = pid;
test_clone3_set_tid(set_tid, 2, CLONE_NEWPID, 0, pid, 0);
test_clone3_set_tid("create PID 1 in new NS",
set_tid, 2, CLONE_NEWPID, 0, pid, 0);
ksft_print_msg("unshare PID namespace\n");
if (unshare(CLONE_NEWPID) == -1)
......@@ -284,7 +302,8 @@ int main(int argc, char *argv[])
set_tid[0] = pid;
/* This should fail as there is no PID 1 in that namespace */
test_clone3_set_tid(set_tid, 1, 0, -EINVAL, 0, 0);
test_clone3_set_tid("duplicate PID 1",
set_tid, 1, 0, -EINVAL, 0, 0);
/* Let's create a PID 1 */
ns_pid = fork();
......@@ -295,21 +314,25 @@ int main(int argc, char *argv[])
*/
set_tid[0] = 43;
set_tid[1] = -1;
test_clone3_set_tid(set_tid, 2, 0, -EINVAL, 0, 0);
test_clone3_set_tid("check leak on invalid TID -1",
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);
test_clone3_set_tid("check leak on invalid specific 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);
test_clone3_set_tid("create PID 2 in child NS",
set_tid, 1, 0, 0, 2, 0);
set_tid[0] = 1;
set_tid[1] = -1;
set_tid[2] = pid;
/* This should fail as there is invalid PID at level '1'. */
test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, -EINVAL, 0, 0);
test_clone3_set_tid("fail due to invalid TID at level 1",
set_tid, 3, CLONE_NEWPID, -EINVAL, 0, 0);
set_tid[0] = 1;
set_tid[1] = 42;
......@@ -319,13 +342,15 @@ int main(int argc, char *argv[])
* namespaces. Again assuming this is running in the host's
* PID namespace. Not yet nested.
*/
test_clone3_set_tid(set_tid, 4, CLONE_NEWPID, -EINVAL, 0, 0);
test_clone3_set_tid("fail due to too few active PID NSs",
set_tid, 4, CLONE_NEWPID, -EINVAL, 0, 0);
/*
* This should work and from the parent we should see
* something like 'NSpid: pid 42 1'.
*/
test_clone3_set_tid(set_tid, 3, CLONE_NEWPID, 0, 42, true);
test_clone3_set_tid("verify that we have 3 PID NSs",
set_tid, 3, CLONE_NEWPID, 0, 42, true);
child_exit(ksft_cnt.ksft_fail);
}
......@@ -380,16 +405,14 @@ int main(int argc, char *argv[])
ksft_cnt.ksft_pass += 6 - (ksft_cnt.ksft_fail - WEXITSTATUS(status));
ksft_cnt.ksft_fail = WEXITSTATUS(status);
if (ns3 == pid && ns2 == 42 && ns1 == 1)
ksft_test_result_pass(
"PIDs in all namespaces as expected (%d,%d,%d)\n",
ns3, ns2, ns1);
else
ksft_test_result_fail(
"PIDs in all namespaces not as expected (%d,%d,%d)\n",
ns3, ns2, ns1);
ksft_print_msg("Expecting PIDs %d, 42, 1\n", pid);
ksft_print_msg("Have PIDs in namespaces: %d, %d, %d\n", ns3, ns2, ns1);
ksft_test_result(ns3 == pid && ns2 == 42 && ns1 == 1,
"PIDs in all namespaces as expected\n");
out:
ret = 0;
return !ret ? ksft_exit_pass() : ksft_exit_fail();
if (ret)
ksft_exit_fail();
ksft_exit_pass();
}
......@@ -178,8 +178,7 @@ cpufreq_basic_tests()
count=$(count_cpufreq_managed_cpus)
if [ $count = 0 ]; then
printf "No cpu is managed by cpufreq core, exiting\n"
exit;
ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting\n"
else
printf "CPUFreq manages: $count CPUs\n\n"
fi
......
......@@ -7,15 +7,15 @@ source governor.sh
source module.sh
source special-tests.sh
DIR="$(dirname $(readlink -f "$0"))"
source "${DIR}"/../kselftest/ktap_helpers.sh
FUNC=basic # do basic tests by default
OUTFILE=cpufreq_selftest
SYSFS=
CPUROOT=
CPUFREQROOT=
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
helpme()
{
printf "Usage: $0 [-h] [-todg args]
......@@ -32,7 +32,7 @@ helpme()
[-d <driver's module name: only with \"-t modtest>\"]
[-g <governor's module name: only with \"-t modtest>\"]
\n"
exit 2
exit "${KSFT_FAIL}"
}
prerequisite()
......@@ -40,8 +40,8 @@ prerequisite()
msg="skip all tests:"
if [ $UID != 0 ]; then
echo $msg must be run as root >&2
exit $ksft_skip
ktap_skip_all "$msg must be run as root"
exit "${KSFT_SKIP}"
fi
taskset -p 01 $$
......@@ -49,21 +49,21 @@ prerequisite()
SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
if [ ! -d "$SYSFS" ]; then
echo $msg sysfs is not mounted >&2
exit 2
ktap_skip_all "$msg sysfs is not mounted"
exit "${KSFT_SKIP}"
fi
CPUROOT=$SYSFS/devices/system/cpu
CPUFREQROOT="$CPUROOT/cpufreq"
if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
echo $msg cpus not available in sysfs >&2
exit 2
ktap_skip_all "$msg cpus not available in sysfs"
exit "${KSFT_SKIP}"
fi
if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
echo $msg cpufreq directory not available in sysfs >&2
exit 2
ktap_skip_all "$msg cpufreq directory not available in sysfs"
exit "${KSFT_SKIP}"
fi
}
......@@ -105,8 +105,7 @@ do_test()
count=$(count_cpufreq_managed_cpus)
if [ $count = 0 -a $FUNC != "modtest" ]; then
echo "No cpu is managed by cpufreq core, exiting"
exit 2;
ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"
fi
case "$FUNC" in
......@@ -125,8 +124,7 @@ do_test()
"modtest")
# Do we have modules in place?
if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
echo "No driver or governor module passed with -d or -g"
exit 2;
ktap_exit_fail_msg "No driver or governor module passed with -d or -g"
fi
if [ $DRIVER_MOD ]; then
......@@ -137,8 +135,7 @@ do_test()
fi
else
if [ $count = 0 ]; then
echo "No cpu is managed by cpufreq core, exiting"
exit 2;
ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"
fi
module_governor_test $GOVERNOR_MOD
......@@ -162,7 +159,7 @@ do_test()
;;
*)
echo "Invalid [-f] function type"
ktap_print_msg "Invalid [-f] function type"
helpme
;;
esac
......@@ -186,13 +183,25 @@ dmesg_dumps()
dmesg >> $1.dmesg_full.txt
}
ktap_print_header
# Parse arguments
parse_arguments $@
ktap_set_plan 1
# Make sure all requirements are met
prerequisite
# Run requested functions
clear_dumps $OUTFILE
do_test | tee -a $OUTFILE.txt
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
exit ${PIPESTATUS[0]};
fi
dmesg_dumps $OUTFILE
ktap_test_pass "Completed successfully"
ktap_print_totals
exit "${KSFT_PASS}"
......@@ -24,16 +24,14 @@ test_basic_insmod_rmmod()
# insert module
insmod $1
if [ $? != 0 ]; then
printf "Insmod $1 failed\n"
exit;
ktap_exit_fail_msg "Insmod $1 failed\n"
fi
printf "Removing $1 module\n"
# remove module
rmmod $1
if [ $? != 0 ]; then
printf "rmmod $1 failed\n"
exit;
ktap_exit_fail_msg "rmmod $1 failed\n"
fi
printf "\n"
......
......@@ -37,25 +37,25 @@ int main(void)
ksft_test_result_skip("error: unshare, errno %d\n", errno);
ksft_finished();
}
ksft_exit_fail_msg("error: unshare, errno %d\n", errno);
ksft_exit_fail_perror("error: unshare");
}
if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) == -1)
ksft_exit_fail_msg("error: mount '/', errno %d\n", errno);
ksft_exit_fail_perror("error: mount '/'");
/* Require "exec" filesystem. */
if (mount(NULL, "/tmp", "ramfs", 0, NULL) == -1)
ksft_exit_fail_msg("error: mount ramfs, errno %d\n", errno);
ksft_exit_fail_perror("error: mount ramfs");
#define FILENAME "/tmp/1"
fd = creat(FILENAME, 0700);
if (fd == -1)
ksft_exit_fail_msg("error: creat, errno %d\n", errno);
ksft_exit_fail_perror("error: creat");
#define S "#!" FILENAME "\n"
if (write(fd, S, strlen(S)) != strlen(S))
ksft_exit_fail_msg("error: write, errno %d\n", errno);
ksft_exit_fail_perror("error: write");
close(fd);
......
......@@ -3,6 +3,4 @@
CFLAGS += $(KHDR_INCLUDES) -pthread
TEST_GEN_PROGS := binderfs_test
binderfs_test: binderfs_test.c ../../kselftest.h ../../kselftest_harness.h
include ../../lib.mk
......@@ -3,6 +3,7 @@
#define _GNU_SOURCE
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <sched.h>
#include <fcntl.h>
......
......@@ -255,7 +255,13 @@ prlog() { # messages
[ "$LOG_FILE" ] && printf "$*$newline" | strip_esc >> $LOG_FILE
}
catlog() { #file
cat $1
if [ "${KTAP}" = "1" ]; then
cat $1 | while read line ; do
echo "# $line"
done
else
cat $1
fi
[ "$LOG_FILE" ] && cat $1 | strip_esc >> $LOG_FILE
}
prlog "=== Ftrace unit tests ==="
......
......@@ -5,4 +5,4 @@
#
# Copyright (C) Arm Ltd., 2023
./ftracetest -K
./ftracetest -K -v
......@@ -53,7 +53,7 @@ fi
echo > dynamic_events
if [ "$FIELDS" ] ; then
if [ "$FIELDS" -a "$FPROBES" ] ; then
echo "t:tpevent ${TP2} obj_size=s->object_size" >> dynamic_events
echo "f:fpevent ${TP3}%return path=\$retval->name:string" >> dynamic_events
echo "t:tpevent2 ${TP4} p->se.group_node.next->prev" >> dynamic_events
......
......@@ -11,7 +11,7 @@ echo 1 > events/tests/enable
echo > trace
cat trace > /dev/null
function streq() {
streq() {
test $1 = $2
}
......
......@@ -11,7 +11,7 @@ echo 1 > events/kprobes/enable
echo > trace
cat trace > /dev/null
function streq() {
streq() {
test $1 = $2
}
......
......@@ -198,13 +198,12 @@ int main(int argc, char **argv)
struct msgque_data msgque;
if (getuid() != 0)
return ksft_exit_skip(
"Please run the test as root - Exiting.\n");
ksft_exit_skip("Please run the test as root - Exiting.\n");
msgque.key = ftok(argv[0], 822155650);
if (msgque.key == -1) {
printf("Can't make key: %d\n", -errno);
return ksft_exit_fail();
ksft_exit_fail();
}
msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666);
......@@ -243,13 +242,13 @@ int main(int argc, char **argv)
printf("Failed to test queue: %d\n", err);
goto err_out;
}
return ksft_exit_pass();
ksft_exit_pass();
err_destroy:
if (msgctl(msgque.msq_id, IPC_RMID, NULL)) {
printf("Failed to destroy queue: %d\n", -errno);
return ksft_exit_fail();
ksft_exit_fail();
}
err_out:
return ksft_exit_fail();
ksft_exit_fail();
}
......@@ -16,10 +16,12 @@
* For each test, report any progress, debugging, etc with:
*
* ksft_print_msg(fmt, ...);
* ksft_perror(msg);
*
* and finally report the pass/fail/skip/xfail state of the test with one of:
*
* ksft_test_result(condition, fmt, ...);
* ksft_test_result_report(result, fmt, ...);
* ksft_test_result_pass(fmt, ...);
* ksft_test_result_fail(fmt, ...);
* ksft_test_result_skip(fmt, ...);
......@@ -39,6 +41,7 @@
* the program is aborting before finishing all tests):
*
* ksft_exit_fail_msg(fmt, ...);
* ksft_exit_fail_perror(msg);
*
*/
#ifndef __KSELFTEST_H
......@@ -305,13 +308,34 @@ void ksft_test_result_code(int exit_code, const char *test_name,
printf("\n");
}
static inline __noreturn int ksft_exit_pass(void)
/**
* ksft_test_result() - Report test success based on truth of condition
*
* @condition: if true, report test success, otherwise failure.
*/
#define ksft_test_result_report(result, fmt, ...) do { \
switch (result) { \
case KSFT_PASS: \
ksft_test_result_pass(fmt, ##__VA_ARGS__); \
break; \
case KSFT_FAIL: \
ksft_test_result_fail(fmt, ##__VA_ARGS__); \
break; \
case KSFT_XFAIL: \
ksft_test_result_xfail(fmt, ##__VA_ARGS__); \
break; \
case KSFT_SKIP: \
ksft_test_result_skip(fmt, ##__VA_ARGS__); \
break; \
} } while (0)
static inline __noreturn void ksft_exit_pass(void)
{
ksft_print_cnts();
exit(KSFT_PASS);
}
static inline __noreturn int ksft_exit_fail(void)
static inline __noreturn void ksft_exit_fail(void)
{
ksft_print_cnts();
exit(KSFT_FAIL);
......@@ -338,7 +362,7 @@ static inline __noreturn int ksft_exit_fail(void)
ksft_cnt.ksft_xfail + \
ksft_cnt.ksft_xskip)
static inline __noreturn __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...)
static inline __noreturn __printf(1, 2) void ksft_exit_fail_msg(const char *msg, ...)
{
int saved_errno = errno;
va_list args;
......@@ -353,19 +377,32 @@ static inline __noreturn __printf(1, 2) int ksft_exit_fail_msg(const char *msg,
exit(KSFT_FAIL);
}
static inline __noreturn int ksft_exit_xfail(void)
static inline __noreturn void ksft_exit_fail_perror(const char *msg)
{
#ifndef NOLIBC
ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
#else
/*
* nolibc doesn't provide strerror() and it seems
* inappropriate to add one, just print the errno.
*/
ksft_exit_fail_msg("%s: %d)\n", msg, errno);
#endif
}
static inline __noreturn void ksft_exit_xfail(void)
{
ksft_print_cnts();
exit(KSFT_XFAIL);
}
static inline __noreturn int ksft_exit_xpass(void)
static inline __noreturn void ksft_exit_xpass(void)
{
ksft_print_cnts();
exit(KSFT_XPASS);
}
static inline __noreturn __printf(1, 2) int ksft_exit_skip(const char *msg, ...)
static inline __noreturn __printf(1, 2) void ksft_exit_skip(const char *msg, ...)
{
int saved_errno = errno;
va_list args;
......
......@@ -43,7 +43,7 @@ __ktap_test() {
directive="$3" # optional
local directive_str=
[[ ! -z "$directive" ]] && directive_str="# $directive"
[ ! -z "$directive" ] && directive_str="# $directive"
echo $result $KTAP_TESTNO $description $directive_str
......@@ -99,7 +99,7 @@ ktap_exit_fail_msg() {
ktap_finished() {
ktap_print_totals
if [ $(("$KTAP_CNT_PASS" + "$KTAP_CNT_SKIP")) -eq "$KSFT_NUM_TESTS" ]; then
if [ $((KTAP_CNT_PASS + KTAP_CNT_SKIP)) -eq "$KSFT_NUM_TESTS" ]; then
exit "$KSFT_PASS"
else
exit "$KSFT_FAIL"
......
......@@ -244,6 +244,7 @@ l4_test()
l5_test()
{
tests=$(find $(dirname "$test") -type f -name "*.mk")
[[ -z "${tests// }" ]] && return
test_libs=$(grep "^IOURING_EXTRA_LIBS +\?=" $tests | \
cut -d "=" -f 2)
......
......@@ -51,7 +51,7 @@
#define __KSELFTEST_HARNESS_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
static_assert(0, "kselftest harness requires _GNU_SOURCE to be defined");
#endif
#include <asm/types.h>
#include <ctype.h>
......
......@@ -7,6 +7,8 @@ else ifneq ($(filter -%,$(LLVM)),)
LLVM_SUFFIX := $(LLVM)
endif
CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
......@@ -18,7 +20,13 @@ CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
CLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu
CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
# Default to host architecture if ARCH is not explicitly given.
ifeq ($(ARCH),)
CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple)
else
CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
endif
ifeq ($(CROSS_COMPILE),)
ifeq ($(CLANG_TARGET_FLAGS),)
......@@ -30,7 +38,7 @@ else
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
endif # CROSS_COMPILE
CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as
CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
else
CC := $(CROSS_COMPILE)gcc
endif # LLVM
......@@ -45,7 +53,7 @@ selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
top_srcdir = $(selfdir)/../../..
ifeq ($(KHDR_INCLUDES),)
KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include
KHDR_INCLUDES := -D_GNU_SOURCE -isystem $(top_srcdir)/usr/include
endif
# The following are built by lib.mk common compile rules.
......
......@@ -69,5 +69,5 @@ int main(int argc, char **argv)
/* Multi-threaded */
test_mt_membarrier();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -24,5 +24,5 @@ int main(int argc, char **argv)
test_membarrier_get_registrations(/*cmd=*/0);
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -177,7 +177,7 @@ int main(int argc, char **argv)
ksft_print_header();
if (prereq() || geteuid())
return ksft_exit_skip("Prerequisites unsatisfied\n");
ksft_exit_skip("Prerequisites unsatisfied\n");
ksft_set_plan(1);
......@@ -225,7 +225,7 @@ int main(int argc, char **argv)
}
if (check_compaction(mem_free, hugepage_size) == 0)
return ksft_exit_pass();
ksft_exit_pass();
return ksft_exit_fail();
ksft_exit_fail();
}
......@@ -1779,5 +1779,5 @@ int main(int argc, char **argv)
if (err)
ksft_exit_fail_msg("%d out of %d tests failed\n",
err, ksft_test_num());
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -456,5 +456,5 @@ int main(int argc, char **argv)
if (err)
ksft_exit_fail_msg("%d out of %d tests failed\n",
err, ksft_test_num());
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -228,7 +228,7 @@ int main(int argc, char **argv)
break;
}
ksft_test_result_skip("Please run this test as root\n");
return ksft_exit_pass();
ksft_exit_pass();
}
p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0);
......@@ -267,5 +267,5 @@ int main(int argc, char **argv)
free(tid);
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -646,5 +646,5 @@ int main(int argc, char **argv)
if (err)
ksft_exit_fail_msg("%d out of %d tests failed\n",
err, ksft_test_num());
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -307,5 +307,5 @@ int main(int argc, char **argv)
if (err)
ksft_exit_fail_msg("%d out of %d tests failed\n",
err, ksft_test_num());
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -375,5 +375,5 @@ int main(void)
if (err)
ksft_exit_fail_msg("%d out of %d tests failed\n",
err, ksft_test_num());
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -1484,7 +1484,7 @@ int main(int argc, char *argv[])
ksft_print_header();
if (init_uffd())
return ksft_exit_pass();
ksft_exit_pass();
ksft_set_plan(115);
......@@ -1660,5 +1660,5 @@ int main(int argc, char *argv[])
userfaultfd_tests();
close(pagemap_fd);
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -209,5 +209,5 @@ int main(int argc, char **argv)
close(pagemap_fd);
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -307,5 +307,5 @@ int main(int argc, char **argv)
test_pidfd_fdinfo_nspid();
test_pidfd_dead_fdinfo();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -159,5 +159,7 @@ int main(int argc, char **argv)
if (pidfd >= 0)
close(pidfd);
return !ret ? ksft_exit_pass() : ksft_exit_fail();
if (ret)
ksft_exit_fail();
ksft_exit_pass();
}
......@@ -112,5 +112,5 @@ int main(int argc, char **argv)
}
ksft_test_result_pass("pidfd poll test: pass\n");
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -572,5 +572,5 @@ int main(int argc, char **argv)
test_pidfd_send_signal_exited_fail();
test_pidfd_send_signal_recycled_pid_fail();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -23,7 +23,7 @@ count_tests() {
total_tests=0
for i in $SUPPLIES; do
total_tests=$(("$total_tests" + "$NUM_TESTS"))
total_tests=$((total_tests + NUM_TESTS))
done
echo "$total_tests"
......
......@@ -5,6 +5,8 @@ CFLAGS += $(KHDR_INCLUDES)
TEST_GEN_PROGS := resctrl_tests
LOCAL_HDRS += $(wildcard *.h)
include ../lib.mk
$(OUTPUT)/resctrl_tests: $(wildcard *.[ch])
$(OUTPUT)/resctrl_tests: $(wildcard *.c)
......@@ -128,7 +128,7 @@ static int check_results(struct resctrl_val_param *param, const char *cache_type
return fail;
}
void cat_test_cleanup(void)
static void cat_test_cleanup(void)
{
remove(RESULT_FILE_NAME);
}
......@@ -284,13 +284,10 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param
ret = cat_test(test, uparams, &param, span, start_mask);
if (ret)
goto out;
return ret;
ret = check_results(&param, test->resource,
cache_total_size, full_cache_mask, start_mask);
out:
cat_test_cleanup();
return ret;
}
......@@ -373,6 +370,7 @@ struct resctrl_test l3_cat_test = {
.resource = "L3",
.feature_check = test_resource_feature_check,
.run_test = cat_run_test,
.cleanup = cat_test_cleanup,
};
struct resctrl_test l3_noncont_cat_test = {
......
......@@ -40,11 +40,11 @@ static int show_results_info(unsigned long sum_llc_val, int no_of_bits,
int ret;
avg_llc_val = sum_llc_val / num_of_runs;
avg_diff = (long)abs(cache_span - avg_llc_val);
avg_diff = (long)(cache_span - avg_llc_val);
diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100;
ret = platform && abs((int)diff_percent) > max_diff_percent &&
abs(avg_diff) > max_diff;
labs(avg_diff) > max_diff;
ksft_print_msg("%s Check cache miss rate within %lu%%\n",
ret ? "Fail:" : "Pass:", max_diff_percent);
......@@ -91,7 +91,7 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of
MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, true);
}
void cmt_test_cleanup(void)
static void cmt_test_cleanup(void)
{
remove(RESULT_FILE_NAME);
}
......@@ -161,7 +161,6 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param
ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
out:
cmt_test_cleanup();
free(span_str);
return ret;
......@@ -178,4 +177,5 @@ struct resctrl_test cmt_test = {
.resource = "L3",
.feature_check = cmt_feature_check,
.run_test = cmt_run_test,
.cleanup = cmt_test_cleanup,
};
......@@ -60,8 +60,8 @@ static bool show_mba_info(unsigned long *bw_imc, unsigned long *bw_resc)
/* Memory bandwidth from 100% down to 10% */
for (allocation = 0; allocation < ALLOCATION_MAX / ALLOCATION_STEP;
allocation++) {
unsigned long avg_bw_imc, avg_bw_resc;
unsigned long sum_bw_imc = 0, sum_bw_resc = 0;
long avg_bw_imc, avg_bw_resc;
int avg_diff_per;
float avg_diff;
......@@ -137,7 +137,7 @@ static int check_results(void)
return show_mba_info(bw_imc, bw_resc);
}
void mba_test_cleanup(void)
static void mba_test_cleanup(void)
{
remove(RESULT_FILE_NAME);
}
......@@ -158,13 +158,10 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param
ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
if (ret)
goto out;
return ret;
ret = check_results();
out:
mba_test_cleanup();
return ret;
}
......@@ -180,4 +177,5 @@ struct resctrl_test mba_test = {
.vendor_specific = ARCH_INTEL,
.feature_check = mba_feature_check,
.run_test = mba_run_test,
.cleanup = mba_test_cleanup,
};
......@@ -17,8 +17,8 @@
static int
show_bw_info(unsigned long *bw_imc, unsigned long *bw_resc, size_t span)
{
unsigned long avg_bw_imc = 0, avg_bw_resc = 0;
unsigned long sum_bw_imc = 0, sum_bw_resc = 0;
long avg_bw_imc = 0, avg_bw_resc = 0;
int runs, ret, avg_diff_per;
float avg_diff = 0;
......@@ -105,7 +105,7 @@ static int mbm_setup(const struct resctrl_test *test,
return ret;
}
void mbm_test_cleanup(void)
static void mbm_test_cleanup(void)
{
remove(RESULT_FILE_NAME);
}
......@@ -126,15 +126,12 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param
ret = resctrl_val(test, uparams, uparams->benchmark_cmd, &param);
if (ret)
goto out;
return ret;
ret = check_results(DEFAULT_SPAN);
if (ret && (get_vendor() == ARCH_INTEL))
ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n");
out:
mbm_test_cleanup();
return ret;
}
......@@ -150,4 +147,5 @@ struct resctrl_test mbm_test = {
.vendor_specific = ARCH_INTEL,
.feature_check = mbm_feature_check,
.run_test = mbm_run_test,
.cleanup = mbm_test_cleanup,
};
......@@ -72,6 +72,7 @@ struct user_params {
* @disabled: Test is disabled
* @feature_check: Callback to check required resctrl features
* @run_test: Callback to run the test
* @cleanup: Callback to cleanup after the test
*/
struct resctrl_test {
const char *name;
......@@ -82,6 +83,7 @@ struct resctrl_test {
bool (*feature_check)(const struct resctrl_test *test);
int (*run_test)(const struct resctrl_test *test,
const struct user_params *uparams);
void (*cleanup)(void);
};
/*
......@@ -156,9 +158,6 @@ int resctrl_val(const struct resctrl_test *test,
const struct user_params *uparams,
const char * const *benchmark_cmd,
struct resctrl_val_param *param);
void tests_cleanup(void);
void mbm_test_cleanup(void);
void mba_test_cleanup(void);
unsigned long create_bit_mask(unsigned int start, unsigned int len);
unsigned int count_contiguous_bits(unsigned long val, unsigned int *start);
int get_full_cbm(const char *cache_type, unsigned long *mask);
......@@ -166,11 +165,9 @@ int get_mask_no_shareable(const char *cache_type, unsigned long *mask);
int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size);
int resource_info_unsigned_get(const char *resource, const char *filename, unsigned int *val);
void ctrlc_handler(int signum, siginfo_t *info, void *ptr);
int signal_handler_register(void);
int signal_handler_register(const struct resctrl_test *test);
void signal_handler_unregister(void);
void cat_test_cleanup(void);
unsigned int count_bits(unsigned long n);
void cmt_test_cleanup(void);
void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config);
void perf_event_initialize_read_format(struct perf_event_read *pe_read);
......
......@@ -81,19 +81,11 @@ static void cmd_help(void)
printf("\t-h: help\n");
}
void tests_cleanup(void)
{
mbm_test_cleanup();
mba_test_cleanup();
cmt_test_cleanup();
cat_test_cleanup();
}
static int test_prepare(void)
static int test_prepare(const struct resctrl_test *test)
{
int res;
res = signal_handler_register();
res = signal_handler_register(test);
if (res) {
ksft_print_msg("Failed to register signal handler\n");
return res;
......@@ -108,8 +100,10 @@ static int test_prepare(void)
return 0;
}
static void test_cleanup(void)
static void test_cleanup(const struct resctrl_test *test)
{
if (test->cleanup)
test->cleanup();
umount_resctrlfs();
signal_handler_unregister();
}
......@@ -136,7 +130,7 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p
ksft_print_msg("Starting %s test ...\n", test->name);
if (test_prepare()) {
if (test_prepare(test)) {
ksft_exit_fail_msg("Abnormal failure when preparing for the test\n");
return;
}
......@@ -151,7 +145,7 @@ static void run_single_test(const struct resctrl_test *test, const struct user_p
ksft_test_result(!ret, "%s: test\n", test->name);
cleanup:
test_cleanup();
test_cleanup(test);
}
static void init_user_params(struct user_params *uparams)
......@@ -253,13 +247,13 @@ int main(int argc, char **argv)
* 2. We execute perf commands
*/
if (geteuid() != 0)
return ksft_exit_skip("Not running as root. Skipping...\n");
ksft_exit_skip("Not running as root. Skipping...\n");
if (!check_resctrlfs_support())
return ksft_exit_skip("resctrl FS does not exist. Enable X86_CPU_RESCTRL config option.\n");
ksft_exit_skip("resctrl FS does not exist. Enable X86_CPU_RESCTRL config option.\n");
if (umount_resctrlfs())
return ksft_exit_skip("resctrl FS unmount failed.\n");
ksft_exit_skip("resctrl FS unmount failed.\n");
filter_dmesg();
......
......@@ -62,6 +62,7 @@ struct imc_counter_config {
static char mbm_total_path[1024];
static int imcs;
static struct imc_counter_config imc_counters_config[MAX_IMCS][2];
static const struct resctrl_test *current_test;
void membw_initialize_perf_event_attr(int i, int j)
{
......@@ -472,7 +473,8 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr)
if (bm_pid)
kill(bm_pid, SIGKILL);
umount_resctrlfs();
tests_cleanup();
if (current_test && current_test->cleanup)
current_test->cleanup();
ksft_print_msg("Ending\n\n");
exit(EXIT_SUCCESS);
......@@ -482,13 +484,14 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr)
* Register CTRL-C handler for parent, as it has to kill
* child process before exiting.
*/
int signal_handler_register(void)
int signal_handler_register(const struct resctrl_test *test)
{
struct sigaction sigact = {};
int ret = 0;
bm_pid = 0;
current_test = test;
sigact.sa_sigaction = ctrlc_handler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = SA_SIGINFO;
......@@ -510,6 +513,7 @@ void signal_handler_unregister(void)
{
struct sigaction sigact = {};
current_test = NULL;
sigact.sa_handler = SIG_DFL;
sigemptyset(&sigact.sa_mask);
if (sigaction(SIGINT, &sigact, NULL) ||
......
......@@ -12,7 +12,7 @@ OBJCOPY := $(CROSS_COMPILE)objcopy
endif
INCLUDES := -I$(top_srcdir)/tools/include
HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC
HOST_CFLAGS := -Wall -Werror $(KHDR_INCLUDES) -g $(INCLUDES) -fPIC
HOST_LDFLAGS := -z noexecstack -lcrypto
ENCL_CFLAGS += -Wall -Werror -static-pie -nostdlib -ffreestanding -fPIE \
-fno-stack-protector -mrdrnd $(INCLUDES)
......
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2016-20 Intel Corporation. */
#define _GNU_SOURCE
#include <assert.h>
#include <getopt.h>
#include <stdbool.h>
......
......@@ -109,6 +109,5 @@ int main(void)
ksft_exit_fail_msg("%d out of %d sync tests failed\n",
err, ksft_test_num());
/* need this return to keep gcc happy */
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -205,7 +205,7 @@ int main(int argc, char **argv)
adjtimex(&tx1);
if (err)
return ksft_exit_fail();
ksft_exit_fail();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -173,6 +173,6 @@ int main(void)
timer_delete(tm1);
}
if (final_ret)
return ksft_exit_fail();
return ksft_exit_pass();
ksft_exit_fail();
ksft_exit_pass();
}
......@@ -89,8 +89,8 @@ int main(int argc, char **argv)
if (ret) {
printf("[FAIL]");
return ksft_exit_fail();
ksft_exit_fail();
}
printf("[OK]");
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -257,7 +257,7 @@ int main(int argc, char **argv)
set_frequency(0.0);
if (fails)
return ksft_exit_fail();
ksft_exit_fail();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -268,7 +268,7 @@ int main(int argc, char **argv)
if (ret < 0) {
printf("Error: Problem setting STA_INS/STA_DEL!: %s\n",
time_state_str(ret));
return ksft_exit_fail();
ksft_exit_fail();
}
/* Validate STA_INS was set */
......@@ -277,7 +277,7 @@ int main(int argc, char **argv)
if (tx.status != STA_INS && tx.status != STA_DEL) {
printf("Error: STA_INS/STA_DEL not set!: %s\n",
time_state_str(ret));
return ksft_exit_fail();
ksft_exit_fail();
}
if (tai_time) {
......@@ -295,7 +295,7 @@ int main(int argc, char **argv)
se.sigev_value.sival_int = 0;
if (timer_create(CLOCK_REALTIME, &se, &tm1) == -1) {
printf("Error: timer_create failed\n");
return ksft_exit_fail();
ksft_exit_fail();
}
its1.it_value.tv_sec = next_leap;
its1.it_value.tv_nsec = 0;
......@@ -366,7 +366,7 @@ int main(int argc, char **argv)
if (error_found) {
printf("Errors observed\n");
clear_time_state();
return ksft_exit_fail();
ksft_exit_fail();
}
printf("\n");
if ((iterations != -1) && !(--iterations))
......@@ -374,5 +374,5 @@ int main(int argc, char **argv)
}
clear_time_state();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -87,7 +87,7 @@ int main(void)
tv.tv_usec = 0;
if (settimeofday(&tv, NULL)) {
printf("Error: You're likely not running with proper (ie: root) permissions\n");
return ksft_exit_fail();
ksft_exit_fail();
}
tx.modes = 0;
adjtimex(&tx);
......@@ -104,5 +104,5 @@ int main(void)
fflush(stdout);
}
printf("[OK]\n");
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -107,8 +107,8 @@ int main(int argc, char **argv)
ret = mqueue_lat_test();
if (ret < 0) {
printf("[FAILED]\n");
return ksft_exit_fail();
ksft_exit_fail();
}
printf("[OK]\n");
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -260,16 +260,16 @@ int main(int argc, char **argv)
ksft_print_msg("based timers if other threads run on the CPU...\n");
if (check_itimer(ITIMER_VIRTUAL) < 0)
return ksft_exit_fail();
ksft_exit_fail();
if (check_itimer(ITIMER_PROF) < 0)
return ksft_exit_fail();
ksft_exit_fail();
if (check_itimer(ITIMER_REAL) < 0)
return ksft_exit_fail();
ksft_exit_fail();
if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0)
return ksft_exit_fail();
ksft_exit_fail();
/*
* It's unfortunately hard to reliably test a timer expiration
......@@ -281,10 +281,10 @@ int main(int argc, char **argv)
* find a better solution.
*/
if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0)
return ksft_exit_fail();
ksft_exit_fail();
if (check_timer_distribution() < 0)
return ksft_exit_fail();
ksft_exit_fail();
ksft_finished();
}
......@@ -137,11 +137,11 @@ int main(int argc, char **argv)
if (tx1.offset || tx2.offset ||
tx1.freq != tx2.freq || tx1.tick != tx2.tick) {
printf(" [SKIP]\n");
return ksft_exit_skip("The clock was adjusted externally. Shutdown NTPd or other time sync daemons\n");
ksft_exit_skip("The clock was adjusted externally. Shutdown NTPd or other time sync daemons\n");
}
printf(" [FAILED]\n");
return ksft_exit_fail();
ksft_exit_fail();
}
printf(" [OK]\n");
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -128,6 +128,6 @@ int main(int argc, char *argv[])
/* restore clock */
settime(start);
if (ret)
return ksft_exit_fail();
return ksft_exit_pass();
ksft_exit_fail();
ksft_exit_pass();
}
......@@ -61,9 +61,9 @@ int main(int argc, char **argv)
ret = get_tai();
if (ret != i) {
printf("[FAILED] expected: %i got %i\n", i, ret);
return ksft_exit_fail();
ksft_exit_fail();
}
}
printf("[OK]\n");
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -278,6 +278,6 @@ int main(void)
ret |= do_timer_oneshot(clock_id, 0);
}
if (ret)
return ksft_exit_fail();
return ksft_exit_pass();
ksft_exit_fail();
ksft_exit_pass();
}
......@@ -102,9 +102,9 @@ int main(int argc, char **argv)
printf("[OK]\n");
set_tz(min, dst);
return ksft_exit_pass();
ksft_exit_pass();
err:
set_tz(min, dst);
return ksft_exit_fail();
ksft_exit_fail();
}
......@@ -70,8 +70,8 @@ int main(int argc, char **argv)
if (ret) {
printf("[FAILED]\n");
return ksft_exit_fail();
ksft_exit_fail();
}
printf("[OK]\n");
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -189,5 +189,5 @@ int main(int argc, char **argv)
/* die */
if (ret)
ksft_exit_fail();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -320,10 +320,10 @@ int validate_set_offset(void)
int main(int argc, char **argv)
{
if (validate_freq())
return ksft_exit_fail();
ksft_exit_fail();
if (validate_set_offset())
return ksft_exit_fail();
ksft_exit_fail();
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -47,42 +47,60 @@ int main(int argc, char **argv)
int r;
char tty[PATH_MAX] = {};
struct stat st1, st2;
int result = KSFT_FAIL;
ksft_print_header();
ksft_set_plan(1);
r = readlink("/proc/self/fd/0", tty, PATH_MAX);
if (r < 0)
ksft_exit_fail_msg("readlink on /proc/self/fd/0 failed: %m\n");
if (r < 0) {
ksft_print_msg("readlink on /proc/self/fd/0 failed: %m\n");
goto out;
}
if (!tty_valid(tty)) {
ksft_print_msg("invalid tty path '%s'\n", tty);
result = KSFT_SKIP;
goto out;
if (!tty_valid(tty))
ksft_exit_skip("invalid tty path '%s'\n", tty);
}
r = stat(tty, &st1);
if (r < 0)
ksft_exit_fail_msg("stat failed on tty path '%s': %m\n", tty);
if (r < 0) {
ksft_print_msg("stat failed on tty path '%s': %m\n", tty);
goto out;
}
/* We need to wait at least 8 seconds in order to observe timestamp change */
/* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fbf47635315ab308c9b58a1ea0906e711a9228de */
sleep(10);
r = write_dev_tty();
if (r < 0)
ksft_exit_fail_msg("failed to write to /dev/tty: %s\n",
strerror(-r));
if (r < 0) {
ksft_print_msg("failed to write to /dev/tty: %s\n",
strerror(-r));
goto out;
}
r = stat(tty, &st2);
if (r < 0)
ksft_exit_fail_msg("stat failed on tty path '%s': %m\n", tty);
if (r < 0) {
ksft_print_msg("stat failed on tty path '%s': %m\n", tty);
goto out;
}
/* We wrote to the terminal so timestamps should have been updated */
if (st1.st_atim.tv_sec == st2.st_atim.tv_sec &&
st1.st_mtim.tv_sec == st2.st_mtim.tv_sec) {
ksft_test_result_fail("tty timestamps not updated\n");
ksft_exit_fail();
ksft_print_msg("tty timestamps not updated\n");
goto out;
}
ksft_test_result_pass(
ksft_print_msg(
"timestamps of terminal '%s' updated after write to /dev/tty\n", tty);
return EXIT_SUCCESS;
result = KSFT_PASS;
out:
ksft_test_result_report(result, "tty_tstamp_update\n");
ksft_finished();
}
......@@ -1237,5 +1237,5 @@ int main(int argc, char **argv)
ksft_set_plan(tests_cnt);
return ksft_exit_pass();
ksft_exit_pass();
}
......@@ -19,6 +19,7 @@
#include <sys/auxv.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include "../kselftest.h"
#define PAGE_SIZE 4096
......@@ -29,13 +30,13 @@ static int try_to_remap(void *vdso_addr, unsigned long size)
/* Searching for memory location where to remap */
dest_addr = mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (dest_addr == MAP_FAILED) {
printf("[WARN]\tmmap failed (%d): %m\n", errno);
ksft_print_msg("WARN: mmap failed (%d): %m\n", errno);
return 0;
}
printf("[NOTE]\tMoving vDSO: [%p, %#lx] -> [%p, %#lx]\n",
vdso_addr, (unsigned long)vdso_addr + size,
dest_addr, (unsigned long)dest_addr + size);
ksft_print_msg("Moving vDSO: [%p, %#lx] -> [%p, %#lx]\n",
vdso_addr, (unsigned long)vdso_addr + size,
dest_addr, (unsigned long)dest_addr + size);
fflush(stdout);
new_addr = mremap(vdso_addr, size, size,
......@@ -43,10 +44,10 @@ static int try_to_remap(void *vdso_addr, unsigned long size)
if ((unsigned long)new_addr == (unsigned long)-1) {
munmap(dest_addr, size);
if (errno == EINVAL) {
printf("[NOTE]\tvDSO partial move failed, will try with bigger size\n");
ksft_print_msg("vDSO partial move failed, will try with bigger size\n");
return -1; /* Retry with larger */
}
printf("[FAIL]\tmremap failed (%d): %m\n", errno);
ksft_print_msg("[FAIL]\tmremap failed (%d): %m\n", errno);
return 1;
}
......@@ -58,11 +59,12 @@ int main(int argc, char **argv, char **envp)
{
pid_t child;
ksft_print_header();
ksft_set_plan(1);
child = fork();
if (child == -1) {
printf("[WARN]\tfailed to fork (%d): %m\n", errno);
return 1;
}
if (child == -1)
ksft_exit_fail_msg("failed to fork (%d): %m\n", errno);
if (child == 0) {
unsigned long vdso_size = PAGE_SIZE;
......@@ -70,9 +72,9 @@ int main(int argc, char **argv, char **envp)
int ret = -1;
auxval = getauxval(AT_SYSINFO_EHDR);
printf("\tAT_SYSINFO_EHDR is %#lx\n", auxval);
ksft_print_msg("AT_SYSINFO_EHDR is %#lx\n", auxval);
if (!auxval || auxval == -ENOENT) {
printf("[WARN]\tgetauxval failed\n");
ksft_print_msg("WARN: getauxval failed\n");
return 0;
}
......@@ -92,16 +94,13 @@ int main(int argc, char **argv, char **envp)
int status;
if (waitpid(child, &status, 0) != child ||
!WIFEXITED(status)) {
printf("[FAIL]\tmremap() of the vDSO does not work on this kernel!\n");
return 1;
} else if (WEXITSTATUS(status) != 0) {
printf("[FAIL]\tChild failed with %d\n",
WEXITSTATUS(status));
return 1;
}
printf("[OK]\n");
!WIFEXITED(status))
ksft_test_result_fail("mremap() of the vDSO does not work on this kernel!\n");
else if (WEXITSTATUS(status) != 0)
ksft_test_result_fail("Child failed with %d\n", WEXITSTATUS(status));
else
ksft_test_result_pass("%s\n", __func__);
}
return 0;
ksft_finished();
}
This diff is collapsed.
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