make python scripts PEP8 compliant
[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 # keycode constants
37 CTRL_A = chr(1)
38 CTRL_B = chr(2)
39 CTRL_C = chr(3)
40 CTRL_D = chr(4)
41 CTRL_E = chr(5)
42 CTRL_F = chr(6)
43 CTRL_K = chr(11)
44 CTRL_L = chr(12)
45 CTRL_N = chr(14)
46 CTRL_P = chr(16)
47 CTRL_W = chr(23)
48 CTRL_Y = chr(25)
49 ALT_B = chr(27) + chr(98)
50 ALT_D = chr(27) + chr(100)
51 ALT_F = chr(27) + chr(102)
52 ALT_BKSPACE = chr(27) + chr(127)
53 DEL = chr(27) + chr(91) + chr(51) + chr(126)
54 TAB = chr(9)
55 HELP = chr(63)
56 BKSPACE = chr(127)
57 RIGHT = chr(27) + chr(91) + chr(67)
58 DOWN = chr(27) + chr(91) + chr(66)
59 LEFT = chr(27) + chr(91) + chr(68)
60 UP = chr(27) + chr(91) + chr(65)
61 ENTER2 = '\r'
62 ENTER = '\n'
63
64 # expected result constants
65 NOT_FOUND = "Command not found"
66 BAD_ARG = "Bad arguments"
67 AMBIG = "Ambiguous command"
68 CMD1 = "Command 1 parsed!"
69 CMD2 = "Command 2 parsed!"
70 SINGLE = "Single word command parsed!"
71 SINGLE_LONG = "Single long word command parsed!"
72 AUTO1 = "Autocomplete command 1 parsed!"
73 AUTO2 = "Autocomplete command 2 parsed!"
74
75 # misc defines
76 CMD_QUIT = "quit"
77 CMD_GET_BUFSIZE = "get_history_bufsize"
78 BUFSIZE_TEMPLATE = "History buffer size: "
79 PROMPT = "CMDLINE_TEST>>"
80
81 # test defines
82 # each test tests progressively diverse set of keys. this way for example
83 # if we want to use some key sequence in the test, we first need to test
84 # that it itself does what it is expected to do. Most of the tests are
85 # designed that way.
86 #
87 # example: "arrows & delete test 1". we enter a partially valid command,
88 # then move 3 chars left and use delete three times. this way we get to
89 # know that "delete", "left" and "ctrl+B" all work (because if any of
90 # them fails, the whole test will fail and next tests won't be run).
91 #
92 # each test consists of name, character sequence to send to child,
93 # and expected output (if any).
94
95 tests = [
96     # test basic commands
97     {"Name": "command test 1",
98      "Sequence": "ambiguous first" + ENTER,
99      "Result": CMD1},
100     {"Name": "command test 2",
101      "Sequence": "ambiguous second" + ENTER,
102      "Result": CMD2},
103     {"Name": "command test 3",
104      "Sequence": "ambiguous ambiguous" + ENTER,
105      "Result": AMBIG},
106     {"Name": "command test 4",
107      "Sequence": "ambiguous ambiguous2" + ENTER,
108      "Result": AMBIG},
109
110     {"Name": "invalid command test 1",
111      "Sequence": "ambiguous invalid" + ENTER,
112      "Result": BAD_ARG},
113     # test invalid commands
114     {"Name": "invalid command test 2",
115      "Sequence": "invalid" + ENTER,
116      "Result": NOT_FOUND},
117     {"Name": "invalid command test 3",
118      "Sequence": "ambiguousinvalid" + ENTER2,
119      "Result": NOT_FOUND},
120
121     # test arrows and deletes
122     {"Name": "arrows & delete test 1",
123      "Sequence": "singlebad" + LEFT*2 + CTRL_B + DEL*3 + ENTER,
124      "Result": SINGLE},
125     {"Name": "arrows & delete test 2",
126      "Sequence": "singlebad" + LEFT*5 + RIGHT + CTRL_F + DEL*3 + ENTER,
127      "Result": SINGLE},
128
129     # test backspace
130     {"Name": "backspace test",
131      "Sequence": "singlebad" + BKSPACE*3 + ENTER,
132      "Result": SINGLE},
133
134     # test goto left and goto right
135     {"Name": "goto left test",
136      "Sequence": "biguous first" + CTRL_A + "am" + ENTER,
137      "Result": CMD1},
138     {"Name": "goto right test",
139      "Sequence": "biguous fir" + CTRL_A + "am" + CTRL_E + "st" + ENTER,
140      "Result": CMD1},
141
142     # test goto words
143     {"Name": "goto left word test",
144      "Sequence": "ambiguous st" + ALT_B + "fir" + ENTER,
145      "Result": CMD1},
146     {"Name": "goto right word test",
147      "Sequence": "ambig first" + CTRL_A + ALT_F + "uous" + ENTER,
148      "Result": CMD1},
149
150     # test removing words
151     {"Name": "remove left word 1",
152      "Sequence": "single invalid" + CTRL_W + ENTER,
153      "Result": SINGLE},
154     {"Name": "remove left word 2",
155      "Sequence": "single invalid" + ALT_BKSPACE + ENTER,
156      "Result": SINGLE},
157     {"Name": "remove right word",
158      "Sequence": "single invalid" + ALT_B + ALT_D + ENTER,
159      "Result": SINGLE},
160
161     # test kill buffer (copy and paste)
162     {"Name": "killbuffer test 1",
163      "Sequence": "ambiguous" + CTRL_A + CTRL_K + " first" + CTRL_A +
164                  CTRL_Y + ENTER,
165      "Result": CMD1},
166     {"Name": "killbuffer test 2",
167      "Sequence": "ambiguous" + CTRL_A + CTRL_K + CTRL_Y*26 + ENTER,
168      "Result": NOT_FOUND},
169
170     # test newline
171     {"Name": "newline test",
172      "Sequence": "invalid" + CTRL_C + "single" + ENTER,
173      "Result": SINGLE},
174
175     # test redisplay (nothing should really happen)
176     {"Name": "redisplay test",
177      "Sequence": "single" + CTRL_L + ENTER,
178      "Result": SINGLE},
179
180     # test autocomplete
181     {"Name": "autocomplete test 1",
182      "Sequence": "si" + TAB + ENTER,
183      "Result": SINGLE},
184     {"Name": "autocomplete test 2",
185      "Sequence": "si" + TAB + "_" + TAB + ENTER,
186      "Result": SINGLE_LONG},
187     {"Name": "autocomplete test 3",
188      "Sequence": "in" + TAB + ENTER,
189      "Result": NOT_FOUND},
190     {"Name": "autocomplete test 4",
191      "Sequence": "am" + TAB + ENTER,
192      "Result": BAD_ARG},
193     {"Name": "autocomplete test 5",
194      "Sequence": "am" + TAB + "fir" + TAB + ENTER,
195      "Result": CMD1},
196     {"Name": "autocomplete test 6",
197      "Sequence": "am" + TAB + "fir" + TAB + TAB + ENTER,
198      "Result": CMD1},
199     {"Name": "autocomplete test 7",
200      "Sequence": "am" + TAB + "fir" + TAB + " " + TAB + ENTER,
201      "Result": CMD1},
202     {"Name": "autocomplete test 8",
203      "Sequence": "am" + TAB + "     am" + TAB + "   " + ENTER,
204      "Result": AMBIG},
205     {"Name": "autocomplete test 9",
206      "Sequence": "am" + TAB + "inv" + TAB + ENTER,
207      "Result": BAD_ARG},
208     {"Name": "autocomplete test 10",
209      "Sequence": "au" + TAB + ENTER,
210      "Result": NOT_FOUND},
211     {"Name": "autocomplete test 11",
212      "Sequence": "au" + TAB + "1" + ENTER,
213      "Result": AUTO1},
214     {"Name": "autocomplete test 12",
215      "Sequence": "au" + TAB + "2" + ENTER,
216      "Result": AUTO2},
217     {"Name": "autocomplete test 13",
218      "Sequence": "au" + TAB + "2" + TAB + ENTER,
219      "Result": AUTO2},
220     {"Name": "autocomplete test 14",
221      "Sequence": "au" + TAB + "2   " + TAB + ENTER,
222      "Result": AUTO2},
223     {"Name": "autocomplete test 15",
224      "Sequence": "24" + TAB + ENTER,
225      "Result": "24"},
226
227     # test history
228     {"Name": "history test 1",
229      "Sequence": "invalid" + ENTER + "single" + ENTER + "invalid" +
230                  ENTER + UP + CTRL_P + ENTER,
231      "Result": SINGLE},
232     {"Name": "history test 2",
233      "Sequence": "invalid" + ENTER + "ambiguous first" + ENTER + "invalid" +
234                  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 ]