2006-08-26 11:35:28 +00:00
|
|
|
// DESCRIPTION: Verilator: Verilog Test module
|
|
|
|
//
|
|
|
|
// This file ONLY is placed into the Public Domain, for any use,
|
|
|
|
// without warranty, 2003 by Wilson Snyder.
|
|
|
|
|
|
|
|
`include "verilated.v"
|
|
|
|
|
|
|
|
module t;
|
|
|
|
`verilator_file_descriptor file;
|
|
|
|
|
2008-06-28 00:04:20 +00:00
|
|
|
integer chars;
|
|
|
|
reg [1*8:1] letterl;
|
|
|
|
reg [8*8:1] letterq;
|
|
|
|
reg [16*8:1] letterw;
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
initial begin
|
|
|
|
// Display formatting
|
|
|
|
`ifdef verilator
|
|
|
|
if (file != 0) $stop;
|
|
|
|
$fwrite(file, "Never printed, file closed\n");
|
2008-06-26 12:52:02 +00:00
|
|
|
if (!$feof(file)) $stop;
|
2006-08-26 11:35:28 +00:00
|
|
|
`endif
|
|
|
|
|
2006-12-19 14:09:57 +00:00
|
|
|
file = $fopen("obj_dir/t_sys_file_test.log","w"); // The "w" is required so we get a FD not a MFD
|
2008-06-26 12:52:02 +00:00
|
|
|
if ($feof(file)) $stop;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
$fdisplay(file, "[%0t] hello v=%x", $time, 32'h12345667);
|
|
|
|
$fwrite(file, "[%0t] %s\n", $time, "Hello2");
|
2008-06-27 12:45:05 +00:00
|
|
|
$fflush(file);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
$fclose(file);
|
|
|
|
`ifdef verilator
|
2008-04-24 14:32:39 +00:00
|
|
|
if (file != 0) $stop(1); // Also test arguments to stop
|
2006-08-26 11:35:28 +00:00
|
|
|
$fwrite(file, "Never printed, file closed\n");
|
|
|
|
`endif
|
|
|
|
|
2006-12-19 14:09:57 +00:00
|
|
|
begin
|
2008-06-28 00:04:20 +00:00
|
|
|
// Check for opening errors
|
2006-12-19 14:09:57 +00:00
|
|
|
file = $fopen("obj_dir/DOES_NOT_EXIST","r"); // The "r" is required so we get a FD not a MFD
|
|
|
|
if (|file) $stop; // Should not exist, IE must return 0
|
|
|
|
end
|
|
|
|
|
2006-12-21 15:28:32 +00:00
|
|
|
begin
|
|
|
|
// Check quadword access; a little strange, but it's legal to open "."
|
|
|
|
file = $fopen(".","r");
|
|
|
|
$fclose(file);
|
|
|
|
end
|
|
|
|
|
2008-06-28 00:04:20 +00:00
|
|
|
begin
|
|
|
|
// Check read functions
|
|
|
|
file = $fopen("t/t_sys_file_input.dat","r");
|
|
|
|
if ($feof(file)) $stop;
|
|
|
|
|
|
|
|
// $fgetc
|
|
|
|
if ($fgetc(file) != "h") $stop;
|
|
|
|
if ($fgetc(file) != "i") $stop;
|
|
|
|
if ($fgetc(file) != "\n") $stop;
|
|
|
|
|
|
|
|
// $fgets
|
|
|
|
chars = $fgets(letterl, file);
|
|
|
|
$write("c=%0d l=%s\n", chars, letterl);
|
|
|
|
if (chars != 1) $stop;
|
|
|
|
if (letterl != "l") $stop;
|
|
|
|
|
|
|
|
chars = $fgets(letterq, file);
|
|
|
|
$write("c=%0d q=%x=%s", chars, letterq, letterq); // Output includes newline
|
|
|
|
if (chars != 5) $stop;
|
|
|
|
if (letterq != "\0\0\0quad\n") $stop;
|
|
|
|
|
|
|
|
letterw = "5432109876543210";
|
|
|
|
chars = $fgets(letterw, file);
|
|
|
|
$write("c=%0d w=%s", chars, letterw); // Output includes newline
|
|
|
|
if (chars != 10) $stop;
|
|
|
|
if (letterw != "\0\0\0\0\0\0widestuff\n") $stop;
|
|
|
|
|
|
|
|
$fclose(file);
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
$write("*-* All Finished *-*\n");
|
2008-04-24 14:32:39 +00:00
|
|
|
$finish(0); // Test arguments to finish
|
2006-08-26 11:35:28 +00:00
|
|
|
end
|
|
|
|
endmodule
|