Skip to content

Commit

Permalink
test-avrdude: Replace associative array with function call
Browse files Browse the repository at this point in the history
Macos ships a quite old version of bash (3.x) which does not have
associative arrays (declare -A) yet.

As the test-avrdude script only uses one associative array
for a static mapping of one character strings to one word
strings, this can be easily replaced by a shell function
containing a "case" statement.

Before this fix:

2024-08-15T15:39:59.9596380Z Prepare "-cdryrun -pm2560" and press 'enter' or 'space' to continue. Press any other key to skip
2024-08-15T15:40:00.5796130Z ✅   0.155 s: flash raw format -T/-U write/verify cola-vending-machine.raw
2024-08-15T15:40:00.7006170Z ✅   0.111 s: flash extended address and hole test
2024-08-15T15:40:00.7057180Z ./tools/test-avrdude: line 322: declare: -A: invalid option
2024-08-15T15:40:00.7057750Z declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
2024-08-15T15:40:00.9218810Z ✅   0.212 s: flash writing R numbers
2024-08-15T15:40:01.1793950Z ✅   0.240 s: flash reading and verifying R numbers
2024-08-15T15:40:01.3661060Z ✅   0.173 s: flash writing R numbers
2024-08-15T15:40:01.6317540Z ✅   0.254 s: flash reading and verifying R numbers
2024-08-15T15:40:01.8235780Z ✅   0.182 s: flash writing R numbers
2024-08-15T15:40:02.0724260Z ✅   0.239 s: flash reading and verifying R numbers
2024-08-15T15:40:02.2713120Z ✅   0.188 s: flash writing R numbers
2024-08-15T15:40:02.4497490Z ✅   0.162 s: flash reading and verifying R numbers
2024-08-15T15:40:02.5897960Z ✅   0.128 s: flash writing R numbers
2024-08-15T15:40:02.8667350Z ✅   0.263 s: flash reading and verifying R numbers
2024-08-15T15:40:03.0635260Z ✅   0.181 s: flash writing srec format
2024-08-15T15:40:03.2152560Z ✅   0.142 s: flash reading and verifying srec format file

After this fix:

2024-08-15T17:23:24.5161820Z Prepare "-cdryrun -pm2560" and press 'enter' or 'space' to continue. Press any other key to skip
2024-08-15T17:23:25.1088990Z ✅   0.162 s: flash raw format -T/-U write/verify cola-vending-machine.raw
2024-08-15T17:23:25.2742090Z ✅   0.157 s: flash extended address and hole test
2024-08-15T17:23:25.4795650Z ✅   0.196 s: flash writing binary numbers
2024-08-15T17:23:25.6721130Z ✅   0.180 s: flash reading and verifying binary numbers
2024-08-15T17:23:25.8423490Z ✅   0.161 s: flash writing octal numbers
2024-08-15T17:23:26.0901770Z ✅   0.235 s: flash reading and verifying octal numbers
2024-08-15T17:23:26.2308860Z ✅   0.127 s: flash writing decimal numbers
2024-08-15T17:23:26.4667010Z ✅   0.228 s: flash reading and verifying decimal numbers
2024-08-15T17:23:26.6574670Z ✅   0.180 s: flash writing hexadecimal numbers
2024-08-15T17:23:26.8651240Z ✅   0.200 s: flash reading and verifying hexadecimal numbers
2024-08-15T17:23:27.0446640Z ✅   0.168 s: flash writing R numbers
2024-08-15T17:23:27.3074230Z ✅   0.250 s: flash reading and verifying R numbers
2024-08-15T17:23:27.4962750Z ✅   0.179 s: flash writing srec format
2024-08-15T17:23:27.6594570Z ✅   0.150 s: flash reading and verifying srec format file
  • Loading branch information
ndim committed Aug 15, 2024
1 parent d349e18 commit b14a856
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tools/test-avrdude
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,19 @@ for (( p=0; p<$arraylength; p++ )); do
result [ $? == 0 ]

# Test binary, octal, decimal, hexadecimal and R number lists for I/O
declare -A numsys=([b]=binary [o]=octal [d]=decimal [h]=hexadecimal [R]=R)
numsys() {
# this function replaces constant associative array, as
# macos bash does not support associative arrays.
case "$1" in
b) echo "binary" ;;
o) echo "octal" ;;
d) echo "decimal" ;;
h) echo "hexadecimal" ;;
R) echo "R" ;;
esac
}
for fmt in b o d h R; do
specify="flash writing ${numsys[$fmt]} numbers"
specify="flash writing $(numsys "$fmt") numbers"
command=(${avrdude[@]}
-U $tfiles/urboot_m2560_1s_x16m0_115k2_uart0_rxe0_txe1_led+b7_pr_ee_ce.hex
-T '"write flash 0x3fd00 0xc0cac01a 0xcafe \"secret Coca Cola recipe\""'
Expand All @@ -331,7 +341,7 @@ for (( p=0; p<$arraylength; p++ )); do
execute "${command[@]}"
result [ $? == 0 ]

specify="flash reading and verifying ${numsys[$fmt]} numbers"
specify="flash reading and verifying $(numsys "$fmt") numbers"
command=(${avrdude[@]}
-U flash:w:$tmpfile:$fmt
-U flash:r:$resfile:r)
Expand Down

0 comments on commit b14a856

Please sign in to comment.