brintos

brintos / linux-shallow public Read only

0
0
Text · 4.1 KiB · f12ff74 Raw
219 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4source cpu.sh5source cpufreq.sh6source governor.sh7source module.sh8source special-tests.sh9 10DIR="$(dirname $(readlink -f "$0"))"11source "${DIR}"/../kselftest/ktap_helpers.sh12 13FUNC=basic	# do basic tests by default14OUTFILE=cpufreq_selftest15SYSFS=16CPUROOT=17CPUFREQROOT=18 19helpme()20{21	printf "Usage: $0 [-h] [-todg args]22	[-h <help>]23	[-o <output-file-for-dump>]24	[-t <basic: Basic cpufreq testing25	     suspend: suspend/resume,26	     hibernate: hibernate/resume,27	     suspend_rtc: suspend/resume back using the RTC wakeup alarm,28	     hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,29	     modtest: test driver or governor modules. Only to be used with -d or -g options,30	     sptest1: Simple governor switch to produce lockdep.31	     sptest2: Concurrent governor switch to produce lockdep.32	     sptest3: Governor races, shuffle between governors quickly.33	     sptest4: CPU hotplugs with updates to cpufreq files.>]34	[-d <driver's module name: only with \"-t modtest>\"]35	[-g <governor's module name: only with \"-t modtest>\"]36	\n"37	exit "${KSFT_FAIL}"38}39 40prerequisite()41{42	msg="skip all tests:"43 44	if [ $UID != 0 ]; then45		ktap_skip_all "$msg must be run as root"46		exit "${KSFT_SKIP}"47	fi48 49	taskset -p 01 $$50 51	SYSFS=`mount -t sysfs | head -1 | awk '{ print $3 }'`52 53	if [ ! -d "$SYSFS" ]; then54		ktap_skip_all "$msg sysfs is not mounted"55		exit "${KSFT_SKIP}"56	fi57 58	CPUROOT=$SYSFS/devices/system/cpu59	CPUFREQROOT="$CPUROOT/cpufreq"60 61	if ! ls $CPUROOT/cpu* > /dev/null 2>&1; then62		ktap_skip_all "$msg cpus not available in sysfs"63		exit "${KSFT_SKIP}"64	fi65 66	if ! ls $CPUROOT/cpufreq > /dev/null 2>&1; then67		ktap_skip_all "$msg cpufreq directory not available in sysfs"68		exit "${KSFT_SKIP}"69	fi70}71 72parse_arguments()73{74	while getopts ht:o:d:g: arg75	do76		case $arg in77			h) # --help78				helpme79				;;80 81			t) # --func_type (Function to perform: basic, suspend, hibernate,82			   # suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))83				FUNC=$OPTARG84				;;85 86			o) # --output-file (Output file to store dumps)87				OUTFILE=$OPTARG88				;;89 90			d) # --driver-mod-name (Name of the driver module)91				DRIVER_MOD=$OPTARG92				;;93 94			g) # --governor-mod-name (Name of the governor module)95				GOVERNOR_MOD=$OPTARG96				;;97 98			\?)99				helpme100				;;101		esac102	done103}104 105do_test()106{107	# Check if CPUs are managed by cpufreq or not108	count=$(count_cpufreq_managed_cpus)109 110	if [ $count = 0 -a $FUNC != "modtest" ]; then111		ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"112	fi113 114	case "$FUNC" in115		"basic")116		cpufreq_basic_tests117		;;118 119		"suspend")120		do_suspend "suspend" 1121		;;122 123		"hibernate")124		do_suspend "hibernate" 1125		;;126 127		"suspend_rtc")128                do_suspend "suspend" 1 rtc129                ;;130 131                "hibernate_rtc")132                do_suspend "hibernate" 1 rtc133                ;;134 135		"modtest")136		# Do we have modules in place?137		if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then138			ktap_exit_fail_msg "No driver or governor module passed with -d or -g"139		fi140 141		if [ $DRIVER_MOD ]; then142			if [ $GOVERNOR_MOD ]; then143				module_test $DRIVER_MOD $GOVERNOR_MOD144			else145				module_driver_test $DRIVER_MOD146			fi147		else148			if [ $count = 0 ]; then149				ktap_exit_fail_msg "No cpu is managed by cpufreq core, exiting"150			fi151 152			module_governor_test $GOVERNOR_MOD153		fi154		;;155 156		"sptest1")157		simple_lockdep158		;;159 160		"sptest2")161		concurrent_lockdep162		;;163 164		"sptest3")165		governor_race166		;;167 168		"sptest4")169		hotplug_with_updates170		;;171 172		*)173		ktap_print_msg "Invalid [-f] function type"174		helpme175		;;176	esac177}178 179# clear dumps180# $1: file name181clear_dumps()182{183	echo "" > $1.txt184	echo "" > $1.dmesg_cpufreq.txt185	echo "" > $1.dmesg_full.txt186}187 188# $1: output file name189dmesg_dumps()190{191	dmesg | grep cpufreq >> $1.dmesg_cpufreq.txt192 193	# We may need the full logs as well194	dmesg >> $1.dmesg_full.txt195}196 197ktap_print_header198 199# Parse arguments200parse_arguments $@201 202ktap_set_plan 1203 204# Make sure all requirements are met205prerequisite206 207# Run requested functions208clear_dumps $OUTFILE209do_test | tee -a $OUTFILE.txt210if [ "${PIPESTATUS[0]}" -ne 0 ]; then211    exit ${PIPESTATUS[0]};212fi213dmesg_dumps $OUTFILE214 215ktap_test_pass "Completed successfully"216 217ktap_print_totals218exit "${KSFT_PASS}"219