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
51 ALT_B = chr(27) + chr(98)
52 ALT_D = chr(27) + chr(100)
53 ALT_F = chr(27) + chr(102)
54 ALT_BKSPACE = chr(27) + chr(127)
55 DEL = chr(27) + chr(91) + chr(51) + chr(126)
59 RIGHT = chr(27) + chr(91) + chr(67)
60 DOWN = chr(27) + chr(91) + chr(66)
61 LEFT = chr(27) + chr(91) + chr(68)
62 UP = chr(27) + chr(91) + chr(65)
66 # expected result constants
67 NOT_FOUND = "Command not found"
68 BAD_ARG = "Bad arguments"
69 AMBIG = "Ambiguous command"
70 CMD1 = "Command 1 parsed!"
71 CMD2 = "Command 2 parsed!"
72 SINGLE = "Single word command parsed!"
73 SINGLE_LONG = "Single long word command parsed!"
74 AUTO1 = "Autocomplete command 1 parsed!"
75 AUTO2 = "Autocomplete command 2 parsed!"
79 CMD_GET_BUFSIZE = "get_history_bufsize"
80 BUFSIZE_TEMPLATE = "History buffer size: "
81 PROMPT = "CMDLINE_TEST>>"
84 # each test tests progressively diverse set of keys. this way for example
85 # if we want to use some key sequence in the test, we first need to test
86 # that it itself does what it is expected to do. Most of the tests are
89 # example: "arrows & delete test 1". we enter a partially valid command,
90 # then move 3 chars left and use delete three times. this way we get to
91 # know that "delete", "left" and "ctrl+B" all work (because if any of
92 # them fails, the whole test will fail and next tests won't be run).
94 # each test consists of name, character sequence to send to child,
95 # and expected output (if any).
99 {"Name" : "command test 1",
100 "Sequence" : "ambiguous first" + ENTER,
102 {"Name" : "command test 2",
103 "Sequence" : "ambiguous second" + ENTER,
105 {"Name" : "command test 3",
106 "Sequence" : "ambiguous ambiguous" + ENTER,
108 {"Name" : "command test 4",
109 "Sequence" : "ambiguous ambiguous2" + ENTER,
112 {"Name" : "invalid command test 1",
113 "Sequence" : "ambiguous invalid" + ENTER,
115 # test invalid commands
116 {"Name" : "invalid command test 2",
117 "Sequence" : "invalid" + ENTER,
118 "Result" : NOT_FOUND},
119 {"Name" : "invalid command test 3",
120 "Sequence" : "ambiguousinvalid" + ENTER2,
121 "Result" : NOT_FOUND},
123 # test arrows and deletes
124 {"Name" : "arrows & delete test 1",
125 "Sequence" : "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER,
127 {"Name" : "arrows & delete test 2",
128 "Sequence" : "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER,
132 {"Name" : "backspace test",
133 "Sequence" : "singlebad" + BKSPACE*3 + ENTER,
136 # test goto left and goto right
137 {"Name" : "goto left test",
138 "Sequence" : "biguous first" + CTRL_A + "am" + ENTER,
140 {"Name" : "goto right test",
141 "Sequence" : "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER,
145 {"Name" : "goto left word test",
146 "Sequence" : "ambiguous st" + ALT_B + "fir" + ENTER,
148 {"Name" : "goto right word test",
149 "Sequence" : "ambig first" + CTRL_A + ALT_F + "uous" + ENTER,
152 # test removing words
153 {"Name" : "remove left word 1",
154 "Sequence" : "single invalid" + CTRL_W + ENTER,
156 {"Name" : "remove left word 2",
157 "Sequence" : "single invalid" + ALT_BKSPACE + ENTER,
159 {"Name" : "remove right word",
160 "Sequence" : "single invalid" + ALT_B + ALT_D + ENTER,
163 # test kill buffer (copy and paste)
164 {"Name" : "killbuffer test 1",
165 "Sequence" : "ambiguous" + CTRL_A + CTRL_K + " first" + CTRL_A + CTRL_Y + ENTER,
167 {"Name" : "killbuffer test 2",
168 "Sequence" : "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER,
169 "Result" : NOT_FOUND},
172 {"Name" : "newline test",
173 "Sequence" : "invalid" + CTRL_C + "single" + ENTER,
176 # test redisplay (nothing should really happen)
177 {"Name" : "redisplay test",
178 "Sequence" : "single" + CTRL_L + ENTER,
182 {"Name" : "autocomplete test 1",
183 "Sequence" : "si" + TAB + ENTER,
185 {"Name" : "autocomplete test 2",
186 "Sequence" : "si" + TAB + "_" + TAB + ENTER,
187 "Result" : SINGLE_LONG},
188 {"Name" : "autocomplete test 3",
189 "Sequence" : "in" + TAB + ENTER,
190 "Result" : NOT_FOUND},
191 {"Name" : "autocomplete test 4",
192 "Sequence" : "am" + TAB + ENTER,
194 {"Name" : "autocomplete test 5",
195 "Sequence" : "am" + TAB + "fir" + TAB + ENTER,
197 {"Name" : "autocomplete test 6",
198 "Sequence" : "am" + TAB + "fir" + TAB + TAB + ENTER,
200 {"Name" : "autocomplete test 7",
201 "Sequence" : "am" + TAB + "fir" + TAB + " " + TAB + ENTER,
203 {"Name" : "autocomplete test 8",
204 "Sequence" : "am" + TAB + " am" + TAB + " " + ENTER,
206 {"Name" : "autocomplete test 9",
207 "Sequence" : "am" + TAB + "inv" + TAB + ENTER,
209 {"Name" : "autocomplete test 10",
210 "Sequence" : "au" + TAB + ENTER,
211 "Result" : NOT_FOUND},
212 {"Name" : "autocomplete test 11",
213 "Sequence" : "au" + TAB + "1" + ENTER,
215 {"Name" : "autocomplete test 12",
216 "Sequence" : "au" + TAB + "2" + ENTER,
218 {"Name" : "autocomplete test 13",
219 "Sequence" : "au" + TAB + "2" + TAB + ENTER,
221 {"Name" : "autocomplete test 14",
222 "Sequence" : "au" + TAB + "2 " + TAB + ENTER,
224 {"Name" : "autocomplete test 15",
225 "Sequence" : "24" + TAB + ENTER,
229 {"Name" : "history test 1",
230 "Sequence" : "invalid" + ENTER + "single" + ENTER + "invalid" + ENTER + UP + CTRL_P + ENTER,
232 {"Name" : "history test 2",
233 "Sequence" : "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" + ENTER + "single" + ENTER + UP * 3 + CTRL_N + DOWN + ENTER,
237 # tests that improve coverage
241 {"Name" : "empty space test 1",
242 "Sequence" : RIGHT + LEFT + CTRL_B + CTRL_F + ENTER,
244 {"Name" : "empty space test 2",
245 "Sequence" : BKSPACE + ENTER,
247 {"Name" : "empty space test 3",
248 "Sequence" : CTRL_E*2 + CTRL_A*2 + ENTER,
250 {"Name" : "empty space test 4",
251 "Sequence" : ALT_F*2 + ALT_B*2 + ENTER,
253 {"Name" : "empty space test 5",
254 "Sequence" : " " + CTRL_E*2 + CTRL_A*2 + ENTER,
256 {"Name" : "empty space test 6",
257 "Sequence" : " " + CTRL_A + ALT_F*2 + ALT_B*2 + ENTER,
259 {"Name" : "empty space test 7",
260 "Sequence" : " " + CTRL_A + CTRL_D + CTRL_E + CTRL_D + ENTER,
262 {"Name" : "empty space test 8",
263 "Sequence" : " space" + CTRL_W*2 + ENTER,
265 {"Name" : "empty space test 9",
266 "Sequence" : " space" + ALT_BKSPACE*2 + ENTER,
268 {"Name" : "empty space test 10",
269 "Sequence" : " space " + CTRL_A + ALT_D*3 + ENTER,
272 # non-printable char tests
273 {"Name" : "non-printable test 1",
274 "Sequence" : chr(27) + chr(47) + ENTER,
276 {"Name" : "non-printable test 2",
277 "Sequence" : chr(27) + chr(128) + ENTER*7,
279 {"Name" : "non-printable test 3",
280 "Sequence" : chr(27) + chr(91) + chr(127) + ENTER*6,
283 # miscellaneous tests
284 {"Name" : "misc test 1",
287 {"Name" : "misc test 2",
288 "Sequence" : "single #comment" + ENTER,
290 {"Name" : "misc test 3",
291 "Sequence" : "#empty line" + ENTER,
293 {"Name" : "misc test 4",
294 "Sequence" : " single " + ENTER,
296 {"Name" : "misc test 5",
297 "Sequence" : "single#" + ENTER,
299 {"Name" : "misc test 6",
300 "Sequence" : 'a' * 257 + ENTER,
301 "Result" : NOT_FOUND},
302 {"Name" : "misc test 7",
303 "Sequence" : "clear_history" + UP*5 + DOWN*5 + ENTER,
305 {"Name" : "misc test 8",
306 "Sequence" : "a" + HELP + CTRL_C,
308 {"Name" : "misc test 9",
309 "Sequence" : CTRL_D*3,