-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
92 lines (87 loc) · 2.32 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
## Resources:
## Get Arguments with flags: https://stackoverflow.com/questions/7069682/how-to-get-arguments-with-flags-in-bash-script
## Test for empty array: https://serverfault.com/questions/477503/check-if-array-is-empty-in-bash
RETEST=NO
COMPILE_ONLY=NO
TESTARRAY=();
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-r|--retest)
printf "\n--> RETEST - skip compilation\n"
RETEST=YES
shift # past argument
shift # past value
;;
-c|--compileOnly)
printf "\n--> COMPILE ONLY - skip flash\n"
COMPILE_ONLY=YES
shift # past argument
shift # past value
;;
-t|--test)
shift
printf "\n--> TESTING: %s\n" $1
TESTARRAY+=($1);
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ -n $1 ]]; then
device=$1
fi
## Create Compile/Test array
if [ ${#TESTARRAY[@]} -eq 0 ]; then
printf "\nGathering all examples\n"
for path in examples/*/ ; do
TESTARRAY+=($path)
done
else
TESTARRAY[0]="examples/${TESTARRAY[0]}"
fi
## COMPILE EXAMPLES
if [ $RETEST != YES ]; then
printf "\nCompiling\n"
for path in ${TESTARRAY[@]} ; do
directoryName=$(basename $path)
printf "\nCompiling %s to bin/%s.bin\n" $path $directoryName
particle compile p ./$path --saveTo bin/$directoryName.bin
if [ $? -eq 0 ]; then
printf "\n\nSUCCESS: created bin/%s.bin" $directoryName
else
printf "\n\nFAIL: unable to compile bin for \"%s\"\n" $directoryName
exit 1;
break;
fi
done
fi
## FLASH EXAMPLES AND TEST
if [ $COMPILE_ONLY != YES ]; then
printf "Flashing examples\n\n"
for path in ${TESTARRAY[@]} ; do
bin=bin/$(basename $path).bin
# for bin in bin/* ; do
printf "\n\n---%s---\n" $bin
particle flash $device $bin
if [ $? -eq 0 ]; then
printf "\n\nSUCCESS: Flashed %s to %s" $bin $1
else
printf "\n\nFAIL: unable to flash %s to %s" $bin $1
#break;
fi
printf "\n_______________________\n"
printf "Starting Serial Monitor\n"
printf "Press \" CTRL + \\ \" to exit serial monitor\n"
printf "and start next test"
printf "\n_______________________\n"
particle serial monitor --follow
done
fi