diff options
Diffstat (limited to 'scripts/qemuimage-testlib')
-rwxr-xr-x | scripts/qemuimage-testlib | 232 |
1 files changed, 231 insertions, 1 deletions
diff --git a/scripts/qemuimage-testlib b/scripts/qemuimage-testlib index 5318ca636c..c39fb7ae21 100755 --- a/scripts/qemuimage-testlib +++ b/scripts/qemuimage-testlib | |||
@@ -19,6 +19,9 @@ TYPE="ext3" | |||
19 | # The folder to hold all scripts running on targets | 19 | # The folder to hold all scripts running on targets |
20 | TOOLS="$COREBASE/scripts/qemuimage-tests/tools" | 20 | TOOLS="$COREBASE/scripts/qemuimage-tests/tools" |
21 | 21 | ||
22 | # The folder to hold all projects for toolchain testing | ||
23 | TOOLCHAIN_PROJECTS="$COREBASE/scripts/qemuimage-tests/toolchain_projects" | ||
24 | |||
22 | # Test Directory on target for testing | 25 | # Test Directory on target for testing |
23 | TARGET_TEST_DIR="/opt/test" | 26 | TARGET_TEST_DIR="/opt/test" |
24 | 27 | ||
@@ -28,6 +31,24 @@ PID=0 | |||
28 | # Global variable for target ip address | 31 | # Global variable for target ip address |
29 | TARGET_IPADDR=0 | 32 | TARGET_IPADDR=0 |
30 | 33 | ||
34 | # Global variable for test project version during toolchain test | ||
35 | # Version of cvs is 1.11.23 | ||
36 | # Version of iptables is 1.4.9 | ||
37 | # Version of sudoku-savant is 1.3 | ||
38 | PROJECT_PV=0 | ||
39 | |||
40 | # Global variable for test project download URL during toolchain test | ||
41 | # URL of cvs is http://ftp.gnu.org/non-gnu/cvs/source/stable/1.11.23/cvs-1.11.23.tar.bz2 | ||
42 | # URL of iptables is http://netfilter.org/projects/iptables/files/iptables-1.4.9.tar.bz2 | ||
43 | # URL of sudoku-savant is http://downloads.sourceforge.net/project/sudoku-savant/sudoku-savant/sudoku-savant-1.3/sudoku-savant-1.3.tar.bz2 | ||
44 | PROJECT_DOWNLOAD_URL=0 | ||
45 | |||
46 | # SDK folder to hold toolchain tarball | ||
47 | TOOLCHAIN_DIR="${DEPLOY_DIR}/sdk" | ||
48 | |||
49 | # Toolchain test folder to hold extracted toolchain tarball | ||
50 | TOOLCHAIN_TEST="/opt" | ||
51 | |||
31 | # common function for information print | 52 | # common function for information print |
32 | Test_Error() | 53 | Test_Error() |
33 | { | 54 | { |
@@ -400,7 +421,7 @@ Test_Create_Qemu() | |||
400 | RUNQEMU=`which runqemu` | 421 | RUNQEMU=`which runqemu` |
401 | else | 422 | else |
402 | Test_Error "Can not find runqemu in \$PATH, return fail" | 423 | Test_Error "Can not find runqemu in \$PATH, return fail" |
403 | exit 1 | 424 | return 1 |
404 | fi | 425 | fi |
405 | 426 | ||
406 | if [ "$QEMUARCH" = "qemux86" -o "$QEMUARCH" = "qemux86-64" ]; then | 427 | if [ "$QEMUARCH" = "qemux86" -o "$QEMUARCH" = "qemux86-64" ]; then |
@@ -499,3 +520,212 @@ Test_Create_Qemu() | |||
499 | return $ret | 520 | return $ret |
500 | fi | 521 | fi |
501 | } | 522 | } |
523 | |||
524 | # Function to prepare test project for toolchain test | ||
525 | # $1 is the folder holding test project file | ||
526 | # $2 is the test project name | ||
527 | Test_Project_Prepare() | ||
528 | { | ||
529 | local toolchain_dir=$1 | ||
530 | local ret=1 | ||
531 | |||
532 | if [ ! -d ${toolchain_dir} ]; then | ||
533 | mkdir -p ${toolchain_dir} | ||
534 | ret=$? | ||
535 | |||
536 | if [ $ret -ne 0 ]; then | ||
537 | Test_Info "Create ${toolchain_dir} fail, return" | ||
538 | return $ret | ||
539 | fi | ||
540 | fi | ||
541 | |||
542 | ret=0 | ||
543 | # Download test project tarball if it does not exist | ||
544 | if [ ! -f ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} ]; then | ||
545 | wget -c -t 5 $PROJECT_DOWNLOAD_URL -O ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} | ||
546 | ret=$? | ||
547 | fi | ||
548 | |||
549 | # Extract the test project into ${TEST_TMP} | ||
550 | if [ $ret -eq 0 ]; then | ||
551 | tar jxf ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} -C ${TEST_TMP} | ||
552 | ret=$? | ||
553 | if [ $ret -eq 0 ]; then | ||
554 | Test_Info "Extract ${2}-${PROJECT_PV}.${suffix} into ${TEST_TMP} successfully" | ||
555 | return $ret | ||
556 | else | ||
557 | Test_Info "Fail to extract ${2}-${PROJECT_PV}.${suffix} into ${TEST_TMP}" | ||
558 | return $ret | ||
559 | fi | ||
560 | else | ||
561 | Test_Info "Fail to download ${2}-${PROJECT_PV}.${suffix} from $PROJECT_DOWNLOAD_URL" | ||
562 | rm -rf ${toolchain_dir}/${2}-${PROJECT_PV}.${suffix} | ||
563 | return $ret | ||
564 | fi | ||
565 | } | ||
566 | |||
567 | # Function to prepare toolchain environment | ||
568 | # $1 is toolchain directory to hold toolchain tarball | ||
569 | # $2 is prefix name for toolchain tarball | ||
570 | Test_Toolchain_Prepare() | ||
571 | { | ||
572 | local toolchain_dir=$1 | ||
573 | local sdk_name=$2 | ||
574 | local ret=1 | ||
575 | |||
576 | if [ ! -d ${toolchain_dir} ]; then | ||
577 | Test_Info "No directory ${toolchain_dir}, which holds toolchain tarballs" | ||
578 | return 1 | ||
579 | fi | ||
580 | |||
581 | # Check if there is any toolchain tarball under $toolchain_dir with prefix $sdk_name | ||
582 | for i in `dir ${toolchain_dir}` | ||
583 | do | ||
584 | echo $i | grep "${sdk_name}-toolchain-gmae" | ||
585 | if [ $? -eq 0 ]; then | ||
586 | rm -rf ${TEST_TMP}/opt | ||
587 | tar jxf ${toolchain_dir}/${i} -C ${TEST_TMP} | ||
588 | ret=$? | ||
589 | break | ||
590 | fi | ||
591 | done | ||
592 | |||
593 | if [ $ret -eq 0 ]; then | ||
594 | Test_Info "Check if /opt is accessible for non-root user" | ||
595 | |||
596 | # Check if the non-root test user has write access of $TOOLCHAIN_TEST | ||
597 | if [ -d ${TOOLCHAIN_TEST} ]; then | ||
598 | touch ${TOOLCHAIN_TEST} | ||
599 | if [ $? -ne 0 ]; then | ||
600 | Test_Info "Has no right to modify folder $TOOLCHAIN_TEST, pls. chown it to test user" | ||
601 | return 2 | ||
602 | fi | ||
603 | else | ||
604 | mkdir -p ${TOOLCHAIN_TEST} | ||
605 | if [ $? -ne 0 ]; then | ||
606 | Test_Info "Has no right to create folder $TOOLCHAIN_TEST, pls. create it and chown it to test user" | ||
607 | return 2 | ||
608 | fi | ||
609 | fi | ||
610 | |||
611 | # If there is a toolchain folder under $TOOLCHAIN_TEST, let's remove it | ||
612 | if [ -d ${TOOLCHAIN_TEST}/poky ]; then | ||
613 | rm -rf ${TOOLCHAIN_TEST}/poky | ||
614 | fi | ||
615 | |||
616 | # Copy toolchain into $TOOLCHAIN_TEST | ||
617 | cp -r ${TEST_TMP}/opt/poky ${TOOLCHAIN_TEST} | ||
618 | ret=$? | ||
619 | |||
620 | if [ $ret -eq 0 ]; then | ||
621 | Test_Info "Successfully copy toolchain into $TOOLCHAIN_TEST" | ||
622 | return $ret | ||
623 | else | ||
624 | Test_Info "Meet error when copy toolchain into $TOOLCHAIN_TEST" | ||
625 | return $ret | ||
626 | fi | ||
627 | else | ||
628 | Test_Info "No tarball named ${sdk_name}-toolchain-gmae under ${toolchain_dir}" | ||
629 | return $ret | ||
630 | fi | ||
631 | } | ||
632 | |||
633 | # Function to execute command and exit if run out of time | ||
634 | # $1 is timeout value | ||
635 | # $2 is the command to be executed | ||
636 | Test_Time_Out() | ||
637 | { | ||
638 | local timeout=$1 | ||
639 | shift | ||
640 | local command=$* | ||
641 | local date=0 | ||
642 | local tmp=`mktemp` | ||
643 | local ret=1 | ||
644 | |||
645 | # Run command in background | ||
646 | ($command; echo $? > $tmp) & | ||
647 | while ps -e -o pid | grep -qw $!; do | ||
648 | if [ $date -ge $timeout ]; then | ||
649 | Test_Info "$timeout Timeout when running command $command" | ||
650 | rm -rf $tmp | ||
651 | return 1 | ||
652 | fi | ||
653 | sleep 5 | ||
654 | date=`expr $date + 5` | ||
655 | done | ||
656 | ret=`cat $tmp` | ||
657 | rm -rf $tmp | ||
658 | return $ret | ||
659 | } | ||
660 | |||
661 | # Function to test toolchain | ||
662 | # $1 is test project name | ||
663 | # $2 is the timeout value | ||
664 | Test_Toolchain() | ||
665 | { | ||
666 | local test_project=$1 | ||
667 | local timeout=$2 | ||
668 | local ret=1 | ||
669 | local suffix="tar.bz2" | ||
670 | local env_setup="" | ||
671 | local pro_install="${TEST_TMP}/pro_install" | ||
672 | |||
673 | # Set value for PROJECT_PV and PROJECT_DOWNLOAD_URL accordingly | ||
674 | if [ $test_project == "cvs" ]; then | ||
675 | PROJECT_PV=1.11.23 | ||
676 | PROJECT_DOWNLOAD_URL="http://ftp.gnu.org/non-gnu/cvs/source/stable/1.11.23/cvs-1.11.23.tar.bz2" | ||
677 | elif [ $test_project == "iptables" ]; then | ||
678 | PROJECT_PV=1.4.9 | ||
679 | PROJECT_DOWNLOAD_URL="http://netfilter.org/projects/iptables/files/iptables-1.4.9.tar.bz2" | ||
680 | elif [ $test_project == "sudoku-savant" ]; then | ||
681 | PROJECT_PV=1.3 | ||
682 | PROJECT_DOWNLOAD_URL="http://downloads.sourceforge.net/project/sudoku-savant/sudoku-savant/sudoku-savant-1.3/sudoku-savant-1.3.tar.bz2" | ||
683 | else | ||
684 | Test_Info "Unknown test project name $test_project" | ||
685 | return 1 | ||
686 | fi | ||
687 | |||
688 | # Download test project and extract it | ||
689 | Test_Project_Prepare $TOOLCHAIN_PROJECTS $test_project | ||
690 | if [ $? -ne 0 ]; then | ||
691 | Test_Info "Prepare test project file failed" | ||
692 | return 1 | ||
693 | fi | ||
694 | |||
695 | # Extract toolchain tarball into ${TEST_TMP} | ||
696 | Test_Toolchain_Prepare $TOOLCHAIN_DIR $SDK_NAME | ||
697 | ret=$? | ||
698 | if [ $ret -ne 0 ]; then | ||
699 | Test_Info "Prepare toolchain test environment failed" | ||
700 | return $ret | ||
701 | fi | ||
702 | |||
703 | if [ ! -d ${pro_install} ]; then | ||
704 | mkdir -p ${pro_install} | ||
705 | fi | ||
706 | |||
707 | # Begin to build test project in toolchain environment | ||
708 | env_setup=`find ${TOOLCHAIN_TEST}/poky -name "environment-setup*"` | ||
709 | |||
710 | source $env_setup | ||
711 | |||
712 | if [ $test_project == "cvs" -o $test_project == "iptables" ]; then | ||
713 | cd ${TEST_TMP}/${test_project}-${PROJECT_PV} | ||
714 | Test_Time_Out $timeout ./configure ${CONFIGURE_FLAGS} || { Test_Info "configure failed with $test_project"; return 1; } | ||
715 | Test_Time_Out $timeout make -j4 || { Test_Info "make failed with $test_project"; return 1; } | ||
716 | Test_Time_Out $timeout make install DESTDIR=${pro_install} || { Test_Info "make failed with $test_project"; return 1; } | ||
717 | cd - | ||
718 | ret=0 | ||
719 | elif [ $test_project == "sudoku-savant" ]; then | ||
720 | cd ${TEST_TMP}/${test_project}-${PROJECT_PV} | ||
721 | Test_Time_Out $timeout ./configure ${CONFIGURE_FLAGS} || { Test_Info "configure failed with $test_project"; return 1; } | ||
722 | Test_Time_Out $timeout make -j4 || { Test_Info "make failed with $test_project"; return 1; } | ||
723 | cd - | ||
724 | ret=0 | ||
725 | else | ||
726 | Test_Info "Unknown test project $test_project" | ||
727 | ret=1 | ||
728 | fi | ||
729 | |||
730 | return $ret | ||
731 | } | ||