Giter Site home page Giter Site logo

amanda-matthes / testbench_generator_for_systemverilog_modules Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 13 KB

Takes a SystemVerilog module and creates a skeleton for a testbench. It parses the modport list and creates an instance in the testbench as well as some other useful stuff.

License: MIT License

Python 97.18% SystemVerilog 2.82%

testbench_generator_for_systemverilog_modules's Introduction

Testbench Generator for SystemVerilog modules

This python script takes in the SystemVerilog code for a module and creates a testbench from the module portlist. The testbench contains a clock and all the regs and wires that are necessary to connect the testbench to the module.

It can:

  • Ignore comments (both // and /**/)
  • Deal with arrays (e.g. wire [63:0] data)

It cannot (yet):

  • Deal with types other than reg and wire
  • Deal with parameters in the module declaration

Example:

The file


/*
This is an 8-bit counter
*/
module counter (
    input wire clk, res_n,
    output reg [7:0] cnt_out
    );                                   
    
    [...]
    
endmodule

will produce this testbench:


module counter_tb;

reg clk; 
reg res_n; 
wire [7:0] cnt_out; 
parameter PERIOD = 20;
clock #(.PERIOD(PERIOD)) clk_I (clk);

counter counter_I (
.clk(clk),
.res_n(res_n),
.cnt_out(cnt_out));

task initialise; 
    begin
        res_n <= 1;
        #PERIOD
        reset;
    end
endtask

task reset;
    begin
        @(negedge clk) res_n <= 0;
        #PERIOD
        @(negedge clk) res_n <= 1;
    end
endtask

endmodule

Notice how the testbench contains the following things:

  1. Instance of the module under test
  2. The task "reset" which pulls the reset for one period
  3. The task "initialise" which initialises all regs in the testbench with 0, exept for active low signals whose names end in "_n" which are initialised with 1

It also creates a clock instance which might not be useful for others, especially if it is not called "clock" or your standard name for the clock signal is not "clk". I'll try to make this more useful for other users at some point. But right now it's more for myself. Feel free to copy and adjust for your needs :)

testbench_generator_for_systemverilog_modules's People

Contributors

amanda-matthes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.