5 # Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in
16 # the documentation and/or other materials provided with the
18 # * Neither the name of Intel Corporation nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # collection of static data
49 ALT_B = chr(27) + chr(98)
50 ALT_D = chr(27) + chr(100)
51 ALT_F = chr(27) + chr(102)
52 ALT_BKSPACE = chr(27) + chr(127)
53 DEL = chr(27) + chr(91) + chr(51) + chr(126)
57 RIGHT = chr(27) + chr(91) + chr(67)
58 DOWN = chr(27) + chr(91) + chr(66)
59 LEFT = chr(27) + chr(91) + chr(68)
60 UP = chr(27) + chr(91) + chr(65)
64 # expected result constants
65 NOT_FOUND = "Command not found"
66 BAD_ARG = "Bad arguments"
67 AMBIG = "Ambiguous command"
68 CMD1 = "Command 1 parsed!"
69 CMD2 = "Command 2 parsed!"
70 SINGLE = "Single word command parsed!"
71 SINGLE_LONG = "Single long word command parsed!"
72 AUTO1 = "Autocomplete command 1 parsed!"
73 AUTO2 = "Autocomplete command 2 parsed!"
77 CMD_GET_BUFSIZE = "get_history_bufsize"
78 BUFSIZE_TEMPLATE = "History buffer size: "
79 PROMPT = "CMDLINE_TEST>>"
82 # each test tests progressively diverse set of keys. this way for example
83 # if we want to use some key sequence in the test, we first need to test
84 # that it itself does what it is expected to do. Most of the tests are
87 # example: "arrows & delete test 1". we enter a partially valid command,
88 # then move 3 chars left and use delete three times. this way we get to
89 # know that "delete", "left" and "ctrl+B" all work (because if any of
90 # them fails, the whole test will fail and next tests won't be run).
92 # each test consists of name, character sequence to send to child,
93 # and expected output (if any).
97 {"Name": "command test 1",
98 "Sequence": "ambiguous first" + ENTER,
100 {"Name": "command test 2",
101 "Sequence": "ambiguous second" + ENTER,
103 {"Name": "command test 3",
104 "Sequence": "ambiguous ambiguous" + ENTER,
106 {"Name": "command test 4",
107 "Sequence": "ambiguous ambiguous2" + ENTER,
110 {"Name": "invalid command test 1",
111 "Sequence": "ambiguous invalid" + ENTER,
113 # test invalid commands
114 {"Name": "invalid command test 2",
115 "Sequence": "invalid" + ENTER,
116 "Result": NOT_FOUND},
117 {"Name": "invalid command test 3",
118 "Sequence": "ambiguousinvalid" + ENTER2,
119 "Result": NOT_FOUND},
121 # test arrows and deletes
122 {"Name": "arrows & delete test 1",
123 "Sequence": "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER,
125 {"Name": "arrows & delete test 2",
126 "Sequence": "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER,
130 {"Name": "backspace test",
131 "Sequence": "singlebad" + BKSPACE*3 + ENTER,
134 # test goto left and goto right
135 {"Name": "goto left test",
136 "Sequence": "biguous first" + CTRL_A + "am" + ENTER,
138 {"Name": "goto right test",
139 "Sequence": "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER,
143 {"Name": "goto left word test",
144 "Sequence": "ambiguous st" + ALT_B + "fir" + ENTER,
146 {"Name": "goto right word test",
147 "Sequence": "ambig first" + CTRL_A + ALT_F + "uous" + ENTER,
150 # test removing words
151 {"Name": "remove left word 1",
152 "Sequence": "single invalid" + CTRL_W + ENTER,
154 {"Name": "remove left word 2",
155 "Sequence": "single invalid" + ALT_BKSPACE + ENTER,
157 {"Name": "remove right word",
158 "Sequence": "single invalid" + ALT_B + ALT_D + ENTER,
161 # test kill buffer (copy and paste)
162 {"Name": "killbuffer test 1",
163 "Sequence": "ambiguous" + CTRL_A + CTRL_K + " first" + CTRL_A +
166 {"Name": "killbuffer test 2",
167 "Sequence": "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER,
168 "Result": NOT_FOUND},
171 {"Name": "newline test",
172 "Sequence": "invalid" + CTRL_C + "single" + ENTER,
175 # test redisplay (nothing should really happen)
176 {"Name": "redisplay test",
177 "Sequence": "single" + CTRL_L + ENTER,
181 {"Name": "autocomplete test 1",
182 "Sequence": "si" + TAB + ENTER,
184 {"Name": "autocomplete test 2",
185 "Sequence": "si" + TAB + "_" + TAB + ENTER,
186 "Result": SINGLE_LONG},
187 {"Name": "autocomplete test 3",
188 "Sequence": "in" + TAB + ENTER,
189 "Result": NOT_FOUND},
190 {"Name": "autocomplete test 4",
191 "Sequence": "am" + TAB + ENTER,
193 {"Name": "autocomplete test 5",
194 "Sequence": "am" + TAB + "fir" + TAB + ENTER,
196 {"Name": "autocomplete test 6",
197 "Sequence": "am" + TAB + "fir" + TAB + TAB + ENTER,
199 {"Name": "autocomplete test 7",
200 "Sequence": "am" + TAB + "fir" + TAB + " " + TAB + ENTER,
202 {"Name": "autocomplete test 8",
203 "Sequence": "am" + TAB + " am" + TAB + " " + ENTER,
205 {"Name": "autocomplete test 9",
206 "Sequence": "am" + TAB + "inv" + TAB + ENTER,
208 {"Name": "autocomplete test 10",
209 "Sequence": "au" + TAB + ENTER,
210 "Result": NOT_FOUND},
211 {"Name": "autocomplete test 11",
212 "Sequence": "au" + TAB + "1" + ENTER,
214 {"Name": "autocomplete test 12",
215 "Sequence": "au" + TAB + "2" + ENTER,
217 {"Name": "autocomplete test 13",
218 "Sequence": "au" + TAB + "2" + TAB + ENTER,
220 {"Name": "autocomplete test 14",
221 "Sequence": "au" + TAB + "2 " + TAB + ENTER,
223 {"Name": "autocomplete test 15",
224 "Sequence": "24" + TAB + ENTER,
228 {"Name": "history test 1",
229 "Sequence": "invalid" + ENTER + "single" + ENTER + "invalid" +
230 ENTER + UP + CTRL_P + ENTER,
232 {"Name": "history test 2",
233 "Sequence": "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" +
234 ENTER + "single" + ENTER + UP * 3 + CTRL_N + DOWN + ENTER,
238 # tests that improve coverage
242 {"Name": "empty space test 1",
243 "Sequence": RIGHT + LEFT + CTRL_B + CTRL_F + ENTER,
245 {"Name": "empty space test 2",
246 "Sequence": BKSPACE + ENTER,
248 {"Name": "empty space test 3",
249 "Sequence": CTRL_E*2 + CTRL_A*2 + ENTER,
251 {"Name": "empty space test 4",
252 "Sequence": ALT_F*2 + ALT_B*2 + ENTER,
254 {"Name": "empty space test 5",
255 "Sequence": " " + CTRL_E*2 + CTRL_A*2 + ENTER,
257 {"Name": "empty space test 6",
258 "Sequence": " " + CTRL_A + ALT_F*2 + ALT_B*2 + ENTER,
260 {"Name": "empty space test 7",
261 "Sequence": " " + CTRL_A + CTRL_D + CTRL_E + CTRL_D + ENTER,
263 {"Name": "empty space test 8",
264 "Sequence": " space" + CTRL_W*2 + ENTER,
266 {"Name": "empty space test 9",
267 "Sequence": " space" + ALT_BKSPACE*2 + ENTER,
269 {"Name": "empty space test 10",
270 "Sequence": " space " + CTRL_A + ALT_D*3 + ENTER,
273 # non-printable char tests
274 {"Name": "non-printable test 1",
275 "Sequence": chr(27) + chr(47) + ENTER,
277 {"Name": "non-printable test 2",
278 "Sequence": chr(27) + chr(128) + ENTER*7,
280 {"Name": "non-printable test 3",
281 "Sequence": chr(27) + chr(91) + chr(127) + ENTER*6,
284 # miscellaneous tests
285 {"Name": "misc test 1",
288 {"Name": "misc test 2",
289 "Sequence": "single #comment" + ENTER,
291 {"Name": "misc test 3",
292 "Sequence": "#empty line" + ENTER,
294 {"Name": "misc test 4",
295 "Sequence": " single " + ENTER,
297 {"Name": "misc test 5",
298 "Sequence": "single#" + ENTER,
300 {"Name": "misc test 6",
301 "Sequence": 'a' * 257 + ENTER,
302 "Result": NOT_FOUND},
303 {"Name": "misc test 7",
304 "Sequence": "clear_history" + UP*5 + DOWN*5 + ENTER,
306 {"Name": "misc test 8",
307 "Sequence": "a" + HELP + CTRL_C,
309 {"Name": "misc test 9",
310 "Sequence": CTRL_D*3,