summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJiajun Xu <jiajun.xu@intel.com>2010-07-08 02:06:58 +0800
committerRichard Purdie <rpurdie@linux.intel.com>2010-07-15 12:48:25 +0100
commitfd1d661b391dfad1edaac937a17c1165f635031a (patch)
tree3bce526d67faf52385482f38c31679db05f6dbd5 /scripts
parentbd19169a60d5aaadc278439578d06c8027cfecf3 (diff)
downloadpoky-fd1d661b391dfad1edaac937a17c1165f635031a.tar.gz
test: add automation framework and sanitytest
Automation test is disabled by default. User need set TESTCLASS to qemu in conf/local.conf and run bitbake command "bitbake poky-image-xxx" or "bitbake poky-image-xxx -c qemuimagetest" to trigger it. Currently only the sanity test with two testcases are added. To run the test, user need prepare a testing environment: 1) "expect" should be installed on system 2) NOPASSWD should be set for user to run bitbake Signed-off-by Jiajun Xu <jiajun.xu@intel.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qemuimage-testlib202
-rwxr-xr-xscripts/qemuimage-tests/sanity/boot31
-rwxr-xr-xscripts/qemuimage-tests/sanity/ssh40
3 files changed, 273 insertions, 0 deletions
diff --git a/scripts/qemuimage-testlib b/scripts/qemuimage-testlib
new file mode 100644
index 0000000000..4e27f8bc6f
--- /dev/null
+++ b/scripts/qemuimage-testlib
@@ -0,0 +1,202 @@
1#!/bin/bash
2# Common function for test
3# Expect should be installed for SSH Testing
4# To execute `runqemu`, NOPASSWD needs to be set in /etc/sudoers for user
5# For example, for user "builder", /etc/sudoers can be like following:
6# #########
7# #Members of the admin group may gain root privileges
8# %builder ALL=(ALL) NOPASSWD: NOPASSWD: ALL
9# #########
10#
11# Author: Jiajun Xu <jiajun.xu@intel.com>
12#
13# This file is licensed under the GNU General Public License,
14# Version 2.
15#
16
17TYPE="ext3"
18
19# common function for information print
20Test_Error()
21{
22 echo -e "\tTest_Error: $*"
23}
24
25Test_Info()
26{
27 echo -e "\tTest_Info: $*"
28}
29
30# function to run command in $ip_addr via ssh
31Test_SSH()
32{
33 local ip_addr=$1
34 shift
35 local command=$@
36 local tmpfile=`mktemp`
37 local timeout=60
38 local ret=0
39 local exp_cmd=`cat << EOF
40eval spawn ssh -o UserKnownHostsFile=$tmpfile root@$ip_addr "$command"
41set timeout $time_out
42expect {
43 "*assword:" { send "\r"; exp_continue}
44 "*(yes/no)?" { send "yes\r"; exp_continue }
45 eof { exit [ lindex [wait] 3 ] }
46}
47EOF`
48 expect -c "$exp_cmd"
49 ret=$?
50 rm -rf $tmpfile
51 return $ret
52}
53
54# function to check if ssh is up in $ip_addr
55Test_SSH_UP()
56{
57 local ip_addr=$1
58 local timeout=$2
59 local interval=0
60
61 while [ ${interval} -lt ${timeout} ]
62 do
63 Test_SSH ${ip_addr} "hostname"
64 if [ $? -ne 0 ]; then
65 interval=`expr $interval + 10`
66 sleep 10
67 else
68 Test_Info "We can ssh on ${ip_addr} now"
69 return 0
70 fi
71
72 done
73
74 Test_Info "We can not ssh on ${ip_addr} in ${timeout}"
75 return 1
76}
77
78# function to record test result in $TEST_RESULT/testresult.log
79Test_Print_Result()
80{
81 local PASS=0
82 local FAIL=0
83 local NORESULT=0
84 if [ $2 -eq 0 ]; then
85 PASS=1
86 elif [ $2 -eq 1 ]; then
87 FAIL=1
88 else
89 NORESULT=1
90 fi
91
92 echo -e "\t$1\t\t$PASS\t$FAIL\t$NORESULT" >> $TEST_RESULT/testresult.log
93}
94
95# function to kill qemu
96Test_Kill_Qemu()
97{
98 sudo pkill -9 qemu
99 return $?
100}
101
102# function to check if there is any qemu process
103Test_Check_Qemu_UP()
104{
105 local count=`ps -ef | grep -c qemu`
106 if [ ${count} -lt 2 ]; then
107 Test_Info "There is no Qemu process"
108 return 1
109 else
110 Test_Info "There is at least Qemu process running"
111 return 0
112 fi
113}
114
115# function to check if network is up
116Test_Check_IP_UP()
117{
118 ping -c1 $1
119 if [ $? -ne 0 ]; then
120 Test_Info "IP $1 is not up"
121 return 1
122 else
123 Test_Info "IP $1 is up"
124 return 0
125 fi
126}
127
128# function to check if qemu and its network
129Test_Create_Qemu()
130{
131 local ret=1
132 local up_time=0
133 local ip_addr=$1
134 local timeout=$2
135 local kernel=""
136 local rootfs=""
137
138 which poky-qemu
139 if [ $? -eq 0 ]; then
140 RUNQEMU=`which poky-qemu`
141 else
142 Test_Error "Can not find poky-qemu in \$PATH, return fail"
143 exit 1
144 fi
145
146 if [ "$QEMUARCH" = "qemux86" ]; then
147 KERNEL=${DEPLOY_DIR}/images/bzImage-${QEMUARCH}.bin
148 elif [ "$QEMUARCH" = "qemuarm" -o "$QEMUARCH" = "spitz" -o "$QEMUARCH" = "borzoi" -o "$QEMUARCH" = "akita" -o "$QEMUARCH" = "nokia800" ]; then
149 KERNEL=${DEPLOY_DIR}/images/zImage-${QEMUARCH}.bin
150 fi
151
152 ROOTFS_IMAGE=`readlink -f ${DEPLOY_DIR}/images/${QEMUTARGET}-${QEMUARCH}.ext3`
153 TEST_ROOTFS_IMAGE="${TEST_TMP}/${QEMUTARGET}-${QEMUARCH}-test.ext3"
154
155 CP=`which cp`
156 if [ -e "$TEST_ROOTFS_IMAGE" ]; then
157 rm -rf $TEST_ROOTFS_IMAGE
158 fi
159 $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE
160
161 export MACHINE=$QEMUARCH
162 # Create Qemu in localhost VNC Port 1
163
164 xterm -display ${DISPLAY} -e "${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE}" &
165
166 sleep 5
167
168 while [ ${up_time} -lt ${timeout} ]
169 do
170 Test_Check_Qemu_UP
171 if [ $? -ne 0 ]; then
172 Test_Info "Wait for qemu up..."
173 up_time=`expr $up_time + 5`
174 sleep 5
175 else
176 Test_Info "Begin to check if qemu network is up"
177 break
178 fi
179 done
180
181 while [ ${up_time} -lt ${timeout} ]
182 do
183 Test_Check_IP_UP ${ip_addr}
184 if [ $? -eq 0 ]; then
185 Test_Info "Qemu Network is up, ping with ${ip_addr} is OK"
186 ret=0
187 break
188 else
189 Test_Info "Wait for Qemu Network up"
190 up_time=`expr $up_time + 5`
191 sleep 5
192 fi
193 done
194
195 if [ $ret -eq 0 ]; then
196 Test_Info "Qemu and its network is up"
197 return $ret
198 else
199 Test_Info "Qemu or its network is not up in ${timeout}"
200 return $ret
201 fi
202}
diff --git a/scripts/qemuimage-tests/sanity/boot b/scripts/qemuimage-tests/sanity/boot
new file mode 100755
index 0000000000..b4c0094f25
--- /dev/null
+++ b/scripts/qemuimage-tests/sanity/boot
@@ -0,0 +1,31 @@
1#!/bin/bash
2#
3# Boot Test Case for Sanity Test
4# The case boot up the Qemu target with `runqemu qemux86`.
5# Then check if qemu and qemu network is up.
6#
7# Author: Jiajun Xu <jiajun.xu@intel.com>
8#
9# This file is licensed under the GNU General Public License,
10# Version 2.
11#
12
13. $OEROOT/scripts/qemuimage-testlib
14
15TIMEOUT=120
16QEMU_IPADDR="192.168.7.2"
17
18# Start qemu and check its network
19Test_Create_Qemu ${QEMU_IPADDR} ${TIMEOUT}
20
21if [ $? -eq 0 ]; then
22 Test_Info "Boot Test PASS"
23 Test_Kill_Qemu
24 Test_Print_Result "Boot" 0
25 exit 0
26else
27 Test_Info "Boot Test FAIL"
28 Test_Kill_Qemu
29 Test_Print_Result "Boot" 1
30 exit 1
31fi
diff --git a/scripts/qemuimage-tests/sanity/ssh b/scripts/qemuimage-tests/sanity/ssh
new file mode 100755
index 0000000000..7dd895951c
--- /dev/null
+++ b/scripts/qemuimage-tests/sanity/ssh
@@ -0,0 +1,40 @@
1#!/bin/bash
2# SSH Test Case for Sanity Test
3# The case boot up the Qemu target with `runqemu qemux86`.
4# Then check if ssh service in qemu is up.
5#
6# Author: Jiajun Xu <jiajun.xu@intel.com>
7#
8# This file is licensed under the GNU General Public License,
9# Version 2.
10#
11
12. $OEROOT/scripts/qemuimage-testlib
13
14TIMEOUT=360
15QEMU_IPADDR="192.168.7.2"
16RET=1
17
18# Start qemu and check its network
19Test_Create_Qemu ${QEMU_IPADDR} ${TIMEOUT}
20
21# If qemu network is up, check ssh service in qemu
22if [ $? -eq 0 ]; then
23 Test_Info "Begin to Test SSH Service in Qemu"
24 Test_SSH_UP ${QEMU_IPADDR} ${TIMEOUT}
25 RET=$?
26else
27 RET=1
28fi
29
30if [ ${RET} -eq 0 ]; then
31 Test_Info "SSH Test PASS"
32 Test_Kill_Qemu
33 Test_Print_Result "SSH" 0
34 exit 0
35else
36 Test_Info "SSH Test FAIL"
37 Test_Kill_Qemu
38 Test_Print_Result "SSH" 1
39 exit 1
40fi