summaryrefslogtreecommitdiff
path: root/nandgame/counter_tb.sv
blob: b72547570a15d05535cf7eadbcb798201a681627 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
`timescale 1us/1us

module counter_tb;

logic tst_clk, tst_store_X, tst_count;
logic [15:0] tst_in_X, tst_result;

counter uut (
  .clk_in(tst_clk),
  .X_in(tst_in_X),
  .counter_out(tst_result),
  .st_store_X_in(tst_store_X),
  .count_enable_in(tst_count)
);

string filename;
initial begin
`ifdef DUMP_FILE_NAME
  filename=`DUMP_FILE_NAME;
`else
  filename="counter.lxt2";
`endif
  $dumpfile(filename); $dumpvars();
  tst_clk = 0;
  tst_store_X = 0;
  tst_in_X = 0;
  tst_count = 0;
end

always #10 tst_clk = ~tst_clk;

initial begin
  // start of with count disabled
  repeat(5) @(posedge tst_clk);
  assert (tst_result == 0)
  else   $error("Expected 0, got %d", tst_result);
  tst_count = 1;

  // now that counting is enabled
  repeat(5) @(posedge tst_clk);
  assert (tst_result == 5)
  else   $error("Expected 5, got %d", tst_result);

  @(posedge tst_clk);
  tst_store_X = 1;
  tst_in_X = 16'd834;
  repeat(3) begin
    @(posedge tst_clk);
    assert (tst_result == 834)
    else   $error("Expected 834, got %d", tst_result);
    // this shouldn't matter
    tst_count = !tst_count;
  end
  tst_store_X = 0;
  tst_count = 1;

  @(posedge tst_clk);
  assert (tst_result == 835)
  else   $error("Expected 835, got %d", tst_result);
  #30

  $finish();
end

endmodule