Verifying synchronours fifo

Here is my simple design of synchronous fifo:

module sync_fifo #(parameter DEPTH = 8, WIDTH = 16) (
  input bit clk,
  rst_n,
  rd_en,
  wr_en,
  input logic [WIDTH-1 : 0] data_in,
  output logic [WIDTH-1 : 0] data_out,
  output bit full,
  empty
);

  logic [$clog2(DEPTH)-1 : 0] rd_ptr;
  logic [$clog2(DEPTH)-1 : 0] wr_ptr;

  logic [WIDTH-1 : 0] fifo[DEPTH-1 : 0];
  logic [$clog2(DEPTH)-1:0]count;

  always@(posedge clk) begin
    $display($time,"[DUT] wr-en = %0d",wr_en);
  end

  always_ff @(posedge clk) begin
    if(!rst_n) begin
      wr_ptr <=0;
    end
    else begin
      if(wr_en && !full) begin
        fifo[wr_ptr] <= data_in;
        wr_ptr <= wr_ptr +1;
      end
      else $display("[DUT] write failed");
    end
  end

  always_ff @(posedge clk) begin
    if(!rst_n) begin
      rd_ptr <= 0;
    end
    else begin
      if(rd_en && !empty) begin
        data_out <= fifo[rd_ptr];
        rd_ptr <= rd_ptr +1;
      end
    end
  end

  always_ff @(posedge clk) begin
    if(!rst_n) begin
      count <= 0;
    end
    else begin
      case({wr_en,rd_en})
        2'b10 : count <= count + 1;
        2'b01 : count <= count - 1;
        default : count <= count;
      endcase
    end
  end

  assign empty = (count == 0) ? 1'b1 : 1'b0;
  assign full = (DEPTH == count) ? 1'b1 : 1'b0;

endmodule

I wrote a simple testbench to verify it :

But the write operation is not performing as desired . Could someone please explain what’s happening?

Please post your testbench code as text and not an image. Or better yet, post the complete example to EDA Playground so that others can run your code and give you an answer.

There are several problems.

You wanted to do 8 writes, but you only do 7 writes. You set wr_en to 0 too early. Do it after this line, not before it:

repeat(1) @(posedge clk);

Similarly, you only do 7 reads because you set rd_en too early.

You should debug with waveforms, not display statements. You would see that the fifo only got 7 words, not 8.

For all the synchronous inputs to the dut, you need to use nonblocking assignments, like wr_en <= 1. You have simulation race conditions using blocking assignments.