2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2010-2014 Intel Corporation
5 # Script that runs cmdline_test app and feeds keystrokes into it.
6 from __future__ import print_function
7 import cmdline_test_data
14 # function to run test
16 def runTest(child, test):
17 child.send(test["Sequence"])
18 if test["Result"] is None:
20 child.expect(test["Result"], 1)
22 if sys.version_info.major < 3:
23 print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
24 print("Please use Python 3 instead", file=sys.stderr)
27 # history test is a special case
29 # This test does the following:
30 # 1) fills the history with garbage up to its full capacity
31 # (just enough to remove last entry)
32 # 2) scrolls back history to the very beginning
33 # 3) checks if the output is as expected, that is, the first
34 # number in the sequence (not the last entry before it)
36 # This is a self-contained test, it needs only a pexpect child
38 def runHistoryTest(child):
39 # find out history size
40 child.sendline(cmdline_test_data.CMD_GET_BUFSIZE)
41 child.expect("History buffer size: \\d+", timeout=1)
42 history_size = int(child.after[len(cmdline_test_data.BUFSIZE_TEMPLATE):])
45 # fill the history with numbers
46 while i < history_size / 10:
47 # add 1 to prevent from parsing as octals
48 child.send("1" + str(i).zfill(8) + cmdline_test_data.ENTER)
49 # the app will simply print out the number
50 child.expect(str(i + 100000000), timeout=1)
53 child.send(cmdline_test_data.UP * (i + 2) + cmdline_test_data.ENTER)
54 child.expect("100000000", timeout=1)
56 # the path to cmdline_test executable is supplied via command-line.
58 print("Error: please supply cmdline_test app path")
61 test_app_path = sys.argv[1]
63 if not os.path.exists(test_app_path):
64 print("Error: please supply cmdline_test app path")
67 child = pexpect.spawn(test_app_path)
69 print("Running command-line tests...")
70 for test in cmdline_test_data.tests:
71 testname = (test["Name"] + ":").ljust(30)
74 print(testname, "PASS")
76 print(testname, "FAIL")
80 # since last test quits the app, run new instance
81 child = pexpect.spawn(test_app_path)
83 testname = ("History fill test:").ljust(30)
86 print(testname, "PASS")
88 print(testname, "FAIL")