From 1fdeb7b98267ec7d02826f3d8d224dd263896126 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 5 Oct 2025 12:37:30 +0100 Subject: [PATCH] Add regression tests for $fmonitor tasks. Also add a test for multiple $monitor task calls and $monitoron and $monitoroff. --- ivtest/gold/fmonitor1-vvp-stdout.gold | 23 +++++++ ivtest/gold/fmonitor2-vvp-stdout.gold | 46 ++++++++++++++ ivtest/gold/monitor4-vvp-stdout.gold | 17 ++++++ ivtest/ivltests/fmonitor1.v | 59 ++++++++++++++++++ ivtest/ivltests/fmonitor2.v | 88 +++++++++++++++++++++++++++ ivtest/ivltests/monitor4.v | 38 ++++++++++++ ivtest/regress-vvp.list | 3 + ivtest/vvp_tests/fmonitor1.json | 5 ++ ivtest/vvp_tests/fmonitor2.json | 5 ++ ivtest/vvp_tests/monitor4.json | 5 ++ 10 files changed, 289 insertions(+) create mode 100644 ivtest/gold/fmonitor1-vvp-stdout.gold create mode 100644 ivtest/gold/fmonitor2-vvp-stdout.gold create mode 100644 ivtest/gold/monitor4-vvp-stdout.gold create mode 100644 ivtest/ivltests/fmonitor1.v create mode 100644 ivtest/ivltests/fmonitor2.v create mode 100644 ivtest/ivltests/monitor4.v create mode 100644 ivtest/vvp_tests/fmonitor1.json create mode 100644 ivtest/vvp_tests/fmonitor2.json create mode 100644 ivtest/vvp_tests/monitor4.json diff --git a/ivtest/gold/fmonitor1-vvp-stdout.gold b/ivtest/gold/fmonitor1-vvp-stdout.gold new file mode 100644 index 000000000..867eb187e --- /dev/null +++ b/ivtest/gold/fmonitor1-vvp-stdout.gold @@ -0,0 +1,23 @@ +log1: +@0 a = 0 +@1 a = 1 +@2 a = 2 +@3 a = 3 +@4 a = 4 +log2: +@0 b = 0 +@1 b = 1 +@2 b = 2 +@3 b = 3 +@4 b = 4 +@5 b = 5 +@6 b = 6 +@7 b = 7 +@8 b = 8 +@9 b = 9 +log3: +@5 c = 5 +@6 c = 6 +@7 c = 7 +@8 c = 8 +@9 c = 9 diff --git a/ivtest/gold/fmonitor2-vvp-stdout.gold b/ivtest/gold/fmonitor2-vvp-stdout.gold new file mode 100644 index 000000000..879909285 --- /dev/null +++ b/ivtest/gold/fmonitor2-vvp-stdout.gold @@ -0,0 +1,46 @@ +log1a: +@0 a = 0 +@1 a = 1 +@2 a = 2 +@3 a = 3 +@4 a = 4 +log1b: +@0 a = 0 +@1 a = 1 +@2 a = 2 +@3 a = 3 +@4 a = 4 +log2a: +@0 b = 0 +@1 b = 1 +@2 b = 2 +@3 b = 3 +@4 b = 4 +@5 b = 5 +@6 b = 6 +@7 b = 7 +@8 b = 8 +@9 b = 9 +log2b: +@0 b = 0 +@1 b = 1 +@2 b = 2 +@3 b = 3 +@4 b = 4 +@5 b = 5 +@6 b = 6 +@7 b = 7 +@8 b = 8 +@9 b = 9 +log3a: +@5 c = 5 +@6 c = 6 +@7 c = 7 +@8 c = 8 +@9 c = 9 +log3b: +@5 c = 5 +@6 c = 6 +@7 c = 7 +@8 c = 8 +@9 c = 9 diff --git a/ivtest/gold/monitor4-vvp-stdout.gold b/ivtest/gold/monitor4-vvp-stdout.gold new file mode 100644 index 000000000..e584301eb --- /dev/null +++ b/ivtest/gold/monitor4-vvp-stdout.gold @@ -0,0 +1,17 @@ +@0 a = 0 +@1 a = 1 +@2 a = 2 +@3 a = 3 +@4 a = 4 +@5 b = 5 +@6 b = 6 +@7 b = 7 +@8 b = 8 +@9 b = 9 +@10 b = 10 +@15 b = 15 +@16 b = 16 +@17 b = 17 +@18 b = 18 +@19 b = 19 +@20 b = 20 diff --git a/ivtest/ivltests/fmonitor1.v b/ivtest/ivltests/fmonitor1.v new file mode 100644 index 000000000..2793bc54e --- /dev/null +++ b/ivtest/ivltests/fmonitor1.v @@ -0,0 +1,59 @@ +module test; + +integer a, b, c; + +integer fd1, fd2, fd3; + +reg [64*8:1] str; + +initial begin + a = 0; + b = 0; + c = 0; + fd1 = $fopen("log/fmonitor1.log1", "w"); + fd2 = $fopen("log/fmonitor1.log2", "w"); + $fmonitor(fd1, "@%0t a = %0d", $time, a); + $fmonitor(fd2, "@%0t b = %0d", $time, b); + repeat (5) begin + #1; + a = a + 1; + b = b + 1; + c = c + 1; + end + $fclose(fd1); + fd3 = $fopen("log/fmonitor1.log3", "w"); + $fmonitor(fd3, "@%0t c = %0d", $time, c); + repeat (5) begin + #1; + a = a + 1; + b = b + 1; + c = c + 1; + end + $fclose(fd2); + $fclose(fd3); + + $display("log1:"); + fd1 = $fopen("log/fmonitor1.log1", "r"); + while ($fgets(str, fd1)) begin + $write("%0s", str); + end + $fclose(fd1); + + $display("log2:"); + fd2 = $fopen("log/fmonitor1.log2", "r"); + while ($fgets(str, fd2)) begin + $write("%0s", str); + end + $fclose(fd2); + + $display("log3:"); + fd3 = $fopen("log/fmonitor1.log3", "r"); + while ($fgets(str, fd3)) begin + $write("%0s", str); + end + $fclose(fd3); + + $finish(0); +end + +endmodule diff --git a/ivtest/ivltests/fmonitor2.v b/ivtest/ivltests/fmonitor2.v new file mode 100644 index 000000000..25e419b5f --- /dev/null +++ b/ivtest/ivltests/fmonitor2.v @@ -0,0 +1,88 @@ +module test; + +integer a, b, c; + +integer mcd1a, mcd2a, mcd3a; +integer mcd1b, mcd2b, mcd3b; + +integer fd; + +reg [64*8:1] str; + +initial begin + a = 0; + b = 0; + c = 0; + mcd1a = $fopen("log/fmonitor2.log1a"); mcd1b = $fopen("log/fmonitor2.log1b"); + mcd2a = $fopen("log/fmonitor2.log2a"); mcd2b = $fopen("log/fmonitor2.log2b"); + $fmonitor(mcd1a | mcd1b, "@%0t a = %0d", $time, a); + $fmonitor(mcd2a | mcd2b, "@%0t b = %0d", $time, b); + repeat (5) begin + #1; + a = a + 1; + b = b + 1; + c = c + 1; + end + $fclose(mcd1a); + mcd3a = $fopen("log/fmonitor2.log3a"); mcd3b = $fopen("log/fmonitor2.log3b"); + $fmonitor(mcd3a | mcd3b, "@%0t c = %0d", $time, c); + repeat (5) begin + #1; + a = a + 1; + b = b + 1; + c = c + 1; + end + $fclose(mcd2a); + $fclose(mcd3a); + + #1; + $fclose(mcd1b); + $fclose(mcd2b); + $fclose(mcd3b); + + $display("log1a:"); + fd = $fopen("log/fmonitor2.log1a", "r"); + while ($fgets(str, fd)) begin + $write("%0s", str); + end + $fclose(fd); + + $display("log1b:"); + fd = $fopen("log/fmonitor2.log1b", "r"); + while ($fgets(str, fd)) begin + $write("%0s", str); + end + $fclose(fd); + + $display("log2a:"); + fd = $fopen("log/fmonitor2.log2a", "r"); + while ($fgets(str, fd)) begin + $write("%0s", str); + end + $fclose(fd); + + $display("log2b:"); + fd = $fopen("log/fmonitor2.log2b", "r"); + while ($fgets(str, fd)) begin + $write("%0s", str); + end + $fclose(fd); + + $display("log3a:"); + fd = $fopen("log/fmonitor2.log3a", "r"); + while ($fgets(str, fd)) begin + $write("%0s", str); + end + $fclose(fd); + + $display("log3b:"); + fd = $fopen("log/fmonitor2.log3b", "r"); + while ($fgets(str, fd)) begin + $write("%0s", str); + end + $fclose(fd); + + $finish(0); +end + +endmodule diff --git a/ivtest/ivltests/monitor4.v b/ivtest/ivltests/monitor4.v new file mode 100644 index 000000000..736ce7844 --- /dev/null +++ b/ivtest/ivltests/monitor4.v @@ -0,0 +1,38 @@ +// Test that $monitor correctly cancels a preceding $monitor. + +module test; + +integer a, b; + +initial begin + a = 0; + b = 0; + $monitor("@%0t a = %0d", $time, a); + repeat (5) begin + #1; + a = a + 1; + b = b + 1; + end + $monitor("@%0t b = %0d", $time, b); + repeat (5) begin + #1; + a = a + 1; + b = b + 1; + end + $monitoroff; + repeat (5) begin + #1; + a = a + 1; + b = b + 1; + end + #0; + $monitoron; + repeat (5) begin + #1; + a = a + 1; + b = b + 1; + end + $finish(0); +end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index f7232e391..2d5a229e1 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -121,6 +121,8 @@ eofmt_percent vvp_tests/eofmt_percent.json eofmt_percent-vlog95 vvp_tests/eofmt_percent-vlog95.json fdisplay3 vvp_tests/fdisplay3.json final3 vvp_tests/final3.json +fmonitor1 vvp_tests/fmonitor1.json +fmonitor2 vvp_tests/fmonitor2.json fread-error vvp_tests/fread-error.json line_directive vvp_tests/line_directive.json localparam_type vvp_tests/localparam_type.json @@ -147,6 +149,7 @@ module_ordered_list1 vvp_tests/module_ordered_list1.json module_ordered_list2 vvp_tests/module_ordered_list2.json module_port_array1 vvp_tests/module_port_array1.json module_port_array_init1 vvp_tests/module_port_array_init1.json +monitor4 vvp_tests/monitor4.json non-polymorphic-abs vvp_tests/non-polymorphic-abs.json partsel_invalid_idx1 vvp_tests/partsel_invalid_idx1.json partsel_invalid_idx2 vvp_tests/partsel_invalid_idx2.json diff --git a/ivtest/vvp_tests/fmonitor1.json b/ivtest/vvp_tests/fmonitor1.json new file mode 100644 index 000000000..97d2de2d7 --- /dev/null +++ b/ivtest/vvp_tests/fmonitor1.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "fmonitor1.v", + "gold" : "fmonitor1" +} diff --git a/ivtest/vvp_tests/fmonitor2.json b/ivtest/vvp_tests/fmonitor2.json new file mode 100644 index 000000000..a43e6067e --- /dev/null +++ b/ivtest/vvp_tests/fmonitor2.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "fmonitor2.v", + "gold" : "fmonitor2" +} diff --git a/ivtest/vvp_tests/monitor4.json b/ivtest/vvp_tests/monitor4.json new file mode 100644 index 000000000..21d2769a8 --- /dev/null +++ b/ivtest/vvp_tests/monitor4.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "monitor4.v", + "gold" : "monitor4" +}