Merge pull request #1650 from stefanrueger/sed+tmp

Update test-avrdude script
This commit is contained in:
Stefan Rueger
2024-01-31 15:05:19 +13:00
committed by GitHub

View File

@@ -8,11 +8,12 @@ tfiles=$(dirname "$0")/test_files
tfiles=$(printf "%q" "$tfiles") # Quote directory string in case there are spaces etc
avrdude_conf='' # Configuration for every run, eg, '-C path_to_avrdude_conf'
delay=4 # Some programmers need a delay between AVRDUDE calls
delay=0.75 # Some programmers need a delay between AVRDUDE calls
avrdude_bin=avrdude # Executable
list_only=0 # Normal run
declare -a pgm_and_target=() # Array with test option strings, eg, "-c dryrun -p m328p"
skip_eeprom=0 # Do not skip EEPROM tests for bootloaders by default
tmp=/dev/shm # Temporary RAM directory
verbose=0 # Do not show AVRDUDE errors and warnings by default
Usage() {
@@ -26,6 +27,7 @@ Options:
-l list test commands but do not execute them
-p <programmer/part specs> can be used multiple times, overrides default tests
-s skip EEPROM tests for bootloaders
-t <dir> temporary directory
-v verbose: show AVRDUDE error and warning messages
-? or -h show this help text
Example:
@@ -33,7 +35,7 @@ Example:
END
}
while getopts ":\?hc:d:e:lp:sv" opt; do
while getopts ":\?hc:d:e:lp:st:v" opt; do
case ${opt} in
c) avrdude_conf="$OPTARG"
;;
@@ -47,6 +49,8 @@ while getopts ":\?hc:d:e:lp:sv" opt; do
;;
s) skip_eeprom=1
;;
t) tmp="$OPTARG"
;;
v) verbose=1
;;
--) shift;
@@ -93,15 +97,14 @@ arraylength=${#pgm_and_target[@]}
echo -n "Testing $avrdude_bin"
$avrdude_bin -v 2>&1 | grep Version | cut -f2- -d: | sed s/Version/version/
tmp=/dev/shm # Temporary RAM directory
[[ -d $tmp && -w $tmp ]] || tmp=/tmp # Fall back to /tmp if /dev/shm unusable
[[ -d $tmp && -w $tmp ]] || tmp=/tmp # Fall back to /tmp if tmp directory unusable
status=$(mktemp "$tmp/$progname.status.XXXXXX")
logfile=$(mktemp "$tmp/$progname.log.XXXXXX")
outfile=$(mktemp "$tmp/$progname.out.XXXXXX")
trap "rm -f $status $logfile $outfile" EXIT
TIMEFORMAT=%R # time built-in only returns elapsed wall-clock time
elapsed=0 # Global variable holding time of last execute command in seconds
elapsed=-1 # Global variable holding time of last execute command in seconds
command=(sleep 0.1) # Array with AVRDUDE command
# Execute args as command, set $elapsed and return exit value of command; don't call in a subshell
@@ -110,7 +113,7 @@ execute () {
echo "\$ ${command[@]}" | tr -s " "
return 0;
fi
sleep "$delay"
[[ $programmer != -cdry* && $elapsed -ne -1 ]] && sleep "$delay"
# These shenanigans keep stdout, stderr and the exit code of the command
{ read elapsed < <({ time { eval "$@"; echo $? >"$status"; } 2>&4 4>&-; } 4>&2 2>&1 >&3 3>&-); } 3>&1
return $(cat "$status")
@@ -128,7 +131,7 @@ result () {
echo ❌ "$(printf '%7.3f s' $elapsed): $specify (failed command below)"
echo "\$ ${command[@]}" | tr -s " "
FAIL=true
sleep 4 # Let the hw settle down before the next test
[[ $programmer != -cdry* ]] && sleep 4 # Let the hw settle down before next test
fi
[[ $verbose -eq 1 ]] && { touch $logfile $outfile; cat $logfile $outfile; }
else
@@ -148,6 +151,10 @@ nofusetest=(-pattiny11/ -pt11/ -pattiny12/ -pt12/ -pattiny15/ -pt15/ -pat89s51/
-plgt8f328p/ -plgt8f328p/)
for (( p=0; p<$arraylength; p++ )); do
# Isolate programmer and part (assumes -c prog or -cprog but not sth more tricky such as -qc prog)
programmer=$(echo ${pgm_and_target[$p]} | sed 's/ *\([^-]\)/\1/g' | tr \ \\n | grep ^-c | tr A-Z a-z)
part=$(echo ${pgm_and_target[$p]} | sed 's/ *\([^-]\)/\1/g' | tr \ \\n | grep ^-p | tr A-Z a-z)
if [[ $list_only -eq 1 ]]; then
[[ p -ne 0 ]] && echo
echo "# ${pgm_and_target[$p]}"
@@ -155,7 +162,7 @@ for (( p=0; p<$arraylength; p++ )); do
else
echo "Prepare \"${pgm_and_target[$p]}\" and press 'enter' or 'space' to continue. Press any other key to skip"
read -n1 -s -r -p $'' key
sleep 0.25
[[ $programmer != -cdry* ]] && sleep 0.15 # Debounce key when not using dryrun/dryboot
fi
if [ "$key" == '' ]; then
@@ -176,19 +183,13 @@ for (( p=0; p<$arraylength; p++ )); do
# Is the to be tested programmer for a bootloader?
is_bootloader=0
# Isolate programmer (assumes either -c prog or -cprog but not sth more tricky such as -qc prog)
programmer=$(echo ${pgm_and_target[$p]} | sed 's/ *\([^-]\)/\1/g' | tr \ \\n | grep ^-c)
if [ -n "$programmer" ]; then
($avrdude_bin $avrdude_conf "$programmer"/At 2>/dev/null | grep -q prog_modes.PM_SPM) && is_bootloader=1
fi
# Should we test fuses?
fusetest=1
# Isolate part (assumes either -p part or -ppart)
part=$(echo ${pgm_and_target[$p]} | sed 's/ *\([^-]\)/\1/g' | tr \ \\n | grep ^-p | tr A-Z a-z)
if [ -n "$part" ]; then
[[ "${nofusetest[@]}" =~ "$part/" ]] && fusetest=0
fi
[[ -n "$part" && "${nofusetest[@]}" =~ "$part/" ]] && fusetest=0
# Should EEPROM test be carried out?
check_eeprom=1
@@ -269,15 +270,17 @@ for (( p=0; p<$arraylength; p++ )); do
fi
execute "${command[@]}" > $outfile
fusebit=$(grep ^config $outfile | awk '{print $4}')
sed -i -e/^config/d -e/"> "/d $outfile
result [[ '"$fusebit"' == 1 '&&' ! -s $outfile '&&' ! -s $logfile ]]
sed -e/^config/d -e/"> "/d $outfile > ${outfile}-2
result [[ '"$fusebit"' == 1 '&&' ! -s ${outfile}-2 '&&' ! -s $logfile ]]
rm ${outfile}-2
if [ -n "$EE_SIZE" ]; then
specify="fuse access: set eesave fusebit to delete EEPROM on chip erase"
command=(${avrdude[@]} -T '"config eesave=ee*erased"')
execute "${command[@]}" > $outfile
sed -i -e/^config/d -e/"> "/d $outfile
result [[ ! -s $outfile '&&' ! -s $logfile ]]
sed -e/^config/d -e/"> "/d $outfile > ${outfile}-2
result [[ ! -s ${outfile}-2 '&&' ! -s $logfile ]]
rm ${outfile}-2
fi
fi