Skip to content

Commit f8ddee0

Browse files
committed
fix(tests): Add HOMEID support for cli and improve debug
Wait for broker to be ready before starting play I noticed that some test session where failing to start, if failed if broker was not ready, now it retries it. Improving debug of z-wave-stack-binaries-test.sh This is a minor change to test CI, I should expect this commit to be tested. Origin: SiliconLabsSoftware#92 Relate-to: SiliconLabsSoftware/z-wave-engine-application-layer#23 Relate-to: Z-Wave-Alliance/z-wave-stack#732 Signed-off-by: Philippe Coval <[email protected]>
1 parent 32e3f1e commit f8ddee0

File tree

1 file changed

+42
-29
lines changed

1 file changed

+42
-29
lines changed

scripts/tests/z-wave-stack-binaries-test.sh

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ set -o pipefail
1111

1212
# Default configuration can be overloaded from env
1313

14+
# To be explicilty added to env
15+
sudo="${sudo:=}"
16+
1417
duration=3 # Allocated time in mins until watchdog quit
1518

1619
ZPC_COMMAND="${ZPC_COMMAND:=/usr/bin/zpc}"
@@ -91,7 +94,8 @@ EOF
9194

9295
log_()
9396
{
94-
[ "$debug" != "" ] && echo || clear ||:
97+
[ "$debug" != "" ] && echo \
98+
|| clear >/dev/null 2>&1 || reset >/dev/null 2>&1 || :
9599
printf "${yellow}info: $@ ${nocol}\n"
96100
}
97101

@@ -103,18 +107,12 @@ exit_()
103107
sleep 10
104108
[ -z $debug ] || sleep 1000
105109
echo $code > $code_log
106-
screen -S "$name" -X "quit"
110+
screen -S "$name" -X "quit" ||:
111+
ls -l *.log.tmp && more *.log.tmp | cat
107112
exit $code
108113
}
109114

110115

111-
die_()
112-
{
113-
local code=$(( 1 + 0$code))
114-
exit_ $code
115-
}
116-
117-
118116
run_()
119117
{
120118
local task="$1" && shift
@@ -131,12 +129,13 @@ mqtt_()
131129
pidof mosquitto \
132130
&& mosquitto_sub \
133131
-v -t '#' --remove-retained --retained-only -W 1 \
134-
&& break
132+
|| [ 27 = $? ] && break ||: # Break on timeout
135133
sleep .1
136-
done > /dev/null 2>&1
134+
done
135+
log_ "mqtt: broker is ready, operating for ${duration} mins"
137136
mosquitto_sub -v -t '#' -W $((60 * ${duration}))
138137
log_ "mqtt: error: Should have finish before ${duration} may need to update it"
139-
die_
138+
exit_ 10
140139
}
141140

142141

@@ -159,7 +158,7 @@ sub_()
159158
| head -n1 | grep -F "$expect" 2>&1 > /dev/null \
160159
|| { printf "${red}exp: error:: ${expect}${nocol}\n" ;
161160
cat "$mqtt_sub_log" ;
162-
die_ ; }
161+
exit_ 11; }
163162
fi
164163
}
165164

@@ -179,7 +178,6 @@ pub_()
179178

180179
pubsub_()
181180
{
182-
# reset
183181
echo ""
184182
[ "" = "$debug" ] || log_ "pubsub_: $@"
185183
local pub="$1"
@@ -236,13 +234,10 @@ controller_cli_()
236234
| tail -n 1 | sed -e 's|PTY: \(.*\)|\1|g' )
237235
;;
238236
H)
239-
[ -z $debug ] || log_ "TODO: print HOME_ID: from device: https://github.com/Z-Wave-Alliance/z-wave-stack/issues/732"
240-
sleep 1
241-
while [ ! -e "${mqtt_log}" ] ; do sleep 1; done
242-
# [ "$homeid" != "" ]
243-
homeid=$(sed -n -e 's|ucl/by-unid/zw-\(.*\)-\([0-9]*\)/.*|\1|gp' "$mqtt_log" | tail -n1)
237+
homeid=$(grep 'HOME_ID: ' "${controller_log}" \
238+
| tail -n 1 | sed -e 's|HOME_ID: \(.*\)|\1|g' )
244239
echo "HOME_ID: ${homeid}"
245-
[ ! -z $homeid ] || die_
240+
[ ! -z $homeid ] || exit_ 19
246241
;;
247242
n)
248243
contid=$(grep 'NODE_ID: ' "${controller_log}" \
@@ -319,7 +314,7 @@ zpc_()
319314
sleep 1
320315
zpc_cli_ version
321316
zpc_cli_ help
322-
die_
317+
exit_ 13
323318
}
324319

325320

@@ -346,8 +341,8 @@ zpc_cli_()
346341
play_uic_net_add_node_()
347342
{
348343
log_ "net: controller: Add node (set in learn mode)"
349-
controller_cli_ H | grep "^HOME_ID: ........$" || die_
350-
controller_cli_ n | grep "^NODE_ID: " || die_
344+
controller_cli_ H | grep "^HOME_ID: ........$" || exit_ 14
345+
controller_cli_ n | grep "^NODE_ID: " || exit_ 15
351346

352347
sub="ucl/by-mqtt-client/zpc/ApplicationMonitoring/SupportedCommands"
353348
pub="$sub" # Can be anything
@@ -364,7 +359,7 @@ play_uic_net_add_node_()
364359
homeid=$(sed -n -e 's|ucl/by-unid/zw-\(.*\)-\([0-9]*\)/.*|\1|gp' "$mqtt_sub_log")
365360
contid=$(sed -n -e 's|ucl/by-unid/zw-\(.*\)-\([0-9]*\)/.*|\2|gp' "$mqtt_sub_log")
366361
contunid="zw-$homeid-$contid"
367-
node_cli_ n | grep 'NODE_ID: 0' || die_
362+
node_cli_ n | grep 'NODE_ID: 0' || exit_ 16
368363
node_cli_ l
369364

370365
log_ "net: cont: Add node"
@@ -374,7 +369,7 @@ play_uic_net_add_node_()
374369
count="2" # NODEID=0001 is controller , NODEID=0002 is expected node
375370
expect="State/SupportedCommands"
376371
pubsub_ "$pub" "$message" "$sub" "$expect"
377-
node_cli_ H | grep "HOME_ID: ${homeid}" || die_
372+
node_cli_ H | grep "HOME_ID: ${homeid}" || exit_ 17
378373
node_cli_ n # Should not be 0
379374
pub=''
380375
sub=$(echo "$sub" | sed -e "s|/+/|/$nodeunid/|g")
@@ -413,7 +408,7 @@ play_uic_net_remove_node_()
413408
expect=$(echo "$sub (null)" | sed -e "s|/+/|/$nodeunid/|g")
414409
node_cli_ l
415410
pubsub_ "$pub" "$message" "$sub" "$expect" 3
416-
node_cli_ n | grep '^NODE_ID: 0$' || die_
411+
node_cli_ n | grep '^NODE_ID: 0$' || exit_ 18
417412
}
418413

419414

@@ -487,7 +482,9 @@ play_uic_()
487482
play_()
488483
{
489484
log_ "play: Wait for zpc mqtt ready"
490-
while ! grep -- "mqtt_wrapper_mosquitto" "${zpc_log}" ; do sleep 1 ; done
485+
while ! grep -- "\[mqtt_wrapper_mosquitto\]" "${zpc_log}" ; do sleep 1 ; done
486+
while ! grep -- "\[mqtt_client\] Connection to MQTT broker" "${zpc_log}" ; do sleep 1 ; done
487+
491488
controller_cli_ h
492489
node_cli_ h
493490

@@ -501,12 +498,17 @@ setup_()
501498
local project="z-wave-stack-binaries"
502499
local url="https://github.com/Z-Wave-Alliance/${project}"
503500
local pattern="$project-*.tar.gz" # TODO: Bump latest release
504-
pattern="$project-25.1.0-25-g3b1e09d-Linux.tar.gz"
501+
local rev="25.1.0-26-g29d304"
502+
pattern="$project-${rev}-Linux.tar.gz"
505503

506504
mkdir -p "${project}" && cd "${project}"
507505
file -E "${pattern}" \
508506
|| gh release download -R "$url" --pattern "$pattern"
509507
tar xvfz "${project}"*.tar.gz
508+
# TODO: https://github.com/eclipse-mosquitto/mosquitto/issues/3267
509+
mosquitto_pub --version \
510+
|| which mosquitto_pub \
511+
|| $sudo apt install mosquitto-clients
510512
}
511513

512514

@@ -515,6 +517,17 @@ default_()
515517
usage_
516518
sleep 1
517519

520+
log_ "Setup check, if failing please setup using:"
521+
echo "sudo=sudo $0 setup_"
522+
523+
[ "" = "$debug" ] || set
524+
525+
screen --version
526+
527+
# TODO: https://github.com/eclipse-mosquitto/mosquitto/issues/3267
528+
mosquitto_pub --version \
529+
|| which mosquitto_pub
530+
518531
log_ "z-wave-stack-binaries: Check presence in ${z_wave_stack_binaries_bin_dir}"
519532
file -E "${z_wave_stack_binaries_bin_dir}/"*"REALTIME"*".elf"
520533
sleep 2
@@ -576,7 +589,7 @@ EOF
576589
cat "${mqtt_log}"
577590

578591
code=$(cat ${code_log} || echo 254)
579-
exit 0$code
592+
exit_ 0$code
580593
}
581594

582595

0 commit comments

Comments
 (0)