[diag] refactor command processing to remove redundant code (#11055)

All diagnostic commands (instead of `diag start`) should fail if
device is not in diagnostic mode. Previously it was verified by
each command's process method (with a missing check in
`ProcessEcho` and `ProcessGpio`). This commit moves the check
directly to `ProcessCmd` and cleans up redundant code.

Additionally clean the documentation and align the code as for
some commands `status 0x00` was added on success and for some not.

Move `AppendErrorResult()` to `ProcessCmd()` as well.

Signed-off-by: Maciej Baczmanski <[email protected]>
This commit is contained in:
Maciej Baczmański
2024-12-18 13:52:33 -08:00
committed by GitHub
parent 4e9d362b67
commit 33c9e67a9e
6 changed files with 44 additions and 82 deletions
-12
View File
@@ -36,12 +36,10 @@ spawn_node 2
switch_node 1
send "diag start\n"
expect "start diagnostics mode"
expect "status 0x00"
expect_line "Done"
send "diag channel 11\n"
expect "set channel to 11"
expect "status 0x00"
expect_line "Done"
send "diag stats clear\n"
@@ -52,12 +50,10 @@ switch_node 2
send "diag start\n"
expect "start diagnostics mode"
expect "status 0x00"
expect_line "Done"
send "diag channel 11\n"
expect "set channel to 11"
expect "status 0x00"
expect_line "Done"
send "diag stats clear\n"
@@ -66,7 +62,6 @@ expect_line "Done"
send "diag send 10 100\n"
expect "sending 0xa packet(s), length 0x64"
expect "status 0x00"
expect_line "Done"
sleep 2
@@ -95,12 +90,10 @@ switch_node 2
send "diag repeat 20 100\n"
expect "sending packets of length 0x64 at the delay of 0x14 ms"
expect "status 0x00"
expect_line "Done"
sleep 1
send "diag repeat stop\n"
expect "repeated packet transmission is stopped"
expect "status 0x00"
expect_line "Done"
switch_node 1
@@ -123,7 +116,6 @@ spawn_node 1
send "diag start\n"
expect "start diagnostics mode"
expect "status 0x00"
expect_line "Done"
send_user "input too short test\n"
@@ -178,17 +170,14 @@ expect "Done"
send "diag channel 11\n"
expect "set channel to 11"
expect "status 0x00"
expect_line "Done"
send "diag power 10\n"
expect "set tx power to 10 dBm"
expect "status 0x00"
expect_line "Done"
send "diag radio sleep\n"
expect "set radio from receive to sleep"
expect "status 0x00"
expect_line "Done"
send "diag radio state\n"
@@ -197,7 +186,6 @@ expect_line "Done"
send "diag radio receive\n"
expect "set radio from sleep to receive on channel 11"
expect "status 0x00"
expect_line "Done"
send "diag radio state\n"
+3 -2
View File
@@ -33,10 +33,11 @@ spawn_node 1
send "diag rcp\n"
expect "diagnostics mode is disabled"
expect_line "Done"
expect_line "failed"
expect_line "status 0xd"
expect_line "Error 13: InvalidState"
send "diag start\n"
expect "start diagnostics mode"
expect "status 0x00"
expect_line "Done"
send "diag rcp\n"
expect "diagnostics mode is enabled"
@@ -33,7 +33,6 @@ spawn_node 1
send "diag start\n"
expect "start diagnostics mode"
expect "status 0x00"
expect_line "Done"
send "diag powersettings 11\n"
@@ -54,7 +53,6 @@ expect_line "Done"
send "diag start\n"
expect "start diagnostics mode"
expect "status 0x00"
expect_line "Done"
send "diag powersettings 11\n"
+7 -7
View File
@@ -48,9 +48,9 @@ class TestDiag(thread_cert.TestCase):
('diag invalid test\n', 'diag feature \'invalid\' is not supported'),
('diag', 'diagnostics mode is enabled\r\n'),
('diag channel 10', 'failed\r\nstatus 0x7\r\n'),
('diag channel 11', 'set channel to 11\r\nstatus 0x00\r\n'),
('diag channel 11', 'set channel to 11\r\n'),
('diag channel', 'channel: 11\r\n'),
('diag power -10', 'set tx power to -10 dBm\r\nstatus 0x00\r\n'),
('diag power -10', 'set tx power to -10 dBm\r\n'),
('diag power', 'tx power: -10 dBm\r\n'),
(
'diag stats',
@@ -60,26 +60,26 @@ class TestDiag(thread_cert.TestCase):
),
(
'diag send 20 100',
r'sending 0x14 packet\(s\), length 0x64\r\nstatus 0x00\r\n',
r'sending 0x14 packet\(s\), length 0x64\r\n',
),
(
' diag \t send \t 20\t100',
r'sending 0x14 packet\(s\), length 0x64\r\nstatus 0x00\r\n',
r'sending 0x14 packet\(s\), length 0x64\r\n',
),
(
'diag repeat 100 100',
'sending packets of length 0x64 at the delay of 0x64 ms\r\nstatus 0x00\r\n',
'sending packets of length 0x64 at the delay of 0x64 ms\r\n',
),
(
'diag repeat stop',
'repeated packet transmission is stopped\r\nstatus 0x00\r\n',
'repeated packet transmission is stopped\r\n',
),
(
'diag stop',
r'received packets: 0\r\nsent packets: ([1-9]\d*)\r\n'
'first received packet: rssi=0, lqi=0\r\n'
'last received packet: rssi=0, lqi=0\r\n\n'
r'stop diagnostics mode\r\nstatus 0x00\r\n',
r'stop diagnostics mode\r\n',
),
('diag', 'diagnostics mode is disabled\r\n'),
(