X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Fautogen%2FRegenerator.py;h=8bfe054e5ef28cd4429288c78d7d6c6babaaf342;hb=67c955313333b3e478d31e04bdaabcdfddbe2cbe;hp=85e8b60dd5d7ee989b9e3973da66498d6c1a50f5;hpb=7dda8f57f750c253d3c96ac1b02a84c58e36a6d8;p=csit.git diff --git a/resources/libraries/python/autogen/Regenerator.py b/resources/libraries/python/autogen/Regenerator.py index 85e8b60dd5..8bfe054e5e 100644 --- a/resources/libraries/python/autogen/Regenerator.py +++ b/resources/libraries/python/autogen/Regenerator.py @@ -16,7 +16,6 @@ from glob import glob from os import getcwd -from .Testcase import Testcase from .DefaultTestcase import DefaultTestcase @@ -36,7 +35,7 @@ class Regenerator(object): """ self.testcase_class = testcase_class - def regenerate_glob(self, pattern, is_ip6=False, tc_kwargs_list=None): + def regenerate_glob(self, pattern, protocol="ip4", tc_kwargs_list=None): """Regenerate files matching glob pattern based on arguments. In the current working directory, find all files matching @@ -56,18 +55,83 @@ class Regenerator(object): :type tc_kwargs_list: list of tuple or None """ - def add_testcase(file_out, num, **kwargs): - file_out.write(testcase.generate(num=num, **kwargs)) + protocol_to_min_framesize = { + "ip4": 64, + "ip6": 78, + "vxlan+ip4": 114 # What is the real minimum for latency stream? + } + + def get_iface_and_suite_id(filename): + """Get interface and suite ID. + + :param filename: Suite file. + :type filename: str + :returns: Interface ID, Suite ID. + :rtype: tuple + """ + dash_split = filename.split("-", 1) + if len(dash_split[0]) <= 4: + # It was something like "2n1l", we need one more split. + dash_split = dash_split[1].split("-", 1) + return dash_split[0], dash_split[1].split(".", 1)[0] + + def add_testcase(testcase, iface, suite_id, file_out, num, **kwargs): + """Add testcase to file. + + :param testcase: Testcase class. + :param iface: Interface. + :param suite_id: Suite ID. + :param file_out: File to write testcases to. + :param num: Testcase number. + :param kwargs: Key-value pairs used to construct testcase. + :type testcase: Testcase + :type iface: str + :type suite_id: str + :type file_out: file + :type num: int + :type kwargs: dict + :returns: Next testcase number. + :rtype: int + """ + # TODO: Is there a better way to disable some combinations? + if kwargs["framesize"] == 9000 and "vic1227" in iface: + # Not supported in HW. + pass + elif kwargs["framesize"] == 9000 and "avf" in suite_id: + # Not supported by AVF driver. + # https://git.fd.io/vpp/tree/src/plugins/avf/README.md + pass + elif ("soak" in suite_id and + (kwargs["phy_cores"] != 1 + or kwargs["framesize"] in (1518, 9000, "IMIX_v4_1"))): + # Soak test take too long, do not risk other than tc01. + pass + else: + file_out.write(testcase.generate(num=num, **kwargs)) return num + 1 - def add_testcases(file_out, tc_kwargs_list): + def add_testcases(testcase, iface, suite_id, file_out, tc_kwargs_list): + """Add testcases to file. + + :param testcase: Testcase class. + :param iface: Interface. + :param suite_id: Suite ID. + :param file_out: File to write testcases to. + :param tc_kwargs_list: Key-value pairs used to construct testcases. + :type testcase: Testcase + :type iface: str + :type suite_id: str + :type file_out: file + :type tc_kwargs_list: dict + """ num = 1 for tc_kwargs in tc_kwargs_list: - num = add_testcase(file_out, num, **tc_kwargs) + num = add_testcase(testcase, iface, suite_id, file_out, num, + **tc_kwargs) print "Regenerator starts at {cwd}".format(cwd=getcwd()) - min_framesize = 78 if is_ip6 else 64 - kwargs_list = tc_kwargs_list if tc_kwargs_list is not None else [ + min_framesize = protocol_to_min_framesize[protocol] + kwargs_list = tc_kwargs_list if tc_kwargs_list else [ {"framesize": min_framesize, "phy_cores": 1}, {"framesize": min_framesize, "phy_cores": 2}, {"framesize": min_framesize, "phy_cores": 4}, @@ -82,15 +146,14 @@ class Regenerator(object): {"framesize": "IMIX_v4_1", "phy_cores": 4} ] for filename in glob(pattern): + print "Regenerating filename:", filename with open(filename, "r") as file_in: text = file_in.read() text_prolog = "".join(text.partition("*** Test Cases ***")[:-1]) - # TODO: Make the following work for 2n suites. - suite_id = filename.split("-", 1)[1].split(".", 1)[0] - print "Regenerating suite_id:", suite_id + iface, suite_id = get_iface_and_suite_id(filename) testcase = self.testcase_class(suite_id) with open(filename, "w") as file_out: file_out.write(text_prolog) - add_testcases(file_out, kwargs_list) + add_testcases(testcase, iface, suite_id, file_out, kwargs_list) print "Regenerator ends." print # To make autogen check output more readable.