diff options
author | Viliam Luc <vluc@cisco.com> | 2021-08-02 14:25:26 +0200 |
---|---|---|
committer | Viliam Luc <vluc@cisco.com> | 2021-09-10 10:26:24 +0200 |
commit | ec467277744783015a2da6713298b35d13d92e6f (patch) | |
tree | 57b1bb084f5ae9c6346be5a92f8fe5fac38f1cd4 /resources/libraries/python/autogen | |
parent | 9cceefae3248e9a1e9e5586391c9263cf114a753 (diff) |
back-to-back tests: add TG tests
Change-Id: I9d028294deb1e31b6d185deb1c7523e0226a0ada
Signed-off-by: Viliam Luc <vluc@cisco.com>
Diffstat (limited to 'resources/libraries/python/autogen')
-rw-r--r-- | resources/libraries/python/autogen/Regenerator.py | 82 | ||||
-rw-r--r-- | resources/libraries/python/autogen/Testcase.py | 27 |
2 files changed, 106 insertions, 3 deletions
diff --git a/resources/libraries/python/autogen/Regenerator.py b/resources/libraries/python/autogen/Regenerator.py index 7003d3905d..14a9fd0ddb 100644 --- a/resources/libraries/python/autogen/Regenerator.py +++ b/resources/libraries/python/autogen/Regenerator.py @@ -195,6 +195,20 @@ def add_iperf3_testcases(testcase, file_out, tc_kwargs_list): file_out.write(testcase.generate(**kwargs)) +def add_trex_testcases(testcase, file_out, tc_kwargs_list): + """Add trex testcases to file. + + :param testcase: Testcase class. + :param file_out: File to write testcases to. + :param tc_kwargs_list: Key-value pairs used to construct testcases. + :type testcase: Testcase + :type file_out: file + :type tc_kwargs_list: dict + """ + for kwargs in tc_kwargs_list: + file_out.write(testcase.generate(**kwargs)) + + def write_default_files(in_filename, in_prolog, kwargs_list): """Using given filename and prolog, write all generated suites. @@ -480,6 +494,64 @@ def write_iperf3_files(in_filename, in_prolog, kwargs_list): add_iperf3_testcases(testcase, file_out, kwargs_list) +def write_trex_files(in_filename, in_prolog, kwargs_list): + """Using given filename and prolog, write all generated trex suites. + + :param in_filename: Template filename to derive real filenames from. + :param in_prolog: Template content to derive real content from. + :param kwargs_list: List of kwargs for add_trex_testcase. + :type in_filename: str + :type in_prolog: str + :type kwargs_list: list of dict + """ + for suite_type in Constants.PERF_TYPE_TO_KEYWORD: + tmp_filename = replace_defensively( + in_filename, u"ndrpdr", suite_type, 1, + u"File name should contain suite type once.", in_filename + ) + tmp_prolog = replace_defensively( + in_prolog, u"ndrpdr".upper(), suite_type.upper(), 1, + u"Suite type should appear once in uppercase (as tag).", + in_filename + ) + tmp_prolog = replace_defensively( + tmp_prolog, + u"Find NDR and PDR intervals using optimized search", + Constants.PERF_TYPE_TO_KEYWORD[suite_type], 1, + u"Main search keyword should appear once in suite.", + in_filename + ) + tmp_prolog = replace_defensively( + tmp_prolog, + Constants.PERF_TYPE_TO_SUITE_DOC_VER[u"ndrpdr"], + Constants.PERF_TYPE_TO_SUITE_DOC_VER[suite_type], + 1, u"Exact suite type doc not found.", in_filename + ) + tmp_prolog = replace_defensively( + tmp_prolog, + Constants.PERF_TYPE_TO_TEMPLATE_DOC_VER[u"ndrpdr"], + Constants.PERF_TYPE_TO_TEMPLATE_DOC_VER[suite_type], + 1, u"Exact template type doc not found.", in_filename + ) + _, suite_id, suite_tag = get_iface_and_suite_ids(tmp_filename) + testcase = Testcase.trex(suite_id) + for nic_name in Constants.NIC_NAME_TO_CODE: + out_filename = replace_defensively( + tmp_filename, u"10ge2p1x710", + Constants.NIC_NAME_TO_CODE[nic_name], 1, + u"File name should contain NIC code once.", in_filename + ) + out_prolog = replace_defensively( + tmp_prolog, u"Intel-X710", nic_name, 2, + u"NIC name should appear twice (tag and variable).", + in_filename + ) + check_suite_tag(suite_tag, out_prolog) + with open(out_filename, u"wt") as file_out: + file_out.write(out_prolog) + add_trex_testcases(testcase, file_out, kwargs_list) + + def write_device_files(in_filename, in_prolog, kwargs_list): """Using given filename and prolog, write all generated suites. @@ -637,6 +709,13 @@ class Regenerator: {u"frame_size": min_frame_size, u"phy_cores": 0} ] + trex_kwargs_list = [ + {u"frame_size": min_frame_size}, + {u"frame_size": 1518}, + {u"frame_size": 9000}, + {u"frame_size": u"IMIX_v4_1"} + ] + for in_filename in glob(pattern): if not self.quiet: print( @@ -656,6 +735,9 @@ class Regenerator: in_prolog = u"".join( file_in.read().partition(u"*** Test Cases ***")[:-1] ) + if "-tg-" in in_filename: + write_trex_files(in_filename, in_prolog, trex_kwargs_list) + continue if in_filename.endswith(u"-ndrpdr.robot"): if u"scheduler" in in_filename: write_default_files( diff --git a/resources/libraries/python/autogen/Testcase.py b/resources/libraries/python/autogen/Testcase.py index 643d32a3cb..32fc5014cc 100644 --- a/resources/libraries/python/autogen/Testcase.py +++ b/resources/libraries/python/autogen/Testcase.py @@ -33,16 +33,17 @@ class Testcase: """ self.template = Template(template_string) - def generate(self, frame_size, phy_cores): + def generate(self, frame_size, phy_cores=None): """Return string of test case code with placeholders filled. Fail if there are placeholders left unfilled. It is not required for all placeholders to be present in template. :param frame_size: Imix string or numeric frame size. Example: 74. - :param phy_cores: Number of physical cores to use. Example: 2. + :param phy_cores: Number of physical cores to use. Example: 2. It can + be None in n2n testcases. :type frame_size: str or int - :type phy_cores: int or str + :type phy_cores: int, str or None :returns: Filled template, usable as test case code. :rtype: str """ @@ -57,6 +58,8 @@ class Testcase: u"frame_num": str(frame_size), u"frame_str": u"IMIX" } + if phy_cores is None: + return self.template.substitute(subst_dict) cores_str = str(phy_cores) cores_num = int(cores_str) subst_dict.update( @@ -136,3 +139,21 @@ class Testcase: | | frame_size=${{frame_num}} | phy_cores=${{cores_num}} ''' return cls(template_string) + + @classmethod + def trex(cls, suite_id): + """Factory method for creating "trex" testcase objects. + + Testcase name will contain frame size, but not core count. + + :param suite_id: Part of suite name to distinguish from other suites. + :type suite_id: str + :returns: Instance for generating testcase text of this type. + :rtype: Testcase + """ + template_string = f''' +| ${{frame_str}}--{suite_id} +| | [Tags] | ${{frame_str}} +| | frame_size=${{frame_num}} +''' + return cls(template_string) |