Move read_test_dot_seed Python code to a helper library

This commit is contained in:
Rupert Swarbrick 2022-04-19 15:21:13 +01:00 committed by Rupert Swarbrick
parent 35a63d7e66
commit 19d60932d5
3 changed files with 19 additions and 32 deletions

View file

@ -9,10 +9,10 @@ A script to compare an ISS and RTL run to make sure nothing has diverged.
import argparse
import os
import re
import sys
from typing import Dict, Optional, TextIO, Tuple, Union
from scripts.scripts_lib import read_test_dot_seed
from scripts.test_entry import TestEntry, get_test_entry
from scripts.test_run_result import TestRunResult
@ -38,22 +38,9 @@ finally:
sys.path = _OLD_SYS_PATH
_TestAndSeed = Tuple[str, int]
_CompareResult = Tuple[bool, Optional[str], Dict[str, str]]
def read_test_dot_seed(arg: str) -> _TestAndSeed:
'''Read a value for --test-dot-seed'''
match = re.match(r'([^.]+)\.([0-9]+)$', arg)
if match is None:
raise argparse.ArgumentTypeError('Bad --test-dot-seed ({}): '
'should be of the form TEST.SEED.'
.format(arg))
return (match.group(1), int(match.group(2), 10))
def compare_test_run(test: TestEntry,
idx: int,
seed: int,

View file

@ -2,31 +2,15 @@
import argparse
import os
import re
import subprocess
import sys
from typing import Tuple
from sim_cmd import get_simulator_cmd
from scripts_lib import subst_vars
from scripts_lib import read_test_dot_seed, subst_vars
from test_entry import get_test_entry
_CORE_IBEX = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
_TestAndSeed = Tuple[str, int]
def read_test_dot_seed(arg: str) -> _TestAndSeed:
'''Read a value for --test-dot-seed'''
match = re.match(r'([^.]+)\.([0-9]+)$', arg)
if match is None:
raise argparse.ArgumentTypeError('Bad --test-dot-seed ({}): '
'should be of the form TEST.SEED.'
.format(arg))
return (match.group(1), int(match.group(2), 10))
def get_test_sim_cmd(base_cmd, test, idx, seed, sim_dir, bin_dir, lsf_cmd):
'''Generate the command that runs a test iteration in the simulator

View file

@ -3,17 +3,21 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
import re
import shlex
import subprocess
import sys
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Tuple
THIS_DIR = os.path.dirname(__file__)
IBEX_ROOT = os.path.join(THIS_DIR, 4 * '../')
RISCV_DV_ROOT = os.path.normpath(os.path.join(IBEX_ROOT,
'vendor/google_riscv-dv'))
TestAndSeed = Tuple[str, int]
def run_one(verbose: bool,
cmd: List[str],
@ -83,3 +87,15 @@ def subst_vars(string: str, var_dict: Dict[str, str]) -> str:
for key, value in var_dict.items():
string = string.replace('<{}>'.format(key), value)
return string
def read_test_dot_seed(arg: str) -> TestAndSeed:
'''Read a value for --test-dot-seed'''
match = re.match(r'([^.]+)\.([0-9]+)$', arg)
if match is None:
raise argparse.ArgumentTypeError('Bad --test-dot-seed ({}): '
'should be of the form TEST.SEED.'
.format(arg))
return (match.group(1), int(match.group(2), 10))