1 # Copyright (c) 2022 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Module defining utilities for test directory regeneration.
16 TODO: How can we check each suite id is unique,
17 when currently the suite generation is run on each directory separately?
27 from resources.libraries.python.Constants import Constants
28 from resources.libraries.python.autogen.Testcase import Testcase
31 PROTOCOL_TO_MIN_FRAME_SIZE = {
34 u"ethip4vxlan": 114, # What is the real minimum for latency stream?
37 MIN_FRAME_SIZE_VALUES = list(PROTOCOL_TO_MIN_FRAME_SIZE.values())
40 def replace_defensively(
41 whole, to_replace, replace_with, how_many, msg, in_filename):
42 """Replace substrings while checking the number of occurrences.
44 Return edited copy of the text. Assuming "whole" is really a string,
45 or something else with .replace not affecting it.
47 :param whole: The text to perform replacements on.
48 :param to_replace: Substring occurrences of which to replace.
49 :param replace_with: Substring to replace occurrences with.
50 :param how_many: Number of occurrences to expect.
51 :param msg: Error message to raise.
52 :param in_filename: File name in which the error occurred.
55 :type replace_with: str
58 :type in_filename: str
59 :returns: The whole text after replacements are done.
61 :raises ValueError: If number of occurrences does not match.
63 found = whole.count(to_replace)
65 raise ValueError(f"{in_filename}: {msg}")
66 return whole.replace(to_replace, replace_with)
69 def get_iface_and_suite_ids(filename):
70 """Get NIC code, suite ID and suite tag.
72 NIC code is the part of suite name
73 which should be replaced for other NIC.
74 Suite ID is the part os suite name
75 which is appended to test case names.
76 Suite tag is suite ID without both test type and NIC driver parts.
78 :param filename: Suite file.
80 :returns: NIC code, suite ID, suite tag.
81 :rtype: 3-tuple of str
83 dash_split = filename.split(u"-", 1)
84 if len(dash_split[0]) <= 4:
85 # It was something like "2n1l", we need one more split.
86 dash_split = dash_split[1].split(u"-", 1)
87 nic_code = dash_split[0]
88 suite_id = dash_split[1].split(u".robot", 1)[0]
89 suite_tag = suite_id.rsplit(u"-", 1)[0]
90 for prefix in Constants.FORBIDDEN_SUITE_PREFIX_LIST:
91 if suite_tag.startswith(prefix):
92 suite_tag = suite_tag[len(prefix):]
93 return nic_code, suite_id, suite_tag
96 def check_suite_tag(suite_tag, prolog):
97 """Verify suite tag occurres once in prolog.
99 Call this after all edits are done,
100 to confirm the (edited) suite tag still matches the (edited) suite name.
102 Currently, the edited suite tag is expect to be identical
103 to the primary suite tag, but having a function is more flexible.
105 The occurences are counted including "| " prefix,
106 to lower the chance to match a comment.
108 :param suite_tag: Part of suite name, between NIC driver and suite type.
109 :param prolog: The part of .robot file content without test cases.
112 :raises ValueError: If suite_tag not found exactly once.
114 found = prolog.count(u"| " + suite_tag)
116 raise ValueError(f"Suite tag found {found} times for {suite_tag}")
119 def add_default_testcases(testcase, iface, suite_id, file_out, tc_kwargs_list):
120 """Add default testcases to file.
122 :param testcase: Testcase class.
123 :param iface: Interface.
124 :param suite_id: Suite ID.
125 :param file_out: File to write testcases to.
126 :param tc_kwargs_list: Key-value pairs used to construct testcases.
127 :type testcase: Testcase
131 :type tc_kwargs_list: dict
133 for kwargs in tc_kwargs_list:
134 # TODO: Is there a better way to disable some combinations?
136 if kwargs[u"frame_size"] == 9000:
137 if u"vic1227" in iface:
138 # Not supported in HW.
140 if u"vic1385" in iface:
141 # Not supported in HW.
143 if u"-16vm2t-" in suite_id or u"-16dcr2t-" in suite_id:
144 if kwargs[u"phy_cores"] > 3:
145 # CSIT lab only has 28 (physical) core processors,
146 # so these test would fail when attempting to assign cores.
148 if u"-24vm1t-" in suite_id or u"-24dcr1t-" in suite_id:
149 if kwargs[u"phy_cores"] > 3:
150 # CSIT lab only has 28 (physical) core processors,
151 # so these test would fail when attempting to assign cores.
153 if u"soak" in suite_id:
154 # Soak test take too long, do not risk other than tc01.
155 if kwargs[u"phy_cores"] != 1:
157 if kwargs[u"frame_size"] not in MIN_FRAME_SIZE_VALUES:
161 or u"-pps-" in suite_id
162 or u"-tput-" in suite_id
164 if kwargs[u"frame_size"] not in MIN_FRAME_SIZE_VALUES:
167 file_out.write(testcase.generate(**kwargs))
170 def add_tcp_testcases(testcase, file_out, tc_kwargs_list):
171 """Add TCP testcases to file.
173 :param testcase: Testcase class.
174 :param file_out: File to write testcases to.
175 :param tc_kwargs_list: Key-value pairs used to construct testcases.
176 :type testcase: Testcase
178 :type tc_kwargs_list: dict
180 for kwargs in tc_kwargs_list:
181 file_out.write(testcase.generate(**kwargs))
184 def add_iperf3_testcases(testcase, file_out, tc_kwargs_list):
185 """Add iperf3 testcases to file.
187 :param testcase: Testcase class.
188 :param file_out: File to write testcases to.
189 :param tc_kwargs_list: Key-value pairs used to construct testcases.
190 :type testcase: Testcase
192 :type tc_kwargs_list: dict
194 for kwargs in tc_kwargs_list:
195 file_out.write(testcase.generate(**kwargs))
198 def add_trex_testcases(testcase, suite_id, file_out, tc_kwargs_list):
199 """Add trex testcases to file.
201 :param testcase: Testcase class.
202 :param suite_id: Suite ID.
203 :param file_out: File to write testcases to.
204 :param tc_kwargs_list: Key-value pairs used to construct testcases.
205 :type testcase: Testcase
208 :type tc_kwargs_list: dict
210 for kwargs in tc_kwargs_list:
211 # TODO: Is there a better way to disable some combinations?
215 or u"-pps-" in suite_id
216 or u"-tput-" in suite_id
218 if kwargs[u"frame_size"] not in MIN_FRAME_SIZE_VALUES:
221 file_out.write(testcase.generate(**kwargs))
224 def write_default_files(in_filename, in_prolog, kwargs_list):
225 """Using given filename and prolog, write all generated suites.
227 :param in_filename: Template filename to derive real filenames from.
228 :param in_prolog: Template content to derive real content from.
229 :param kwargs_list: List of kwargs for add_default_testcase.
230 :type in_filename: str
232 :type kwargs_list: list of dict
234 for suite_type in Constants.PERF_TYPE_TO_KEYWORD:
235 tmp_filename = replace_defensively(
236 in_filename, u"ndrpdr", suite_type, 1,
237 u"File name should contain suite type once.", in_filename
239 tmp_prolog = replace_defensively(
240 in_prolog, u"ndrpdr".upper(), suite_type.upper(), 1,
241 u"Suite type should appear once in uppercase (as tag).",
244 tmp_prolog = replace_defensively(
246 u"Find NDR and PDR intervals using optimized search",
247 Constants.PERF_TYPE_TO_KEYWORD[suite_type], 1,
248 u"Main search keyword should appear once in suite.",
251 tmp_prolog = replace_defensively(
253 Constants.PERF_TYPE_TO_SUITE_DOC_VER[u"ndrpdr"],
254 Constants.PERF_TYPE_TO_SUITE_DOC_VER[suite_type],
255 1, u"Exact suite type doc not found.", in_filename
257 tmp_prolog = replace_defensively(
259 Constants.PERF_TYPE_TO_TEMPLATE_DOC_VER[u"ndrpdr"],
260 Constants.PERF_TYPE_TO_TEMPLATE_DOC_VER[suite_type],
261 1, u"Exact template type doc not found.", in_filename
263 _, suite_id, _ = get_iface_and_suite_ids(tmp_filename)
264 testcase = Testcase.default(suite_id)
265 for nic_name in Constants.NIC_NAME_TO_CODE:
266 tmp2_filename = replace_defensively(
267 tmp_filename, u"10ge2p1x710",
268 Constants.NIC_NAME_TO_CODE[nic_name], 1,
269 u"File name should contain NIC code once.", in_filename
271 tmp2_prolog = replace_defensively(
272 tmp_prolog, u"Intel-X710", nic_name, 2,
273 u"NIC name should appear twice (tag and variable).",
276 if tmp2_prolog.count(u"HW_") == 2:
277 # TODO CSIT-1481: Crypto HW should be read
278 # from topology file instead.
279 if nic_name in Constants.NIC_NAME_TO_CRYPTO_HW:
280 tmp2_prolog = replace_defensively(
281 tmp2_prolog, u"HW_DH895xcc",
282 Constants.NIC_NAME_TO_CRYPTO_HW[nic_name], 1,
283 u"HW crypto name should appear.", in_filename
285 iface, old_suite_id, old_suite_tag = get_iface_and_suite_ids(
288 if u"DPDK" in in_prolog:
289 for driver in Constants.DPDK_NIC_NAME_TO_DRIVER[nic_name]:
290 out_filename = replace_defensively(
291 tmp2_filename, old_suite_id,
292 Constants.DPDK_NIC_DRIVER_TO_SUITE_PREFIX[driver] \
294 1, u"Error adding driver prefix.", in_filename
296 out_prolog = replace_defensively(
297 tmp2_prolog, u"vfio-pci", driver, 1,
298 u"Driver name should appear once.", in_filename
300 out_prolog = replace_defensively(
302 Constants.DPDK_NIC_DRIVER_TO_TAG[u"vfio-pci"],
303 Constants.DPDK_NIC_DRIVER_TO_TAG[driver], 1,
304 u"Driver tag should appear once.", in_filename
306 iface, suite_id, suite_tag = get_iface_and_suite_ids(
309 # The next replace is probably a noop, but it is safer to
310 # maintain the same structure as for other edits.
311 out_prolog = replace_defensively(
312 out_prolog, old_suite_tag, suite_tag, 1,
313 f"Perf suite tag {old_suite_tag} should appear once.",
316 check_suite_tag(suite_tag, out_prolog)
317 # TODO: Reorder loops so suite_id is finalized sooner.
318 testcase = Testcase.default(suite_id)
319 with open(out_filename, u"wt") as file_out:
320 file_out.write(out_prolog)
321 add_default_testcases(
322 testcase, iface, suite_id, file_out, kwargs_list
325 for driver in Constants.NIC_NAME_TO_DRIVER[nic_name]:
326 out_filename = replace_defensively(
327 tmp2_filename, old_suite_id,
328 Constants.NIC_DRIVER_TO_SUITE_PREFIX[driver] + old_suite_id,
329 1, u"Error adding driver prefix.", in_filename
331 out_prolog = replace_defensively(
332 tmp2_prolog, u"vfio-pci", driver, 1,
333 u"Driver name should appear once.", in_filename
335 out_prolog = replace_defensively(
336 out_prolog, Constants.NIC_DRIVER_TO_TAG[u"vfio-pci"],
337 Constants.NIC_DRIVER_TO_TAG[driver], 1,
338 u"Driver tag should appear once.", in_filename
340 out_prolog = replace_defensively(
341 out_prolog, Constants.NIC_DRIVER_TO_PLUGINS[u"vfio-pci"],
342 Constants.NIC_DRIVER_TO_PLUGINS[driver], 1,
343 u"Driver plugin should appear once.", in_filename
345 out_prolog = replace_defensively(
346 out_prolog, Constants.NIC_DRIVER_TO_VFS[u"vfio-pci"],
347 Constants.NIC_DRIVER_TO_VFS[driver], 1,
348 u"NIC VFs argument should appear once.", in_filename
350 iface, suite_id, suite_tag = get_iface_and_suite_ids(
353 # The next replace is probably a noop, but it is safer to
354 # maintain the same structure as for other edits.
355 out_prolog = replace_defensively(
356 out_prolog, old_suite_tag, suite_tag, 1,
357 f"Perf suite tag {old_suite_tag} should appear once.",
360 check_suite_tag(suite_tag, out_prolog)
361 # TODO: Reorder loops so suite_id is finalized sooner.
362 testcase = Testcase.default(suite_id)
363 with open(out_filename, u"wt") as file_out:
364 file_out.write(out_prolog)
365 add_default_testcases(
366 testcase, iface, suite_id, file_out, kwargs_list
370 def write_reconf_files(in_filename, in_prolog, kwargs_list):
371 """Using given filename and prolog, write all generated reconf suites.
373 Use this for suite type reconf, as its local template
374 is incompatible with mrr/ndrpdr/soak local template,
375 while test cases are compatible.
377 :param in_filename: Template filename to derive real filenames from.
378 :param in_prolog: Template content to derive real content from.
379 :param kwargs_list: List of kwargs for add_testcase.
380 :type in_filename: str
382 :type kwargs_list: list of dict
384 _, suite_id, _ = get_iface_and_suite_ids(in_filename)
385 testcase = Testcase.default(suite_id)
386 for nic_name in Constants.NIC_NAME_TO_CODE:
387 tmp_filename = replace_defensively(
388 in_filename, u"10ge2p1x710",
389 Constants.NIC_NAME_TO_CODE[nic_name], 1,
390 u"File name should contain NIC code once.", in_filename
392 tmp_prolog = replace_defensively(
393 in_prolog, u"Intel-X710", nic_name, 2,
394 u"NIC name should appear twice (tag and variable).",
397 if tmp_prolog.count(u"HW_") == 2:
398 # TODO CSIT-1481: Crypto HW should be read
399 # from topology file instead.
400 if nic_name in Constants.NIC_NAME_TO_CRYPTO_HW.keys():
401 tmp_prolog = replace_defensively(
402 tmp_prolog, u"HW_DH895xcc",
403 Constants.NIC_NAME_TO_CRYPTO_HW[nic_name], 1,
404 u"HW crypto name should appear.", in_filename
406 iface, old_suite_id, old_suite_tag = get_iface_and_suite_ids(
409 for driver in Constants.NIC_NAME_TO_DRIVER[nic_name]:
410 out_filename = replace_defensively(
411 tmp_filename, old_suite_id,
412 Constants.NIC_DRIVER_TO_SUITE_PREFIX[driver] + old_suite_id,
413 1, u"Error adding driver prefix.", in_filename
415 out_prolog = replace_defensively(
416 tmp_prolog, u"vfio-pci", driver, 1,
417 u"Driver name should appear once.", in_filename
419 out_prolog = replace_defensively(
420 out_prolog, Constants.NIC_DRIVER_TO_TAG[u"vfio-pci"],
421 Constants.NIC_DRIVER_TO_TAG[driver], 1,
422 u"Driver tag should appear once.", in_filename
424 out_prolog = replace_defensively(
425 out_prolog, Constants.NIC_DRIVER_TO_PLUGINS[u"vfio-pci"],
426 Constants.NIC_DRIVER_TO_PLUGINS[driver], 1,
427 u"Driver plugin should appear once.", in_filename
429 out_prolog = replace_defensively(
430 out_prolog, Constants.NIC_DRIVER_TO_VFS[u"vfio-pci"],
431 Constants.NIC_DRIVER_TO_VFS[driver], 1,
432 u"NIC VFs argument should appear once.", in_filename
434 iface, suite_id, suite_tag = get_iface_and_suite_ids(out_filename)
435 out_prolog = replace_defensively(
436 out_prolog, old_suite_tag, suite_tag, 1,
437 u"Perf suite tag should appear once.", in_filename
439 check_suite_tag(suite_tag, out_prolog)
440 # TODO: Reorder loops so suite_id is finalized sooner.
441 testcase = Testcase.default(suite_id)
442 with open(out_filename, u"wt") as file_out:
443 file_out.write(out_prolog)
444 add_default_testcases(
445 testcase, iface, suite_id, file_out, kwargs_list
449 def write_tcp_files(in_filename, in_prolog, kwargs_list):
450 """Using given filename and prolog, write all generated tcp suites.
452 :param in_filename: Template filename to derive real filenames from.
453 :param in_prolog: Template content to derive real content from.
454 :param kwargs_list: List of kwargs for add_default_testcase.
455 :type in_filename: str
457 :type kwargs_list: list of dict
459 # TODO: Generate rps from cps? There are subtle differences.
460 _, suite_id, suite_tag = get_iface_and_suite_ids(in_filename)
461 testcase = Testcase.tcp(suite_id)
462 for nic_name in Constants.NIC_NAME_TO_CODE:
463 tmp_filename = replace_defensively(
464 in_filename, u"10ge2p1x710",
465 Constants.NIC_NAME_TO_CODE[nic_name], 1,
466 u"File name should contain NIC code once.", in_filename
468 tmp_prolog = replace_defensively(
469 in_prolog, u"Intel-X710", nic_name, 2,
470 u"NIC name should appear twice (tag and variable).",
473 iface, old_suite_id, old_suite_tag = get_iface_and_suite_ids(
476 for driver in Constants.NIC_NAME_TO_DRIVER[nic_name]:
477 out_filename = replace_defensively(
478 tmp_filename, old_suite_id,
479 Constants.NIC_DRIVER_TO_SUITE_PREFIX[driver] + old_suite_id,
480 1, u"Error adding driver prefix.", in_filename
482 out_prolog = replace_defensively(
483 tmp_prolog, u"vfio-pci", driver, 1,
484 u"Driver name should appear once.", in_filename
486 out_prolog = replace_defensively(
487 out_prolog, Constants.NIC_DRIVER_TO_TAG[u"vfio-pci"],
488 Constants.NIC_DRIVER_TO_TAG[driver], 1,
489 u"Driver tag should appear once.", in_filename
491 out_prolog = replace_defensively(
492 out_prolog, Constants.NIC_DRIVER_TO_PLUGINS[u"vfio-pci"],
493 Constants.NIC_DRIVER_TO_PLUGINS[driver], 1,
494 u"Driver plugin should appear once.", in_filename
496 out_prolog = replace_defensively(
497 out_prolog, Constants.NIC_DRIVER_TO_VFS[u"vfio-pci"],
498 Constants.NIC_DRIVER_TO_VFS[driver], 1,
499 u"NIC VFs argument should appear once.", in_filename
501 iface, suite_id, suite_tag = get_iface_and_suite_ids(out_filename)
502 out_prolog = replace_defensively(
503 out_prolog, old_suite_tag, suite_tag, 1,
504 u"Perf suite tag should appear once.", in_filename
506 check_suite_tag(suite_tag, out_prolog)
507 testcase = Testcase.tcp(suite_id)
508 with open(out_filename, u"wt") as file_out:
509 file_out.write(out_prolog)
510 add_tcp_testcases(testcase, file_out, kwargs_list)
513 def write_iperf3_files(in_filename, in_prolog, kwargs_list):
514 """Using given filename and prolog, write all generated iperf3 suites.
516 :param in_filename: Template filename to derive real filenames from.
517 :param in_prolog: Template content to derive real content from.
518 :param kwargs_list: List of kwargs for add_default_testcase.
519 :type in_filename: str
521 :type kwargs_list: list of dict
523 _, suite_id, suite_tag = get_iface_and_suite_ids(in_filename)
524 testcase = Testcase.iperf3(suite_id)
525 for nic_name in Constants.NIC_NAME_TO_CODE:
526 out_filename = replace_defensively(
527 in_filename, u"10ge2p1x710",
528 Constants.NIC_NAME_TO_CODE[nic_name], 1,
529 u"File name should contain NIC code once.", in_filename
531 out_prolog = replace_defensively(
532 in_prolog, u"Intel-X710", nic_name, 2,
533 u"NIC name should appear twice (tag and variable).",
536 check_suite_tag(suite_tag, out_prolog)
537 with open(out_filename, u"wt") as file_out:
538 file_out.write(out_prolog)
539 add_iperf3_testcases(testcase, file_out, kwargs_list)
542 def write_trex_files(in_filename, in_prolog, kwargs_list):
543 """Using given filename and prolog, write all generated trex suites.
545 :param in_filename: Template filename to derive real filenames from.
546 :param in_prolog: Template content to derive real content from.
547 :param kwargs_list: List of kwargs for add_trex_testcase.
548 :type in_filename: str
550 :type kwargs_list: list of dict
552 for suite_type in Constants.PERF_TYPE_TO_KEYWORD:
553 tmp_filename = replace_defensively(
554 in_filename, u"ndrpdr", suite_type, 1,
555 u"File name should contain suite type once.", in_filename
557 tmp_prolog = replace_defensively(
558 in_prolog, u"ndrpdr".upper(), suite_type.upper(), 1,
559 u"Suite type should appear once in uppercase (as tag).",
562 tmp_prolog = replace_defensively(
564 u"Find NDR and PDR intervals using optimized search",
565 Constants.PERF_TYPE_TO_KEYWORD[suite_type], 1,
566 u"Main search keyword should appear once in suite.",
569 tmp_prolog = replace_defensively(
571 Constants.PERF_TYPE_TO_SUITE_DOC_VER[u"ndrpdr"],
572 Constants.PERF_TYPE_TO_SUITE_DOC_VER[suite_type],
573 1, u"Exact suite type doc not found.", in_filename
575 tmp_prolog = replace_defensively(
577 Constants.PERF_TYPE_TO_TEMPLATE_DOC_VER[u"ndrpdr"],
578 Constants.PERF_TYPE_TO_TEMPLATE_DOC_VER[suite_type],
579 1, u"Exact template type doc not found.", in_filename
581 _, suite_id, suite_tag = get_iface_and_suite_ids(tmp_filename)
582 testcase = Testcase.trex(suite_id)
583 for nic_name in Constants.NIC_NAME_TO_CODE:
584 out_filename = replace_defensively(
585 tmp_filename, u"10ge2p1x710",
586 Constants.NIC_NAME_TO_CODE[nic_name], 1,
587 u"File name should contain NIC code once.", in_filename
589 out_prolog = replace_defensively(
590 tmp_prolog, u"Intel-X710", nic_name, 2,
591 u"NIC name should appear twice (tag and variable).",
594 check_suite_tag(suite_tag, out_prolog)
595 with open(out_filename, u"wt") as file_out:
596 file_out.write(out_prolog)
597 add_trex_testcases(testcase, suite_id, file_out, kwargs_list)
600 def write_device_files(in_filename, in_prolog, kwargs_list):
601 """Using given filename and prolog, write all generated suites.
603 :param in_filename: Template filename to derive real filenames from.
604 :param in_prolog: Template content to derive real content from.
605 :param kwargs_list: List of kwargs for add_default_testcase.
606 :type in_filename: str
608 :type kwargs_list: list of dict
610 for suite_type in Constants.DEVICE_TYPE_TO_KEYWORD:
611 tmp_filename = replace_defensively(
612 in_filename, u"scapy", suite_type, 1,
613 u"File name should contain suite type once.", in_filename
615 _, suite_id, _ = get_iface_and_suite_ids(tmp_filename)
616 testcase = Testcase.default(suite_id)
617 for nic_name in Constants.NIC_NAME_TO_CODE:
618 tmp2_filename = replace_defensively(
619 tmp_filename, u"10ge2p1x710",
620 Constants.NIC_NAME_TO_CODE[nic_name], 1,
621 u"File name should contain NIC code once.", in_filename
623 tmp2_prolog = replace_defensively(
624 in_prolog, u"Intel-X710", nic_name, 2,
625 u"NIC name should appear twice (tag and variable).",
628 iface, old_suite_id, _ = get_iface_and_suite_ids(
631 for driver in Constants.NIC_NAME_TO_DRIVER[nic_name]:
632 out_filename = replace_defensively(
633 tmp2_filename, old_suite_id,
634 Constants.NIC_DRIVER_TO_SUITE_PREFIX[driver] + old_suite_id,
635 1, u"Error adding driver prefix.", in_filename
637 out_prolog = replace_defensively(
638 tmp2_prolog, u"vfio-pci", driver, 1,
639 u"Driver name should appear once.", in_filename
641 out_prolog = replace_defensively(
642 out_prolog, Constants.NIC_DRIVER_TO_TAG[u"vfio-pci"],
643 Constants.NIC_DRIVER_TO_TAG[driver], 1,
644 u"Driver tag should appear once.", in_filename
646 out_prolog = replace_defensively(
647 out_prolog, Constants.NIC_DRIVER_TO_PLUGINS[u"vfio-pci"],
648 Constants.NIC_DRIVER_TO_PLUGINS[driver], 1,
649 u"Driver plugin should appear once.", in_filename
651 out_prolog = replace_defensively(
652 out_prolog, Constants.NIC_DRIVER_TO_VFS[u"vfio-pci"],
653 Constants.NIC_DRIVER_TO_VFS[driver], 1,
654 u"NIC VFs argument should appear once.", in_filename
656 iface, suite_id, suite_tag = get_iface_and_suite_ids(
659 check_suite_tag(suite_tag, out_prolog)
660 # TODO: Reorder loops so suite_id is finalized sooner.
661 testcase = Testcase.default(suite_id)
662 with open(out_filename, u"wt") as file_out:
663 file_out.write(out_prolog)
664 add_default_testcases(
665 testcase, iface, suite_id, file_out, kwargs_list
670 """Class containing file generating methods."""
672 def __init__(self, quiet=True):
673 """Initialize the instance.
675 :param quiet: Reduce log prints (to stderr) when True (default).
680 def regenerate_glob(self, pattern, protocol=u"ip4"):
681 """Regenerate files matching glob pattern based on arguments.
683 In the current working directory, find all files matching
684 the glob pattern. Use testcase template to regenerate test cases
685 according to suffix, governed by protocol, autonumbering them.
686 Also generate suites for other NICs and drivers.
688 Log-like prints are emitted to sys.stderr.
690 :param pattern: Glob pattern to select files. Example: \*-ndrpdr.robot
691 :param protocol: String determining minimal frame size. Default: "ip4"
694 :raises RuntimeError: If invalid source suite is encountered.
697 print(f"Regenerator starts at {getcwd()}", file=sys.stderr)
699 min_frame_size = PROTOCOL_TO_MIN_FRAME_SIZE[protocol]
700 default_kwargs_list = [
701 {u"frame_size": min_frame_size, u"phy_cores": 1},
702 {u"frame_size": min_frame_size, u"phy_cores": 2},
703 {u"frame_size": min_frame_size, u"phy_cores": 4},
704 {u"frame_size": 1518, u"phy_cores": 1},
705 {u"frame_size": 1518, u"phy_cores": 2},
706 {u"frame_size": 1518, u"phy_cores": 4},
707 {u"frame_size": 9000, u"phy_cores": 1},
708 {u"frame_size": 9000, u"phy_cores": 2},
709 {u"frame_size": 9000, u"phy_cores": 4},
710 {u"frame_size": u"IMIX_v4_1", u"phy_cores": 1},
711 {u"frame_size": u"IMIX_v4_1", u"phy_cores": 2},
712 {u"frame_size": u"IMIX_v4_1", u"phy_cores": 4}
714 hs_bps_kwargs_list = [
715 {u"frame_size": 1460, u"phy_cores": 1},
717 hs_quic_kwargs_list = [
718 {u"frame_size": 1280, u"phy_cores": 1},
720 iperf3_kwargs_list = [
721 {u"frame_size": 128000, u"phy_cores": 1},
722 {u"frame_size": 128000, u"phy_cores": 2},
723 {u"frame_size": 128000, u"phy_cores": 4}
725 # List for tests with one dataplane core
726 # (and variable number of other cores).
728 {u"frame_size": min_frame_size, u"phy_cores": 2},
729 {u"frame_size": min_frame_size, u"phy_cores": 3},
730 {u"frame_size": min_frame_size, u"phy_cores": 4},
731 {u"frame_size": 1518, u"phy_cores": 2},
732 {u"frame_size": 1518, u"phy_cores": 3},
733 {u"frame_size": 1518, u"phy_cores": 4},
734 {u"frame_size": 9000, u"phy_cores": 2},
735 {u"frame_size": 9000, u"phy_cores": 3},
736 {u"frame_size": 9000, u"phy_cores": 4},
737 {u"frame_size": u"IMIX_v4_1", u"phy_cores": 2},
738 {u"frame_size": u"IMIX_v4_1", u"phy_cores": 3},
739 {u"frame_size": u"IMIX_v4_1", u"phy_cores": 4}
743 {u"frame_size": 0, u"phy_cores": 1},
744 {u"frame_size": 0, u"phy_cores": 2},
745 {u"frame_size": 64, u"phy_cores": 1},
746 {u"frame_size": 64, u"phy_cores": 2},
747 {u"frame_size": 1024, u"phy_cores": 1},
748 {u"frame_size": 1024, u"phy_cores": 2},
749 {u"frame_size": 2048, u"phy_cores": 1},
750 {u"frame_size": 2048, u"phy_cores": 2}
753 device_kwargs_list = [
754 {u"frame_size": min_frame_size, u"phy_cores": 0}
758 {u"frame_size": min_frame_size},
759 {u"frame_size": 1518},
760 {u"frame_size": 9000},
761 {u"frame_size": u"IMIX_v4_1"}
764 for in_filename in glob(pattern):
767 u"Regenerating in_filename:", in_filename, file=sys.stderr
769 iface, _, _ = get_iface_and_suite_ids(in_filename)
770 if not iface.endswith(u"10ge2p1x710"):
772 f"Error in {in_filename}: non-primary NIC found."
774 for prefix in Constants.FORBIDDEN_SUITE_PREFIX_LIST:
775 if prefix in in_filename:
777 f"Error in {in_filename}: non-primary driver found."
779 with open(in_filename, u"rt") as file_in:
780 in_prolog = u"".join(
781 file_in.read().partition(u"*** Test Cases ***")[:-1]
783 if "-tg" in in_filename:
784 write_trex_files(in_filename, in_prolog, trex_kwargs_list)
786 if in_filename.endswith(u"-ndrpdr.robot"):
787 if u"scheduler" in in_filename:
789 in_filename, in_prolog, dp1_kwargs_list
793 in_filename, in_prolog, default_kwargs_list
795 elif in_filename.endswith(u"-reconf.robot"):
796 write_reconf_files(in_filename, in_prolog, default_kwargs_list)
797 elif in_filename.endswith(u"-rps.robot") \
798 or in_filename.endswith(u"-cps.robot"):
799 write_tcp_files(in_filename, in_prolog, http_kwargs_list)
800 elif in_filename.endswith(u"-bps.robot"):
801 hoststack_kwargs_list = \
802 hs_quic_kwargs_list if u"quic" in in_filename \
803 else hs_bps_kwargs_list
804 write_tcp_files(in_filename, in_prolog, hoststack_kwargs_list)
805 elif in_filename.endswith(u"-iperf3-mrr.robot"):
806 write_iperf3_files(in_filename, in_prolog, iperf3_kwargs_list)
807 elif in_filename.endswith(u"-scapy.robot"):
808 write_device_files(in_filename, in_prolog, device_kwargs_list)
811 f"Error in {in_filename}: non-primary suite type found."
814 print(u"Regenerator ends.", file=sys.stderr)
815 print(file=sys.stderr) # To make autogen check output more readable.