data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv
None: at end of input
1: b'%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:5: Cannot find include file: sim_exec_report.vh\n`include "sim_exec_report.vh" \n         ^~~~~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change,data/full_repos/permissive/214858095/sim_exec_report.vh\n             data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change,data/full_repos/permissive/214858095/sim_exec_report.vh.v\n             data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change,data/full_repos/permissive/214858095/sim_exec_report.vh.sv\n             sim_exec_report.vh\n             sim_exec_report.vh.v\n             sim_exec_report.vh.sv\n             obj_dir/sim_exec_report.vh\n             obj_dir/sim_exec_report.vh.v\n             obj_dir/sim_exec_report.vh.sv\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:6: Cannot find include file: sim_clks_rsts.vh\n`include "sim_clks_rsts.vh" \n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:7: Cannot find include file: sim_cvita_lib.svh\n`include "sim_cvita_lib.svh" \n         ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:8: Cannot find include file: sim_axis_lib.svh\n`include "sim_axis_lib.svh" \n         ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:9: Cannot find include file: sim_set_rb_lib.svh\n`include "sim_set_rb_lib.svh" \n         ^~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:12: Define or directive not defined: \'`TEST_BENCH_INIT\'\n  `TEST_BENCH_INIT("axi_rate_change_tb",4,1);\n  ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:12: syntax error, unexpected \'(\'\n  `TEST_BENCH_INIT("axi_rate_change_tb",4,1);\n                   ^~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:14: Define or directive not defined: \'`DEFINE_CLK\'\n  `DEFINE_CLK(clk, CLK_PERIOD, 50);\n  ^~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:14: syntax error, unexpected \'(\'\n  `DEFINE_CLK(clk, CLK_PERIOD, 50);\n              ^~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:15: Define or directive not defined: \'`DEFINE_RESET\'\n  `DEFINE_RESET(reset, 0, 100);\n  ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:124: syntax error, unexpected \'@\'\n          @(posedge clk);\n          ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:134: syntax error, unexpected \'@\'\n      @(posedge clk);\n      ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:137: syntax error, unexpected \'@\'\n      @(posedge clk);\n      ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:143: syntax error, unexpected \'@\'\n      @(posedge clk);\n      ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:144: Unsupported: fork statements\n      fork\n      ^~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:146: syntax error, unexpected IDENTIFIER\n        cvita_hdr_t send_header;\n                    ^~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:148: syntax error, unexpected IDENTIFIER, expecting "\'{"\n        logic [31:0] words_sent;\n                     ^~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:182: syntax error, unexpected IDENTIFIER\n        cvita_hdr_t recv_header;\n                    ^~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:185: syntax error, unexpected IDENTIFIER, expecting "\'{"\n        logic [63:0] expected_timestamp;\n                     ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:186: syntax error, unexpected IDENTIFIER, expecting "\'{"\n        logic [31:0] word;\n                     ^~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:187: syntax error, unexpected IDENTIFIER, expecting "\'{"\n        logic [15:0] word_cnt_div_m, word_cnt_div_m_frac;\n                     ^~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:188: syntax error, unexpected IDENTIFIER, expecting "\'{"\n        logic [15:0] word_cnt_div_spp_frac;\n                     ^~~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:207: Define or directive not defined: \'`ASSERT_FATAL\'\n            `ASSERT_FATAL(last == 1, "Incorrect packet length! Last not asserted!");\n            ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:207: syntax error, unexpected \',\'\n            `ASSERT_FATAL(last == 1, "Incorrect packet length! Last not asserted!");\n                                   ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:211: Define or directive not defined: \'`ASSERT_FATAL\'\n            `ASSERT_FATAL(last == 0, s);\n            ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:211: syntax error, unexpected \',\'\n            `ASSERT_FATAL(last == 0, s);\n                                   ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:218: Define or directive not defined: \'`ASSERT_FATAL\'\n            `ASSERT_FATAL(recv_header.eob == expected_eob, s);\n            ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:218: syntax error, unexpected \',\'\n            `ASSERT_FATAL(recv_header.eob == expected_eob, s);\n                                                         ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:223: Define or directive not defined: \'`ASSERT_FATAL\'\n            `ASSERT_FATAL(recv_header.timestamp == expected_timestamp, s);\n            ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:223: syntax error, unexpected \',\'\n            `ASSERT_FATAL(recv_header.timestamp == expected_timestamp, s);\n                                                                     ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:228: Define or directive not defined: \'`ASSERT_FATAL\'\n          `ASSERT_FATAL(((word[31:16] == word_cnt_div_m) && (word[15:0] == word_cnt_div_m_frac)), s);\n          ^~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:228: syntax error, unexpected \',\'\n          `ASSERT_FATAL(((word[31:16] == word_cnt_div_m) && (word[15:0] == word_cnt_div_m_frac)), s);\n                                                                                                ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:242: syntax error, unexpected IDENTIFIER\n    cvita_hdr_t tmp_header;\n                ^~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:243: syntax error, unexpected IDENTIFIER, expecting "\'{"\n    logic [63:0] word;\n                 ^~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:251: Define or directive not defined: \'`TEST_CASE_START\'\n                                                                                                                                                   : ... Suggested alternative: \'`SV_COV_START\'\n    `TEST_CASE_START("Wait for Reset");\n    ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:251: syntax error, unexpected \';\'\n    `TEST_CASE_START("Wait for Reset");\n                                      ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:255: syntax error, unexpected \'@\'\n    while (reset) @(posedge clk);\n                  ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:256: Define or directive not defined: \'`TEST_CASE_DONE\'\n    `TEST_CASE_DONE(~reset);\n    ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:256: syntax error, unexpected \';\'\n    `TEST_CASE_DONE(~reset);\n                           ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:263: Define or directive not defined: \'`TEST_CASE_START\'\n                                                                                                                                                   : ... Suggested alternative: \'`SV_COV_START\'\n    `TEST_CASE_START("Check various rates");\n    ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:263: syntax error, unexpected \';\'\n    `TEST_CASE_START("Check various rates");\n                                           ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:270: Define or directive not defined: \'`TEST_CASE_DONE\'\n    `TEST_CASE_DONE(1);\n    ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:270: syntax error, unexpected \';\'\n    `TEST_CASE_DONE(1);\n                      ^\n%Warning-STMTDLY: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:272: Unsupported: Ignoring delay on this delayed statement.\n    #2000;  \n    ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:280: Define or directive not defined: \'`TEST_CASE_START\'\n                                                                                                                                                   : ... Suggested alternative: \'`SV_COV_START\'\n    `TEST_CASE_START("Test partial packets");\n    ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:280: syntax error, unexpected \';\'\n    `TEST_CASE_START("Test partial packets");\n                                            ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:287: Define or directive not defined: \'`TEST_CASE_DONE\'\n    `TEST_CASE_DONE(1);\n    ^~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:287: syntax error, unexpected \';\'\n    `TEST_CASE_DONE(1);\n                      ^\n%Warning-STMTDLY: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:289: Unsupported: Ignoring delay on this delayed statement.\n    #2000;\n    ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:299: Define or directive not defined: \'`TEST_CASE_START\'\n                                                                                                                                                   : ... Suggested alternative: \'`SV_COV_START\'\n    `TEST_CASE_START("Test for bubble states");\n    ^~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:299: syntax error, unexpected \';\'\n    `TEST_CASE_START("Test for bubble states");\n                                              ^\n%Error: data/full_repos/permissive/214858095/FPGA_Exploration/spartan6/B205mini/ISE_Project/lib/sim/rfnoc/axi_rate_change/axi_rate_change_tb.sv:304: Define or directive not defined: \'`ASSERT_FATAL\'\n    `ASSERT_FATAL(clock_cnt == number_words, s);\n    ^~~~~~~~~~~~~\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module axi_rate_change_tb();
  `TEST_BENCH_INIT("axi_rate_change_tb",`NUM_TEST_CASES,`NS_PER_TICK);
  localparam CLK_PERIOD = $ceil(1e9/166.67e6);
  `DEFINE_CLK(clk, CLK_PERIOD, 50);
  `DEFINE_RESET(reset, 0, 100);

  localparam SR_N_ADDR      = 0;
  localparam SR_M_ADDR      = 1;
  localparam SR_CONFIG_ADDR = 2;
  localparam MAX_N = 16;
  localparam MAX_M = 16;

  logic [15:0] src_sid = 16'h0000;
  logic [15:0] dst_sid = 16'h0010;
  settings_bus_master sb (.clk(clk));
  axis_master #(.DWIDTH(32+128)) m_axis (.clk(clk));
  axis_slave #(.DWIDTH(32+128)) s_axis (.clk(clk));
  logic clear, clear_user;
  logic [31:0] m_axis_data_tdata, s_axis_data_tdata;
  logic m_axis_data_tlast, m_axis_data_tvalid, m_axis_data_tready;
  logic s_axis_data_tlast, s_axis_data_tvalid, s_axis_data_tready;
  logic warning_long_throttle, error_extra_outputs, error_drop_pkt_lockup;
  axi_rate_change #(
    .WIDTH(32),
    .MAX_N(MAX_N),
    .MAX_M(MAX_M),
    .SR_N_ADDR(SR_N_ADDR),
    .SR_M_ADDR(SR_M_ADDR),
    .SR_CONFIG_ADDR(SR_CONFIG_ADDR))
  axi_rate_change (
    .clk(clk), .reset(reset), .clear(clear), .clear_user(clear_user),
    .src_sid(src_sid), .dst_sid(dst_sid),
    .set_stb(sb.settings_bus.set_stb), .set_addr(sb.settings_bus.set_addr), .set_data(sb.settings_bus.set_data),
    .i_tdata(m_axis.axis.tdata[31:0]), .i_tlast(m_axis.axis.tlast), .i_tvalid(m_axis.axis.tvalid), .i_tready(m_axis.axis.tready), .i_tuser(m_axis.axis.tdata[159:32]),
    .o_tdata(s_axis.axis.tdata[31:0]), .o_tlast(s_axis.axis.tlast), .o_tvalid(s_axis.axis.tvalid), .o_tready(s_axis.axis.tready), .o_tuser(s_axis.axis.tdata[159:32]),
    .m_axis_data_tdata(m_axis_data_tdata), .m_axis_data_tlast(m_axis_data_tlast),
    .m_axis_data_tvalid(m_axis_data_tvalid), .m_axis_data_tready(m_axis_data_tready),
    .s_axis_data_tdata(s_axis_data_tdata), .s_axis_data_tlast(s_axis_data_tlast),
    .s_axis_data_tvalid(s_axis_data_tvalid), .s_axis_data_tready(s_axis_data_tready),
    .warning_long_throttle(warning_long_throttle),
    .error_extra_outputs(error_extra_outputs),
    .error_drop_pkt_lockup(error_drop_pkt_lockup));





  integer rate_n, rate_m, count_n, count_m, count_in, count_out;
  always @(posedge clk) begin
    if (reset | clear_user | clear) begin
      s_axis_data_tlast  <= 1'b0;
      count_n            <= 1;
      count_m            <= 1;
      count_in           <= 0;
      count_out          <= 0;
    end else begin

      if (m_axis_data_tvalid & m_axis_data_tready) begin
        if (count_n == rate_n) begin
          count_n        <= 1;
          count_in       <= count_in + 1;
        end else begin
          count_n        <= count_n + 1;
        end
      end
      if (count_in != count_out) begin
        if (s_axis_data_tvalid & s_axis_data_tready) begin
          if (count_m == rate_m) begin
            count_m          <= 1;
            count_out        <= count_out + 1;
          end else begin
            count_m          <= count_m + 1;
          end
        end
      end
    end
  end

  assign s_axis_data_tdata  = {count_out[15:0], count_m[15:0]};
  assign s_axis_data_tvalid = (count_in != count_out);
  assign m_axis_data_tready = s_axis_data_tready;


  int clock_cnt;
  logic clock_cnt_en = 1'b0;
  logic clock_cnt_start = 1'b0;
  always @(posedge clk) begin
    if (clock_cnt_en == 1'b1) begin

      if (s_axis.axis.tvalid & ~clock_cnt_start) begin
        clock_cnt_start <= 1'b1;
        clock_cnt       <= clock_cnt + 1;
      end else if (clock_cnt_start) begin
        clock_cnt       <= clock_cnt + 1;
      end
    end else begin
      clock_cnt_start <= 1'b0;
      clock_cnt       <= 0;
    end
  end


  task random_wait(int unsigned min_cycles, int unsigned max_cycles);
    begin
      int unsigned num_cycles;
      do begin
        num_cycles = $random() & (2**($clog2(max_cycles))-1);
      end while ((num_cycles < min_cycles) || (num_cycles > max_cycles));

      if (num_cycles != 0) begin
        for (int unsigned i = 0; i < num_cycles; i++) begin
          @(posedge clk);
        end
        @(negedge clk);
      end
    end
  endtask

  task test_rate(int n, int m, int num_words, int spp = 16, bit rand_delay_in = 0, bit rand_delay_out = 0);
    begin
      clear = 1'b1;
      @(posedge clk);
      @(posedge clk);
      clear = 1'b0;
      @(posedge clk);
      @(posedge clk);
      rate_n = n;
      rate_m = m;
      sb.write(SR_N_ADDR, n);
      sb.write(SR_M_ADDR, m);
      @(posedge clk);
      fork
      begin
        cvita_hdr_t send_header;
        int words_left_to_send, words_to_send;
        logic [31:0] words_sent;
        real timestamp;
        timestamp = 0.0;
        words_sent = 0;
        words_left_to_send = num_words;

        while (words_left_to_send > 0) begin

          send_header = '{default:0};
          send_header.has_time = 1;
          send_header.timestamp = longint'(timestamp);
          send_header.eob = (words_left_to_send <= spp);
          if (words_left_to_send >= spp) begin
            send_header.length = 16+4*spp;
            words_to_send = spp;
            words_left_to_send -= spp;
          end else begin
            send_header.length = 16+4*words_left_to_send;
            words_to_send = words_left_to_send;
            words_left_to_send = 0;
          end

          for (int i = 0; i < words_to_send; i++) begin
            if (rand_delay_in) random_wait(0,2*spp);
            m_axis.push_word({send_header,words_sent + i},i == words_to_send-1);
          end
          words_sent += words_to_send;

          send_header.seqnum++;
          timestamp += (1.0*m/n)*words_to_send;
        end
      end
      begin
        string s;
        cvita_hdr_t recv_header;
        logic last, expected_eob;
        real timestamp;
        logic [63:0] expected_timestamp;
        logic [31:0] word;
        logic [15:0] word_cnt_div_m, word_cnt_div_m_frac;
        logic [15:0] word_cnt_div_spp_frac;
        int words_left_to_recv, words_recvd;
        timestamp = 0.0;
        expected_timestamp = 0;
        word_cnt_div_spp_frac = 0;
        word_cnt_div_m = 0;
        word_cnt_div_m_frac = 0;
        words_recvd = 0;
        words_left_to_recv = $floor(num_words/n)*m;

        while (words_left_to_recv > 0) begin
          s_axis.pull_word({recv_header,word},last);
          word_cnt_div_spp_frac++;
          word_cnt_div_m_frac++;
          words_recvd++;
          words_left_to_recv--;
          timestamp += 1.0*n;

          if ((word_cnt_div_spp_frac == spp) || (words_left_to_recv == 0)) begin
            `ASSERT_FATAL(last == 1, "Incorrect packet length! Last not asserted!");
            word_cnt_div_spp_frac = 0;
          end else begin
            $sformat(s, "Incorrect packet length! Expected: %0d, Actual %0d", spp, words_recvd);
            `ASSERT_FATAL(last == 0, s);
          end

          if (last) begin
            words_recvd = 0;
            expected_eob = (words_left_to_recv == 0);
            $sformat(s, "Incorrect EOB state! Expected: %0d, Actual %0d", expected_eob, recv_header.eob);
            `ASSERT_FATAL(recv_header.eob == expected_eob, s);
          end

          if (last) begin
            $sformat(s, "Incorrect timestamp! Expected: %0d, Actual %0d", expected_timestamp, recv_header.timestamp);
            `ASSERT_FATAL(recv_header.timestamp == expected_timestamp, s);
            expected_timestamp = longint'(timestamp);
          end

          $sformat(s, "Incorrect packet data! Expected: 0x%08h, Actual: 0x%08h", {word_cnt_div_m, word_cnt_div_m_frac}, word);
          `ASSERT_FATAL(((word[31:16] == word_cnt_div_m) && (word[15:0] == word_cnt_div_m_frac)), s);

          if (word_cnt_div_m_frac == m) begin
            word_cnt_div_m_frac = 0;
            word_cnt_div_m++;
          end
        end
      end
      join
    end
  endtask

  initial begin : tb_main
    string s;
    cvita_hdr_t tmp_header;
    logic [63:0] word;
    logic last;
    integer spp, number_words;
    spp = 16;


    `TEST_CASE_START("Wait for Reset");
    sb.reset();
    m_axis.reset();
    s_axis.reset();
    while (reset) @(posedge clk);
    `TEST_CASE_DONE(~reset);


    `TEST_CASE_START("Check various rates");
    for (int _n = 1; _n <= MAX_N; _n++) begin
      for (int _m = 1; _m <= MAX_M; _m++) begin
        $display("Testing rate %0d:%0d", _n, _m);
        test_rate(_n, _m, _n*spp*3, spp, 1, 1);
      end
    end
    `TEST_CASE_DONE(1);

    #2000;


    `TEST_CASE_START("Test partial packets");
    for (int _n = 1; _n <= MAX_N; _n++) begin
      for (int _m = 1; _m <= MAX_M; _m++) begin
        $display("Testing rate %0d:%0d", _n, _m);
        test_rate(_n, _m, _n*spp + spp-1, spp, 1, 1);
      end
    end
    `TEST_CASE_DONE(1);

    #2000;


    `TEST_CASE_START("Test for bubble states");
    clock_cnt_en = 1'b1;
    number_words = 100000;
    test_rate(1, 1, number_words, spp, 0, 0);
    $sformat(s, "Incorrect number of clock cycles -- Possible bubble states detected! Expected: %0d, Actual: %0d", number_words, clock_cnt);
    `ASSERT_FATAL(clock_cnt == number_words, s);
    clock_cnt_en = 1'b0;
    `TEST_CASE_DONE(1);

    `TEST_BENCH_DONE;

  end


  initial begin
    while (reset) @(posedge clk);
    forever begin
      @(posedge clk);
      `ASSERT_FATAL(~warning_long_throttle,    "Throttle state deadlock!");
      `ASSERT_FATAL(~error_extra_outputs,      "Extra outputs detected!");
      `ASSERT_FATAL(~error_drop_pkt_lockup,    "Drop packet deadlock!");
    end
  end

endmodule
module axi_rate_change_tb();

  `TEST_BENCH_INIT("axi_rate_change_tb",`NUM_TEST_CASES,`NS_PER_TICK);
  localparam CLK_PERIOD = $ceil(1e9/166.67e6);
  `DEFINE_CLK(clk, CLK_PERIOD, 50);
  `DEFINE_RESET(reset, 0, 100);

  localparam SR_N_ADDR      = 0;
  localparam SR_M_ADDR      = 1;
  localparam SR_CONFIG_ADDR = 2;
  localparam MAX_N = 16;
  localparam MAX_M = 16;

  logic [15:0] src_sid = 16'h0000;
  logic [15:0] dst_sid = 16'h0010;
  settings_bus_master sb (.clk(clk));
  axis_master #(.DWIDTH(32+128)) m_axis (.clk(clk));
  axis_slave #(.DWIDTH(32+128)) s_axis (.clk(clk));
  logic clear, clear_user;
  logic [31:0] m_axis_data_tdata, s_axis_data_tdata;
  logic m_axis_data_tlast, m_axis_data_tvalid, m_axis_data_tready;
  logic s_axis_data_tlast, s_axis_data_tvalid, s_axis_data_tready;
  logic warning_long_throttle, error_extra_outputs, error_drop_pkt_lockup;
  axi_rate_change #(
    .WIDTH(32),
    .MAX_N(MAX_N),
    .MAX_M(MAX_M),
    .SR_N_ADDR(SR_N_ADDR),
    .SR_M_ADDR(SR_M_ADDR),
    .SR_CONFIG_ADDR(SR_CONFIG_ADDR))
  axi_rate_change (
    .clk(clk), .reset(reset), .clear(clear), .clear_user(clear_user),
    .src_sid(src_sid), .dst_sid(dst_sid),
    .set_stb(sb.settings_bus.set_stb), .set_addr(sb.settings_bus.set_addr), .set_data(sb.settings_bus.set_data),
    .i_tdata(m_axis.axis.tdata[31:0]), .i_tlast(m_axis.axis.tlast), .i_tvalid(m_axis.axis.tvalid), .i_tready(m_axis.axis.tready), .i_tuser(m_axis.axis.tdata[159:32]),
    .o_tdata(s_axis.axis.tdata[31:0]), .o_tlast(s_axis.axis.tlast), .o_tvalid(s_axis.axis.tvalid), .o_tready(s_axis.axis.tready), .o_tuser(s_axis.axis.tdata[159:32]),
    .m_axis_data_tdata(m_axis_data_tdata), .m_axis_data_tlast(m_axis_data_tlast),
    .m_axis_data_tvalid(m_axis_data_tvalid), .m_axis_data_tready(m_axis_data_tready),
    .s_axis_data_tdata(s_axis_data_tdata), .s_axis_data_tlast(s_axis_data_tlast),
    .s_axis_data_tvalid(s_axis_data_tvalid), .s_axis_data_tready(s_axis_data_tready),
    .warning_long_throttle(warning_long_throttle),
    .error_extra_outputs(error_extra_outputs),
    .error_drop_pkt_lockup(error_drop_pkt_lockup));





  integer rate_n, rate_m, count_n, count_m, count_in, count_out;
  always @(posedge clk) begin
    if (reset | clear_user | clear) begin
      s_axis_data_tlast  <= 1'b0;
      count_n            <= 1;
      count_m            <= 1;
      count_in           <= 0;
      count_out          <= 0;
    end else begin

      if (m_axis_data_tvalid & m_axis_data_tready) begin
        if (count_n == rate_n) begin
          count_n        <= 1;
          count_in       <= count_in + 1;
        end else begin
          count_n        <= count_n + 1;
        end
      end
      if (count_in != count_out) begin
        if (s_axis_data_tvalid & s_axis_data_tready) begin
          if (count_m == rate_m) begin
            count_m          <= 1;
            count_out        <= count_out + 1;
          end else begin
            count_m          <= count_m + 1;
          end
        end
      end
    end
  end

  assign s_axis_data_tdata  = {count_out[15:0], count_m[15:0]};
  assign s_axis_data_tvalid = (count_in != count_out);
  assign m_axis_data_tready = s_axis_data_tready;


  int clock_cnt;
  logic clock_cnt_en = 1'b0;
  logic clock_cnt_start = 1'b0;
  always @(posedge clk) begin
    if (clock_cnt_en == 1'b1) begin

      if (s_axis.axis.tvalid & ~clock_cnt_start) begin
        clock_cnt_start <= 1'b1;
        clock_cnt       <= clock_cnt + 1;
      end else if (clock_cnt_start) begin
        clock_cnt       <= clock_cnt + 1;
      end
    end else begin
      clock_cnt_start <= 1'b0;
      clock_cnt       <= 0;
    end
  end


  task random_wait(int unsigned min_cycles, int unsigned max_cycles);
    begin
      int unsigned num_cycles;
      do begin
        num_cycles = $random() & (2**($clog2(max_cycles))-1);
      end while ((num_cycles < min_cycles) || (num_cycles > max_cycles));

      if (num_cycles != 0) begin
        for (int unsigned i = 0; i < num_cycles; i++) begin
          @(posedge clk);
        end
        @(negedge clk);
      end
    end
  endtask

  task test_rate(int n, int m, int num_words, int spp = 16, bit rand_delay_in = 0, bit rand_delay_out = 0);
    begin
      clear = 1'b1;
      @(posedge clk);
      @(posedge clk);
      clear = 1'b0;
      @(posedge clk);
      @(posedge clk);
      rate_n = n;
      rate_m = m;
      sb.write(SR_N_ADDR, n);
      sb.write(SR_M_ADDR, m);
      @(posedge clk);
      fork
      begin
        cvita_hdr_t send_header;
        int words_left_to_send, words_to_send;
        logic [31:0] words_sent;
        real timestamp;
        timestamp = 0.0;
        words_sent = 0;
        words_left_to_send = num_words;

        while (words_left_to_send > 0) begin

          send_header = '{default:0};
          send_header.has_time = 1;
          send_header.timestamp = longint'(timestamp);
          send_header.eob = (words_left_to_send <= spp);
          if (words_left_to_send >= spp) begin
            send_header.length = 16+4*spp;
            words_to_send = spp;
            words_left_to_send -= spp;
          end else begin
            send_header.length = 16+4*words_left_to_send;
            words_to_send = words_left_to_send;
            words_left_to_send = 0;
          end

          for (int i = 0; i < words_to_send; i++) begin
            if (rand_delay_in) random_wait(0,2*spp);
            m_axis.push_word({send_header,words_sent + i},i == words_to_send-1);
          end
          words_sent += words_to_send;

          send_header.seqnum++;
          timestamp += (1.0*m/n)*words_to_send;
        end
      end
      begin
        string s;
        cvita_hdr_t recv_header;
        logic last, expected_eob;
        real timestamp;
        logic [63:0] expected_timestamp;
        logic [31:0] word;
        logic [15:0] word_cnt_div_m, word_cnt_div_m_frac;
        logic [15:0] word_cnt_div_spp_frac;
        int words_left_to_recv, words_recvd;
        timestamp = 0.0;
        expected_timestamp = 0;
        word_cnt_div_spp_frac = 0;
        word_cnt_div_m = 0;
        word_cnt_div_m_frac = 0;
        words_recvd = 0;
        words_left_to_recv = $floor(num_words/n)*m;

        while (words_left_to_recv > 0) begin
          s_axis.pull_word({recv_header,word},last);
          word_cnt_div_spp_frac++;
          word_cnt_div_m_frac++;
          words_recvd++;
          words_left_to_recv--;
          timestamp += 1.0*n;

          if ((word_cnt_div_spp_frac == spp) || (words_left_to_recv == 0)) begin
            `ASSERT_FATAL(last == 1, "Incorrect packet length! Last not asserted!");
            word_cnt_div_spp_frac = 0;
          end else begin
            $sformat(s, "Incorrect packet length! Expected: %0d, Actual %0d", spp, words_recvd);
            `ASSERT_FATAL(last == 0, s);
          end

          if (last) begin
            words_recvd = 0;
            expected_eob = (words_left_to_recv == 0);
            $sformat(s, "Incorrect EOB state! Expected: %0d, Actual %0d", expected_eob, recv_header.eob);
            `ASSERT_FATAL(recv_header.eob == expected_eob, s);
          end

          if (last) begin
            $sformat(s, "Incorrect timestamp! Expected: %0d, Actual %0d", expected_timestamp, recv_header.timestamp);
            `ASSERT_FATAL(recv_header.timestamp == expected_timestamp, s);
            expected_timestamp = longint'(timestamp);
          end

          $sformat(s, "Incorrect packet data! Expected: 0x%08h, Actual: 0x%08h", {word_cnt_div_m, word_cnt_div_m_frac}, word);
          `ASSERT_FATAL(((word[31:16] == word_cnt_div_m) && (word[15:0] == word_cnt_div_m_frac)), s);

          if (word_cnt_div_m_frac == m) begin
            word_cnt_div_m_frac = 0;
            word_cnt_div_m++;
          end
        end
      end
      join
    end
  endtask

  initial begin : tb_main
    string s;
    cvita_hdr_t tmp_header;
    logic [63:0] word;
    logic last;
    integer spp, number_words;
    spp = 16;


    `TEST_CASE_START("Wait for Reset");
    sb.reset();
    m_axis.reset();
    s_axis.reset();
    while (reset) @(posedge clk);
    `TEST_CASE_DONE(~reset);


    `TEST_CASE_START("Check various rates");
    for (int _n = 1; _n <= MAX_N; _n++) begin
      for (int _m = 1; _m <= MAX_M; _m++) begin
        $display("Testing rate %0d:%0d", _n, _m);
        test_rate(_n, _m, _n*spp*3, spp, 1, 1);
      end
    end
    `TEST_CASE_DONE(1);

    #2000;


    `TEST_CASE_START("Test partial packets");
    for (int _n = 1; _n <= MAX_N; _n++) begin
      for (int _m = 1; _m <= MAX_M; _m++) begin
        $display("Testing rate %0d:%0d", _n, _m);
        test_rate(_n, _m, _n*spp + spp-1, spp, 1, 1);
      end
    end
    `TEST_CASE_DONE(1);

    #2000;


    `TEST_CASE_START("Test for bubble states");
    clock_cnt_en = 1'b1;
    number_words = 100000;
    test_rate(1, 1, number_words, spp, 0, 0);
    $sformat(s, "Incorrect number of clock cycles -- Possible bubble states detected! Expected: %0d, Actual: %0d", number_words, clock_cnt);
    `ASSERT_FATAL(clock_cnt == number_words, s);
    clock_cnt_en = 1'b0;
    `TEST_CASE_DONE(1);

    `TEST_BENCH_DONE;

  end


  initial begin
    while (reset) @(posedge clk);
    forever begin
      @(posedge clk);
      `ASSERT_FATAL(~warning_long_throttle,    "Throttle state deadlock!");
      `ASSERT_FATAL(~error_extra_outputs,      "Extra outputs detected!");
      `ASSERT_FATAL(~error_drop_pkt_lockup,    "Drop packet deadlock!");
    end
  end

endmodule