brintos

brintos / linux-shallow public Read only

0
0
Text · 4.8 KiB · 7f2667e Raw
243 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# Modules specific tests cases5 6# protect against multiple inclusion7if [ $FILE_MODULE ]; then8	return 09else10	FILE_MODULE=DONE11fi12 13source cpu.sh14source cpufreq.sh15source governor.sh16 17# Check basic insmod/rmmod18# $1: module19test_basic_insmod_rmmod()20{21	printf "** Test: Running ${FUNCNAME[0]} **\n\n"22 23	printf "Inserting $1 module\n"24	# insert module25	insmod $126	if [ $? != 0 ]; then27		ktap_exit_fail_msg "Insmod $1 failed\n"28	fi29 30	printf "Removing $1 module\n"31	# remove module32	rmmod $133	if [ $? != 0 ]; then34		ktap_exit_fail_msg "rmmod $1 failed\n"35	fi36 37	printf "\n"38}39 40# Insert cpufreq driver module and perform basic tests41# $1: cpufreq-driver module to insert42# $2: If we want to play with CPUs (1) or not (0)43module_driver_test_single()44{45	printf "** Test: Running ${FUNCNAME[0]} for driver $1 and cpus_hotplug=$2 **\n\n"46 47	if [ $2 -eq 1 ]; then48		# offline all non-boot CPUs49		for_each_non_boot_cpu offline_cpu50		printf "\n"51	fi52 53	# insert module54	printf "Inserting $1 module\n\n"55	insmod $156	if [ $? != 0 ]; then57		printf "Insmod $1 failed\n"58		return;59	fi60 61	if [ $2 -eq 1 ]; then62		# online all non-boot CPUs63		for_each_non_boot_cpu online_cpu64		printf "\n"65	fi66 67	# run basic tests68	cpufreq_basic_tests69 70	# remove module71	printf "Removing $1 module\n\n"72	rmmod $173	if [ $? != 0 ]; then74		printf "rmmod $1 failed\n"75		return;76	fi77 78	# There shouldn't be any cpufreq directories now.79	for_each_cpu cpu_should_not_have_cpufreq_directory80	printf "\n"81}82 83# $1: cpufreq-driver module to insert84module_driver_test()85{86	printf "** Test: Running ${FUNCNAME[0]} **\n\n"87 88	# check if module is present or not89	ls $1 > /dev/null90	if [ $? != 0 ]; then91		printf "$1: not present in `pwd` folder\n"92		return;93	fi94 95	# test basic module tests96	test_basic_insmod_rmmod $197 98	# Do simple module test99	module_driver_test_single $1 0100 101	# Remove CPUs before inserting module and then bring them back102	module_driver_test_single $1 1103	printf "\n"104}105 106# find governor name based on governor module name107# $1: governor module name108find_gov_name()109{110	if [ $1 = "cpufreq_ondemand.ko" ]; then111		printf "ondemand"112	elif [ $1 = "cpufreq_conservative.ko" ]; then113		printf "conservative"114	elif [ $1 = "cpufreq_userspace.ko" ]; then115		printf "userspace"116	elif [ $1 = "cpufreq_performance.ko" ]; then117		printf "performance"118	elif [ $1 = "cpufreq_powersave.ko" ]; then119		printf "powersave"120	elif [ $1 = "cpufreq_schedutil.ko" ]; then121		printf "schedutil"122	fi123}124 125# $1: governor string, $2: governor module, $3: policy126# example: module_governor_test_single "ondemand" "cpufreq_ondemand.ko" 2127module_governor_test_single()128{129	printf "** Test: Running ${FUNCNAME[0]} for $3 **\n\n"130 131	backup_governor $3132 133	# switch to new governor134	printf "Switch from $CUR_GOV to $1\n"135	switch_show_governor $3 $1136 137	# try removing module, it should fail as governor is used138	printf "Removing $2 module\n\n"139	rmmod $2140	if [ $? = 0 ]; then141		printf "WARN: rmmod $2 succeeded even if governor is used\n"142		insmod $2143	else144		printf "Pass: unable to remove $2 while it is being used\n\n"145	fi146 147	# switch back to old governor148	printf "Switchback to $CUR_GOV from $1\n"149	restore_governor $3150	printf "\n"151}152 153# Insert cpufreq governor module and perform basic tests154# $1: cpufreq-governor module to insert155module_governor_test()156{157	printf "** Test: Running ${FUNCNAME[0]} **\n\n"158 159	# check if module is present or not160	ls $1 > /dev/null161	if [ $? != 0 ]; then162		printf "$1: not present in `pwd` folder\n"163		return;164	fi165 166	# test basic module tests167	test_basic_insmod_rmmod $1168 169	# insert module170	printf "Inserting $1 module\n\n"171	insmod $1172	if [ $? != 0 ]; then173		printf "Insmod $1 failed\n"174		return;175	fi176 177	# switch to new governor for each cpu178	for_each_policy module_governor_test_single $(find_gov_name $1) $1179 180	# remove module181	printf "Removing $1 module\n\n"182	rmmod $1183	if [ $? != 0 ]; then184		printf "rmmod $1 failed\n"185		return;186	fi187	printf "\n"188}189 190# test modules: driver and governor191# $1: driver module, $2: governor module192module_test()193{194	printf "** Test: Running ${FUNCNAME[0]} **\n\n"195 196	# check if modules are present or not197	ls $1 $2 > /dev/null198	if [ $? != 0 ]; then199		printf "$1 or $2: is not present in `pwd` folder\n"200		return;201	fi202 203	# TEST1: Insert gov after driver204	# insert driver module205	printf "Inserting $1 module\n\n"206	insmod $1207	if [ $? != 0 ]; then208		printf "Insmod $1 failed\n"209		return;210	fi211 212	# run governor tests213	module_governor_test $2214 215	# remove driver module216	printf "Removing $1 module\n\n"217	rmmod $1218	if [ $? != 0 ]; then219		printf "rmmod $1 failed\n"220		return;221	fi222 223	# TEST2: Insert driver after governor224	# insert governor module225	printf "Inserting $2 module\n\n"226	insmod $2227	if [ $? != 0 ]; then228		printf "Insmod $2 failed\n"229		return;230	fi231 232	# run governor tests233	module_driver_test $1234 235	# remove driver module236	printf "Removing $2 module\n\n"237	rmmod $2238	if [ $? != 0 ]; then239		printf "rmmod $2 failed\n"240		return;241	fi242}243