Skip to main content

a framework for building hardware verification platform using software method

Project description

Toffee

PyPI version

English Version | 中文版本

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.8.0+
  • 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.3.1.tar.gz (35.9 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.3.1-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytoffee-0.3.1.tar.gz
Algorithm Hash digest
SHA256 47dbaa9813847a935a731315c0fc82e465a43a9ee12c2a136fd30e8fd4e4e8e6
MD5 7e9bacd44b8341372f5f480fc429b424
BLAKE2b-256 9a4ff6b9e6924754a3c5d2928c3ab09a78c3180563b73a964113866f6e6bcfb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytoffee-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 43.5 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79ca42f99172f88719c9f25336ea9c56c5e28049849a973b726e07c7b880d4a9
MD5 4b309c63cdab765a6f524321898e6eb0
BLAKE2b-256 9f3618eb396fef60f9b1a61ef999498ee5fd124b31c0b621bbbc14274ba9e580

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