summaryrefslogtreecommitdiff
path: root/homework_2/SRC/base_test.sv
blob: b6b81efdc88850444b8ed8474db539ce3b76df8f (plain) (blame)
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
66
67
// Test class instantiates the environment and starts it.
class base_test extends uvm_test;
  `uvm_component_utils(base_test)
  function new(string name = "base_test", uvm_component parent = null);
    super.new(name, parent);
  endfunction

  env            e0;
  gen_item_seq   seq;
  virtual des_if vif;

  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase);

    // Create the environment
    e0 = env::type_id::create("e0", this);

    // Get virtual IF handle from top level and pass it to everything
    // in env level
    if (!uvm_config_db#(virtual des_if)::get(this, "", "des_vif", vif))
      `uvm_fatal("TEST", "Did not get vif")

    uvm_config_db#(virtual des_if)::set(this, "e0.a0.*", "des_vif", vif);

    // Create sequence and randomize it
    seq = gen_item_seq::type_id::create("seq");

    if (!seq.randomize()) `uvm_fatal("TEST", "Failed to randomize sequence")
  endfunction

  virtual task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    apply_reset();
    seq.start(e0.a0.s0);

    #200;

    `uvm_info("TEST_DONE", "Sequence detector test completed", UVM_LOW)

    phase.drop_objection(this);
  endtask

  virtual task apply_reset();
    vif.reset <= 1'b1;
    vif.inp   <= 0;

    repeat (5) @(posedge vif.clk);

    vif.reset <= 0;

    repeat (10) @(posedge vif.clk);
  endtask
endclass

class test_both_patterns extends base_test;
  `uvm_component_utils(test_both_patterns)
  function new(string name = "test_both_patterns", uvm_component parent = null);
    super.new(name, parent);
  endfunction

  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase);

    if (!seq.randomize() with {num inside {[520 : 620]};})
      `uvm_fatal("TEST", "Failed to randomize sequence length")
  endfunction
endclass