summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/test/cmdline_test/cmdline_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/spdk/dpdk/test/cmdline_test/cmdline_test.py
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/spdk/dpdk/test/cmdline_test/cmdline_test.py')
-rwxr-xr-xsrc/spdk/dpdk/test/cmdline_test/cmdline_test.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/spdk/dpdk/test/cmdline_test/cmdline_test.py b/src/spdk/dpdk/test/cmdline_test/cmdline_test.py
new file mode 100755
index 00000000..3a8fac42
--- /dev/null
+++ b/src/spdk/dpdk/test/cmdline_test/cmdline_test.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2010-2014 Intel Corporation
+
+# Script that runs cmdline_test app and feeds keystrokes into it.
+from __future__ import print_function
+import cmdline_test_data
+import os
+import pexpect
+import sys
+
+
+#
+# function to run test
+#
+def runTest(child, test):
+ child.send(test["Sequence"])
+ if test["Result"] is None:
+ return 0
+ child.expect(test["Result"], 1)
+
+
+#
+# history test is a special case
+#
+# This test does the following:
+# 1) fills the history with garbage up to its full capacity
+# (just enough to remove last entry)
+# 2) scrolls back history to the very beginning
+# 3) checks if the output is as expected, that is, the first
+# number in the sequence (not the last entry before it)
+#
+# This is a self-contained test, it needs only a pexpect child
+#
+def runHistoryTest(child):
+ # find out history size
+ child.sendline(cmdline_test_data.CMD_GET_BUFSIZE)
+ child.expect("History buffer size: \\d+", timeout=1)
+ history_size = int(child.after[len(cmdline_test_data.BUFSIZE_TEMPLATE):])
+ i = 0
+
+ # fill the history with numbers
+ while i < history_size / 10:
+ # add 1 to prevent from parsing as octals
+ child.send("1" + str(i).zfill(8) + cmdline_test_data.ENTER)
+ # the app will simply print out the number
+ child.expect(str(i + 100000000), timeout=1)
+ i += 1
+ # scroll back history
+ child.send(cmdline_test_data.UP * (i + 2) + cmdline_test_data.ENTER)
+ child.expect("100000000", timeout=1)
+
+# the path to cmdline_test executable is supplied via command-line.
+if len(sys.argv) < 2:
+ print("Error: please supply cmdline_test app path")
+ sys.exit(1)
+
+test_app_path = sys.argv[1]
+
+if not os.path.exists(test_app_path):
+ print("Error: please supply cmdline_test app path")
+ sys.exit(1)
+
+child = pexpect.spawn(test_app_path)
+
+print("Running command-line tests...")
+for test in cmdline_test_data.tests:
+ testname = (test["Name"] + ":").ljust(30)
+ try:
+ runTest(child, test)
+ print(testname, "PASS")
+ except:
+ print(testname, "FAIL")
+ print(child)
+ sys.exit(1)
+
+# since last test quits the app, run new instance
+child = pexpect.spawn(test_app_path)
+
+testname = ("History fill test:").ljust(30)
+try:
+ runHistoryTest(child)
+ print(testname, "PASS")
+except:
+ print(testname, "FAIL")
+ print(child)
+ sys.exit(1)
+child.close()
+sys.exit(0)