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