|
6 | 6 | # General Public License v2.1. See the file LICENSE in the top level |
7 | 7 | # directory for more details. |
8 | 8 |
|
9 | | -import sys |
| 9 | +import json |
10 | 10 | import os |
| 11 | +import sys |
11 | 12 | from testrunner import run |
12 | 13 |
|
13 | 14 |
|
14 | | -EXPECTED_HELP = ( |
15 | | - 'Command Description', |
16 | | - '---------------------------------------', |
17 | | - 'bufsize Get the shell\'s buffer size', |
18 | | - 'start_test starts a test', |
19 | | - 'end_test ends a test', |
20 | | - 'echo prints the input command', |
21 | | - 'empty print nothing on command', |
22 | | - 'periodic periodically print command', |
23 | | - 'app_metadata Returns application metadata', |
24 | | - 'pm interact with layered PM subsystem', |
25 | | - 'ps Prints information about running threads.', |
26 | | - 'reboot Reboot the node', |
27 | | - 'version Prints current RIOT_VERSION', |
28 | | - 'xfa_test1 xfa test command 1', |
29 | | - 'xfa_test2 xfa test command 2' |
30 | | -) |
| 15 | +# This is the minimum subset of commands expected to be available on all |
| 16 | +# boards. The test will still pass if additional commands are present, as |
| 17 | +# `shell_cmds_default` may pull in board specific commands. |
| 18 | +EXPECTED_CMDS = { |
| 19 | + 'bufsize': 'Get the shell\'s buffer size', |
| 20 | + 'start_test': 'starts a test', |
| 21 | + 'end_test': 'ends a test', |
| 22 | + 'echo': 'prints the input command', |
| 23 | + 'empty': 'print nothing on command', |
| 24 | + 'periodic': 'periodically print command', |
| 25 | + 'app_metadata': 'Returns application metadata', |
| 26 | + 'pm': 'interact with layered PM subsystem', |
| 27 | + 'ps': 'Prints information about running threads.', |
| 28 | + 'reboot': 'Reboot the node', |
| 29 | + 'version': 'Prints current RIOT_VERSION', |
| 30 | + 'xfa_test1': 'xfa test command 1', |
| 31 | + 'xfa_test2': 'xfa test command 2', |
| 32 | +} |
31 | 33 |
|
32 | 34 | EXPECTED_PS = ( |
33 | 35 | '\tpid | state Q | pri', |
|
103 | 105 |
|
104 | 106 | # test default commands |
105 | 107 | ('ps', EXPECTED_PS), |
106 | | - ('help', EXPECTED_HELP), |
107 | 108 |
|
108 | 109 | # test commands added to shell_commands_xfa |
109 | 110 | ('xfa_test1', '[XFA TEST 1 OK]'), |
@@ -151,6 +152,41 @@ def check_cmd(child, cmd, expected): |
151 | 152 | child.expect_exact(line) |
152 | 153 |
|
153 | 154 |
|
| 155 | +def check_help(child): |
| 156 | + # First: use help_json to get the list of supported commands and do some |
| 157 | + # checking for this (e.g. are all expected cmds present) |
| 158 | + child.expect(PROMPT) |
| 159 | + child.sendline('help_json') |
| 160 | + child.expect(r"(\{[^\n\r]*\})\r\n") |
| 161 | + cmdlist = json.loads(child.match.group(1))["cmds"] |
| 162 | + cmds_expected = set(EXPECTED_CMDS) |
| 163 | + cmds_actual = set() |
| 164 | + desc_actual = {} |
| 165 | + for item in cmdlist: |
| 166 | + if item['cmd'] in EXPECTED_CMDS: |
| 167 | + assert item['cmd'] in cmds_expected, f"command {item['cmd']} listed twice" |
| 168 | + assert item['desc'] == EXPECTED_CMDS[item['cmd']], f"description of {item['cmd']} not expected" |
| 169 | + cmds_expected.remove(item['cmd']) |
| 170 | + |
| 171 | + cmds_actual.add(item['cmd']) |
| 172 | + desc_actual[item['cmd']] = item['desc'] |
| 173 | + |
| 174 | + assert len(cmds_expected) == 0, f"commands {cmds_expected} missing" |
| 175 | + |
| 176 | + # Now: Run regular help and expect the same commands as help_json |
| 177 | + child.expect(PROMPT) |
| 178 | + child.sendline('help') |
| 179 | + child.expect_exact('Command Description\r\n') |
| 180 | + child.expect_exact('---------------------------------------\r\n') |
| 181 | + while len(cmds_actual) > 0: |
| 182 | + child.expect(r"([a-z0-9_-]*)[ \t]*(.*)\r\n") |
| 183 | + cmd = child.match.group(1) |
| 184 | + desc = child.match.group(2) |
| 185 | + assert cmd in cmds_actual, f"Command \"{cmd}\" unexpected or listed twice in help" |
| 186 | + cmds_actual.remove(cmd) |
| 187 | + assert desc == desc_actual[cmd], f"Description for \"{cmd}\" not matching" |
| 188 | + |
| 189 | + |
154 | 190 | def check_startup(child): |
155 | 191 | child.sendline(CONTROL_C) |
156 | 192 | child.expect_exact(PROMPT) |
@@ -247,6 +283,8 @@ def testfunc(child): |
247 | 283 |
|
248 | 284 | check_cmd(child, cmd, expected) |
249 | 285 |
|
| 286 | + check_help(child) |
| 287 | + |
250 | 288 | if RIOT_TERMINAL in CLEANTERMS: |
251 | 289 | for cmd, expected in CMDS_CLEANTERM: |
252 | 290 | check_cmd(child, cmd, expected) |
|
0 commit comments