Toffee Package API

Submodules

toffee.agent module

class toffee.agent.Agent(bundle)[源代码]

基类:object

Provides an agent for operation on the DUT.

all_driver_method()[源代码]

Yields all driver method in the agent.

返回:

A generator that yields all driver method in the agent.

all_monitor_method()[源代码]

Yields all monitor methods in the agent.

返回:

A generator that yields all monitor method in the agent.

get_driver_method(name)[源代码]

Get the driver method by name.

get_monitor_method(name)[源代码]

Get the monitor method by name.

monitor_size(monitor_name)[源代码]

Get the queue size of the monitor.

参数:

monitor_name -- The name of the monitor.

返回:

The queue size of the monitor.

start_monitor(monitor_name, maxsize=4)[源代码]

After monitoring begins, monitor_method places the monitored data in a separate queue. Calling monitor_method in a test case will get the monitored data.

参数:
  • monitor_name -- The name of the monitor.

  • maxsize -- The maximum size of the queue.

toffee.agent.driver_method()[源代码]

Decorator for driver method.

返回:

The decorator for driver method.

toffee.agent.monitor_method()[源代码]

Decorator for monitor method.

返回:

The decorator for monitor method.

toffee.asynchronous module

class toffee.asynchronous.Event[源代码]

基类:Event

Change the function in the Event to meet the asynchronous requirements.

async wait()[源代码]

Block until the internal flag is true.

If the internal flag is true on entry, return True immediately. Otherwise, block until another coroutine calls set() to set the flag to true, then return True.

class toffee.asynchronous.Queue[源代码]

基类:Queue

Change the function in the Queue to meet the asynchronous requirements.

async get()[源代码]

Remove and return an item from the queue.

If queue is empty, wait until an item is available.

async put(item)[源代码]

Put an item into the queue.

Put an item into the queue. If the queue is full, wait until a free slot is available before adding item.

toffee.asynchronous.create_task(coro, *, name=None, context=None)[源代码]

Schedule the execution of a coroutine object in a spawn task.

Return a Task object.

async toffee.asynchronous.gather(*coros)[源代码]

Gather multiple coroutines and run them at the same time.

async toffee.asynchronous.main_coro(test, env_handle=None)[源代码]

Wrapper for a coroutine to meet the rules for toffee.

参数:
  • test -- The test to be run, it can be a coroutine or a function.

  • env_handle -- A handle to create the environment. make sure the env is created before the test starts. if the env_handle is provided, the test will be called with the env_handle's return value. when the env_handle is set, make sure the test is a function and has the same number of arguments as the env_handle's return.

返回:

The result of the coroutine (or function).

toffee.asynchronous.run(test, env_handle=None, dut=None)[源代码]

Start the asynchronous event loop and run the coroutine.

参数:
  • test -- The test to be run, it can be a coroutine or a function.

  • env_handle -- A handle to create the environment. make sure the env is created before the test starts. if the env_handle is provided, the test will be called with the env_handle's return value. when the env_handle is set, make sure the test is a function and has the same number of arguments as the env_handle's return.

  • dut -- The DUT object.

返回:

The result of the coroutine (or function).

async toffee.asynchronous.sleep(delay: float)[源代码]

Change the implementation of the sleep function to meet the asynchronous requirements.

toffee.asynchronous.start_clock(dut)[源代码]

Start a clock loop on a DUT.

toffee.bundle module

class toffee.bundle.Bundle[源代码]

基类:MObject

A bundle is a collection of signals in a DUT.

all_signals(level_string='')[源代码]

Yield all signals of the bundle.

返回:

A generator of signal names and signals.

all_signals_rule()[源代码]

Get all signals rules in the bundle.

返回:

A dictionary of all signals rules in the bundle.

as_dict(multilevel=True)[源代码]

Collect all signals values into a dictionary.

参数:

multilevel -- When multilevel is true, the subbundle signal values are put into a secondary dictionary. Otherwise, the dictionary returned will have only one level, with the sub-bundles separated by dots in keys.

返回:

A dictionary of all signals values in the bundle.

assign(item, multilevel=True, level_string='')[源代码]

Assign all signals values.

参数:
  • item -- item can be a dict or an object with a __bundle_assign__ method defined. When item is a dictionary, if "*" is in the dictionary, the value of "*" will be assigned to all signals that are not in the dictionary. Otherwise assign will call the __bundle_assign__ function in item to complete the assignment to the bundle

  • multilevel -- When multilevel is true, the subbundle signal values are taken from a secondary dictionary. Otherwise, the dictionary should have only one level, with the sub-bundles separated by dots in keys.

bind(dut, unconnected_signal_access=True)[源代码]

Bind the dut's signal to this bundle. it will overwrites the previous bind.

参数:
  • dut -- The dut to bind the bundle to.

  • unconnected_signal_access -- Whether unconnected signals could be accessed.

返回:

The bundle itself.

detect_connectivity(signal_name)[源代码]

Detect wether a signal name could be connected to this bundle.

参数:
  • bundle -- The bundle to connect.

  • signal_name -- The name of the signal to connect.

返回:

True if the signal name could be connected to the bundle, False otherwise.

static detect_multiple_connections(dut)[源代码]

Detect signals that are connected to multiple bundles.

参数:

dut -- The dut to detect.

返回:

A list of signals that are connected to multiple bundles.

detect_specific_connectivity(signal_name, specific_signal)[源代码]

Detects whether a signal name can be connected to a specific signal in the bundle

参数:
  • signal_name -- The name of the signal to connect.

  • specific_signal -- The specific signal in this bundle to connect to, format such as "subbundle1.subbundle2.siganlA"

static detect_unconnected_signals(dut)[源代码]

Detect signals that are not connected to any bundle.

参数:

dut -- The dut to detect.

返回:

A list of unconnected signals

static dut_all_signals(dut)[源代码]

Yield all signals of the dut.

参数:

dut -- The dut to get signals from.

返回:

A generator of dictionaries containing the name, original name, and signal of the signal.

classmethod from_dict(dict={})[源代码]

Create a bundle from a dictionary. The keys of the dictionary are the names of the signals in the bundle, and the values are the names of the signals in DUT.

参数:

dict -- The dictionary to guide bundle connections

返回:

A new bundle.

classmethod from_prefix(prefix='', dut=None)[源代码]

Create a bundle from a prefix.

参数:

prefix -- The prefix to match the signals.

返回:

A new bundle.

classmethod from_regex(regex='')[源代码]

Create a bundle from a regex. The signals captured in the regex will be used for matching. If there are multiple capture groups, they are concatenated into a string to match.

参数:

regex -- The regex to match the signals.

返回:

A new bundle.

classmethod from_xport(xport)[源代码]

Create a bundle from an XPort.

参数:

xport -- The XPort to create the bundle from.

返回:

A new bundle.

make_requset_response_for(dut)[源代码]

Make a request response for the dut.

参数:

dut -- The dut to make the request response for.

static new_class_from_list(signal_list)[源代码]

Create a new bundle class with a list of signals quickly.

>>> myBundle = Bundle.new_class_from_list(["a", "b", "c"]).from_prefix("io_")
参数:

signal_list -- A list of signals.

返回:

A new bundle class.

static new_class_from_xport(xport)[源代码]

Create a new bundle class with an XPort quickly.

参数:

xport -- The XPort to create the bundle from.

返回:

A new bundle class.

process_requests(request: Dict | List[Dict] | None)[源代码]

Process the requests.

参数:

request -- The request to process.

randomize_all(value_range=None, exclude_signals=[], random_func=<bound method Random.randint of <random.Random object>>)[源代码]

Randomize all signals values in the bundle.

参数:
  • value_range -- The range of the random values, eg. (0, 100), both values are inclusive. If None, the range of random values will be the range of each signal value.

  • exclude_signals -- A list of signals to exclude from randomization, sub-bundle names are separated by dots.

  • random_func -- The random function to use, default is random.randint.

set_all(value)[源代码]

Set all signals values to a value, including sub-bundles.

参数:

value -- The value to set.

返回:

The bundle itself.

set_dict(dict={})[源代码]

Set the bundle to bind from a dictionary.

参数:

dict -- The dictionary to guide bundle connections

返回:

The bundle itself.

set_name(name)[源代码]

Set the name of the bundle.

参数:

name -- The name of the bundle.

返回:

The bundle itself.

set_prefix(prefix='')[源代码]

Set the bundle to bind from prefix.

参数:

prefix -- The prefix to match the signals.

返回:

The bundle itself.

set_regex(regex='')[源代码]

Set the bundle to bind from regex.

参数:

regex -- The regex to match the signals.

返回:

The bundle itself.

set_write_mode(write_mode: WriteMode)[源代码]

Set the write mode of the bundle. it will change the write mode of all signals in the bundle.

参数:

write_mode -- The write mode to set.

返回:

The bundle itself.

set_write_mode_as_fall()[源代码]

Set the write mode of the bundle to fall.

返回:

The bundle itself.

set_write_mode_as_imme()[源代码]

Set the write mode of the bundle to immediate.

返回:

The bundle itself.

set_write_mode_as_rise()[源代码]

Set the write mode of the bundle to rise.

返回:

The bundle itself.

signals = []
async step(ncycles=1)[源代码]

Wait for the clock for ncycles. Only works if the bundle has a connected signal.

参数:

ncycles -- The number of cycles to wait.

class toffee.bundle.BundleList(bundle, format: str, limit: int, rule=None)[源代码]

基类:object

assign(value, multilevel=True)[源代码]
classmethod from_bundlelist(old_bundle_list: BundleList)[源代码]
class toffee.bundle.DummySignal[源代码]

基类:object

A dummy signal class that does nothing. It will return None when accessed, and do nothing when set.

class toffee.bundle.Signal[源代码]

基类:UnconnectedSignal

class toffee.bundle.SignalList(format: str, limit: int, rule=None)[源代码]

基类:object

assign(value)[源代码]
bind_signal(bundle, signal_name: str, signal, info_bundle_name, info_dut_name)[源代码]
classmethod from_signallist(old_signal_list: SignalList)[源代码]
toffee.bundle.Signals(num: int)[源代码]
class toffee.bundle.WriteMode(*values)[源代码]

基类:Enum

The write mode of a bundle.

Fall = 2
Imme = 0
Rise = 1

toffee.debug module

class toffee.debug.PdbToffee(dut, *args, **kwargs)[源代码]

基类:Pdb

do_tflush(arg)[源代码]
do_tforce(arg)[源代码]
do_tlist(arg)[源代码]
do_tprint(arg)[源代码]
do_trelease(arg)[源代码]
do_tset(arg)[源代码]
do_tstep(arg)[源代码]
toffee.debug.debug(*args, **kwargs)[源代码]
toffee.debug.error(*args, **kwargs)[源代码]
toffee.debug.get(dut, *args, **kwargs)[源代码]
toffee.debug.info(*args, **kwargs)[源代码]

toffee.delay module

class toffee.delay.Delayer(signal, delay)[源代码]

基类:MObject

A Delayer class is used to delay the signal value.

sample()[源代码]

Sample the signal value once and store it in the value list.

property value

Get the value of the signal after the delay.

toffee.env module

class toffee.env.Env[源代码]

基类:MObject

Env is used to wrap the entire verification environment and provides reference model synchronization

all_agent_names()[源代码]

Yields all agent names in the env.

返回:

A generator that yields all agent names in the env.

attach(model)[源代码]

Attach a model to the env.

参数:

model -- The model to be attached.

返回:

The env itself.

unattach(model)[源代码]

Unattach a model from the env.

参数:

model -- The model to be unattached.

返回:

The env itself.

toffee.executor module

class toffee.executor.Executor(exit='all')[源代码]

基类:MObject

The executor class is used to manage the execution of multiple coroutines.

get_results()[源代码]

Get the results of the coroutines.

返回:

A dictionary of results.

async wait_all()[源代码]

Wait for all the coroutines to complete. This function should be called after execute.

toffee.funcov module

class toffee.funcov.CovCondition[源代码]

基类:MObject

CovCondition class

class toffee.funcov.CovEq(value)[源代码]

基类:CovCondition

CovEq class, check if the target is equal to the value

class toffee.funcov.CovGe(value)[源代码]

基类:CovCondition

CovGe class, check if the target is greater or equal to the value

class toffee.funcov.CovGroup(name: str = '', disable_sample_when_point_hinted=True)[源代码]

基类:object

functional coverage group

add_cover_point(target: object, bins: dict | CovCondition | Callable[[object, object], bool], name: str = '', once=None, dynamic_bin=False)

Add a watch point to the group @param target: the object to be watched, need to have a value attribute. eg target.value is available @param bins: a dict of CovCondition objects, a single CovCondition object or a Callable object (its params is call(target) -> bool). @param name: the name of the point

add_watch_point(target: object, bins: dict | CovCondition | Callable[[object, object], bool], name: str = '', once=None, dynamic_bin=False)[源代码]

Add a watch point to the group @param target: the object to be watched, need to have a value attribute. eg target.value is available @param bins: a dict of CovCondition objects, a single CovCondition object or a Callable object (its params is call(target) -> bool). @param name: the name of the point

as_dict()[源代码]

return the group as a dict

clear()[源代码]

clear all points

cover_point(key: str)[源代码]

return the point with key @param key: the key of the point

cover_points()[源代码]

return the name list for all points

del_point(name: str)[源代码]

delete a point with name @param name: the name of the point

init()[源代码]
is_all_covered() bool[源代码]

check if all points are covered

is_point_covered(key: str) bool[源代码]

check if the point with key is covered @param key: the key of the point

mark_function(name: str, func: Callable | str | list, bin_name: str | list = '*', raise_error=True)[源代码]

Mark one or more functions for a point

Description:

By this reverse marking, record the relationship between checkpoints and target coverage functions to facilitate the management and analysis of checkpoints and test cases.

参数:
  • name (str) -- checkpoint name

  • func (Union[Callable,str, list]) -- function or function list to be marked

  • bin_name (Union[str, list]) -- bin name, support wildcard and regex. Default to '*' all bins.

返回:

this covgroup object

返回类型:

CovGroup

reset_point(name: str)[源代码]

reset a point with name @param name: the name of the point

resume_sample()[源代码]

resume sampling

sample()[源代码]

sample the group

sample_stoped()[源代码]

check if the group is stoped

stop_sample()[源代码]

stop sampling

class toffee.funcov.CovGt(value)[源代码]

基类:CovCondition

CovGt class, check if the target is greater than the value

class toffee.funcov.CovIn(value)[源代码]

基类:CovCondition

CovIn class, check if the target is in the value

class toffee.funcov.CovIsInRange(low, high)[源代码]

基类:CovCondition

CovIsInRange class, check if the target is in the range

class toffee.funcov.CovLe(value)[源代码]

基类:CovCondition

CovLe class, check if the target is less or equal to the value

class toffee.funcov.CovLt(value)[源代码]

基类:CovCondition

CovLt class, check if the target is less than the value

class toffee.funcov.CovNe(value)[源代码]

基类:CovCondition

CovNe class, check if the target is not equal to the value

class toffee.funcov.CovNotIn(value)[源代码]

基类:CovCondition

CovNotIn class, check if the target is not in the value

toffee.funcov.Eq

CovEq 的别名

toffee.funcov.Ge

CovGe 的别名

toffee.funcov.Gt

CovGt 的别名

toffee.funcov.In

CovIn 的别名

toffee.funcov.IsInRange

CovIsInRange 的别名

toffee.funcov.Le

CovLe 的别名

toffee.funcov.Lt

CovLt 的别名

toffee.funcov.Ne

CovNe 的别名

toffee.funcov.NotIn

CovNotIn 的别名

toffee.logger module

toffee.logger.critical(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'CRITICAL'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.critical("Houston, we have a %s", "major disaster", exc_info=True)

toffee.logger.debug(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'DEBUG'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.debug("Houston, we have a %s", "thorny problem", exc_info=True)

toffee.logger.error(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'ERROR'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.error("Houston, we have a %s", "major problem", exc_info=True)

toffee.logger.exception(msg, *args, exc_info=True, **kwargs)[源代码]

Convenience method for logging an ERROR with exception information.

toffee.logger.get_logger() Logger[源代码]

Returns the global logger for Toffee

toffee.logger.info(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'INFO'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.info("Houston, we have a %s", "notable problem", exc_info=True)

toffee.logger.log(level, msg, *args, **kwargs)[源代码]

Log 'msg % args' with the integer severity 'level'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.log(level, "We have a %s", "mysterious problem", exc_info=True)

toffee.logger.setup_logging(log_level=30, format='%(name)s_%(levelname)s @%(filename)s:%(lineno)d%(log_id)s:\t%(message)s', console_display=True, log_file=None)[源代码]

Setup the logging configuration for Toffee

参数:
  • log_level -- The log level for the logger

  • format -- The format of the log message

  • console_display -- Whether to display logs on the console

  • log_file -- The log file name to write logs, if None, logs are not written to a file

toffee.logger.summary()[源代码]

Display a summary of the logs

toffee.logger.warning(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'WARNING'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.warning("Houston, we have a %s", "bit of a problem", exc_info=True)

toffee.model module

class toffee.model.AgentPort(agent_name: str = '', maxsize: int = 4, *, agents: list = [], methods: list = [])[源代码]

基类:Port

get_path()[源代码]
class toffee.model.DriverPort(driver_path: str = '', *, agent_name: str = '', driver_name: str = '', maxsize: int = 4)[源代码]

基类:Port

The DriverPort is used to match driver_method in the agent and obtain call arguments.

get_path()[源代码]

Get the driver path.

class toffee.model.Model[源代码]

基类:Component

The Model is used to provide a reference model for the DUT.

clear_matched()[源代码]

Clear the matched status of all driver ports, monitor ports, driver hooks, and agent hooks.

collect_all()[源代码]

Collect all driver ports, monitor ports, driver hooks, and agent hooks.

ensure_all_matched()[源代码]

Ensure all driver ports, monitor ports, driver hooks, and agent hooks are matched.

get_driver_hook(driver_path: str, mark_matched: bool = False)[源代码]

Get the driver hook by name.

get_driver_port(drive_path: str, mark_matched: bool = False)[源代码]

Get the driver port by name.

get_monitor_hook(monitor_path: str, mark_matched: bool = False)[源代码]

Get the monitor hook by name.

get_monitor_port(monitor_path: str, mark_matched: bool = False)[源代码]

Get the monitor port by name.

is_attached()[源代码]

Check if the model is attached to an agent.

async main()[源代码]
class toffee.model.MonitorPort(monitor_path: str = '', *, agent_name: str = '', monitor_name: str = '', maxsize: int = 4)[源代码]

基类:Port

The MonitorPort is used to match the monitor_method in the agent, and obtain the results.

get_path()[源代码]

Get the monitor path.

toffee.model.agent_hook(agent_name: str = '', *, agents: list = [], methods: list = [], priority: int = 99, sche_order: str = 'model_first')[源代码]

Decorator for agent hook.

参数:
  • agent_name -- The name of the agent to be hooked. If it is empty, the name of the function will be used.

  • agents -- The list of agents to be hooked.

  • methods -- The list of paths of the methods to be hooked.

  • priority -- The priority of the agent hook which should be an integer between 0 and 99. The smaller the number, the higher the priority. It will determine the order of calls within the same cycle. The default priority of agent hook is 99.

  • sche_order -- The order in which the hook is called relative to the dut. If it is "model_first", it will be called before the corresponding agent_method runs, and vice versa after it runs.

toffee.model.driver_hook(driver_path: str = '', *, agent_name: str = '', driver_name: str = '', priority=99, sche_order='model_first')[源代码]

Decorator for driver hook.

参数:
  • driver_path -- The path of the driver.

  • agent_name -- The name of the agent to be hooked.

  • driver_name -- The name of the driver to be hooked.

  • priority -- The priority of the driver hook which should be an integer between 0 and 99. The smaller the number, the higher the priority. It will determine the order of calls within the same cycle. The default priority of driver hook is 99.

  • sche_order -- The order in which the hook is called relative to the dut. If it is "model_first", it will be called before the corresponding driver_method runs, and vice versa after it runs.

toffee.model.monitor_hook(monitor_path: str = '', *, agent_name: str = '', monitor_name: str = '', priority: int = 0)[源代码]

Decorator for monitor hook.

参数:
  • monitor_path -- The path of the monitor.

  • agent_name -- The name of the agent to be hooked.

  • monitor_name -- The name of the monitor to be hooked.

  • priority -- The priority of the monitor hook which should be an integer between 0 and 99. The smaller the number, the higher the priority. It will use the same priority as driver_hook, determining the order of calls within the same cycle. The default priority of monitor hook is -1, which means the monitor hook will be executed before driver hook.

toffee.triggers module

async toffee.triggers.AllValid(*pins, delay=1)[源代码]

Wait for all the pins to be valid.

参数:
  • pins -- The pins to be checked.

  • delay -- The minimum number of clock cycles to pass before checking.

async toffee.triggers.Change(pin)[源代码]

Wait for the pin value to change.

参数:

pin -- The pin to be checked.

async toffee.triggers.ClockCycles(item, ncycles=1)[源代码]

Wait for the specified number of clock cycles.

参数:
  • item -- The item to be waited for. It can be a dut, a bundle, or an xpin.

  • ncycles -- The number of clock cycles to be waited for.

async toffee.triggers.Condition(item, func, delay=1)[源代码]

Wait for the specified condition to be true.

参数:
  • item -- The item to be waited for. It can be a dut, a bundle, or an xpin.

  • func -- The condition function to be checked, it should accept a single argument 'item' and return a boolean.

  • delay -- The minimum number of clock cycles to pass before checking.

async toffee.triggers.FallingEdge(pin)[源代码]

Wait for the pin to have a falling edge. Specifically, the function returns when the pin has a value of non-0 in the previous cycle and a value of 0 in the current cycle.

参数:

pin -- The pin to be checked.

async toffee.triggers.RisingEdge(pin)[源代码]

Wait for the pin to have a rising edge. Specifically, the function returns when the pin has a value of 0 in the previous cycle and a value of non-0 in the current cycle.

参数:

pin -- The pin to be checked.

async toffee.triggers.Value(pin, value: int, delay=1)[源代码]

Wait for the pin to have the specified value.

参数:
  • pin -- The pin to be checked.

  • value -- The value to be checked.

  • delay -- The minimum number of clock cycles to pass before checking.

Subpackages

Module contents

class toffee.Agent(bundle)[源代码]

基类:object

Provides an agent for operation on the DUT.

all_driver_method()[源代码]

Yields all driver method in the agent.

返回:

A generator that yields all driver method in the agent.

all_monitor_method()[源代码]

Yields all monitor methods in the agent.

返回:

A generator that yields all monitor method in the agent.

get_driver_method(name)[源代码]

Get the driver method by name.

get_monitor_method(name)[源代码]

Get the monitor method by name.

monitor_size(monitor_name)[源代码]

Get the queue size of the monitor.

参数:

monitor_name -- The name of the monitor.

返回:

The queue size of the monitor.

start_monitor(monitor_name, maxsize=4)[源代码]

After monitoring begins, monitor_method places the monitored data in a separate queue. Calling monitor_method in a test case will get the monitored data.

参数:
  • monitor_name -- The name of the monitor.

  • maxsize -- The maximum size of the queue.

class toffee.AgentPort(agent_name: str = '', maxsize: int = 4, *, agents: list = [], methods: list = [])[源代码]

基类:Port

get_path()[源代码]
async toffee.AllValid(*pins, delay=1)[源代码]

Wait for all the pins to be valid.

参数:
  • pins -- The pins to be checked.

  • delay -- The minimum number of clock cycles to pass before checking.

class toffee.Bundle[源代码]

基类:MObject

A bundle is a collection of signals in a DUT.

all_signals(level_string='')[源代码]

Yield all signals of the bundle.

返回:

A generator of signal names and signals.

all_signals_rule()[源代码]

Get all signals rules in the bundle.

返回:

A dictionary of all signals rules in the bundle.

as_dict(multilevel=True)[源代码]

Collect all signals values into a dictionary.

参数:

multilevel -- When multilevel is true, the subbundle signal values are put into a secondary dictionary. Otherwise, the dictionary returned will have only one level, with the sub-bundles separated by dots in keys.

返回:

A dictionary of all signals values in the bundle.

assign(item, multilevel=True, level_string='')[源代码]

Assign all signals values.

参数:
  • item -- item can be a dict or an object with a __bundle_assign__ method defined. When item is a dictionary, if "*" is in the dictionary, the value of "*" will be assigned to all signals that are not in the dictionary. Otherwise assign will call the __bundle_assign__ function in item to complete the assignment to the bundle

  • multilevel -- When multilevel is true, the subbundle signal values are taken from a secondary dictionary. Otherwise, the dictionary should have only one level, with the sub-bundles separated by dots in keys.

bind(dut, unconnected_signal_access=True)[源代码]

Bind the dut's signal to this bundle. it will overwrites the previous bind.

参数:
  • dut -- The dut to bind the bundle to.

  • unconnected_signal_access -- Whether unconnected signals could be accessed.

返回:

The bundle itself.

detect_connectivity(signal_name)[源代码]

Detect wether a signal name could be connected to this bundle.

参数:
  • bundle -- The bundle to connect.

  • signal_name -- The name of the signal to connect.

返回:

True if the signal name could be connected to the bundle, False otherwise.

static detect_multiple_connections(dut)[源代码]

Detect signals that are connected to multiple bundles.

参数:

dut -- The dut to detect.

返回:

A list of signals that are connected to multiple bundles.

detect_specific_connectivity(signal_name, specific_signal)[源代码]

Detects whether a signal name can be connected to a specific signal in the bundle

参数:
  • signal_name -- The name of the signal to connect.

  • specific_signal -- The specific signal in this bundle to connect to, format such as "subbundle1.subbundle2.siganlA"

static detect_unconnected_signals(dut)[源代码]

Detect signals that are not connected to any bundle.

参数:

dut -- The dut to detect.

返回:

A list of unconnected signals

static dut_all_signals(dut)[源代码]

Yield all signals of the dut.

参数:

dut -- The dut to get signals from.

返回:

A generator of dictionaries containing the name, original name, and signal of the signal.

classmethod from_dict(dict={})[源代码]

Create a bundle from a dictionary. The keys of the dictionary are the names of the signals in the bundle, and the values are the names of the signals in DUT.

参数:

dict -- The dictionary to guide bundle connections

返回:

A new bundle.

classmethod from_prefix(prefix='', dut=None)[源代码]

Create a bundle from a prefix.

参数:

prefix -- The prefix to match the signals.

返回:

A new bundle.

classmethod from_regex(regex='')[源代码]

Create a bundle from a regex. The signals captured in the regex will be used for matching. If there are multiple capture groups, they are concatenated into a string to match.

参数:

regex -- The regex to match the signals.

返回:

A new bundle.

classmethod from_xport(xport)[源代码]

Create a bundle from an XPort.

参数:

xport -- The XPort to create the bundle from.

返回:

A new bundle.

make_requset_response_for(dut)[源代码]

Make a request response for the dut.

参数:

dut -- The dut to make the request response for.

static new_class_from_list(signal_list)[源代码]

Create a new bundle class with a list of signals quickly.

>>> myBundle = Bundle.new_class_from_list(["a", "b", "c"]).from_prefix("io_")
参数:

signal_list -- A list of signals.

返回:

A new bundle class.

static new_class_from_xport(xport)[源代码]

Create a new bundle class with an XPort quickly.

参数:

xport -- The XPort to create the bundle from.

返回:

A new bundle class.

process_requests(request: Dict | List[Dict] | None)[源代码]

Process the requests.

参数:

request -- The request to process.

randomize_all(value_range=None, exclude_signals=[], random_func=<bound method Random.randint of <random.Random object>>)[源代码]

Randomize all signals values in the bundle.

参数:
  • value_range -- The range of the random values, eg. (0, 100), both values are inclusive. If None, the range of random values will be the range of each signal value.

  • exclude_signals -- A list of signals to exclude from randomization, sub-bundle names are separated by dots.

  • random_func -- The random function to use, default is random.randint.

set_all(value)[源代码]

Set all signals values to a value, including sub-bundles.

参数:

value -- The value to set.

返回:

The bundle itself.

set_dict(dict={})[源代码]

Set the bundle to bind from a dictionary.

参数:

dict -- The dictionary to guide bundle connections

返回:

The bundle itself.

set_name(name)[源代码]

Set the name of the bundle.

参数:

name -- The name of the bundle.

返回:

The bundle itself.

set_prefix(prefix='')[源代码]

Set the bundle to bind from prefix.

参数:

prefix -- The prefix to match the signals.

返回:

The bundle itself.

set_regex(regex='')[源代码]

Set the bundle to bind from regex.

参数:

regex -- The regex to match the signals.

返回:

The bundle itself.

set_write_mode(write_mode: WriteMode)[源代码]

Set the write mode of the bundle. it will change the write mode of all signals in the bundle.

参数:

write_mode -- The write mode to set.

返回:

The bundle itself.

set_write_mode_as_fall()[源代码]

Set the write mode of the bundle to fall.

返回:

The bundle itself.

set_write_mode_as_imme()[源代码]

Set the write mode of the bundle to immediate.

返回:

The bundle itself.

set_write_mode_as_rise()[源代码]

Set the write mode of the bundle to rise.

返回:

The bundle itself.

signals = []
async step(ncycles=1)[源代码]

Wait for the clock for ncycles. Only works if the bundle has a connected signal.

参数:

ncycles -- The number of cycles to wait.

class toffee.BundleList(bundle, format: str, limit: int, rule=None)[源代码]

基类:object

assign(value, multilevel=True)[源代码]
classmethod from_bundlelist(old_bundle_list: BundleList)[源代码]
async toffee.Change(pin)[源代码]

Wait for the pin value to change.

参数:

pin -- The pin to be checked.

async toffee.ClockCycles(item, ncycles=1)[源代码]

Wait for the specified number of clock cycles.

参数:
  • item -- The item to be waited for. It can be a dut, a bundle, or an xpin.

  • ncycles -- The number of clock cycles to be waited for.

async toffee.Condition(item, func, delay=1)[源代码]

Wait for the specified condition to be true.

参数:
  • item -- The item to be waited for. It can be a dut, a bundle, or an xpin.

  • func -- The condition function to be checked, it should accept a single argument 'item' and return a boolean.

  • delay -- The minimum number of clock cycles to pass before checking.

class toffee.CovCondition[源代码]

基类:MObject

CovCondition class

class toffee.CovEq(value)[源代码]

基类:CovCondition

CovEq class, check if the target is equal to the value

class toffee.CovGe(value)[源代码]

基类:CovCondition

CovGe class, check if the target is greater or equal to the value

class toffee.CovGroup(name: str = '', disable_sample_when_point_hinted=True)[源代码]

基类:object

functional coverage group

add_cover_point(target: object, bins: dict | CovCondition | Callable[[object, object], bool], name: str = '', once=None, dynamic_bin=False)

Add a watch point to the group @param target: the object to be watched, need to have a value attribute. eg target.value is available @param bins: a dict of CovCondition objects, a single CovCondition object or a Callable object (its params is call(target) -> bool). @param name: the name of the point

add_watch_point(target: object, bins: dict | CovCondition | Callable[[object, object], bool], name: str = '', once=None, dynamic_bin=False)[源代码]

Add a watch point to the group @param target: the object to be watched, need to have a value attribute. eg target.value is available @param bins: a dict of CovCondition objects, a single CovCondition object or a Callable object (its params is call(target) -> bool). @param name: the name of the point

as_dict()[源代码]

return the group as a dict

clear()[源代码]

clear all points

cover_point(key: str)[源代码]

return the point with key @param key: the key of the point

cover_points()[源代码]

return the name list for all points

del_point(name: str)[源代码]

delete a point with name @param name: the name of the point

init()[源代码]
is_all_covered() bool[源代码]

check if all points are covered

is_point_covered(key: str) bool[源代码]

check if the point with key is covered @param key: the key of the point

mark_function(name: str, func: Callable | str | list, bin_name: str | list = '*', raise_error=True)[源代码]

Mark one or more functions for a point

Description:

By this reverse marking, record the relationship between checkpoints and target coverage functions to facilitate the management and analysis of checkpoints and test cases.

参数:
  • name (str) -- checkpoint name

  • func (Union[Callable,str, list]) -- function or function list to be marked

  • bin_name (Union[str, list]) -- bin name, support wildcard and regex. Default to '*' all bins.

返回:

this covgroup object

返回类型:

CovGroup

reset_point(name: str)[源代码]

reset a point with name @param name: the name of the point

resume_sample()[源代码]

resume sampling

sample()[源代码]

sample the group

sample_stoped()[源代码]

check if the group is stoped

stop_sample()[源代码]

stop sampling

class toffee.CovGt(value)[源代码]

基类:CovCondition

CovGt class, check if the target is greater than the value

class toffee.CovIn(value)[源代码]

基类:CovCondition

CovIn class, check if the target is in the value

class toffee.CovIsInRange(low, high)[源代码]

基类:CovCondition

CovIsInRange class, check if the target is in the range

class toffee.CovLe(value)[源代码]

基类:CovCondition

CovLe class, check if the target is less or equal to the value

class toffee.CovLt(value)[源代码]

基类:CovCondition

CovLt class, check if the target is less than the value

class toffee.CovNe(value)[源代码]

基类:CovCondition

CovNe class, check if the target is not equal to the value

class toffee.CovNotIn(value)[源代码]

基类:CovCondition

CovNotIn class, check if the target is not in the value

class toffee.Delayer(signal, delay)[源代码]

基类:MObject

A Delayer class is used to delay the signal value.

sample()[源代码]

Sample the signal value once and store it in the value list.

property value

Get the value of the signal after the delay.

class toffee.DriverPort(driver_path: str = '', *, agent_name: str = '', driver_name: str = '', maxsize: int = 4)[源代码]

基类:Port

The DriverPort is used to match driver_method in the agent and obtain call arguments.

get_path()[源代码]

Get the driver path.

class toffee.DummySignal[源代码]

基类:object

A dummy signal class that does nothing. It will return None when accessed, and do nothing when set.

class toffee.Env[源代码]

基类:MObject

Env is used to wrap the entire verification environment and provides reference model synchronization

all_agent_names()[源代码]

Yields all agent names in the env.

返回:

A generator that yields all agent names in the env.

attach(model)[源代码]

Attach a model to the env.

参数:

model -- The model to be attached.

返回:

The env itself.

unattach(model)[源代码]

Unattach a model from the env.

参数:

model -- The model to be unattached.

返回:

The env itself.

toffee.Eq

CovEq 的别名

class toffee.Event[源代码]

基类:Event

Change the function in the Event to meet the asynchronous requirements.

async wait()[源代码]

Block until the internal flag is true.

If the internal flag is true on entry, return True immediately. Otherwise, block until another coroutine calls set() to set the flag to true, then return True.

class toffee.Executor(exit='all')[源代码]

基类:MObject

The executor class is used to manage the execution of multiple coroutines.

get_results()[源代码]

Get the results of the coroutines.

返回:

A dictionary of results.

async wait_all()[源代码]

Wait for all the coroutines to complete. This function should be called after execute.

async toffee.FallingEdge(pin)[源代码]

Wait for the pin to have a falling edge. Specifically, the function returns when the pin has a value of non-0 in the previous cycle and a value of 0 in the current cycle.

参数:

pin -- The pin to be checked.

toffee.Ge

CovGe 的别名

toffee.Gt

CovGt 的别名

toffee.In

CovIn 的别名

toffee.IsInRange

CovIsInRange 的别名

class toffee.LFSR_64(seed: int = 1)[源代码]

基类:object

property rand
step()[源代码]
toffee.Le

CovLe 的别名

toffee.Lt

CovLt 的别名

class toffee.Model[源代码]

基类:Component

The Model is used to provide a reference model for the DUT.

clear_matched()[源代码]

Clear the matched status of all driver ports, monitor ports, driver hooks, and agent hooks.

collect_all()[源代码]

Collect all driver ports, monitor ports, driver hooks, and agent hooks.

ensure_all_matched()[源代码]

Ensure all driver ports, monitor ports, driver hooks, and agent hooks are matched.

get_driver_hook(driver_path: str, mark_matched: bool = False)[源代码]

Get the driver hook by name.

get_driver_port(drive_path: str, mark_matched: bool = False)[源代码]

Get the driver port by name.

get_monitor_hook(monitor_path: str, mark_matched: bool = False)[源代码]

Get the monitor hook by name.

get_monitor_port(monitor_path: str, mark_matched: bool = False)[源代码]

Get the monitor port by name.

is_attached()[源代码]

Check if the model is attached to an agent.

async main()[源代码]
class toffee.MonitorPort(monitor_path: str = '', *, agent_name: str = '', monitor_name: str = '', maxsize: int = 4)[源代码]

基类:Port

The MonitorPort is used to match the monitor_method in the agent, and obtain the results.

get_path()[源代码]

Get the monitor path.

toffee.Ne

CovNe 的别名

toffee.NotIn

CovNotIn 的别名

class toffee.PLRU(ways_num)[源代码]

基类:object

Pseudo Least Recently Used replacement policy

get()[源代码]
update(way)[源代码]
class toffee.Queue[源代码]

基类:Queue

Change the function in the Queue to meet the asynchronous requirements.

async get()[源代码]

Remove and return an item from the queue.

If queue is empty, wait until an item is available.

async put(item)[源代码]

Put an item into the queue.

Put an item into the queue. If the queue is full, wait until a free slot is available before adding item.

async toffee.RisingEdge(pin)[源代码]

Wait for the pin to have a rising edge. Specifically, the function returns when the pin has a value of 0 in the previous cycle and a value of non-0 in the current cycle.

参数:

pin -- The pin to be checked.

class toffee.Signal[源代码]

基类:UnconnectedSignal

class toffee.SignalList(format: str, limit: int, rule=None)[源代码]

基类:object

assign(value)[源代码]
bind_signal(bundle, signal_name: str, signal, info_bundle_name, info_dut_name)[源代码]
classmethod from_signallist(old_signal_list: SignalList)[源代码]
toffee.Signals(num: int)[源代码]
class toffee.TwoBitsCounter(init_value=2)[源代码]

基类:object

Two bit saturation counter 00 <-> 01 <-> 10 <-> 11

00: Strongly not taken 01: Weakly not taken 10: Weakly taken 11: Strongly taken

get_prediction()[源代码]
update(taken)[源代码]
async toffee.Value(pin, value: int, delay=1)[源代码]

Wait for the pin to have the specified value.

参数:
  • pin -- The pin to be checked.

  • value -- The value to be checked.

  • delay -- The minimum number of clock cycles to pass before checking.

class toffee.WriteMode(*values)[源代码]

基类:Enum

The write mode of a bundle.

Fall = 2
Imme = 0
Rise = 1
toffee.agent_hook(agent_name: str = '', *, agents: list = [], methods: list = [], priority: int = 99, sche_order: str = 'model_first')[源代码]

Decorator for agent hook.

参数:
  • agent_name -- The name of the agent to be hooked. If it is empty, the name of the function will be used.

  • agents -- The list of agents to be hooked.

  • methods -- The list of paths of the methods to be hooked.

  • priority -- The priority of the agent hook which should be an integer between 0 and 99. The smaller the number, the higher the priority. It will determine the order of calls within the same cycle. The default priority of agent hook is 99.

  • sche_order -- The order in which the hook is called relative to the dut. If it is "model_first", it will be called before the corresponding agent_method runs, and vice versa after it runs.

toffee.create_task(coro, *, name=None, context=None)[源代码]

Schedule the execution of a coroutine object in a spawn task.

Return a Task object.

toffee.critical(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'CRITICAL'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.critical("Houston, we have a %s", "major disaster", exc_info=True)

toffee.driver_hook(driver_path: str = '', *, agent_name: str = '', driver_name: str = '', priority=99, sche_order='model_first')[源代码]

Decorator for driver hook.

参数:
  • driver_path -- The path of the driver.

  • agent_name -- The name of the agent to be hooked.

  • driver_name -- The name of the driver to be hooked.

  • priority -- The priority of the driver hook which should be an integer between 0 and 99. The smaller the number, the higher the priority. It will determine the order of calls within the same cycle. The default priority of driver hook is 99.

  • sche_order -- The order in which the hook is called relative to the dut. If it is "model_first", it will be called before the corresponding driver_method runs, and vice versa after it runs.

toffee.driver_method()[源代码]

Decorator for driver method.

返回:

The decorator for driver method.

toffee.error(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'ERROR'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.error("Houston, we have a %s", "major problem", exc_info=True)

toffee.exception(msg, *args, exc_info=True, **kwargs)[源代码]

Convenience method for logging an ERROR with exception information.

async toffee.gather(*coros)[源代码]

Gather multiple coroutines and run them at the same time.

toffee.get_logger() Logger[源代码]

Returns the global logger for Toffee

toffee.info(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'INFO'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.info("Houston, we have a %s", "notable problem", exc_info=True)

toffee.log(level, msg, *args, **kwargs)[源代码]

Log 'msg % args' with the integer severity 'level'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.log(level, "We have a %s", "mysterious problem", exc_info=True)

async toffee.main_coro(test, env_handle=None)[源代码]

Wrapper for a coroutine to meet the rules for toffee.

参数:
  • test -- The test to be run, it can be a coroutine or a function.

  • env_handle -- A handle to create the environment. make sure the env is created before the test starts. if the env_handle is provided, the test will be called with the env_handle's return value. when the env_handle is set, make sure the test is a function and has the same number of arguments as the env_handle's return.

返回:

The result of the coroutine (or function).

toffee.monitor_hook(monitor_path: str = '', *, agent_name: str = '', monitor_name: str = '', priority: int = 0)[源代码]

Decorator for monitor hook.

参数:
  • monitor_path -- The path of the monitor.

  • agent_name -- The name of the agent to be hooked.

  • monitor_name -- The name of the monitor to be hooked.

  • priority -- The priority of the monitor hook which should be an integer between 0 and 99. The smaller the number, the higher the priority. It will use the same priority as driver_hook, determining the order of calls within the same cycle. The default priority of monitor hook is -1, which means the monitor hook will be executed before driver hook.

toffee.monitor_method()[源代码]

Decorator for monitor method.

返回:

The decorator for monitor method.

toffee.run(test, env_handle=None, dut=None)[源代码]

Start the asynchronous event loop and run the coroutine.

参数:
  • test -- The test to be run, it can be a coroutine or a function.

  • env_handle -- A handle to create the environment. make sure the env is created before the test starts. if the env_handle is provided, the test will be called with the env_handle's return value. when the env_handle is set, make sure the test is a function and has the same number of arguments as the env_handle's return.

  • dut -- The DUT object.

返回:

The result of the coroutine (or function).

toffee.setup_logging(log_level=30, format='%(name)s_%(levelname)s @%(filename)s:%(lineno)d%(log_id)s:\t%(message)s', console_display=True, log_file=None)[源代码]

Setup the logging configuration for Toffee

参数:
  • log_level -- The log level for the logger

  • format -- The format of the log message

  • console_display -- Whether to display logs on the console

  • log_file -- The log file name to write logs, if None, logs are not written to a file

async toffee.sleep(delay: float)[源代码]

Change the implementation of the sleep function to meet the asynchronous requirements.

toffee.start_clock(dut)[源代码]

Start a clock loop on a DUT.

toffee.summary()[源代码]

Display a summary of the logs

toffee.warning(msg, *args, **kwargs)[源代码]

Log 'msg % args' with severity 'WARNING'.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.warning("Houston, we have a %s", "bit of a problem", exc_info=True)