xref: /linux/tools/testing/selftests/cpufreq/special-tests.sh (revision 67f8bc848ee31831336bd478e57d2f993551902e)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Special test cases reported by people
5
6# Testcase 1: Reported here: http://marc.info/?l=linux-pm&m=140618592709858&w=2
7
8# protect against multiple inclusion
9if [ $FILE_SPECIAL ]; then
10	return 0
11else
12	FILE_SPECIAL=DONE
13fi
14
15source cpu.sh
16source cpufreq.sh
17source governor.sh
18
19# Test 1
20# $1: policy
21__simple_lockdep()
22{
23	# switch to ondemand
24	__switch_governor $1 "ondemand"
25
26	# cat ondemand files
27	local ondir=$(find_gov_directory $1 "ondemand")
28	if [ -z $ondir ]; then
29		printf "${FUNCNAME[0]}Ondemand directory not created, quit"
30		return
31	fi
32
33	cat $ondir/*
34
35	# switch to conservative
36	__switch_governor $1 "conservative"
37}
38
39simple_lockdep()
40{
41	printf "** Test: Running ${FUNCNAME[0]} **\n"
42
43	save_all_governors
44	for_each_policy __simple_lockdep
45	restore_all_governors
46}
47
48# Test 2
49# $1: policy
50__concurrent_lockdep()
51{
52	for i in `seq 0 100`; do
53		__simple_lockdep $1
54	done
55}
56
57concurrent_lockdep()
58{
59	printf "** Test: Running ${FUNCNAME[0]} **\n"
60
61	save_all_governors
62	for_each_policy_concurrent __concurrent_lockdep
63	wait
64	restore_all_governors
65}
66
67# Test 3
68quick_shuffle()
69{
70	# this is called concurrently from governor_race
71	for I in `seq 1000`
72	do
73		echo ondemand | tee $CPUFREQROOT/policy*/scaling_governor &
74		echo userspace | tee $CPUFREQROOT/policy*/scaling_governor &
75	done
76	wait
77}
78
79governor_race()
80{
81	printf "** Test: Running ${FUNCNAME[0]} **\n"
82
83	save_all_governors
84
85	# run 8 concurrent instances
86	for I in `seq 8`
87	do
88		quick_shuffle &
89	done
90	wait
91
92	restore_all_governors
93}
94
95# Test 4
96# $1: cpu
97hotplug_with_updates_cpu()
98{
99	local filepath="$CPUROOT/$1/cpufreq"
100
101	# switch to ondemand
102	__switch_governor_for_cpu $1 "ondemand"
103
104	for i in `seq 1 5000`
105	do
106		reboot_cpu $1
107	done &
108
109	local freqs=$(cat $filepath/scaling_available_frequencies)
110	local oldfreq=$(cat $filepath/scaling_min_freq)
111
112	for j in `seq 1 5000`
113	do
114		# Set all frequencies one-by-one
115		for freq in $freqs; do
116			echo $freq > $filepath/scaling_min_freq
117		done
118	done
119
120	# restore old freq
121	echo $oldfreq > $filepath/scaling_min_freq
122}
123
124hotplug_with_updates()
125{
126	save_all_governors
127	for_each_non_boot_cpu hotplug_with_updates_cpu
128	wait
129	restore_all_governors
130}
131