5 # Copyright(c) 2010-2012 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.
35 # collection of static data
52 ALT_B = chr(27) + chr(98)
53 ALT_D = chr(27) + chr(100)
54 ALT_F = chr(27) + chr(102)
55 ALT_BKSPACE = chr(27) + chr(127)
56 DEL = chr(27) + chr(91) + chr(51) + chr(126)
60 RIGHT = chr(27) + chr(91) + chr(67)
61 DOWN = chr(27) + chr(91) + chr(66)
62 LEFT = chr(27) + chr(91) + chr(68)
63 UP = chr(27) + chr(91) + chr(65)
67 # expected result constants
68 NOT_FOUND = "Command not found"
69 BAD_ARG = "Bad arguments"
70 AMBIG = "Ambiguous command"
71 CMD1 = "Command 1 parsed!"
72 CMD2 = "Command 2 parsed!"
73 SINGLE = "Single word command parsed!"
74 SINGLE_LONG = "Single long word command parsed!"
75 AUTO1 = "Autocomplete command 1 parsed!"
76 AUTO2 = "Autocomplete command 2 parsed!"
80 CMD_GET_BUFSIZE = "get_history_bufsize"
81 BUFSIZE_TEMPLATE = "History buffer size: "
82 PROMPT = "CMDLINE_TEST>>"
85 # each test tests progressively diverse set of keys. this way for example
86 # if we want to use some key sequence in the test, we first need to test
87 # that it itself does what it is expected to do. Most of the tests are
90 # example: "arrows & delete test 1". we enter a partially valid command,
91 # then move 3 chars left and use delete three times. this way we get to
92 # know that "delete", "left" and "ctrl+B" all work (because if any of
93 # them fails, the whole test will fail and next tests won't be run).
95 # each test consists of name, character sequence to send to child,
96 # and expected output (if any).
100 {"Name" : "command test 1",
101 "Sequence" : "ambiguous first" + ENTER,
103 {"Name" : "command test 2",
104 "Sequence" : "ambiguous second" + ENTER,
106 {"Name" : "command test 3",
107 "Sequence" : "ambiguous ambiguous" + ENTER,
109 {"Name" : "command test 4",
110 "Sequence" : "ambiguous ambiguous2" + ENTER,
113 {"Name" : "invalid command test 1",
114 "Sequence" : "ambiguous invalid" + ENTER,
116 # test invalid commands
117 {"Name" : "invalid command test 2",
118 "Sequence" : "invalid" + ENTER,
119 "Result" : NOT_FOUND},
120 {"Name" : "invalid command test 3",
121 "Sequence" : "ambiguousinvalid" + ENTER2,
122 "Result" : NOT_FOUND},
124 # test arrows and deletes
125 {"Name" : "arrows & delete test 1",
126 "Sequence" : "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER,
128 {"Name" : "arrows & delete test 2",
129 "Sequence" : "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER,
133 {"Name" : "backspace test",
134 "Sequence" : "singlebad" + BKSPACE*3 + ENTER,
137 # test goto left and goto right
138 {"Name" : "goto left test",
139 "Sequence" : "biguous first" + CTRL_A + "am" + ENTER,
141 {"Name" : "goto right test",
142 "Sequence" : "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER,
146 {"Name" : "goto left word test",
147 "Sequence" : "ambiguous st" + ALT_B + "fir" + ENTER,
149 {"Name" : "goto right word test",
150 "Sequence" : "ambig first" + CTRL_A + ALT_F + "uous" + ENTER,
153 # test removing words
154 {"Name" : "remove left word 1",
155 "Sequence" : "single invalid" + CTRL_W + ENTER,
157 {"Name" : "remove left word 2",
158 "Sequence" : "single invalid" + ALT_BKSPACE + ENTER,
160 {"Name" : "remove right word",
161 "Sequence" : "single invalid" + ALT_B + ALT_D + ENTER,
164 # test kill buffer (copy and paste)
165 {"Name" : "killbuffer test 1",
166 "Sequence" : "ambiguous" + CTRL_A + CTRL_K + " first" + CTRL_A + CTRL_Y + ENTER,
168 {"Name" : "killbuffer test 2",
169 "Sequence" : "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER,
170 "Result" : NOT_FOUND},
173 {"Name" : "newline test",
174 "Sequence" : "invalid" + CTRL_C + "single" + ENTER,
177 # test redisplay (nothing should really happen)
178 {"Name" : "redisplay test",
179 "Sequence" : "single" + CTRL_L + ENTER,
183 {"Name" : "autocomplete test 1",
184 "Sequence" : "si" + TAB + ENTER,
186 {"Name" : "autocomplete test 2",
187 "Sequence" : "si" + TAB + "_" + TAB + ENTER,
188 "Result" : SINGLE_LONG},
189 {"Name" : "autocomplete test 3",
190 "Sequence" : "in" + TAB + ENTER,
191 "Result" : NOT_FOUND},
192 {"Name" : "autocomplete test 4",
193 "Sequence" : "am" + TAB + ENTER,
195 {"Name" : "autocomplete test 5",
196 "Sequence" : "am" + TAB + "fir" + TAB + ENTER,
198 {"Name" : "autocomplete test 6",
199 "Sequence" : "am" + TAB + "fir" + TAB + TAB + ENTER,
201 {"Name" : "autocomplete test 7",
202 "Sequence" : "am" + TAB + "fir" + TAB + " " + TAB + ENTER,
204 {"Name" : "autocomplete test 8",
205 "Sequence" : "am" + TAB + " am" + TAB + " " + ENTER,
207 {"Name" : "autocomplete test 9",
208 "Sequence" : "am" + TAB + "inv" + TAB + ENTER,
210 {"Name" : "autocomplete test 10",
211 "Sequence" : "au" + TAB + ENTER,
212 "Result" : NOT_FOUND},
213 {"Name" : "autocomplete test 11",
214 "Sequence" : "au" + TAB + "1" + ENTER,
216 {"Name" : "autocomplete test 12",
217 "Sequence" : "au" + TAB + "2" + ENTER,
219 {"Name" : "autocomplete test 13",
220 "Sequence" : "au" + TAB + "2" + TAB + ENTER,
222 {"Name" : "autocomplete test 14",
223 "Sequence" : "au" + TAB + "2 " + TAB + ENTER,
225 {"Name" : "autocomplete test 15",
226 "Sequence" : "24" + TAB + ENTER,
230 {"Name" : "history test 1",
231 "Sequence" : "invalid" + ENTER + "single" + ENTER + "invalid" + ENTER + UP + CTRL_P + ENTER,
233 {"Name" : "history test 2",
234 "Sequence" : "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" + 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,