3 # Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in
14 # the documentation and/or other materials provided with the
16 # * Neither the name of Intel Corporation nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # collection of static data
47 ALT_B = chr(27) + chr(98)
48 ALT_D = chr(27) + chr(100)
49 ALT_F = chr(27) + chr(102)
50 ALT_BKSPACE = chr(27) + chr(127)
51 DEL = chr(27) + chr(91) + chr(51) + chr(126)
55 RIGHT = chr(27) + chr(91) + chr(67)
56 DOWN = chr(27) + chr(91) + chr(66)
57 LEFT = chr(27) + chr(91) + chr(68)
58 UP = chr(27) + chr(91) + chr(65)
62 # expected result constants
63 NOT_FOUND = "Command not found"
64 BAD_ARG = "Bad arguments"
65 AMBIG = "Ambiguous command"
66 CMD1 = "Command 1 parsed!"
67 CMD2 = "Command 2 parsed!"
68 SINGLE = "Single word command parsed!"
69 SINGLE_LONG = "Single long word command parsed!"
70 AUTO1 = "Autocomplete command 1 parsed!"
71 AUTO2 = "Autocomplete command 2 parsed!"
75 CMD_GET_BUFSIZE = "get_history_bufsize"
76 BUFSIZE_TEMPLATE = "History buffer size: "
77 PROMPT = "CMDLINE_TEST>>"
80 # each test tests progressively diverse set of keys. this way for example
81 # if we want to use some key sequence in the test, we first need to test
82 # that it itself does what it is expected to do. Most of the tests are
85 # example: "arrows & delete test 1". we enter a partially valid command,
86 # then move 3 chars left and use delete three times. this way we get to
87 # know that "delete", "left" and "ctrl+B" all work (because if any of
88 # them fails, the whole test will fail and next tests won't be run).
90 # each test consists of name, character sequence to send to child,
91 # and expected output (if any).
95 {"Name": "command test 1",
96 "Sequence": "ambiguous first" + ENTER,
98 {"Name": "command test 2",
99 "Sequence": "ambiguous second" + ENTER,
101 {"Name": "command test 3",
102 "Sequence": "ambiguous ambiguous" + ENTER,
104 {"Name": "command test 4",
105 "Sequence": "ambiguous ambiguous2" + ENTER,
108 {"Name": "invalid command test 1",
109 "Sequence": "ambiguous invalid" + ENTER,
111 # test invalid commands
112 {"Name": "invalid command test 2",
113 "Sequence": "invalid" + ENTER,
114 "Result": NOT_FOUND},
115 {"Name": "invalid command test 3",
116 "Sequence": "ambiguousinvalid" + ENTER2,
117 "Result": NOT_FOUND},
119 # test arrows and deletes
120 {"Name": "arrows & delete test 1",
121 "Sequence": "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER,
123 {"Name": "arrows & delete test 2",
124 "Sequence": "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER,
128 {"Name": "backspace test",
129 "Sequence": "singlebad" + BKSPACE*3 + ENTER,
132 # test goto left and goto right
133 {"Name": "goto left test",
134 "Sequence": "biguous first" + CTRL_A + "am" + ENTER,
136 {"Name": "goto right test",
137 "Sequence": "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER,
141 {"Name": "goto left word test",
142 "Sequence": "ambiguous st" + ALT_B + "fir" + ENTER,
144 {"Name": "goto right word test",
145 "Sequence": "ambig first" + CTRL_A + ALT_F + "uous" + ENTER,
148 # test removing words
149 {"Name": "remove left word 1",
150 "Sequence": "single invalid" + CTRL_W + ENTER,
152 {"Name": "remove left word 2",
153 "Sequence": "single invalid" + ALT_BKSPACE + ENTER,
155 {"Name": "remove right word",
156 "Sequence": "single invalid" + ALT_B + ALT_D + ENTER,
159 # test kill buffer (copy and paste)
160 {"Name": "killbuffer test 1",
161 "Sequence": "ambiguous" + CTRL_A + CTRL_K + " first" + CTRL_A +
164 {"Name": "killbuffer test 2",
165 "Sequence": "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER,
166 "Result": NOT_FOUND},
169 {"Name": "newline test",
170 "Sequence": "invalid" + CTRL_C + "single" + ENTER,
173 # test redisplay (nothing should really happen)
174 {"Name": "redisplay test",
175 "Sequence": "single" + CTRL_L + ENTER,
179 {"Name": "autocomplete test 1",
180 "Sequence": "si" + TAB + ENTER,
182 {"Name": "autocomplete test 2",
183 "Sequence": "si" + TAB + "_" + TAB + ENTER,
184 "Result": SINGLE_LONG},
185 {"Name": "autocomplete test 3",
186 "Sequence": "in" + TAB + ENTER,
187 "Result": NOT_FOUND},
188 {"Name": "autocomplete test 4",
189 "Sequence": "am" + TAB + ENTER,
191 {"Name": "autocomplete test 5",
192 "Sequence": "am" + TAB + "fir" + TAB + ENTER,
194 {"Name": "autocomplete test 6",
195 "Sequence": "am" + TAB + "fir" + TAB + TAB + ENTER,
197 {"Name": "autocomplete test 7",
198 "Sequence": "am" + TAB + "fir" + TAB + " " + TAB + ENTER,
200 {"Name": "autocomplete test 8",
201 "Sequence": "am" + TAB + " am" + TAB + " " + ENTER,
203 {"Name": "autocomplete test 9",
204 "Sequence": "am" + TAB + "inv" + TAB + ENTER,
206 {"Name": "autocomplete test 10",
207 "Sequence": "au" + TAB + ENTER,
208 "Result": NOT_FOUND},
209 {"Name": "autocomplete test 11",
210 "Sequence": "au" + TAB + "1" + ENTER,
212 {"Name": "autocomplete test 12",
213 "Sequence": "au" + TAB + "2" + ENTER,
215 {"Name": "autocomplete test 13",
216 "Sequence": "au" + TAB + "2" + TAB + ENTER,
218 {"Name": "autocomplete test 14",
219 "Sequence": "au" + TAB + "2 " + TAB + ENTER,
221 {"Name": "autocomplete test 15",
222 "Sequence": "24" + TAB + ENTER,
226 {"Name": "history test 1",
227 "Sequence": "invalid" + ENTER + "single" + ENTER + "invalid" +
228 ENTER + UP + CTRL_P + ENTER,
230 {"Name": "history test 2",
231 "Sequence": "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" +
232 ENTER + "single" + ENTER + UP * 3 + CTRL_N + DOWN + ENTER,
236 # tests that improve coverage
240 {"Name": "empty space test 1",
241 "Sequence": RIGHT + LEFT + CTRL_B + CTRL_F + ENTER,
243 {"Name": "empty space test 2",
244 "Sequence": BKSPACE + ENTER,
246 {"Name": "empty space test 3",
247 "Sequence": CTRL_E*2 + CTRL_A*2 + ENTER,
249 {"Name": "empty space test 4",
250 "Sequence": ALT_F*2 + ALT_B*2 + ENTER,
252 {"Name": "empty space test 5",
253 "Sequence": " " + CTRL_E*2 + CTRL_A*2 + ENTER,
255 {"Name": "empty space test 6",
256 "Sequence": " " + CTRL_A + ALT_F*2 + ALT_B*2 + ENTER,
258 {"Name": "empty space test 7",
259 "Sequence": " " + CTRL_A + CTRL_D + CTRL_E + CTRL_D + ENTER,
261 {"Name": "empty space test 8",
262 "Sequence": " space" + CTRL_W*2 + ENTER,
264 {"Name": "empty space test 9",
265 "Sequence": " space" + ALT_BKSPACE*2 + ENTER,
267 {"Name": "empty space test 10",
268 "Sequence": " space " + CTRL_A + ALT_D*3 + ENTER,
271 # non-printable char tests
272 {"Name": "non-printable test 1",
273 "Sequence": chr(27) + chr(47) + ENTER,
275 {"Name": "non-printable test 2",
276 "Sequence": chr(27) + chr(128) + ENTER*7,
278 {"Name": "non-printable test 3",
279 "Sequence": chr(27) + chr(91) + chr(127) + ENTER*6,
282 # miscellaneous tests
283 {"Name": "misc test 1",
286 {"Name": "misc test 2",
287 "Sequence": "single #comment" + ENTER,
289 {"Name": "misc test 3",
290 "Sequence": "#empty line" + ENTER,
292 {"Name": "misc test 4",
293 "Sequence": " single " + ENTER,
295 {"Name": "misc test 5",
296 "Sequence": "single#" + ENTER,
298 {"Name": "misc test 6",
299 "Sequence": 'a' * 257 + ENTER,
300 "Result": NOT_FOUND},
301 {"Name": "misc test 7",
302 "Sequence": "clear_history" + UP*5 + DOWN*5 + ENTER,
304 {"Name": "misc test 8",
305 "Sequence": "a" + HELP + CTRL_C,
307 {"Name": "misc test 9",
308 "Sequence": CTRL_D*3,