test/crypto: fix autotest function parameters
[dpdk.git] / app / test-cmdline / cmdline_test.py
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2010-2014 Intel Corporation
4
5 # Script that runs cmdline_test app and feeds keystrokes into it.
6 import cmdline_test_data
7 import os
8 import pexpect
9 import sys
10
11
12 #
13 # function to run test
14 #
15 def runTest(child, test):
16     child.send(test["Sequence"])
17     if test["Result"] is None:
18         return 0
19     child.expect(test["Result"], 1)
20
21 #
22 # history test is a special case
23 #
24 # This test does the following:
25 # 1) fills the history with garbage up to its full capacity
26 #    (just enough to remove last entry)
27 # 2) scrolls back history to the very beginning
28 # 3) checks if the output is as expected, that is, the first
29 #    number in the sequence (not the last entry before it)
30 #
31 # This is a self-contained test, it needs only a pexpect child
32 #
33 def runHistoryTest(child):
34     # find out history size
35     child.sendline(cmdline_test_data.CMD_GET_BUFSIZE)
36     child.expect("History buffer size: \\d+", timeout=1)
37     history_size = int(child.after[len(cmdline_test_data.BUFSIZE_TEMPLATE):])
38     i = 0
39
40     # fill the history with numbers
41     while i < history_size // 10:
42         # add 1 to prevent from parsing as octals
43         child.send("1" + str(i).zfill(8) + cmdline_test_data.ENTER)
44         # the app will simply print out the number
45         child.expect(str(i + 100000000), timeout=1)
46         i += 1
47     # scroll back history
48     child.send(cmdline_test_data.UP * (i + 2) + cmdline_test_data.ENTER)
49     child.expect("100000000", timeout=1)
50
51 # the path to cmdline_test executable is supplied via command-line.
52 if len(sys.argv) < 2:
53     print("Error: please supply cmdline_test app path")
54     sys.exit(1)
55
56 test_app_path = sys.argv[1]
57
58 if not os.path.exists(test_app_path):
59     print("Error: please supply cmdline_test app path")
60     sys.exit(1)
61
62 child = pexpect.spawn(test_app_path)
63
64 print("Running command-line tests...")
65 for test in cmdline_test_data.tests:
66     testname = (test["Name"] + ":").ljust(30)
67     try:
68         runTest(child, test)
69         print(testname, "PASS")
70     except:
71         print(testname, "FAIL")
72         print(child)
73         sys.exit(1)
74
75 # since last test quits the app, run new instance
76 child = pexpect.spawn(test_app_path)
77
78 testname = ("History fill test:").ljust(30)
79 try:
80     runHistoryTest(child)
81     print(testname, "PASS")
82 except:
83     print(testname, "FAIL")
84     print(child)
85     sys.exit(1)
86 child.close()
87 sys.exit(0)