Base on Google Test, we build a template framework for unit tests systemc model.
About some information Google Test, you can refer here
By using this framework, you can do unit tests for your model and ensure quality for your product.
After download, follow the steps below.
Step 1: Copy your source code to sample folder
Step 2: Open VS solution FreeSourceC_DevEnv_SystemC.sln
Step 3: add the code (from sample folder ) to Models in FreeSource_Bench
(ex: or_gate.cpp and or_gate.h)
Step 4: add include Directory for your source code
FreeSource_Bench property -> VC++ Directories -> Include Directories
Step 5: Modify UnitTest.cpp
use macro TEST(test_case_name, test_name) to make your test case.
Note: OR_GATE model is an example model. You can delete it if you want.
We use OR_GATE for example model.
It has 3 ports :
A: input port
B: input port
Q: output port ( = A| B)
In a simple example, we make 2 test cases to do unit tests for OR_GATE.
- Check initialize for the output port. We expected the initialized value is false
1 2 3 4 5 |
TEST(OR_GATE_Check,check_out_port_init) { EXPECT_EQ(Q_sig.read(), false); sc_start(10, SC_PS); } |
- Check operation ( output value is changed when the input value is changed )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
TEST(OR_GATE_Check, check_output_when_input_change) { A_sig.write(true); sc_start(10, SC_PS); B_sig.write(false); sc_start(10, SC_PS); EXPECT_EQ(Q_sig.read(), true); sc_start(10, SC_PS); A_sig.write(true); sc_start(10, SC_PS); B_sig.write(true); sc_start(10, SC_PS); EXPECT_EQ(Q_sig.read(), true); sc_start(10, SC_PS); A_sig.write(false); sc_start(10, SC_PS); B_sig.write(false); sc_start(10, SC_PS); EXPECT_EQ(Q_sig.read(), false); sc_start(10, SC_PS); A_sig.write(false); sc_start(10, SC_PS); B_sig.write(true); sc_start(10, SC_PS); EXPECT_EQ(Q_sig.read(), true); sc_start(10, SC_PS); } |
Download Project (VS2015):
Google Drive 1