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.0.tar.gz (35.8 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.0-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytoffee-0.3.0.tar.gz
  • Upload date:
  • Size: 35.8 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.0.tar.gz
Algorithm Hash digest
SHA256 398dd1a902bd9883c96918b66740253c049b2a937067e9754f18f2b79b87c03a
MD5 2eec20723a820bbd6563c3e3d85ccb08
BLAKE2b-256 b7ab850e710bf496a73c28958157b70a435a3f3bc4c4b382e808c5fbf00c1d1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytoffee-0.3.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5910a08b9cc044b8f6f0cdf96199d788a31978126853836711be213ab7594d9d
MD5 12abcc372ca764d782a92bed15593472
BLAKE2b-256 d477730fa57991635fedb930a503189181b108ab7dc5c3d52d189db4afa8fd7c

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