tb_regex_cpu.v (2496B)
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | `timescale 1ns / 1ps module tb_regex_cpu; reg clk; reg rst; reg start; reg end_of_str; reg [ 7:0] char_in; reg char_valid; reg prog_en; reg [ 7:0] prog_addr; reg [31:0] prog_data; wire ready; wire [15:0] match_bus; regex_cpu #( .NUM_REGEX(16) ) uut ( .clk(clk), .rst(rst), .start(start), .end_of_str(end_of_str), .char_in(char_in), .char_valid(char_valid), .prog_en(prog_en), .prog_addr(prog_addr), .prog_data(prog_data), .ready(ready), .match_bus(match_bus) ); always #5 clk = ~clk; task send_char; input [7:0] c; begin wait (ready); @(posedge clk); char_in = c; char_valid = 1; @(posedge clk); char_valid = 0; @(posedge clk); wait (ready); end endtask task finish_string; begin wait (ready); @(posedge clk); end_of_str = 1; @(posedge clk); end_of_str = 0; @(posedge clk); wait (ready); end endtask task test_string; input [127:0] s; input integer len; integer i; reg [7:0] c; begin @(posedge clk); start = 1; @(posedge clk); start = 0; @(posedge clk); wait (ready); for (i = 0; i < len; i = i + 1) begin c = s[(len-1-i)*8+:8]; send_char(c); end finish_string(); $display("Test Done. MatchBus: %b", match_bus); #20; end endtask initial begin $dumpfile("processor/build/dump_processor.vcd"); $dumpvars(0, tb_regex_cpu); clk = 0; rst = 1; start = 0; end_of_str = 0; char_in = 0; char_valid = 0; prog_en = 0; prog_addr = 0; prog_data = 0; #20 rst = 0; $display("--- Starting Robust Simulation ---"); $display("1. Testing 'abbc' (Regex 0)..."); test_string("abbc", 4); $display("2. Testing 'abb' (Regex 1)..."); test_string("abb", 3); $display("3. Testing 'ac' (Regex 2)..."); test_string("ac", 2); $display("4. Testing 'ccc' (Regex 4)..."); test_string("ccc", 3); $display("5. Testing 'abc' (Regex 7)..."); test_string("abc", 3); $display("6. Testing 'babc' (Regex 9)..."); test_string("babc", 4); $display("7. Testing 'acac' (Regex 10)..."); test_string("acac", 4); $display("8. Testing 'cccb' (Regex 11)..."); test_string("cccb", 4); #50 $finish; end endmodule |