xref: /linux/tools/testing/selftests/cpufreq/main.sh (revision b03eaf8dbac5534590ec52612f789d8fb292af9c)
1e66d5b67SViresh Kumar#!/bin/bash
2e66d5b67SViresh Kumar
3e66d5b67SViresh Kumarsource cpu.sh
4e66d5b67SViresh Kumarsource cpufreq.sh
5e66d5b67SViresh Kumarsource governor.sh
6e66d5b67SViresh Kumar
7e66d5b67SViresh KumarFUNC=basic	# do basic tests by default
8e66d5b67SViresh KumarOUTFILE=cpufreq_selftest
9e66d5b67SViresh KumarSYSFS=
10e66d5b67SViresh KumarCPUROOT=
11e66d5b67SViresh KumarCPUFREQROOT=
12e66d5b67SViresh Kumar
13e66d5b67SViresh Kumarhelpme()
14e66d5b67SViresh Kumar{
15e66d5b67SViresh Kumar	printf "Usage: $0 [-h] [-to args]
16e66d5b67SViresh Kumar	[-h <help>]
17e66d5b67SViresh Kumar	[-o <output-file-for-dump>]
18*b03eaf8dSViresh Kumar	[-t <basic: Basic cpufreq testing
19*b03eaf8dSViresh Kumar	     suspend: suspend/resume,
20*b03eaf8dSViresh Kumar	     hibernate: hibernate/resume>]
21e66d5b67SViresh Kumar	\n"
22e66d5b67SViresh Kumar	exit 2
23e66d5b67SViresh Kumar}
24e66d5b67SViresh Kumar
25e66d5b67SViresh Kumarprerequisite()
26e66d5b67SViresh Kumar{
27e66d5b67SViresh Kumar	msg="skip all tests:"
28e66d5b67SViresh Kumar
29e66d5b67SViresh Kumar	if [ $UID != 0 ]; then
30e66d5b67SViresh Kumar		echo $msg must be run as root >&2
31e66d5b67SViresh Kumar		exit 2
32e66d5b67SViresh Kumar	fi
33e66d5b67SViresh Kumar
34e66d5b67SViresh Kumar	taskset -p 01 $$
35e66d5b67SViresh Kumar
36e66d5b67SViresh Kumar	SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`
37e66d5b67SViresh Kumar
38e66d5b67SViresh Kumar	if [ ! -d "$SYSFS" ]; then
39e66d5b67SViresh Kumar		echo $msg sysfs is not mounted >&2
40e66d5b67SViresh Kumar		exit 2
41e66d5b67SViresh Kumar	fi
42e66d5b67SViresh Kumar
43e66d5b67SViresh Kumar	CPUROOT=$SYSFS/devices/system/cpu
44e66d5b67SViresh Kumar	CPUFREQROOT="$CPUROOT/cpufreq"
45e66d5b67SViresh Kumar
46e66d5b67SViresh Kumar	if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then
47e66d5b67SViresh Kumar		echo $msg cpus not available in sysfs >&2
48e66d5b67SViresh Kumar		exit 2
49e66d5b67SViresh Kumar	fi
50e66d5b67SViresh Kumar
51e66d5b67SViresh Kumar	if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then
52e66d5b67SViresh Kumar		echo $msg cpufreq directory not available in sysfs >&2
53e66d5b67SViresh Kumar		exit 2
54e66d5b67SViresh Kumar	fi
55e66d5b67SViresh Kumar}
56e66d5b67SViresh Kumar
57e66d5b67SViresh Kumarparse_arguments()
58e66d5b67SViresh Kumar{
59e66d5b67SViresh Kumar	while getopts ht:o: arg
60e66d5b67SViresh Kumar	do
61e66d5b67SViresh Kumar		case $arg in
62e66d5b67SViresh Kumar			h) # --help
63e66d5b67SViresh Kumar				helpme
64e66d5b67SViresh Kumar				;;
65e66d5b67SViresh Kumar
66*b03eaf8dSViresh Kumar			t) # --func_type (Function to perform: basic, suspend, hibernate (default: basic))
67e66d5b67SViresh Kumar				FUNC=$OPTARG
68e66d5b67SViresh Kumar				;;
69e66d5b67SViresh Kumar
70e66d5b67SViresh Kumar			o) # --output-file (Output file to store dumps)
71e66d5b67SViresh Kumar				OUTFILE=$OPTARG
72e66d5b67SViresh Kumar				;;
73e66d5b67SViresh Kumar
74e66d5b67SViresh Kumar			\?)
75e66d5b67SViresh Kumar				helpme
76e66d5b67SViresh Kumar				;;
77e66d5b67SViresh Kumar		esac
78e66d5b67SViresh Kumar	done
79e66d5b67SViresh Kumar}
80e66d5b67SViresh Kumar
81e66d5b67SViresh Kumardo_test()
82e66d5b67SViresh Kumar{
83e66d5b67SViresh Kumar	# Check if CPUs are managed by cpufreq or not
84e66d5b67SViresh Kumar	count=$(count_cpufreq_managed_cpus)
85e66d5b67SViresh Kumar
86e66d5b67SViresh Kumar	if [ $count = 0 ]; then
87e66d5b67SViresh Kumar		echo "No cpu is managed by cpufreq core, exiting"
88e66d5b67SViresh Kumar		exit 2;
89e66d5b67SViresh Kumar	fi
90e66d5b67SViresh Kumar
91e66d5b67SViresh Kumar	case "$FUNC" in
92e66d5b67SViresh Kumar		"basic")
93e66d5b67SViresh Kumar		cpufreq_basic_tests
94e66d5b67SViresh Kumar		;;
95e66d5b67SViresh Kumar
96*b03eaf8dSViresh Kumar		"suspend")
97*b03eaf8dSViresh Kumar		do_suspend "suspend" 1
98*b03eaf8dSViresh Kumar		;;
99*b03eaf8dSViresh Kumar
100*b03eaf8dSViresh Kumar		"hibernate")
101*b03eaf8dSViresh Kumar		do_suspend "hibernate" 1
102*b03eaf8dSViresh Kumar		;;
103*b03eaf8dSViresh Kumar
104e66d5b67SViresh Kumar		*)
105e66d5b67SViresh Kumar		echo "Invalid [-f] function type"
106e66d5b67SViresh Kumar		helpme
107e66d5b67SViresh Kumar		;;
108e66d5b67SViresh Kumar	esac
109e66d5b67SViresh Kumar}
110e66d5b67SViresh Kumar
111e66d5b67SViresh Kumar# clear dumps
112e66d5b67SViresh Kumar# $1: file name
113e66d5b67SViresh Kumarclear_dumps()
114e66d5b67SViresh Kumar{
115e66d5b67SViresh Kumar	echo "" > $1.txt
116e66d5b67SViresh Kumar	echo "" > $1.dmesg_cpufreq.txt
117e66d5b67SViresh Kumar	echo "" > $1.dmesg_full.txt
118e66d5b67SViresh Kumar}
119e66d5b67SViresh Kumar
120e66d5b67SViresh Kumar# $1: output file name
121e66d5b67SViresh Kumardmesg_dumps()
122e66d5b67SViresh Kumar{
123e66d5b67SViresh Kumar	dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt
124e66d5b67SViresh Kumar
125e66d5b67SViresh Kumar	# We may need the full logs as well
126e66d5b67SViresh Kumar	dmesg >> $1.dmesg_full.txt
127e66d5b67SViresh Kumar}
128e66d5b67SViresh Kumar
129e66d5b67SViresh Kumar# Parse arguments
130e66d5b67SViresh Kumarparse_arguments $@
131e66d5b67SViresh Kumar
132e66d5b67SViresh Kumar# Make sure all requirements are met
133e66d5b67SViresh Kumarprerequisite
134e66d5b67SViresh Kumar
135e66d5b67SViresh Kumar# Run requested functions
136e66d5b67SViresh Kumarclear_dumps $OUTFILE
137e66d5b67SViresh Kumardo_test >> $OUTFILE.txt
138e66d5b67SViresh Kumardmesg_dumps $OUTFILE
139