From 5e22ca77ec565e31cb31e65f6f0fca605ebeb12d Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 19 May 2018 09:30:54 -0400 Subject: [PATCH] Tests: Fix misc multithreaded issues, merge from threads branch. --- include/verilated.h | 4 +--- test_regress/Makefile_obj | 6 +++++- test_regress/t/t_vlcov_merge.pl | 3 +++ test_regress/t/t_vpi_get.cpp | 29 ++++++++++++++++++----------- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/verilated.h b/include/verilated.h index 49b270a99..c9ebf8977 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -186,9 +186,7 @@ public: // METHODS /// Check that the current thread ID is the same as the construction thread ID void check() VL_MT_UNSAFE_ONE { - // Memoize results in local thread, to prevent slow get_id() call - VL_THREAD_LOCAL bool t_okThread = (m_threadid == VL_THREAD_ID()); - if (!VL_LIKELY(t_okThread)) { + if (!VL_LIKELY(m_threadid == VL_THREAD_ID())) { fatal_different(); } } diff --git a/test_regress/Makefile_obj b/test_regress/Makefile_obj index a08ed2b56..1536a77e7 100644 --- a/test_regress/Makefile_obj +++ b/test_regress/Makefile_obj @@ -28,8 +28,12 @@ VPATH += ../../$(VM_USER_DIR) # Needed by DPI tests CPPFLAGS += -DVERILATOR=1 -# Needed by tracing routines +# Debugging CPPFLAGS += -DVL_DEBUG=1 +# Assertions disabled as SystemC libraries are not clean +#CPPFLAGS += -D_GLIBCXX_DEBUG + +# Needed by tracing routines CPPFLAGS += -DTEST_OBJ_DIR=$(TEST_OBJ_DIR) CPPFLAGS += -DVM_PREFIX=$(VM_PREFIX) CPPFLAGS += -DVM_PREFIX_INCLUDE="<$(VM_PREFIX).h>" diff --git a/test_regress/t/t_vlcov_merge.pl b/test_regress/t/t_vlcov_merge.pl index 6a0e57121..72de4372c 100755 --- a/test_regress/t/t_vlcov_merge.pl +++ b/test_regress/t/t_vlcov_merge.pl @@ -19,6 +19,9 @@ run(cmd => ["../bin/verilator_coverage", # Older clib's didn't properly sort maps, but the coverage data doesn't # really care about ordering. So avoid false failures by sorting. +# Set LC_ALL as suggested in the sort manpage to avoid sort order +# changes from the locale. +$ENV{LC_ALL} = "C"; run(cmd => ["sort", "$Self->{obj_dir}/coverage.dat", "> $Self->{obj_dir}/coverage-sort.dat", diff --git a/test_regress/t/t_vpi_get.cpp b/test_regress/t/t_vpi_get.cpp index 4cd41d87a..066deaa87 100644 --- a/test_regress/t/t_vpi_get.cpp +++ b/test_regress/t/t_vpi_get.cpp @@ -156,20 +156,27 @@ struct params { unsigned int scalar; int type; } attributes, children; -} values[] = { - {"onebit", {1, vpiNoDirection, 1, vpiReg}, {0, 0, 0, 0}}, - {"twoone", {2, vpiNoDirection, 0, vpiReg}, {0, 0, 0, 0}}, - {"onetwo", {2, vpiNoDirection, 0, TestSimulator::is_verilator() ? vpiReg : vpiMemory}, {0, 0, 0, 0}}, - {"fourthreetwoone", {2, vpiNoDirection, 0, vpiMemory}, {2, vpiNoDirection, 0, vpiMemoryWord}}, - {"clk", {1, vpiInput, 1, vpiPort}, {0, 0, 0, 0}}, - {"testin", {16, vpiInput, 0, vpiPort}, {0, 0, 0, 0}}, - {"testout", {24, vpiOutput, 0, vpiPort}, {0, 0, 0, 0}}, - {"sub.subin", {1, vpiInput, 1, vpiPort}, {0, 0, 0, 0}}, - {"sub.subout", {1, vpiOutput, 1, vpiPort}, {0, 0, 0, 0}}, - {NULL, {0, 0, 0, 0}, {0, 0, 0, 0}} }; int mon_check_props() { + // This table needs to be function-static. + // This avoids calling is_verilator() below at global-static init time. + // When global-static led to a race between the is_verilator call below, and + // the code that sets up the VerilatedAssertOneThread() check in + // verilated_vpi.cc, it was causing the check to falsely fail + // (due to m_threadid within the check not being initted yet.) + static struct params values[] = { + {"onebit", {1, vpiNoDirection, 1, vpiReg}, {0, 0, 0, 0}}, + {"twoone", {2, vpiNoDirection, 0, vpiReg}, {0, 0, 0, 0}}, + {"onetwo", {2, vpiNoDirection, 0, TestSimulator::is_verilator() ? vpiReg : vpiMemory}, {0, 0, 0, 0}}, + {"fourthreetwoone", {2, vpiNoDirection, 0, vpiMemory}, {2, vpiNoDirection, 0, vpiMemoryWord}}, + {"clk", {1, vpiInput, 1, vpiPort}, {0, 0, 0, 0}}, + {"testin", {16, vpiInput, 0, vpiPort}, {0, 0, 0, 0}}, + {"testout", {24, vpiOutput, 0, vpiPort}, {0, 0, 0, 0}}, + {"sub.subin", {1, vpiInput, 1, vpiPort}, {0, 0, 0, 0}}, + {"sub.subout", {1, vpiOutput, 1, vpiPort}, {0, 0, 0, 0}}, + {NULL, {0, 0, 0, 0}, {0, 0, 0, 0}} + }; struct params* value = values; while (value->signal) { TestVpiHandle h = VPI_HANDLE(value->signal);