]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
selftest: cpufreq: Add special tests
authorViresh Kumar <viresh.kumar@linaro.org>
Fri, 13 Jan 2017 06:36:48 +0000 (12:06 +0530)
committerShuah Khan <shuahkh@osg.samsung.com>
Thu, 19 Jan 2017 17:32:27 +0000 (10:32 -0700)
This patch adds support for special tests which were reported on the PM
list over the years, which helped catching core bugs by several
developers.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
tools/testing/selftests/cpufreq/Makefile
tools/testing/selftests/cpufreq/governor.sh
tools/testing/selftests/cpufreq/main.sh
tools/testing/selftests/cpufreq/special-tests.sh [new file with mode: 0755]

index 80c8727dcec10b59f4867749b29e4972ebd729f8..3955cd96f3a25c1b52acea7510996679c4b36df6 100644 (file)
@@ -1,7 +1,7 @@
 all:
 
 TEST_PROGS := main.sh
-TEST_FILES := cpu.sh cpufreq.sh governor.sh module.sh
+TEST_FILES := cpu.sh cpufreq.sh governor.sh module.sh special-tests.sh
 
 include ../lib.mk
 
index 2e42432892ab9b8a2c140e5e8e0badc8e6757409..def645103555f6b77ccc8a48e2bbc81efc9675d0 100755 (executable)
@@ -71,6 +71,13 @@ __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
index 2515867ac9de42fa737a927aae71939a8b50f9ca..01bac76ac0ec71e8c9aa1371e45ee3736ecc1d24 100755 (executable)
@@ -4,6 +4,7 @@ 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
@@ -19,7 +20,11 @@ helpme()
        [-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>]
+            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"
@@ -67,7 +72,7 @@ parse_arguments()
                                helpme
                                ;;
 
-                       t) # --func_type (Function to perform: basic, suspend, hibernate, modtest (default: basic))
+                       t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
                                FUNC=$OPTARG
                                ;;
 
@@ -136,6 +141,22 @@ do_test()
                fi
                ;;
 
+               "sptest1")
+               simple_lockdep
+               ;;
+
+               "sptest2")
+               concurrent_lockdep
+               ;;
+
+               "sptest3")
+               governor_race
+               ;;
+
+               "sptest4")
+               hotplug_with_updates
+               ;;
+
                *)
                echo "Invalid [-f] function type"
                helpme
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
+}