update Intel copyright years to 2014
[dpdk.git] / app / cmdline_test / cmdline_test_data.py
1 #!/usr/bin/python
2
3 #   BSD LICENSE
4
5 #   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
6 #   All rights reserved.
7
8 #   Redistribution and use in source and binary forms, with or without
9 #   modification, are permitted provided that the following conditions
10 #   are met:
11
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
17 #       distribution.
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.
21
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.
33
34 # collection of static data
35
36 import sys
37
38 # keycode constants
39 CTRL_A = chr(1)
40 CTRL_B = chr(2)
41 CTRL_C = chr(3)
42 CTRL_D = chr(4)
43 CTRL_E = chr(5)
44 CTRL_F = chr(6)
45 CTRL_K = chr(11)
46 CTRL_L = chr(12)
47 CTRL_N = chr(14)
48 CTRL_P = chr(16)
49 CTRL_W = chr(23)
50 CTRL_Y = chr(25)
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)
56 TAB = chr(9)
57 HELP = chr(63)
58 BKSPACE = chr(127)
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)
63 ENTER2 = '\r'
64 ENTER = '\n'
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!"
76
77 # misc defines
78 CMD_QUIT = "quit"
79 CMD_GET_BUFSIZE = "get_history_bufsize"
80 BUFSIZE_TEMPLATE = "History buffer size: "
81 PROMPT = "CMDLINE_TEST>>"
82
83 # test defines
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
87 # designed that way.
88 #
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).
93 #
94 # each test consists of name, character sequence to send to child,
95 # and expected output (if any).
96
97 tests = [
98 # test basic commands
99         {"Name" : "command test 1",
100          "Sequence" : "ambiguous first" + ENTER,
101          "Result" : CMD1},
102         {"Name" : "command test 2",
103          "Sequence" : "ambiguous second" + ENTER,
104          "Result" : CMD2},
105         {"Name" : "command test 3",
106          "Sequence" : "ambiguous ambiguous" + ENTER,
107          "Result" : AMBIG},
108         {"Name" : "command test 4",
109          "Sequence" : "ambiguous ambiguous2" + ENTER,
110          "Result" : AMBIG},
111
112         {"Name" : "invalid command test 1",
113          "Sequence" : "ambiguous invalid" + ENTER,
114          "Result" : BAD_ARG},
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},
122
123 # test arrows and deletes
124         {"Name" : "arrows & delete test 1",
125          "Sequence" : "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER,
126          "Result" : SINGLE},
127         {"Name" : "arrows & delete test 2",
128          "Sequence" : "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER,
129          "Result" : SINGLE},
130
131 # test backspace
132         {"Name" : "backspace test",
133          "Sequence" : "singlebad" + BKSPACE*3 + ENTER,
134          "Result" : SINGLE},
135
136 # test goto left and goto right
137         {"Name" : "goto left test",
138          "Sequence" : "biguous first" + CTRL_A + "am" + ENTER,
139          "Result" : CMD1},
140         {"Name" : "goto right test",
141          "Sequence" : "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER,
142          "Result" : CMD1},
143
144 # test goto words
145         {"Name" : "goto left word test",
146          "Sequence" : "ambiguous st" + ALT_B + "fir" + ENTER,
147          "Result" : CMD1},
148         {"Name" : "goto right word test",
149          "Sequence" : "ambig first" + CTRL_A + ALT_F + "uous" + ENTER,
150          "Result" : CMD1},
151
152 # test removing words
153         {"Name" : "remove left word 1",
154          "Sequence" : "single invalid" + CTRL_W + ENTER,
155          "Result" : SINGLE},
156         {"Name" : "remove left word 2",
157          "Sequence" : "single invalid" + ALT_BKSPACE + ENTER,
158          "Result" : SINGLE},
159         {"Name" : "remove right word",
160          "Sequence" : "single invalid" + ALT_B + ALT_D + ENTER,
161          "Result" : SINGLE},
162
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,
166          "Result" : CMD1},
167         {"Name" : "killbuffer test 2",
168          "Sequence" : "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER,
169          "Result" : NOT_FOUND},
170
171 # test newline
172         {"Name" : "newline test",
173          "Sequence" : "invalid" + CTRL_C + "single" + ENTER,
174          "Result" : SINGLE},
175
176 # test redisplay (nothing should really happen)
177         {"Name" : "redisplay test",
178          "Sequence" : "single" + CTRL_L + ENTER,
179          "Result" : SINGLE},
180
181 # test autocomplete
182         {"Name" : "autocomplete test 1",
183          "Sequence" : "si" + TAB + ENTER,
184          "Result" : SINGLE},
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,
193          "Result" : BAD_ARG},
194         {"Name" : "autocomplete test 5",
195          "Sequence" : "am" + TAB + "fir" + TAB + ENTER,
196          "Result" : CMD1},
197         {"Name" : "autocomplete test 6",
198          "Sequence" : "am" + TAB + "fir" + TAB + TAB + ENTER,
199          "Result" : CMD1},
200         {"Name" : "autocomplete test 7",
201          "Sequence" : "am" + TAB + "fir" + TAB + " " + TAB + ENTER,
202          "Result" : CMD1},
203         {"Name" : "autocomplete test 8",
204          "Sequence" : "am" + TAB + "     am" + TAB + "   " + ENTER,
205          "Result" : AMBIG},
206         {"Name" : "autocomplete test 9",
207          "Sequence" : "am" + TAB + "inv" + TAB + ENTER,
208          "Result" : BAD_ARG},
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,
214          "Result" : AUTO1},
215         {"Name" : "autocomplete test 12",
216          "Sequence" : "au" + TAB + "2" + ENTER,
217          "Result" : AUTO2},
218         {"Name" : "autocomplete test 13",
219          "Sequence" : "au" + TAB + "2" + TAB + ENTER,
220          "Result" : AUTO2},
221         {"Name" : "autocomplete test 14",
222          "Sequence" : "au" + TAB + "2   " + TAB + ENTER,
223          "Result" : AUTO2},
224         {"Name" : "autocomplete test 15",
225          "Sequence" : "24" + TAB + ENTER,
226          "Result" : "24"},
227
228 # test history
229         {"Name" : "history test 1",
230          "Sequence" : "invalid" + ENTER + "single" + ENTER + "invalid" + ENTER + UP + CTRL_P + ENTER,
231          "Result" : SINGLE},
232         {"Name" : "history test 2",
233          "Sequence" : "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" + ENTER + "single" + ENTER + UP * 3 + CTRL_N + DOWN + ENTER,
234          "Result" : SINGLE},
235
236 #
237 # tests that improve coverage
238 #
239
240 # empty space tests
241         {"Name" : "empty space test 1",
242          "Sequence" : RIGHT + LEFT + CTRL_B + CTRL_F + ENTER,
243          "Result" : PROMPT},
244         {"Name" : "empty space test 2",
245          "Sequence" : BKSPACE + ENTER,
246          "Result" : PROMPT},
247         {"Name" : "empty space test 3",
248          "Sequence" : CTRL_E*2 + CTRL_A*2 + ENTER,
249          "Result" : PROMPT},
250         {"Name" : "empty space test 4",
251          "Sequence" : ALT_F*2 + ALT_B*2 + ENTER,
252          "Result" : PROMPT},
253         {"Name" : "empty space test 5",
254          "Sequence" : " " + CTRL_E*2 + CTRL_A*2 + ENTER,
255          "Result" : PROMPT},
256         {"Name" : "empty space test 6",
257          "Sequence" : " " + CTRL_A + ALT_F*2 + ALT_B*2 + ENTER,
258          "Result" : PROMPT},
259         {"Name" : "empty space test 7",
260          "Sequence" : "  " + CTRL_A + CTRL_D + CTRL_E + CTRL_D + ENTER,
261          "Result" : PROMPT},
262         {"Name" : "empty space test 8",
263          "Sequence" : " space" + CTRL_W*2 + ENTER,
264          "Result" : PROMPT},
265         {"Name" : "empty space test 9",
266          "Sequence" : " space" + ALT_BKSPACE*2 + ENTER,
267          "Result" : PROMPT},
268         {"Name" : "empty space test 10",
269          "Sequence" : " space " + CTRL_A + ALT_D*3 + ENTER,
270          "Result" : PROMPT},
271
272 # non-printable char tests
273         {"Name" : "non-printable test 1",
274          "Sequence" : chr(27) + chr(47) + ENTER,
275          "Result" : PROMPT},
276         {"Name" : "non-printable test 2",
277          "Sequence" : chr(27) + chr(128) + ENTER*7,
278          "Result" : PROMPT},
279         {"Name" : "non-printable test 3",
280          "Sequence" : chr(27) + chr(91) + chr(127) + ENTER*6,
281          "Result" : PROMPT},
282
283 # miscellaneous tests
284         {"Name" : "misc test 1",
285          "Sequence" : ENTER,
286          "Result" : PROMPT},
287         {"Name" : "misc test 2",
288          "Sequence" : "single #comment" + ENTER,
289          "Result" : SINGLE},
290         {"Name" : "misc test 3",
291          "Sequence" : "#empty line" + ENTER,
292          "Result" : PROMPT},
293         {"Name" : "misc test 4",
294          "Sequence" : "   single  " + ENTER,
295          "Result" : SINGLE},
296         {"Name" : "misc test 5",
297          "Sequence" : "single#" + ENTER,
298          "Result" : SINGLE},
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,
304          "Result" : PROMPT},
305         {"Name" : "misc test 8",
306          "Sequence" : "a" + HELP + CTRL_C,
307          "Result" : PROMPT},
308         {"Name" : "misc test 9",
309          "Sequence" : CTRL_D*3,
310          "Result" : None},
311 ]
312