EDA Playground lets you type in and run HDL code (using a selection of free and commercial simulators and synthesizers).
It's great for learning HDLs, it's great for testing out unfamiliar things and it's great for sharing code.
You can start typing straight away. But to run your code, you'll need to sign or log in. Logging in with a Google account gives you access to all non-commercial simulators and some commercial simulators:
To run commercial simulators, you need to register and log in with a username and password. Registration is free, and only pre-approved email's will have access to the commercial simulators.
203
/*
------------------------
SVUnit DEMO INSTRUCTIONS
------------------------
Time to learn the basics of unit testing with SVUnit!
Here's a simple set of unit tests for an interface called
svunitOnSwitch. The purpose of the design is to offer a few
utility functions as well as to operate an on/off output.
The API of the svunitOnSwitch is as follows:
output logic on;
function logic true();
function logic false();
function int return43();
turn_on();
turn_off();
The svunitOnSwitch is defined over there --------------->
The SVTESTs below are the acceptance unit tests that verify
the functionality of the svunitOnSwitch. If you push run (in
the top left corner) you'll see all the tests fail b/c none
of the svunitOnSwitch functionality is implemented. Your
job is to build a complete svunitOnSwitch, 1 requirement at
a time, by:
* examining the requirement defined in the unit test
(HINT: a unit test is marked by the `SVTEST macro)
* implementng the corresponding code in the svunitOnSwitch
(HINT: watch for the "no implementation yet" comment)
* running the test suite to make sure your implementation
satisfies the unit test
When you've gone through all the tests and your entire test
suite passes, you're done! You've verified the
svunitOnSwitch and learned the basics of SVUnit!
The unit tests start a few lines down so scroll down to get
started.
Ready... set... go!
-----------------------------------------------------------
-----------------------------------------------------------
You can do a lot more than test a simple svunitOnSwith with
SVUnit. When you're ready to test your own design and
testbench IP visit:
www.AgileSoC.com/svunit
-----------------------------------------------------------
-----------------------------------------------------------
*/
`include "svunit_defines.svh"
import svunit_pkg::*;
module svunitDemo_unit_test;
string name = "svunitDemo_ut";
`SVUNIT_TESTS_BEGIN
//------------------------------
// test: true_test
// the true() function should
// return 1
//------------------------------
`SVTEST(true_returns_1)
`FAIL_UNLESS(uut.true() === 1);
`SVTEST_END
//------------------------------
// test: false_test
// the false() function should
// return 0
//------------------------------
`SVTEST(false_returns_0)
`FAIL_UNLESS(uut.false() === 0);
`SVTEST_END
//-----------------------------------
// test: return43
// The function return43() returns
// a value. this test should fail
// if that doesn't happen.
//-----------------------------------
`SVTEST(return43)
`FAIL_UNLESS(uut.return43() === 43);
`SVTEST_END
//---------------------------------
// test: turn_on
// our uut has an output pin
// called 'on' that we can
// assert via turn_on()
//---------------------------------
`SVTEST(turn_on)
uut.turn_on();
`FAIL_UNLESS(uut.on === 1);
`SVTEST_END
//---------------------------------
// test: turn_off
// we can turn 'on' off using
// turn_off() method
//---------------------------------
`SVTEST(turn_off)
uut.turn_off();
`FAIL_UNLESS(uut.on === 0);
`SVTEST_END
/*
----------------------------------------
----------------------------------------
For more SVUnit, Remember to visit:
www.AgileSoC.com/svunit
And try the other SVUnit examples at:
www.edaplayground.com
----------------------------------------
----------------------------------------
*/
`SVUNIT_TESTS_END
svunit_testcase svunit_ut;
//===================================
// This is the UUT that we're
// running the Unit Tests on
//===================================
svunitOnSwitch uut();
//===================================
// Build. Runs once
//===================================
function void build();
svunit_ut = new(name);
endfunction
//===================================
// Setup for running the Unit Tests
// Runs before every SVTEST.
//===================================
task setup();
svunit_ut.setup();
/* Place Setup Code Here */
endtask
//===================================
// Here we deconstruct anything we
// need after running the Unit Tests
// Runs after every SVTEST.
//===================================
task teardown();
svunit_ut.teardown();
/* Place Teardown Code Here */
endtask
endmodule
/*
svunitOnSwitch
The API is defined but that's pretty much it! Use
the unit tests to help fill the proper implementation.
*/
interface svunitOnSwitch (
output logic on
);
initial on = 'hx;
function logic true();
// no implementation yet
endfunction
function logic false();
// no implementation yet
endfunction
function int return43();
// no implementation yet
endfunction
function void turn_on();
// no implementation yet
endfunction
function void turn_off();
// no implementation yet
endfunction
endinterface
Your account is not validated. If you wish to use commercial simulators, you need a validated account.
If you have already registered (or have recently changed your email address), but have not clicked on the link in the email we sent you, please do so. If you cannot find the email, please check your spam/junk folder. Or click here to resend the email.
If you have not already registered for a full account, you can do so by clicking below. You will then need to provide us with some identification information. You may wish to save your code first.
Creating, deleting, and renaming files is not supported during Collaboration. To encourage development of these features for Collaboration, tweet to @EDAPlayground
This playground may have been modified. Please save or copy before starting collaboration.
Your exercise has been submitted.