Skip to content

Commit b006332

Browse files
committed
[Nexthop] Run_test option to run on reference board
**Pre-submission checklist** - [x] I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running `pip install -r requirements-dev.txt && pre-commit install` - [x] `pre-commit run` Explicitly control when the config should be modified to set AUTOLOAD_BOARD_SETTINGS instead of autodetecting montblanc since not all montblancs are reference boards. As well, modified a copy of the original config to preserve the original and passed in the copy to the tests. Verified the help output: ``` [root@fboss101 fboss]# ./bin/run_test.py --help Setting fboss environment variables usage: run_test.py [-h] [--coldboot_only] [--filter FILTER] [--filter_file FILTER_FILE] [--list_tests] [--config CONFIG] [--qsfp-config QSFP_CONFIG] [--sai_replayer_logging SAI_REPLAYER_LOGGING] [--skip-known-bad-tests SKIP_KNOWN_BAD_TESTS] [--known-bad-tests-file KNOWN_BAD_TESTS_FILE] [--unsupported-tests-file UNSUPPORTED_TESTS_FILE] [--mgmt-if MGMT_IF] [--sai-bin SAI_BIN] [--oss] [--no-oss] [--fruid-path FRUID_PATH] [--simulator SIMULATOR] [--sai_logging SAI_LOGGING] [--fboss_logging FBOSS_LOGGING] [--setup-for-coldboot SETUP_FOR_COLDBOOT] [--setup-for-warmboot SETUP_FOR_WARMBOOT] [--run-on-reference-board] {bcm,sai,qsfp,link,sai_agent} ... Run tests. ... --setup-for-warmboot SETUP_FOR_WARMBOOT run script before warm boot run --run-on-reference-board Modify SAI settings to run on reference board instead of real product ``` Ran the script with the option enabled, verified that a copy of the config was made and the original remained unchanged. ``` [root@fboss101 fboss]# ./bin/run_test.py sai --filter=*HwEmptyTest.CheckInit* --config /opt/fboss/share/hw_test_configs/montblanc.agent.materialized_JSON --run-on-reference-board Setting fboss environment variables The --skip-known-bad-tests option is not set, therefore unsupported tests will be run. HwEmptyTest. CheckInit Using a modified config file {self._config_file_modified} for test runs Replaced AUTOLOAD_BOARD_SETTINGS: 0 by AUTOLOAD_BOARD_SETTINGS: 1 in file /tmp/modified-montblanc.agent.materialized_JSON ... [root@fboss101 fboss]# grep -l 'AUTOLOAD_BOARD_SETTINGS: 1' /tmp/modified-montblanc.agent.materialized_JSON /tmp/modified-montblanc.agent.materialized_JSON [root@fboss101 fboss]# grep -l 'AUTOLOAD_BOARD_SETTINGS: 0' /tmp/modified-montblanc.agent.materialized_JSON [root@fboss101 fboss]# grep -l 'AUTOLOAD_BOARD_SETTINGS: 1' /opt/fboss/share/hw_test_configs/montblanc.agent.materialized_JSON [root@fboss101 fboss]# grep -l 'AUTOLOAD_BOARD_SETTINGS: 0' /opt/fboss/share/hw_test_configs/montblanc.agent.materialized_JSON /opt/fboss/share/hw_test_configs/montblanc.agent.materialized_JSON [root@fboss101 fboss]# ```
1 parent 9921520 commit b006332

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

fboss/oss/scripts/run_scripts/run_test.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
import os
99
import re
10+
import shutil
1011
import subprocess
1112
import sys
1213
import time
@@ -284,6 +285,10 @@ class TestRunner(abc.ABC):
284285
re.VERBOSE,
285286
)
286287

288+
def __init__(self):
289+
super().__init__()
290+
self._config_file_modified = None
291+
287292
@abc.abstractmethod
288293
def _get_config_path(self):
289294
pass
@@ -621,7 +626,31 @@ def _replace_string_in_file(self, file_path, old_str, new_str):
621626
except Exception as e:
622627
print(f"Error when replacing string in {file_path}: {str(e)}")
623628

624-
def _run_tests(self, tests_to_run, args):
629+
def _backup_and_modify_config(self, conf_file):
630+
"""Create a copy of the config and modify settings"""
631+
if args.run_on_reference_board:
632+
# Create a copy of the config file for modification
633+
try:
634+
# Create a modified copy in /tmp with standard name
635+
config_filename = os.path.basename(conf_file)
636+
self._config_file_modified = f"/tmp/modified-{config_filename}"
637+
shutil.copy2(conf_file, self._config_file_modified)
638+
639+
print("Using a modified config file {self._config_file_modified} for test runs")
640+
# Some platforms, like TH5 SVK, need to set
641+
# AUTOLOAD_BOARD_SETTINGS=1 to autodetect reference board
642+
self._replace_string_in_file(
643+
self._config_file_modified,
644+
"AUTOLOAD_BOARD_SETTINGS: 0",
645+
"AUTOLOAD_BOARD_SETTINGS: 1",
646+
)
647+
return self._config_file_modified
648+
except Exception as e:
649+
print(f"Error creating config copy {conf_file}: {str(e)}")
650+
return conf_file
651+
return conf_file
652+
653+
def _run_tests(self, tests_to_run, conf_file, args):
625654
if args.sai_replayer_logging:
626655
if os.path.isdir(args.sai_replayer_logging) or os.path.isfile(
627656
args.sai_replayer_logging
@@ -662,14 +691,6 @@ def _run_tests(self, tests_to_run, args):
662691
warmboot = True
663692

664693
test_binary_name = self._get_test_binary_name()
665-
conf_file = (
666-
args.config if (args.config is not None) else self._get_config_path()
667-
)
668-
if args.oss and self._string_in_file(args.fruid_path, "MONTBLANC"):
669-
# TH5 SVK platform need to set AUTOLOAD_BOARD_SETTINGS=1
670-
self._replace_string_in_file(
671-
conf_file, "AUTOLOAD_BOARD_SETTINGS: 0", "AUTOLOAD_BOARD_SETTINGS: 1"
672-
)
673694
if test_binary_name != "qsfp_hw_test" and not os.path.exists(conf_file):
674695
print("########## Conf file not found: " + conf_file)
675696
return []
@@ -773,7 +794,11 @@ def run_test(self, args):
773794
# Check if tests need to be run or only listed
774795
if args.list_tests is False:
775796
start_time = datetime.now()
776-
output = self._run_tests(tests_to_run, args)
797+
original_conf_file = (
798+
args.config if (args.config is not None) else self._get_config_path()
799+
)
800+
conf_file = self._backup_and_modify_config(original_conf_file)
801+
output = self._run_tests(tests_to_run, conf_file, args)
777802
end_time = datetime.now()
778803
delta_time = end_time - start_time
779804
print(
@@ -1419,6 +1444,12 @@ def _filter_tests(self, tests: List[str]) -> List[str]:
14191444
default=DEFAULT_TEST_RUN_TIMEOUT_IN_SECOND,
14201445
help="Specify test run timeout in seconds",
14211446
)
1447+
ap.add_argument(
1448+
"--run-on-reference-board",
1449+
action="store_true",
1450+
help="Modify SAI settings to run on reference board instead of real product",
1451+
default=False,
1452+
)
14221453

14231454
# Add subparsers for different test types
14241455
subparsers = ap.add_subparsers()

0 commit comments

Comments
 (0)