summaryrefslogtreecommitdiffstats
path: root/scripts/qemuimage-tests/tools/compiler_test.sh
diff options
context:
space:
mode:
authorJiajun Xu <jiajun.xu@intel.com>2010-12-31 15:15:31 +0800
committerSaul Wold <sgw@linux.intel.com>2011-01-02 01:25:40 -0800
commit62caed8237baabd2b51d8f216f555880ae4a23c8 (patch)
treeca8d7e3230921912777781adce08de5f97a09af2 /scripts/qemuimage-tests/tools/compiler_test.sh
parentbcf8853e457f7ec43dfcaa91c66c0ae159565b53 (diff)
downloadpoky-62caed8237baabd2b51d8f216f555880ae4a23c8.tar.gz
qemuimagetest: Add basic function check for gcc/g++/make command in target
Add one case for compile tools sanity test in target, including gcc/g++/make. Signed-off-by Jiajun Xu <jiajun.xu@intel.com>
Diffstat (limited to 'scripts/qemuimage-tests/tools/compiler_test.sh')
-rw-r--r--scripts/qemuimage-tests/tools/compiler_test.sh137
1 files changed, 137 insertions, 0 deletions
diff --git a/scripts/qemuimage-tests/tools/compiler_test.sh b/scripts/qemuimage-tests/tools/compiler_test.sh
new file mode 100644
index 0000000000..9c30d6d78b
--- /dev/null
+++ b/scripts/qemuimage-tests/tools/compiler_test.sh
@@ -0,0 +1,137 @@
1#!/bin/bash
2# compiler test script running in target
3#
4# Author: Jiajun Xu <jiajun.xu@intel.com>
5#
6# This file is licensed under the GNU General Public License,
7# Version 2.
8#
9
10# Prepare test folder for compiler test
11COMPILE_FOLDER="/opt/test/compile_test"
12TEST_FILE="$COMPILE_FOLDER/compile_test.c"
13EXECUTE_FILE="$COMPILE_FOLDER/compile_test"
14TEST_MAKEFILE="$COMPILE_FOLDER/makefile"
15TEST_LIST="gcc g++ make"
16
17if [ ! -d $COMPILE_FOLDER ]; then
18 mkdir -p $COMPILE_FOLDER
19fi
20
21Target_Info()
22{
23 echo -e "\tTARGET: $*"
24}
25
26Target_Err()
27{
28 echo -e "\tTARGET: ##### Error Log #####"
29 $@
30 echo -e "\tTARGET: ##### End #####"
31}
32
33# Function to generate a c test file for compiler testing
34Gen_File()
35{
36 temp=`mktemp`
37
38 # Generate c/c++ test file for compiler testing
39 echo "#include <stdio.h>" >> $temp
40 echo "#include <math.h>" >> $temp
41 echo "" >> $temp
42 echo "double" >> $temp
43 echo "convert(long long l)" >> $temp
44 echo "{" >> $temp
45 echo " return (double)l; // or double(l)" >> $temp
46 echo "}" >> $temp
47 echo "" >> $temp
48 echo "int" >> $temp
49 echo "main(int argc, char * argv[])" >> $temp
50 echo "{" >> $temp
51 echo " long long l = 10;" >> $temp
52 echo " double f;" >> $temp
53 echo "" >> $temp
54 echo " f = convert(l);" >> $temp
55 echo " printf(\"convert: %lld => %f\n\", l, f);" >> $temp
56 echo "" >> $temp
57 echo " f = 1234.67;" >> $temp
58 echo " printf(\"floorf(%f) = %f\n\", f, floorf(f));" >> $temp
59 echo " return 0;" >> $temp
60 echo "}" >> $temp
61 echo $temp
62}
63
64# Function to generate a makefile for compiler testing
65Gen_Makefile()
66{
67 temp=`mktemp`
68 basename=`basename $EXECUTE_FILE`
69
70 echo -e "$basename: $basename.o" >> $temp
71 echo -e "\tgcc -o $basename $basename.o -lm" >> $temp
72 echo -e "$basename.o: $basename.c" >> $temp
73 echo -e "\tgcc -c $basename.c" >> $temp
74
75 echo $temp
76}
77
78# Generate a c test file for compiler testing
79test_file=`Gen_File`
80
81MOVE=`which mv`
82$MOVE $test_file $TEST_FILE
83
84# Begin compiler test in target
85for cmd in $TEST_LIST
86do
87 which $cmd
88 if [ $? -ne 0 ]; then
89 Target_Info "No $cmd command found"
90 exit 1
91 fi
92
93 if [ "$cmd" == "make" ]; then
94 rm -rf $EXECUTE_FILE
95
96 # For makefile test, we need to generate a makefile and run with a c file
97 makefile=`Gen_Makefile`
98 $MOVE $makefile $TEST_MAKEFILE
99
100 cd `dirname $TEST_MAKEFILE`
101 make
102
103 if [ $? -ne 0 ]; then
104 Target_Info "$cmd running with error, Pls. check error in following"
105 Target_Err make
106 exit 1
107 fi
108 else
109 rm -rf $EXECUTE_FILE
110
111 # For gcc/g++, we compile a c test file and check the output
112 $cmd $TEST_FILE -o $EXECUTE_FILE -lm
113
114 if [ $? -ne 0 ]; then
115 Target_Info "$cmd running with error, Pls. check error in following"
116 Target_Err $cmd $TEST_FILE -o $EXECUTE_FILE -lm
117 exit 1
118 fi
119 fi
120
121 # Check if the binary file generated by $cmd can work without error
122 if [ -f $EXECUTE_FILE ]; then
123 $EXECUTE_FILE
124 if [ $? -ne 0 ]; then
125 Target_Info "$EXECUTE_FILE running with error, Pls. check error in following"
126 Target_Err $EXECUTE_FILE
127 exit 1
128 else
129 Target_Info "$cmd can work without problem in target"
130 fi
131 else
132 Target_Info "No executalbe file $EXECUTE_FILE found, Pls. check the error log"
133 exit 1
134 fi
135done
136
137exit 0