Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull kselftest updates from Shuah Khan:

- kbuild kselftest-merge target fixes

- fixes to several tests

- resctrl test fixes and enhancements

- ksft_perror() helper and reporting improvements

- printf attribute to kselftest prints to improve reporting

- documentation and clang build warning fixes

The bulk of the patches are for resctrl fixes and enhancements.

* tag 'linux_kselftest-next-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (51 commits)
selftests/resctrl: Fix MBM test failure when MBA unavailable
selftests/clone3: Report descriptive test names
selftests:modify the incorrect print format
selftests/efivarfs: create-read: fix a resource leak
selftests/ftrace: Add riscv support for kprobe arg tests
selftests/ftrace: add loongarch support for kprobe args char tests
selftests/amd-pstate: Added option to provide perf binary path
selftests/amd-pstate: Fix broken paths to run workloads in amd-pstate-ut
selftests/resctrl: Move run_benchmark() to a more fitting file
selftests/resctrl: Fix schemata write error check
selftests/resctrl: Reduce failures due to outliers in MBA/MBM tests
selftests/resctrl: Fix feature checks
selftests/resctrl: Refactor feature check to use resource and feature name
selftests/resctrl: Move _GNU_SOURCE define into Makefile
selftests/resctrl: Remove duplicate feature check from CMT test
selftests/resctrl: Extend signal handler coverage to unmount on receiving signal
selftests/resctrl: Fix uninitialized .sa_flags
selftests/resctrl: Cleanup benchmark argument parsing
selftests/resctrl: Remove ben_count variable
selftests/resctrl: Make benchmark command const and build it with pointers
...

+698 -560
+3 -3
Documentation/dev-tools/kselftest.rst
··· 112 112 You can also specify a restricted list of tests to run together with a 113 113 dedicated skiplist:: 114 114 115 - $ make TARGETS="bpf breakpoints size timers" SKIP_TARGETS=bpf kselftest 115 + $ make TARGETS="breakpoints size timers" SKIP_TARGETS=size kselftest 116 116 117 117 See the top-level tools/testing/selftests/Makefile for the list of all 118 118 possible targets. ··· 165 165 The `-c` option can be used to run all the tests from a test collection, or 166 166 the `-t` option for specific single tests. Either can be used multiple times:: 167 167 168 - $ ./run_kselftest.sh -c bpf -c seccomp -t timers:posix_timers -t timer:nanosleep 168 + $ ./run_kselftest.sh -c size -c seccomp -t timers:posix_timers -t timer:nanosleep 169 169 170 170 For other features see the script usage output, seen with the `-h` option. 171 171 ··· 210 210 tests by using variables specified in `Running a subset of selftests`_ 211 211 section:: 212 212 213 - $ make -C tools/testing/selftests gen_tar TARGETS="bpf" FORMAT=.xz 213 + $ make -C tools/testing/selftests gen_tar TARGETS="size" FORMAT=.xz 214 214 215 215 .. _tar's auto-compress: https://www.gnu.org/software/tar/manual/html_node/gzip.html#auto_002dcompress 216 216
+2 -2
Makefile
··· 1367 1367 PHONY += kselftest-merge 1368 1368 kselftest-merge: 1369 1369 $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!)) 1370 - $(Q)find $(srctree)/tools/testing/selftests -name config | \ 1371 - xargs $(srctree)/scripts/kconfig/merge_config.sh -m $(objtree)/.config 1370 + $(Q)find $(srctree)/tools/testing/selftests -name config -o -name config.$(UTS_MACHINE) | \ 1371 + xargs $(srctree)/scripts/kconfig/merge_config.sh -y -m $(objtree)/.config 1372 1372 $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig 1373 1373 1374 1374 # ---------------------------------------------------------------------------
+1 -2
tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py
··· 30 30 import Gnuplot 31 31 from numpy import * 32 32 from decimal import * 33 - sys.path.append('../intel_pstate_tracer') 34 - #import intel_pstate_tracer 33 + sys.path.append(os.path.join(os.path.dirname(__file__), "..", "intel_pstate_tracer")) 35 34 import intel_pstate_tracer as ipt 36 35 37 36 __license__ = "GPL version 2"
+11 -6
tools/testing/selftests/amd-pstate/gitsource.sh
··· 1 - #!/bin/sh 1 + #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 4 # Testing and monitor the cpu desire performance, frequency, load, ··· 66 66 67 67 install_gitsource() 68 68 { 69 - if [ ! -d $git_name ]; then 69 + if [ ! -d $SCRIPTDIR/$git_name ]; then 70 + pushd $(pwd) > /dev/null 2>&1 71 + cd $SCRIPTDIR 70 72 printf "Download gitsource, please wait a moment ...\n\n" 71 73 wget -O $git_tar $gitsource_url > /dev/null 2>&1 72 74 73 75 printf "Tar gitsource ...\n\n" 74 76 tar -xzf $git_tar 77 + popd > /dev/null 2>&1 75 78 fi 76 79 } 77 80 ··· 82 79 run_gitsource() 83 80 { 84 81 echo "Launching amd pstate tracer for $1 #$2 tracer_interval: $TRACER_INTERVAL" 85 - ./amd_pstate_trace.py -n tracer-gitsource-$1-$2 -i $TRACER_INTERVAL > /dev/null 2>&1 & 82 + $TRACER -n tracer-gitsource-$1-$2 -i $TRACER_INTERVAL > /dev/null 2>&1 & 86 83 87 84 printf "Make and test gitsource for $1 #$2 make_cpus: $MAKE_CPUS\n" 88 - cd $git_name 89 - perf stat -a --per-socket -I 1000 -e power/energy-pkg/ /usr/bin/time -o ../$OUTFILE_GIT.time-gitsource-$1-$2.log make test -j$MAKE_CPUS > ../$OUTFILE_GIT-perf-$1-$2.log 2>&1 90 - cd .. 85 + BACKUP_DIR=$(pwd) 86 + pushd $BACKUP_DIR > /dev/null 2>&1 87 + cd $SCRIPTDIR/$git_name 88 + $PERF stat -a --per-socket -I 1000 -e power/energy-pkg/ /usr/bin/time -o $BACKUP_DIR/$OUTFILE_GIT.time-gitsource-$1-$2.log make test -j$MAKE_CPUS > $BACKUP_DIR/$OUTFILE_GIT-perf-$1-$2.log 2>&1 89 + popd > /dev/null 2>&1 91 90 92 91 for job in `jobs -p` 93 92 do
+15 -6
tools/testing/selftests/amd-pstate/run.sh
··· 8 8 FILE_MAIN=DONE 9 9 fi 10 10 11 - source basic.sh 12 - source tbench.sh 13 - source gitsource.sh 11 + SCRIPTDIR=`dirname "$0"` 12 + TRACER=$SCRIPTDIR/../../../power/x86/amd_pstate_tracer/amd_pstate_trace.py 13 + 14 + source $SCRIPTDIR/basic.sh 15 + source $SCRIPTDIR/tbench.sh 16 + source $SCRIPTDIR/gitsource.sh 14 17 15 18 # amd-pstate-ut only run on x86/x86_64 AMD systems. 16 19 ARCH=$(uname -m 2>/dev/null | sed -e 's/i.86/x86/' -e 's/x86_64/x86/') ··· 25 22 OUTFILE_TBENCH="$OUTFILE.tbench" 26 23 OUTFILE_GIT="$OUTFILE.gitsource" 27 24 25 + PERF=/usr/bin/perf 28 26 SYSFS= 29 27 CPUROOT= 30 28 CPUFREQROOT= ··· 155 151 [-p <tbench process number>] 156 152 [-l <loop times for tbench>] 157 153 [-i <amd tracer interval>] 154 + [-b <perf binary>] 158 155 [-m <comparative test: acpi-cpufreq>] 159 156 \n" 160 157 exit 2 ··· 163 158 164 159 parse_arguments() 165 160 { 166 - while getopts ho:c:t:p:l:i:m: arg 161 + while getopts ho:c:t:p:l:i:b:m: arg 167 162 do 168 163 case $arg in 169 164 h) # --help ··· 194 189 TRACER_INTERVAL=$OPTARG 195 190 ;; 196 191 192 + b) # --perf-binary 193 + PERF=`realpath $OPTARG` 194 + ;; 195 + 197 196 m) # --comparative-test 198 197 COMPARATIVE_TEST=$OPTARG 199 198 ;; ··· 211 202 212 203 command_perf() 213 204 { 214 - if ! command -v perf > /dev/null; then 215 - echo $msg please install perf. >&2 205 + if ! $PERF -v; then 206 + echo $msg please install perf or provide perf binary path as argument >&2 216 207 exit $ksft_skip 217 208 fi 218 209 }
+2 -2
tools/testing/selftests/amd-pstate/tbench.sh
··· 64 64 run_tbench() 65 65 { 66 66 echo "Launching amd pstate tracer for $1 #$2 tracer_interval: $TRACER_INTERVAL" 67 - ./amd_pstate_trace.py -n tracer-tbench-$1-$2 -i $TRACER_INTERVAL > /dev/null 2>&1 & 67 + $TRACER -n tracer-tbench-$1-$2 -i $TRACER_INTERVAL > /dev/null 2>&1 & 68 68 69 69 printf "Test tbench for $1 #$2 time_limit: $TIME_LIMIT procs_num: $PROCESS_NUM\n" 70 70 tbench_srv > /dev/null 2>&1 & 71 - perf stat -a --per-socket -I 1000 -e power/energy-pkg/ tbench -t $TIME_LIMIT $PROCESS_NUM > $OUTFILE_TBENCH-perf-$1-$2.log 2>&1 71 + $PERF stat -a --per-socket -I 1000 -e power/energy-pkg/ tbench -t $TIME_LIMIT $PROCESS_NUM > $OUTFILE_TBENCH-perf-$1-$2.log 2>&1 72 72 73 73 pid=`pidof tbench_srv` 74 74 kill $pid
+1 -1
tools/testing/selftests/cachestat/test_cachestat.c
··· 27 27 void print_cachestat(struct cachestat *cs) 28 28 { 29 29 ksft_print_msg( 30 - "Using cachestat: Cached: %lu, Dirty: %lu, Writeback: %lu, Evicted: %lu, Recently Evicted: %lu\n", 30 + "Using cachestat: Cached: %llu, Dirty: %llu, Writeback: %llu, Evicted: %llu, Recently Evicted: %llu\n", 31 31 cs->nr_cache, cs->nr_dirty, cs->nr_writeback, 32 32 cs->nr_evicted, cs->nr_recently_evicted); 33 33 }
+1 -1
tools/testing/selftests/capabilities/Makefile
··· 2 2 TEST_GEN_FILES := validate_cap 3 3 TEST_GEN_PROGS := test_execve 4 4 5 - CFLAGS += -O2 -g -std=gnu99 -Wall 5 + CFLAGS += -O2 -g -std=gnu99 -Wall $(KHDR_INCLUDES) 6 6 LDLIBS += -lcap-ng -lrt -ldl 7 7 8 8 include ../lib.mk
-8
tools/testing/selftests/capabilities/test_execve.c
··· 20 20 21 21 #include "../kselftest.h" 22 22 23 - #ifndef PR_CAP_AMBIENT 24 - #define PR_CAP_AMBIENT 47 25 - # define PR_CAP_AMBIENT_IS_SET 1 26 - # define PR_CAP_AMBIENT_RAISE 2 27 - # define PR_CAP_AMBIENT_LOWER 3 28 - # define PR_CAP_AMBIENT_CLEAR_ALL 4 29 - #endif 30 - 31 23 static int nerrs; 32 24 static pid_t mpid; /* main() pid is used to avoid duplicate test counts */ 33 25
-8
tools/testing/selftests/capabilities/validate_cap.c
··· 9 9 10 10 #include "../kselftest.h" 11 11 12 - #ifndef PR_CAP_AMBIENT 13 - #define PR_CAP_AMBIENT 47 14 - # define PR_CAP_AMBIENT_IS_SET 1 15 - # define PR_CAP_AMBIENT_RAISE 2 16 - # define PR_CAP_AMBIENT_LOWER 3 17 - # define PR_CAP_AMBIENT_CLEAR_ALL 4 18 - #endif 19 - 20 12 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 19) 21 13 # define HAVE_GETAUXVAL 22 14 #endif
+194 -75
tools/testing/selftests/clone3/clone3.c
··· 7 7 #include <inttypes.h> 8 8 #include <linux/types.h> 9 9 #include <linux/sched.h> 10 + #include <stdbool.h> 10 11 #include <stdint.h> 11 12 #include <stdio.h> 12 13 #include <stdlib.h> ··· 104 103 return 0; 105 104 } 106 105 107 - static void test_clone3(uint64_t flags, size_t size, int expected, 108 - enum test_mode test_mode) 106 + static bool test_clone3(uint64_t flags, size_t size, int expected, 107 + enum test_mode test_mode) 109 108 { 110 109 int ret; 111 110 ··· 115 114 ret = call_clone3(flags, size, test_mode); 116 115 ksft_print_msg("[%d] clone3() with flags says: %d expected %d\n", 117 116 getpid(), ret, expected); 118 - if (ret != expected) 119 - ksft_test_result_fail( 117 + if (ret != expected) { 118 + ksft_print_msg( 120 119 "[%d] Result (%d) is different than expected (%d)\n", 121 120 getpid(), ret, expected); 122 - else 123 - ksft_test_result_pass( 124 - "[%d] Result (%d) matches expectation (%d)\n", 125 - getpid(), ret, expected); 121 + return false; 122 + } 123 + 124 + return true; 126 125 } 126 + 127 + typedef bool (*filter_function)(void); 128 + typedef size_t (*size_function)(void); 129 + 130 + static bool not_root(void) 131 + { 132 + if (getuid() != 0) { 133 + ksft_print_msg("Not running as root\n"); 134 + return true; 135 + } 136 + 137 + return false; 138 + } 139 + 140 + static size_t page_size_plus_8(void) 141 + { 142 + return getpagesize() + 8; 143 + } 144 + 145 + struct test { 146 + const char *name; 147 + uint64_t flags; 148 + size_t size; 149 + size_function size_function; 150 + int expected; 151 + enum test_mode test_mode; 152 + filter_function filter; 153 + }; 154 + 155 + static const struct test tests[] = { 156 + { 157 + .name = "simple clone3()", 158 + .flags = 0, 159 + .size = 0, 160 + .expected = 0, 161 + .test_mode = CLONE3_ARGS_NO_TEST, 162 + }, 163 + { 164 + .name = "clone3() in a new PID_NS", 165 + .flags = CLONE_NEWPID, 166 + .size = 0, 167 + .expected = 0, 168 + .test_mode = CLONE3_ARGS_NO_TEST, 169 + .filter = not_root, 170 + }, 171 + { 172 + .name = "CLONE_ARGS_SIZE_VER0", 173 + .flags = 0, 174 + .size = CLONE_ARGS_SIZE_VER0, 175 + .expected = 0, 176 + .test_mode = CLONE3_ARGS_NO_TEST, 177 + }, 178 + { 179 + .name = "CLONE_ARGS_SIZE_VER0 - 8", 180 + .flags = 0, 181 + .size = CLONE_ARGS_SIZE_VER0 - 8, 182 + .expected = -EINVAL, 183 + .test_mode = CLONE3_ARGS_NO_TEST, 184 + }, 185 + { 186 + .name = "sizeof(struct clone_args) + 8", 187 + .flags = 0, 188 + .size = sizeof(struct __clone_args) + 8, 189 + .expected = 0, 190 + .test_mode = CLONE3_ARGS_NO_TEST, 191 + }, 192 + { 193 + .name = "exit_signal with highest 32 bits non-zero", 194 + .flags = 0, 195 + .size = 0, 196 + .expected = -EINVAL, 197 + .test_mode = CLONE3_ARGS_INVAL_EXIT_SIGNAL_BIG, 198 + }, 199 + { 200 + .name = "negative 32-bit exit_signal", 201 + .flags = 0, 202 + .size = 0, 203 + .expected = -EINVAL, 204 + .test_mode = CLONE3_ARGS_INVAL_EXIT_SIGNAL_NEG, 205 + }, 206 + { 207 + .name = "exit_signal not fitting into CSIGNAL mask", 208 + .flags = 0, 209 + .size = 0, 210 + .expected = -EINVAL, 211 + .test_mode = CLONE3_ARGS_INVAL_EXIT_SIGNAL_CSIG, 212 + }, 213 + { 214 + .name = "NSIG < exit_signal < CSIG", 215 + .flags = 0, 216 + .size = 0, 217 + .expected = -EINVAL, 218 + .test_mode = CLONE3_ARGS_INVAL_EXIT_SIGNAL_NSIG, 219 + }, 220 + { 221 + .name = "Arguments sizeof(struct clone_args) + 8", 222 + .flags = 0, 223 + .size = sizeof(struct __clone_args) + 8, 224 + .expected = 0, 225 + .test_mode = CLONE3_ARGS_ALL_0, 226 + }, 227 + { 228 + .name = "Arguments sizeof(struct clone_args) + 16", 229 + .flags = 0, 230 + .size = sizeof(struct __clone_args) + 16, 231 + .expected = -E2BIG, 232 + .test_mode = CLONE3_ARGS_ALL_0, 233 + }, 234 + { 235 + .name = "Arguments sizeof(struct clone_arg) * 2", 236 + .flags = 0, 237 + .size = sizeof(struct __clone_args) + 16, 238 + .expected = -E2BIG, 239 + .test_mode = CLONE3_ARGS_ALL_0, 240 + }, 241 + { 242 + .name = "Arguments > page size", 243 + .flags = 0, 244 + .size_function = page_size_plus_8, 245 + .expected = -E2BIG, 246 + .test_mode = CLONE3_ARGS_NO_TEST, 247 + }, 248 + { 249 + .name = "CLONE_ARGS_SIZE_VER0 in a new PID NS", 250 + .flags = CLONE_NEWPID, 251 + .size = CLONE_ARGS_SIZE_VER0, 252 + .expected = 0, 253 + .test_mode = CLONE3_ARGS_NO_TEST, 254 + .filter = not_root, 255 + }, 256 + { 257 + .name = "CLONE_ARGS_SIZE_VER0 - 8 in a new PID NS", 258 + .flags = CLONE_NEWPID, 259 + .size = CLONE_ARGS_SIZE_VER0 - 8, 260 + .expected = -EINVAL, 261 + .test_mode = CLONE3_ARGS_NO_TEST, 262 + }, 263 + { 264 + .name = "sizeof(struct clone_args) + 8 in a new PID NS", 265 + .flags = CLONE_NEWPID, 266 + .size = sizeof(struct __clone_args) + 8, 267 + .expected = 0, 268 + .test_mode = CLONE3_ARGS_NO_TEST, 269 + .filter = not_root, 270 + }, 271 + { 272 + .name = "Arguments > page size in a new PID NS", 273 + .flags = CLONE_NEWPID, 274 + .size_function = page_size_plus_8, 275 + .expected = -E2BIG, 276 + .test_mode = CLONE3_ARGS_NO_TEST, 277 + }, 278 + { 279 + .name = "New time NS", 280 + .flags = CLONE_NEWTIME, 281 + .size = 0, 282 + .expected = 0, 283 + .test_mode = CLONE3_ARGS_NO_TEST, 284 + }, 285 + { 286 + .name = "exit signal (SIGCHLD) in flags", 287 + .flags = SIGCHLD, 288 + .size = 0, 289 + .expected = -EINVAL, 290 + .test_mode = CLONE3_ARGS_NO_TEST, 291 + }, 292 + }; 127 293 128 294 int main(int argc, char *argv[]) 129 295 { 130 - uid_t uid = getuid(); 296 + size_t size; 297 + int i; 131 298 132 299 ksft_print_header(); 133 - ksft_set_plan(19); 300 + ksft_set_plan(ARRAY_SIZE(tests)); 134 301 test_clone3_supported(); 135 302 136 - /* Just a simple clone3() should return 0.*/ 137 - test_clone3(0, 0, 0, CLONE3_ARGS_NO_TEST); 303 + for (i = 0; i < ARRAY_SIZE(tests); i++) { 304 + if (tests[i].filter && tests[i].filter()) { 305 + ksft_test_result_skip("%s\n", tests[i].name); 306 + continue; 307 + } 138 308 139 - /* Do a clone3() in a new PID NS.*/ 140 - if (uid == 0) 141 - test_clone3(CLONE_NEWPID, 0, 0, CLONE3_ARGS_NO_TEST); 142 - else 143 - ksft_test_result_skip("Skipping clone3() with CLONE_NEWPID\n"); 309 + if (tests[i].size_function) 310 + size = tests[i].size_function(); 311 + else 312 + size = tests[i].size; 144 313 145 - /* Do a clone3() with CLONE_ARGS_SIZE_VER0. */ 146 - test_clone3(0, CLONE_ARGS_SIZE_VER0, 0, CLONE3_ARGS_NO_TEST); 314 + ksft_print_msg("Running test '%s'\n", tests[i].name); 147 315 148 - /* Do a clone3() with CLONE_ARGS_SIZE_VER0 - 8 */ 149 - test_clone3(0, CLONE_ARGS_SIZE_VER0 - 8, -EINVAL, CLONE3_ARGS_NO_TEST); 150 - 151 - /* Do a clone3() with sizeof(struct clone_args) + 8 */ 152 - test_clone3(0, sizeof(struct __clone_args) + 8, 0, CLONE3_ARGS_NO_TEST); 153 - 154 - /* Do a clone3() with exit_signal having highest 32 bits non-zero */ 155 - test_clone3(0, 0, -EINVAL, CLONE3_ARGS_INVAL_EXIT_SIGNAL_BIG); 156 - 157 - /* Do a clone3() with negative 32-bit exit_signal */ 158 - test_clone3(0, 0, -EINVAL, CLONE3_ARGS_INVAL_EXIT_SIGNAL_NEG); 159 - 160 - /* Do a clone3() with exit_signal not fitting into CSIGNAL mask */ 161 - test_clone3(0, 0, -EINVAL, CLONE3_ARGS_INVAL_EXIT_SIGNAL_CSIG); 162 - 163 - /* Do a clone3() with NSIG < exit_signal < CSIG */ 164 - test_clone3(0, 0, -EINVAL, CLONE3_ARGS_INVAL_EXIT_SIGNAL_NSIG); 165 - 166 - test_clone3(0, sizeof(struct __clone_args) + 8, 0, CLONE3_ARGS_ALL_0); 167 - 168 - test_clone3(0, sizeof(struct __clone_args) + 16, -E2BIG, 169 - CLONE3_ARGS_ALL_0); 170 - 171 - test_clone3(0, sizeof(struct __clone_args) * 2, -E2BIG, 172 - CLONE3_ARGS_ALL_0); 173 - 174 - /* Do a clone3() with > page size */ 175 - test_clone3(0, getpagesize() + 8, -E2BIG, CLONE3_ARGS_NO_TEST); 176 - 177 - /* Do a clone3() with CLONE_ARGS_SIZE_VER0 in a new PID NS. */ 178 - if (uid == 0) 179 - test_clone3(CLONE_NEWPID, CLONE_ARGS_SIZE_VER0, 0, 180 - CLONE3_ARGS_NO_TEST); 181 - else 182 - ksft_test_result_skip("Skipping clone3() with CLONE_NEWPID\n"); 183 - 184 - /* Do a clone3() with CLONE_ARGS_SIZE_VER0 - 8 in a new PID NS */ 185 - test_clone3(CLONE_NEWPID, CLONE_ARGS_SIZE_VER0 - 8, -EINVAL, 186 - CLONE3_ARGS_NO_TEST); 187 - 188 - /* Do a clone3() with sizeof(struct clone_args) + 8 in a new PID NS */ 189 - if (uid == 0) 190 - test_clone3(CLONE_NEWPID, sizeof(struct __clone_args) + 8, 0, 191 - CLONE3_ARGS_NO_TEST); 192 - else 193 - ksft_test_result_skip("Skipping clone3() with CLONE_NEWPID\n"); 194 - 195 - /* Do a clone3() with > page size in a new PID NS */ 196 - test_clone3(CLONE_NEWPID, getpagesize() + 8, -E2BIG, 197 - CLONE3_ARGS_NO_TEST); 198 - 199 - /* Do a clone3() in a new time namespace */ 200 - test_clone3(CLONE_NEWTIME, 0, 0, CLONE3_ARGS_NO_TEST); 201 - 202 - /* Do a clone3() with exit signal (SIGCHLD) in flags */ 203 - test_clone3(SIGCHLD, 0, -EINVAL, CLONE3_ARGS_NO_TEST); 316 + ksft_test_result(test_clone3(tests[i].flags, size, 317 + tests[i].expected, 318 + tests[i].test_mode), 319 + "%s\n", tests[i].name); 320 + } 204 321 205 322 ksft_finished(); 206 323 }
-2
tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c
··· 27 27 #include "../kselftest_harness.h" 28 28 #include "clone3_selftests.h" 29 29 30 - #ifndef MAX_PID_NS_LEVEL 31 30 #define MAX_PID_NS_LEVEL 32 32 - #endif 33 31 34 32 static void child_exit(int ret) 35 33 {
-4
tools/testing/selftests/clone3/clone3_clear_sighand.c
··· 16 16 #include "../kselftest.h" 17 17 #include "clone3_selftests.h" 18 18 19 - #ifndef CLONE_CLEAR_SIGHAND 20 - #define CLONE_CLEAR_SIGHAND 0x100000000ULL 21 - #endif 22 - 23 19 static void nop_handler(int signo) 24 20 { 25 21 }
-13
tools/testing/selftests/clone3/clone3_selftests.h
··· 15 15 16 16 #define ptr_to_u64(ptr) ((__u64)((uintptr_t)(ptr))) 17 17 18 - #ifndef CLONE_INTO_CGROUP 19 - #define CLONE_INTO_CGROUP 0x200000000ULL /* Clone into a specific cgroup given the right permissions. */ 20 - #endif 21 - 22 18 #ifndef __NR_clone3 23 19 #define __NR_clone3 -1 24 20 #endif ··· 28 32 __aligned_u64 stack; 29 33 __aligned_u64 stack_size; 30 34 __aligned_u64 tls; 31 - #ifndef CLONE_ARGS_SIZE_VER0 32 - #define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */ 33 - #endif 34 35 __aligned_u64 set_tid; 35 36 __aligned_u64 set_tid_size; 36 - #ifndef CLONE_ARGS_SIZE_VER1 37 - #define CLONE_ARGS_SIZE_VER1 80 /* sizeof second published struct */ 38 - #endif 39 37 __aligned_u64 cgroup; 40 - #ifndef CLONE_ARGS_SIZE_VER2 41 - #define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */ 42 - #endif 43 38 }; 44 39 45 40 static pid_t sys_clone3(struct __clone_args *args, size_t size)
-2
tools/testing/selftests/clone3/clone3_set_tid.c
··· 23 23 #include "../kselftest.h" 24 24 #include "clone3_selftests.h" 25 25 26 - #ifndef MAX_PID_NS_LEVEL 27 26 #define MAX_PID_NS_LEVEL 32 28 - #endif 29 27 30 28 static int pipe_1[2]; 31 29 static int pipe_2[2];
-28
tools/testing/selftests/core/close_range_test.c
··· 16 16 #include "../kselftest_harness.h" 17 17 #include "../clone3/clone3_selftests.h" 18 18 19 - #ifndef __NR_close_range 20 - #if defined __alpha__ 21 - #define __NR_close_range 546 22 - #elif defined _MIPS_SIM 23 - #if _MIPS_SIM == _MIPS_SIM_ABI32 /* o32 */ 24 - #define __NR_close_range (436 + 4000) 25 - #endif 26 - #if _MIPS_SIM == _MIPS_SIM_NABI32 /* n32 */ 27 - #define __NR_close_range (436 + 6000) 28 - #endif 29 - #if _MIPS_SIM == _MIPS_SIM_ABI64 /* n64 */ 30 - #define __NR_close_range (436 + 5000) 31 - #endif 32 - #elif defined __ia64__ 33 - #define __NR_close_range (436 + 1024) 34 - #else 35 - #define __NR_close_range 436 36 - #endif 37 - #endif 38 - 39 - #ifndef CLOSE_RANGE_UNSHARE 40 - #define CLOSE_RANGE_UNSHARE (1U << 1) 41 - #endif 42 - 43 - #ifndef CLOSE_RANGE_CLOEXEC 44 - #define CLOSE_RANGE_CLOEXEC (1U << 2) 45 - #endif 46 - 47 19 static inline int sys_close_range(unsigned int fd, unsigned int max_fd, 48 20 unsigned int flags) 49 21 {
tools/testing/selftests/damon/debugfs_attrs.sh
tools/testing/selftests/damon/debugfs_duplicate_context_creation.sh
tools/testing/selftests/damon/debugfs_empty_targets.sh
tools/testing/selftests/damon/debugfs_huge_count_read_write.sh
tools/testing/selftests/damon/debugfs_rm_non_contexts.sh
tools/testing/selftests/damon/debugfs_schemes.sh
tools/testing/selftests/damon/debugfs_target_ids.sh
tools/testing/selftests/damon/lru_sort.sh
tools/testing/selftests/damon/reclaim.sh
tools/testing/selftests/damon/sysfs.sh
tools/testing/selftests/damon/sysfs_update_removed_scheme_dir.sh
+1
tools/testing/selftests/dmabuf-heaps/.gitignore
··· 1 + dmabuf-heap
+2
tools/testing/selftests/efivarfs/create-read.c
··· 32 32 rc = read(fd, buf, sizeof(buf)); 33 33 if (rc != 0) { 34 34 fprintf(stderr, "Reading a new var should return EOF\n"); 35 + close(fd); 35 36 return EXIT_FAILURE; 36 37 } 37 38 39 + close(fd); 38 40 return EXIT_SUCCESS; 39 41 }
+52 -35
tools/testing/selftests/exec/execveat.c
··· 23 23 24 24 #include "../kselftest.h" 25 25 26 + #define TESTS_EXPECTED 51 27 + #define TEST_NAME_LEN (PATH_MAX * 4) 28 + 26 29 static char longpath[2 * PATH_MAX] = ""; 27 30 static char *envp[] = { "IN_TEST=yes", NULL, NULL }; 28 31 static char *argv[] = { "execveat", "99", NULL }; ··· 46 43 static int _check_execveat_fail(int fd, const char *path, int flags, 47 44 int expected_errno, const char *errno_str) 48 45 { 46 + char test_name[TEST_NAME_LEN]; 49 47 int rc; 50 48 51 49 errno = 0; 52 - printf("Check failure of execveat(%d, '%s', %d) with %s... ", 53 - fd, path?:"(null)", flags, errno_str); 50 + snprintf(test_name, sizeof(test_name), 51 + "Check failure of execveat(%d, '%s', %d) with %s", 52 + fd, path?:"(null)", flags, errno_str); 54 53 rc = execveat_(fd, path, argv, envp, flags); 55 54 56 55 if (rc > 0) { 57 - printf("[FAIL] (unexpected success from execveat(2))\n"); 56 + ksft_print_msg("unexpected success from execveat(2)\n"); 57 + ksft_test_result_fail("%s\n", test_name); 58 58 return 1; 59 59 } 60 60 if (errno != expected_errno) { 61 - printf("[FAIL] (expected errno %d (%s) not %d (%s)\n", 62 - expected_errno, strerror(expected_errno), 63 - errno, strerror(errno)); 61 + ksft_print_msg("expected errno %d (%s) not %d (%s)\n", 62 + expected_errno, strerror(expected_errno), 63 + errno, strerror(errno)); 64 + ksft_test_result_fail("%s\n", test_name); 64 65 return 1; 65 66 } 66 - printf("[OK]\n"); 67 + ksft_test_result_pass("%s\n", test_name); 67 68 return 0; 68 69 } 69 70 70 71 static int check_execveat_invoked_rc(int fd, const char *path, int flags, 71 72 int expected_rc, int expected_rc2) 72 73 { 74 + char test_name[TEST_NAME_LEN]; 73 75 int status; 74 76 int rc; 75 77 pid_t child; 76 78 int pathlen = path ? strlen(path) : 0; 77 79 78 80 if (pathlen > 40) 79 - printf("Check success of execveat(%d, '%.20s...%s', %d)... ", 80 - fd, path, (path + pathlen - 20), flags); 81 + snprintf(test_name, sizeof(test_name), 82 + "Check success of execveat(%d, '%.20s...%s', %d)... ", 83 + fd, path, (path + pathlen - 20), flags); 81 84 else 82 - printf("Check success of execveat(%d, '%s', %d)... ", 83 - fd, path?:"(null)", flags); 85 + snprintf(test_name, sizeof(test_name), 86 + "Check success of execveat(%d, '%s', %d)... ", 87 + fd, path?:"(null)", flags); 88 + 84 89 child = fork(); 85 90 if (child < 0) { 86 - printf("[FAIL] (fork() failed)\n"); 91 + ksft_perror("fork() failed"); 92 + ksft_test_result_fail("%s\n", test_name); 87 93 return 1; 88 94 } 89 95 if (child == 0) { 90 96 /* Child: do execveat(). */ 91 97 rc = execveat_(fd, path, argv, envp, flags); 92 - printf("[FAIL]: execveat() failed, rc=%d errno=%d (%s)\n", 93 - rc, errno, strerror(errno)); 98 + ksft_print_msg("execveat() failed, rc=%d errno=%d (%s)\n", 99 + rc, errno, strerror(errno)); 100 + ksft_test_result_fail("%s\n", test_name); 94 101 exit(1); /* should not reach here */ 95 102 } 96 103 /* Parent: wait for & check child's exit status. */ 97 104 rc = waitpid(child, &status, 0); 98 105 if (rc != child) { 99 - printf("[FAIL] (waitpid(%d,...) returned %d)\n", child, rc); 106 + ksft_print_msg("waitpid(%d,...) returned %d\n", child, rc); 107 + ksft_test_result_fail("%s\n", test_name); 100 108 return 1; 101 109 } 102 110 if (!WIFEXITED(status)) { 103 - printf("[FAIL] (child %d did not exit cleanly, status=%08x)\n", 104 - child, status); 111 + ksft_print_msg("child %d did not exit cleanly, status=%08x\n", 112 + child, status); 113 + ksft_test_result_fail("%s\n", test_name); 105 114 return 1; 106 115 } 107 116 if ((WEXITSTATUS(status) != expected_rc) && 108 117 (WEXITSTATUS(status) != expected_rc2)) { 109 - printf("[FAIL] (child %d exited with %d not %d nor %d)\n", 110 - child, WEXITSTATUS(status), expected_rc, expected_rc2); 118 + ksft_print_msg("child %d exited with %d not %d nor %d\n", 119 + child, WEXITSTATUS(status), expected_rc, 120 + expected_rc2); 121 + ksft_test_result_fail("%s\n", test_name); 111 122 return 1; 112 123 } 113 - printf("[OK]\n"); 124 + ksft_test_result_pass("%s\n", test_name); 114 125 return 0; 115 126 } 116 127 ··· 146 129 { 147 130 int fd = open(filename, flags); 148 131 149 - if (fd < 0) { 150 - printf("Failed to open '%s'; " 132 + if (fd < 0) 133 + ksft_exit_fail_msg("Failed to open '%s'; " 151 134 "check prerequisites are available\n", filename); 152 - exit(1); 153 - } 154 135 return fd; 155 136 } 156 137 ··· 177 162 char *cwd = getcwd(NULL, 0); 178 163 179 164 if (!cwd) { 180 - printf("Failed to getcwd(), errno=%d (%s)\n", 181 - errno, strerror(errno)); 165 + ksft_perror("Failed to getcwd()"); 182 166 return 2; 183 167 } 184 168 strcpy(longpath, cwd); ··· 207 193 */ 208 194 fd = open(longpath, O_RDONLY); 209 195 if (fd > 0) { 210 - printf("Invoke copy of '%s' via filename of length %zu:\n", 211 - src, strlen(longpath)); 196 + ksft_print_msg("Invoke copy of '%s' via filename of length %zu:\n", 197 + src, strlen(longpath)); 212 198 fail += check_execveat(fd, "", AT_EMPTY_PATH); 213 199 } else { 214 - printf("Failed to open length %zu filename, errno=%d (%s)\n", 215 - strlen(longpath), errno, strerror(errno)); 200 + ksft_print_msg("Failed to open length %zu filename, errno=%d (%s)\n", 201 + strlen(longpath), errno, strerror(errno)); 216 202 fail++; 217 203 } 218 204 ··· 419 405 const char *in_test = getenv("IN_TEST"); 420 406 421 407 if (verbose) { 422 - printf(" invoked with:"); 408 + ksft_print_msg("invoked with:\n"); 423 409 for (ii = 0; ii < argc; ii++) 424 - printf(" [%d]='%s'", ii, argv[ii]); 425 - printf("\n"); 410 + ksft_print_msg("\t[%d]='%s\n'", ii, argv[ii]); 426 411 } 427 412 428 413 /* Check expected environment transferred. */ 429 414 if (!in_test || strcmp(in_test, "yes") != 0) { 430 - printf("[FAIL] (no IN_TEST=yes in env)\n"); 415 + ksft_print_msg("no IN_TEST=yes in env\n"); 431 416 return 1; 432 417 } 433 418 434 419 /* Use the final argument as an exit code. */ 435 420 rc = atoi(argv[argc - 1]); 436 - fflush(stdout); 421 + exit(rc); 437 422 } else { 423 + ksft_print_header(); 424 + ksft_set_plan(TESTS_EXPECTED); 438 425 prerequisites(); 439 426 if (verbose) 440 427 envp[1] = "VERBOSE=1"; 441 428 rc = run_tests(); 442 429 if (rc > 0) 443 430 printf("%d tests failed\n", rc); 431 + ksft_finished(); 444 432 } 433 + 445 434 return rc; 446 435 }
-4
tools/testing/selftests/firmware/fw_namespace.c
··· 17 17 #include <sys/wait.h> 18 18 #include <unistd.h> 19 19 20 - #ifndef CLONE_NEWNS 21 - # define CLONE_NEWNS 0x00020000 22 - #endif 23 - 24 20 static char *fw_path = NULL; 25 21 26 22 static void die(char *fmt, ...)
+6
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_char.tc
··· 28 28 mips*) 29 29 ARG1=%r4 30 30 ;; 31 + loongarch*) 32 + ARG1=%r4 33 + ;; 34 + riscv*) 35 + ARG1=%a0 36 + ;; 31 37 *) 32 38 echo "Please implement other architecture here" 33 39 exit_untested
+3
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc
··· 31 31 loongarch*) 32 32 ARG1=%r4 33 33 ;; 34 + riscv*) 35 + ARG1=%a0 36 + ;; 34 37 *) 35 38 echo "Please implement other architecture here" 36 39 exit_untested
+4
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
··· 44 44 GOODREG=%r4 45 45 BADREG=%r12 46 46 ;; 47 + riscv*) 48 + GOODREG=%a0 49 + BADREG=%a8 50 + ;; 47 51 *) 48 52 echo "Please implement other architecture here" 49 53 exit_untested
+31 -15
tools/testing/selftests/kselftest.h
··· 48 48 #include <stdlib.h> 49 49 #include <unistd.h> 50 50 #include <stdarg.h> 51 + #include <string.h> 51 52 #include <stdio.h> 52 53 #endif 53 54 ··· 77 76 #define KSFT_XFAIL 2 78 77 #define KSFT_XPASS 3 79 78 #define KSFT_SKIP 4 79 + 80 + #define __printf(a, b) __attribute__((format(printf, a, b))) 80 81 81 82 /* counters */ 82 83 struct ksft_count { ··· 132 129 static inline void ksft_set_plan(unsigned int plan) 133 130 { 134 131 ksft_plan = plan; 135 - printf("1..%d\n", ksft_plan); 132 + printf("1..%u\n", ksft_plan); 136 133 } 137 134 138 135 static inline void ksft_print_cnts(void) ··· 140 137 if (ksft_plan != ksft_test_num()) 141 138 printf("# Planned tests != run tests (%u != %u)\n", 142 139 ksft_plan, ksft_test_num()); 143 - printf("# Totals: pass:%d fail:%d xfail:%d xpass:%d skip:%d error:%d\n", 140 + printf("# Totals: pass:%u fail:%u xfail:%u xpass:%u skip:%u error:%u\n", 144 141 ksft_cnt.ksft_pass, ksft_cnt.ksft_fail, 145 142 ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass, 146 143 ksft_cnt.ksft_xskip, ksft_cnt.ksft_error); 147 144 } 148 145 149 - static inline void ksft_print_msg(const char *msg, ...) 146 + static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...) 150 147 { 151 148 int saved_errno = errno; 152 149 va_list args; ··· 158 155 va_end(args); 159 156 } 160 157 161 - static inline void ksft_test_result_pass(const char *msg, ...) 158 + static inline void ksft_perror(const char *msg) 159 + { 160 + #ifndef NOLIBC 161 + ksft_print_msg("%s: %s (%d)\n", msg, strerror(errno), errno); 162 + #else 163 + /* 164 + * nolibc doesn't provide strerror() and it seems 165 + * inappropriate to add one, just print the errno. 166 + */ 167 + ksft_print_msg("%s: %d)\n", msg, errno); 168 + #endif 169 + } 170 + 171 + static inline __printf(1, 2) void ksft_test_result_pass(const char *msg, ...) 162 172 { 163 173 int saved_errno = errno; 164 174 va_list args; ··· 179 163 ksft_cnt.ksft_pass++; 180 164 181 165 va_start(args, msg); 182 - printf("ok %d ", ksft_test_num()); 166 + printf("ok %u ", ksft_test_num()); 183 167 errno = saved_errno; 184 168 vprintf(msg, args); 185 169 va_end(args); 186 170 } 187 171 188 - static inline void ksft_test_result_fail(const char *msg, ...) 172 + static inline __printf(1, 2) void ksft_test_result_fail(const char *msg, ...) 189 173 { 190 174 int saved_errno = errno; 191 175 va_list args; ··· 193 177 ksft_cnt.ksft_fail++; 194 178 195 179 va_start(args, msg); 196 - printf("not ok %d ", ksft_test_num()); 180 + printf("not ok %u ", ksft_test_num()); 197 181 errno = saved_errno; 198 182 vprintf(msg, args); 199 183 va_end(args); ··· 211 195 ksft_test_result_fail(fmt, ##__VA_ARGS__);\ 212 196 } while (0) 213 197 214 - static inline void ksft_test_result_xfail(const char *msg, ...) 198 + static inline __printf(1, 2) void ksft_test_result_xfail(const char *msg, ...) 215 199 { 216 200 int saved_errno = errno; 217 201 va_list args; ··· 219 203 ksft_cnt.ksft_xfail++; 220 204 221 205 va_start(args, msg); 222 - printf("ok %d # XFAIL ", ksft_test_num()); 206 + printf("ok %u # XFAIL ", ksft_test_num()); 223 207 errno = saved_errno; 224 208 vprintf(msg, args); 225 209 va_end(args); 226 210 } 227 211 228 - static inline void ksft_test_result_skip(const char *msg, ...) 212 + static inline __printf(1, 2) void ksft_test_result_skip(const char *msg, ...) 229 213 { 230 214 int saved_errno = errno; 231 215 va_list args; ··· 233 217 ksft_cnt.ksft_xskip++; 234 218 235 219 va_start(args, msg); 236 - printf("ok %d # SKIP ", ksft_test_num()); 220 + printf("ok %u # SKIP ", ksft_test_num()); 237 221 errno = saved_errno; 238 222 vprintf(msg, args); 239 223 va_end(args); 240 224 } 241 225 242 226 /* TODO: how does "error" differ from "fail" or "skip"? */ 243 - static inline void ksft_test_result_error(const char *msg, ...) 227 + static inline __printf(1, 2) void ksft_test_result_error(const char *msg, ...) 244 228 { 245 229 int saved_errno = errno; 246 230 va_list args; ··· 248 232 ksft_cnt.ksft_error++; 249 233 250 234 va_start(args, msg); 251 - printf("not ok %d # error ", ksft_test_num()); 235 + printf("not ok %u # error ", ksft_test_num()); 252 236 errno = saved_errno; 253 237 vprintf(msg, args); 254 238 va_end(args); ··· 287 271 ksft_cnt.ksft_xfail + \ 288 272 ksft_cnt.ksft_xskip) 289 273 290 - static inline int ksft_exit_fail_msg(const char *msg, ...) 274 + static inline __printf(1, 2) int ksft_exit_fail_msg(const char *msg, ...) 291 275 { 292 276 int saved_errno = errno; 293 277 va_list args; ··· 314 298 exit(KSFT_XPASS); 315 299 } 316 300 317 - static inline int ksft_exit_skip(const char *msg, ...) 301 + static inline __printf(1, 2) int ksft_exit_skip(const char *msg, ...) 318 302 { 319 303 int saved_errno = errno; 320 304 va_list args;
+4 -4
tools/testing/selftests/kvm/include/test_util.h
··· 33 33 #define pr_info(...) _no_printf(__VA_ARGS__) 34 34 #endif 35 35 36 - void print_skip(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 36 + void __printf(1, 2) print_skip(const char *fmt, ...); 37 37 #define __TEST_REQUIRE(f, fmt, ...) \ 38 38 do { \ 39 39 if (!(f)) \ ··· 46 46 ssize_t test_read(int fd, void *buf, size_t count); 47 47 int test_seq_read(const char *path, char **bufp, size_t *sizep); 48 48 49 - void test_assert(bool exp, const char *exp_str, 50 - const char *file, unsigned int line, const char *fmt, ...) 51 - __attribute__((format(printf, 5, 6))); 49 + void __printf(5, 6) test_assert(bool exp, const char *exp_str, 50 + const char *file, unsigned int line, 51 + const char *fmt, ...); 52 52 53 53 #define TEST_ASSERT(e, fmt, ...) \ 54 54 test_assert((e), #e, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
+1 -1
tools/testing/selftests/mm/mremap_test.c
··· 338 338 char c = (char) rand(); 339 339 340 340 if (((char *) dest_addr)[i] != c) { 341 - ksft_print_msg("Data after remap doesn't match at offset %d\n", 341 + ksft_print_msg("Data after remap doesn't match at offset %llu\n", 342 342 i); 343 343 ksft_print_msg("Expected: %#x\t Got: %#x\n", c & 0xff, 344 344 ((char *) dest_addr)[i] & 0xff);
+1 -1
tools/testing/selftests/mm/pkey-helpers.h
··· 34 34 extern int iteration_nr; 35 35 36 36 #ifdef __GNUC__ 37 - __attribute__((format(printf, 1, 2))) 37 + __printf(1, 2) 38 38 #endif 39 39 static inline void sigsafe_printf(const char *format, ...) 40 40 {
+1 -1
tools/testing/selftests/openat2/openat2_test.c
··· 300 300 301 301 ksft_print_msg("openat2 unexpectedly returned "); 302 302 if (fdpath) 303 - ksft_print_msg("%d['%s'] with %X (!= %X)\n", 303 + ksft_print_msg("%d['%s'] with %X (!= %llX)\n", 304 304 fd, fdpath, fdflags, 305 305 test->how.flags); 306 306 else
+1 -1
tools/testing/selftests/pidfd/pidfd_fdinfo_test.c
··· 62 62 break; 63 63 64 64 case PIDFD_PASS: 65 - ksft_test_result_pass("%s test: Passed\n"); 65 + ksft_test_result_pass("%s test: Passed\n", test_name); 66 66 break; 67 67 68 68 default:
+6 -6
tools/testing/selftests/pidfd/pidfd_test.c
··· 381 381 382 382 static void *test_pidfd_poll_exec_thread(void *priv) 383 383 { 384 - ksft_print_msg("Child Thread: starting. pid %d tid %d ; and sleeping\n", 384 + ksft_print_msg("Child Thread: starting. pid %d tid %ld ; and sleeping\n", 385 385 getpid(), syscall(SYS_gettid)); 386 386 ksft_print_msg("Child Thread: doing exec of sleep\n"); 387 387 388 388 execl("/bin/sleep", "sleep", str(CHILD_THREAD_MIN_WAIT), (char *)NULL); 389 389 390 - ksft_print_msg("Child Thread: DONE. pid %d tid %d\n", 390 + ksft_print_msg("Child Thread: DONE. pid %d tid %ld\n", 391 391 getpid(), syscall(SYS_gettid)); 392 392 return NULL; 393 393 } ··· 427 427 { 428 428 pthread_t t1; 429 429 430 - ksft_print_msg("Child (pidfd): starting. pid %d tid %d\n", getpid(), 430 + ksft_print_msg("Child (pidfd): starting. pid %d tid %ld\n", getpid(), 431 431 syscall(SYS_gettid)); 432 432 pthread_create(&t1, NULL, test_pidfd_poll_exec_thread, NULL); 433 433 /* ··· 480 480 481 481 static void *test_pidfd_poll_leader_exit_thread(void *priv) 482 482 { 483 - ksft_print_msg("Child Thread: starting. pid %d tid %d ; and sleeping\n", 483 + ksft_print_msg("Child Thread: starting. pid %d tid %ld ; and sleeping\n", 484 484 getpid(), syscall(SYS_gettid)); 485 485 sleep(CHILD_THREAD_MIN_WAIT); 486 - ksft_print_msg("Child Thread: DONE. pid %d tid %d\n", getpid(), syscall(SYS_gettid)); 486 + ksft_print_msg("Child Thread: DONE. pid %d tid %ld\n", getpid(), syscall(SYS_gettid)); 487 487 return NULL; 488 488 } 489 489 ··· 492 492 { 493 493 pthread_t t1, t2; 494 494 495 - ksft_print_msg("Child: starting. pid %d tid %d\n", getpid(), syscall(SYS_gettid)); 495 + ksft_print_msg("Child: starting. pid %d tid %ld\n", getpid(), syscall(SYS_gettid)); 496 496 pthread_create(&t1, NULL, test_pidfd_poll_leader_exit_thread, NULL); 497 497 pthread_create(&t2, NULL, test_pidfd_poll_leader_exit_thread, NULL); 498 498
+1 -1
tools/testing/selftests/resctrl/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2 3 + CFLAGS = -g -Wall -O2 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE 4 4 CFLAGS += $(KHDR_INCLUDES) 5 5 6 6 TEST_GEN_PROGS := resctrl_tests
+4 -3
tools/testing/selftests/resctrl/cache.c
··· 205 205 * cache_val: execute benchmark and measure LLC occupancy resctrl 206 206 * and perf cache miss for the benchmark 207 207 * @param: parameters passed to cache_val() 208 + * @span: buffer size for the benchmark 208 209 * 209 210 * Return: 0 on success. non-zero on failure. 210 211 */ 211 - int cat_val(struct resctrl_val_param *param) 212 + int cat_val(struct resctrl_val_param *param, size_t span) 212 213 { 213 214 int memflush = 1, operation = 0, ret = 0; 214 215 char *resctrl_val = param->resctrl_val; ··· 246 245 if (ret) 247 246 break; 248 247 249 - if (run_fill_buf(param->span, memflush, operation, true)) { 248 + if (run_fill_buf(span, memflush, operation, true)) { 250 249 fprintf(stderr, "Error-running fill buffer\n"); 251 250 ret = -1; 252 251 goto pe_close; ··· 295 294 ret = platform && abs((int)diff_percent) > max_diff_percent && 296 295 (cmt ? (abs(avg_diff) > max_diff) : true); 297 296 298 - ksft_print_msg("%s Check cache miss rate within %d%%\n", 297 + ksft_print_msg("%s Check cache miss rate within %lu%%\n", 299 298 ret ? "Fail:" : "Pass:", max_diff_percent); 300 299 301 300 ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent));
+7 -14
tools/testing/selftests/resctrl/cat_test.c
··· 41 41 return ret; 42 42 } 43 43 44 - static int check_results(struct resctrl_val_param *param) 44 + static int check_results(struct resctrl_val_param *param, size_t span) 45 45 { 46 46 char *token_array[8], temp[512]; 47 47 unsigned long sum_llc_perf_miss = 0; ··· 76 76 fclose(fp); 77 77 no_of_bits = count_bits(param->mask); 78 78 79 - return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span / 64, 79 + return show_cache_info(sum_llc_perf_miss, no_of_bits, span / 64, 80 80 MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, 81 81 get_vendor() == ARCH_INTEL, false); 82 82 } ··· 96 96 char cbm_mask[256]; 97 97 int count_of_bits; 98 98 char pipe_message; 99 + size_t span; 99 100 100 101 /* Get default cbm mask for L3/L2 cache */ 101 102 ret = get_cbm_mask(cache_type, cbm_mask); ··· 141 140 /* Set param values for parent thread which will be allocated bitmask 142 141 * with (max_bits - n) bits 143 142 */ 144 - param.span = cache_size * (count_of_bits - n) / count_of_bits; 143 + span = cache_size * (count_of_bits - n) / count_of_bits; 145 144 strcpy(param.ctrlgrp, "c2"); 146 145 strcpy(param.mongrp, "m2"); 147 146 strcpy(param.filename, RESULT_FILE_NAME2); ··· 163 162 param.mask = l_mask_1; 164 163 strcpy(param.ctrlgrp, "c1"); 165 164 strcpy(param.mongrp, "m1"); 166 - param.span = cache_size * n / count_of_bits; 165 + span = cache_size * n / count_of_bits; 167 166 strcpy(param.filename, RESULT_FILE_NAME1); 168 167 param.num_of_runs = 0; 169 168 param.cpu_no = sibling_cpu_no; 170 - } else { 171 - ret = signal_handler_register(); 172 - if (ret) { 173 - kill(bm_pid, SIGKILL); 174 - goto out; 175 - } 176 169 } 177 170 178 171 remove(param.filename); 179 172 180 - ret = cat_val(&param); 173 + ret = cat_val(&param, span); 181 174 if (ret == 0) 182 - ret = check_results(&param); 175 + ret = check_results(&param, span); 183 176 184 177 if (bm_pid == 0) { 185 178 /* Tell parent that child is ready */ ··· 203 208 } 204 209 close(pipefd[0]); 205 210 kill(bm_pid, SIGKILL); 206 - signal_handler_unregister(); 207 211 } 208 212 209 - out: 210 213 cat_test_cleanup(); 211 214 212 215 return ret;
+25 -12
tools/testing/selftests/resctrl/cmt_test.c
··· 27 27 return 0; 28 28 } 29 29 30 - static int check_results(struct resctrl_val_param *param, int no_of_bits) 30 + static int check_results(struct resctrl_val_param *param, size_t span, int no_of_bits) 31 31 { 32 32 char *token_array[8], temp[512]; 33 33 unsigned long sum_llc_occu_resc = 0; ··· 58 58 } 59 59 fclose(fp); 60 60 61 - return show_cache_info(sum_llc_occu_resc, no_of_bits, param->span, 61 + return show_cache_info(sum_llc_occu_resc, no_of_bits, span, 62 62 MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, 63 63 true, true); 64 64 } ··· 68 68 remove(RESULT_FILE_NAME); 69 69 } 70 70 71 - int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd) 71 + int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) 72 72 { 73 + const char * const *cmd = benchmark_cmd; 74 + const char *new_cmd[BENCHMARK_ARGS]; 73 75 unsigned long cache_size = 0; 74 76 unsigned long long_mask; 77 + char *span_str = NULL; 75 78 char cbm_mask[256]; 76 79 int count_of_bits; 77 - int ret; 78 - 79 - if (!validate_resctrl_feature_request(CMT_STR)) 80 - return -1; 80 + size_t span; 81 + int ret, i; 81 82 82 83 ret = get_cbm_mask("L3", cbm_mask); 83 84 if (ret) ··· 106 105 .cpu_no = cpu_no, 107 106 .filename = RESULT_FILE_NAME, 108 107 .mask = ~(long_mask << n) & long_mask, 109 - .span = cache_size * n / count_of_bits, 110 108 .num_of_runs = 0, 111 109 .setup = cmt_setup, 112 110 }; 113 111 114 - if (strcmp(benchmark_cmd[0], "fill_buf") == 0) 115 - sprintf(benchmark_cmd[1], "%zu", param.span); 112 + span = cache_size * n / count_of_bits; 113 + 114 + if (strcmp(cmd[0], "fill_buf") == 0) { 115 + /* Duplicate the command to be able to replace span in it */ 116 + for (i = 0; benchmark_cmd[i]; i++) 117 + new_cmd[i] = benchmark_cmd[i]; 118 + new_cmd[i] = NULL; 119 + 120 + ret = asprintf(&span_str, "%zu", span); 121 + if (ret < 0) 122 + return -1; 123 + new_cmd[1] = span_str; 124 + cmd = new_cmd; 125 + } 116 126 117 127 remove(RESULT_FILE_NAME); 118 128 119 - ret = resctrl_val(benchmark_cmd, &param); 129 + ret = resctrl_val(cmd, &param); 120 130 if (ret) 121 131 goto out; 122 132 123 - ret = check_results(&param, n); 133 + ret = check_results(&param, span, n); 124 134 125 135 out: 126 136 cmt_test_cleanup(); 137 + free(span_str); 127 138 128 139 return ret; 129 140 }
+3 -3
tools/testing/selftests/resctrl/mba_test.c
··· 12 12 13 13 #define RESULT_FILE_NAME "result_mba" 14 14 #define NUM_OF_RUNS 5 15 - #define MAX_DIFF_PERCENT 5 15 + #define MAX_DIFF_PERCENT 8 16 16 #define ALLOCATION_MAX 100 17 17 #define ALLOCATION_MIN 10 18 18 #define ALLOCATION_STEP 10 ··· 141 141 remove(RESULT_FILE_NAME); 142 142 } 143 143 144 - int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd) 144 + int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd) 145 145 { 146 146 struct resctrl_val_param param = { 147 147 .resctrl_val = MBA_STR, ··· 149 149 .mongrp = "m1", 150 150 .cpu_no = cpu_no, 151 151 .filename = RESULT_FILE_NAME, 152 - .bw_report = bw_report, 152 + .bw_report = "reads", 153 153 .setup = mba_setup 154 154 }; 155 155 int ret;
+5 -6
tools/testing/selftests/resctrl/mbm_test.c
··· 11 11 #include "resctrl.h" 12 12 13 13 #define RESULT_FILE_NAME "result_mbm" 14 - #define MAX_DIFF_PERCENT 5 14 + #define MAX_DIFF_PERCENT 8 15 15 #define NUM_OF_RUNS 5 16 16 17 17 static int ··· 95 95 return END_OF_TESTS; 96 96 97 97 /* Set up shemata with 100% allocation on the first run. */ 98 - if (p->num_of_runs == 0) 98 + if (p->num_of_runs == 0 && validate_resctrl_feature_request("MB", NULL)) 99 99 ret = write_schemata(p->ctrlgrp, "100", p->cpu_no, 100 100 p->resctrl_val); 101 101 ··· 109 109 remove(RESULT_FILE_NAME); 110 110 } 111 111 112 - int mbm_bw_change(size_t span, int cpu_no, char *bw_report, char **benchmark_cmd) 112 + int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd) 113 113 { 114 114 struct resctrl_val_param param = { 115 115 .resctrl_val = MBM_STR, 116 116 .ctrlgrp = "c1", 117 117 .mongrp = "m1", 118 - .span = span, 119 118 .cpu_no = cpu_no, 120 119 .filename = RESULT_FILE_NAME, 121 - .bw_report = bw_report, 120 + .bw_report = "reads", 122 121 .setup = mbm_setup 123 122 }; 124 123 int ret; ··· 128 129 if (ret) 129 130 goto out; 130 131 131 - ret = check_results(span); 132 + ret = check_results(DEFAULT_SPAN); 132 133 133 134 out: 134 135 mbm_test_cleanup();
+10 -14
tools/testing/selftests/resctrl/resctrl.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - #define _GNU_SOURCE 3 2 #ifndef RESCTRL_H 4 3 #define RESCTRL_H 5 4 #include <stdio.h> ··· 27 28 #define RESCTRL_PATH "/sys/fs/resctrl" 28 29 #define PHYS_ID_PATH "/sys/devices/system/cpu/cpu" 29 30 #define INFO_PATH "/sys/fs/resctrl/info" 30 - #define L3_PATH "/sys/fs/resctrl/info/L3" 31 - #define MB_PATH "/sys/fs/resctrl/info/MB" 32 - #define L3_MON_PATH "/sys/fs/resctrl/info/L3_MON" 33 - #define L3_MON_FEATURES_PATH "/sys/fs/resctrl/info/L3_MON/mon_features" 34 31 35 32 #define ARCH_INTEL 1 36 33 #define ARCH_AMD 2 37 34 38 35 #define END_OF_TESTS 1 36 + 37 + #define BENCHMARK_ARGS 64 38 + 39 + #define DEFAULT_SPAN (250 * MB) 39 40 40 41 #define PARENT_EXIT(err_msg) \ 41 42 do { \ ··· 51 52 * @ctrlgrp: Name of the control monitor group (con_mon grp) 52 53 * @mongrp: Name of the monitor group (mon grp) 53 54 * @cpu_no: CPU number to which the benchmark would be binded 54 - * @span: Memory bytes accessed in each benchmark iteration 55 55 * @filename: Name of file to which the o/p should be written 56 56 * @bw_report: Bandwidth report type (reads vs writes) 57 57 * @setup: Call back function to setup test environment ··· 60 62 char ctrlgrp[64]; 61 63 char mongrp[64]; 62 64 int cpu_no; 63 - size_t span; 64 65 char filename[64]; 65 66 char *bw_report; 66 67 unsigned long mask; ··· 83 86 int mount_resctrlfs(void); 84 87 int umount_resctrlfs(void); 85 88 int validate_bw_report_request(char *bw_report); 86 - bool validate_resctrl_feature_request(const char *resctrl_val); 89 + bool validate_resctrl_feature_request(const char *resource, const char *feature); 87 90 char *fgrep(FILE *inf, const char *str); 88 91 int taskset_benchmark(pid_t bm_pid, int cpu_no); 89 - void run_benchmark(int signum, siginfo_t *info, void *ucontext); 90 92 int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, 91 93 char *resctrl_val); 92 94 int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, ··· 93 97 int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, 94 98 int group_fd, unsigned long flags); 95 99 int run_fill_buf(size_t span, int memflush, int op, bool once); 96 - int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param); 97 - int mbm_bw_change(size_t span, int cpu_no, char *bw_report, char **benchmark_cmd); 100 + int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *param); 101 + int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd); 98 102 void tests_cleanup(void); 99 103 void mbm_test_cleanup(void); 100 - int mba_schemata_change(int cpu_no, char *bw_report, char **benchmark_cmd); 104 + int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd); 101 105 void mba_test_cleanup(void); 102 106 int get_cbm_mask(char *cache_type, char *cbm_mask); 103 107 int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size); 104 108 void ctrlc_handler(int signum, siginfo_t *info, void *ptr); 105 109 int signal_handler_register(void); 106 110 void signal_handler_unregister(void); 107 - int cat_val(struct resctrl_val_param *param); 111 + int cat_val(struct resctrl_val_param *param, size_t span); 108 112 void cat_test_cleanup(void); 109 113 int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type); 110 - int cmt_resctrl_val(int cpu_no, int n, char **benchmark_cmd); 114 + int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd); 111 115 unsigned int count_bits(unsigned long n); 112 116 void cmt_test_cleanup(void); 113 117 int get_core_sibling(int cpu_no);
+101 -81
tools/testing/selftests/resctrl/resctrl_tests.c
··· 10 10 */ 11 11 #include "resctrl.h" 12 12 13 - #define BENCHMARK_ARGS 64 14 - #define BENCHMARK_ARG_SIZE 64 15 - 16 13 static int detect_vendor(void) 17 14 { 18 15 FILE *inf = fopen("/proc/cpuinfo", "r"); ··· 49 52 50 53 static void cmd_help(void) 51 54 { 52 - printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list] [-n no_of_bits]\n"); 53 - printf("\t-b benchmark_cmd [options]: run specified benchmark for MBM, MBA and CMT\n"); 55 + printf("usage: resctrl_tests [-h] [-t test list] [-n no_of_bits] [-b benchmark_cmd [option]...]\n"); 56 + printf("\t-b benchmark_cmd [option]...: run specified benchmark for MBM, MBA and CMT\n"); 54 57 printf("\t default benchmark is builtin fill_buf\n"); 55 58 printf("\t-t test list: run tests specified in the test list, "); 56 59 printf("e.g. -t mbm,mba,cmt,cat\n"); ··· 67 70 cat_test_cleanup(); 68 71 } 69 72 70 - static void run_mbm_test(char **benchmark_cmd, size_t span, 71 - int cpu_no, char *bw_report) 73 + static int test_prepare(void) 74 + { 75 + int res; 76 + 77 + res = signal_handler_register(); 78 + if (res) { 79 + ksft_print_msg("Failed to register signal handler\n"); 80 + return res; 81 + } 82 + 83 + res = mount_resctrlfs(); 84 + if (res) { 85 + signal_handler_unregister(); 86 + ksft_print_msg("Failed to mount resctrl FS\n"); 87 + return res; 88 + } 89 + return 0; 90 + } 91 + 92 + static void test_cleanup(void) 93 + { 94 + umount_resctrlfs(); 95 + signal_handler_unregister(); 96 + } 97 + 98 + static void run_mbm_test(const char * const *benchmark_cmd, int cpu_no) 72 99 { 73 100 int res; 74 101 75 102 ksft_print_msg("Starting MBM BW change ...\n"); 76 103 77 - res = mount_resctrlfs(); 78 - if (res) { 79 - ksft_exit_fail_msg("Failed to mount resctrl FS\n"); 104 + if (test_prepare()) { 105 + ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); 80 106 return; 81 107 } 82 108 83 - if (!validate_resctrl_feature_request(MBM_STR) || (get_vendor() != ARCH_INTEL)) { 109 + if (!validate_resctrl_feature_request("L3_MON", "mbm_total_bytes") || 110 + !validate_resctrl_feature_request("L3_MON", "mbm_local_bytes") || 111 + (get_vendor() != ARCH_INTEL)) { 84 112 ksft_test_result_skip("Hardware does not support MBM or MBM is disabled\n"); 85 - goto umount; 113 + goto cleanup; 86 114 } 87 115 88 - res = mbm_bw_change(span, cpu_no, bw_report, benchmark_cmd); 116 + res = mbm_bw_change(cpu_no, benchmark_cmd); 89 117 ksft_test_result(!res, "MBM: bw change\n"); 90 118 if ((get_vendor() == ARCH_INTEL) && res) 91 119 ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); 92 120 93 - umount: 94 - umount_resctrlfs(); 121 + cleanup: 122 + test_cleanup(); 95 123 } 96 124 97 - static void run_mba_test(char **benchmark_cmd, int cpu_no, char *bw_report) 125 + static void run_mba_test(const char * const *benchmark_cmd, int cpu_no) 98 126 { 99 127 int res; 100 128 101 129 ksft_print_msg("Starting MBA Schemata change ...\n"); 102 130 103 - res = mount_resctrlfs(); 104 - if (res) { 105 - ksft_exit_fail_msg("Failed to mount resctrl FS\n"); 131 + if (test_prepare()) { 132 + ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); 106 133 return; 107 134 } 108 135 109 - if (!validate_resctrl_feature_request(MBA_STR) || (get_vendor() != ARCH_INTEL)) { 136 + if (!validate_resctrl_feature_request("MB", NULL) || 137 + !validate_resctrl_feature_request("L3_MON", "mbm_local_bytes") || 138 + (get_vendor() != ARCH_INTEL)) { 110 139 ksft_test_result_skip("Hardware does not support MBA or MBA is disabled\n"); 111 - goto umount; 140 + goto cleanup; 112 141 } 113 142 114 - res = mba_schemata_change(cpu_no, bw_report, benchmark_cmd); 143 + res = mba_schemata_change(cpu_no, benchmark_cmd); 115 144 ksft_test_result(!res, "MBA: schemata change\n"); 116 145 117 - umount: 118 - umount_resctrlfs(); 146 + cleanup: 147 + test_cleanup(); 119 148 } 120 149 121 - static void run_cmt_test(char **benchmark_cmd, int cpu_no) 150 + static void run_cmt_test(const char * const *benchmark_cmd, int cpu_no) 122 151 { 123 152 int res; 124 153 125 154 ksft_print_msg("Starting CMT test ...\n"); 126 155 127 - res = mount_resctrlfs(); 128 - if (res) { 129 - ksft_exit_fail_msg("Failed to mount resctrl FS\n"); 156 + if (test_prepare()) { 157 + ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); 130 158 return; 131 159 } 132 160 133 - if (!validate_resctrl_feature_request(CMT_STR)) { 161 + if (!validate_resctrl_feature_request("L3_MON", "llc_occupancy") || 162 + !validate_resctrl_feature_request("L3", NULL)) { 134 163 ksft_test_result_skip("Hardware does not support CMT or CMT is disabled\n"); 135 - goto umount; 164 + goto cleanup; 136 165 } 137 166 138 167 res = cmt_resctrl_val(cpu_no, 5, benchmark_cmd); ··· 166 143 if ((get_vendor() == ARCH_INTEL) && res) 167 144 ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); 168 145 169 - umount: 170 - umount_resctrlfs(); 146 + cleanup: 147 + test_cleanup(); 171 148 } 172 149 173 150 static void run_cat_test(int cpu_no, int no_of_bits) ··· 176 153 177 154 ksft_print_msg("Starting CAT test ...\n"); 178 155 179 - res = mount_resctrlfs(); 180 - if (res) { 181 - ksft_exit_fail_msg("Failed to mount resctrl FS\n"); 156 + if (test_prepare()) { 157 + ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); 182 158 return; 183 159 } 184 160 185 - if (!validate_resctrl_feature_request(CAT_STR)) { 161 + if (!validate_resctrl_feature_request("L3", NULL)) { 186 162 ksft_test_result_skip("Hardware does not support CAT or CAT is disabled\n"); 187 - goto umount; 163 + goto cleanup; 188 164 } 189 165 190 166 res = cat_perf_miss_val(cpu_no, no_of_bits, "L3"); 191 167 ksft_test_result(!res, "CAT: test\n"); 192 168 193 - umount: 194 - umount_resctrlfs(); 169 + cleanup: 170 + test_cleanup(); 195 171 } 196 172 197 173 int main(int argc, char **argv) 198 174 { 199 - bool has_ben = false, mbm_test = true, mba_test = true, cmt_test = true; 200 - char *benchmark_cmd[BENCHMARK_ARGS], bw_report[64], bm_type[64]; 201 - char benchmark_cmd_area[BENCHMARK_ARGS][BENCHMARK_ARG_SIZE]; 202 - int c, cpu_no = 1, argc_new = argc, i, no_of_bits = 0; 203 - int ben_ind, ben_count, tests = 0; 204 - size_t span = 250 * MB; 175 + bool mbm_test = true, mba_test = true, cmt_test = true; 176 + const char *benchmark_cmd[BENCHMARK_ARGS] = {}; 177 + int c, cpu_no = 1, i, no_of_bits = 0; 178 + char *span_str = NULL; 205 179 bool cat_test = true; 180 + int tests = 0; 181 + int ret; 206 182 207 - for (i = 0; i < argc; i++) { 208 - if (strcmp(argv[i], "-b") == 0) { 209 - ben_ind = i + 1; 210 - ben_count = argc - ben_ind; 211 - argc_new = ben_ind - 1; 212 - has_ben = true; 213 - break; 214 - } 215 - } 216 - 217 - while ((c = getopt(argc_new, argv, "ht:b:n:p:")) != -1) { 183 + while ((c = getopt(argc, argv, "ht:b:n:p:")) != -1) { 218 184 char *token; 219 185 220 186 switch (c) { 187 + case 'b': 188 + /* 189 + * First move optind back to the (first) optarg and 190 + * then build the benchmark command using the 191 + * remaining arguments. 192 + */ 193 + optind--; 194 + if (argc - optind >= BENCHMARK_ARGS) 195 + ksft_exit_fail_msg("Too long benchmark command"); 196 + 197 + /* Extract benchmark command from command line. */ 198 + for (i = 0; i < argc - optind; i++) 199 + benchmark_cmd[i] = argv[i + optind]; 200 + benchmark_cmd[i] = NULL; 201 + 202 + goto last_arg; 221 203 case 't': 222 204 token = strtok(optarg, ","); 223 205 ··· 271 243 return -1; 272 244 } 273 245 } 246 + last_arg: 274 247 275 248 ksft_print_header(); 276 249 ··· 283 254 if (geteuid() != 0) 284 255 return ksft_exit_skip("Not running as root. Skipping...\n"); 285 256 286 - if (has_ben) { 287 - /* Extract benchmark command from command line. */ 288 - for (i = ben_ind; i < argc; i++) { 289 - benchmark_cmd[i - ben_ind] = benchmark_cmd_area[i]; 290 - sprintf(benchmark_cmd[i - ben_ind], "%s", argv[i]); 291 - } 292 - benchmark_cmd[ben_count] = NULL; 293 - } else { 294 - /* If no benchmark is given by "-b" argument, use fill_buf. */ 295 - for (i = 0; i < 5; i++) 296 - benchmark_cmd[i] = benchmark_cmd_area[i]; 297 - 298 - strcpy(benchmark_cmd[0], "fill_buf"); 299 - sprintf(benchmark_cmd[1], "%zu", span); 300 - strcpy(benchmark_cmd[2], "1"); 301 - strcpy(benchmark_cmd[3], "0"); 302 - strcpy(benchmark_cmd[4], "false"); 303 - benchmark_cmd[5] = NULL; 304 - } 305 - 306 - sprintf(bw_report, "reads"); 307 - sprintf(bm_type, "fill_buf"); 308 - 309 257 if (!check_resctrlfs_support()) 310 258 return ksft_exit_skip("resctrl FS does not exist. Enable X86_CPU_RESCTRL config option.\n"); 311 259 ··· 291 285 292 286 filter_dmesg(); 293 287 288 + if (!benchmark_cmd[0]) { 289 + /* If no benchmark is given by "-b" argument, use fill_buf. */ 290 + benchmark_cmd[0] = "fill_buf"; 291 + ret = asprintf(&span_str, "%u", DEFAULT_SPAN); 292 + if (ret < 0) 293 + ksft_exit_fail_msg("Out of memory!\n"); 294 + benchmark_cmd[1] = span_str; 295 + benchmark_cmd[2] = "1"; 296 + benchmark_cmd[3] = "0"; 297 + benchmark_cmd[4] = "false"; 298 + benchmark_cmd[5] = NULL; 299 + } 300 + 294 301 ksft_set_plan(tests ? : 4); 295 302 296 303 if (mbm_test) 297 - run_mbm_test(benchmark_cmd, span, cpu_no, bw_report); 304 + run_mbm_test(benchmark_cmd, cpu_no); 298 305 299 306 if (mba_test) 300 - run_mba_test(benchmark_cmd, cpu_no, bw_report); 307 + run_mba_test(benchmark_cmd, cpu_no); 301 308 302 309 if (cmt_test) 303 310 run_cmt_test(benchmark_cmd, cpu_no); ··· 318 299 if (cat_test) 319 300 run_cat_test(cpu_no, no_of_bits); 320 301 302 + free(span_str); 321 303 ksft_finished(); 322 304 }
+70 -16
tools/testing/selftests/resctrl/resctrl_val.c
··· 468 468 469 469 void ctrlc_handler(int signum, siginfo_t *info, void *ptr) 470 470 { 471 - kill(bm_pid, SIGKILL); 471 + /* Only kill child after bm_pid is set after fork() */ 472 + if (bm_pid) 473 + kill(bm_pid, SIGKILL); 472 474 umount_resctrlfs(); 473 475 tests_cleanup(); 474 476 ksft_print_msg("Ending\n\n"); ··· 484 482 */ 485 483 int signal_handler_register(void) 486 484 { 487 - struct sigaction sigact; 485 + struct sigaction sigact = {}; 488 486 int ret = 0; 487 + 488 + bm_pid = 0; 489 489 490 490 sigact.sa_sigaction = ctrlc_handler; 491 491 sigemptyset(&sigact.sa_mask); ··· 508 504 */ 509 505 void signal_handler_unregister(void) 510 506 { 511 - struct sigaction sigact; 507 + struct sigaction sigact = {}; 512 508 513 509 sigact.sa_handler = SIG_DFL; 514 510 sigemptyset(&sigact.sa_mask); ··· 626 622 } 627 623 628 624 /* 625 + * run_benchmark - Run a specified benchmark or fill_buf (default benchmark) 626 + * in specified signal. Direct benchmark stdio to /dev/null. 627 + * @signum: signal number 628 + * @info: signal info 629 + * @ucontext: user context in signal handling 630 + */ 631 + static void run_benchmark(int signum, siginfo_t *info, void *ucontext) 632 + { 633 + int operation, ret, memflush; 634 + char **benchmark_cmd; 635 + size_t span; 636 + bool once; 637 + FILE *fp; 638 + 639 + benchmark_cmd = info->si_ptr; 640 + 641 + /* 642 + * Direct stdio of child to /dev/null, so that only parent writes to 643 + * stdio (console) 644 + */ 645 + fp = freopen("/dev/null", "w", stdout); 646 + if (!fp) 647 + PARENT_EXIT("Unable to direct benchmark status to /dev/null"); 648 + 649 + if (strcmp(benchmark_cmd[0], "fill_buf") == 0) { 650 + /* Execute default fill_buf benchmark */ 651 + span = strtoul(benchmark_cmd[1], NULL, 10); 652 + memflush = atoi(benchmark_cmd[2]); 653 + operation = atoi(benchmark_cmd[3]); 654 + if (!strcmp(benchmark_cmd[4], "true")) 655 + once = true; 656 + else if (!strcmp(benchmark_cmd[4], "false")) 657 + once = false; 658 + else 659 + PARENT_EXIT("Invalid once parameter"); 660 + 661 + if (run_fill_buf(span, memflush, operation, once)) 662 + fprintf(stderr, "Error in running fill buffer\n"); 663 + } else { 664 + /* Execute specified benchmark */ 665 + ret = execvp(benchmark_cmd[0], benchmark_cmd); 666 + if (ret) 667 + perror("wrong\n"); 668 + } 669 + 670 + fclose(stdout); 671 + PARENT_EXIT("Unable to run specified benchmark"); 672 + } 673 + 674 + /* 629 675 * resctrl_val: execute benchmark and measure memory bandwidth on 630 676 * the benchmark 631 677 * @benchmark_cmd: benchmark command and its arguments ··· 683 629 * 684 630 * Return: 0 on success. non-zero on failure. 685 631 */ 686 - int resctrl_val(char **benchmark_cmd, struct resctrl_val_param *param) 632 + int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *param) 687 633 { 688 634 char *resctrl_val = param->resctrl_val; 689 635 unsigned long bw_resc_start = 0; ··· 760 706 761 707 ksft_print_msg("Benchmark PID: %d\n", bm_pid); 762 708 763 - ret = signal_handler_register(); 764 - if (ret) 765 - goto out; 766 - 767 - value.sival_ptr = benchmark_cmd; 709 + /* 710 + * The cast removes constness but nothing mutates benchmark_cmd within 711 + * the context of this process. At the receiving process, it becomes 712 + * argv, which is mutable, on exec() but that's after fork() so it 713 + * doesn't matter for the process running the tests. 714 + */ 715 + value.sival_ptr = (void *)benchmark_cmd; 768 716 769 717 /* Taskset benchmark to specified cpu */ 770 718 ret = taskset_benchmark(bm_pid, param->cpu_no); 771 719 if (ret) 772 - goto unregister; 720 + goto out; 773 721 774 722 /* Write benchmark to specified control&monitoring grp in resctrl FS */ 775 723 ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, 776 724 resctrl_val); 777 725 if (ret) 778 - goto unregister; 726 + goto out; 779 727 780 728 if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || 781 729 !strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { 782 730 ret = initialize_mem_bw_imc(); 783 731 if (ret) 784 - goto unregister; 732 + goto out; 785 733 786 734 initialize_mem_bw_resctrl(param->ctrlgrp, param->mongrp, 787 735 param->cpu_no, resctrl_val); ··· 798 742 sizeof(pipe_message)) { 799 743 perror("# failed reading message from child process"); 800 744 close(pipefd[0]); 801 - goto unregister; 745 + goto out; 802 746 } 803 747 } 804 748 close(pipefd[0]); ··· 807 751 if (sigqueue(bm_pid, SIGUSR1, value) == -1) { 808 752 perror("# sigqueue SIGUSR1 to child"); 809 753 ret = errno; 810 - goto unregister; 754 + goto out; 811 755 } 812 756 813 757 /* Give benchmark enough time to fully run */ ··· 836 780 } 837 781 } 838 782 839 - unregister: 840 - signal_handler_unregister(); 841 783 out: 842 784 kill(bm_pid, SIGKILL); 843 785
+51 -107
tools/testing/selftests/resctrl/resctrlfs.c
··· 8 8 * Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>, 9 9 * Fenghua Yu <fenghua.yu@intel.com> 10 10 */ 11 + #include <fcntl.h> 12 + #include <limits.h> 13 + 11 14 #include "resctrl.h" 12 15 13 16 static int find_resctrl_mount(char *buffer) ··· 295 292 } 296 293 297 294 /* 298 - * run_benchmark - Run a specified benchmark or fill_buf (default benchmark) 299 - * in specified signal. Direct benchmark stdio to /dev/null. 300 - * @signum: signal number 301 - * @info: signal info 302 - * @ucontext: user context in signal handling 303 - * 304 - * Return: void 305 - */ 306 - void run_benchmark(int signum, siginfo_t *info, void *ucontext) 307 - { 308 - int operation, ret, memflush; 309 - char **benchmark_cmd; 310 - size_t span; 311 - bool once; 312 - FILE *fp; 313 - 314 - benchmark_cmd = info->si_ptr; 315 - 316 - /* 317 - * Direct stdio of child to /dev/null, so that only parent writes to 318 - * stdio (console) 319 - */ 320 - fp = freopen("/dev/null", "w", stdout); 321 - if (!fp) 322 - PARENT_EXIT("Unable to direct benchmark status to /dev/null"); 323 - 324 - if (strcmp(benchmark_cmd[0], "fill_buf") == 0) { 325 - /* Execute default fill_buf benchmark */ 326 - span = strtoul(benchmark_cmd[1], NULL, 10); 327 - memflush = atoi(benchmark_cmd[2]); 328 - operation = atoi(benchmark_cmd[3]); 329 - if (!strcmp(benchmark_cmd[4], "true")) 330 - once = true; 331 - else if (!strcmp(benchmark_cmd[4], "false")) 332 - once = false; 333 - else 334 - PARENT_EXIT("Invalid once parameter"); 335 - 336 - if (run_fill_buf(span, memflush, operation, once)) 337 - fprintf(stderr, "Error in running fill buffer\n"); 338 - } else { 339 - /* Execute specified benchmark */ 340 - ret = execvp(benchmark_cmd[0], benchmark_cmd); 341 - if (ret) 342 - perror("wrong\n"); 343 - } 344 - 345 - fclose(stdout); 346 - PARENT_EXIT("Unable to run specified benchmark"); 347 - } 348 - 349 - /* 350 295 * create_grp - Create a group only if one doesn't exist 351 296 * @grp_name: Name of the group 352 297 * @grp: Full path and name of the group ··· 439 488 */ 440 489 int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) 441 490 { 442 - char controlgroup[1024], schema[1024], reason[64]; 443 - int resource_id, ret = 0; 444 - FILE *fp; 491 + char controlgroup[1024], reason[128], schema[1024] = {}; 492 + int resource_id, fd, schema_len = -1, ret = 0; 445 493 446 494 if (strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) && 447 495 strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) && ··· 468 518 469 519 if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) || 470 520 !strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) 471 - sprintf(schema, "%s%d%c%s", "L3:", resource_id, '=', schemata); 521 + schema_len = snprintf(schema, sizeof(schema), "%s%d%c%s\n", 522 + "L3:", resource_id, '=', schemata); 472 523 if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) || 473 524 !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) 474 - sprintf(schema, "%s%d%c%s", "MB:", resource_id, '=', schemata); 475 - 476 - fp = fopen(controlgroup, "w"); 477 - if (!fp) { 478 - sprintf(reason, "Failed to open control group"); 525 + schema_len = snprintf(schema, sizeof(schema), "%s%d%c%s\n", 526 + "MB:", resource_id, '=', schemata); 527 + if (schema_len < 0 || schema_len >= sizeof(schema)) { 528 + snprintf(reason, sizeof(reason), 529 + "snprintf() failed with return value : %d", schema_len); 479 530 ret = -1; 480 - 481 531 goto out; 482 532 } 483 533 484 - if (fprintf(fp, "%s\n", schema) < 0) { 485 - sprintf(reason, "Failed to write schemata in control group"); 486 - fclose(fp); 534 + fd = open(controlgroup, O_WRONLY); 535 + if (fd < 0) { 536 + snprintf(reason, sizeof(reason), 537 + "open() failed : %s", strerror(errno)); 487 538 ret = -1; 488 539 489 - goto out; 540 + goto err_schema_not_empty; 490 541 } 491 - fclose(fp); 542 + if (write(fd, schema, schema_len) < 0) { 543 + snprintf(reason, sizeof(reason), 544 + "write() failed : %s", strerror(errno)); 545 + close(fd); 546 + ret = -1; 492 547 548 + goto err_schema_not_empty; 549 + } 550 + close(fd); 551 + 552 + err_schema_not_empty: 553 + schema[schema_len - 1] = 0; 493 554 out: 494 555 ksft_print_msg("Write schema \"%s\" to resctrl FS%s%s\n", 495 556 schema, ret ? " # " : "", ··· 565 604 566 605 /* 567 606 * validate_resctrl_feature_request - Check if requested feature is valid. 568 - * @resctrl_val: Requested feature 607 + * @resource: Required resource (e.g., MB, L3, L2, L3_MON, etc.) 608 + * @feature: Required monitor feature (in mon_features file). Can only be 609 + * set for L3_MON. Must be NULL for all other resources. 569 610 * 570 - * Return: True if the feature is supported, else false. False is also 571 - * returned if resctrl FS is not mounted. 611 + * Return: True if the resource/feature is supported, else false. False is 612 + * also returned if resctrl FS is not mounted. 572 613 */ 573 - bool validate_resctrl_feature_request(const char *resctrl_val) 614 + bool validate_resctrl_feature_request(const char *resource, const char *feature) 574 615 { 616 + char res_path[PATH_MAX]; 575 617 struct stat statbuf; 576 - bool found = false; 577 618 char *res; 578 619 FILE *inf; 579 620 int ret; 580 621 581 - if (!resctrl_val) 622 + if (!resource) 582 623 return false; 583 624 584 625 ret = find_resctrl_mount(NULL); 585 626 if (ret) 586 627 return false; 587 628 588 - if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) { 589 - if (!stat(L3_PATH, &statbuf)) 590 - return true; 591 - } else if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR))) { 592 - if (!stat(MB_PATH, &statbuf)) 593 - return true; 594 - } else if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) || 595 - !strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { 596 - if (!stat(L3_MON_PATH, &statbuf)) { 597 - inf = fopen(L3_MON_FEATURES_PATH, "r"); 598 - if (!inf) 599 - return false; 629 + snprintf(res_path, sizeof(res_path), "%s/%s", INFO_PATH, resource); 600 630 601 - if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { 602 - res = fgrep(inf, "llc_occupancy"); 603 - if (res) { 604 - found = true; 605 - free(res); 606 - } 607 - } 631 + if (stat(res_path, &statbuf)) 632 + return false; 608 633 609 - if (!strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) { 610 - res = fgrep(inf, "mbm_total_bytes"); 611 - if (res) { 612 - free(res); 613 - res = fgrep(inf, "mbm_local_bytes"); 614 - if (res) { 615 - found = true; 616 - free(res); 617 - } 618 - } 619 - } 620 - fclose(inf); 621 - } 622 - } 634 + if (!feature) 635 + return true; 623 636 624 - return found; 637 + snprintf(res_path, sizeof(res_path), "%s/%s/mon_features", INFO_PATH, resource); 638 + inf = fopen(res_path, "r"); 639 + if (!inf) 640 + return false; 641 + 642 + res = fgrep(inf, feature); 643 + free(res); 644 + fclose(inf); 645 + 646 + return !!res; 625 647 } 626 648 627 649 int filter_dmesg(void)
+10 -10
tools/testing/selftests/rseq/param_test.c
··· 1231 1231 } 1232 1232 1233 1233 /* Wait for initialization. */ 1234 - while (!atomic_load(&args->percpu_list_ptr)) {} 1234 + while (!__atomic_load_n(&args->percpu_list_ptr, __ATOMIC_ACQUIRE)) {} 1235 1235 1236 1236 for (i = 0; i < iters; ++i) { 1237 1237 int ret; ··· 1299 1299 test_membarrier_init_percpu_list(&list_a); 1300 1300 test_membarrier_init_percpu_list(&list_b); 1301 1301 1302 - atomic_store(&args->percpu_list_ptr, (intptr_t)&list_a); 1302 + __atomic_store_n(&args->percpu_list_ptr, (intptr_t)&list_a, __ATOMIC_RELEASE); 1303 1303 1304 - while (!atomic_load(&args->stop)) { 1304 + while (!__atomic_load_n(&args->stop, __ATOMIC_ACQUIRE)) { 1305 1305 /* list_a is "active". */ 1306 1306 cpu_a = rand() % CPU_SETSIZE; 1307 1307 /* 1308 1308 * As list_b is "inactive", we should never see changes 1309 1309 * to list_b. 1310 1310 */ 1311 - if (expect_b != atomic_load(&list_b.c[cpu_b].head->data)) { 1311 + if (expect_b != __atomic_load_n(&list_b.c[cpu_b].head->data, __ATOMIC_ACQUIRE)) { 1312 1312 fprintf(stderr, "Membarrier test failed\n"); 1313 1313 abort(); 1314 1314 } 1315 1315 1316 1316 /* Make list_b "active". */ 1317 - atomic_store(&args->percpu_list_ptr, (intptr_t)&list_b); 1317 + __atomic_store_n(&args->percpu_list_ptr, (intptr_t)&list_b, __ATOMIC_RELEASE); 1318 1318 if (rseq_membarrier_expedited(cpu_a) && 1319 1319 errno != ENXIO /* missing CPU */) { 1320 1320 perror("sys_membarrier"); ··· 1324 1324 * Cpu A should now only modify list_b, so the values 1325 1325 * in list_a should be stable. 1326 1326 */ 1327 - expect_a = atomic_load(&list_a.c[cpu_a].head->data); 1327 + expect_a = __atomic_load_n(&list_a.c[cpu_a].head->data, __ATOMIC_ACQUIRE); 1328 1328 1329 1329 cpu_b = rand() % CPU_SETSIZE; 1330 1330 /* 1331 1331 * As list_a is "inactive", we should never see changes 1332 1332 * to list_a. 1333 1333 */ 1334 - if (expect_a != atomic_load(&list_a.c[cpu_a].head->data)) { 1334 + if (expect_a != __atomic_load_n(&list_a.c[cpu_a].head->data, __ATOMIC_ACQUIRE)) { 1335 1335 fprintf(stderr, "Membarrier test failed\n"); 1336 1336 abort(); 1337 1337 } 1338 1338 1339 1339 /* Make list_a "active". */ 1340 - atomic_store(&args->percpu_list_ptr, (intptr_t)&list_a); 1340 + __atomic_store_n(&args->percpu_list_ptr, (intptr_t)&list_a, __ATOMIC_RELEASE); 1341 1341 if (rseq_membarrier_expedited(cpu_b) && 1342 1342 errno != ENXIO /* missing CPU*/) { 1343 1343 perror("sys_membarrier"); 1344 1344 abort(); 1345 1345 } 1346 1346 /* Remember a value from list_b. */ 1347 - expect_b = atomic_load(&list_b.c[cpu_b].head->data); 1347 + expect_b = __atomic_load_n(&list_b.c[cpu_b].head->data, __ATOMIC_ACQUIRE); 1348 1348 } 1349 1349 1350 1350 test_membarrier_free_percpu_list(&list_a); ··· 1401 1401 } 1402 1402 } 1403 1403 1404 - atomic_store(&thread_args.stop, 1); 1404 + __atomic_store_n(&thread_args.stop, 1, __ATOMIC_RELEASE); 1405 1405 ret = pthread_join(manager_thread, NULL); 1406 1406 if (ret) { 1407 1407 errno = ret;
+1 -1
tools/testing/selftests/sigaltstack/sas.c
··· 111 111 112 112 /* Make sure more than the required minimum. */ 113 113 stack_size = getauxval(AT_MINSIGSTKSZ) + SIGSTKSZ; 114 - ksft_print_msg("[NOTE]\tthe stack size is %lu\n", stack_size); 114 + ksft_print_msg("[NOTE]\tthe stack size is %u\n", stack_size); 115 115 116 116 ksft_print_header(); 117 117 ksft_set_plan(3);
+4 -4
tools/testing/selftests/static_keys/test_static_keys.sh
··· 6 6 ksft_skip=4 7 7 8 8 if ! /sbin/modprobe -q -n test_static_key_base; then 9 - echo "static_key: module test_static_key_base is not found [SKIP]" 9 + echo "static_keys: module test_static_key_base is not found [SKIP]" 10 10 exit $ksft_skip 11 11 fi 12 12 13 13 if ! /sbin/modprobe -q -n test_static_keys; then 14 - echo "static_key: module test_static_keys is not found [SKIP]" 14 + echo "static_keys: module test_static_keys is not found [SKIP]" 15 15 exit $ksft_skip 16 16 fi 17 17 18 18 if /sbin/modprobe -q test_static_key_base; then 19 19 if /sbin/modprobe -q test_static_keys; then 20 - echo "static_key: ok" 20 + echo "static_keys: ok" 21 21 /sbin/modprobe -q -r test_static_keys 22 22 /sbin/modprobe -q -r test_static_key_base 23 23 else ··· 25 25 /sbin/modprobe -q -r test_static_key_base 26 26 fi 27 27 else 28 - echo "static_key: [FAIL]" 28 + echo "static_keys: [FAIL]" 29 29 exit 1 30 30 fi
+1
tools/testing/selftests/tdx/.gitignore
··· 1 + tdx_guest_test
+12 -14
tools/testing/selftests/timers/nsleep-lat.c
··· 118 118 clock_gettime(clockid, &end); 119 119 120 120 if (((timespec_sub(start, end)/count)-ns) > UNRESONABLE_LATENCY) { 121 - printf("Large rel latency: %lld ns :", (timespec_sub(start, end)/count)-ns); 121 + ksft_print_msg("Large rel latency: %lld ns :", (timespec_sub(start, end)/count)-ns); 122 122 return -1; 123 123 } 124 124 ··· 132 132 } 133 133 134 134 if (latency/count > UNRESONABLE_LATENCY) { 135 - printf("Large abs latency: %lld ns :", latency/count); 135 + ksft_print_msg("Large abs latency: %lld ns :", latency/count); 136 136 return -1; 137 137 } 138 138 139 139 return 0; 140 140 } 141 141 142 - 142 + #define SKIPPED_CLOCK_COUNT 3 143 143 144 144 int main(int argc, char **argv) 145 145 { 146 146 long long length; 147 147 int clockid, ret; 148 + 149 + ksft_print_header(); 150 + ksft_set_plan(NR_CLOCKIDS - CLOCK_REALTIME - SKIPPED_CLOCK_COUNT); 148 151 149 152 for (clockid = CLOCK_REALTIME; clockid < NR_CLOCKIDS; clockid++) { 150 153 ··· 156 153 clockid == CLOCK_THREAD_CPUTIME_ID || 157 154 clockid == CLOCK_HWSPECIFIC) 158 155 continue; 159 - 160 - printf("nsleep latency %-26s ", clockstring(clockid)); 161 - fflush(stdout); 162 156 163 157 length = 10; 164 158 while (length <= (NSEC_PER_SEC * 10)) { ··· 167 167 } 168 168 169 169 if (ret == UNSUPPORTED) { 170 - printf("[UNSUPPORTED]\n"); 171 - continue; 170 + ksft_test_result_skip("%s\n", clockstring(clockid)); 171 + } else { 172 + ksft_test_result(ret >= 0, "%s\n", 173 + clockstring(clockid)); 172 174 } 173 - if (ret < 0) { 174 - printf("[FAILED]\n"); 175 - return ksft_exit_fail(); 176 - } 177 - printf("[OK]\n"); 178 175 } 179 - return ksft_exit_pass(); 176 + 177 + ksft_finished(); 180 178 }
+41 -40
tools/testing/selftests/timers/posix_timers.c
··· 76 76 77 77 static int check_itimer(int which) 78 78 { 79 + const char *name; 79 80 int err; 80 81 struct timeval start, end; 81 82 struct itimerval val = { 82 83 .it_value.tv_sec = DELAY, 83 84 }; 84 85 85 - printf("Check itimer "); 86 - 87 86 if (which == ITIMER_VIRTUAL) 88 - printf("virtual... "); 87 + name = "ITIMER_VIRTUAL"; 89 88 else if (which == ITIMER_PROF) 90 - printf("prof... "); 89 + name = "ITIMER_PROF"; 91 90 else if (which == ITIMER_REAL) 92 - printf("real... "); 93 - 94 - fflush(stdout); 91 + name = "ITIMER_REAL"; 92 + else 93 + return -1; 95 94 96 95 done = 0; 97 96 ··· 103 104 104 105 err = gettimeofday(&start, NULL); 105 106 if (err < 0) { 106 - perror("Can't call gettimeofday()\n"); 107 + ksft_perror("Can't call gettimeofday()"); 107 108 return -1; 108 109 } 109 110 110 111 err = setitimer(which, &val, NULL); 111 112 if (err < 0) { 112 - perror("Can't set timer\n"); 113 + ksft_perror("Can't set timer"); 113 114 return -1; 114 115 } 115 116 ··· 122 123 123 124 err = gettimeofday(&end, NULL); 124 125 if (err < 0) { 125 - perror("Can't call gettimeofday()\n"); 126 + ksft_perror("Can't call gettimeofday()"); 126 127 return -1; 127 128 } 128 129 129 - if (!check_diff(start, end)) 130 - printf("[OK]\n"); 131 - else 132 - printf("[FAIL]\n"); 130 + ksft_test_result(check_diff(start, end) == 0, "%s\n", name); 133 131 134 132 return 0; 135 133 } 136 134 137 135 static int check_timer_create(int which) 138 136 { 137 + const char *type; 139 138 int err; 140 139 timer_t id; 141 140 struct timeval start, end; ··· 141 144 .it_value.tv_sec = DELAY, 142 145 }; 143 146 144 - printf("Check timer_create() "); 145 147 if (which == CLOCK_THREAD_CPUTIME_ID) { 146 - printf("per thread... "); 148 + type = "thread"; 147 149 } else if (which == CLOCK_PROCESS_CPUTIME_ID) { 148 - printf("per process... "); 150 + type = "process"; 151 + } else { 152 + ksft_print_msg("Unknown timer_create() type %d\n", which); 153 + return -1; 149 154 } 150 - fflush(stdout); 151 155 152 156 done = 0; 153 157 err = timer_create(which, NULL, &id); 154 158 if (err < 0) { 155 - perror("Can't create timer\n"); 159 + ksft_perror("Can't create timer"); 156 160 return -1; 157 161 } 158 162 signal(SIGALRM, sig_handler); 159 163 160 164 err = gettimeofday(&start, NULL); 161 165 if (err < 0) { 162 - perror("Can't call gettimeofday()\n"); 166 + ksft_perror("Can't call gettimeofday()"); 163 167 return -1; 164 168 } 165 169 166 170 err = timer_settime(id, 0, &val, NULL); 167 171 if (err < 0) { 168 - perror("Can't set timer\n"); 172 + ksft_perror("Can't set timer"); 169 173 return -1; 170 174 } 171 175 ··· 174 176 175 177 err = gettimeofday(&end, NULL); 176 178 if (err < 0) { 177 - perror("Can't call gettimeofday()\n"); 179 + ksft_perror("Can't call gettimeofday()"); 178 180 return -1; 179 181 } 180 182 181 - if (!check_diff(start, end)) 182 - printf("[OK]\n"); 183 - else 184 - printf("[FAIL]\n"); 183 + ksft_test_result(check_diff(start, end) == 0, 184 + "timer_create() per %s\n", type); 185 185 186 186 return 0; 187 187 } ··· 216 220 .it_interval.tv_nsec = 1000 * 1000, 217 221 }; 218 222 219 - printf("Check timer_create() per process signal distribution... "); 220 - fflush(stdout); 221 - 222 223 remain = nthreads + 1; /* worker threads + this thread */ 223 224 signal(SIGALRM, distribution_handler); 224 225 err = timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); 225 226 if (err < 0) { 226 - perror("Can't create timer\n"); 227 + ksft_perror("Can't create timer"); 227 228 return -1; 228 229 } 229 230 err = timer_settime(id, 0, &val, NULL); 230 231 if (err < 0) { 231 - perror("Can't set timer\n"); 232 + ksft_perror("Can't set timer"); 232 233 return -1; 233 234 } 234 235 235 236 for (i = 0; i < nthreads; i++) { 236 - if (pthread_create(&threads[i], NULL, distribution_thread, NULL)) { 237 - perror("Can't create thread\n"); 237 + err = pthread_create(&threads[i], NULL, distribution_thread, 238 + NULL); 239 + if (err) { 240 + ksft_print_msg("Can't create thread: %s (%d)\n", 241 + strerror(errno), errno); 238 242 return -1; 239 243 } 240 244 } ··· 243 247 while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); 244 248 245 249 for (i = 0; i < nthreads; i++) { 246 - if (pthread_join(threads[i], NULL)) { 247 - perror("Can't join thread\n"); 250 + err = pthread_join(threads[i], NULL); 251 + if (err) { 252 + ksft_print_msg("Can't join thread: %s (%d)\n", 253 + strerror(errno), errno); 248 254 return -1; 249 255 } 250 256 } 251 257 252 258 if (timer_delete(id)) { 253 - perror("Can't delete timer\n"); 259 + ksft_perror("Can't delete timer"); 254 260 return -1; 255 261 } 256 262 257 - printf("[OK]\n"); 263 + ksft_test_result_pass("check_timer_distribution\n"); 258 264 return 0; 259 265 } 260 266 261 267 int main(int argc, char **argv) 262 268 { 263 - printf("Testing posix timers. False negative may happen on CPU execution \n"); 264 - printf("based timers if other threads run on the CPU...\n"); 269 + ksft_print_header(); 270 + ksft_set_plan(6); 271 + 272 + ksft_print_msg("Testing posix timers. False negative may happen on CPU execution \n"); 273 + ksft_print_msg("based timers if other threads run on the CPU...\n"); 265 274 266 275 if (check_itimer(ITIMER_VIRTUAL) < 0) 267 276 return ksft_exit_fail(); ··· 295 294 if (check_timer_distribution() < 0) 296 295 return ksft_exit_fail(); 297 296 298 - return ksft_exit_pass(); 297 + ksft_finished(); 299 298 }
+5 -3
tools/testing/selftests/uevent/uevent_filtering.c
··· 78 78 { 79 79 int sk_fd, ret; 80 80 socklen_t sk_addr_len; 81 - int fret = -1, rcv_buf_sz = __UEVENT_BUFFER_SIZE; 81 + int rcv_buf_sz = __UEVENT_BUFFER_SIZE; 82 82 uint64_t sync_add = 1; 83 83 struct sockaddr_nl sk_addr = { 0 }, rcv_addr = { 0 }; 84 84 char buf[__UEVENT_BUFFER_SIZE] = { 0 }; ··· 121 121 122 122 if ((size_t)sk_addr_len != sizeof(sk_addr)) { 123 123 fprintf(stderr, "Invalid socket address size\n"); 124 + ret = -1; 124 125 goto on_error; 125 126 } 126 127 ··· 148 147 ret = write_nointr(sync_fd, &sync_add, sizeof(sync_add)); 149 148 close(sync_fd); 150 149 if (ret != sizeof(sync_add)) { 150 + ret = -1; 151 151 fprintf(stderr, "Failed to synchronize with parent process\n"); 152 152 goto on_error; 153 153 } 154 154 155 - fret = 0; 155 + ret = 0; 156 156 for (;;) { 157 157 ssize_t r; 158 158 ··· 189 187 on_error: 190 188 close(sk_fd); 191 189 192 - return fret; 190 + return ret; 193 191 } 194 192 195 193 int trigger_uevent(unsigned int times)
+4
tools/testing/selftests/user_events/.gitignore
··· 1 + abi_test 2 + dyn_test 3 + ftrace_test 4 + perf_test