Rollback about TEST build type
[apps/app-templates.git] / test-widget / launcher.sh.in
1 #!/bin/bash
2
3 ###########################################################################
4 # Copyright (C) 2017, 2018 IoT.bzh
5 #
6 # Author: Romain Forlot <romain.forlot@iot.bzh>
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 ###########################################################################
20
21 PORT=$1
22 TOKEN=$2
23
24 # Research the Api name used
25 CFGFILE=$(find ${AFM_APP_INSTALL_DIR} -name "*json" -print | head -n1)
26 API=$(grep '\"api\"' ${CFGFILE} | cut -d'"' -f4)
27
28 AFBCLIENTIN=$(mktemp -u)
29 AFBCLIENTOUT=$(mktemp -u)
30 mkfifo $AFBCLIENTIN
31 mkfifo $AFBCLIENTOUT
32
33 declare -a testVerb
34
35 if [[ $(jq '.testVerb|type' $CFGFILE) == "array" ]]
36 then
37         testVerbLength=$(jq '.testVerb | length')
38         for (( idx=0; idx<testVerbLength; idx++ )) do
39                 testVerb[$idx]=$(jq -r ".testVerb[$idx].uid" ${CFGFILE})
40         done
41 else
42         testVerb[0]=$(jq -r ".testVerb.uid" ${CFGFILE})
43 fi
44
45 tail -f  $AFBCLIENTIN | afb-client-demo ws://localhost:${PORT}/api?token=${TOKEN} > $AFBCLIENTOUT 2>&1 &
46 CLIENTPID=$!
47
48 testVerbLength=${#testVerb[@]}
49 for (( idx=0; idx<testVerbLength; idx++ )) do
50         echo "$API ${testVerb[$idx]}" > $AFBCLIENTIN
51 done
52
53 while read -r line
54 do
55         [ "$(echo "${line}" | grep -E 'Ran [[:digit]]+ tests in')" ] && break
56 done < $AFBCLIENTOUT
57
58 rm -f $AFBCLIENTIN
59 rm -f $AFBCLIENTOUT
60 kill $CLIENTPID