X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Fframework.py;h=7633ca04d0bd3ecbafd6c7f99ac1d2bd30ac1493;hb=a45dc07c153c4dd350b02fd30de471bbdb838ac9;hp=242a0798212ec72400113828e093ab2f9c43b4f3;hpb=6919b0de476e50307520a1f2389ffe7988f2c5a6;p=vpp.git diff --git a/test/framework.py b/test/framework.py index 242a0798212..7633ca04d0b 100644 --- a/test/framework.py +++ b/test/framework.py @@ -40,6 +40,12 @@ if os.name == 'posix' and sys.version_info[0] < 3: else: import subprocess +# Python2/3 compatible +try: + input = raw_input +except NameError: + pass + PASS = 0 FAIL = 1 ERROR = 2 @@ -132,23 +138,31 @@ def pump_output(testclass): # flag will take care of properly terminating the loop -def is_skip_aarch64_set(): +def _is_skip_aarch64_set(): return os.getenv('SKIP_AARCH64', 'n').lower() in ('yes', 'y', '1') +is_skip_aarch64_set = _is_skip_aarch64_set() + -def is_platform_aarch64(): +def _is_platform_aarch64(): return platform.machine() == 'aarch64' +is_platform_aarch64 = _is_platform_aarch64() -def running_extended_tests(): + +def _running_extended_tests(): s = os.getenv("EXTENDED_TESTS", "n") return True if s.lower() in ("y", "yes", "1") else False +running_extended_tests = _running_extended_tests() + -def running_on_centos(): +def _running_on_centos(): os_id = os.getenv("OS_ID", "") return True if "centos" in os_id.lower() else False +running_on_centos = _running_on_centos + class KeepAliveReporter(object): """ @@ -192,6 +206,7 @@ class VppTestCase(unittest.TestCase): """ extra_vpp_punt_config = [] + extra_vpp_plugin_config = [] @property def packet_infos(self): @@ -307,7 +322,7 @@ class VppTestCase(unittest.TestCase): "{", "socket-name", cls.stats_sock, "}", "plugins", "{", "plugin", "dpdk_plugin.so", "{", "disable", "}", "plugin", "unittest_plugin.so", "{", "enable", - "}", "}", ] + "}"] + cls.extra_vpp_plugin_config + ["}", ] if cls.extra_vpp_punt_config is not None: cls.vpp_cmdline.extend(cls.extra_vpp_punt_config) if plugin_path is not None: @@ -338,7 +353,7 @@ class VppTestCase(unittest.TestCase): print("Now is the time to attach a gdb by running the above " "command and set up breakpoints etc.") print(single_line_delim) - raw_input("Press ENTER to continue running the testcase...") + input("Press ENTER to continue running the testcase...") @classmethod def run_vpp(cls): @@ -478,8 +493,8 @@ class VppTestCase(unittest.TestCase): print(double_line_delim) print("VPP or GDB server is still running") print(single_line_delim) - raw_input("When done debugging, press ENTER to kill the " - "process and finish running the testcase...") + input("When done debugging, press ENTER to kill the " + "process and finish running the testcase...") # first signal that we want to stop the pump thread, then wake it up if hasattr(cls, 'pump_thread_stop_flag'): @@ -916,15 +931,18 @@ class VppTestCase(unittest.TestCase): self.assert_checksum_valid(pkt, 'ICMPv6EchoReply', 'cksum') def assert_packet_counter_equal(self, counter, expected_value): - counters = self.vapi.cli("sh errors").split('\n') - counter_value = -1 - for i in range(1, len(counters) - 1): - results = counters[i].split() - if results[1] == counter: - counter_value = int(results[0]) - break - self.assert_equal(counter_value, expected_value, - "packet counter `%s'" % counter) + if counter.startswith("/"): + counter_value = self.statistics.get_counter(counter) + self.assert_equal(counter_value, expected_value, + "packet counter `%s'" % counter) + else: + counters = self.vapi.cli("sh errors").split('\n') + counter_value = -1 + for i in range(1, len(counters) - 1): + results = counters[i].split() + if results[1] == counter: + counter_value = int(results[0]) + break @classmethod def sleep(cls, timeout, remark=None): @@ -990,6 +1008,11 @@ class VppTestCase(unittest.TestCase): return rx + def runTest(self): + """ unittest calls runTest when TestCase is instantiated without a + test case. Use case: Writing unittests against VppTestCase""" + pass + def get_testcase_doc_name(test): return getdoc(test.__class__).splitlines()[0]