application-lifecycle: replace continue by return
[src/qa-testdefinitions.git] / common / scripts / application-lifecycle.sh
index bf9d575..72be11f 100755 (executable)
@@ -5,7 +5,11 @@ set -x
 export TERM=dumb
 export COLUMNS=1000
 
-AGLDRIVER=agl-driver
+export AGLDRIVER=agl-driver
+
+# for pyagl - unless redefined in a test
+export AGL_AVAILABLE_INTERFACES="ethernet"
+export AGL_CAN_INTERFACE="vcan0"
 
 while [ $# -ge 1 ]
 do
@@ -83,6 +87,7 @@ done
 
 inspect_wgt() {
        wgtfile=$1
+       WGTNAME=$2
 
        export SERVICE_PLATFORM=0
        export SERVICE_USER=0
@@ -120,6 +125,15 @@ inspect_wgt() {
                    export APPLICATION_USER=1
                    # no other type known (yet)
                fi
+               # the file naming convention is servicename.wgt
+               # but some didnt respect it
+               export WGTSERVICENAME=$(grep 'id=.*' config.xml | sed 's,^.*id=,id=,' | cut -d= -f2 | cut -d'"' -f2)
+               if [ -z "$WGTSERVICENAME" ];then
+                       echo "WARN: failed to find name in config.xml, fallback to filename"
+                       export WGTSERVICENAME="$WGTNAME"
+               else
+                       echo "DEBUG: detected service name as $WGTSERVICENAME"
+               fi
        else
                echo "DEBUG: fail to unzip"
        fi
@@ -163,15 +177,15 @@ do_release_test() {
        afm-util list --all > $LIST
        if [ $? -ne 0 ];then
                echo "ERROR: afm-util list exit with error"
-               continue
+               return 1
        fi
        if [ ! -s "$LIST" ];then
                echo "ERROR: afm-util list is empty"
-               continue
+               return 1
        fi
 
        echo "DEBUG: check presence of $WGTNAME"
-       NAMEID=$(grep id\\\":\\\"${WGTNAME}\" $LIST | cut -d\" -f4 | cut -d\\ -f1)
+       NAMEID=$(grep id\\\":\\\"${WGTSERVICENAME}\" $LIST | cut -d\" -f4 | cut -d\\ -f1)
        if [ ! -z "$NAMEID" ];then
                echo "DEBUG: $WGTNAME already installed as $NAMEID"
                # need to kill then deinstall
@@ -211,29 +225,29 @@ do_release_test() {
        if [ $? -ne 0 ];then
                echo "ERROR: afm-util install"
                lava-test-case afm-util-install-$WGTNAMEF --result fail
-               continue
+               return 1
        else
                lava-test-case afm-util-install-$WGTNAMEF --result pass
        fi
        # message is like \"added\":\"mediaplayer@0.1\"
-       NAMEID=$(grep d\\\":\\\"${WGTNAME}\" $OUT | cut -d\" -f4 | cut -d\\ -f1)
+       NAMEID=$(grep d\\\":\\\"${WGTSERVICENAME}\" $OUT | cut -d\" -f4 | cut -d\\ -f1)
        if [ -z "$NAMEID" ];then
                echo "ERROR: Cannot get nameid"
                echo "DEBUG: ========== DUMPING output =========="
                cat $OUT
                echo "DEBUG: ========== END DUMP =========="
-               continue
+               return 1
        fi
        echo "DEBUG: $WGTNAME is installed as $NAMEID"
 
        afm-util list --all > $LIST
        if [ $? -ne 0 ];then
                echo "ERROR: afm-util list exit with error"
-               continue
+               return 1
        fi
        if [ ! -s "$LIST" ];then
                echo "ERROR: afm-util list is empty"
-               continue
+               return 1
        fi
        echo "DEBUG: Verify that $WGTNAME is installed"
        grep -q $NAMEID $LIST
@@ -264,7 +278,7 @@ do_release_test() {
                echo "ERROR: afm-util start"
                lava-test-case afm-util-start-$WGTNAMEF --result fail
                journalctl -an 200
-               continue
+               return 1
        else
                lava-test-case afm-util-start-$WGTNAMEF --result pass
        fi
@@ -277,7 +291,7 @@ do_release_test() {
        if [ $? -ne 0 ];then
                echo "ERROR: afm-util ps"
                lava-test-case afm-util-ps-$WGTNAMEF --result fail
-               continue
+               return 1
        else
                cat $PSLIST
                lava-test-case afm-util-ps-$WGTNAMEF --result pass
@@ -291,7 +305,7 @@ do_release_test() {
                if [ $? -ne 0 ];then
                        echo "ERROR: afm-util start"
                        lava-test-case afm-util-start-$WGTNAMEF --result fail
-                       continue
+                       return 1
                fi
                RID="$(cat rid)"
        fi
@@ -299,7 +313,7 @@ do_release_test() {
        if [ "$RID" == 'null' ];then
                echo "ERROR: RID is null, service fail to start"
                lava-test-case afm-util-status-$WGTNAMEF --result fail
-               continue
+               return 1
        fi
 
        echo "DEBUG: status $NAMEID ($RID)"
@@ -307,7 +321,7 @@ do_release_test() {
        if [ $? -ne 0 ];then
                echo "ERROR: afm-util status"
                lava-test-case afm-util-status-$WGTNAMEF --result fail
-               continue
+               return 1
        else
                lava-test-case afm-util-status-$WGTNAMEF --result pass
        fi
@@ -317,7 +331,7 @@ do_release_test() {
        if [ $? -ne 0 ];then
                echo "ERROR: afm-util kill"
                lava-test-case afm-util-kill-$WGTNAMEF --result fail
-               continue
+               return 1
        else
                lava-test-case afm-util-kill-$WGTNAMEF --result pass
        fi
@@ -328,14 +342,14 @@ do_release_test() {
                echo "ERROR: afm-util start2"
                lava-test-case afm-util-start2-$WGTNAMEF --result fail
                journalctl -an 200
-               continue
+               return 1
        else
                lava-test-case afm-util-start2-$WGTNAMEF --result pass
        fi
        RID="$(cat rid)"
        if [ "$RID" == 'null' ];then
                echo "ERROR: RID is null"
-               continue
+               return 1
        fi
        sleep 10
        echo "DEBUG: status2 $NAMEID ($RID)"
@@ -343,7 +357,7 @@ do_release_test() {
        if [ $? -ne 0 ];then
                echo "ERROR: afm-util status2"
                lava-test-case afm-util-status2-$WGTNAMEF --result fail
-               continue
+               return 1
        else
                lava-test-case afm-util-status2-$WGTNAMEF --result pass
        fi
@@ -353,37 +367,50 @@ WGTNAMES=$(grep -o '[a-z-]*.wgt' index.html | sed 's,.wgt$,,' | sed 's,-debug$,,
 for WGTNAME in $WGTNAMES
 do
        if [ -e $WGTNAME.wgt ];then
-               inspect_wgt $WGTNAME.wgt
+               inspect_wgt $WGTNAME.wgt $WGTNAME
                do_release_test $WGTNAME $WGTNAME.wgt
+               pytest --show-capture=no --color=no -k "not hwrequired and not internet" /usr/lib/python?.?/site-packages/pyagl/tests/ -L
        else
                echo "WARN: cannot find $WGTNAME.wgt"
        fi
-       if [ -e $WGTNAME-test.wgt ];then
-               # wgt-test do not have the same permissions in the config.xml as the parent wgt
-               # so keep the value from last run
-               #inspect_wgt $WGTNAME-test.wgt
-               check_service_running $WGTNAME
-               if [ $? -eq 1 ];then
-                       do_afm_test $TOPDIR/$WGTNAME-test.wgt
-                       if [ $? -eq 0 ];then
-                               lava-test-case run-test-$WGTNAME --result pass
-                       else
-                               lava-test-case run-test-$WGTNAME --result fail
-                       fi
-               else
-                       echo "DEBUG: $WGTNAME is not running, skipping test"
-                       lava-test-case run-test-$WGTNAME --result skip
-               fi
-       else
-               echo "WARN: cannot find $WGTNAME.wgt"
-       fi
+       # disabled due to SPEC-3608
+       #if [ -e $WGTNAME-test.wgt ];then
+       #       # wgt-test do not have the same permissions in the config.xml as the parent wgt
+       #       # so keep the value from last run
+       #       #inspect_wgt $WGTNAME-test.wgt
+       #       check_service_running $WGTNAME
+       #       if [ $? -eq 1 ];then
+       #               do_afm_test $TOPDIR/$WGTNAME-test.wgt
+       #               if [ $? -eq 0 ];then
+       #                       lava-test-case run-test-$WGTNAME --result pass
+       #               else
+       #                       lava-test-case run-test-$WGTNAME --result fail
+       #               fi
+       #       else
+       #               echo "DEBUG: $WGTNAME is not running, skipping test"
+       #               lava-test-case run-test-$WGTNAME --result skip
+       #       fi
+       #else
+       #       echo "WARN: cannot find $WGTNAME.wgt"
+       #fi
        if [ -e $WGTNAME-debug.wgt ];then
-               inspect_wgt $WGTNAME-debug.wgt
+               inspect_wgt $WGTNAME-debug.wgt $WGTNAME
                do_release_test $WGTNAME $WGTNAME-debug.wgt
+               pytest --color=no -k "not hwrequired" /usr/lib/python?.?/site-packages/pyagl/tests/
        fi
-       if [ -e $WGTNAME-coverage.wgt ];then
-               inspect_wgt $WGTNAME-coverage.wgt
-               echo "DEBUG: coverage not handled yet"
+       if [ -e "$WGTNAME-coverage.wgt" ];then
+               gcovr-wrapper "$WGTNAME-coverage.wgt" > coverage.result
+               RET=$?
+               cat coverage.result
+               if [ $RET -eq 0 ];then
+                       lava-test-case "run-test-$WGTNAME-coverage" --result pass
+                       LINES_PERCENT=$(grep -o '^lines.*%' coverage.result | cut -d ' ' -f2 | cut -d% -f1)
+                       lava-test-case "run-test-$WGTNAME-coverage-percentage-lines" --result pass --measurement "$LINES_PERCENT"
+                       BRANCHES_PERCENT=$(grep -o '^branches.*%' coverage.result | cut -d ' ' -f2 | cut -d% -f1)
+                       lava-test-case "run-test-$WGTNAME-coverage-percentage-branches" --result pass --measurement "$BRANCHES_PERCENT"
+               else
+                       lava-test-case "run-test-$WGTNAME-coverage" --result fail
+               fi
        fi
 done