Skip to content

Commit

Permalink
pqm: Rewrite Expect to bash, refactor DAPLINK boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
trupples committed Jul 11, 2024
1 parent 108377c commit 3a807f3
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 304 deletions.
44 changes: 44 additions & 0 deletions main_tests/lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,50 @@ stop_gps_spoofing(){
pkill plutoplayer &>/dev/null
}

daplink_mountpoint(){
mount | awk '/DAPLINK/ { for (i=1; i<=NF; i++) if ($i ~ "/DAPLINK") print $i }'
}

daplink_upload(){
mountpoint=$(daplink_mountpoint)
echo $mountpoint

# Start monitoring the mountpoint
inotifywait -m -e unmount "$mountpoint" | (
rsync -ah -v --progress "$1" "$mountpoint"
sync

while read -r directory event filename; do
echo "$mountpoint has been unmounted. Waiting for it to be mounted again..."
start_time=$(date +%s)
while true; do
if mountpoint -q "$mountpoint"; then
echo "$mountpoint has been remounted."
pkill -P $$ inotifywait # Send SIGTERM to child inotifywait process
break
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -ge 30 ]; then
echo "Timeout reached. $mountpoint did not remount within 30 seconds."
pkill -P $$ inotifywait # Send SIGTERM to child inotifywait process
break
fi
sleep 1 # Adjust the interval as needed
done
done
)

# verify if there s a FAIL.txt file
if [[ -f "${mountpoint}/FAIL.txt" ]]; then
echo "FAILED"
return 1
else
echo "no fail.txt found. SUCCESS"
return 0
fi
}



#----------------------------------#
Expand Down
39 changes: 4 additions & 35 deletions main_tests/pqm/erase_flash.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
#!/bin/bash

mountpoint=$(mount | awk '/DAPLINK/ { for (i=1; i<=NF; i++) if ($i ~ "/DAPLINK") print $i }')
echo $mountpoint
SCRIPT_DIR="$(readlink -f $(dirname $0))"
source $SCRIPT_DIR/../lib/utils.sh


# Start monitoring the mountpoint
inotifywait -m -e unmount "$mountpoint" | (
touch $mountpoint/erase.act
sync

while read -r directory event filename; do
echo "$mountpoint has been unmounted. Waiting for it to be mounted again..."
start_time=$(date +%s)
while true; do
if mountpoint -q "$mountpoint"; then
echo "$mountpoint has been remounted."
pkill -P $$ inotifywait # Send SIGTERM to child inotifywait process
break
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -ge 30 ]; then
echo "Timeout reached. $mountpoint did not remount within 30 seconds."
pkill -P $$ inotifywait # Send SIGTERM to child inotifywait process
break
fi
sleep 1 # Adjust the interval as needed
done
done
)

if [[ -f "${mountpoint}/FAIL.txt" ]]; then
echo "FAILED"
exit 1
else
echo "no fail.txt found. SUCCESS"
fi
touch /tmp/erase.act
daplink_upload /tmp/erase.act
56 changes: 11 additions & 45 deletions main_tests/pqm/firmware_prod.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,20 @@
#!/bin/bash

SCRIPT_DIR="$(readlink -f $(dirname $0))"
source $SCRIPT_DIR/../lib/utils.sh

#RELEASE_FW=https://swdownloads.analog.com/cse/prod_test_rel/ev_charger_fw/ad-acevsecrdset-sl.zip
FW_DOWNLOAD_PATH=/home/analog/production-tests/main_tests/pqm

# cp the hex file to daplink
mountpoint=$(mount | awk '/DAPLINK/ { for (i=1; i<=NF; i++) if ($i ~ "/DAPLINK") print $i }')
echo $mountpoint

# Start monitoring the mountpoint
inotifywait -m -e unmount "$mountpoint" | (

#wget -T 5 $RELEASE_FW -O $FW_DOWNLOAD_PATH/ad-acevsecrdset-sl.zip
#unzip $FW_DOWNLOAD_PATH/ad-acevsecrdset-sl.zip -d $FW_DOWNLOAD_PATH
ret=$?

if [ $ret == 0 ];then
echo "wget success"
rsync -ah -v --progress $FW_DOWNLOAD_PATH/pqm_prod_test.hex $mountpoint
else
echo "wget error"
rsync -ah -v --progress /home/analog/production-tests/main_tests/pqm/pqm_prod_test.hex $mountpoint
fi

sync
while read -r directory event filename; do
echo "$mountpoint has been unmounted. Waiting for it to be mounted again..."
start_time=$(date +%s)
while true; do
if mountpoint -q "$mountpoint"; then
echo "$mountpoint has been remounted."
pkill -P $$ inotifywait # Send SIGTERM to child inotifywait process
break
fi
current_time=$(date +%s)
elapsed_time=$((current_time - start_time))
if [ "$elapsed_time" -ge 30 ]; then
echo "Timeout reached. $mountpoint did not remount within 30 seconds."
pkill -P $$ inotifywait # Send SIGTERM to child inotifywait process
break
fi
sleep 1 # Adjust the interval as needed
done
done
)

# verify if there s a FAIL.txt file
#wget -T 5 $RELEASE_FW -O $FW_DOWNLOAD_PATH/ad-acevsecrdset-sl.zip
#unzip $FW_DOWNLOAD_PATH/ad-acevsecrdset-sl.zip -d $FW_DOWNLOAD_PATH
ret=$?

if [[ -f "${mountpoint}/FAIL.txt" ]]; then
echo "FAILED"
exit 1
if [ $ret == 0 ];then
echo "wget success"
daplink_upload $FW_DOWNLOAD_PATH/pqm_prod_test.hex
else
echo "no fail.txt found. SUCCESS"
echo "wget error"
daplink_upload /home/analog/production-tests/main_tests/pqm/pqm_prod_test.hex
fi
8 changes: 1 addition & 7 deletions main_tests/pqm/production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
SCRIPT_DIR="$(readlink -f $(dirname $0))"
source $SCRIPT_DIR/../lib/utils.sh


MODE="$1"
case $MODE in
"Erase Flash")
sudo $SCRIPT_DIR/erase_flash.sh
;;

"System Test")
# Upload test firmware
sudo $SCRIPT_DIR/firmware_prod.sh || {
handle_error_state "$BOARD_SERIAL"
exit 1
}

# Upload and run test firmware
export tty=/dev/ttyACM0
echo_blue "Serial self-test starting..."
$SCRIPT_DIR/system_test.sh || {
Expand Down
Loading

0 comments on commit 3a807f3

Please sign in to comment.