Skip to content

Commit 383eaac

Browse files
committed
tools: Add sim_repeater utility
Signed-off-by: Jan Malek <[email protected]>
1 parent 91e6390 commit 383eaac

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
@@ -9,7 +9,7 @@
99
from typing import List
1010

1111
import nox
12-
from nox_utils import VerificationTest, isCocotbSimFailure, nox_config
12+
from nox_utils import VerificationTest, isCocotbSimFailure, nox_config, sim_repeater_path
1313

1414
# Common nox configuration
1515
nox = nox_config(nox)
@@ -116,6 +116,7 @@ def _verify(session, test_group, test_type, test_name, coverage=None, simulator=
116116
filelist = f"{i3c_root}/src/i3c.f"
117117

118118
args = [
119+
sim_repeater_path(),
119120
"make",
120121
"-C",
121122
test.testPath,
@@ -125,6 +126,7 @@ def _verify(session, test_group, test_type, test_name, coverage=None, simulator=
125126
"FILELIST=" + filelist,
126127
"NOX_SESSION=1",
127128
]
129+
128130
if simulator == "verilator":
129131
plusargs.extend(
130132
[

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)