1#!/bin/bash
2#
3# aslts - execute ASL test suite
4#
5
6# Will build temporary versions of iASL and acpiexec
7postfix=`date +%H%M%S`
8tmp_iasl=/tmp/iasl-$postfix
9tmp_acpiexec=/tmp/acpiexec-$postfix
10
11TEST_CASES=
12TEST_MODES=
13REBUILD_TOOLS=yes
14
15usage() {
16
17	echo "Usage:"
18	echo "`basename $0` [-c case] [-m mode] [-u]"
19	echo "Where:"
20	echo "  -c:	Specify individual test cases (can be used multiple times)"
21	echo "  -m:	Specify individual test modes (can be used multiple times)"
22	echo "  -u:	Do not force rebuilding of ACPICA utilities (acpiexec, iasl)"
23	echo ""
24
25	echo "Available test modes:"
26	echo "  n32	32-bit normal mode"
27	echo "  n64	64-bit normal mode"
28	echo "  s32	32-bit slack mode"
29	echo "  s64	64-bit slack mode"
30	echo ""
31
32	Do 3
33	exit 1
34}
35
36# Setup environment and variables.
37# Need a path to ASLTS and iasl,acpiexec generation dir
38setup_environment() {
39
40	aslts_dir=$1
41	generation_dir=$2
42
43	if [ -z "$generation_dir" ] ; then
44		echo "missing generation directory argument"
45		exit
46	elif [ -z "$aslts_dir" ] ; then
47		echo "missing aslts directory argument"
48		exit
49	elif [ ! -d "$generation_dir" ] ; then
50		echo $generation_dir is not a dir
51		exit
52	elif [ ! -d "$aslts_dir" ] ; then
53		echo $aslts_dir is not a dir
54		exit
55	fi
56
57	# Variables required by ASLTS
58	unset ASL
59	unset acpiexec
60	unset ASLTSDIR
61
62	export ASL=$tmp_iasl
63	export acpiexec=$tmp_acpiexec		
64	export ASLTSDIR=$aslts_dir
65	export PATH=$ASLTSDIR/bin:$PATH
66}
67
68
69# Generate both iASL and acpiexec from source
70build_acpi_tools() {
71
72	restore_dir=$PWD
73	cd ${generation_dir}
74	rm -f $tmp_iasl $tmp_acpiexec
75
76	# Build native-width iASL compiler and acpiexec
77	if [ ! -e bin/iasl -o ! -e bin/acpiexec ]; then
78		REBUILD_TOOLS=yes
79	fi
80	if [ "x$REBUILD_TOOLS" = "xyes" ]; then
81		make clean
82		make iasl ASLTS=TRUE
83		make acpiexec ASLTS=TRUE
84	fi
85
86	if [ -d "bin" ] && [ -f "bin/iasl" ]; then
87		echo "Installing ACPICA tools"
88		cp bin/iasl $tmp_iasl
89		cp bin/acpiexec $tmp_acpiexec
90	else
91		echo "Could not find iASL/acpiexec tools"
92		exit
93	fi
94
95	# Ensure that the tools are available
96	if [ ! -f $tmp_iasl ] ; then
97		echo "iasl compiler not found"
98		exit
99	elif [ ! -f $tmp_acpiexec ] ; then
100		echo "acpiexec utility not found"
101		exit
102	fi
103
104	cd $restore_dir
105}
106
107
108# Compile and run the ASLTS suite
109run_aslts() {
110
111	# Remove a previous version of the AML test code
112	version=`$ASL | grep version | awk '{print $5}'`
113	rm -rf $ASLTSDIR/tmp/aml/$version
114
115	if [ "x$TEST_CASES" = "x" ]; then
116		# Compile all ASL test modules
117		Do 0 aslts
118		if [ $? -ne 0 ]; then
119			echo "ASLTS Compile Failure"
120			exit 1
121		fi
122	else
123		Do 0 $TEST_CASES
124	fi
125
126	# Execute the test suite
127	echo ""
128	echo "ASL Test Suite Started: `date`"
129	start_time=$(date)
130
131	if [ "x$TEST_MODES" = "x" ]; then
132		TEST_MODES="n32 n64 s32 s64"
133	fi
134	Do 1 $TEST_MODES $TEST_CASES
135
136	echo ""
137	echo "ASL Test Suite Finished: `date`"
138	echo "                Started: $start_time"
139
140	rm -f $tmp_iasl $tmp_acpiexec
141}
142
143SRCDIR=`(cd \`dirname $0\`; cd ..; pwd)`
144setup_environment $SRCDIR/tests/aslts $SRCDIR/generate/unix
145
146# To use common utilities
147. $SRCDIR/tests/aslts/bin/common
148. $SRCDIR/tests/aslts/bin/settings
149RESET_SETTINGS
150INIT_ALL_AVAILABLE_CASES
151INIT_ALL_AVAILABLE_MODES
152
153while getopts "c:m:u" opt
154do
155	case $opt in
156	c)
157		get_collection_opcode "$OPTARG"
158		if [ $? -eq $COLLS_NUM ]; then
159			echo "Invalid test case: $OPTARG"
160			usage
161		else
162			TEST_CASES="$OPTARG $TEST_CASES"
163		fi
164	;;
165	m)
166		check_mode_id "$OPTARG"
167		if [ $? -eq 1 ]; then
168			echo "Invalid test mode: $OPTARG"
169			usage
170		else
171			TEST_MODES="$OPTARG $TEST_MODES"
172		fi
173	;;
174	u)
175		REBUILD_TOOLS=no
176	;;
177	?)
178		echo "Invalid argument: $opt"
179		usage
180	;;
181	esac
182done
183shift $(($OPTIND - 1))
184
185build_acpi_tools
186run_aslts
187
188