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