Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ out/**
!out/.gitkeep
build/**
!build/.gitkeep
.DS_Store
134 changes: 134 additions & 0 deletions test/zbs_tb.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
`timescale 1ns/1ns
`include "test/utils.svh"

module zbs_tb;

logic [31:0] reg1;
logic [31:0] reg2;
logic [2:0] inst;
logic [31:0] out;

logic [31:0] expected;

zbs uut (
.reg1(reg1),

Check warning on line 14 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow each comma with a single space (comma-leading format).
.reg2(reg2),

Check warning on line 15 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow each comma with a single space (comma-leading format).
.inst(inst),

Check warning on line 16 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow each comma with a single space (comma-leading format).
.out(out)
);

initial begin

// -------- bclr test --------
reg1 = 32'b1010;
reg2 = 32'd1; // clear bit 1
inst = 3'b000;
#10;

expected = reg1 & ~(32'h1 << reg2[4:0]);

assert(out == expected)

Check warning on line 30 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow keyword with exactly 1 space.
else $fatal("bclr failed: expected %b got %b", expected, out);


// -------- bset test --------
reg1 = 32'b1110;
reg2 = 32'd0; // set bit 0
inst = 3'b001;
#10;

expected = reg1 | (32'h1 << reg2[4:0]);

assert(out == expected)

Check warning on line 42 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow keyword with exactly 1 space.
else $fatal("bset failed: expected %b got %b", expected, out);


// -------- binv test --------
reg1 = 32'b1010;
reg2 = 32'd1;
inst = 3'b010;
#10;

expected = reg1 ^ (32'h1 << reg2[4:0]);

assert(out == expected)

Check warning on line 54 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow keyword with exactly 1 space.
else $fatal("binv failed: expected %b got %b", expected, out);


// -------- bext test --------
reg1 = 32'b1010;
reg2 = 32'd3;
inst = 3'b011;
#10;

expected = (reg1 >> reg2[4:0]) & 32'h1;

assert(out == expected)

Check warning on line 66 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow keyword with exactly 1 space.
else $fatal("bext failed: expected %b got %b", expected, out);

// -------- Edge Cases ---------

// Bit 0 boundary
reg1 = 32'hFFFFFFFF;
reg2 = 32'd0;
inst = 3'b000; // bclr
#10;

expected = reg1 & ~(32'h1 << reg2[4:0]);

assert(out == expected)

Check warning on line 79 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow keyword with exactly 1 space.
else $fatal("corner case bit0 failed");


// Bit 31 boundary
reg1 = 32'hFFFFFFFF;
reg2 = 32'd31;
inst = 3'b000; // bclr
#10;

expected = reg1 & ~(32'h1 << reg2[4:0]);

assert(out == expected)

Check warning on line 91 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Follow keyword with exactly 1 space.
else $fatal("corner case bit31 failed");


// ----------- Randomized Testing (Experimental) -----------


Check warning on line 97 in test/zbs_tb.sv

View workflow job for this annotation

GitHub Actions / svlint

Remove trailing whitespace.
repeat (1000) begin

reg1 = $urandom;
reg2 = $urandom % 32;
inst = $urandom % 4;

#1;

case(inst)

3'b000: expected = reg1 & ~(32'h1 << reg2[4:0]);

3'b001: expected = reg1 | (32'h1 << reg2[4:0]);

3'b010: expected = reg1 ^ (32'h1 << reg2[4:0]);

3'b011: expected = (reg1 >> reg2[4:0]) & 32'h1;

default: expected = 32'd0;

endcase

assert(out == expected)
else $fatal("random test failed: inst=%0d reg1=%h reg2=%d expected=%h got=%h",
inst, reg1, reg2, expected, out);

end

$display("All tests passed!");

$finish;

end

`SETUP_VCD_DUMP(zbs_tb)

endmodule
Loading