iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💎

Testbench Description in Veryl

に公開
2025/11/10
2件

Introduction

Veryl is a new hardware description language currently under development.
When writing tests in a hardware description language, testbenches are typically created; however, at present, Veryl does not support testbench descriptions and relies on external testbench tools such as SystemVerilog or cocotb (Python).
But as the development of Veryl's native simulator progresses, it will become necessary to consider how to describe testbenches in Veryl. This article summarizes the current ideas for testbench description in Veryl.

Introducing Testbench-Specific Syntax

The first idea that comes to mind is to introduce dedicated syntax for testbenches in Veryl.
Not only in hardware description languages but also in programming languages, it is common to write implementation and tests in the same language, so this approach seems natural.

For example, in Veryl's case, by introducing constructs like clock definitions and clock waits, simple testbenches could be written as follows:

#[clock(10, 10)] // Clock waveform definition
var clk :clock;

initial {
    a = 0;
    @clk; // Wait for clock
    a = 1;
    @clk;
    $assert(b == 1);
}

This might work in the short term, but as various tests are written, demands such as:

  • Wanting to write reusable verification components
  • Wanting to write more complex assertions

are likely to arise. Supporting these would likely lead to a language specification as bloated as SystemVerilog's.
One of Veryl's concepts is to focus on synthesizable descriptions rather than supporting all the bloated features of SystemVerilog, so going in this direction is undesirable.

Writing Testbenches in a Programming Language

Do we really need to write testbenches in a hardware description language? To write a testbench, we only need a way to set signal values at each clock cycle or read values; it might be easier to write in a general-purpose programming language than in a constrained hardware description language.
Existing examples include cocotb, where testbenches are written in Python, and earlier Verilator required writing in C++.

The advantage of writing testbenches in a programming language is not only the availability of rich language features but also the ability to leverage the libraries provided by that programming language.
For instance, writing a testbench in a hardware description language that reads jpeg or png images and inputs them as video signals would be extremely difficult, but with a general-purpose programming language, existing image I/O libraries can be easily utilized.

However, choosing to write testbenches in a programming language raises several issues. First, users writing Veryl would need to learn not only Veryl but also some programming language for testbench writing. Recently, the number of engineers who can handle both hardware description languages and programming languages has been increasing, but it seems that users who specialize in hardware description languages are still not negligible.

Moreover, saying "Veryl provides a C API, so please write tests in any programming language you like" has the advantage of allowing each user to choose their preferred language, but it would result in the absence of a standard way to write tests in Veryl. Looking at others' testbenches, all written in different languages, would be incomprehensible.
Furthermore, if the programming languages for writing testbenches vary, the required execution environments and compilers also vary, raising the barrier to running tests from someone else's project.

It would be ideal to select one programming language and have everyone write in it, but preferences vary greatly, so this seems like an impractical solution.

Introducing Verification Components as Plugins

As a method to define standard test descriptions in Veryl while allowing complex components to be written in a flexible programming language, introducing verification components as plugins can be considered.
For example, if there is a verification component clk_gen that generates a clock, the testbench shown earlier could be written like this:

inst u_clk: clk_gen (
    clk,
);

initial {
    a = 0;
    u_clk.wait();
    a = 1;
    u_clk.wait();
    $assert(b == 1);
}

The verification components themselves are written in a programming language, and the Veryl simulator loads and executes them as plugins. By adopting such a structure, without extending the language itself, we can introduce:

  • Transaction-level components such as AXI
  • Constrained random sequences
  • Complex assertions

These could be introduced as plugins. If the Veryl simulator provides an API to obtain coverage information, advanced verification features like fuzzing might also be realized.

Furthermore, with this approach, users who only need to use existing verification components can complete their tests entirely in Veryl. If they find the existing components insufficient, they can learn a programming language to write original components, or they could delegate that part to experienced software engineers.

Conclusion

I have summarized my current thoughts on testbench description in Veryl. At this point, the third idea, "introducing verification components as plugins," seems to offer the best user experience for Veryl users.
If any Veryl users have opinions or feedback, please feel free to leave a comment.

Discussion

石谷太一石谷太一

テストシナリオ実装部も、プラグイン実装部も、Verilog の fork/join の様に、簡単にスレッドを作れる仕組みが必要かと思います。

dalancedalance

確かにそうですね。コードブロックを関数引数に取れればforkもプラグイン実装にできそうですが、さすがに書きにくいと思うのでfork/joinくらいの構文拡張は許容すべきかもしれません。