summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-10-22 17:17:35 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-10-24 14:04:10 +0200
commit021609cd6bafc542629c67e5385d890acb751d13 (patch)
treeda934be978f4b402264c74abb2f608546c306627
parentd43fec70f9c72367f8ff719f086647a6ae70f99e (diff)
Add Lava markers on output and select test set
The launch scripts now allow you to select a verb from the test api to only launch that verb instead of all. Also using the verb's argument {'lavaOutput':true}, the test framework adds specific Lava markers. Reformat the script to accept options instead of only positionnal arguments Change-Id: I52539cd2bef460aacb8d327d5abb34ecfd94f512 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--afm-test.native.sh57
-rwxr-xr-xafm-test.target.sh47
-rw-r--r--conf.d/controller/lua.d/aft.lua38
3 files changed, 110 insertions, 32 deletions
diff --git a/afm-test.native.sh b/afm-test.native.sh
index 9f9d6ca..ffdb869 100644
--- a/afm-test.native.sh
+++ b/afm-test.native.sh
@@ -38,11 +38,12 @@ cleanNexit() {
function usage() {
cat >&2 << EOF
-Usage: $0 <binding-wgt-rootdir> <test-wgt-rootdir> [mode] [timeout]
+Usage: $0 <binding-wgt-rootdir> <test-wgt-rootdir> [-m|--mode <SOLO|SERVICE>] [-t|--timeout <X>] [-l|--lavaoutput]
binding-wgt-rootdir: path to the test wgt file
test-wgt-rootdir: path to the test folder file
-mode: SOLO (1 binder) or SERVICE (2 binders)
-timeout: default 3 seconds
+-m|--mode: SOLO (1 binder) or SERVICE (2 binders) (Default: SOLO)
+-t|--timeout: timeout in second. (Default 3 seconds)
+-l|--lavaoutput: Flags indicating the binding to add Lava special test markers.
EOF
}
@@ -52,6 +53,34 @@ PORT=1234
PORTSERVICE=$((PORT+1))
TOKEN=
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+ -l|--lavaoutput)
+ LAVAOUTPUT="TRUE"
+ shift # past argument
+ ;;
+ -m|--mode)
+ MODE="$2"
+ shift # past argument
+ shift # past value
+ ;;
+ -t|--timeout)
+ TIMEOUT="$2"
+ shift # past argument
+ shift # past value
+ ;;
+ *)
+ POSITIONAL+=("$1") # save it in an array for later
+ shift # past argument
+ ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
if [ "$1" ] && [ "$2" ]
then
SERVICEPACKAGEDIR="$(readlink -f $1)"
@@ -62,19 +91,8 @@ else
cleanNexit 1
fi
-if [ "$3" ]
-then
- MODE="$3"
-else
- MODE="SOLO"
-fi
-
-if [ "$4" ]
-then
- TIMEOUT=$4
-else
- TIMEOUT=3
-fi
+[ -z "$MODE" ] && MODE="SOLO"
+[ -z "$TIMEOUT" ] && TIMEOUT=3
TESTCFGFILE=$(find "${TESTPACKAGEDIR}" -name "aft-*.json" -print | head -n1)
TESTAPINAME=$(grep '\"api\"' "${TESTCFGFILE}" | cut -d'"' -f4)
@@ -116,7 +134,12 @@ LOGFILETEST="test.log"
testVerbLength=${#testVerb[@]}
for (( idx=0; idx<testVerbLength; idx++ )) do
- testVerbCalls="--call=${TESTAPINAME}/${testVerb[$idx]}:'{}' ${testVerbCalls}"
+ if [ "${LAVAOUTPUT}" ]
+ then
+ testVerbCalls="--call=${TESTAPINAME}/${testVerb[$idx]}:{\"lavaOutput\":true} ${testVerbCalls}"
+ else
+ testVerbCalls="--call=${TESTAPINAME}/${testVerb[$idx]}:{} ${testVerbCalls}"
+ fi
done
if [ ${MODE} = "SOLO" ]
diff --git a/afm-test.target.sh b/afm-test.target.sh
index 5038e74..c6739ae 100755
--- a/afm-test.target.sh
+++ b/afm-test.target.sh
@@ -23,12 +23,15 @@ trap cleanup SIGTERM SIGINT SIGABRT SIGHUP
function cleanup() {
afm-util kill $pid >&2
afm-util remove $APP >&2
+ rm ${AFM_PLATFORM_RUNDIR}/${APP}.env 2> /dev/null
exit 1
}
function usage() {
cat >&2 << EOF
-Usage: $0 <path>
+Usage: $0 [-l|--lava] [-v|--verb <verb>] <path>
+-l|--lavaoutput: flag that enable Lava test marker to the output. (Default: disabled)
+-v|--verb: select a specific verb to launch from the test API. (Default: all)
path: path to the test wgt file
EOF
}
@@ -41,6 +44,29 @@ function info() {
echo "PASS: $*" >&2
}
+POSITIONAL=()
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+ -l|--lavaoutput)
+ VERBARGS="{'lavaOutput':true}"
+ shift # past argument
+ ;;
+ -v|--verb)
+ VERBSELECTED="$2"
+ shift # past argument
+ shift # past value
+ ;;
+ *)
+ POSITIONAL+=("$1") # save it in an array for later
+ shift # past argument
+ ;;
+esac
+done
+set -- "${POSITIONAL[@]}" # restore positional parameters
+
# check application name passed as first arg
WGT=$1
[[ -z "$WGT" ]] && { usage; exit 0;}
@@ -48,9 +74,20 @@ WGT=$1
INSTALL=$(afm-util install $WGT)
APP=$(echo $INSTALL | jq -r .added)
+AFM_PLATFORM_RUNDIR=/run/platform/debug/
[[ "$APP" == "null" ]] && error "Widget contains error. Abort"
APP_HOME=${HOME}/app-data/$(echo ${APP} |cut -d'@' -f1)
+# Clean the old test results
+find "${APP_HOME}" -name '*tap' -exec rm -f {} \;
+
+# Configure the test launch for a specific verb and args
+mkdir -p ${AFM_PLATFORM_RUNDIR}
+cat > ${AFM_PLATFORM_RUNDIR}/${APP}.env << EOF
+VERBSELECTED="${VERBSELECTED}"
+VERBARGS="${VERBARGS}"
+EOF
+
# ask appfw to start application
pid=$(afm-util start $APP)
[[ -z "$pid" || ! -e "/proc/$pid" ]] && error "Failed to start application $APP"
@@ -68,12 +105,12 @@ done
# Terminate the App
afm-util kill $pid > /dev/null
afm-util remove $APP > /dev/null
+rm ${AFM_PLATFORM_RUNDIR}/${APP}.env 2> /dev/null
-# Little sed script making compliant the output of test results for ptest.
find "${APP_HOME}" -name '*tap' -exec \
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:' {} \;
+--e '1d' \
+--e 's:^ok +([0-9]+)\t+(.*):PASS\: \1 \2:' \
+--e 's:^not ok +([0-9]+)\t+(.*):FAIL\: \1 \2:' {} \;
info "$APP killed and removed"
diff --git a/conf.d/controller/lua.d/aft.lua b/conf.d/controller/lua.d/aft.lua
index 449aab4..d38b329 100644
--- a/conf.d/controller/lua.d/aft.lua
+++ b/conf.d/controller/lua.d/aft.lua
@@ -32,6 +32,7 @@ _AFT = {
afterEach = nil,
beforeAll = nil,
afterAll = nil,
+ lavaOutput = false,
}
function _AFT.enableEventHistory()
@@ -412,12 +413,26 @@ function _AFT.describe(testName, testFunction, setUp, tearDown)
os.exit(1)
end
function aTest:setUp()
+ if _AFT.lavaOutput then
+ print('<LAVA_SIGNAL_STARTTC '..testName..'>')
+ end
if _AFT.beforeEach then _AFT.beforeEach() end
if type(setUp) == 'function' then setUp() end
end
function aTest:tearDown()
if type(tearDown) == 'function' then tearDown() end
if _AFT.afterEach then _AFT.afterEach() end
+ if _AFT.lavaOutput then
+ local result = 'FAIL'
+ for _,v in pairs(lu.LuaUnit.result.tests) do
+ if v.className == testName then
+ result = v.status
+ end
+ end
+
+ print('<LAVA_SIGNAL_TESTCASE TEST_CASE_ID='..testName..' RESULT='..result..'>')
+ print('<LAVA_SIGNAL_ENDTC '..testName..'>')
+ end
end
table.insert(_AFT.tests_list, {testName, aTest})
@@ -636,25 +651,28 @@ local function readOneFile(f)
cmdHandle:close()
end
-function _launch_test(context, args)
+function _launch_test(context, confArgs, queryArgs)
_AFT.context = context
_AFT.bindingRootDir = AFB:getrootdir(_AFT.context)
+ -- Enable the lava additionals output markers
+ if queryArgs and queryArgs.lavaOutput then _AFT.lavaOutput = queryArgs.lavaOutput end
+
-- Prepare the tests execution configuring the monitoring and loading
-- lua test files to execute in the Framework.
AFB:servsync(_AFT.context, "monitor", "set", { verbosity = "debug" })
- if type(args.trace) == "string" then
- AFB:servsync(_AFT.context, "monitor", "trace", { add = { request = "vverbose", event = "push_after", pattern = args.trace.."/*" }})
- elseif type(args.trace) == "table" then
- for _,v in pairs(args.trace) do
+ if type(confArgs.trace) == "string" then
+ AFB:servsync(_AFT.context, "monitor", "trace", { add = { request = "vverbose", event = "push_after", pattern = confArgs.trace.."/*" }})
+ elseif type(confArgs.trace) == "table" then
+ for _,v in pairs(confArgs.trace) do
if type(v) == "string" then
AFB:servsync(_AFT.context, "monitor", "trace", { add = { request = "vverbose", event = "push_after", pattern = v.."/*" }})
end
end
end
- if args.files and type(args.files) == 'table' then
- for _,f in pairs(args.files) do
+ if confArgs.files and type(confArgs.files) == 'table' then
+ for _,f in pairs(confArgs.files) do
_AFT.setOutputFile(f)
readOneFile(f)
process_tests()
@@ -664,9 +682,9 @@ function _launch_test(context, args)
_AFT.afterAll = nil
_AFT.tests_list = {}
end
- elseif type(args.files) == 'string' then
- _AFT.setOutputFile(args.files)
- readOneFile(args.files)
+ elseif type(confArgs.files) == 'string' then
+ _AFT.setOutputFile(confArgs.files)
+ readOneFile(confArgs.files)
process_tests()
end