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
10tmp_acpibin=/tmp/acpibin-$postfix
11
12TEST_CASES=
13TEST_MODES=
14REBUILD_TOOLS=yes
15BINCOMPONLY=no
16DATATABLEONLY=no
17EXECONLY=no
18
19usage() {
20
21	echo "Usage:"
22	echo "`basename $0` [-c case] [-m mode] [-u]"
23	echo "Where:"
24	echo "  -c:	Specify individual test cases (can be used multiple times)"
25	echo "  -m:	Specify individual test modes (can be used multiple times)"
26	echo "  -u:	Do not force rebuilding of ACPICA utilities (acpiexec, iasl)"
27	echo "  -e:     Perform the execution of aml files and omit binary comparison of regular aml and disassembled aml file."
28	echo "  -b:     Only perform binary comparison of regular aml and disasssembled aml file"
29	echo "  -d:     Only execute data table compiler/disassembler test"
30	echo ""
31
32	echo "Available test modes:"
33	echo "  n32	32-bit unoptimized code (tests are compiled with iasl -oa -r 1 and other flags)"
34	echo "  n64	64-bit unoptimized code (tests are compiled with iasl -oa -r 2 and other flags)"
35	echo "  o32	32-bit optimized code (tests are compiled with iasl -r 1 and other flags)"
36	echo "  o64	64-bit optimized code (tests are compiled with iasl -r 2 and other flags)"
37	echo ""
38
39	Do 3
40	exit 1
41}
42
43# Setup environment and variables.
44# Need a path to ASLTS and iasl,acpiexec generation dir
45setup_environment() {
46
47	aslts_dir=$1
48	generation_dir=$2
49
50	if [ -z "$generation_dir" ] ; then
51		echo "missing generation directory argument"
52		exit
53	elif [ -z "$aslts_dir" ] ; then
54		echo "missing aslts directory argument"
55		exit
56	elif [ ! -d "$generation_dir" ] ; then
57		echo $generation_dir is not a dir
58		exit
59	elif [ ! -d "$aslts_dir" ] ; then
60		echo $aslts_dir is not a dir
61		exit
62	fi
63
64	# Variables required by ASLTS
65	unset ASL
66	unset acpiexec
67	unset ASLTSDIR
68
69	export ASL=$tmp_iasl
70	export acpiexec=$tmp_acpiexec
71	export acpibin=$tmp_acpibin
72	export ASLTSDIR=$aslts_dir
73	export PATH=$ASLTSDIR/bin:$PATH
74}
75
76
77# Generate both iASL and acpiexec from source
78build_acpi_tools() {
79
80	restore_dir=$PWD
81	cd ${generation_dir}
82	rm -f $tmp_iasl $tmp_acpiexec $tmp_acpibin
83
84	# Build native-width iASL compiler and acpiexec
85	if [ ! -e bin/iasl -o ! -e bin/acpiexec ]; then
86		REBUILD_TOOLS=yes
87	fi
88	if [ "x$REBUILD_TOOLS" = "xyes" ]; then
89		jobs=`nproc`
90		make clean
91		make iasl ASLTS=TRUE -j$jobs
92		make acpibin ASLTS=TRUE -j$jobs
93		make acpiexec ASLTS=TRUE -j$jobs
94	fi
95
96	if [ -d "bin" ] && [ -f "bin/iasl" ]; then
97		echo "Installing ACPICA tools"
98		cp bin/iasl $tmp_iasl
99		cp bin/acpiexec $tmp_acpiexec
100		cp bin/acpibin $tmp_acpibin
101	else
102		echo "Could not find iASL/acpiexec tools"
103		exit
104	fi
105
106	# Ensure that the tools are available
107	if [ ! -f $tmp_iasl ] ; then
108		echo "iasl compiler not found"
109		exit
110	elif [ ! -f $tmp_acpiexec ] ; then
111		echo "acpiexec utility not found"
112		exit
113	elif [ ! -f $tmp_acpibin ] ; then
114		echo "acpibin utility not found"
115		exit
116	fi
117
118	cd $restore_dir
119}
120
121# Run a simple compiler test.
122# This test does the following:
123# 1 generate all sample tables in the compiler
124# 2 compile all tables (.asl -> .aml)
125# 3 disassembles all tables (.aml -> .dsl)
126# 4 recompiles all all tables (.dsl -> recomp.aml)
127# 5 runs binary comparison between .aml and recomp.aml
128run_compiler_template_test()
129{
130	pushd templates
131
132	rm -f *.asl *.aml *.dsl
133
134	$ASL -T all 2> /dev/null
135	for filename in *.asl
136	do
137		make -s NAME=$(basename "$filename" .asl)
138	done
139
140	rm -f *.asl *.aml *.dsl
141	popd
142}
143
144
145# Compile and run the ASLTS suite
146run_aslts() {
147
148	# Remove a previous version of the AML test code
149	version=`$ASL | grep version | awk '{print $5}'`
150	rm -rf $ASLTSDIR/tmp/aml/$version
151
152	# run templates test
153
154	run_compiler_template_test
155
156	if [ "x$DATATABLEONLY" = "xyes" ]; then
157		return 0
158	fi;
159
160	if [ "x$TEST_MODES" = "x" ]; then
161		TEST_MODES="n32 n64 o32 o64"
162	fi
163	Do 0 $TEST_MODES $TEST_CASES $EXECONLY
164	if [ $? -ne 0 ]; then
165		echo "ASLTS Compile Failure"
166		exit 1
167	fi
168
169	# Execute the test suite
170	if [ "x$BINCOMPONLY" = "xno" ]; then
171		echo ""
172		echo "ASL Test Suite Started: `date`"
173		start_time=$(date)
174
175		if [ "x$TEST_MODES" = "x" ]; then
176			TEST_MODES="n32 n64 o32 o64"
177		fi
178		Do 1 $TEST_MODES $TEST_CASES
179
180		echo ""
181		echo "ASL Test Suite Finished: `date`"
182		echo "                Started: $start_time"
183
184		rm -f $tmp_iasl $tmp_acpiexec $tmp_acpibin
185	fi;
186}
187
188SRCDIR=`(cd \`dirname $0\`; cd ..; pwd)`
189setup_environment $SRCDIR/tests/aslts $SRCDIR/generate/unix
190
191# To use common utilities
192. $SRCDIR/tests/aslts/bin/common
193. $SRCDIR/tests/aslts/bin/settings
194RESET_SETTINGS
195INIT_ALL_AVAILABLE_CASES
196INIT_ALL_AVAILABLE_MODES
197
198while getopts "c:m:uebd" opt
199do
200	case $opt in
201	b)
202		BINCOMPONLY=yes
203		echo "Running only binary comparisons"
204	;;
205	c)
206		get_collection_opcode "$OPTARG"
207		if [ $? -eq $COLLS_NUM ]; then
208			echo "Invalid test case: $OPTARG"
209			usage
210		else
211			TEST_CASES="$OPTARG $TEST_CASES"
212		fi
213	;;
214	d)
215		DATATABLEONLY=yes
216		echo "Running only data table test"
217	;;
218	e)
219		EXECONLY=yes
220		echo "Running tests without binary comparisons"
221	;;
222	m)
223		check_mode_id "$OPTARG"
224		if [ $? -eq 1 ]; then
225			echo "Invalid test mode: $OPTARG"
226			usage
227		else
228			TEST_MODES="$OPTARG $TEST_MODES"
229		fi
230	;;
231	u)
232		REBUILD_TOOLS=no
233	;;
234	?)
235		echo "Invalid argument: $opt"
236		usage
237	;;
238	esac
239done
240shift $(($OPTIND - 1))
241
242build_acpi_tools
243run_aslts
244