summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiajun Xu <jiajun.xu@intel.com>2010-10-30 01:03:22 +0800
committerRichard Purdie <rpurdie@linux.intel.com>2010-11-10 21:09:22 +0800
commit12a861359a3413ded52174c814e8653c56caee17 (patch)
tree305a53f25d58def6e2793e7f6fcdd1a7387f0287
parent53b775b49645ce6bcac48def8671bf5f751c730b (diff)
downloadopenembedded-core-12a861359a3413ded52174c814e8653c56caee17.tar.gz
openembedded-core-12a861359a3413ded52174c814e8653c56caee17.tar.bz2
openembedded-core-12a861359a3413ded52174c814e8653c56caee17.tar.xz
openembedded-core-12a861359a3413ded52174c814e8653c56caee17.zip
imagetest-qemu: Add test case for dmesg check in target
Add a test case for error log check with command dmesg in target. The case introduces a new folder in target, "/opt/test", which holds test scripts running in target. Signed-off-by Jiajun Xu <jiajun.xu@intel.com>
-rw-r--r--meta/classes/imagetest-qemu.bbclass6
-rw-r--r--scripts/qemuimage-testlib122
-rwxr-xr-xscripts/qemuimage-tests/sanity/boot3
-rwxr-xr-xscripts/qemuimage-tests/sanity/dmesg52
-rwxr-xr-xscripts/qemuimage-tests/sanity/ssh5
-rw-r--r--scripts/qemuimage-tests/scenario/qemuarm/poky-image-sato1
-rw-r--r--scripts/qemuimage-tests/scenario/qemuarm/poky-image-sdk1
-rw-r--r--scripts/qemuimage-tests/scenario/qemumips/poky-image-sato1
-rw-r--r--scripts/qemuimage-tests/scenario/qemumips/poky-image-sdk1
-rw-r--r--scripts/qemuimage-tests/scenario/qemuppc/poky-image-sato1
-rw-r--r--scripts/qemuimage-tests/scenario/qemuppc/poky-image-sdk1
-rw-r--r--scripts/qemuimage-tests/scenario/qemux86/poky-image-sato1
-rw-r--r--scripts/qemuimage-tests/scenario/qemux86/poky-image-sdk1
-rw-r--r--scripts/qemuimage-tests/tools/dmesg.sh26
14 files changed, 211 insertions, 11 deletions
diff --git a/meta/classes/imagetest-qemu.bbclass b/meta/classes/imagetest-qemu.bbclass
index 5742644e0..bd4dc9c0b 100644
--- a/meta/classes/imagetest-qemu.bbclass
+++ b/meta/classes/imagetest-qemu.bbclass
@@ -133,9 +133,11 @@ python do_qemuimagetest() {
ret = 1
elif m.group('noresult') == "1":
ret = 2
- print line,
+ line = line.strip('\n')
+ bb.note(line)
else:
- print line,
+ line = line.strip('\n')
+ bb.note(line)
f.close()
if ret != 0:
diff --git a/scripts/qemuimage-testlib b/scripts/qemuimage-testlib
index 733cd12c0..3ebf5ffd2 100644
--- a/scripts/qemuimage-testlib
+++ b/scripts/qemuimage-testlib
@@ -16,9 +16,18 @@
TYPE="ext3"
+# The folder to hold all scripts running on targets
+TOOLS="$POKYBASE/scripts/qemuimage-tests/tools"
+
+# Test Directory on target for testing
+TARGET_TEST_DIR="/opt/test"
+
# Global variable for process id
PID=0
+# Global variable for target ip address
+TARGET_IPADDR=0
+
# common function for information print
Test_Error()
{
@@ -30,6 +39,35 @@ Test_Info()
echo -e "\tTest_Info: $*"
}
+# function to copy files from host into target
+# $1 is the ip address of target
+# $2 is the files, which need to be copied into target
+# $3 is the path on target, where files are copied into
+Test_SCP()
+{
+ local ip_addr=$1
+ local src=$2
+ local des=$3
+ local tmpfile=`mktemp`
+ local timeout=60
+ local ret=0
+
+ # We use expect to interactive with target by ssh
+ local exp_cmd=`cat << EOF
+eval spawn scp -o UserKnownHostsFile=$tmpfile "$src" root@$ip_addr:"$des"
+set timeout $time_out
+expect {
+ "*assword:" { send "\r"; exp_continue}
+ "*(yes/no)?" { send "yes\r"; exp_continue }
+ eof { exit [ lindex [wait] 3 ] }
+}
+EOF`
+ expect -c "$exp_cmd"
+ ret=$?
+ rm -rf $tmpfile
+ return $ret
+}
+
# function to run command in $ip_addr via ssh
Test_SSH()
{
@@ -78,6 +116,27 @@ Test_SSH_UP()
return 1
}
+# function to prepare target test environment
+# $1 is the ip address of target system
+# $2 is the files, which needs to be copied into target
+Test_Target_Pre()
+{
+ local ip_addr=$1
+ local testscript=$2
+
+ # Create a pre-defined folder for test scripts
+ Test_SSH $ip_addr "mkdir -p $TARGET_TEST_DIR"
+ if [ $? -eq 0 ]; then
+ # Copy test scripts into target
+ Test_SCP $ip_addr $testscript $TARGET_TEST_DIR && return 0
+ else
+ Test_Error "Fail to create $TARGET_TEST_DIR on target"
+ return 1
+ fi
+
+ return 1
+}
+
# function to record test result in $TEST_RESULT/testresult.log
Test_Print_Result()
{
@@ -232,13 +291,63 @@ Test_Find_Image()
return 1
}
+# function to parse IP address of target
+# $1 is the pid of qemu startup process
+Test_Fetch_Target_IP()
+{
+ local opid=$1
+ local ppid=0
+ local ip_addr=0
+ local i=0
+ declare local pid
+
+ # Check if $1 pid exists and contains ipaddr of target
+ ps -fp $opid | grep -oq "192\.168\.7\.[0-9]*::"
+
+ # Find all children pid of the pid $1
+ # and check if they contain ipaddr of target
+ if [ $? -ne 0 ]; then
+ # Check if there is any child pid of the pid $1
+ ppid=$opid
+ ps -f --ppid $ppid > /dev/zero
+ ret=$?
+
+ while [ $ret -eq 0 ]
+ do
+ # If yes, get the child pid and check if the child pid has other child pid
+ # Continue the while loop until there is no child pid found
+ pid[$i]=`ps -f --ppid $ppid | awk '{if ($2 != "PID") print $2}'`
+ ppid=${pid[$i]}
+ i=$((i+1))
+ ps -f --ppid $ppid > /dev/zero
+ ret=$?
+ done
+
+ # Check these children pids, if they have ipaddr included in command line
+ while [ $i -ne 0 ]
+ do
+ i=$((i-1))
+ ps -fp ${pid[$i]} | grep -oq "192\.168\.7\.[0-9]*::"
+ if [ $? -eq 0 ]; then
+ ip_addr=`ps -fp ${pid[$i]} | grep -o "192\.168\.7\.[0-9]*::" | awk -F":" '{print $1}'`
+ fi
+ sleep 1
+ done
+ else
+ ip_addr=`ps -fp $opid | grep -o "192\.168\.7\.[0-9]*::" | awk -F":" '{print $1}'`
+ fi
+
+ echo $ip_addr
+
+ return
+}
+
# function to check if qemu and its network
Test_Create_Qemu()
{
+ local timeout=$1
local ret=1
local up_time=0
- local ip_addr=$1
- local timeout=$2
which poky-qemu
if [ $? -eq 0 ]; then
@@ -288,11 +397,16 @@ Test_Create_Qemu()
fi
done
+ # Parse IP address of target from the qemu command line
+ if [ ${up_time} -lt ${timeout} ]; then
+ TARGET_IPADDR=`Test_Fetch_Target_IP $PID`
+ fi
+
while [ ${up_time} -lt ${timeout} ]
do
- Test_Check_IP_UP ${ip_addr}
+ Test_Check_IP_UP ${TARGET_IPADDR}
if [ $? -eq 0 ]; then
- Test_Info "Qemu Network is up, ping with ${ip_addr} is OK"
+ Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK"
ret=0
break
else
diff --git a/scripts/qemuimage-tests/sanity/boot b/scripts/qemuimage-tests/sanity/boot
index 57b204b17..5014e8a5a 100755
--- a/scripts/qemuimage-tests/sanity/boot
+++ b/scripts/qemuimage-tests/sanity/boot
@@ -12,10 +12,9 @@
. $POKYBASE/scripts/qemuimage-testlib
TIMEOUT=120
-QEMU_IPADDR="192.168.7.2"
# Start qemu and check its network
-Test_Create_Qemu ${QEMU_IPADDR} ${TIMEOUT}
+Test_Create_Qemu ${TIMEOUT}
if [ $? -eq 0 ]; then
Test_Info "Boot Test PASS"
diff --git a/scripts/qemuimage-tests/sanity/dmesg b/scripts/qemuimage-tests/sanity/dmesg
new file mode 100755
index 000000000..c384659b6
--- /dev/null
+++ b/scripts/qemuimage-tests/sanity/dmesg
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Dmesg Check Test Case for Sanity Test
+# The case boot up the Qemu target with `runqemu qemux86`.
+# Then check if there is any error log in dmesg.
+#
+# Author: Jiajun Xu <jiajun.xu@intel.com>
+#
+# This file is licensed under the GNU General Public License,
+# Version 2.
+#
+
+. $POKYBASE/scripts/qemuimage-testlib
+
+TIMEOUT=360
+RET=1
+
+# Start qemu and check its network
+Test_Create_Qemu ${TIMEOUT}
+
+# If qemu network is up, check ssh service in qemu
+if [ $? -eq 0 ]; then
+ Test_Info "Begin to Test SSH Service in Qemu"
+ Test_SSH_UP ${TARGET_IPADDR} ${TIMEOUT}
+ RET=$?
+else
+ RET=1
+fi
+
+# Check if there is any error log in dmesg
+if [ $RET -eq 0 -a -f $TOOLS/dmesg.sh ]; then
+ # Copy dmesg.sh into target
+ Test_Target_Pre ${TARGET_IPADDR} $TOOLS/dmesg.sh
+ if [ $? -eq 0 ]; then
+ # Run dmesg.sh to check if there is any error message with command dmesg
+ Test_SSH ${TARGET_IPADDR} "sh $TARGET_TEST_DIR/dmesg.sh"
+ RET=$?
+ else
+ RET=1
+ fi
+fi
+
+if [ ${RET} -eq 0 ]; then
+ Test_Info "Dmesg Test PASS"
+ Test_Kill_Qemu
+ Test_Print_Result "dmesg" 0
+ exit 0
+else
+ Test_Info "Dmesg Test FAIL, Pls. check above error log"
+ Test_Kill_Qemu
+ Test_Print_Result "dmesg" 1
+ exit 1
+fi
diff --git a/scripts/qemuimage-tests/sanity/ssh b/scripts/qemuimage-tests/sanity/ssh
index 3c7638cc2..f9143d055 100755
--- a/scripts/qemuimage-tests/sanity/ssh
+++ b/scripts/qemuimage-tests/sanity/ssh
@@ -12,16 +12,15 @@
. $POKYBASE/scripts/qemuimage-testlib
TIMEOUT=360
-QEMU_IPADDR="192.168.7.2"
RET=1
# Start qemu and check its network
-Test_Create_Qemu ${QEMU_IPADDR} ${TIMEOUT}
+Test_Create_Qemu ${TIMEOUT}
# If qemu network is up, check ssh service in qemu
if [ $? -eq 0 ]; then
Test_Info "Begin to Test SSH Service in Qemu"
- Test_SSH_UP ${QEMU_IPADDR} ${TIMEOUT}
+ Test_SSH_UP ${TARGET_IPADDR} ${TIMEOUT}
RET=$?
else
RET=1
diff --git a/scripts/qemuimage-tests/scenario/qemuarm/poky-image-sato b/scripts/qemuimage-tests/scenario/qemuarm/poky-image-sato
index 95a091b74..f6e7cb160 100644
--- a/scripts/qemuimage-tests/scenario/qemuarm/poky-image-sato
+++ b/scripts/qemuimage-tests/scenario/qemuarm/poky-image-sato
@@ -1,2 +1,3 @@
sanity boot
sanity ssh
+sanity dmesg
diff --git a/scripts/qemuimage-tests/scenario/qemuarm/poky-image-sdk b/scripts/qemuimage-tests/scenario/qemuarm/poky-image-sdk
index 95a091b74..f6e7cb160 100644
--- a/scripts/qemuimage-tests/scenario/qemuarm/poky-image-sdk
+++ b/scripts/qemuimage-tests/scenario/qemuarm/poky-image-sdk
@@ -1,2 +1,3 @@
sanity boot
sanity ssh
+sanity dmesg
diff --git a/scripts/qemuimage-tests/scenario/qemumips/poky-image-sato b/scripts/qemuimage-tests/scenario/qemumips/poky-image-sato
index 95a091b74..f6e7cb160 100644
--- a/scripts/qemuimage-tests/scenario/qemumips/poky-image-sato
+++ b/scripts/qemuimage-tests/scenario/qemumips/poky-image-sato
@@ -1,2 +1,3 @@
sanity boot
sanity ssh
+sanity dmesg
diff --git a/scripts/qemuimage-tests/scenario/qemumips/poky-image-sdk b/scripts/qemuimage-tests/scenario/qemumips/poky-image-sdk
index 95a091b74..f6e7cb160 100644
--- a/scripts/qemuimage-tests/scenario/qemumips/poky-image-sdk
+++ b/scripts/qemuimage-tests/scenario/qemumips/poky-image-sdk
@@ -1,2 +1,3 @@
sanity boot
sanity ssh
+sanity dmesg
diff --git a/scripts/qemuimage-tests/scenario/qemuppc/poky-image-sato b/scripts/qemuimage-tests/scenario/qemuppc/poky-image-sato
index 95a091b74..f6e7cb160 100644
--- a/scripts/qemuimage-tests/scenario/qemuppc/poky-image-sato
+++ b/scripts/qemuimage-tests/scenario/qemuppc/poky-image-sato
@@ -1,2 +1,3 @@
sanity boot
sanity ssh
+sanity dmesg
diff --git a/scripts/qemuimage-tests/scenario/qemuppc/poky-image-sdk b/scripts/qemuimage-tests/scenario/qemuppc/poky-image-sdk
index 95a091b74..f6e7cb160 100644
--- a/scripts/qemuimage-tests/scenario/qemuppc/poky-image-sdk
+++ b/scripts/qemuimage-tests/scenario/qemuppc/poky-image-sdk
@@ -1,2 +1,3 @@
sanity boot
sanity ssh
+sanity dmesg
diff --git a/scripts/qemuimage-tests/scenario/qemux86/poky-image-sato b/scripts/qemuimage-tests/scenario/qemux86/poky-image-sato
index 95a091b74..f6e7cb160 100644
--- a/scripts/qemuimage-tests/scenario/qemux86/poky-image-sato
+++ b/scripts/qemuimage-tests/scenario/qemux86/poky-image-sato
@@ -1,2 +1,3 @@
sanity boot
sanity ssh
+sanity dmesg
diff --git a/scripts/qemuimage-tests/scenario/qemux86/poky-image-sdk b/scripts/qemuimage-tests/scenario/qemux86/poky-image-sdk
index 95a091b74..f6e7cb160 100644
--- a/scripts/qemuimage-tests/scenario/qemux86/poky-image-sdk
+++ b/scripts/qemuimage-tests/scenario/qemux86/poky-image-sdk
@@ -1,2 +1,3 @@
sanity boot
sanity ssh
+sanity dmesg
diff --git a/scripts/qemuimage-tests/tools/dmesg.sh b/scripts/qemuimage-tests/tools/dmesg.sh
new file mode 100644
index 000000000..66c022343
--- /dev/null
+++ b/scripts/qemuimage-tests/tools/dmesg.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+# Dmesg test script running in QEMU
+#
+# Author: Jiajun Xu <jiajun.xu@intel.com>
+#
+# This file is licensed under the GNU General Public License,
+# Version 2.
+#
+
+which dmesg
+if [ $? -ne 0 ]; then
+ echo "QEMU: No dmesg command found"
+ exit 1
+fi
+
+dmesg | grep -iq "error"
+if [ $? -eq 0 ]; then
+ echo "QEMU: There is some error log in dmesg:"
+ echo "QEMU: ##### Error Log ######"
+ dmesg | grep -i "error"
+ echo "QEMU: ##### End ######"
+ exit 1
+else
+ echo "QEMU: No error log in dmesg"
+ exit 0
+fi