• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3TMPDIR=/tmp
4
5PASS=0
6FAIL=1
7NOSUPPORT=2
8MISSING_FILE=3
9UNTESTED=4
10YES=0
11
12cleanup() {
13	if [ -f ${1} ] ; then
14		rm -f ${1}
15	fi
16}
17
18check_arch() {
19	case "$(uname -m)" in
20	i[4-6]86|x86_64)
21		;;
22	*)
23		tst_brkm TCONF "Arch not supported; not running testcases"
24		;;
25	esac
26}
27
28check_config_options() {
29	if ( ! ${3} "${1}" ${2} | grep -v "#" > /dev/null ) ; then
30		tst_brkm TCONF "NOSUPPORT: current system dosen't support ${1}"
31	fi
32}
33
34get_topology() {
35	declare -a cpus
36	declare -a phyid
37
38	total_cpus=`tst_ncpus`
39	(( total_cpus-=1 ))
40	for cpu in $(seq 0 "${total_cpus}" )
41	do
42		cpus[$cpu]=cpu${cpu}
43		phyid[$cpu]=$(cat \
44		/sys/devices/system/cpu/cpu${cpu}/topology/physical_package_id)
45	done
46	j=0
47	while [ "${j}" -lt "${total_cpus}" ]
48	do
49		(( k = $j + 1 ))
50		if [ ${phyid[$j]} -eq ${phyid[$k]} ] ; then
51			echo "${cpus[$j]} -P ${cpus[$k]}" | sed -e "s/cpu//g"
52		fi
53		(( j+=1 ))
54	done
55}
56
57check_cpufreq() {
58	total_cpus=`tst_ncpus`
59	(( total_cpus-=1 ))
60
61	for cpu in $(seq 0 "${total_cpus}" )
62	do
63		if [ ! -d /sys/devices/system/cpu/cpu${cpu}/cpufreq ] ; then
64			tst_brkm TCONF "NOSUPPORT: cpufreq support not " \
65				"found please check Kernel configuration " \
66				"or BIOS settings"
67		fi
68	done
69}
70
71get_supporting_freq() {
72	cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies \
73		| uniq
74}
75
76get_supporting_govr() {
77	cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors \
78		| uniq
79}
80
81is_hyper_threaded() {
82	siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'`
83	cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq | cut -f2 -d':'`
84	[ $siblings -gt $cpu_cores ]; echo $?
85}
86
87check_input() {
88	validity_check=${2:-valid}
89	testfile=$3
90	if [ "${validity_check}" = "invalid" ] ; then
91		PASS="Testcase FAIL - Able to execute"
92		FAIL="Testcase PASS - Unable to execute"
93	else
94		PASS="Testcase PASS"
95		FAIL="Testcase FAIL"
96	fi
97	RC=0
98	for input in ${1}
99	do
100		echo ${input} > ${test_file} 2>/dev/null
101		return_value=$?
102		output=$(cat ${test_file})
103		if [ "${return_value}" = "0" -a "${input}" = "${output}" ] ; then
104			echo "${0}: ${PASS}: echo ${input} > ${test_file}"
105			if [ "${validity_check}" = "invalid" ] ; then
106				RC=1
107			fi
108		else
109			echo "${0}: ${FAIL}: echo ${input} > ${test_file}"
110			if [ "${validity_check}" = "valid" ] ; then
111				RC=1
112			fi
113		fi
114	done
115	return $RC
116}
117
118is_multi_socket() {
119	no_of_sockets=`cat \
120		/sys/devices/system/cpu/cpu*/topology/physical_package_id \
121		| sort -u | wc -l`
122	[ $no_of_sockets -gt 1 ] ; echo $?
123}
124
125is_multi_core() {
126	siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'`
127	cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq | cut -f2 -d':'`
128	if [ $siblings -eq $cpu_cores ]; then
129		[ $cpu_cores -gt 1 ]; echo $?
130	else
131		: $(( num_of_cpus = siblings / cpu_cores ))
132		[ $num_of_cpus -gt 1 ]; echo $?
133	fi
134}
135
136is_dual_core() {
137	siblings=`grep siblings /proc/cpuinfo | uniq | cut -f2 -d':'`
138	cpu_cores=`grep "cpu cores" /proc/cpuinfo | uniq \
139			| cut -f2 -d':'`
140        if [ $siblings -eq $cpu_cores ]; then
141                [ $cpu_cores -eq 2 ]; echo $?
142        else
143                : $(( num_of_cpus = siblings / cpu_cores ))
144                [ $num_of_cpus -eq 2 ]; echo $?
145        fi
146}
147
148get_kernel_version() {
149	# Get kernel minor version
150	export kernel_version=`uname -r | awk -F. '{print $1"."$2"."$3}' \
151		| cut -f1 -d'-'`
152}
153
154get_valid_input() {
155	kernel_version=$1
156	case "$kernel_version" in
157	'2.6.26' | '2.6.27' | '2.6.28')
158			export valid_input="0 1" ;;
159		*) export valid_input="0 1 2" ;;
160	esac
161}
162
163analyze_result_hyperthreaded() {
164	sched_mc=$1
165    pass_count=$2
166    sched_smt=$3
167	PASS="Test PASS"
168	FAIL="Test FAIL"
169
170	RC=0
171	case "$sched_mc" in
172	0)
173		case "$sched_smt" in
174		0)
175			if [ $pass_count -lt 5 ]; then
176				echo "${PASS}: cpu consolidation failed for" \
177					"sched_mc=$sched_mc & sched_smt=$sched_smt"
178			else
179				RC=1
180				echo "${FAIL}: cpu consolidation passed for" \
181					"sched_mc=$sched_mc & sched_smt=$sched_smt"
182			fi
183			;;
184		*)
185			if [ $pass_count -lt 5 ]; then
186				RC=1
187				echo "${FAIL}: cpu consolidation for" \
188					"sched_mc=$sched_mc & sched_smt=$sched_smt"
189			else
190				echo "${PASS}: cpu consolidation for" \
191					"sched_mc=$sched_mc & sched_smt=$sched_smt"
192			fi
193			;;
194		esac ;;
195	*)
196		if [ $pass_count -lt 5 ]; then
197			RC=1
198			echo "${FAIL}: cpu consolidation for" \
199				"sched_mc=$sched_mc & sched_smt=$sched_smt"
200		else
201			echo "${PASS}: cpu consolidation for" \
202				"sched_mc=$sched_mc & sched_smt=$sched_smt"
203		fi
204		;;
205	esac
206	return $RC
207}
208
209analyze_package_consolidation_result() {
210	sched_mc=$1
211    pass_count=$2
212
213	if [ $# -gt 2 ]
214	then
215		sched_smt=$3
216	else
217		sched_smt=-1
218	fi
219
220	PASS="Test PASS"
221	FAIL="Test FAIL"
222
223	RC=0
224	if [ $hyper_threaded -eq $YES -a $sched_smt -gt -1 ]; then
225		analyze_result_hyperthreaded $sched_mc $pass_count $sched_smt
226	else
227		case "$sched_mc" in
228	    0)
229    	    if [ $pass_count -lt 5 ]; then
230				echo "${PASS}: cpu consolidation failed for" \
231					"sched_mc=$sched_mc"
232        	else
233				RC=1
234				echo "${FAIL}: cpu consolidation passed for" \
235					"sched_mc=$sched_mc"
236			fi
237			;;
238    	*)
239			if [ $pass_count -lt 5 ]; then
240				RC=1
241				echo "${FAIL}: consolidation at package level" \
242					"failed for sched_mc=$sched_mc"
243			else
244				echo "${PASS}: consolidation at package level" \
245					"passed for sched_mc=$sched_mc"
246			fi
247        	;;
248    	esac
249	fi
250	return $RC
251}
252
253analyze_core_consolidation_result() {
254	sched_smt=$1
255	pass_count=$2
256	PASS="Test PASS"
257	FAIL="Test FAIL"
258
259	RC=0
260	case "$sched_smt" in
261	0)
262		if [ $pass_count -lt 5 ]; then
263			echo "${PASS}: consolidation at core level failed" \
264				"when sched_smt=$sched_smt"
265		else
266			RC=1
267			echo "${FAIL}: consolidation at core level passed for" \
268				"sched_smt=$sched_smt"
269		fi ;;
270	*)
271		if [ $pass_count -lt 5 ]; then
272			RC=1
273			echo "${FAIL}: consolidation at core level failed for" \
274				"sched_smt=$sched_smt"
275		else
276			echo "${PASS}: consolidation at core level passed for" \
277				"sched_smt=$sched_smt"
278		fi ;;
279	esac
280	return $RC
281}
282
283analyze_sched_domain_result(){
284	sched_mc=$1
285	result=$2
286	sched_smt=$3
287	PASS="Test PASS"
288	FAIL="Test FAIL"
289
290	RC=0
291	if [ $hyper_threaded -eq $YES ]; then
292		if [ $sched_smt ]; then
293			if [ "$result" = 0 ];then
294				echo "${PASS}: sched domain test for" \
295					"sched_mc=$sched_mc & sched_smt=$sched_smt"
296			else
297				RC=1
298				echo "${FAIL}: sched domain test for" \
299					"sched_mc=$sched_mc & sched_smt=$sched_smt"
300			fi
301		else
302			if [ "$result" = 0 ];then
303				echo "${PASS}: sched domain test for" \
304					"sched_mc=$sched_mc"
305			else
306				RC=1
307				echo "${FAIL}: sched domain test for" \
308					"sched_mc=$sched_mc"
309			fi
310		fi
311	else
312		if [ "$result" = 0 ];then
313			echo "${PASS}: sched domain test for sched_mc=$sched_mc"
314		else
315			RC=1
316			echo "${FAIL}: sched domain test for sched_mc=$sched_mc"
317		fi
318	fi
319	return $RC
320}
321