forked from lupyuen/remote-bl602
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·179 lines (154 loc) · 5.02 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env bash
## Automated Testing of Apache NuttX RTOS on Sophgo SG2000 SoC / Milk-V Duo S SBC
set -e ## Exit when any command fails
set -x ## Echo commands
## Default Build Prefix is "nuttx-sg2000"
if [ "$BUILD_PREFIX" == '' ]; then
export BUILD_PREFIX=nuttx-sg2000
fi
## Default Build Date is today (YYYY-MM-DD)
if [ "$BUILD_DATE" == '' ]; then
export BUILD_DATE=$(date +'%Y-%m-%d')
fi
## Default USB Device is /dev/tty.usbserial-0001
if [ "$USB_DEVICE" == '' ]; then
export USB_DEVICE=/dev/tty.usbserial-0001
fi
set +x ## Disable echo
date
echo "----- Download the latest NuttX build for $BUILD_DATE"
set -x ## Enable echo
wget -q https://github.com/lupyuen/nuttx-sg2000/releases/download/$BUILD_PREFIX-$BUILD_DATE/nuttx.zip -O /tmp/nuttx.zip
pushd /tmp
unzip -o nuttx.zip
popd
set +x ## Disable echo
date
## Get the Script Directory
SCRIPT_PATH="${BASH_SOURCE}"
SCRIPT_DIR="$(cd -P "$(dirname -- "${SCRIPT_PATH}")" >/dev/null 2>&1 && pwd)"
## Print the Commit Hashes
if [ -f /tmp/nuttx.hash ]; then
cat /tmp/nuttx.hash
fi
## Write the Release Tag for populating the Release Log later
echo "$BUILD_PREFIX-$BUILD_DATE" >/tmp/release.tag
## Copy NuttX Image to TFTP Server
echo "----- Copy NuttX Image to TFTP Server"
set -x ## Enable echo
scp /tmp/Image tftpserver:/tftpboot/Image-sg2000
ssh tftpserver ls -l /tftpboot/Image-sg2000
rm /tmp/Image
set +x ## Disable echo
date
echo "----- Close the screen session"
set -x ## Enable echo
$SCRIPT_DIR/close.exp || true
set +x ## Disable echo
date
## Without a Smart Power Plug:
## echo Power off the SBC, press Enter, then power on...
## read
## Get the Home Assistant Token, copied from http://localhost:8123/profile/security
## token=xxxx
set +x ## Disable echo
. $HOME/home-assistant-token.sh
set -x ## Enable echo
set +x ## Disable echo
date
echo "----- Power Off the SBC"
curl \
-X POST \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d '{"entity_id": "automation.sg2000_power_off"}' \
http://localhost:8123/api/services/automation/trigger
set -x ## Enable echo
set +x ## Disable echo
date
echo "----- Power On the SBC"
curl \
-X POST \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d '{"entity_id": "automation.sg2000_power_on"}' \
http://localhost:8123/api/services/automation/trigger
set -x ## Enable echo
## Run the Automated Test
set +x ## Disable echo
date
echo "----- Run the Automated Test"
set -x ## Enable echo
$SCRIPT_DIR/nuttx.exp
## Without a Smart Power Plug:
## echo Power off the SBC
set +x ## Disable echo
date
echo "----- Power Off the SBC"
curl \
-X POST \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d '{"entity_id": "automation.sg2000_power_off"}' \
http://localhost:8123/api/services/automation/trigger
date
set -x ## Enable echo
## TODO: Check whether NuttX has crashed
# set +e ## Don't exit when any command fails
# match=$(grep "registerdump" /tmp/test.log)
# set -e ## Exit when any command fails
# if [ "$match" == "" ]; then
# ## If BL602 has not crashed, send the test command to BL602
# else
# ## If BL602 has crashed, do the Crash Analysis
# echo; echo "===== Boot FAILED. Below is the Crash Analysis"; echo
# ## Don't exit when any command fails (grep)
# set +e
# ## Find all code addresses 23?????? in the Output Log, remove duplicates, skip 23007000.
# ## Returns a newline-delimited list of addresses: "23011000\n230053a0\n..."
# grep --extended-regexp \
# --only-matching \
# "23[0-9a-f]{6}" \
# /tmp/test.log \
# | grep -v "23007000" \
# | uniq \
# >/tmp/test.addr
# ## For every address, show the corresponding line in the disassembly
# for addr in $(cat /tmp/test.addr); do
# ## Skip addresses that don't match
# match=$(grep "$addr:" /tmp/nuttx.S)
# if [ "$match" != "" ]; then
# echo "----- Code Address $addr"
# grep \
# --context=5 \
# --color=auto \
# "$addr:" \
# /tmp/nuttx.S
# echo
# fi
# done
# ## Find all data addresses 42?????? in the Output Log, remove duplicates.
# ## Returns a newline-delimited list of addresses: "23011000\n230053a0\n..."
# grep --extended-regexp \
# --only-matching \
# "42[0-9a-f]{6}" \
# /tmp/test.log \
# | uniq \
# >/tmp/test.addr
# ## For every address, show the corresponding line in the disassembly
# for addr in $(cat /tmp/test.addr); do
# ## Skip addresses that don't match
# match=$(grep "^$addr" /tmp/nuttx.S)
# if [ "$match" != "" ]; then
# echo "----- Data Address $addr"
# grep \
# --color=auto \
# "^$addr" \
# /tmp/nuttx.S \
# | grep -v "noinit"
# echo
# fi
# done
# ## Exit when any command fails
# set -e
# fi