Skip to content

Commit 2b192d7

Browse files
jan-malekkgugala
authored andcommitted
tools: Add sim_repeater utility
Signed-off-by: Jan Malek <[email protected]>
1 parent eb6c027 commit 2b192d7

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

tools/nox_utils/src/nox_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
from xml.etree import ElementTree
7+
from pathlib import Path
78

89
"""
910
Common functions and utilities for noxfile.py
@@ -20,6 +21,10 @@ def nox_config(nox):
2021
return nox
2122

2223

24+
def sim_repeater_path():
25+
return str((Path(__file__).parent / ".." / ".." / "sim_repeater.sh").resolve())
26+
27+
2328
def setupLogger(verbose=False, filename="setup_logger.log"):
2429
logger = logging.getLogger()
2530
logHandler = logging.FileHandler(filename=filename, mode="w", encoding="utf-8")

tools/sim_repeater.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
SIM_TRIES="${SIM_TRIES:-3}"
4+
RETRY_COOLDOWN=10
5+
TEMP_LOGS="$(mktemp -d)"
6+
7+
function cleanup {
8+
rm -rf "${TEMP_LOGS}"
9+
}
10+
11+
trap cleanup EXIT
12+
13+
# Needed to propagate the exit code through the pipe to `tee`
14+
set -o pipefail
15+
16+
for (( i=1; i<="${SIM_TRIES}"; i++ )); do
17+
echo "$@"
18+
"$@" 2>&1 | tee "${TEMP_LOGS}/${i}"
19+
RESULT=$?
20+
21+
if [ -n "${SIM_RETRY_CONDITION}" ] && [ $RESULT != 0 ]; then
22+
if grep -E "${SIM_RETRY_CONDITION}" "${TEMP_LOGS}/${i}" &> /dev/null; then
23+
echo "Retry condition encountered. Retrying in ${RETRY_COOLDOWN}s"
24+
echo ''
25+
sleep "${RETRY_COOLDOWN}"
26+
continue
27+
fi
28+
fi
29+
30+
exit $RESULT
31+
done
32+
33+
echo "Limit of ${SIM_TRIES} tries exceeded. Exiting"
34+
exit 1

verification/cocotb/noxfile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import shutil
66

77
import nox
8-
from nox_utils import VerificationTest, isCocotbSimFailure, nox_config
8+
from nox_utils import VerificationTest, isCocotbSimFailure, nox_config, sim_repeater_path
99

1010
# Common nox configuration
1111
nox = nox_config(nox)
@@ -46,13 +46,15 @@ def _verify(session, test_group, test_type, test_name, coverage=None, simulator=
4646
shutil.rmtree(os.path.join(test.testPath, test.sim_build))
4747

4848
args = [
49+
sim_repeater_path(),
4950
"make",
5051
"-C",
5152
test.testPath,
5253
"all",
5354
"MODULE=" + test_name,
5455
"COCOTB_RESULTS_FILE=" + test.filenames["xml"],
5556
]
57+
5658
if simulator == "verilator":
5759
plusargs.extend(
5860
[

verification/uvm_i3c/noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import nox
66

7-
from nox_utils import nox_config, isUVMSimFailure, create_test_id
7+
from nox_utils import nox_config, isUVMSimFailure, create_test_id, sim_repeater_path
88

99
nox = nox_config(nox)
1010

@@ -42,7 +42,7 @@ def verify_uvm(
4242
root_dir = setup_root_dir()
4343

4444
make_targets = ["config", simulator]
45-
args = ["make", "-C", root_dir, *make_targets, f"UVM_TB_FILES={tb_files}"]
45+
args = [sim_repeater_path(), "make", "-C", root_dir, *make_targets, f"UVM_TB_FILES={tb_files}"]
4646

4747
if uvm_testname != "":
4848
args.append(f"UVM_TESTNAME={uvm_testname}")

0 commit comments

Comments
 (0)