From ff1d20d50cc1a87843841ad6677d6352929d5ef7 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 3 Oct 2024 20:36:23 -0400 Subject: [PATCH] Tests: Add t_struct_initial_assign, still fails (#5380) (#5381). --- test_regress/t/t_struct_initial_assign.py | 18 +++++ test_regress/t/t_struct_initial_assign.v | 80 +++++++++++++++++++ .../t/t_struct_initial_assign_public.py | 19 +++++ 3 files changed, 117 insertions(+) create mode 100755 test_regress/t/t_struct_initial_assign.py create mode 100644 test_regress/t/t_struct_initial_assign.v create mode 100755 test_regress/t/t_struct_initial_assign_public.py diff --git a/test_regress/t/t_struct_initial_assign.py b/test_regress/t/t_struct_initial_assign.py new file mode 100755 index 000000000..9a14c1acd --- /dev/null +++ b/test_regress/t/t_struct_initial_assign.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2024 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('simulator') + +test.compile(verilator_flags2=["--timing"]) + +test.execute(fails=test.vlt_all) # Issue #5380 + +test.passes() diff --git a/test_regress/t/t_struct_initial_assign.v b/test_regress/t/t_struct_initial_assign.v new file mode 100644 index 000000000..c9163d24b --- /dev/null +++ b/test_regress/t/t_struct_initial_assign.v @@ -0,0 +1,80 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2003 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +// Issue #5380 + +typedef struct packed { + logic field0; + logic field1; +} str_t; + +module t (/*AUTOARG*/ + // Inputs + clk +); + input clk; + + str_t bar_in; + str_t bar_out; + + Sub sub(bar_in, bar_out); + + // Test procedure + initial begin + integer i; + str_t initOut; + + bar_in = '0; // Set bar_in to 0 initially + + // Wait for the first falling edge of the clock + @(negedge clk); + + // Capture the initial output value + initOut = bar_out; + + // Apply stimulus for 10 clock cycles + for (i = 0; i < 10; i = i + 1) begin + if (i > 0) begin + bar_in = '1; // Switch to 1 after the first cycle + end + + @(negedge clk); + + // Check if the output field0 has changed + $display("bar_out.field0 = %h", bar_out.field0); + $display("initOut.field0 = %h", initOut.field0); + if (bar_out.field0 !== initOut.field0) begin + $display("%%Error: bar_out value changed when it should not have"); + $stop; + end + end + + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule + +module Sub + ( + input str_t bar_in, + output str_t bar_out + ); + + // This is a continuous assignment + always_comb begin + bar_out.field1 = bar_in.field1; + end + + // This should be an initial assignment, but verilator thinks it's a continous assignment + logic temp0 = bar_in.field0; + // If it is observed (verilator public, coverage, etc.), then it switches correctly to initial + // logic temp0 /* verilator public */ = bar_in.field0; + + always_comb begin + bar_out.field0 = temp0; + end +endmodule diff --git a/test_regress/t/t_struct_initial_assign_public.py b/test_regress/t/t_struct_initial_assign_public.py new file mode 100755 index 000000000..48b2cf60e --- /dev/null +++ b/test_regress/t/t_struct_initial_assign_public.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2024 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('simulator') +test.top_filename = "t/t_struct_initial_assign.v" + +test.compile(verilator_flags2=["--timing", "--public-flat-rw"]) + +test.execute() + +test.passes()