qemuimage-testlib 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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. TYPE="ext3"
  17. # The folder to hold all scripts running on targets
  18. TOOLS="$COREBASE/scripts/qemuimage-tests/tools"
  19. # The folder to hold all projects for toolchain testing
  20. TOOLCHAIN_PROJECTS="$COREBASE/scripts/qemuimage-tests/toolchain_projects"
  21. # Test Directory on target for testing
  22. TARGET_TEST_DIR="/opt/test"
  23. # Global variables for process id
  24. XTERMPID=0
  25. QEMUPID=0
  26. # Global variable for target ip address
  27. TARGET_IPADDR=0
  28. # Global variable for test project version during toolchain test
  29. # Version of cvs is 1.12.13
  30. # Version of iptables is 1.4.11
  31. # Version of sudoku-savant is 1.3
  32. PROJECT_PV=0
  33. # Global variable for test project download URL during toolchain test
  34. # URL of cvs is http://ftp.gnu.org/non-gnu/cvs/source/feature/1.12.13/cvs-1.12.13.tar.bz2
  35. # URL of iptables is http://netfilter.org/projects/iptables/files/iptables-1.4.11.tar.bz2
  36. # URL of sudoku-savant is http://downloads.sourceforge.net/project/sudoku-savant/sudoku-savant/sudoku-savant-1.3/sudoku-savant-1.3.tar.bz2
  37. PROJECT_DOWNLOAD_URL=0
  38. # SDK folder to hold toolchain tarball
  39. TOOLCHAIN_DIR="${DEPLOY_DIR}/sdk"
  40. # Toolchain test folder to hold extracted toolchain tarball
  41. TOOLCHAIN_TEST="/opt"
  42. # common function for information print
  43. Test_Error()
  44. {
  45. echo -e "\tTest_Error: $*"
  46. }
  47. Test_Info()
  48. {
  49. echo -e "\tTest_Info: $*"
  50. }
  51. # function to update target ip address
  52. # $1 is the process id of the process, which starts the qemu target
  53. # $2 is the ip address of the target
  54. Test_Update_IPSAVE()
  55. {
  56. local pid=$1
  57. local ip_addr=$2
  58. if [ "$TEST_SERIALIZE" -eq 1 -a "$pid" != "0" -a "$pid" != "" -a "$ip_addr" != "" -a "$ip_addr" != "" ]; then
  59. echo "Saving $pid $ip_addr to $TARGET_IPSAVE"
  60. echo "$pid $ip_addr" > $TARGET_IPSAVE
  61. fi
  62. }
  63. # function to copy files from host into target
  64. # $1 is the ip address of target
  65. # $2 is the files, which need to be copied into target
  66. # $3 is the path on target, where files are copied into
  67. Test_SCP()
  68. {
  69. local ip_addr=$1
  70. local src=$2
  71. local des=$3
  72. local time_out=60
  73. local ret=0
  74. # We use expect to interactive with target by ssh
  75. local exp_cmd=`cat << EOF
  76. eval spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$src" root@$ip_addr:"$des"
  77. set timeout $time_out
  78. expect {
  79. "*assword:" { send "\r"; exp_continue}
  80. "*(yes/no)?" { send "yes\r"; exp_continue }
  81. eof { exit [ lindex [wait] 3 ] }
  82. }
  83. EOF`
  84. expect=`which expect`
  85. if [ ! -x "$expect" ]; then
  86. Test_Error "ERROR: Please install expect"
  87. return 1
  88. fi
  89. expect -c "$exp_cmd"
  90. ret=$?
  91. return $ret
  92. }
  93. # function to copy files from target to host
  94. # $1 is the ip address of target
  95. # $2 is the files, which need to be copied into target
  96. # $3 is the path on target, where files are copied into
  97. Test_SCP_From()
  98. {
  99. local ip_addr=$1
  100. local src=$2
  101. local des=$3
  102. local time_out=60
  103. local ret=0
  104. # We use expect to interactive with target by ssh
  105. local exp_cmd=`cat << EOF
  106. eval spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$ip_addr:"$src" "$des"
  107. set timeout $time_out
  108. expect {
  109. "*assword:" { send "\r"; exp_continue}
  110. "*(yes/no)?" { send "yes\r"; exp_continue }
  111. eof { exit [ lindex [wait] 3 ] }
  112. }
  113. EOF`
  114. expect=`which expect`
  115. if [ ! -x "$expect" ]; then
  116. Test_Error "ERROR: Please install expect"
  117. return 1
  118. fi
  119. expect -c "$exp_cmd"
  120. ret=$?
  121. return $ret
  122. }
  123. # function to run command in $ip_addr via ssh
  124. Test_SSH()
  125. {
  126. local ip_addr=$1
  127. shift
  128. local command=$@
  129. local time_out=60
  130. local ret=0
  131. local exp_cmd=`cat << EOF
  132. eval spawn ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$ip_addr "$command"
  133. set timeout $time_out
  134. expect {
  135. "*assword:" { send "\r"; exp_continue}
  136. "*(yes/no)?" { send "yes\r"; exp_continue }
  137. eof { exit [ lindex [wait] 3 ] }
  138. }
  139. EOF`
  140. expect=`which expect`
  141. if [ ! -x "$expect" ]; then
  142. Test_Error "ERROR: Please install expect"
  143. return 1
  144. fi
  145. expect -c "$exp_cmd"
  146. ret=$?
  147. return $ret
  148. }
  149. # function to check if ssh is up in $ip_addr
  150. Test_SSH_UP()
  151. {
  152. local ip_addr=$1
  153. local timeout=$2
  154. local interval=0
  155. # If TEST_SERIALIZE is set, use existing running qemu for testing
  156. if [ ${TEST_SERIALIZE} -eq 1 -a -e ${TARGET_IPSAVE} ]; then
  157. timeout=50
  158. fi
  159. while [ ${interval} -lt ${timeout} ]
  160. do
  161. Test_SSH ${ip_addr} "hostname"
  162. if [ $? -ne 0 ]; then
  163. interval=`expr $interval + 10`
  164. sleep 10
  165. else
  166. Test_Info "We can ssh on ${ip_addr} within ${interval} seconds"
  167. return 0
  168. fi
  169. done
  170. Test_Info "We can not ssh on ${ip_addr} in ${timeout} seconds"
  171. return 1
  172. }
  173. # function to prepare target test environment
  174. # $1 is the ip address of target system
  175. # $2 is the files, which needs to be copied into target
  176. Test_Target_Pre()
  177. {
  178. local ip_addr=$1
  179. local testscript=$2
  180. # Create a pre-defined folder for test scripts
  181. Test_SSH $ip_addr "mkdir -p $TARGET_TEST_DIR"
  182. if [ $? -eq 0 ]; then
  183. # Copy test scripts into target
  184. Test_SCP $ip_addr $testscript $TARGET_TEST_DIR && return 0
  185. else
  186. Test_Error "Fail to create $TARGET_TEST_DIR on target"
  187. return 1
  188. fi
  189. return 1
  190. }
  191. # function to record test result in $TEST_RESULT/testresult.log
  192. Test_Print_Result()
  193. {
  194. local PASS=0
  195. local FAIL=0
  196. local NORESULT=0
  197. if [ $2 -eq 0 ]; then
  198. PASS=1
  199. elif [ $2 -eq 1 ]; then
  200. FAIL=1
  201. else
  202. NORESULT=1
  203. fi
  204. # Format the output of the test result
  205. echo -e "$1 $PASS $FAIL $NORESULT" | awk '{printf("\t"); for(i=1;i<=NF;i++) printf("%-15s",$i); printf("\n");}' >> $TEST_RESULT/testresult.log
  206. }
  207. # Test_Kill_Qemu to kill child pid with parent pid given
  208. # $1 is qemu process id, which needs to be killed
  209. Test_Kill_Qemu()
  210. {
  211. local index=0
  212. local total=0
  213. local k=0
  214. # When TEST_SERIALIZE is set, qemu process will not be
  215. # killed until all the cases are finished
  216. if [ ${TEST_SERIALIZE} -eq 1 -a -e ${TEST_STATUS} ]; then
  217. index=`sed -n 2p ${TEST_STATUS} | awk '{print $3}'`
  218. total=`sed -n 2p ${TEST_STATUS} | awk '{print $4}'`
  219. if [ ${index} != ${total} ]; then
  220. Test_Info "Do not kill the qemu process and use it for later testing (step $index of $total)"
  221. Test_Update_IPSAVE $XTERMPID $TARGET_IPADDR
  222. else
  223. k=1
  224. fi
  225. else
  226. k=1
  227. fi
  228. if [ $k -eq 1 ]; then
  229. if [ "$QEMUPID" != "0" -a "$QEMUPID" != "" ]; then
  230. running=`ps -wwfp $QEMUPID`
  231. if [ $? -eq 0 ]; then
  232. echo "killing $QEMUPID"
  233. kill $QEMUPID
  234. fi
  235. fi
  236. if [ "$XTERMPID" != "0" -a "$XTERMPID" != "" ]; then
  237. running=`ps -wwfp $XTERMPID`
  238. if [ $? -eq 0 ]; then
  239. echo "killing $XTERMPID"
  240. kill $XTERMPID
  241. fi
  242. fi
  243. fi
  244. return
  245. }
  246. # function to check if network is up
  247. Test_Check_IP_UP()
  248. {
  249. ping -c1 $1 1> /dev/null
  250. if [ $? -ne 0 ]; then
  251. Test_Info "IP $1 is not up"
  252. return 1
  253. else
  254. Test_Info "IP $1 is up"
  255. return 0
  256. fi
  257. }
  258. # function to find kernel/rootfs image
  259. Test_Find_Image()
  260. {
  261. where=""
  262. kernel=""
  263. arch=""
  264. target=""
  265. extension=""
  266. rootfs=""
  267. while getopts "l:k:a:t:" Option
  268. do
  269. case $Option in
  270. l) where="$OPTARG"
  271. ;;
  272. k) kernel="$OPTARG"
  273. extension="bin"
  274. ;;
  275. a) arch="$OPTARG"
  276. ;;
  277. t) target="$OPTARG"
  278. extension="ext3"
  279. ;;
  280. *) echo "invalid option: -$Option" && return 1
  281. ;;
  282. esac
  283. done
  284. if [ ! -z $kernel ]; then
  285. if [ -L ${where}/${kernel}-${arch}.${extension} ]; then
  286. echo ${where}/${kernel}-${arch}.${extension}
  287. return 0
  288. else
  289. for i in `dir ${where}`
  290. do
  291. # Exclude qemux86-64 when target is qemux86
  292. echo $i | grep "${kernel}.*${arch}.*\.${extension}" | grep -qv "${kernel}.*${arch}-64.*\.${extension}"
  293. if [ $? -eq 0 ]; then
  294. echo ${where}/${i}
  295. return 0
  296. fi
  297. done
  298. return 1
  299. fi
  300. fi
  301. if [ ! -z $target ]; then
  302. if [ -L ${where}/${target}-${arch}.${extension} ]; then
  303. rootfs=`readlink -f ${where}/${target}-${arch}.${extension}`
  304. echo ${rootfs}
  305. return 0
  306. else
  307. for i in `dir ${where}`
  308. do
  309. # Exclude qemux86-64 when target is qemux86
  310. echo $i | grep "${target}-${arch}.*\.${extension}" | grep -qv "${target}-${arch}-64.*\.${extension}"
  311. if [ $? -eq 0 ]; then
  312. echo ${where}/${i}
  313. return 0
  314. fi
  315. done
  316. return 1
  317. fi
  318. fi
  319. return 1
  320. }
  321. # function to parse IP address of target
  322. # $1 is the pid of qemu startup process
  323. Test_Fetch_Target_IP()
  324. {
  325. local opid=$1
  326. local ip_addr=0
  327. if [ "$opid" = "0" -o "$opid" = "" ]; then
  328. echo ""
  329. return
  330. fi
  331. # Check if $1 pid exists and contains ipaddr of target
  332. ip_addr=`ps -wwfp $opid | grep -o "192\.168\.7\.[0-9]*::" | awk -F":" '{print $1}'`
  333. echo $ip_addr
  334. return
  335. }
  336. # function to check if qemu and its network
  337. Test_Create_Qemu()
  338. {
  339. local timeout=$1
  340. local up_time=0
  341. RUNQEMU=`which runqemu`
  342. if [ $? -ne 0 ]; then
  343. Test_Error "Can not find runqemu in \$PATH, return fail"
  344. return 1
  345. fi
  346. if [ "$QEMUARCH" = "qemux86" -o "$QEMUARCH" = "qemux86-64" ]; then
  347. KERNEL=$(Test_Find_Image -l ${DEPLOY_DIR}/images -k bzImage -a ${QEMUARCH})
  348. elif [ "$QEMUARCH" = "qemuarm" -o "$QEMUARCH" = "spitz" -o "$QEMUARCH" = "borzoi" -o "$QEMUARCH" = "akita" -o "$QEMUARCH" = "nokia800" ]; then
  349. KERNEL=$(Test_Find_Image -l ${DEPLOY_DIR}/images -k zImage -a ${QEMUARCH})
  350. elif [ "$QEMUARCH" = "qemumips" -o "$QEMUARCH" = "qemuppc" ]; then
  351. KERNEL=$(Test_Find_Image -l ${DEPLOY_DIR}/images -k vmlinux -a ${QEMUARCH})
  352. fi
  353. # If there is no kernel image found, return failed directly
  354. if [ $? -eq 1 ]; then
  355. Test_Info "No kernel image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check"
  356. return 1
  357. fi
  358. ROOTFS_IMAGE=$(Test_Find_Image -l ${DEPLOY_DIR}/images -t ${QEMUTARGET} -a ${QEMUARCH})
  359. # If there is no rootfs image found, return failed directly
  360. if [ $? -eq 1 ]; then
  361. Test_Info "No ${QEMUTARGET} rootfs image file found under ${DEPLOY_DIR}/images for ${QEMUARCH}, pls. have a check"
  362. return 1
  363. fi
  364. TEST_ROOTFS_IMAGE="${TEST_TMP}/${QEMUTARGET}-${QEMUARCH}-test.ext3"
  365. CP=`which cp`
  366. # When TEST_SERIALIZE is set, we use the existing image under tmp folder
  367. if [ ${TEST_SERIALIZE} -eq 1 -a -e "$TARGET_IPSAVE" ]; then
  368. # If TARGET_IPSAVE exists, check PID of the qemu process from it
  369. XTERMPID=`awk '{print $1}' $TARGET_IPSAVE`
  370. timeout=50
  371. else
  372. rm -rf $TEST_ROOTFS_IMAGE
  373. echo "Copying rootfs $ROOTFS_IMAGE to $TEST_ROOTFS_IMAGE"
  374. $CP $ROOTFS_IMAGE $TEST_ROOTFS_IMAGE
  375. if [ $? -ne 0 ]; then
  376. Test_Info "Image ${ROOTFS_IMAGE} copy to ${TEST_ROOTFS_IMAGE} failed, return fail"
  377. return 1
  378. fi
  379. export MACHINE=$QEMUARCH
  380. # Create Qemu in localhost VNC Port 1
  381. echo "Running xterm -display ${DISPLAY} -e 'OE_TMPDIR=${OE_TMPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE} 2>&1 | tee ${RUNQEMU_LOGFILE} || /bin/sleep 60' &"
  382. xterm -display ${DISPLAY} -e "OE_TMPDIR=${OE_TMPDIR} ${RUNQEMU} ${KERNEL} ${TEST_ROOTFS_IMAGE} 2>&1 | tee ${RUNQEMU_LOGFILE} || /bin/sleep 60" &
  383. # Get the pid of the xterm processor, which will be used in Test_Kill_Qemu
  384. XTERMPID=$!
  385. echo "XTERMPID is $XTERMPID"
  386. # When starting, qemu can reexecute itself and change PID so wait a short while for things to settle
  387. sleep 5
  388. fi
  389. while [ ${up_time} -lt 30 ]
  390. do
  391. QEMUPID=`qemuimage-testlib-pythonhelper --findqemu $XTERMPID 2>/dev/null`
  392. if [ $? -ne 0 ]; then
  393. Test_Info "Wait for qemu up..."
  394. up_time=`expr $up_time + 5`
  395. sleep 5
  396. else
  397. Test_Info "Begin to check if qemu network is up"
  398. echo "QEMUPID is $QEMUPID"
  399. break
  400. fi
  401. done
  402. if [ ${up_time} == 30 ]; then
  403. Test_Info "No qemu process appeared to start, exiting"
  404. ps axww -O ppid
  405. Test_Info "Process list dumped for debugging purposes"
  406. Test_Info "runqemu output log:"
  407. cat ${RUNQEMU_LOGFILE}
  408. echo
  409. return 1
  410. fi
  411. up_time=0
  412. # Parse IP address of target from the qemu command line
  413. TARGET_IPADDR=`Test_Fetch_Target_IP $QEMUPID`
  414. echo "Target IP is ${TARGET_IPADDR}"
  415. if [ "${TARGET_IPADDR}" = "" -o "${TARGET_IPADDR}" = "0" ]; then
  416. Test_Info "There is no qemu process or qemu ip address found, return failed"
  417. ps -wwf
  418. ps axww -O ppid
  419. Test_Info "runqemu output log:"
  420. cat ${RUNQEMU_LOGFILE}
  421. echo
  422. return 1
  423. fi
  424. while [ ${up_time} -lt ${timeout} ]
  425. do
  426. Test_Check_IP_UP ${TARGET_IPADDR}
  427. if [ $? -eq 0 ]; then
  428. Test_Info "Qemu Network is up, ping with ${TARGET_IPADDR} is OK within ${up_time} seconds"
  429. return 0
  430. else
  431. Test_Info "Wait for Qemu Network up"
  432. up_time=`expr $up_time + 5`
  433. sleep 5
  434. fi
  435. done
  436. Test_Info "Process list dumped for debugging purposes:"
  437. ps axww -O ppid
  438. Test_Info "runqemu output log:"
  439. cat ${RUNQEMU_LOGFILE}
  440. Test_Info "Qemu or its network is not up in ${timeout} seconds"
  441. Test_Update_IPSAVE $XTERMPID $TARGET_IPADDR
  442. return 1
  443. }
  444. # Function to prepare test project for toolchain test
  445. # $1 is the folder holding test project file
  446. # $2 is the test project name
  447. Test_Project_Prepare()
  448. {
  449. local toolchain_dir=$1
  450. if [ ! -d ${toolchain_dir} ]; then
  451. mkdir -p ${toolchain_dir}
  452. if [ $? -ne 0 ]; then
  453. ret=$?
  454. Test_Info "Create ${toolchain_dir} fail, return"
  455. return $ret
  456. fi
  457. fi
  458. # Download test project tarball if it does not exist
  459. if [ ! -f ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} ]; then
  460. wget -c -t 5 $PROJECT_DOWNLOAD_URL -O ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix}
  461. if [ $? -ne 0 ]; then
  462. ret=$?
  463. Test_Info "Fail to download ${2}-${PROJECT_PV}.${suffix} from $PROJECT_DOWNLOAD_URL"
  464. rm -rf ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix}
  465. return $ret
  466. fi
  467. fi
  468. # Extract the test project into ${TEST_TMP}
  469. tar jxf ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} -C ${TEST_TMP}
  470. if [ $? -ne 0 ]; then
  471. ret=$?
  472. Test_Info "Fail to extract ${2}-${PROJECT_PV}.${suffix} into ${TEST_TMP}"
  473. return $ret
  474. fi
  475. Test_Info "Extract ${2}-${PROJECT_PV}.${suffix} into ${TEST_TMP} successfully"
  476. return 0
  477. }
  478. # Function to prepare toolchain environment
  479. # $1 is toolchain directory to hold toolchain tarball
  480. # $2 is prefix name for toolchain tarball
  481. Test_Toolchain_Prepare()
  482. {
  483. local toolchain_dir=$1
  484. local sdk_name=$2
  485. local ret=1
  486. if [ ! -d ${toolchain_dir} ]; then
  487. Test_Info "No directory ${toolchain_dir}, which holds toolchain tarballs"
  488. return 1
  489. fi
  490. # Check if there is any toolchain tarball under $toolchain_dir with prefix $sdk_name
  491. for i in `dir ${toolchain_dir}`
  492. do
  493. echo $i | grep "${sdk_name}-toolchain-gmae"
  494. if [ $? -eq 0 ]; then
  495. rm -rf ${TEST_TMP}/opt
  496. tar jxf ${toolchain_dir}/${i} -C ${TEST_TMP}
  497. ret=$?
  498. break
  499. fi
  500. done
  501. if [ $ret -eq 0 ]; then
  502. Test_Info "Check if /opt is accessible for non-root user"
  503. # Check if the non-root test user has write access of $TOOLCHAIN_TEST
  504. if [ -d ${TOOLCHAIN_TEST} ]; then
  505. touch ${TOOLCHAIN_TEST}
  506. if [ $? -ne 0 ]; then
  507. Test_Info "Has no right to modify folder $TOOLCHAIN_TEST, pls. chown it to test user"
  508. return 2
  509. fi
  510. else
  511. mkdir -p ${TOOLCHAIN_TEST}
  512. if [ $? -ne 0 ]; then
  513. Test_Info "Has no right to create folder $TOOLCHAIN_TEST, pls. create it and chown it to test user"
  514. return 2
  515. fi
  516. fi
  517. # If there is a toolchain folder under $TOOLCHAIN_TEST, let's remove it
  518. if [ -d ${TOOLCHAIN_TEST}/poky ]; then
  519. rm -rf ${TOOLCHAIN_TEST}/poky
  520. fi
  521. # Copy toolchain into $TOOLCHAIN_TEST
  522. cp -r ${TEST_TMP}/opt/poky ${TOOLCHAIN_TEST}
  523. ret=$?
  524. if [ $ret -eq 0 ]; then
  525. Test_Info "Successfully copy toolchain into $TOOLCHAIN_TEST"
  526. return $ret
  527. else
  528. Test_Info "Meet error when copy toolchain into $TOOLCHAIN_TEST"
  529. return $ret
  530. fi
  531. else
  532. Test_Info "No tarball named ${sdk_name}-toolchain-gmae under ${toolchain_dir}"
  533. return $ret
  534. fi
  535. }
  536. # Function to execute command and exit if run out of time
  537. # $1 is timeout value
  538. # $2 is the command to be executed
  539. Test_Time_Out()
  540. {
  541. local timeout=$1
  542. shift
  543. local command=$*
  544. local date=0
  545. local tmp=`mktemp`
  546. local ret=1
  547. local pid=0
  548. local ppid=0
  549. local i=0
  550. declare local pid_l
  551. # Run command in background
  552. ($command; echo $? > $tmp) &
  553. pid=$!
  554. while ps -e -o pid | grep -qw $pid; do
  555. if [ $date -ge $timeout ]; then
  556. Test_Info "$timeout Timeout when running command $command"
  557. rm -rf $tmp
  558. # Find all child processes of pid and kill them
  559. ppid=$pid
  560. ps -f --ppid $ppid
  561. ret=$?
  562. while [ $ret -eq 0 ]
  563. do
  564. # If yes, get the child pid and check if the child pid has other child pid
  565. # Continue the while loop until there is no child pid found
  566. pid_l[$i]=`ps -f --ppid $ppid | awk '{if ($2 != "PID") print $2}'`
  567. ppid=${pid_l[$i]}
  568. i=$((i+1))
  569. ps -f --ppid $ppid
  570. ret=$?
  571. done
  572. # Kill these children pids from the last one
  573. while [ $i -ne 0 ]
  574. do
  575. i=$((i-1))
  576. kill ${pid_l[$i]}
  577. sleep 2
  578. done
  579. # Kill the parent id
  580. kill $pid
  581. return 1
  582. fi
  583. sleep 5
  584. date=`expr $date + 5`
  585. done
  586. ret=`cat $tmp`
  587. rm -rf $tmp
  588. return $ret
  589. }
  590. # Function to test toolchain
  591. # $1 is test project name
  592. # $2 is the timeout value
  593. Test_Toolchain()
  594. {
  595. local test_project=$1
  596. local timeout=$2
  597. local ret=1
  598. local suffix="tar.bz2"
  599. local env_setup=""
  600. local pro_install="${TEST_TMP}/pro_install"
  601. # Set value for PROJECT_PV and PROJECT_DOWNLOAD_URL accordingly
  602. if [ $test_project == "cvs" ]; then
  603. PROJECT_PV=1.12.13
  604. PROJECT_DOWNLOAD_URL="http://ftp.gnu.org/non-gnu/cvs/source/feature/1.12.13/cvs-1.12.13.tar.bz2"
  605. elif [ $test_project == "iptables" ]; then
  606. PROJECT_PV=1.4.11
  607. PROJECT_DOWNLOAD_URL="http://netfilter.org/projects/iptables/files/iptables-1.4.11.tar.bz2"
  608. elif [ $test_project == "sudoku-savant" ]; then
  609. PROJECT_PV=1.3
  610. PROJECT_DOWNLOAD_URL="http://downloads.sourceforge.net/project/sudoku-savant/sudoku-savant/sudoku-savant-1.3/sudoku-savant-1.3.tar.bz2"
  611. else
  612. Test_Info "Unknown test project name $test_project"
  613. return 1
  614. fi
  615. # Download test project and extract it
  616. Test_Project_Prepare $TOOLCHAIN_PROJECTS $test_project
  617. if [ $? -ne 0 ]; then
  618. Test_Info "Prepare test project file failed"
  619. return 1
  620. fi
  621. # Extract toolchain tarball into ${TEST_TMP}
  622. Test_Toolchain_Prepare $TOOLCHAIN_DIR $SDK_NAME
  623. ret=$?
  624. if [ $ret -ne 0 ]; then
  625. Test_Info "Prepare toolchain test environment failed"
  626. return $ret
  627. fi
  628. if [ ! -d ${pro_install} ]; then
  629. mkdir -p ${pro_install}
  630. fi
  631. # Begin to build test project in toolchain environment
  632. env_setup=`find ${TOOLCHAIN_TEST}/poky -name "environment-setup*"`
  633. source $env_setup
  634. if [ $test_project == "cvs" -o $test_project == "iptables" ]; then
  635. cd ${TEST_TMP}/${test_project}-${PROJECT_PV}
  636. Test_Time_Out $timeout ./configure ${CONFIGURE_FLAGS} || { Test_Info "configure failed with $test_project"; return 1; }
  637. Test_Time_Out $timeout make -j4 || { Test_Info "make failed with $test_project"; return 1; }
  638. Test_Time_Out $timeout make install DESTDIR=${pro_install} || { Test_Info "make failed with $test_project"; return 1; }
  639. cd -
  640. ret=0
  641. elif [ $test_project == "sudoku-savant" ]; then
  642. cd ${TEST_TMP}/${test_project}-${PROJECT_PV}
  643. Test_Time_Out $timeout ./configure ${CONFIGURE_FLAGS} || { Test_Info "configure failed with $test_project"; return 1; }
  644. Test_Time_Out $timeout make -j4 || { Test_Info "make failed with $test_project"; return 1; }
  645. cd -
  646. ret=0
  647. else
  648. Test_Info "Unknown test project $test_project"
  649. ret=1
  650. fi
  651. return $ret
  652. }
  653. Test_Display_Syslog()
  654. {
  655. local tmplog=`mktemp`
  656. Test_SCP_From ${TARGET_IPADDR} /var/log/messages $tmplog
  657. echo "System logs:"
  658. cat $tmplog
  659. rm -f $tmplog
  660. }