X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Fcmdline_test%2Fcmdline_test.py;h=229f71f3e39e0c6a517c33bf08c79244a126f933;hb=6f619653b9b15ac2514fe8d935018dd0b07c75f0;hp=b78295b1f56a6f6de3829c9d0b8f3b036917e9b8;hpb=b6df9fc8715f9a925136006b18fdd65f9c621757;p=dpdk.git diff --git a/app/cmdline_test/cmdline_test.py b/app/cmdline_test/cmdline_test.py index b78295b1f5..229f71f3e3 100755 --- a/app/cmdline_test/cmdline_test.py +++ b/app/cmdline_test/cmdline_test.py @@ -1,49 +1,53 @@ -#!/usr/bin/python +#!/usr/bin/env python # BSD LICENSE -# -# Copyright(c) 2010-2013 Intel Corporation. All rights reserved. +# +# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. # All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions # are met: -# -# * Redistributions of source code must retain the above copyright +# +# * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the # distribution. -# * Neither the name of Intel Corporation nor the names of its -# contributors may be used to endorse or promote products derived +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived # from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# # 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 -import sys, pexpect, string, os, cmdline_test_data # # function to run test # -def runTest(child,test): - child.send(test["Sequence"]) - if test["Result"] == None: - return 0 - child.expect(test["Result"],1) +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 @@ -58,58 +62,57 @@ def runTest(child,test): # 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 + # 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) + # 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) + 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) + print("Error: please supply cmdline_test app path") + sys.exit(1) child = pexpect.spawn(test_app_path) -print "Running command-line tests..." +print("Running command-line tests...") for test in cmdline_test_data.tests: - print (test["Name"] + ":").ljust(30), - try: - runTest(child,test) - print "PASS" - except: - print "FAIL" - print child - sys.exit(1) + 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) -print ("History fill test:").ljust(30), +testname = ("History fill test:").ljust(30) try: - runHistoryTest(child) - print "PASS" + runHistoryTest(child) + print(testname, "PASS") except: - print "FAIL" - print child - sys.exit(1) + print(testname, "FAIL") + print(child) + sys.exit(1) child.close() sys.exit(0) -