GHDL: generics leak between configurations when `ghdl.sim_flags` is set
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 領域
- testing
調査の方向性
vunit/sim_if/ghdl.py の GHDLInterface._get_command() から始め、ghdl.sim_flags に実行フラグ、ジェネリック、アサーションレベルがどのように追加されるかを調べてください。提供されている tb_generic_leak.vhd と run.py の例を -p1 -v で実行し、漏れを再現してください。設定が以前のシミュレーションのジェネリックフラグを引き継がなくなり、両方の設定で期待値が報告されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
With GHDL, a configuration can be simulated with generics set by another configuration. When ghdl.sim_flags is set, every simulation appends its -g<name>=<value> flags to one list shared by all configurations of the test bench. GHDL uses the last -g for each generic. So a configuration inherits any generic set by an earlier simulation that it doesn't set itself.
Which configurations are affected depends on the order in which they are simulated. Serial runs fail deterministically when a configuration that sets a generic runs before one that relies on its default. Parallel runs fail intermittently, and a test can pass while simulating the wrong configuration.
Reproduction
tb_generic_leak.vhd:
library vunit_lib;
context vunit_lib.vunit_context;
entity tb_generic_leak is
generic (
runner_cfg : string;
a : integer := 0;
b : integer := 0
);
end entity;
architecture tb of tb_generic_leak is
begin
main : process
begin
test_runner_setup(runner, runner_cfg);
info("a = " & integer'image(a) & ", b = " & integer'image(b));
test_runner_cleanup(runner);
end process;
end architecture;
run.py:
from pathlib import Path
from vunit import VUnit
vu = VUnit.from_argv()
vu.add_vhdl_builtins()
lib = vu.add_library("lib")
lib.add_source_files(Path(__file__).parent / "tb_generic_leak.vhd")
vu.set_sim_option("ghdl.sim_flags", ["--ieee-asserts=disable"])
tb = lib.test_bench("tb_generic_leak")
# Configurations are simulated in the order they are added when running serially
tb.add_config(name="sets_b", generics=dict(b=1))
tb.add_config(name="sets_a", generics=dict(a=1)) # b is expected to keep its default (0)
vu.main()
Run it with python run.py -p1 -v:
sets_b: INFO - a = 0, b = 1
sets_a: INFO - a = 1, b = 1 <- expected b = 0
The output is correct in either of these cases:
- The
set_sim_option("ghdl.sim_flags", ...)call is left out, because.get(..., [])then returns a new list each time. - The call is moved after the
add_config()calls, because each existing configuration then gets its own copy of the list. Only configurations added after the option is set share the default configuration's list.
Cause
In vunit/sim_if/ghdl.py, GHDLInterface._get_command() does this:
sim = config.sim_options.get("ghdl.sim_flags", [])
sim += hooks.get_flags(self, "run_flags")
for name, value in config.generics.items():
sim += [f"-g{name!s}={value!s}"]
sim += [f"--assert-level={config.vhdl_assert_stop_level!s}"]
sim is the list object stored in sim_options, so += extends it in place. That list can be shared between configurations:
set_sim_option()copies the value once into each configuration that exists at that point, including the default configuration.Configuration.copy(), used byadd_config()and inIndependentSimTestCase._simulate(), makes only a shallow copy ofsim_options. So configurations added after the option is set share the default configuration's list.
The shared list therefore grows by one set of -g flags per simulation. Instrumenting _get_command() on a 16-test project showed the same list object for every configuration, and its length went 2 -> 12 -> 24 -> …
Fix
Copying the list before extending it worked in my case, but maybe there is a better/more general fix.
- sim = config.sim_options.get("ghdl.sim_flags", [])
+ sim = list(config.sim_options.get("ghdl.sim_flags", []))
Environment
- VUnit 5.0.0.dev12 (master at af474320)
- 主要言語
- VHDL
- スター
- 850
- フォーク
- 305
- 平均マージ
- 2日 13分
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
VUnit/vunit のほかの issue
-
KeyError in test scheduler when using TestBench.scan_tests_from_file()対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
AXI slave VCs have identical stalling behavior対応中かも @Lay007 が 39 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 1〜2日 初心者へのやさしさ 52/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
curriculum documentation quality
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
githubnext/gh-aw-workshop#5367 ·
メンテナーはふだん 3 日以内に返信
-
assertions 🔍
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
WriterSetTimes: the UTIME_NOW check fails when the kernel uses its coarse clock対応中かも @JakeChampion が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
JakeChampion/lang#14224 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
eyalgolan/statecraft-israel#2732 ·
メンテナーはふだん 1 日以内に返信
-
beginner blocked
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
hiero-ledger/hiero-sdk-js#4670 ·
メンテナーはふだん 1 日以内に返信