1#!/usr/bin/expect -f
2#
3#  Copyright (c) 2022, The OpenThread Authors.
4#  All rights reserved.
5#
6#  Redistribution and use in source and binary forms, with or without
7#  modification, are permitted provided that the following conditions are met:
8#  1. Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10#  2. Redistributions in binary form must reproduce the above copyright
11#     notice, this list of conditions and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#  3. Neither the name of the copyright holder nor the
14#     names of its contributors may be used to endorse or promote products
15#     derived from this software without specific prior written permission.
16#
17#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27#  POSSIBILITY OF SUCH DAMAGE.
28#
29
30source "tests/scripts/expect/_common.exp"
31source "tests/scripts/expect/_multinode.exp"
32
33spawn_node 1
34spawn_node 2
35
36switch_node 1
37send "diag start\n"
38expect "start diagnostics mode"
39expect "status 0x00"
40expect_line "Done"
41
42send "diag channel 11\n"
43expect "set channel to 11"
44expect "status 0x00"
45expect_line "Done"
46
47send "diag stats clear\n"
48expect "stats cleared"
49expect_line "Done"
50
51switch_node 2
52
53send "diag start\n"
54expect "start diagnostics mode"
55expect "status 0x00"
56expect_line "Done"
57
58send "diag channel 11\n"
59expect "set channel to 11"
60expect "status 0x00"
61expect_line "Done"
62
63send "diag stats clear\n"
64expect "stats cleared"
65expect_line "Done"
66
67send "diag send 10 100\n"
68expect "sending 0xa packet(s), length 0x64"
69expect "status 0x00"
70expect_line "Done"
71
72sleep 2
73
74send "diag stats\n"
75expect "received packets: 0"
76expect "sent packets: 10"
77expect "first received packet: rssi=0, lqi=0"
78expect "last received packet: rssi=0, lqi=0"
79expect_line "Done"
80
81switch_node 1
82
83send "diag stats\n"
84expect "received packets: 10"
85expect "sent packets: 0"
86expect "first received packet: rssi=-20, lqi=0"
87expect "last received packet: rssi=-20, lqi=0"
88expect_line "Done"
89
90send "diag stats clear\n"
91expect "stats cleared"
92expect_line "Done"
93
94switch_node 2
95
96send "diag repeat 20 100\n"
97expect "sending packets of length 0x64 at the delay of 0x14 ms"
98expect "status 0x00"
99expect_line "Done"
100sleep 1
101send "diag repeat stop\n"
102expect "repeated packet transmission is stopped"
103expect "status 0x00"
104expect_line "Done"
105
106switch_node 1
107
108send "diag stats\n"
109expect -r {received packets: \d+}
110expect "sent packets: 0"
111expect "first received packet: rssi=-20, lqi=0"
112expect "last received packet: rssi=-20, lqi=0"
113expect_line "Done"
114
115send "diag stats clear\n"
116expect "stats cleared"
117expect_line "Done"
118
119dispose_all
120
121
122spawn_node 1
123
124send "diag start\n"
125expect "start diagnostics mode"
126expect "status 0x00"
127expect_line "Done"
128
129send_user "input too short test\n"
130send "diag frame 11\n"
131expect "Error"
132
133send_user "input too long test\n"
134send "diag frame 11223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900\n"
135expect "Error"
136
137send_user "input odd length test\n"
138send "diag frame 123\n"
139expect "Error"
140
141send_user "shortest frame test\n"
142send "diag frame 112233\n"
143expect "Done"
144send "diag send 1\n"
145expect "length 0x3"
146expect "Done"
147
148send_user "longest frame test\n"
149send "diag frame 11223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677\n"
150expect "Done"
151send "diag repeat 1\n"
152expect "length 0x7f"
153expect "Done"
154
155send_user "send frame with security processed\n"
156send "diag frame -s 112233\n"
157expect "Done"
158send "diag send 1\n"
159expect "length 0x3"
160expect "Done"
161
162send "diag repeat stop\n"
163expect "Done"
164
165send "diag channel 11\n"
166expect "set channel to 11"
167expect "status 0x00"
168expect_line "Done"
169
170send "diag power 10\n"
171expect "set tx power to 10 dBm"
172expect "status 0x00"
173expect_line "Done"
174
175send "diag radio sleep\n"
176expect "set radio from receive to sleep"
177expect "status 0x00"
178expect_line "Done"
179
180send "diag radio state\n"
181expect "sleep"
182expect_line "Done"
183
184send "diag radio receive\n"
185expect "set radio from sleep to receive on channel 11"
186expect "status 0x00"
187expect_line "Done"
188
189send "diag radio state\n"
190expect "receive"
191expect_line "Done"
192
193send "diag gpio set 0 1\n"
194expect_line "Done"
195
196send "diag gpio get 0\n"
197expect "1"
198expect_line "Done"
199
200send "diag gpio mode 0 in\n"
201expect_line "Done"
202
203send "diag gpio mode 0\n"
204expect "in"
205expect_line "Done"
206
207send "diag gpio mode 0 out\n"
208expect_line "Done"
209
210send "diag gpio mode 0\n"
211expect "out"
212expect_line "Done"
213
214send "diag cw start\n"
215expect_line "Done"
216
217send "diag cw stop\n"
218expect_line "Done"
219
220send "diag stream start\n"
221expect_line "Done"
222
223send "diag stream stop\n"
224expect_line "Done"
225
226send "diag rawpowersetting 112233\n"
227expect_line "Done"
228
229send "diag rawpowersetting\n"
230expect "112233"
231expect_line "Done"
232
233send "diag rawpowersetting enable\n"
234expect_line "Done"
235
236send "diag rawpowersetting disable\n"
237expect_line "Done"
238
239send "diag invalid_commad\n"
240expect "Error 35: InvalidCommand"
241
242send "diag stop\n"
243expect_line "Done"
244
245send "diag channel\n"
246expect "failed"
247expect "status 0xd"
248expect "Error 13: InvalidState"
249
250dispose_all
251