Skip to main content

a framework for building hardware verification platform using software method

Project description

Toffee

PyPI version

English Version | 中文版本

mlvp has been renamed to Toffee

Toffee is a Python-based hardware verification framework designed to help users build hardware verification environments more conveniently and systematically using Python. It leverages the multi-language conversion tool picker, which converts Verilog code of hardware designs into Python Packages, enabling users to drive and verify hardware designs in Python.

Toffee incorporates elements of UVM methodology to ensure the verification environment's standardization and reusability. Moreover, Toffee redesigns the verification environment setup to better align with software developers' workflows, making it easier for software developers to engage in hardware verification tasks.

For more information about Toffee, please refer to the Toffee Documentation.

Installation

Toffee requires the following dependencies:

  • Python 3.6.8+
  • Picker 0.9.0+

Once these dependencies are installed, you can install Toffee via pip:

pip install pytoffee

Or install the latest version of Toffee with the following command:

pip install pytoffee@git+https://github.com/XS-MLVP/toffee@master

For a local installation:

git clone https://github.com/XS-MLVP/toffee.git
cd toffee
pip install .

Usage

We use a simple adder example located in the example/adder directory to demonstrate how to use Toffee.

The design of the adder is as follows:

module Adder #(
    parameter WIDTH = 64
) (
    input  [WIDTH-1:0] io_a,
    input  [WIDTH-1:0] io_b,
    input              io_cin,
    output [WIDTH-1:0] io_sum,
    output             io_cout
);

assign {io_cout, io_sum}  = io_a + io_b + io_cin;

endmodule

Before building the verification environment using Toffee, you need to use picker to convert the design into a Python Package. After installing the dependencies, run the following command in the example/adder directory to complete the conversion:

make dut

To verify the functionality of the adder, you need to set up the verification environment using Toffee.

First, create a driver method for the adder interface. Here, Bundle describes the interface to be driven, while Agent is used to write the driving method for this interface. The setup is shown below:

class AdderBundle(Bundle):
    a, b, cin, sum, cout = Signals(5)


class AdderAgent(Agent):
    @driver_method()
    async def exec_add(self, a, b, cin):
        self.bundle.a.value = a
        self.bundle.b.value = b
        self.bundle.cin.value = cin
        await self.bundle.step()
        return self.bundle.sum.value, self.bundle.cout.value

To verify the functionality of the adder, define a Model class to capture interaction information with the DUT and perform comparisons.

class AdderModel(Model):
    @driver_hook(agent_name="add_agent")
    def exec_add(self, a, b, cin):
        result = a + b + cin
        sum = result & ((1 << 64) - 1)
        cout = result >> 64
        return sum, cout

Next, create a top-level test environment and associate it with the Model, as shown below:

class AdderEnv(Env):
    def __init__(self, adder_bundle):
        super().__init__()
        self.add_agent = AdderAgent(adder_bundle)

        self.attach(AdderModel())

At this point, the verification environment is complete. The methods in the Model will be automatically invoked and compared with the output of the adder.

Afterward, write test cases to verify the functionality of the adder. With toffee-test, test cases can be written as follows:

@toffee_test.testcase
async def test_random(adder_env):
    for _ in range(1000):
        a = random.randint(0, 2**64 - 1)
        b = random.randint(0, 2**64 - 1)
        cin = random.randint(0, 1)
        await adder_env.add_agent.exec_add(a, b, cin)

@toffee_test.testcase
async def test_boundary(adder_env):
    for cin in [0, 1]:
        for a in [0, 2**64 - 1]:
            for b in [0, 2**64 - 1]:
                await adder_env.add_agent.exec_add(a, b, cin)

Run the example in the example/adder directory with the following command:

make run

A report will be automatically generated in the reports directory upon completion.

For more detailed usage, please refer to the Toffee Documentation.

Additional Information

This project is part of UnityChip's open verification initiative. For more information, please visit open-verify.cc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytoffee-0.2.3.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytoffee-0.2.3-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file pytoffee-0.2.3.tar.gz.

File metadata

  • Download URL: pytoffee-0.2.3.tar.gz
  • Upload date:
  • Size: 33.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for pytoffee-0.2.3.tar.gz
Algorithm Hash digest
SHA256 98bec94112989794bedb83f74278311080550bb1398632f56e2d5ba415472faa
MD5 ee8edf955155b7d21a1f22a6fc786d4f
BLAKE2b-256 64cc1b6cdade3ba576d67b8fd1a7f4dce7e80087f71ef04ace3bbec2bf8e1682

See more details on using hashes here.

File details

Details for the file pytoffee-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pytoffee-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 41.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for pytoffee-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 867609d80aca849a880fd48299f3a77573d09bf50b7109a2f63ee1f7a7915f1a
MD5 da6c8157f959b865acc1467b855d6148
BLAKE2b-256 949b705ef8a27c4e23d3c28ba8917be2112ba40496afb8a385f5a552724e4d7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page