From c2bf5c03af183d836c3f32081073529f0dea3a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6ppner?= <jonas.hoeppner@garz-fricke.com> Date: Thu, 30 May 2024 13:17:11 +0000 Subject: [PATCH] bluetooth: Allow to specify package cnt and delay for bt_test GRNFS-27 --- scripts/bt_test.sh | 70 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 8 deletions(-) mode change 100644 => 100755 scripts/bt_test.sh diff --git a/scripts/bt_test.sh b/scripts/bt_test.sh old mode 100644 new mode 100755 index e55dd38..717eb88 --- a/scripts/bt_test.sh +++ b/scripts/bt_test.sh @@ -1,20 +1,74 @@ -#!/bin/sh -x +#!/bin/sh L2PINGD_LOG="/tmp/bt_test.log" +PING_COUNT="5" +PING_GOOD_COUNT="3" +DELAY="100" + +# parse parameters +while [ $# -gt 0 ]; +do + case "$1" in + '-v' ) + set -x + ;; + '-h' ) + echo " trigger l2pingd to do X pings of which Y needs to be successful" + echo " -h: print help" + echo " -n: number of pings to send in total, default: $PING_COUNT" + echo " -g: numbers of pings that need to be successful to return success, default: $PING_GOOD_COUNT" + echo " -d: delay in ms between the pings, default: $DELAY" + echo " -v: More verbose messages" + exit 0 + ;; + '-n' ) + PING_COUNT="$2" + shift + ;; + '-g' ) + PING_GOOD_COUNT="$2" + shift + ;; + esac + shift +done + +DELAY="$(( DELAY * 1000 ))" + echo "" > "$L2PINGD_LOG" -kill -USR2 $(pgrep l2pingd) -status="pass" -for i in 0 1 2 3 4; do - kill -USR1 $(pgrep l2pingd) - sleep 0.3 +PID_L2PINGD="$(pgrep l2pingd)" +if [ -z "$PID_L2PINGD" ];then + echo "l2pings is not running" + echo "RESULT: fail" + exit 1 +fi + + +# Reset the packet id to map the log +kill -USR2 $PID_L2PINGD + +status="fail" +cnt=0 +good=0 - if ! grep -q "id $i time" "$L2PINGD_LOG"; then - status="fail" +while [ $cnt -lt $PING_COUNT ]; +do + kill -USR1 $PID_L2PINGD + usleep $DELAY + + if grep -q "id $cnt time" "$L2PINGD_LOG"; then + good=$(( good + 1 )) fi + cnt=$(( cnt + 1 )) done +if [ $good -ge $PING_GOOD_COUNT ]; +then + status="pass" +fi +echo "Received $good out of $cnt pings" echo "RESULT: $status" if [ "$status" = "pass" ]; then exit 0 -- GitLab