Conf

riescue.Conf provides a way to modify the riescue.FeatMgr configuration and adds hookable methods. Configuration is done by modifying the riescue.FeatMgr and/or riescue.FeatMgrBuilder objects in place before or after building.

A custom Conf class can be instantiated and passed into the py:meth:riescue.RiescueD.run or py:meth:riescue.RiescueD.configure methods.

class riescue.dtest_framework.config.Conf

User configuration for Riescue. Provides dynamic configuration for test environment and generation options.

Allows for users to write hooks into a file and use them to modify the test environment before or after building, or to modify some generated code, like the end of test code.

E.g. to add an end of test write to a custom address:

from riescue import RiescueD, FeatMgr, Conf
from riescue.lib.rand import RandNum
import riescue.lib.enums as RV

def end_test(featmgr: FeatMgr) -> str:
    return '''
        li t0, 0x10000000
        sw t0, 0(t0)
    '''

class MyEotConf(Conf):
    def add_hooks(self, featmgr: FeatMgr) -> None:
        featmgr.register_hook(RV.HookPoint.PRE_HALT, end_test)

rd = RiescueD(testfile="test.rasm", cpuconfig="cpu_config.json")
conf = MyEotConf()
rd.run(conf=conf)

E.g. to force all tests to run in MACHINE mode:

from riescue import RiescueD, FeatMgr, Conf
from riescue.lib.rand import RandNum
import riescue.lib.enums as RV


class MyConf(Conf):
    def post_build(self, featmgr: FeatMgr) -> None:
        # always make it MACHINE
        featmgr.priv_mode = RV.RiscvPrivileges.MACHINE


rd = RiescueD(testfile="test.rasm", cpuconfig="cpu_config.json")
rd.configure(conf=MyConf())
rd.generate()
rd.build()
rd.simulate()
pre_build(featmgr_builder: FeatMgrBuilder) None

Called at start of FeatMgrBuilder.build(), before FeatMgr is built.

Parameters:

featmgr_builder – The FeatMgrBuilder to build

post_build(featmgr: FeatMgr) None

Called at end of FeatMgrBuilder.build(), after FeatMgr is built.

Parameters:

featmgr – The FeatMgr to build

add_hooks(featmgr: FeatMgr) None

Used to add hooks to the FeatMgr. Called after post_build().

Call with riescue.FeatMgr.register_hook()

Parameters:

featmgr – Built FeatMgr

static load_conf_from_path(path: Path) Conf

Dynamically loads Conf class from to a .py script. File must contain a Conf class definition and a setup() method that returns an initialized Conf object.

Methods is used by RiescueD to load from the CLI --conf command-line option.

E.g.

class MyConf(Conf):
    def __init__(self):
        self.custom_hook_comment = "# a different comment"

    def custom_hook(self, featmgr: FeatMgr) -> str:
        return f'''
            {self.custom_hook_comment}
            nop
        '''

    def add_hooks(self, featmgr: FeatMgr) -> None:
        featmgr.register_hook(HookPoint.PRE_HALT, self.custom_hook)
def setup() -> Conf:
    return MyConf()
Raises:
  • FileNotFoundError – If the configuration file does not exist

  • ImportError – If the configuration module cannot be imported

  • RuntimeError – If the configuration module does not contain a a setup() method that returns a Conf object.

Conf scripts and the CLI

Conf classes can also be saved to a file and loaded from the command line. This allows for custom behavior to be added without having to use the Python API.

riescue.RiescueD has the --conf command-line option to load a Conf class from a script.

The only requirements for a Conf script passed through using --conf is

  • The script must contain a setup() method

  • The setup() method must return an instance of a Conf subclass

Users can override one or any of the methods.

Adding Runtime Hooks using a Conf script

Users can add runtime hooks to the test by overriding the riescue.Conf.add_hooks() method using one of the riescue.lib.enums.HookPoint enum values.

E.g. a valid Conf script can look like:

from riescue import RiescueD, FeatMgr, Conf
from riescue.lib.rand import RandNum
import riescue.lib.enums as RV

def end_test(featmgr: FeatMgr) -> str:
    return '''
        li t0, 0x10000000
        sw t0, 0(t0)
    '''

class MyEotConf(Conf):
    def add_hooks(self, featmgr: FeatMgr) -> None:
        featmgr.register_hook(RV.HookPoint.PRE_HALT, end_test)

def setup() -> Conf:
    return MyEotConf()