From 91d3627b5f737e1b113c52e7364cdf18f174e70f Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Mon, 20 Aug 2018 18:49:44 +0200 Subject: Enhance afm-test script - Create a cleanup function to be called in case of error - Assume the app home directory to be able to retrieve the test results log file. - Use a sed script to make the output of test results compliant with ptest. Change-Id: I6e3f0ca59a1ca8fc7537955c440a4c55196b9ec6 Signed-off-by: Romain Forlot --- afm-test | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/afm-test b/afm-test index 0be7737..000ab4c 100755 --- a/afm-test +++ b/afm-test @@ -18,6 +18,14 @@ # limitations under the License. ########################################################################### +trap cleanup SIGTERM SIGINT SIGABRT SIGHUP + +function cleanup() { + afm-util kill $pid >&2 + afm-util remove $APP >&2 + exit 1 +} + function usage() { cat >&2 << EOF Usage: $0 @@ -26,11 +34,11 @@ EOF } function error() { - echo "ERR: $@" >&2 - exit 1 + echo "FAIL: $@" >&2 + cleanup } function info() { - echo "INF: $@" >&2 + echo "PASS: $@" >&2 } # check application name passed as first arg @@ -41,23 +49,27 @@ WGT=$1 INSTALL=$(afm-util install $WGT) APP=$(echo $INSTALL | jq -r .added) [[ "$APP" == "null" ]] && error "Widget contains error. Abort" +APP_HOME=${HOME}/app-data/$(echo ${APP} |cut -d'@' -f1) # ask appfw to start application pid=$(afm-util start $APP) [[ -z "$pid" || ! -e "/proc/$pid" ]] && error "Failed to start application $APP" info "$APP started with pid=$pid" -ps -ef | grep -v grep | grep -q $pid +kill -0 $pid RUNNING=$? while [[ $RUNNING -eq 0 ]] do - ps -ef | grep -v grep | grep -q $pid + kill -0 $pid RUNNING=$? + sleep 0.2 done # Terminate the App afm-util kill $pid >&2 afm-util remove $APP >&2 -info "$APP killed and removed" +# Little sed script making compliant the output of test results for ptest. +sed -r -e '/^# (S| +)/d' -e '1d' -e 's:^ok +([0-9]+)\t+(.*):PASS\: \1 \2:' -e 's:^not ok +([0-9]+)\t+(.*):FAIL\: \1 \2:' ${APP_HOME}/test_results.log +info "$APP killed and removed" -- cgit 1.2.3-korg