1#!/usr/bin/env python 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. 6from __future__ import print_function 7import cmdline_test_data 8import os 9import pexpect 10import sys 11 12 13# 14# function to run test 15# 16def runTest(child, test): 17 child.send(test["Sequence"]) 18 if test["Result"] is None: 19 return 0 20 child.expect(test["Result"], 1) 21 22if 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) 25 26# 27# history test is a special case 28# 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) 35# 36# This is a self-contained test, it needs only a pexpect child 37# 38def 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):]) 43 i = 0 44 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) 51 i += 1 52 # scroll back history 53 child.send(cmdline_test_data.UP * (i + 2) + cmdline_test_data.ENTER) 54 child.expect("100000000", timeout=1) 55 56# the path to cmdline_test executable is supplied via command-line. 57if len(sys.argv) < 2: 58 print("Error: please supply cmdline_test app path") 59 sys.exit(1) 60 61test_app_path = sys.argv[1] 62 63if not os.path.exists(test_app_path): 64 print("Error: please supply cmdline_test app path") 65 sys.exit(1) 66 67child = pexpect.spawn(test_app_path) 68 69print("Running command-line tests...") 70for test in cmdline_test_data.tests: 71 testname = (test["Name"] + ":").ljust(30) 72 try: 73 runTest(child, test) 74 print(testname, "PASS") 75 except: 76 print(testname, "FAIL") 77 print(child) 78 sys.exit(1) 79 80# since last test quits the app, run new instance 81child = pexpect.spawn(test_app_path) 82 83testname = ("History fill test:").ljust(30) 84try: 85 runHistoryTest(child) 86 print(testname, "PASS") 87except: 88 print(testname, "FAIL") 89 print(child) 90 sys.exit(1) 91child.close() 92sys.exit(0) 93