1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2010-2014 Intel Corporation
4 # collection of static data
19 ALT_B = chr(27) + chr(98)
20 ALT_D = chr(27) + chr(100)
21 ALT_F = chr(27) + chr(102)
22 ALT_BKSPACE = chr(27) + chr(127)
23 DEL = chr(27) + chr(91) + chr(51) + chr(126)
27 RIGHT = chr(27) + chr(91) + chr(67)
28 DOWN = chr(27) + chr(91) + chr(66)
29 LEFT = chr(27) + chr(91) + chr(68)
30 UP = chr(27) + chr(91) + chr(65)
34 # expected result constants
35 NOT_FOUND = "Command not found"
36 BAD_ARG = "Bad arguments"
37 AMBIG = "Ambiguous command"
38 CMD1 = "Command 1 parsed!"
39 CMD2 = "Command 2 parsed!"
40 SINGLE = "Single word command parsed!"
41 SINGLE_LONG = "Single long word command parsed!"
42 AUTO1 = "Autocomplete command 1 parsed!"
43 AUTO2 = "Autocomplete command 2 parsed!"
47 CMD_GET_BUFSIZE = "get_history_bufsize"
48 BUFSIZE_TEMPLATE = "History buffer size: "
49 PROMPT = "CMDLINE_TEST>>"
52 # each test tests progressively diverse set of keys. this way for example
53 # if we want to use some key sequence in the test, we first need to test
54 # that it itself does what it is expected to do. Most of the tests are
57 # example: "arrows & delete test 1". we enter a partially valid command,
58 # then move 3 chars left and use delete three times. this way we get to
59 # know that "delete", "left" and "ctrl+B" all work (because if any of
60 # them fails, the whole test will fail and next tests won't be run).
62 # each test consists of name, character sequence to send to child,
63 # and expected output (if any).
67 {"Name": "command test 1",
68 "Sequence": "ambiguous first" + ENTER,
70 {"Name": "command test 2",
71 "Sequence": "ambiguous second" + ENTER,
73 {"Name": "command test 3",
74 "Sequence": "ambiguous ambiguous" + ENTER,
76 {"Name": "command test 4",
77 "Sequence": "ambiguous ambiguous2" + ENTER,
80 {"Name": "invalid command test 1",
81 "Sequence": "ambiguous invalid" + ENTER,
83 # test invalid commands
84 {"Name": "invalid command test 2",
85 "Sequence": "invalid" + ENTER,
87 {"Name": "invalid command test 3",
88 "Sequence": "ambiguousinvalid" + ENTER2,
91 # test arrows and deletes
92 {"Name": "arrows & delete test 1",
93 "Sequence": "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER,
95 {"Name": "arrows & delete test 2",
96 "Sequence": "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER,
100 {"Name": "backspace test",
101 "Sequence": "singlebad" + BKSPACE*3 + ENTER,
104 # test goto left and goto right
105 {"Name": "goto left test",
106 "Sequence": "biguous first" + CTRL_A + "am" + ENTER,
108 {"Name": "goto right test",
109 "Sequence": "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER,
113 {"Name": "goto left word test",
114 "Sequence": "ambiguous st" + ALT_B + "fir" + ENTER,
116 {"Name": "goto right word test",
117 "Sequence": "ambig first" + CTRL_A + ALT_F + "uous" + ENTER,
120 # test removing words
121 {"Name": "remove left word 1",
122 "Sequence": "single invalid" + CTRL_W + ENTER,
124 {"Name": "remove left word 2",
125 "Sequence": "single invalid" + ALT_BKSPACE + ENTER,
127 {"Name": "remove right word",
128 "Sequence": "single invalid" + ALT_B + ALT_D + ENTER,
131 # test kill buffer (copy and paste)
132 {"Name": "killbuffer test 1",
133 "Sequence": "ambiguous" + CTRL_A + CTRL_K + " first" + CTRL_A +
136 {"Name": "killbuffer test 2",
137 "Sequence": "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER,
138 "Result": NOT_FOUND},
141 {"Name": "newline test",
142 "Sequence": "invalid" + CTRL_C + "single" + ENTER,
145 # test redisplay (nothing should really happen)
146 {"Name": "redisplay test",
147 "Sequence": "single" + CTRL_L + ENTER,
151 {"Name": "autocomplete test 1",
152 "Sequence": "si" + TAB + ENTER,
154 {"Name": "autocomplete test 2",
155 "Sequence": "si" + TAB + "_" + TAB + ENTER,
156 "Result": SINGLE_LONG},
157 {"Name": "autocomplete test 3",
158 "Sequence": "in" + TAB + ENTER,
159 "Result": NOT_FOUND},
160 {"Name": "autocomplete test 4",
161 "Sequence": "am" + TAB + ENTER,
163 {"Name": "autocomplete test 5",
164 "Sequence": "am" + TAB + "fir" + TAB + ENTER,
166 {"Name": "autocomplete test 6",
167 "Sequence": "am" + TAB + "fir" + TAB + TAB + ENTER,
169 {"Name": "autocomplete test 7",
170 "Sequence": "am" + TAB + "fir" + TAB + " " + TAB + ENTER,
172 {"Name": "autocomplete test 8",
173 "Sequence": "am" + TAB + " am" + TAB + " " + ENTER,
175 {"Name": "autocomplete test 9",
176 "Sequence": "am" + TAB + "inv" + TAB + ENTER,
178 {"Name": "autocomplete test 10",
179 "Sequence": "au" + TAB + ENTER,
180 "Result": NOT_FOUND},
181 {"Name": "autocomplete test 11",
182 "Sequence": "au" + TAB + "1" + ENTER,
184 {"Name": "autocomplete test 12",
185 "Sequence": "au" + TAB + "2" + ENTER,
187 {"Name": "autocomplete test 13",
188 "Sequence": "au" + TAB + "2" + TAB + ENTER,
190 {"Name": "autocomplete test 14",
191 "Sequence": "au" + TAB + "2 " + TAB + ENTER,
193 {"Name": "autocomplete test 15",
194 "Sequence": "24" + TAB + ENTER,
198 {"Name": "history test 1",
199 "Sequence": "invalid" + ENTER + "single" + ENTER + "invalid" +
200 ENTER + UP + CTRL_P + ENTER,
202 {"Name": "history test 2",
203 "Sequence": "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" +
204 ENTER + "single" + ENTER + UP * 3 + CTRL_N + DOWN + ENTER,
208 # tests that improve coverage
212 {"Name": "empty space test 1",
213 "Sequence": RIGHT + LEFT + CTRL_B + CTRL_F + ENTER,
215 {"Name": "empty space test 2",
216 "Sequence": BKSPACE + ENTER,
218 {"Name": "empty space test 3",
219 "Sequence": CTRL_E*2 + CTRL_A*2 + ENTER,
221 {"Name": "empty space test 4",
222 "Sequence": ALT_F*2 + ALT_B*2 + ENTER,
224 {"Name": "empty space test 5",
225 "Sequence": " " + CTRL_E*2 + CTRL_A*2 + ENTER,
227 {"Name": "empty space test 6",
228 "Sequence": " " + CTRL_A + ALT_F*2 + ALT_B*2 + ENTER,
230 {"Name": "empty space test 7",
231 "Sequence": " " + CTRL_A + CTRL_D + CTRL_E + CTRL_D + ENTER,
233 {"Name": "empty space test 8",
234 "Sequence": " space" + CTRL_W*2 + ENTER,
236 {"Name": "empty space test 9",
237 "Sequence": " space" + ALT_BKSPACE*2 + ENTER,
239 {"Name": "empty space test 10",
240 "Sequence": " space " + CTRL_A + ALT_D*3 + ENTER,
243 # non-printable char tests
244 {"Name": "non-printable test 1",
245 "Sequence": chr(27) + chr(47) + ENTER,
247 {"Name": "non-printable test 2",
248 "Sequence": chr(27) + chr(128) + ENTER*7,
250 {"Name": "non-printable test 3",
251 "Sequence": chr(27) + chr(91) + chr(127) + ENTER*6,
254 # miscellaneous tests
255 {"Name": "misc test 1",
258 {"Name": "misc test 2",
259 "Sequence": "single #comment" + ENTER,
261 {"Name": "misc test 3",
262 "Sequence": "#empty line" + ENTER,
264 {"Name": "misc test 4",
265 "Sequence": " single " + ENTER,
267 {"Name": "misc test 5",
268 "Sequence": "single#" + ENTER,
270 {"Name": "misc test 6",
271 "Sequence": 'a' * 257 + ENTER,
272 "Result": NOT_FOUND},
273 {"Name": "misc test 7",
274 "Sequence": "clear_history" + UP*5 + DOWN*5 + ENTER,
276 {"Name": "misc test 8",
277 "Sequence": "a" + HELP + CTRL_C,
279 {"Name": "misc test 9",
280 "Sequence": CTRL_D*3,