mirror of
https://github.com/MPSU/APS.git
synced 2025-09-16 01:30:10 +00:00
Обновление тестбенчей
This commit is contained in:
@@ -11,33 +11,36 @@ See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
|
||||
|
||||
module lab_01_tb_fulladder();
|
||||
|
||||
logic tb_a_i;
|
||||
logic tb_b_i;
|
||||
logic tb_carry_i;
|
||||
logic tb_carry_o;
|
||||
logic tb_sum_o;
|
||||
logic [2:0] test_case;
|
||||
logic tb_a_i;
|
||||
logic tb_b_i;
|
||||
logic tb_carry_i;
|
||||
logic tb_carry_o;
|
||||
logic tb_sum_o;
|
||||
logic [2:0] test_case;
|
||||
|
||||
fulladder DUT (
|
||||
.a_i(tb_a_i),
|
||||
.b_i(tb_b_i),
|
||||
.sum_o(tb_sum_o),
|
||||
.carry_i(tb_carry_i),
|
||||
.carry_o(tb_carry_o)
|
||||
);
|
||||
fulladder DUT (
|
||||
.a_i(tb_a_i),
|
||||
.b_i(tb_b_i),
|
||||
.sum_o(tb_sum_o),
|
||||
.carry_i(tb_carry_i),
|
||||
.carry_o(tb_carry_o)
|
||||
);
|
||||
|
||||
assign {tb_a_i, tb_b_i, tb_carry_i} = test_case;
|
||||
assign {tb_a_i, tb_b_i, tb_carry_i} = test_case;
|
||||
|
||||
initial begin
|
||||
$display("\nTest has been started\n");
|
||||
initial begin
|
||||
$display("\nTest has been started\n");
|
||||
#5ns;
|
||||
test_case = 3'd0;
|
||||
repeat(8) begin
|
||||
#5ns;
|
||||
test_case = 3'd0;
|
||||
repeat(8) begin
|
||||
#5ns;
|
||||
test_case++;
|
||||
end
|
||||
$display("\nTest has been finished. Check results at waveform window.\n");
|
||||
$finish();
|
||||
test_case++;
|
||||
end
|
||||
$display("\nTest has been finished. Check results at waveform window.\n");
|
||||
$finish();
|
||||
#5;
|
||||
$display("You're trying to run simulation that has finished. Aborting simulation.")
|
||||
$fatal();
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
@@ -11,72 +11,75 @@ See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
|
||||
|
||||
module lab_01_tb_fulladder32();
|
||||
|
||||
logic [31:0] tb_a_i;
|
||||
logic [31:0] tb_b_i;
|
||||
logic tb_carry_i;
|
||||
logic tb_carry_o;
|
||||
logic [31:0] tb_sum_o;
|
||||
logic [31:0] tb_a_i;
|
||||
logic [31:0] tb_b_i;
|
||||
logic tb_carry_i;
|
||||
logic tb_carry_o;
|
||||
logic [31:0] tb_sum_o;
|
||||
|
||||
logic clk = 0;
|
||||
always #5ns clk = ~clk;
|
||||
logic clk = 0;
|
||||
always #5ns clk = ~clk;
|
||||
|
||||
int err_cnt = 0;
|
||||
int err_cnt = 0;
|
||||
|
||||
fulladder32 DUT (
|
||||
.a_i(tb_a_i),
|
||||
.b_i(tb_b_i),
|
||||
.sum_o(tb_sum_o),
|
||||
.carry_i(tb_carry_i),
|
||||
.carry_o(tb_carry_o)
|
||||
);
|
||||
fulladder32 DUT (
|
||||
.a_i(tb_a_i),
|
||||
.b_i(tb_b_i),
|
||||
.sum_o(tb_sum_o),
|
||||
.carry_i(tb_carry_i),
|
||||
.carry_o(tb_carry_o)
|
||||
);
|
||||
|
||||
initial begin
|
||||
$display("Test has been started");
|
||||
sequential_add_test();
|
||||
random_test();
|
||||
$display("\nTest has been finished\nNumber of errors: %d\n", err_cnt);
|
||||
$finish();
|
||||
end
|
||||
initial begin
|
||||
$display("Test has been started");
|
||||
sequential_add_test();
|
||||
random_test();
|
||||
$display("\nTest has been finished\nNumber of errors: %d\n", err_cnt);
|
||||
$finish();
|
||||
#5;
|
||||
$display("You're trying to run simulation that has finished. Aborting simulation.")
|
||||
$fatal();
|
||||
end
|
||||
|
||||
task sequential_add_test();
|
||||
@(posedge clk);
|
||||
tb_a_i = 0;
|
||||
tb_b_i = 0;
|
||||
tb_carry_i = 0;
|
||||
@(posedge clk);
|
||||
for(int i = 0; i < 16; i++) begin
|
||||
tb_a_i += 256;
|
||||
for(int j = 0; j < 16; j++) begin
|
||||
tb_b_i += 256;
|
||||
tb_carry_i = ~tb_carry_i;
|
||||
@(posedge clk);
|
||||
end
|
||||
end
|
||||
endtask
|
||||
|
||||
task random_test();
|
||||
repeat(1e4) begin
|
||||
tb_a_i = $urandom();
|
||||
tb_b_i = $urandom();
|
||||
tb_carry_i = $urandom_range(1);
|
||||
task sequential_add_test();
|
||||
@(posedge clk);
|
||||
tb_a_i = 0;
|
||||
tb_b_i = 0;
|
||||
tb_carry_i = 0;
|
||||
@(posedge clk);
|
||||
for(int i = 0; i < 16; i++) begin
|
||||
tb_a_i += 256;
|
||||
for(int j = 0; j < 16; j++) begin
|
||||
tb_b_i += 256;
|
||||
tb_carry_i = ~tb_carry_i;
|
||||
@(posedge clk);
|
||||
end
|
||||
endtask
|
||||
|
||||
logic [32:0] reference;
|
||||
assign reference = {1'b0, tb_a_i} + {1'b0, tb_b_i} + tb_carry_i;
|
||||
|
||||
sum_check: assert property (
|
||||
@(negedge clk)
|
||||
reference === {tb_carry_o, tb_sum_o}
|
||||
)
|
||||
else begin
|
||||
err_cnt++;
|
||||
$error("\noperands : a_i = 0x%08h, b_i = 0x%08h, carry_i = %b\nyour res : sum = 0x%08h, carry_o = %b\nreference: sum = 0x%08h, carry_o = %b",
|
||||
tb_a_i, tb_b_i, tb_carry_i, tb_sum_o, tb_carry_o, reference[31:0], reference [32]);
|
||||
if(err_cnt == 10) begin
|
||||
$display("\nTest has been stopped after 10 errors");
|
||||
$stop();
|
||||
end
|
||||
end
|
||||
endtask
|
||||
|
||||
task random_test();
|
||||
repeat(1e4) begin
|
||||
tb_a_i = $urandom();
|
||||
tb_b_i = $urandom();
|
||||
tb_carry_i = $urandom_range(1);
|
||||
@(posedge clk);
|
||||
end
|
||||
endtask
|
||||
|
||||
logic [32:0] reference;
|
||||
assign reference = {1'b0, tb_a_i} + {1'b0, tb_b_i} + tb_carry_i;
|
||||
|
||||
sum_check: assert property (
|
||||
@(negedge clk)
|
||||
reference === {tb_carry_o, tb_sum_o}
|
||||
)
|
||||
else begin
|
||||
err_cnt++;
|
||||
$error("\noperands : a_i = 0x%08h, b_i = 0x%08h, carry_i = %b\nyour res : sum = 0x%08h, carry_o = %b\nreference: sum = 0x%08h, carry_o = %b",
|
||||
tb_a_i, tb_b_i, tb_carry_i, tb_sum_o, tb_carry_o, reference[31:0], reference [32]);
|
||||
if(err_cnt == 10) begin
|
||||
$display("\nTest has been stopped after 10 errors");
|
||||
$stop();
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
|
@@ -11,33 +11,36 @@ See https://github.com/MPSU/APS/blob/master/LICENSE file for licensing details.
|
||||
|
||||
module lab_01_tb_fulladder4();
|
||||
|
||||
logic [3:0] tb_a_i;
|
||||
logic [3:0] tb_b_i;
|
||||
logic tb_carry_i;
|
||||
logic tb_carry_o;
|
||||
logic [3:0] tb_sum_o;
|
||||
logic [8:0] test_case;
|
||||
logic [3:0] tb_a_i;
|
||||
logic [3:0] tb_b_i;
|
||||
logic tb_carry_i;
|
||||
logic tb_carry_o;
|
||||
logic [3:0] tb_sum_o;
|
||||
logic [8:0] test_case;
|
||||
|
||||
fulladder4 DUT (
|
||||
.a_i(tb_a_i),
|
||||
.b_i(tb_b_i),
|
||||
.sum_o(tb_sum_o),
|
||||
.carry_i(tb_carry_i),
|
||||
.carry_o(tb_carry_o)
|
||||
);
|
||||
fulladder4 DUT (
|
||||
.a_i(tb_a_i),
|
||||
.b_i(tb_b_i),
|
||||
.sum_o(tb_sum_o),
|
||||
.carry_i(tb_carry_i),
|
||||
.carry_o(tb_carry_o)
|
||||
);
|
||||
|
||||
assign {tb_a_i, tb_b_i, tb_carry_i} = test_case;
|
||||
assign {tb_a_i, tb_b_i, tb_carry_i} = test_case;
|
||||
|
||||
initial begin
|
||||
$display("Test has been started");
|
||||
initial begin
|
||||
$display("Test has been started");
|
||||
#5ns;
|
||||
test_case = 9'd0;
|
||||
repeat(512) begin
|
||||
#5ns;
|
||||
test_case = 9'd0;
|
||||
repeat(512) begin
|
||||
#5ns;
|
||||
test_case++;
|
||||
end
|
||||
$display("\nTest has been finished Check results at waveform window.\n");
|
||||
$finish();
|
||||
test_case++;
|
||||
end
|
||||
$display("\nTest has been finished Check results at waveform window.\n");
|
||||
$finish();
|
||||
#5;
|
||||
$display("You're trying to run simulation that has finished. Aborting simulation.")
|
||||
$fatal();
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
Reference in New Issue
Block a user