2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2010-2014 Intel Corporation
5 # collection of static data
20 ALT_B = chr(27) + chr(98)
21 ALT_D = chr(27) + chr(100)
22 ALT_F = chr(27) + chr(102)
23 ALT_BKSPACE = chr(27) + chr(127)
24 DEL = chr(27) + chr(91) + chr(51) + chr(126)
28 RIGHT = chr(27) + chr(91) + chr(67)
29 DOWN = chr(27) + chr(91) + chr(66)
30 LEFT = chr(27) + chr(91) + chr(68)
31 UP = chr(27) + chr(91) + chr(65)
35 # expected result constants
36 NOT_FOUND = "Command not found"
37 BAD_ARG = "Bad arguments"
38 AMBIG = "Ambiguous command"
39 CMD1 = "Command 1 parsed!"
40 CMD2 = "Command 2 parsed!"
41 SINGLE = "Single word command parsed!"
42 SINGLE_LONG = "Single long word command parsed!"
43 AUTO1 = "Autocomplete command 1 parsed!"
44 AUTO2 = "Autocomplete command 2 parsed!"
48 CMD_GET_BUFSIZE = "get_history_bufsize"
49 BUFSIZE_TEMPLATE = "History buffer size: "
50 PROMPT = "CMDLINE_TEST>>"
53 # each test tests progressively diverse set of keys. this way for example
54 # if we want to use some key sequence in the test, we first need to test
55 # that it itself does what it is expected to do. Most of the tests are
58 # example: "arrows & delete test 1". we enter a partially valid command,
59 # then move 3 chars left and use delete three times. this way we get to
60 # know that "delete", "left" and "ctrl+B" all work (because if any of
61 # them fails, the whole test will fail and next tests won't be run).
63 # each test consists of name, character sequence to send to child,
64 # and expected output (if any).
68 {"Name": "command test 1",
69 "Sequence": "ambiguous first" + ENTER,
71 {"Name": "command test 2",
72 "Sequence": "ambiguous second" + ENTER,
74 {"Name": "command test 3",
75 "Sequence": "ambiguous ambiguous" + ENTER,
77 {"Name": "command test 4",
78 "Sequence": "ambiguous ambiguous2" + ENTER,
81 {"Name": "invalid command test 1",
82 "Sequence": "ambiguous invalid" + ENTER,
84 # test invalid commands
85 {"Name": "invalid command test 2",
86 "Sequence": "invalid" + ENTER,
88 {"Name": "invalid command test 3",
89 "Sequence": "ambiguousinvalid" + ENTER2,
92 # test arrows and deletes
93 {"Name": "arrows & delete test 1",
94 "Sequence": "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER,
96 {"Name": "arrows & delete test 2",
97 "Sequence": "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER,
101 {"Name": "backspace test",
102 "Sequence": "singlebad" + BKSPACE*3 + ENTER,
105 # test goto left and goto right
106 {"Name": "goto left test",
107 "Sequence": "biguous first" + CTRL_A + "am" + ENTER,
109 {"Name": "goto right test",
110 "Sequence": "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER,
114 {"Name": "goto left word test",
115 "Sequence": "ambiguous st" + ALT_B + "fir" + ENTER,
117 {"Name": "goto right word test",
118 "Sequence": "ambig first" + CTRL_A + ALT_F + "uous" + ENTER,
121 # test removing words
122 {"Name": "remove left word 1",
123 "Sequence": "single invalid" + CTRL_W + ENTER,
125 {"Name": "remove left word 2",
126 "Sequence": "single invalid" + ALT_BKSPACE + ENTER,
128 {"Name": "remove right word",
129 "Sequence": "single invalid" + ALT_B + ALT_D + ENTER,
132 # test kill buffer (copy and paste)
133 {"Name": "killbuffer test 1",
134 "Sequence": "ambiguous" + CTRL_A + CTRL_K + " first" + CTRL_A +
137 {"Name": "killbuffer test 2",
138 "Sequence": "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER,
139 "Result": NOT_FOUND},
142 {"Name": "newline test",
143 "Sequence": "invalid" + CTRL_C + "single" + ENTER,
146 # test redisplay (nothing should really happen)
147 {"Name": "redisplay test",
148 "Sequence": "single" + CTRL_L + ENTER,
152 {"Name": "autocomplete test 1",
153 "Sequence": "si" + TAB + ENTER,
155 {"Name": "autocomplete test 2",
156 "Sequence": "si" + TAB + "_" + TAB + ENTER,
157 "Result": SINGLE_LONG},
158 {"Name": "autocomplete test 3",
159 "Sequence": "in" + TAB + ENTER,
160 "Result": NOT_FOUND},
161 {"Name": "autocomplete test 4",
162 "Sequence": "am" + TAB + ENTER,
164 {"Name": "autocomplete test 5",
165 "Sequence": "am" + TAB + "fir" + TAB + ENTER,
167 {"Name": "autocomplete test 6",
168 "Sequence": "am" + TAB + "fir" + TAB + TAB + ENTER,
170 {"Name": "autocomplete test 7",
171 "Sequence": "am" + TAB + "fir" + TAB + " " + TAB + ENTER,
173 {"Name": "autocomplete test 8",
174 "Sequence": "am" + TAB + " am" + TAB + " " + ENTER,
176 {"Name": "autocomplete test 9",
177 "Sequence": "am" + TAB + "inv" + TAB + ENTER,
179 {"Name": "autocomplete test 10",
180 "Sequence": "au" + TAB + ENTER,
181 "Result": NOT_FOUND},
182 {"Name": "autocomplete test 11",
183 "Sequence": "au" + TAB + "1" + ENTER,
185 {"Name": "autocomplete test 12",
186 "Sequence": "au" + TAB + "2" + ENTER,
188 {"Name": "autocomplete test 13",
189 "Sequence": "au" + TAB + "2" + TAB + ENTER,
191 {"Name": "autocomplete test 14",
192 "Sequence": "au" + TAB + "2 " + TAB + ENTER,
194 {"Name": "autocomplete test 15",
195 "Sequence": "24" + TAB + ENTER,
199 {"Name": "history test 1",
200 "Sequence": "invalid" + ENTER + "single" + ENTER + "invalid" +
201 ENTER + UP + CTRL_P + ENTER,
203 {"Name": "history test 2",
204 "Sequence": "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" +
205 ENTER + "single" + ENTER + UP * 3 + CTRL_N + DOWN + ENTER,
209 # tests that improve coverage
213 {"Name": "empty space test 1",
214 "Sequence": RIGHT + LEFT + CTRL_B + CTRL_F + ENTER,
216 {"Name": "empty space test 2",
217 "Sequence": BKSPACE + ENTER,
219 {"Name": "empty space test 3",
220 "Sequence": CTRL_E*2 + CTRL_A*2 + ENTER,
222 {"Name": "empty space test 4",
223 "Sequence": ALT_F*2 + ALT_B*2 + ENTER,
225 {"Name": "empty space test 5",
226 "Sequence": " " + CTRL_E*2 + CTRL_A*2 + ENTER,
228 {"Name": "empty space test 6",
229 "Sequence": " " + CTRL_A + ALT_F*2 + ALT_B*2 + ENTER,
231 {"Name": "empty space test 7",
232 "Sequence": " " + CTRL_A + CTRL_D + CTRL_E + CTRL_D + ENTER,
234 {"Name": "empty space test 8",
235 "Sequence": " space" + CTRL_W*2 + ENTER,
237 {"Name": "empty space test 9",
238 "Sequence": " space" + ALT_BKSPACE*2 + ENTER,
240 {"Name": "empty space test 10",
241 "Sequence": " space " + CTRL_A + ALT_D*3 + ENTER,
244 # non-printable char tests
245 {"Name": "non-printable test 1",
246 "Sequence": chr(27) + chr(47) + ENTER,
248 {"Name": "non-printable test 2",
249 "Sequence": chr(27) + chr(128) + ENTER*7,
251 {"Name": "non-printable test 3",
252 "Sequence": chr(27) + chr(91) + chr(127) + ENTER*6,
255 # miscellaneous tests
256 {"Name": "misc test 1",
259 {"Name": "misc test 2",
260 "Sequence": "single #comment" + ENTER,
262 {"Name": "misc test 3",
263 "Sequence": "#empty line" + ENTER,
265 {"Name": "misc test 4",
266 "Sequence": " single " + ENTER,
268 {"Name": "misc test 5",
269 "Sequence": "single#" + ENTER,
271 {"Name": "misc test 6",
272 "Sequence": 'a' * 257 + ENTER,
273 "Result": NOT_FOUND},
274 {"Name": "misc test 7",
275 "Sequence": "clear_history" + UP*5 + DOWN*5 + ENTER,
277 {"Name": "misc test 8",
278 "Sequence": "a" + HELP + CTRL_C,
280 {"Name": "misc test 9",
281 "Sequence": CTRL_D*3,