]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge tag 'linux-kselftest-4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Feb 2017 23:32:53 +0000 (15:32 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Feb 2017 23:32:53 +0000 (15:32 -0800)
Pull Kselftest update from Shuah Khan:
 "This update consists of:

   - fixes to several existing tests from Stafford Horne

   - cpufreq tests from Viresh Kumar

   - Selftest build and install fixes from Bamvor Jian Zhang and Michael
     Ellerman

   - Fixes to protection-keys tests from Dave Hansen

   - Warning fixes from Shuah Khan"

* tag 'linux-kselftest-4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: (28 commits)
  selftests/powerpc: Fix remaining fallout from recent changes
  selftests/powerpc: Fix the clean rule since recent changes
  selftests: Fix the .S and .S -> .o rules
  selftests: Fix the .c linking rule
  selftests: Fix selftests build to just build, not run tests
  selftests, x86, protection_keys: fix wrong offset in siginfo
  selftests, x86, protection_keys: fix uninitialized variable warning
  selftest: cpufreq: Update MAINTAINERS file
  selftest: cpufreq: Add special tests
  selftest: cpufreq: Add support to test cpufreq modules
  selftest: cpufreq: Add suspend/resume/hibernate support
  selftest: cpufreq: Add support for cpufreq tests
  selftests: Add intel_pstate to TARGETS
  selftests/intel_pstate: Update makefile to match new style
  selftests/intel_pstate: Fix warning on loop index overflow
  cpupower: Restore format of frequency-info limit
  selftests/futex: Add headers to makefile dependencies
  selftests/futex: Add stdio used for logging
  selftests: x86 protection_keys remove dead code
  selftests: x86 protection_keys fix unused variable compile warnings
  ...

59 files changed:
Documentation/kselftest.txt
MAINTAINERS
tools/power/cpupower/utils/cpufreq-info.c
tools/testing/selftests/Makefile
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/breakpoints/Makefile
tools/testing/selftests/capabilities/Makefile
tools/testing/selftests/cpufreq/Makefile [new file with mode: 0644]
tools/testing/selftests/cpufreq/cpu.sh [new file with mode: 0755]
tools/testing/selftests/cpufreq/cpufreq.sh [new file with mode: 0755]
tools/testing/selftests/cpufreq/governor.sh [new file with mode: 0755]
tools/testing/selftests/cpufreq/main.sh [new file with mode: 0755]
tools/testing/selftests/cpufreq/module.sh [new file with mode: 0755]
tools/testing/selftests/cpufreq/special-tests.sh [new file with mode: 0755]
tools/testing/selftests/efivarfs/Makefile
tools/testing/selftests/exec/Makefile
tools/testing/selftests/ftrace/Makefile
tools/testing/selftests/futex/Makefile
tools/testing/selftests/futex/functional/Makefile
tools/testing/selftests/futex/include/logging.h
tools/testing/selftests/gpio/.gitignore [new file with mode: 0644]
tools/testing/selftests/intel_pstate/Makefile
tools/testing/selftests/intel_pstate/aperf.c
tools/testing/selftests/ipc/.gitignore
tools/testing/selftests/ipc/Makefile
tools/testing/selftests/kcmp/Makefile
tools/testing/selftests/lib.mk
tools/testing/selftests/membarrier/Makefile
tools/testing/selftests/memfd/Makefile
tools/testing/selftests/mount/Makefile
tools/testing/selftests/mqueue/Makefile
tools/testing/selftests/net/Makefile
tools/testing/selftests/nsfs/Makefile
tools/testing/selftests/powerpc/Makefile
tools/testing/selftests/powerpc/alignment/Makefile
tools/testing/selftests/powerpc/benchmarks/Makefile
tools/testing/selftests/powerpc/context_switch/Makefile
tools/testing/selftests/powerpc/copyloops/Makefile
tools/testing/selftests/powerpc/dscr/Makefile
tools/testing/selftests/powerpc/math/Makefile
tools/testing/selftests/powerpc/mm/Makefile
tools/testing/selftests/powerpc/pmu/Makefile
tools/testing/selftests/powerpc/pmu/ebb/Makefile
tools/testing/selftests/powerpc/primitives/Makefile
tools/testing/selftests/powerpc/stringloops/Makefile
tools/testing/selftests/powerpc/switch_endian/Makefile
tools/testing/selftests/powerpc/syscalls/Makefile
tools/testing/selftests/powerpc/tm/Makefile
tools/testing/selftests/powerpc/vphn/Makefile
tools/testing/selftests/pstore/Makefile
tools/testing/selftests/ptrace/Makefile
tools/testing/selftests/seccomp/Makefile
tools/testing/selftests/sigaltstack/Makefile
tools/testing/selftests/size/Makefile
tools/testing/selftests/timers/Makefile
tools/testing/selftests/vm/Makefile
tools/testing/selftests/x86/Makefile
tools/testing/selftests/x86/protection_keys.c
tools/testing/selftests/zram/Makefile

index e5c7254e73d7d4c079638df02b376f81537bea48..d431dc82c2284faeee205ca9aaf8dcef7f0591c0 100644 (file)
@@ -95,3 +95,15 @@ In general, the rules for selftests are
 
  * Don't cause the top-level "make run_tests" to fail if your feature is
    unconfigured.
+
+Contributing new tests(details)
+===============================
+
+ * Use TEST_GEN_XXX if such binaries or files are generated during
+   compiling.
+   TEST_PROGS, TEST_GEN_PROGS mean it is the excutable tested by
+   default.
+   TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the
+   executable which is not tested by default.
+   TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
+   test.
index b4474a8b7e8ab922f8d5abe4517a400b03a54123..6cd8945b9094e1fa8ed5cd31e388aa9e98f14b3c 100644 (file)
@@ -3452,6 +3452,7 @@ B:        https://bugzilla.kernel.org
 F:     Documentation/cpu-freq/
 F:     drivers/cpufreq/
 F:     include/linux/cpufreq.h
+F:     tools/testing/selftests/cpufreq/
 
 CPU FREQUENCY DRIVERS - ARM BIG LITTLE
 M:     Viresh Kumar <viresh.kumar@linaro.org>
index 590d12a25f6e0b8c625011e72d1aa2189e9e1c43..3e701f0e9c1438f781b6dd0248212d250da800a5 100644 (file)
@@ -285,20 +285,24 @@ static int get_freq_hardware(unsigned int cpu, unsigned int human)
 
 /* --hwlimits / -l */
 
-static int get_hardware_limits(unsigned int cpu)
+static int get_hardware_limits(unsigned int cpu, unsigned int human)
 {
        unsigned long min, max;
 
-       printf(_("  hardware limits: "));
        if (cpufreq_get_hardware_limits(cpu, &min, &max)) {
                printf(_("Not Available\n"));
                return -EINVAL;
        }
 
-       print_speed(min);
-       printf(" - ");
-       print_speed(max);
-       printf("\n");
+       if (human) {
+               printf(_("  hardware limits: "));
+               print_speed(min);
+               printf(" - ");
+               print_speed(max);
+               printf("\n");
+       } else {
+               printf("%lu %lu\n", min, max);
+       }
        return 0;
 }
 
@@ -456,7 +460,7 @@ static void debug_output_one(unsigned int cpu)
        get_related_cpus(cpu);
        get_affected_cpus(cpu);
        get_latency(cpu, 1);
-       get_hardware_limits(cpu);
+       get_hardware_limits(cpu, 1);
 
        freqs = cpufreq_get_available_frequencies(cpu);
        if (freqs) {
@@ -622,7 +626,7 @@ int cmd_freq_info(int argc, char **argv)
                        ret = get_driver(cpu);
                        break;
                case 'l':
-                       ret = get_hardware_limits(cpu);
+                       ret = get_hardware_limits(cpu, human);
                        break;
                case 'w':
                        ret = get_freq_hardware(cpu, human);
@@ -639,7 +643,6 @@ int cmd_freq_info(int argc, char **argv)
                }
                if (ret)
                        return ret;
-               printf("\n");
        }
        return ret;
 }
index 831022b12848de68695065040b38bd7ec55f7577..e8b79a7b50bd52322a60541146f39ebbe4a36057 100644 (file)
@@ -1,6 +1,7 @@
 TARGETS =  bpf
 TARGETS += breakpoints
 TARGETS += capabilities
+TARGETS += cpufreq
 TARGETS += cpu-hotplug
 TARGETS += efivarfs
 TARGETS += exec
@@ -8,6 +9,7 @@ TARGETS += firmware
 TARGETS += ftrace
 TARGETS += futex
 TARGETS += gpio
+TARGETS += intel_pstate
 TARGETS += ipc
 TARGETS += kcmp
 TARGETS += lib
@@ -49,29 +51,44 @@ override LDFLAGS =
 override MAKEFLAGS =
 endif
 
+BUILD := $(O)
+ifndef BUILD
+  BUILD := $(KBUILD_OUTPUT)
+endif
+ifndef BUILD
+  BUILD := $(shell pwd)
+endif
+
+export BUILD
 all:
-       for TARGET in $(TARGETS); do \
-               make -C $$TARGET; \
+       for TARGET in $(TARGETS); do            \
+               BUILD_TARGET=$$BUILD/$$TARGET;  \
+               mkdir $$BUILD_TARGET  -p;       \
+               make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
        done;
 
 run_tests: all
        for TARGET in $(TARGETS); do \
-               make -C $$TARGET run_tests; \
+               BUILD_TARGET=$$BUILD/$$TARGET;  \
+               make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
        done;
 
 hotplug:
        for TARGET in $(TARGETS_HOTPLUG); do \
-               make -C $$TARGET; \
+               BUILD_TARGET=$$BUILD/$$TARGET;  \
+               make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
        done;
 
 run_hotplug: hotplug
        for TARGET in $(TARGETS_HOTPLUG); do \
-               make -C $$TARGET run_full_test; \
+               BUILD_TARGET=$$BUILD/$$TARGET;  \
+               make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
        done;
 
 clean_hotplug:
        for TARGET in $(TARGETS_HOTPLUG); do \
-               make -C $$TARGET clean; \
+               BUILD_TARGET=$$BUILD/$$TARGET;  \
+               make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
        done;
 
 run_pstore_crash:
@@ -86,7 +103,8 @@ ifdef INSTALL_PATH
        @# Ask all targets to install their files
        mkdir -p $(INSTALL_PATH)
        for TARGET in $(TARGETS); do \
-               make -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
+               BUILD_TARGET=$$BUILD/$$TARGET;  \
+               make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
        done;
 
        @# Ask all targets to emit their test scripts
@@ -95,10 +113,11 @@ ifdef INSTALL_PATH
        echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
 
        for TARGET in $(TARGETS); do \
+               BUILD_TARGET=$$BUILD/$$TARGET;  \
                echo "echo ; echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
                echo "echo ========================================" >> $(ALL_SCRIPT); \
                echo "cd $$TARGET" >> $(ALL_SCRIPT); \
-               make -s --no-print-directory -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
+               make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
                echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
        done;
 
@@ -109,7 +128,8 @@ endif
 
 clean:
        for TARGET in $(TARGETS); do \
-               make -C $$TARGET clean; \
+               BUILD_TARGET=$$BUILD/$$TARGET;  \
+               make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
        done;
 
 .PHONY: install
index c7816fe60feb92b2e53ab7f1c1e2a560de34c866..4b498265dae6dc3b52b35818453f2c895809b323 100644 (file)
@@ -3,15 +3,12 @@ BPFOBJ := $(LIBDIR)/bpf/bpf.o
 
 CFLAGS += -Wall -O2 -lcap -I../../../include/uapi -I$(LIBDIR)
 
-test_objs = test_verifier test_tag test_maps test_lru_map test_lpm_map
+TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map
 
-TEST_PROGS := $(test_objs) test_kmod.sh
-TEST_FILES := $(test_objs)
+TEST_PROGS := test_kmod.sh
 
 .PHONY: all clean force
 
-all: $(test_objs)
-
 # force a rebuild of BPFOBJ when its dependencies are updated
 force:
 
@@ -21,6 +18,3 @@ $(BPFOBJ): force
 $(test_objs): $(BPFOBJ)
 
 include ../lib.mk
-
-clean:
-       $(RM) $(test_objs)
index 61b79e8df1f4587c655fd3c440575241196e3a92..72aa103e4141d3b252c00a8bcf680edc4cd2dfbb 100644 (file)
@@ -3,17 +3,13 @@ uname_M := $(shell uname -m 2>/dev/null || echo not)
 ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
 
 ifeq ($(ARCH),x86)
-TEST_PROGS := breakpoint_test
+TEST_GEN_PROGS := breakpoint_test
 endif
 ifeq ($(ARCH),aarch64)
-TEST_PROGS := breakpoint_test_arm64
+TEST_GEN_PROGS := breakpoint_test_arm64
 endif
 
-TEST_PROGS += step_after_suspend_test
-
-all: $(TEST_PROGS)
+TEST_GEN_PROGS += step_after_suspend_test
 
 include ../lib.mk
 
-clean:
-       rm -fr breakpoint_test breakpoint_test_arm64 step_after_suspend_test
index 008602aed9209237254ca334a0a745f06c0888c4..29b8adfdac717d76cd32def4aaf61e94744b733f 100644 (file)
@@ -1,15 +1,8 @@
-TEST_FILES := validate_cap
-TEST_PROGS := test_execve
-
-BINARIES := $(TEST_FILES) $(TEST_PROGS)
+TEST_GEN_FILES := validate_cap
+TEST_GEN_PROGS := test_execve
 
 CFLAGS += -O2 -g -std=gnu99 -Wall
 LDLIBS += -lcap-ng -lrt -ldl
 
-all: $(BINARIES)
-
-clean:
-       $(RM) $(BINARIES)
-
 include ../lib.mk
 
diff --git a/tools/testing/selftests/cpufreq/Makefile b/tools/testing/selftests/cpufreq/Makefile
new file mode 100644 (file)
index 0000000..3955cd9
--- /dev/null
@@ -0,0 +1,8 @@
+all:
+
+TEST_PROGS := main.sh
+TEST_FILES := cpu.sh cpufreq.sh governor.sh module.sh special-tests.sh
+
+include ../lib.mk
+
+clean:
diff --git a/tools/testing/selftests/cpufreq/cpu.sh b/tools/testing/selftests/cpufreq/cpu.sh
new file mode 100755 (executable)
index 0000000..8e08a83
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash
+#
+# CPU helpers
+
+# protect against multiple inclusion
+if [ $FILE_CPU ]; then
+       return 0
+else
+       FILE_CPU=DONE
+fi
+
+source cpufreq.sh
+
+for_each_cpu()
+{
+       cpus=$(ls $CPUROOT | grep "cpu[0-9].*")
+       for cpu in $cpus; do
+               $@ $cpu
+       done
+}
+
+for_each_non_boot_cpu()
+{
+       cpus=$(ls $CPUROOT | grep "cpu[1-9].*")
+       for cpu in $cpus; do
+               $@ $cpu
+       done
+}
+
+#$1: cpu
+offline_cpu()
+{
+       printf "Offline $1\n"
+       echo 0 > $CPUROOT/$1/online
+}
+
+#$1: cpu
+online_cpu()
+{
+       printf "Online $1\n"
+       echo 1 > $CPUROOT/$1/online
+}
+
+#$1: cpu
+reboot_cpu()
+{
+       offline_cpu $1
+       online_cpu $1
+}
+
+# Reboot CPUs
+# param: number of times we want to run the loop
+reboot_cpus()
+{
+       printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
+
+       for i in `seq 1 $1`; do
+               for_each_non_boot_cpu offline_cpu
+               for_each_non_boot_cpu online_cpu
+               printf "\n"
+       done
+
+       printf "\n%s\n\n" "------------------------------------------------"
+}
+
+# Prints warning for all CPUs with missing cpufreq directory
+print_unmanaged_cpus()
+{
+       for_each_cpu cpu_should_have_cpufreq_directory
+}
+
+# Counts CPUs with cpufreq directories
+count_cpufreq_managed_cpus()
+{
+       count=0;
+
+       for cpu in `ls $CPUROOT | grep "cpu[0-9].*"`; do
+               if [ -d $CPUROOT/$cpu/cpufreq ]; then
+                       let count=count+1;
+               fi
+       done
+
+       echo $count;
+}
diff --git a/tools/testing/selftests/cpufreq/cpufreq.sh b/tools/testing/selftests/cpufreq/cpufreq.sh
new file mode 100755 (executable)
index 0000000..1ed3832
--- /dev/null
@@ -0,0 +1,241 @@
+#!/bin/bash
+
+# protect against multiple inclusion
+if [ $FILE_CPUFREQ ]; then
+       return 0
+else
+       FILE_CPUFREQ=DONE
+fi
+
+source cpu.sh
+
+
+# $1: cpu
+cpu_should_have_cpufreq_directory()
+{
+       if [ ! -d $CPUROOT/$1/cpufreq ]; then
+               printf "Warning: No cpufreq directory present for $1\n"
+       fi
+}
+
+cpu_should_not_have_cpufreq_directory()
+{
+       if [ -d $CPUROOT/$1/cpufreq ]; then
+               printf "Warning: cpufreq directory present for $1\n"
+       fi
+}
+
+for_each_policy()
+{
+       policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
+       for policy in $policies; do
+               $@ $policy
+       done
+}
+
+for_each_policy_concurrent()
+{
+       policies=$(ls $CPUFREQROOT| grep "policy[0-9].*")
+       for policy in $policies; do
+               $@ $policy &
+       done
+}
+
+# $1: Path
+read_cpufreq_files_in_dir()
+{
+       local files=`ls $1`
+
+       printf "Printing directory: $1\n\n"
+
+       for file in $files; do
+               if [ -f $1/$file ]; then
+                       printf "$file:"
+                       cat $1/$file
+               else
+                       printf "\n"
+                       read_cpufreq_files_in_dir "$1/$file"
+               fi
+       done
+       printf "\n"
+}
+
+
+read_all_cpufreq_files()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n\n"
+
+       read_cpufreq_files_in_dir $CPUFREQROOT
+
+       printf "%s\n\n" "------------------------------------------------"
+}
+
+
+# UPDATE CPUFREQ FILES
+
+# $1: directory path
+update_cpufreq_files_in_dir()
+{
+       local files=`ls $1`
+
+       printf "Updating directory: $1\n\n"
+
+       for file in $files; do
+               if [ -f $1/$file ]; then
+                       # file is writable ?
+                       local wfile=$(ls -l $1/$file | awk '$1 ~ /^.*w.*/ { print $NF; }')
+
+                       if [ ! -z $wfile ]; then
+                               # scaling_setspeed is a special file and we
+                               # should skip updating it
+                               if [ $file != "scaling_setspeed" ]; then
+                                       local val=$(cat $1/$file)
+                                       printf "Writing $val to: $file\n"
+                                       echo $val > $1/$file
+                               fi
+                       fi
+               else
+                       printf "\n"
+                       update_cpufreq_files_in_dir "$1/$file"
+               fi
+       done
+
+       printf "\n"
+}
+
+# Update all writable files with their existing values
+update_all_cpufreq_files()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n\n"
+
+       update_cpufreq_files_in_dir $CPUFREQROOT
+
+       printf "%s\n\n" "------------------------------------------------"
+}
+
+
+# CHANGE CPU FREQUENCIES
+
+# $1: policy
+find_current_freq()
+{
+       cat $CPUFREQROOT/$1/scaling_cur_freq
+}
+
+# $1: policy
+# $2: frequency
+set_cpu_frequency()
+{
+       printf "Change frequency for $1 to $2\n"
+       echo $2 > $CPUFREQROOT/$1/scaling_setspeed
+}
+
+# $1: policy
+test_all_frequencies()
+{
+       local filepath="$CPUFREQROOT/$1"
+
+       backup_governor $1
+
+       local found=$(switch_governor $1 "userspace")
+       if [ $found = 1 ]; then
+               printf "${FUNCNAME[0]}: userspace governor not available for: $1\n"
+               return;
+       fi
+
+       printf "Switched governor for $1 to userspace\n\n"
+
+       local freqs=$(cat $filepath/scaling_available_frequencies)
+       printf "Available frequencies for $1: $freqs\n\n"
+
+       # Set all frequencies one-by-one
+       for freq in $freqs; do
+               set_cpu_frequency $1 $freq
+       done
+
+       printf "\n"
+
+       restore_governor $1
+}
+
+# $1: loop count
+shuffle_frequency_for_all_cpus()
+{
+       printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
+
+       for i in `seq 1 $1`; do
+               for_each_policy test_all_frequencies
+       done
+       printf "\n%s\n\n" "------------------------------------------------"
+}
+
+# Basic cpufreq tests
+cpufreq_basic_tests()
+{
+       printf "*** RUNNING CPUFREQ SANITY TESTS ***\n"
+       printf "====================================\n\n"
+
+       count=$(count_cpufreq_managed_cpus)
+       if [ $count = 0 ]; then
+               printf "No cpu is managed by cpufreq core, exiting\n"
+               exit;
+       else
+               printf "CPUFreq manages: $count CPUs\n\n"
+       fi
+
+       # Detect & print which CPUs are not managed by cpufreq
+       print_unmanaged_cpus
+
+       # read/update all cpufreq files
+       read_all_cpufreq_files
+       update_all_cpufreq_files
+
+       # hotplug cpus
+       reboot_cpus 5
+
+       # Test all frequencies
+       shuffle_frequency_for_all_cpus 2
+
+       # Test all governors
+       shuffle_governors_for_all_cpus 1
+}
+
+# Suspend/resume
+# $1: "suspend" or "hibernate", $2: loop count
+do_suspend()
+{
+       printf "** Test: Running ${FUNCNAME[0]}: Trying $1 for $2 loops **\n\n"
+
+       # Is the directory available
+       if [ ! -d $SYSFS/power/ -o ! -f $SYSFS/power/state ]; then
+               printf "$SYSFS/power/state not available\n"
+               return 1
+       fi
+
+       if [ $1 = "suspend" ]; then
+               filename="mem"
+       elif [ $1 = "hibernate" ]; then
+               filename="disk"
+       else
+               printf "$1 is not a valid option\n"
+               return 1
+       fi
+
+       if [ -n $filename ]; then
+               present=$(cat $SYSFS/power/state | grep $filename)
+
+               if [ -z "$present" ]; then
+                       printf "Tried to $1 but $filename isn't present in $SYSFS/power/state\n"
+                       return 1;
+               fi
+
+               for i in `seq 1 $2`; do
+                       printf "Starting $1\n"
+                       echo $filename > $SYSFS/power/state
+                       printf "Came out of $1\n"
+
+                       printf "Do basic tests after finishing $1 to verify cpufreq state\n\n"
+                       cpufreq_basic_tests
+               done
+       fi
+}
diff --git a/tools/testing/selftests/cpufreq/governor.sh b/tools/testing/selftests/cpufreq/governor.sh
new file mode 100755 (executable)
index 0000000..def6451
--- /dev/null
@@ -0,0 +1,153 @@
+#!/bin/bash
+#
+# Test governors
+
+# protect against multiple inclusion
+if [ $FILE_GOVERNOR ]; then
+       return 0
+else
+       FILE_GOVERNOR=DONE
+fi
+
+source cpu.sh
+source cpufreq.sh
+
+CUR_GOV=
+CUR_FREQ=
+
+# Find governor's directory path
+# $1: policy, $2: governor
+find_gov_directory()
+{
+       if [ -d $CPUFREQROOT/$2 ]; then
+               printf "$CPUFREQROOT/$2\n"
+       elif [ -d $CPUFREQROOT/$1/$2 ]; then
+               printf "$CPUFREQROOT/$1/$2\n"
+       else
+               printf "INVALID\n"
+       fi
+}
+
+# $1: policy
+find_current_governor()
+{
+       cat $CPUFREQROOT/$1/scaling_governor
+}
+
+# $1: policy
+backup_governor()
+{
+       CUR_GOV=$(find_current_governor $1)
+
+       printf "Governor backup done for $1: $CUR_GOV\n"
+
+       if [ $CUR_GOV == "userspace" ]; then
+               CUR_FREQ=$(find_current_freq $1)
+               printf "Governor frequency backup done for $1: $CUR_FREQ\n"
+       fi
+
+       printf "\n"
+}
+
+# $1: policy
+restore_governor()
+{
+       __switch_governor $1 $CUR_GOV
+
+       printf "Governor restored for $1 to $CUR_GOV\n"
+
+       if [ $CUR_GOV == "userspace" ]; then
+               set_cpu_frequency $1 $CUR_FREQ
+               printf "Governor frequency restored for $1: $CUR_FREQ\n"
+       fi
+
+       printf "\n"
+}
+
+# param:
+# $1: policy, $2: governor
+__switch_governor()
+{
+       echo $2 > $CPUFREQROOT/$1/scaling_governor
+}
+
+# param:
+# $1: cpu, $2: governor
+__switch_governor_for_cpu()
+{
+       echo $2 > $CPUROOT/$1/cpufreq/scaling_governor
+}
+
+# SWITCH GOVERNORS
+
+# $1: cpu, $2: governor
+switch_governor()
+{
+       local filepath=$CPUFREQROOT/$1/scaling_available_governors
+
+       # check if governor is available
+       local found=$(cat $filepath | grep $2 | wc -l)
+       if [ $found = 0 ]; then
+               echo 1;
+               return
+       fi
+
+       __switch_governor $1 $2
+       echo 0;
+}
+
+# $1: policy, $2: governor
+switch_show_governor()
+{
+       cur_gov=find_current_governor
+       if [ $cur_gov == "userspace" ]; then
+               cur_freq=find_current_freq
+       fi
+
+       # switch governor
+       __switch_governor $1 $2
+
+       printf "\nSwitched governor for $1 to $2\n\n"
+
+       if [ $2 == "userspace" -o $2 == "powersave" -o $2 == "performance" ]; then
+               printf "No files to read for $2 governor\n\n"
+               return
+       fi
+
+       # show governor files
+       local govpath=$(find_gov_directory $1 $2)
+       read_cpufreq_files_in_dir $govpath
+}
+
+# $1: function to be called, $2: policy
+call_for_each_governor()
+{
+       local filepath=$CPUFREQROOT/$2/scaling_available_governors
+
+       # Exit if cpu isn't managed by cpufreq core
+       if [ ! -f $filepath ]; then
+               return;
+       fi
+
+       backup_governor $2
+
+       local governors=$(cat $filepath)
+       printf "Available governors for $2: $governors\n"
+
+       for governor in $governors; do
+               $1 $2 $governor
+       done
+
+       restore_governor $2
+}
+
+# $1: loop count
+shuffle_governors_for_all_cpus()
+{
+       printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
+
+       for i in `seq 1 $1`; do
+               for_each_policy call_for_each_governor switch_show_governor
+       done
+       printf "%s\n\n" "------------------------------------------------"
+}
diff --git a/tools/testing/selftests/cpufreq/main.sh b/tools/testing/selftests/cpufreq/main.sh
new file mode 100755 (executable)
index 0000000..01bac76
--- /dev/null
@@ -0,0 +1,194 @@
+#!/bin/bash
+
+source cpu.sh
+source cpufreq.sh
+source governor.sh
+source module.sh
+source special-tests.sh
+
+FUNC=basic     # do basic tests by default
+OUTFILE=cpufreq_selftest
+SYSFS=
+CPUROOT=
+CPUFREQROOT=
+
+helpme()
+{
+       printf "Usage: $0 [-h] [-todg args]
+       [-h <help>]
+       [-o <output-file-for-dump>]
+       [-t <basic: Basic cpufreq testing
+            suspend: suspend/resume,
+            hibernate: hibernate/resume,
+            modtest: test driver or governor modules. Only to be used with -d or -g options,
+            sptest1: Simple governor switch to produce lockdep.
+            sptest2: Concurrent governor switch to produce lockdep.
+            sptest3: Governor races, shuffle between governors quickly.
+            sptest4: CPU hotplugs with updates to cpufreq files.>]
+       [-d <driver's module name: only with \"-t modtest>\"]
+       [-g <governor's module name: only with \"-t modtest>\"]
+       \n"
+       exit 2
+}
+
+prerequisite()
+{
+       msg="skip all tests:"
+
+       if [ $UID != 0 ]; then
+               echo $msg must be run as root >&2
+               exit 2
+       fi
+
+       taskset -p 01 $$
+
+       SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
+
+       if [ ! -d "$SYSFS" ]; then
+               echo $msg sysfs is not mounted >&2
+               exit 2
+       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
+       fi
+
+       if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
+               echo $msg cpufreq directory not available in sysfs >&2
+               exit 2
+       fi
+}
+
+parse_arguments()
+{
+       while getopts ht:o:d:g: arg
+       do
+               case $arg in
+                       h) # --help
+                               helpme
+                               ;;
+
+                       t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
+                               FUNC=$OPTARG
+                               ;;
+
+                       o) # --output-file (Output file to store dumps)
+                               OUTFILE=$OPTARG
+                               ;;
+
+                       d) # --driver-mod-name (Name of the driver module)
+                               DRIVER_MOD=$OPTARG
+                               ;;
+
+                       g) # --governor-mod-name (Name of the governor module)
+                               GOVERNOR_MOD=$OPTARG
+                               ;;
+
+                       \?)
+                               helpme
+                               ;;
+               esac
+       done
+}
+
+do_test()
+{
+       # Check if CPUs are managed by cpufreq or not
+       count=$(count_cpufreq_managed_cpus)
+
+       if [ $count = 0 -a $FUNC != "modtest" ]; then
+               echo "No cpu is managed by cpufreq core, exiting"
+               exit 2;
+       fi
+
+       case "$FUNC" in
+               "basic")
+               cpufreq_basic_tests
+               ;;
+
+               "suspend")
+               do_suspend "suspend" 1
+               ;;
+
+               "hibernate")
+               do_suspend "hibernate" 1
+               ;;
+
+               "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;
+               fi
+
+               if [ $DRIVER_MOD ]; then
+                       if [ $GOVERNOR_MOD ]; then
+                               module_test $DRIVER_MOD $GOVERNOR_MOD
+                       else
+                               module_driver_test $DRIVER_MOD
+                       fi
+               else
+                       if [ $count = 0 ]; then
+                               echo "No cpu is managed by cpufreq core, exiting"
+                               exit 2;
+                       fi
+
+                       module_governor_test $GOVERNOR_MOD
+               fi
+               ;;
+
+               "sptest1")
+               simple_lockdep
+               ;;
+
+               "sptest2")
+               concurrent_lockdep
+               ;;
+
+               "sptest3")
+               governor_race
+               ;;
+
+               "sptest4")
+               hotplug_with_updates
+               ;;
+
+               *)
+               echo "Invalid [-f] function type"
+               helpme
+               ;;
+       esac
+}
+
+# clear dumps
+# $1: file name
+clear_dumps()
+{
+       echo "" > $1.txt
+       echo "" > $1.dmesg_cpufreq.txt
+       echo "" > $1.dmesg_full.txt
+}
+
+# $1: output file name
+dmesg_dumps()
+{
+       dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
+
+       # We may need the full logs as well
+       dmesg >> $1.dmesg_full.txt
+}
+
+# Parse arguments
+parse_arguments $@
+
+# Make sure all requirements are met
+prerequisite
+
+# Run requested functions
+clear_dumps $OUTFILE
+do_test >> $OUTFILE.txt
+dmesg_dumps $OUTFILE
diff --git a/tools/testing/selftests/cpufreq/module.sh b/tools/testing/selftests/cpufreq/module.sh
new file mode 100755 (executable)
index 0000000..8ff2244
--- /dev/null
@@ -0,0 +1,243 @@
+#!/bin/bash
+#
+# Modules specific tests cases
+
+# protect against multiple inclusion
+if [ $FILE_MODULE ]; then
+       return 0
+else
+       FILE_MODULE=DONE
+fi
+
+source cpu.sh
+source cpufreq.sh
+source governor.sh
+
+# Check basic insmod/rmmod
+# $1: module
+test_basic_insmod_rmmod()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n\n"
+
+       printf "Inserting $1 module\n"
+       # insert module
+       insmod $1
+       if [ $? != 0 ]; then
+               printf "Insmod $1 failed\n"
+               exit;
+       fi
+
+       printf "Removing $1 module\n"
+       # remove module
+       rmmod $1
+       if [ $? != 0 ]; then
+               printf "rmmod $1 failed\n"
+               exit;
+       fi
+
+       printf "\n"
+}
+
+# Insert cpufreq driver module and perform basic tests
+# $1: cpufreq-driver module to insert
+# $2: If we want to play with CPUs (1) or not (0)
+module_driver_test_single()
+{
+       printf "** Test: Running ${FUNCNAME[0]} for driver $1 and cpus_hotplug=$2 **\n\n"
+
+       if [ $2 -eq 1 ]; then
+               # offline all non-boot CPUs
+               for_each_non_boot_cpu offline_cpu
+               printf "\n"
+       fi
+
+       # insert module
+       printf "Inserting $1 module\n\n"
+       insmod $1
+       if [ $? != 0 ]; then
+               printf "Insmod $1 failed\n"
+               return;
+       fi
+
+       if [ $2 -eq 1 ]; then
+               # online all non-boot CPUs
+               for_each_non_boot_cpu online_cpu
+               printf "\n"
+       fi
+
+       # run basic tests
+       cpufreq_basic_tests
+
+       # remove module
+       printf "Removing $1 module\n\n"
+       rmmod $1
+       if [ $? != 0 ]; then
+               printf "rmmod $1 failed\n"
+               return;
+       fi
+
+       # There shouldn't be any cpufreq directories now.
+       for_each_cpu cpu_should_not_have_cpufreq_directory
+       printf "\n"
+}
+
+# $1: cpufreq-driver module to insert
+module_driver_test()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n\n"
+
+       # check if module is present or not
+       ls $1 > /dev/null
+       if [ $? != 0 ]; then
+               printf "$1: not present in `pwd` folder\n"
+               return;
+       fi
+
+       # test basic module tests
+       test_basic_insmod_rmmod $1
+
+       # Do simple module test
+       module_driver_test_single $1 0
+
+       # Remove CPUs before inserting module and then bring them back
+       module_driver_test_single $1 1
+       printf "\n"
+}
+
+# find governor name based on governor module name
+# $1: governor module name
+find_gov_name()
+{
+       if [ $1 = "cpufreq_ondemand.ko" ]; then
+               printf "ondemand"
+       elif [ $1 = "cpufreq_conservative.ko" ]; then
+               printf "conservative"
+       elif [ $1 = "cpufreq_userspace.ko" ]; then
+               printf "userspace"
+       elif [ $1 = "cpufreq_performance.ko" ]; then
+               printf "performance"
+       elif [ $1 = "cpufreq_powersave.ko" ]; then
+               printf "powersave"
+       elif [ $1 = "cpufreq_schedutil.ko" ]; then
+               printf "schedutil"
+       fi
+}
+
+# $1: governor string, $2: governor module, $3: policy
+# example: module_governor_test_single "ondemand" "cpufreq_ondemand.ko" 2
+module_governor_test_single()
+{
+       printf "** Test: Running ${FUNCNAME[0]} for $3 **\n\n"
+
+       backup_governor $3
+
+       # switch to new governor
+       printf "Switch from $CUR_GOV to $1\n"
+       switch_show_governor $3 $1
+
+       # try removing module, it should fail as governor is used
+       printf "Removing $2 module\n\n"
+       rmmod $2
+       if [ $? = 0 ]; then
+               printf "WARN: rmmod $2 succeeded even if governor is used\n"
+               insmod $2
+       else
+               printf "Pass: unable to remove $2 while it is being used\n\n"
+       fi
+
+       # switch back to old governor
+       printf "Switchback to $CUR_GOV from $1\n"
+       restore_governor $3
+       printf "\n"
+}
+
+# Insert cpufreq governor module and perform basic tests
+# $1: cpufreq-governor module to insert
+module_governor_test()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n\n"
+
+       # check if module is present or not
+       ls $1 > /dev/null
+       if [ $? != 0 ]; then
+               printf "$1: not present in `pwd` folder\n"
+               return;
+       fi
+
+       # test basic module tests
+       test_basic_insmod_rmmod $1
+
+       # insert module
+       printf "Inserting $1 module\n\n"
+       insmod $1
+       if [ $? != 0 ]; then
+               printf "Insmod $1 failed\n"
+               return;
+       fi
+
+       # switch to new governor for each cpu
+       for_each_policy module_governor_test_single $(find_gov_name $1) $1
+
+       # remove module
+       printf "Removing $1 module\n\n"
+       rmmod $1
+       if [ $? != 0 ]; then
+               printf "rmmod $1 failed\n"
+               return;
+       fi
+       printf "\n"
+}
+
+# test modules: driver and governor
+# $1: driver module, $2: governor module
+module_test()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n\n"
+
+       # check if modules are present or not
+       ls $1 $2 > /dev/null
+       if [ $? != 0 ]; then
+               printf "$1 or $2: is not present in `pwd` folder\n"
+               return;
+       fi
+
+       # TEST1: Insert gov after driver
+       # insert driver module
+       printf "Inserting $1 module\n\n"
+       insmod $1
+       if [ $? != 0 ]; then
+               printf "Insmod $1 failed\n"
+               return;
+       fi
+
+       # run governor tests
+       module_governor_test $2
+
+       # remove driver module
+       printf "Removing $1 module\n\n"
+       rmmod $1
+       if [ $? != 0 ]; then
+               printf "rmmod $1 failed\n"
+               return;
+       fi
+
+       # TEST2: Insert driver after governor
+       # insert governor module
+       printf "Inserting $2 module\n\n"
+       insmod $2
+       if [ $? != 0 ]; then
+               printf "Insmod $2 failed\n"
+               return;
+       fi
+
+       # run governor tests
+       module_driver_test $1
+
+       # remove driver module
+       printf "Removing $2 module\n\n"
+       rmmod $2
+       if [ $? != 0 ]; then
+               printf "rmmod $2 failed\n"
+               return;
+       fi
+}
diff --git a/tools/testing/selftests/cpufreq/special-tests.sh b/tools/testing/selftests/cpufreq/special-tests.sh
new file mode 100755 (executable)
index 0000000..58b730f
--- /dev/null
@@ -0,0 +1,115 @@
+#!/bin/bash
+#
+# Special test cases reported by people
+
+# Testcase 1: Reported here: http://marc.info/?l=linux-pm&m=140618592709858&w=2
+
+# protect against multiple inclusion
+if [ $FILE_SPECIAL ]; then
+       return 0
+else
+       FILE_SPECIAL=DONE
+fi
+
+source cpu.sh
+source cpufreq.sh
+source governor.sh
+
+# Test 1
+# $1: policy
+__simple_lockdep()
+{
+       # switch to ondemand
+       __switch_governor $1 "ondemand"
+
+       # cat ondemand files
+       local ondir=$(find_gov_directory $1 "ondemand")
+       if [ -z $ondir ]; then
+               printf "${FUNCNAME[0]}Ondemand directory not created, quit"
+               return
+       fi
+
+       cat $ondir/*
+
+       # switch to conservative
+       __switch_governor $1 "conservative"
+}
+
+simple_lockdep()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n"
+
+       for_each_policy __simple_lockdep
+}
+
+# Test 2
+# $1: policy
+__concurrent_lockdep()
+{
+       for i in `seq 0 100`; do
+               __simple_lockdep $1
+       done
+}
+
+concurrent_lockdep()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n"
+
+       for_each_policy_concurrent __concurrent_lockdep
+}
+
+# Test 3
+quick_shuffle()
+{
+       # this is called concurrently from governor_race
+       for I in `seq 1000`
+       do
+               echo ondemand | sudo tee $CPUFREQROOT/policy*/scaling_governor &
+               echo userspace | sudo tee $CPUFREQROOT/policy*/scaling_governor &
+       done
+}
+
+governor_race()
+{
+       printf "** Test: Running ${FUNCNAME[0]} **\n"
+
+       # run 8 concurrent instances
+       for I in `seq 8`
+       do
+               quick_shuffle &
+       done
+}
+
+# Test 4
+# $1: cpu
+hotplug_with_updates_cpu()
+{
+       local filepath="$CPUROOT/$1/cpufreq"
+
+       # switch to ondemand
+       __switch_governor_for_cpu $1 "ondemand"
+
+       for i in `seq 1 5000`
+       do
+               reboot_cpu $1
+       done &
+
+       local freqs=$(cat $filepath/scaling_available_frequencies)
+       local oldfreq=$(cat $filepath/scaling_min_freq)
+
+       for j in `seq 1 5000`
+       do
+               # Set all frequencies one-by-one
+               for freq in $freqs; do
+                       echo $freq > $filepath/scaling_min_freq
+               done
+       done
+
+       # restore old freq
+       echo $oldfreq > $filepath/scaling_min_freq
+}
+
+hotplug_with_updates()
+{
+       for_each_non_boot_cpu hotplug_with_updates_cpu
+}
index 736c3ddfc787499a3a114ab87ad173054e5468c2..c49dcea69319a36e98eabb9a44bdc5b75ff94575 100644 (file)
@@ -1,13 +1,7 @@
 CFLAGS = -Wall
 
-test_objs = open-unlink create-read
-
-all: $(test_objs)
-
+TEST_GEN_FILES := open-unlink create-read
 TEST_PROGS := efivarfs.sh
-TEST_FILES := $(test_objs)
 
 include ../lib.mk
 
-clean:
-       rm -f $(test_objs)
index d4300602bf376a5f6e87b1eb17620d3652dd9795..2e13035dff7f6f4bfcf28d59e38bd1d7231bacce 100644 (file)
@@ -1,27 +1,23 @@
 CFLAGS = -Wall
-BINARIES = execveat
-DEPS = execveat.symlink execveat.denatured script subdir
-all: $(BINARIES) $(DEPS)
 
-subdir:
+TEST_GEN_PROGS := execveat
+TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir
+# Makefile is a run-time dependency, since it's accessed by the execveat test
+TEST_FILES := Makefile
+
+EXTRA_CLEAN := $(OUTPUT)/subdir.moved $(OUTPUT)/execveat.moved $(OUTPUT)/xxxxx*
+
+include ../lib.mk
+
+$(OUTPUT)/subdir:
        mkdir -p $@
-script:
+$(OUTPUT)/script:
        echo '#!/bin/sh' > $@
        echo 'exit $$*' >> $@
        chmod +x $@
-execveat.symlink: execveat
-       ln -s -f $< $@
-execveat.denatured: execveat
+$(OUTPUT)/execveat.symlink: $(OUTPUT)/execveat
+       cd $(OUTPUT) && ln -s -f $(shell basename $<) $(shell basename $@)
+$(OUTPUT)/execveat.denatured: $(OUTPUT)/execveat
        cp $< $@
        chmod -x $@
-%: %.c
-       $(CC) $(CFLAGS) -o $@ $^
-
-TEST_PROGS := execveat
-# Makefile is a run-time dependency, since it's accessed by the execveat test
-TEST_FILES := $(DEPS) Makefile
-
-include ../lib.mk
 
-clean:
-       rm -rf $(BINARIES) $(DEPS) subdir.moved execveat.moved xxxxx*
index 4e6ed13e7f66150de10a8f645eff508fc0565cff..a8a5e21850e740a099228963db130961e542b838 100644 (file)
@@ -1,9 +1,7 @@
 all:
 
 TEST_PROGS := ftracetest
-TEST_DIRS := test.d
+TEST_FILES := test.d
+EXTRA_CLEAN := $(OUTPUT)/logs/*
 
 include ../lib.mk
-
-clean:
-       rm -rf logs/*
index 6a1752956283cbef8f70ae83c103fa73a1dae4ab..653c5cd9e44d6bc4fba89b79ae8d1d707993e542 100644 (file)
@@ -3,13 +3,18 @@ SUBDIRS := functional
 TEST_PROGS := run.sh
 
 .PHONY: all clean
-all:
-       for DIR in $(SUBDIRS); do $(MAKE) -C $$DIR $@ ; done
 
 include ../lib.mk
 
+all:
+       for DIR in $(SUBDIRS); do               \
+               BUILD_TARGET=$$OUTPUT/$$DIR;    \
+               mkdir $$BUILD_TARGET  -p;       \
+               make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
+       done
+
 override define RUN_TESTS
-       ./run.sh
+       @if [ `dirname $(OUTPUT)` = $(PWD) ]; then ./run.sh; fi
 endef
 
 override define INSTALL_RULE
@@ -17,7 +22,9 @@ override define INSTALL_RULE
        install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)
 
        @for SUBDIR in $(SUBDIRS); do \
-               $(MAKE) -C $$SUBDIR INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
+               BUILD_TARGET=$$OUTPUT/$$SUBDIR; \
+               mkdir $$BUILD_TARGET  -p;       \
+               $(MAKE) OUTPUT=$$BUILD_TARGET -C $$SUBDIR INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
        done;
 endef
 
@@ -26,4 +33,8 @@ override define EMIT_TESTS
 endef
 
 clean:
-       for DIR in $(SUBDIRS); do $(MAKE) -C $$DIR $@ ; done
+       for DIR in $(SUBDIRS); do               \
+               BUILD_TARGET=$$OUTPUT/$$DIR;    \
+               mkdir $$BUILD_TARGET  -p;       \
+               make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
+       done
index 9d6b75ef7b5d679a698862b2406b619e633e8672..a648e7a6cbc3d3d5fc3ea4a1d254e9246950721e 100644 (file)
@@ -2,8 +2,11 @@ INCLUDES := -I../include -I../../
 CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES)
 LDFLAGS := $(LDFLAGS) -pthread -lrt
 
-HEADERS := ../include/futextest.h
-TARGETS := \
+HEADERS := \
+       ../include/futextest.h \
+       ../include/atomic.h \
+       ../include/logging.h
+TEST_GEN_FILES := \
        futex_wait_timeout \
        futex_wait_wouldblock \
        futex_requeue_pi \
@@ -12,14 +15,8 @@ TARGETS := \
        futex_wait_uninitialized_heap \
        futex_wait_private_mapped_file
 
-TEST_PROGS := $(TARGETS) run.sh
-
-.PHONY: all clean
-all: $(TARGETS)
-
-$(TARGETS): $(HEADERS)
+TEST_PROGS := run.sh
 
 include ../../lib.mk
 
-clean:
-       rm -f $(TARGETS)
+$(TEST_GEN_FILES): $(HEADERS)
index 014aa01197af5084c097de3e5a425894ad630140..e14469103f073d071f5e4b43c845440865f72287 100644 (file)
@@ -21,6 +21,7 @@
 #ifndef _LOGGING_H
 #define _LOGGING_H
 
+#include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <linux/futex.h>
diff --git a/tools/testing/selftests/gpio/.gitignore b/tools/testing/selftests/gpio/.gitignore
new file mode 100644 (file)
index 0000000..7d14f74
--- /dev/null
@@ -0,0 +1 @@
+gpio-mockup-chardev
index f5f1a28715ffbf75fc098c9f194fe8e0a53eca57..19678e90efb25d1231e6bdfd97f8b6ea99a6f6bf 100644 (file)
@@ -1,15 +1,10 @@
-CC := $(CROSS_COMPILE)gcc
 CFLAGS := $(CFLAGS) -Wall -D_GNU_SOURCE
 LDFLAGS := $(LDFLAGS) -lm
 
-TARGETS := msr aperf
+TEST_GEN_FILES := msr aperf
 
-TEST_PROGS := $(TARGETS) run.sh
+TEST_PROGS := run.sh
 
-.PHONY: all clean
-all: $(TARGETS)
+include ../lib.mk
 
-$(TARGETS): $(HEADERS)
-
-clean:
-       rm -f $(TARGETS)
+$(TEST_GEN_FILES): $(HEADERS)
index 6046e183f4add3276adbbf4722f65435548f8a96..cd72f3dc83e9dec7ba51c38c674447c0174ff5b4 100644 (file)
@@ -14,7 +14,7 @@ void usage(char *name) {
 }
 
 int main(int argc, char **argv) {
-       int i, cpu, fd;
+       unsigned int i, cpu, fd;
        char msr_file_name[64];
        long long tsc, old_tsc, new_tsc;
        long long aperf, old_aperf, new_aperf;
index 84b66a3c1f740cc846e2ab3755eaf26ec148ab86..9af04c9353c0f89f966b7b642d5d586633ce8f3e 100644 (file)
@@ -1 +1,2 @@
 msgque_test
+msgque
index 25d2e702c68a53f7021d47404fd59d69241f430c..30ef4c7f53eaa3d29baaa47b69fd9090e328b8a9 100644 (file)
@@ -11,12 +11,7 @@ endif
 
 CFLAGS += -I../../../../usr/include/
 
-all:
-       $(CC) $(CFLAGS) msgque.c -o msgque_test
-
-TEST_PROGS := msgque_test
+TEST_GEN_PROGS := msgque
 
 include ../lib.mk
 
-clean:
-       rm -fr ./msgque_test
index 2ae7450a9a8984e2f0ba86a96842010375076757..47aa9887f9d4bfcf53907cafff36b947469cbb80 100644 (file)
@@ -1,10 +1,8 @@
 CFLAGS += -I../../../../usr/include/
 
-all: kcmp_test
+TEST_GEN_PROGS := kcmp_test
 
-TEST_PROGS := kcmp_test
+EXTRA_CLEAN := $(OUTPUT)/kcmp-test-file
 
 include ../lib.mk
 
-clean:
-       $(RM) kcmp_test kcmp-test-file
index 50a93f5f13d64d5b0f9b4851d03f955da9b6e1d9..ce96d80ad64f4da000ecec590365582d399fadf3 100644 (file)
@@ -2,9 +2,15 @@
 # Makefile can operate with or without the kbuild infrastructure.
 CC := $(CROSS_COMPILE)gcc
 
+TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
+TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
+
+all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
+
 define RUN_TESTS
-       @for TEST in $(TEST_PROGS); do \
-               (./$$TEST && echo "selftests: $$TEST [PASS]") || echo "selftests: $$TEST [FAIL]"; \
+       @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
+               BASENAME_TEST=`basename $$TEST`;        \
+               cd `dirname $$TEST`; (./$$BASENAME_TEST && echo "selftests: $$BASENAME_TEST [PASS]") || echo "selftests:  $$BASENAME_TEST [FAIL]"; cd -;\
        done;
 endef
 
@@ -14,8 +20,13 @@ run_tests: all
 define INSTALL_RULE
        @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then                                        \
                mkdir -p ${INSTALL_PATH};                                                                               \
-               echo "rsync -a $(TEST_DIRS) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/";       \
-               rsync -a $(TEST_DIRS) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/;              \
+               echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/";    \
+               rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/;           \
+       fi
+       @if [ "X$(TEST_GEN_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then                                    \
+               mkdir -p ${INSTALL_PATH};                                                                               \
+               echo "rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/";        \
+               rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/;               \
        fi
 endef
 
@@ -27,12 +38,25 @@ else
 endif
 
 define EMIT_TESTS
-       @for TEST in $(TEST_PROGS); do \
-               echo "(./$$TEST && echo \"selftests: $$TEST [PASS]\") || echo \"selftests: $$TEST [FAIL]\""; \
+       @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
+               BASENAME_TEST=`basename $$TEST`;        \
+               echo "(./$$BASENAME_TEST && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \
        done;
 endef
 
 emit_tests:
        $(EMIT_TESTS)
 
+clean:
+       $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
+
+$(OUTPUT)/%:%.c
+       $(LINK.c) $^ $(LDLIBS) -o $@
+
+$(OUTPUT)/%.o:%.S
+       $(COMPILE.S) $^ -o $@
+
+$(OUTPUT)/%:%.S
+       $(LINK.S) $^ $(LDLIBS) -o $@
+
 .PHONY: run_tests all clean install emit_tests
index a1a97085847d2e173f836864f35dfccc38229c2a..02845532b0592315399ed384c98efb25a79c1034 100644 (file)
@@ -1,10 +1,6 @@
 CFLAGS += -g -I../../../../usr/include/
 
-TEST_PROGS := membarrier_test
-
-all: $(TEST_PROGS)
+TEST_GEN_PROGS := membarrier_test
 
 include ../lib.mk
 
-clean:
-       $(RM) $(TEST_PROGS)
index fd396ac811b6a73f086e605ef93e0d2c92401ad6..79891d033de162cdcc921f3de7802738fa0e0a50 100644 (file)
@@ -1,22 +1,13 @@
-CC = $(CROSS_COMPILE)gcc
 CFLAGS += -D_FILE_OFFSET_BITS=64
 CFLAGS += -I../../../../include/uapi/
 CFLAGS += -I../../../../include/
 CFLAGS += -I../../../../usr/include/
 
-TEST_PROGS := memfd_test
-
-all: $(TEST_PROGS)
-
-include ../lib.mk
-
-build_fuse: fuse_mnt fuse_test
+TEST_PROGS := run_fuse_test.sh
+TEST_GEN_FILES := memfd_test fuse_mnt fuse_test
 
 fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags)
 fuse_mnt: LDFLAGS += $(shell pkg-config fuse --libs)
 
-run_fuse: build_fuse
-       @./run_fuse_test.sh || echo "fuse_test: [FAIL]"
+include ../lib.mk
 
-clean:
-       $(RM) memfd_test fuse_test
index 5e35c9c50b72bbebcfb9393928bc10a03fb44479..9093d7ffe87f158e2f1f72d68e791e23afdcac40 100644 (file)
@@ -1,14 +1,11 @@
 # Makefile for mount selftests.
 CFLAGS = -Wall \
          -O2
-all: unprivileged-remount-test
 
-unprivileged-remount-test: unprivileged-remount-test.c
-       $(CC) $(CFLAGS) unprivileged-remount-test.c -o unprivileged-remount-test
+TEST_GEN_PROGS := unprivileged-remount-test
 
 include ../lib.mk
 
-TEST_PROGS := unprivileged-remount-test
 override RUN_TESTS := if [ -f /proc/self/uid_map ] ; \
                      then      \
                                ./unprivileged-remount-test ; \
@@ -17,5 +14,3 @@ override RUN_TESTS := if [ -f /proc/self/uid_map ] ; \
                      fi
 override EMIT_TESTS := echo "$(RUN_TESTS)"
 
-clean:
-       rm -f unprivileged-remount-test
index eebac29acbd91fc6d10b6258f006834834e4b243..79a664aeb8d76509a2f8e46aadf742571765a26a 100644 (file)
@@ -1,8 +1,6 @@
 CFLAGS += -O2
 LDLIBS = -lrt -lpthread -lpopt
-TEST_PROGS := mq_open_tests mq_perf_tests
-
-all: $(TEST_PROGS)
+TEST_GEN_PROGS := mq_open_tests mq_perf_tests
 
 include ../lib.mk
 
@@ -16,5 +14,3 @@ override define EMIT_TESTS
        echo "./mq_perf_tests || echo \"selftests: mq_perf_tests [FAIL]\""
 endef
 
-clean:
-       rm -f mq_open_tests mq_perf_tests
index e24e4c82542e076856c0b99463e9e8cbb1363211..fbfe5d0d5c2e05028e6af86d8db76d95e41c4fc5 100644 (file)
@@ -3,20 +3,13 @@
 CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
 CFLAGS += -I../../../../usr/include/
 
-NET_PROGS =  socket
-NET_PROGS += psock_fanout psock_tpacket
-NET_PROGS += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
-NET_PROGS += reuseport_dualstack
-
-all: $(NET_PROGS)
 reuseport_bpf_numa: LDFLAGS += -lnuma
-%: %.c
-       $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
 
 TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh
-TEST_FILES := $(NET_PROGS)
+TEST_GEN_FILES =  socket
+TEST_GEN_FILES += psock_fanout psock_tpacket
+TEST_GEN_FILES += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
+TEST_GEN_FILES += reuseport_dualstack
 
 include ../lib.mk
 
-clean:
-       $(RM) $(NET_PROGS)
index 2306054a901a4059102eecf7d47bbab6fe1de630..9ff7c7f80625c18b97edc0854193c6ab48f936a4 100644 (file)
@@ -1,12 +1,5 @@
-TEST_PROGS := owner pidns
+TEST_GEN_PROGS := owner pidns
 
 CFLAGS := -Wall -Werror
 
-all: owner pidns
-owner: owner.c
-pidns: pidns.c
-
-clean:
-       $(RM) owner pidns
-
 include ../lib.mk
index c2c4211ba58b83facb996ceab3ecac7f9077a31e..1c5d0575802e47113b49b4b0facfd7bff47a6620 100644 (file)
@@ -34,31 +34,35 @@ endif
 all: $(SUB_DIRS)
 
 $(SUB_DIRS):
-       $(MAKE) -k -C $@ all
+       BUILD_TARGET=$$OUTPUT/$@; mkdir -p $$BUILD_TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -k -C $@ all
 
 include ../lib.mk
 
 override define RUN_TESTS
        @for TARGET in $(SUB_DIRS); do \
-               $(MAKE) -C $$TARGET run_tests; \
+               BUILD_TARGET=$$OUTPUT/$$TARGET; \
+               $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
        done;
 endef
 
 override define INSTALL_RULE
        @for TARGET in $(SUB_DIRS); do \
-               $(MAKE) -C $$TARGET install; \
+               BUILD_TARGET=$$OUTPUT/$$TARGET; \
+               $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install;\
        done;
 endef
 
 override define EMIT_TESTS
        @for TARGET in $(SUB_DIRS); do \
-               $(MAKE) -s -C $$TARGET emit_tests; \
+               BUILD_TARGET=$$OUTPUT/$$TARGET; \
+               $(MAKE) OUTPUT=$$BUILD_TARGET -s -C $$TARGET emit_tests;\
        done;
 endef
 
 clean:
        @for TARGET in $(SUB_DIRS); do \
-               $(MAKE) -C $$TARGET clean; \
+               BUILD_TARGET=$$OUTPUT/$$TARGET; \
+               $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean; \
        done;
        rm -f tags
 
index ad6a4e49da916e0da10d68b0311efb2c7d2d95b8..16b22004e75f4526e3b527f410fa78a9ce4bcc44 100644 (file)
@@ -1,10 +1,5 @@
-TEST_PROGS := copy_unaligned copy_first_unaligned paste_unaligned paste_last_unaligned
-
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): ../harness.c ../utils.c copy_paste_unaligned_common.c
+TEST_GEN_PROGS := copy_unaligned copy_first_unaligned paste_unaligned paste_last_unaligned
 
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS)
+$(TEST_GEN_PROGS): ../harness.c ../utils.c copy_paste_unaligned_common.c
index 545077f98f72d72ea5fce37892812295c0ebe32b..fb96a89bd953bf471fce6c6766ab00e0664ddfbe 100644 (file)
@@ -1,16 +1,11 @@
-TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench null_syscall
+TEST_GEN_PROGS := gettimeofday context_switch mmap_bench futex_bench null_syscall
 
 CFLAGS += -O2
 
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): ../harness.c
-
-context_switch: ../utils.c
-context_switch: CFLAGS += -maltivec -mvsx -mabi=altivec
-context_switch: LDLIBS += -lpthread
-
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS) *.o
+$(TEST_GEN_PROGS): ../harness.c
+
+$(OUTPUT)/context_switch: ../utils.c
+$(OUTPUT)/context_switch: CFLAGS += -maltivec -mvsx -mabi=altivec
+$(OUTPUT)/context_switch: LDLIBS += -lpthread
index e164d14664661a72b43f4d11df41c08d5c5b54f2..e9351bb4285d086c67677c47193d9a3be8251b56 100644 (file)
@@ -1,10 +1,5 @@
-TEST_PROGS := cp_abort
-
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): ../harness.c ../utils.c
+TEST_GEN_PROGS := cp_abort
 
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS)
+$(TEST_GEN_PROGS): ../harness.c ../utils.c
index 384843ea0d40b66f06e96fde05a7a2b6abb53751..681ab19d0a8486b5dafe7b25e5148e4c4d4e0e0b 100644 (file)
@@ -7,19 +7,14 @@ CFLAGS += -maltivec
 # Use our CFLAGS for the implicit .S rule
 ASFLAGS = $(CFLAGS)
 
-TEST_PROGS := copyuser_64 copyuser_power7 memcpy_64 memcpy_power7
+TEST_GEN_PROGS := copyuser_64 copyuser_power7 memcpy_64 memcpy_power7
 EXTRA_SOURCES := validate.c ../harness.c
 
-all: $(TEST_PROGS)
-
-copyuser_64:     CPPFLAGS += -D COPY_LOOP=test___copy_tofrom_user_base
-copyuser_power7: CPPFLAGS += -D COPY_LOOP=test___copy_tofrom_user_power7
-memcpy_64:       CPPFLAGS += -D COPY_LOOP=test_memcpy
-memcpy_power7:   CPPFLAGS += -D COPY_LOOP=test_memcpy_power7
-
-$(TEST_PROGS): $(EXTRA_SOURCES)
-
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS) *.o
+$(OUTPUT)/copyuser_64:     CPPFLAGS += -D COPY_LOOP=test___copy_tofrom_user_base
+$(OUTPUT)/copyuser_power7: CPPFLAGS += -D COPY_LOOP=test___copy_tofrom_user_power7
+$(OUTPUT)/memcpy_64:       CPPFLAGS += -D COPY_LOOP=test_memcpy
+$(OUTPUT)/memcpy_power7:   CPPFLAGS += -D COPY_LOOP=test_memcpy_power7
+
+$(TEST_GEN_PROGS): $(EXTRA_SOURCES)
index 49327ee84e3a32fc26415afe04f8075e52a8872e..c5639deb8887ed49acd3e3238c0384a903b6fbf2 100644 (file)
@@ -1,14 +1,9 @@
-TEST_PROGS := dscr_default_test dscr_explicit_test dscr_user_test      \
+TEST_GEN_PROGS := dscr_default_test dscr_explicit_test dscr_user_test  \
              dscr_inherit_test dscr_inherit_exec_test dscr_sysfs_test  \
              dscr_sysfs_thread_test
 
-dscr_default_test: LDLIBS += -lpthread
-
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): ../harness.c
-
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS) *.o
+$(OUTPUT)/dscr_default_test: LDLIBS += -lpthread
+
+$(TEST_GEN_PROGS): ../harness.c
index a505b66d408a67d4392a7efda885b436d0456587..fa8bae920c911f81f97c26f9f6e72157f7595379 100644 (file)
@@ -1,22 +1,17 @@
-TEST_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal vsx_preempt
+TEST_GEN_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal vsx_preempt
 
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): ../harness.c
-$(TEST_PROGS): CFLAGS += -O2 -g -pthread -m64 -maltivec
-
-fpu_syscall: fpu_asm.S
-fpu_preempt: fpu_asm.S
-fpu_signal:  fpu_asm.S
+include ../../lib.mk
 
-vmx_syscall: vmx_asm.S
-vmx_preempt: vmx_asm.S
-vmx_signal: vmx_asm.S
+$(TEST_GEN_PROGS): ../harness.c
+$(TEST_GEN_PROGS): CFLAGS += -O2 -g -pthread -m64 -maltivec
 
-vsx_preempt: CFLAGS += -mvsx
-vsx_preempt: vsx_asm.S
+$(OUTPUT)/fpu_syscall: fpu_asm.S
+$(OUTPUT)/fpu_preempt: fpu_asm.S
+$(OUTPUT)/fpu_signal:  fpu_asm.S
 
-include ../../lib.mk
+$(OUTPUT)/vmx_syscall: vmx_asm.S
+$(OUTPUT)/vmx_preempt: vmx_asm.S
+$(OUTPUT)/vmx_signal: vmx_asm.S
 
-clean:
-       rm -f $(TEST_PROGS) *.o
+$(OUTPUT)/vsx_preempt: CFLAGS += -mvsx
+$(OUTPUT)/vsx_preempt: vsx_asm.S
index 3bdb96eae55869e04a988f0d6cc30ef9d01fc6ce..1cffe54dccfb8a31f4b704756ce0e82b4393e38c 100644 (file)
@@ -1,19 +1,15 @@
 noarg:
        $(MAKE) -C ../
 
-TEST_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao
-TEST_FILES := tempfile
+TEST_GEN_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao
+TEST_GEN_FILES := tempfile
 
-all: $(TEST_PROGS) $(TEST_FILES)
-
-$(TEST_PROGS): ../harness.c
+include ../../lib.mk
 
-prot_sao: ../utils.c
+$(TEST_GEN_PROGS): ../harness.c
 
-include ../../lib.mk
+$(OUTPUT)/prot_sao: ../utils.c
 
-tempfile:
-       dd if=/dev/zero of=tempfile bs=64k count=1
+$(OUTPUT)/tempfile:
+       dd if=/dev/zero of=$@ bs=64k count=1
 
-clean:
-       rm -f $(TEST_PROGS) tempfile
index ac41a7177f2e2cd659ca89c9a56c8473a502dde3..e4e55d1d3e0fae00a3c91d39ba35242e57f06b22 100644 (file)
@@ -1,44 +1,44 @@
 noarg:
        $(MAKE) -C ../
 
-TEST_PROGS := count_instructions l3_bank_test per_event_excludes
+TEST_GEN_PROGS := count_instructions l3_bank_test per_event_excludes
 EXTRA_SOURCES := ../harness.c event.c lib.c ../utils.c
 
-all: $(TEST_PROGS) ebb
+include ../../lib.mk
+
+all: $(TEST_GEN_PROGS) ebb
 
-$(TEST_PROGS): $(EXTRA_SOURCES)
+$(TEST_GEN_PROGS): $(EXTRA_SOURCES)
 
 # loop.S can only be built 64-bit
-count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES)
+$(OUTPUT)/count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES)
        $(CC) $(CFLAGS) -m64 -o $@ $^
 
-per_event_excludes: ../utils.c
-
-include ../../lib.mk
+$(OUTPUT)/per_event_excludes: ../utils.c
 
 DEFAULT_RUN_TESTS := $(RUN_TESTS)
 override define RUN_TESTS
        $(DEFAULT_RUN_TESTS)
-       $(MAKE) -C ebb run_tests
+       TARGET=ebb; BUILD_TARGET=$$OUTPUT/$$TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests
 endef
 
 DEFAULT_EMIT_TESTS := $(EMIT_TESTS)
 override define EMIT_TESTS
        $(DEFAULT_EMIT_TESTS)
-       $(MAKE) -s -C ebb emit_tests
+       TARGET=ebb; BUILD_TARGET=$$OUTPUT/$$TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -s -C $$TARGET emit_tests
 endef
 
 DEFAULT_INSTALL_RULE := $(INSTALL_RULE)
 override define INSTALL_RULE
        $(DEFAULT_INSTALL_RULE)
-       $(MAKE) -C ebb install
+       TARGET=ebb; BUILD_TARGET=$$OUTPUT/$$TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install
 endef
 
 clean:
-       rm -f $(TEST_PROGS) loop.o
-       $(MAKE) -C ebb clean
+       $(RM) $(TEST_GEN_PROGS) $(OUTPUT)/loop.o
+       TARGET=ebb; BUILD_TARGET=$$OUTPUT/$$TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean
 
 ebb:
-       $(MAKE) -k -C $@ all
+       TARGET=$@; BUILD_TARGET=$$OUTPUT/$$TARGET; mkdir -p $$BUILD_TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -k -C $$TARGET all
 
 .PHONY: all run_tests clean ebb
index 8d2279c4bb4b6a81cb5713f6ba3bf92b72f2e3e7..6001fb0a377a70f9ee1a57acd19424ec44bda6ae 100644 (file)
@@ -4,7 +4,7 @@ noarg:
 # The EBB handler is 64-bit code and everything links against it
 CFLAGS += -m64
 
-TEST_PROGS := reg_access_test event_attributes_test cycles_test        \
+TEST_GEN_PROGS := reg_access_test event_attributes_test cycles_test    \
         cycles_with_freeze_test pmc56_overflow_test            \
         ebb_vs_cpu_event_test cpu_event_vs_ebb_test            \
         cpu_event_pinned_vs_ebb_test task_event_vs_ebb_test    \
@@ -16,16 +16,11 @@ TEST_PROGS := reg_access_test event_attributes_test cycles_test     \
         lost_exception_test no_handler_test                    \
         cycles_with_mmcr2_test
 
-all: $(TEST_PROGS)
+include ../../../lib.mk
 
-$(TEST_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c \
+$(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c \
               ebb.c ebb_handler.S trace.c busy_loop.S
 
-instruction_count_test: ../loop.S
-
-lost_exception_test: ../lib.c
-
-include ../../../lib.mk
+$(OUTPUT)/instruction_count_test: ../loop.S
 
-clean:
-       rm -f $(TEST_PROGS)
+$(OUTPUT)/lost_exception_test: ../lib.c
index b68c6221d3d1bdad82a50356fa5c73083611d948..175366db7be8bc1261194ac80d009cd33e0c9c59 100644 (file)
@@ -1,12 +1,7 @@
 CFLAGS += -I$(CURDIR)
 
-TEST_PROGS := load_unaligned_zeropad
-
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): ../harness.c
+TEST_GEN_PROGS := load_unaligned_zeropad
 
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS) *.o
+$(TEST_GEN_PROGS): ../harness.c
index 2a728f4d2873de636379c277feae38f004c60934..557b9379f3bb9c83ebc1326c27a77e21f855119e 100644 (file)
@@ -2,14 +2,9 @@
 CFLAGS += -m64
 CFLAGS += -I$(CURDIR)
 
-TEST_PROGS := memcmp
+TEST_GEN_PROGS := memcmp
 EXTRA_SOURCES := memcmp_64.S ../harness.c
 
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): $(EXTRA_SOURCES)
-
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS) *.o
+$(TEST_GEN_PROGS): $(EXTRA_SOURCES)
index e21d10674e54135637b540ae8b0457e0ea3075cd..b92c2a132c4f5d038465ef190584da31de3a79a9 100644 (file)
@@ -1,18 +1,15 @@
-TEST_PROGS := switch_endian_test
+TEST_GEN_PROGS := switch_endian_test
 
 ASFLAGS += -O2 -Wall -g -nostdlib -m64
 
-all: $(TEST_PROGS)
+EXTRA_CLEAN = $(OUTPUT)/*.o $(OUTPUT)/check-reversed.S
 
-switch_endian_test: check-reversed.S
+include ../../lib.mk
+
+$(OUTPUT)/switch_endian_test: $(OUTPUT)/check-reversed.S
 
-check-reversed.o: check.o
+$(OUTPUT)/check-reversed.o: $(OUTPUT)/check.o
        $(CROSS_COMPILE)objcopy -j .text --reverse-bytes=4 -O binary $< $@
 
-check-reversed.S: check-reversed.o
+$(OUTPUT)/check-reversed.S: $(OUTPUT)/check-reversed.o
        hexdump -v -e '/1 ".byte 0x%02X\n"' $< > $@
-
-include ../../lib.mk
-
-clean:
-       rm -f $(TEST_PROGS) *.o check-reversed.S
index b35c7945bec550210c36269308352e7f25d0c2e4..da22ca7c38c185a5bb4df90a81fa71a9fbccc6c1 100644 (file)
@@ -1,12 +1,7 @@
-TEST_PROGS := ipc_unmuxed
+TEST_GEN_PROGS := ipc_unmuxed
 
 CFLAGS += -I../../../../../usr/include
 
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): ../harness.c
-
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS) *.o
+$(TEST_GEN_PROGS): ../harness.c
index c6c53c82fdd64fddb16aef156870e0f1656a4f81..5576ee6a51f21bb32a0ede4337d9da049e37fd42 100644 (file)
@@ -1,23 +1,19 @@
 SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu \
        tm-signal-context-chk-vmx tm-signal-context-chk-vsx
 
-TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
+TEST_GEN_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
        tm-vmxcopy tm-fork tm-tar tm-tmspr $(SIGNAL_CONTEXT_CHK_TESTS)
 
-all: $(TEST_PROGS)
+include ../../lib.mk
 
-$(TEST_PROGS): ../harness.c ../utils.c
+$(TEST_GEN_PROGS): ../harness.c ../utils.c
 
 CFLAGS += -mhtm
 
-tm-syscall: tm-syscall-asm.S
-tm-syscall: CFLAGS += -I../../../../../usr/include
-tm-tmspr: CFLAGS += -pthread
+$(OUTPUT)/tm-syscall: tm-syscall-asm.S
+$(OUTPUT)/tm-syscall: CFLAGS += -I../../../../../usr/include
+$(OUTPUT)/tm-tmspr: CFLAGS += -pthread
 
+SIGNAL_CONTEXT_CHK_TESTS := $(patsubst %,$(OUTPUT)/%,$(SIGNAL_CONTEXT_CHK_TESTS))
 $(SIGNAL_CONTEXT_CHK_TESTS): tm-signal.S
 $(SIGNAL_CONTEXT_CHK_TESTS): CFLAGS += -mhtm -m64 -mvsx
-
-include ../../lib.mk
-
-clean:
-       rm -f $(TEST_PROGS) *.o
index a485f2e286ae22cae0706c7cd0fc735d4c7206e3..f8ced26748f84408d902cc4ce58012874c545a58 100644 (file)
@@ -1,12 +1,8 @@
-TEST_PROGS := test-vphn
+TEST_GEN_PROGS := test-vphn
 
 CFLAGS += -m64
 
-all: $(TEST_PROGS)
-
-$(TEST_PROGS): ../harness.c
-
 include ../../lib.mk
 
-clean:
-       rm -f $(TEST_PROGS)
+$(TEST_GEN_PROGS): ../harness.c
+
index bd7abe24ea081442850c88d1b559fe9926a2580c..c5f2440ba1f707fe3c447cedcd00756c1c735496 100644 (file)
@@ -5,11 +5,9 @@ all:
 
 TEST_PROGS := pstore_tests pstore_post_reboot_tests
 TEST_FILES := common_tests pstore_crash_test
+EXTRA_CLEAN := logs/* *uuid
 
 include ../lib.mk
 
 run_crash:
        @sh pstore_crash_test || { echo "pstore_crash_test: [FAIL]"; exit 1; }
-
-clean:
-       rm -rf logs/* *uuid
index 453927fea90cae7b65005fb661bf7b8254686d32..8a2bc5562179b4c2c489976b1861aac6968c0fee 100644 (file)
@@ -1,11 +1,5 @@
 CFLAGS += -iquote../../../../include/uapi -Wall
-peeksiginfo: peeksiginfo.c
 
-all: peeksiginfo
-
-clean:
-       rm -f peeksiginfo
-
-TEST_PROGS := peeksiginfo
+TEST_GEN_PROGS := peeksiginfo
 
 include ../lib.mk
index 8401e87e34e17e8103a6d02925c57e486f017f38..5fa6fd2246b18a45290efef20789a4948d9425d9 100644 (file)
@@ -1,10 +1,6 @@
-TEST_PROGS := seccomp_bpf
+TEST_GEN_PROGS := seccomp_bpf
 CFLAGS += -Wl,-no-as-needed -Wall
 LDFLAGS += -lpthread
 
-all: $(TEST_PROGS)
-
 include ../lib.mk
 
-clean:
-       $(RM) $(TEST_PROGS)
index 56af56eda6fa50fc259716dd397de5cb15cfc07c..f68fbf80d8bea52a94ac38b3c80b185ad138dc1c 100644 (file)
@@ -1,8 +1,5 @@
 CFLAGS = -Wall
-BINARIES = sas
-all: $(BINARIES)
+TEST_GEN_PROGS = sas
 
 include ../lib.mk
 
-clean:
-       rm -rf $(BINARIES)
index bbd0b5398b613c08ee77eb4fbf9740383d874c0d..4685b3e421fcd48f261d32a54edc6fa1658abc70 100644 (file)
@@ -1,11 +1,5 @@
-all: get_size
+CFLAGS := -static -ffreestanding -nostartfiles -s
 
-get_size: get_size.c
-       $(CC) -static -ffreestanding -nostartfiles -s $< -o $@
-
-TEST_PROGS := get_size
+TEST_GEN_PROGS := get_size
 
 include ../lib.mk
-
-clean:
-       $(RM) get_size
index 1d5556869137929564c490473c35386ca3be3692..b90e50c36f9f99a49c414fc351cf0d6f3f1ebf16 100644 (file)
@@ -1,20 +1,16 @@
-CC = $(CROSS_COMPILE)gcc
 BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
 
 # these are all "safe" tests that don't modify
 # system time or require escalated privledges
-TEST_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \
+TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \
             inconsistency-check raw_skew threadtest rtctest
 
-TEST_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \
+TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \
                      skew_consistency clocksource-switch leap-a-day \
                      leapcrash set-tai set-2038 set-tz
 
-bins = $(TEST_PROGS) $(TEST_PROGS_EXTENDED)
-
-all: ${bins}
 
 include ../lib.mk
 
@@ -34,5 +30,3 @@ run_destructive_tests: run_tests
        ./set-tai
        ./set-2038
 
-clean:
-       rm -f ${bins}
index 900dfaf810510d6578a01d287b010c6f61b0b1c4..4cff7e7ddcc47b80ef30a06a779ea45dae5a5f3e 100644 (file)
@@ -1,41 +1,33 @@
 # Makefile for vm selftests
 
 CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS)
-BINARIES = compaction_test
-BINARIES += hugepage-mmap
-BINARIES += hugepage-shm
-BINARIES += map_hugetlb
-BINARIES += mlock2-tests
-BINARIES += on-fault-limit
-BINARIES += thuge-gen
-BINARIES += transhuge-stress
-BINARIES += userfaultfd
-BINARIES += userfaultfd_hugetlb
-BINARIES += userfaultfd_shmem
-BINARIES += mlock-random-test
-
-all: $(BINARIES)
-%: %.c
-       $(CC) $(CFLAGS) -o $@ $^ -lrt
-userfaultfd: userfaultfd.c ../../../../usr/include/linux/kernel.h
-       $(CC) $(CFLAGS) -O2 -o $@ $< -lpthread
-
-userfaultfd_hugetlb: userfaultfd.c ../../../../usr/include/linux/kernel.h
+LDLIBS = -lrt
+TEST_GEN_FILES = compaction_test
+TEST_GEN_FILES += hugepage-mmap
+TEST_GEN_FILES += hugepage-shm
+TEST_GEN_FILES += map_hugetlb
+TEST_GEN_FILES += mlock2-tests
+TEST_GEN_FILES += on-fault-limit
+TEST_GEN_FILES += thuge-gen
+TEST_GEN_FILES += transhuge-stress
+TEST_GEN_FILES += userfaultfd
+TEST_GEN_FILES += userfaultfd_hugetlb
+TEST_GEN_FILES += userfaultfd_shmem
+TEST_GEN_FILES += mlock-random-test
+
+TEST_PROGS := run_vmtests
+
+include ../lib.mk
+
+$(OUTPUT)/userfaultfd: LDLIBS += -lpthread ../../../../usr/include/linux/kernel.h
+
+$(OUTPUT)/userfaultfd_hugetlb: userfaultfd.c ../../../../usr/include/linux/kernel.h
        $(CC) $(CFLAGS) -DHUGETLB_TEST -O2 -o $@ $< -lpthread
 
-userfaultfd_shmem: userfaultfd.c ../../../../usr/include/linux/kernel.h
+$(OUTPUT)/userfaultfd_shmem: userfaultfd.c  ../../../../usr/include/linux/kernel.h
        $(CC) $(CFLAGS) -DSHMEM_TEST -O2 -o $@ $< -lpthread
 
-mlock-random-test: mlock-random-test.c
-       $(CC) $(CFLAGS) -o $@ $< -lcap
+$(OUTPUT)/mlock-random-test: LDLIBS += -lcap
 
 ../../../../usr/include/linux/kernel.h:
        make -C ../../../.. headers_install
-
-TEST_PROGS := run_vmtests
-TEST_FILES := $(BINARIES)
-
-include ../lib.mk
-
-clean:
-       $(RM) $(BINARIES)
index 83d8b1c6cb0e54d03b9f59403e7b72acee089de8..3a5ebae5303e26a0cff0f3a906027ea35c638fbf 100644 (file)
@@ -17,6 +17,9 @@ TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
 BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
 
+BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
+BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
+
 CFLAGS := -O2 -g -std=gnu99 -pthread -Wall
 
 UNAME_M := $(shell uname -m)
@@ -40,10 +43,10 @@ all_64: $(BINARIES_64)
 clean:
        $(RM) $(BINARIES_32) $(BINARIES_64)
 
-$(TARGETS_C_32BIT_ALL:%=%_32): %_32: %.c
+$(BINARIES_32): $(OUTPUT)/%_32: %.c
        $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
 
-$(TARGETS_C_64BIT_ALL:%=%_64): %_64: %.c
+$(BINARIES_64): $(OUTPUT)/%_64: %.c
        $(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
 
 # x86_64 users should be encouraged to install 32-bit libraries
@@ -65,12 +68,12 @@ warn_32bit_failure:
 endif
 
 # Some tests have additional dependencies.
-sysret_ss_attrs_64: thunks.S
-ptrace_syscall_32: raw_syscall_helper_32.S
-test_syscall_vdso_32: thunks_32.S
+$(OUTPUT)/sysret_ss_attrs_64: thunks.S
+$(OUTPUT)/ptrace_syscall_32: raw_syscall_helper_32.S
+$(OUTPUT)/test_syscall_vdso_32: thunks_32.S
 
 # check_initial_reg_state is special: it needs a custom entry, and it
 # needs to be static so that its interpreter doesn't destroy its initial
 # state.
-check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static
-check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static
+$(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static
+$(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static
index df9e0a0cdf294e1e334c6558c9c4f87a38387e1d..3237bc010e1c32b6cf0742a901a5d28b74391c5b 100644 (file)
@@ -192,7 +192,7 @@ void lots_o_noops_around_write(int *write_to_me)
 #define SYS_pkey_alloc  381
 #define SYS_pkey_free   382
 #define REG_IP_IDX REG_EIP
-#define si_pkey_offset 0x18
+#define si_pkey_offset 0x14
 #else
 #define SYS_mprotect_key 329
 #define SYS_pkey_alloc  330
@@ -462,7 +462,7 @@ void pkey_disable_set(int pkey, int flags)
        unsigned long syscall_flags = 0;
        int ret;
        int pkey_rights;
-       u32 orig_pkru;
+       u32 orig_pkru = rdpkru();
 
        dprintf1("START->%s(%d, 0x%x)\n", __func__,
                pkey, flags);
@@ -812,8 +812,6 @@ void setup_hugetlbfs(void)
 {
        int err;
        int fd;
-       int validated_nr_pages;
-       int i;
        char buf[] = "123";
 
        if (geteuid() != 0) {
@@ -1116,11 +1114,6 @@ void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey)
                err = sys_pkey_free(i);
                pkey_assert(err);
 
-               /* not enforced when pkey_get() is not a syscall
-               err = pkey_get(i, 0);
-               pkey_assert(err < 0);
-               */
-
                err = sys_pkey_free(i);
                pkey_assert(err);
 
@@ -1133,14 +1126,8 @@ void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey)
 void test_pkey_syscalls_bad_args(int *ptr, u16 pkey)
 {
        int err;
-       int bad_flag = (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE) + 1;
        int bad_pkey = NR_PKEYS+99;
 
-       /* not enforced when pkey_get() is not a syscall
-       err = pkey_get(bad_pkey, bad_flag);
-       pkey_assert(err < 0);
-       */
-
        /* pass a known-invalid pkey in: */
        err = sys_mprotect_pkey(ptr, PAGE_SIZE, PROT_READ, bad_pkey);
        pkey_assert(err);
@@ -1149,8 +1136,6 @@ void test_pkey_syscalls_bad_args(int *ptr, u16 pkey)
 /* Assumes that all pkeys other than 'pkey' are unallocated */
 void test_pkey_alloc_exhaust(int *ptr, u16 pkey)
 {
-       unsigned long flags;
-       unsigned long init_val;
        int err;
        int allocated_pkeys[NR_PKEYS] = {0};
        int nr_allocated_pkeys = 0;
index 29d80346e3eb5a14108e3e3f514182806ab584e1..c3a87e5f9d36482c4a606afe9c6e82bfff8fe90c 100644 (file)
@@ -2,8 +2,7 @@ all:
 
 TEST_PROGS := zram.sh
 TEST_FILES := zram01.sh zram02.sh zram_lib.sh
+EXTRA_CLEAN := err.log
 
 include ../lib.mk
 
-clean:
-       $(RM) err.log