make test: code cleanup

Change-Id: Ic689de569e5b6e6209d16d6acdb13c489daca1f5
Signed-off-by: Klement Sekera <ksekera@cisco.com>
This commit is contained in:
Klement Sekera
2018-03-21 12:35:51 +01:00
committed by Damjan Marion
parent 3f2dd30b0b
commit 13a83ef4d4
3 changed files with 38 additions and 57 deletions

View File

@ -17,7 +17,7 @@ from inspect import getdoc, isclass
from traceback import format_exception from traceback import format_exception
from logging import FileHandler, DEBUG, Formatter from logging import FileHandler, DEBUG, Formatter
from scapy.packet import Raw from scapy.packet import Raw
from hook import StepHook, PollHook from hook import StepHook, PollHook, VppDiedError
from vpp_pg_interface import VppPGInterface from vpp_pg_interface import VppPGInterface
from vpp_sub_interface import VppSubInterface from vpp_sub_interface import VppSubInterface
from vpp_lo_interface import VppLoInterface from vpp_lo_interface import VppLoInterface
@ -120,21 +120,13 @@ def pump_output(testclass):
def running_extended_tests(): def running_extended_tests():
try: s = os.getenv("EXTENDED_TESTS", "n")
s = os.getenv("EXTENDED_TESTS")
return True if s.lower() in ("y", "yes", "1") else False return True if s.lower() in ("y", "yes", "1") else False
except:
return False
return False
def running_on_centos(): def running_on_centos():
try: os_id = os.getenv("OS_ID", "")
os_id = os.getenv("OS_ID")
return True if "centos" in os_id.lower() else False return True if "centos" in os_id.lower() else False
except:
return False
return False
class KeepAliveReporter(object): class KeepAliveReporter(object):
@ -217,21 +209,11 @@ class VppTestCase(unittest.TestCase):
@classmethod @classmethod
def setUpConstants(cls): def setUpConstants(cls):
""" Set-up the test case class based on environment variables """ """ Set-up the test case class based on environment variables """
try: s = os.getenv("STEP", "n")
s = os.getenv("STEP")
cls.step = True if s.lower() in ("y", "yes", "1") else False cls.step = True if s.lower() in ("y", "yes", "1") else False
except: d = os.getenv("DEBUG", None)
cls.step = False
try:
d = os.getenv("DEBUG")
except:
d = None
try:
c = os.getenv("CACHE_OUTPUT", "1") c = os.getenv("CACHE_OUTPUT", "1")
cls.cache_vpp_output = \ cls.cache_vpp_output = False if c.lower() in ("n", "no", "0") else True
False if c.lower() in ("n", "no", "0") else True
except:
cls.cache_vpp_output = True
cls.set_debug_flags(d) cls.set_debug_flags(d)
cls.vpp_bin = os.getenv('VPP_TEST_BIN', "vpp") cls.vpp_bin = os.getenv('VPP_TEST_BIN', "vpp")
cls.plugin_path = os.getenv('VPP_TEST_PLUGIN_PATH') cls.plugin_path = os.getenv('VPP_TEST_PLUGIN_PATH')
@ -249,12 +231,9 @@ class VppTestCase(unittest.TestCase):
if cls.step or cls.debug_gdb or cls.debug_gdbserver: if cls.step or cls.debug_gdb or cls.debug_gdbserver:
debug_cli = "cli-listen localhost:5002" debug_cli = "cli-listen localhost:5002"
coredump_size = None coredump_size = None
try:
size = os.getenv("COREDUMP_SIZE") size = os.getenv("COREDUMP_SIZE")
if size is not None: if size is not None:
coredump_size = "coredump-size %s" % size coredump_size = "coredump-size %s" % size
except:
pass
if coredump_size is None: if coredump_size is None:
coredump_size = "coredump-size unlimited" coredump_size = "coredump-size unlimited"
cls.vpp_cmdline = [cls.vpp_bin, "unix", cls.vpp_cmdline = [cls.vpp_bin, "unix",
@ -290,7 +269,7 @@ class VppTestCase(unittest.TestCase):
print("Now is the time to attach a gdb by running the above " print("Now is the time to attach a gdb by running the above "
"command and set up breakpoints etc.") "command and set up breakpoints etc.")
print(single_line_delim) print(single_line_delim)
raw_input("Press ENTER to continue running the testcase...") sys.stdin.readline("Press ENTER to continue running the testcase...")
@classmethod @classmethod
def run_vpp(cls): def run_vpp(cls):
@ -368,7 +347,7 @@ class VppTestCase(unittest.TestCase):
cls.sleep(0.1, "after vpp startup, before initial poll") cls.sleep(0.1, "after vpp startup, before initial poll")
try: try:
hook.poll_vpp() hook.poll_vpp()
except: except VppDiedError:
cls.vpp_startup_failed = True cls.vpp_startup_failed = True
cls.logger.critical( cls.logger.critical(
"VPP died shortly after startup, check the" "VPP died shortly after startup, check the"
@ -376,23 +355,22 @@ class VppTestCase(unittest.TestCase):
raise raise
try: try:
cls.vapi.connect() cls.vapi.connect()
except: except Exception:
try: try:
cls.vapi.disconnect() cls.vapi.disconnect()
except: except Exception:
pass pass
if cls.debug_gdbserver: if cls.debug_gdbserver:
print(colorize("You're running VPP inside gdbserver but " print(colorize("You're running VPP inside gdbserver but "
"VPP-API connection failed, did you forget " "VPP-API connection failed, did you forget "
"to 'continue' VPP from within gdb?", RED)) "to 'continue' VPP from within gdb?", RED))
raise raise
except: except Exception:
t, v, tb = sys.exc_info()
try: try:
cls.quit() cls.quit()
except: except Exception:
pass pass
raise (t, v, tb) raise
@classmethod @classmethod
def quit(cls): def quit(cls):
@ -405,8 +383,9 @@ class VppTestCase(unittest.TestCase):
print(double_line_delim) print(double_line_delim)
print("VPP or GDB server is still running") print("VPP or GDB server is still running")
print(single_line_delim) print(single_line_delim)
raw_input("When done debugging, press ENTER to kill the " sys.stdin.readline(
"process and finish running the testcase...") "When done debugging, press ENTER to kill the process and "
"finish running the testcase...")
os.write(cls.pump_thread_wakeup_pipe[1], 'ding dong wake up') os.write(cls.pump_thread_wakeup_pipe[1], 'ding dong wake up')
cls.pump_thread_stop_flag.set() cls.pump_thread_stop_flag.set()
@ -732,7 +711,7 @@ class VppTestCase(unittest.TestCase):
msg = msg % (getdoc(name_or_class).strip(), msg = msg % (getdoc(name_or_class).strip(),
real_value, str(name_or_class(real_value)), real_value, str(name_or_class(real_value)),
expected_value, str(name_or_class(expected_value))) expected_value, str(name_or_class(expected_value)))
except: except Exception:
msg = "Invalid %s: %s does not match expected value %s" % ( msg = "Invalid %s: %s does not match expected value %s" % (
name_or_class, real_value, expected_value) name_or_class, real_value, expected_value)
@ -1051,10 +1030,7 @@ class VppTestRunner(unittest.TextTestRunner):
test_option = "TEST" test_option = "TEST"
def parse_test_option(self): def parse_test_option(self):
try: f = os.getenv(self.test_option, None)
f = os.getenv(self.test_option)
except:
f = None
filter_file_name = None filter_file_name = None
filter_class_name = None filter_class_name = None
filter_func_name = None filter_func_name = None

View File

@ -1,5 +1,6 @@
import signal import signal
import os import os
import sys
import traceback import traceback
from log import RED, single_line_delim, double_line_delim from log import RED, single_line_delim, double_line_delim
from debug import spawn_gdb from debug import spawn_gdb
@ -167,14 +168,15 @@ class StepHook(PollHook):
print("Calls in/below that stack frame will be not be stepped anymore") print("Calls in/below that stack frame will be not be stepped anymore")
print(single_line_delim) print(single_line_delim)
while True: while True:
choice = raw_input("Enter your choice, if any, and press ENTER to " choice = sys.stdin.readline(
"continue running the testcase...") "Enter your choice, if any, and press ENTER to continue "
"running the testcase...")
if choice == "": if choice == "":
choice = None choice = None
try: try:
if choice is not None: if choice is not None:
num = int(choice) num = int(choice)
except: except TypeError:
print("Invalid input") print("Invalid input")
continue continue
if choice is not None and (num < 0 or num >= len(stack)): if choice is not None and (num < 0 or num >= len(stack)):

View File

@ -165,6 +165,9 @@ if __name__ == '__main__':
except: except:
debug = None debug = None
s = os.getenv("STEP", "n")
step = True if s.lower() in ("y", "yes", "1") else False
parser = argparse.ArgumentParser(description="VPP unit tests") parser = argparse.ArgumentParser(description="VPP unit tests")
parser.add_argument("-f", "--failfast", action='count', parser.add_argument("-f", "--failfast", action='count',
help="fast failure flag") help="fast failure flag")
@ -189,7 +192,11 @@ if __name__ == '__main__':
attempts = retries + 1 attempts = retries + 1
if attempts > 1: if attempts > 1:
print("Perform %s attempts to pass the suite..." % attempts) print("Perform %s attempts to pass the suite..." % attempts)
if debug is None or debug.lower() not in ["gdb", "gdbserver"]: if (debug is not None and debug.lower() in ["gdb", "gdbserver"]) or step:
# don't fork if requiring interactive terminal..
sys.exit(not VppTestRunner(
verbosity=verbose, failfast=failfast).run(suite).wasSuccessful())
else:
while True: while True:
result, failed = run_forked(suite) result, failed = run_forked(suite)
attempts = attempts - 1 attempts = attempts - 1
@ -199,7 +206,3 @@ if __name__ == '__main__':
suite = suite_from_failed(suite, failed) suite = suite_from_failed(suite, failed)
continue continue
sys.exit(result) sys.exit(result)
# don't fork if debugging..
sys.exit(not VppTestRunner(verbosity=verbose,
failfast=failfast).run(suite).wasSuccessful())