cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Mentor
Mentor
378 Views
Registered: ‎10-07-2011

File IO: WRITE_MODE & APPEND_MODE weird behavior

Jump to solution

Hello all,

Using 2018.2 on Win10x64, trying to write test data to a file and observing strange behavior.

Basically, WRITE_MODE is not doing anything. It is always failing. APPEND_MODE is working as expected ONLY IF the target file already exists. Below is a summary of all the cases I tested.

Case: Folder doesn't exist
WRITE_MODE & APPEND_MODE
# RUNTIME: Fatal Error: RUNTIME_0048 WriteFileTestbench.vhd (76): Cannot open file "../Data/WriteFile/DummyWrite.txt"; no such file or directory.


Case: Folder exists but file doesn't
WRITE_MODE & APPEND_MODE
# RUNTIME: Fatal Error: RUNTIME_0048 WriteFileTestbench.vhd (76): Cannot open file "../Data/WriteFile/DummyWrite.txt"; no such file or directory.


Case: Folder exists and file is present but empty
WRITE_MODE
# RUNTIME: Fatal Error: RUNTIME_0048 WriteFileTestbench.vhd (75): Cannot open file "../Data/WriteFile/DummyWrite.txt"; no such file or directory.
APPEND_MODE
# Working! Data has been APPENDED to the empty file.


Case: The file exists and contains data from a previous run
WRITE_MODE
# RUNTIME: Fatal Error: RUNTIME_0048 WriteFileTestbench.vhd (75): Cannot open file "../Data/WriteFile/DummyWrite.txt"; no such file or directory.
APPEND_MODE
# Working as expected. Data has been APPENDED to the existing file.

Below is the testbench I'm using.

library std;
use std.textio.all;

library ieee;
use ieee.std_logic_1164.all;

library aldec;
use aldec.random_pkg.all;

-- -----------------------------------------------------------------------------
entity WriteFileTestbench is
end entity;

-- -----------------------------------------------------------------------------
architecture Simulation of WriteFileTestbench is
  -- Test case
  constant cPATH: STRING := "../Data/WriteFile/";
  constant cMODE: FILE_OPEN_KIND := WRITE_MODE;

  -- Simulation Operating Parameters
  constant cLENGTH: POSITIVE := 16;
  constant cSEED: INTEGER := 1731377;

-- -----------------------------------------------------------------------------
begin
  WriteFile: process
    file vFD: TEXT;

    variable vLINE: LINE;
    variable vSEED: INTEGER := cSEED;
    variable vRESULT: REAL;

    variable i: NATURAL;
  begin
    file_open(vFD,cPATH & "DummyWrite.txt",cMODE);

    for i in 0 to cLENGTH - 1 loop
      uniform_p(vSEED,-2147483648,2147483647,vRESULT);
      write(vLINE,INTEGER(vRESULT),RIGHT,16);
    end loop;

    writeline(vFD,vLINE);
    file_close(vFD);
    wait;
  end process;
end architecture;

In conclusion, what I see is:

  1. If the target file doesn't exist, it can't be created.
  2. APPEND_MODE is working almost as expected. It really appends data to some EXISTING file.
  3. WRITE_MODE is useless. It always fails.
  4. READ_MODE is working as expected.

This means there is no way to generate a new file. The only way to save data is to append to an existing file. In this case, the former stuff remains in and the file has to be empty manually from time to time. Annoying!

Is there something wrong with the above? Is this really the way VHDL file IO works?

Claude

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Mentor
Mentor
174 Views
Registered: ‎10-07-2011

I sent a small test case to Aldec. They agree there is a problem with the tool but since a workaround is available, the fix will be postpone to the next release.

The workaround is to only use the APPEND_MODE and to create an empty file before running the testbench (such that the file already exists).

View solution in original post

0 Kudos
2 Replies
Highlighted
Xilinx Employee
Xilinx Employee
200 Views
Registered: ‎09-05-2018

Hi, 

can you please try the above without aldec(use aldec.random_pkg.all) package and try to implement the modes and see if the issue still exists. Since I do not see them at my end.

 

Regards,

Saketh

0 Kudos
Highlighted
Mentor
Mentor
175 Views
Registered: ‎10-07-2011

I sent a small test case to Aldec. They agree there is a problem with the tool but since a workaround is available, the fix will be postpone to the next release.

The workaround is to only use the APPEND_MODE and to create an empty file before running the testbench (such that the file already exists).

View solution in original post

0 Kudos