Repository: cocotb/cocotb

Issue:
Abusive use of LOG_CRITICAL causes crash in Questa
The LOG_CRITICAL is used in many places in the code where the problematic situation should be recovered properly. The use of LOG_CRITICAL with the exit() function causes a nasty crash in Questa, see below. In this example, the provided toplevel cannot be found in the design... such error should output an error message rather than such a crash.

LD_LIBRARY_PATH=/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7:/usr/lib:/usr/lib:/usr/lib:/usr/lib \
        MODULE=fpga_tb1 \
        TESTCASE= \
        TOPLEVEL=fpga_tb_v1 \
        PYTHONPATH=/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7:/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb:/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/src/fpga/test/testbench \
        /data/questasim/linux_x86_64/vsim -pli libvpi.so -L altera_ver -L lpm_ver -L sgate_ver -L altera_mf_ver -L altera_lnsim_ver -L twentynm_ver -L twentynm_hssi_ver -L twentynm_hip_ver -L altera_common_sv_packages -L tse_mac_phy_altera_reset_controller_150 -L tse_mac_phy_altera_eth_tse_nf_phyip_terminator_150 -L tse_mac_phy_altera_xcvr_native_a10_150 -L tse_mac_phy_altera_eth_tse_pcs_pma_nf_phyip_150 -L xcvr_rx_phy_12ch_altera_xcvr_native_a10_150 -L altera -L lpm -L sgate -L altera_mf -L altera_lnsim -L twentynm -L twentynm_hssi -L twentynm_hip -L xcvr_tx_atxpll_12ch_altera_xcvr_atx_pll_a10_150 -L tse_mac_phy_altera_eth_tse_avalon_arbiter_150 -L tse_mac_phy_altera_eth_tse_mac_150 -L xcvr_tx_reset_12ch_altera_xcvr_reset_control_150 -L tse_reset_altera_xcvr_reset_control_150 -L xcvr_tx_phy_12ch_altera_xcvr_native_a10_150 -L iopll_160_altera_iopll_150 -L lli_altera -L clk_ctrl_altclkctrl_150 -L istage_altera -L tse_atxpll_altera_xcvr_atx_pll_a10_150 -L xcvr_rx_reset_12ch_altera_xcvr_reset_control_150 -L fifo_fifo_150 -L Pattern_ram_ram_2port_150 -L fpga_tb -L tse_mac_phy_altera_eth_tse_150 -L fpga -L istage -L bitvis_util -L ipctrl -L lli -L user -L remap -L ttc -L osum -L mon -L testbench -L work -l logs/vsim.log -wlf logs/vsim.wlf -error 3473 -voptargs=+acc -multisource_delay latest -t ps +typdelays -c -do logs/vsim_sim.do "fpga_tb.fpga_tb_v"
Reading pref.tcl
#10.2c_5
# vsim -L altera_ver -L lpm_ver -L sgate_ver -L altera_mf_ver -L altera_lnsim_ver -L twentynm_ver -L twentynm_hssi_ver -L twentynm_hip_ver -L altera_common_sv_packages -L tse_mac_phy_altera_reset_controller_150 -L tse_mac_phy_altera_eth_tse_nf_phyip_terminator_150 -L tse_mac_phy_altera_xcvr_native_a10_150 -L tse_mac_phy_altera_eth_tse_pcs_pma_nf_phyip_150 -L xcvr_rx_phy_12ch_altera_xcvr_native_a10_150 -L altera -L lpm -L sgate -L altera_mf -L altera_lnsim -L twentynm -L twentynm_hssi -L twentynm_hip -L xcvr_tx_atxpll_12ch_altera_xcvr_atx_pll_a10_150 -L tse_mac_phy_altera_eth_tse_avalon_arbiter_150 -L tse_mac_phy_altera_eth_tse_mac_150 -L xcvr_tx_reset_12ch_altera_xcvr_reset_control_150 -L tse_reset_altera_xcvr_reset_control_150 -L xcvr_tx_phy_12ch_altera_xcvr_native_a10_150 -L iopll_160_altera_iopll_150 -L lli_altera -L clk_ctrl_altclkctrl_150 -L istage_altera -L tse_atxpll_altera_xcvr_atx_pll_a10_150 -L xcvr_rx_reset_12ch_altera_xcvr_reset_control_150 -L fifo_fifo_150 -L Pattern_ram_ram_2port_150 -L fpga_tb -L tse_mac_phy_altera_eth_tse_150 -L fpga -L istage -L bitvis_util -L ipctrl -L lli -L user -L remap -L ttc -L osum -L mon -L testbench -L work -do logs/vsim_sim.do -error 3473 -l logs/vsim.log -voptargs=+acc -c -multisource_delay latest -pli libvpi.so -t ps -wlf logs/vsim.wlf +typdelays fpga_tb.fpga_tb_v
# *\* Note: (vsim-3812) Design is being optimized...
# *\* Note: (vsim-3865) Due to PLI being present, full design access is being specified.
# Loading /userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libvpi.so
# //  Questa Sim-64
# //  Version 10.2c_5 linux_x86_64 Nov 19 2013
# //
# //  Copyright 1991-2013 Mentor Graphics Corporation
# //  All Rights Reserved.
# //
# //  THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION
# //  WHICH IS THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS
# //  LICENSORS AND IS SUBJECT TO LICENSE TERMS.
# //
# -.--ns INFO     cocotb.gpi                                GpiCommon.cpp:47   in gpi_print_registered_impl       VPI registered
# Loading work.fpga_tb_v(fast)
# do logs/vsim_sim.do
# *\* Error: (vish-4014) No objects found matching '/fpga_tb/fpga/reset_n'.
# Executing ONERROR command at macro ./logs/vsim_sim.do line 1
# *\* Error: (vish-4014) No objects found matching '/*'.
# Executing ONERROR command at macro ./logs/vsim_sim.do line 2
# Attempting stack trace sig 11
# Signal caught: signo [11]
# vsim_stacktrace.vstf written
# Current time Mon Sep  7 11:46:29 2015
# QuestaSim Stack Trace
# Program = vsim
# Id = "10.2c_5"
# Version = "2013.11"
# Date = "Nov 19 2013"
# Platform = linux_x86_64
# --> START OF USERCODE
#0    0x00007fffecccaebc: 'gpi_get_sim_time + 0x2c' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libgpi.so'
#1    0x00007fffe94f4d27: 'get_sim_time + 0x2b' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/env/cocotb/build/libs/i686/python2.7/simulator.so'
#2    0x00007fffec4bac30: 'PyEval_EvalFrameEx + 0x5a40' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#3    0x00007fffec4bb0db: 'PyEval_EvalFrameEx + 0x5eeb' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#4    0x00007fffec4bb0db: 'PyEval_EvalFrameEx + 0x5eeb' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#5    0x00007fffec4bb0db: 'PyEval_EvalFrameEx + 0x5eeb' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#6    0x00007fffec4bb0db: 'PyEval_EvalFrameEx + 0x5eeb' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#7    0x00007fffec4bb0db: 'PyEval_EvalFrameEx + 0x5eeb' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#8    0x00007fffec4bb0db: 'PyEval_EvalFrameEx + 0x5eeb' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#9    0x00007fffec4bc74e: 'PyEval_EvalCodeEx + 0x88e' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#10   0x00007fffec43a8a8: 'function_call + 0x198' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#11   0x00007fffec40b293: 'PyObject_Call + 0x53' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#12   0x00007fffec4b9335: 'PyEval_EvalFrameEx + 0x4145' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#13   0x00007fffec4bc74e: 'PyEval_EvalCodeEx + 0x88e' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#14   0x00007fffec4bad87: 'PyEval_EvalFrameEx + 0x5b97' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#15   0x00007fffec4bc74e: 'PyEval_EvalCodeEx + 0x88e' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#16   0x00007fffec43a7a1: 'function_call + 0x91' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#17   0x00007fffec40b293: 'PyObject_Call + 0x53' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#18   0x00007fffec4b42f3: 'PyEval_CallObjectWithKeywords + 0x43' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#19   0x00007fffebf99bb7: 'embed_sim_event + 0xb3' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libcocotb.so'
#20   0x00007fffeccca98f: 'gpi_embed_end() + 0x15' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libgpi.so'
#21   0x00007fffed0e0221: 'VpiShutdownCbHdl::run_callback() + 0x11' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libvpi.so'
#22   0x00007fffed0dcf57: 'handle_vpi_callback + 0xea' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libvpi.so'
# <-- END OF USERCODE
#23   0x0000000000656486: '<unknown (@0x656486)>'
#24   0x0000000000656652: '<unknown (@0x656652)>'
#25   0x0000000000a79787: '<unknown (@0xa79787)>'
#26   0x00000000007b2f81: '<unknown (@0x7b2f81)>'
#27   0x0000003db3635b22: 'exit + 0xe2' in '/lib64/libc.so.6'
# --> START OF USERCODE
#28   0x00007fffed0dcc1a: 'VpiImpl::get_root_handle(char const*) + 0x21e' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libvpi.so'
#29   0x00007fffecccaf6a: 'gpi_get_root_handle + 0x94' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libgpi.so'
#30   0x00007fffe94f4bc2: 'get_root_handle + 0x55' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/env/cocotb/build/libs/i686/python2.7/simulator.so'
#31   0x00007fffec4bac30: 'PyEval_EvalFrameEx + 0x5a40' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#32   0x00007fffec4bb0db: 'PyEval_EvalFrameEx + 0x5eeb' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#33   0x00007fffec4bc74e: 'PyEval_EvalCodeEx + 0x88e' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#34   0x00007fffec43a7a1: 'function_call + 0x91' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#35   0x00007fffec40b293: 'PyObject_Call + 0x53' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#36   0x00007fffec4b42f3: 'PyEval_CallObjectWithKeywords + 0x43' in '/userselec/chevillot/tools/lib/libpython2.7.so.1.0'
#37   0x00007fffebf999e1: 'embed_sim_init + 0x5d7' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libcocotb.so'
#38   0x00007fffeccca96a: 'gpi_embed_init(gpi_sim_info_s*) + 0x18' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libgpi.so'
#39   0x00007fffed0e00d8: 'VpiStartupCbHdl::run_callback() + 0x42' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libvpi.so'
#40   0x00007fffed0dcf57: 'handle_vpi_callback + 0xea' in '/userselec/chevillot/Projects/ATLAS/git/cocotb/atlas-lar-ldpb-firmware/LATOME/../env/cocotb/build/libs/i686/python2.7/libvpi.so'
# <-- END OF USERCODE
#41   0x0000000000656486: '<unknown (@0x656486)>'
#42   0x00000000006566d6: '<unknown (@0x6566d6)>'
#43   0x0000000000a79787: '<unknown (@0xa79787)>'
#44   0x00000000008c23aa: '<unknown (@0x8c23aa)>'
#45   0x00000000008c36fe: '<unknown (@0x8c36fe)>'
#46   0x0000000000ec983f: '<unknown (@0xec983f)>'
#47   0x0000000000eca9f9: '<unknown (@0xeca9f9)>'
#48   0x0000000000f0d1ba: '<unknown (@0xf0d1ba)>'
#49   0x0000000000f15cef: '<unknown (@0xf15cef)>'
#50   0x0000000000ecbd13: '<unknown (@0xecbd13)>'
#51   0x0000000000ed6ba4: '<unknown (@0xed6ba4)>'
#52   0x0000000000eca9f9: '<unknown (@0xeca9f9)>'
#53   0x0000000000f0d1ba: '<unknown (@0xf0d1ba)>'
#54   0x0000000000f16010: '<unknown (@0xf16010)>'
#55   0x0000000000ec93e3: '<unknown (@0xec93e3)>'
#56   0x0000000000edbea8: '<unknown (@0xedbea8)>'
#57   0x0000000000eca9f9: '<unknown (@0xeca9f9)>'
#58   0x0000000000ecb646: '<unknown (@0xecb646)>'
#59   0x0000000000ecb9c6: '<unknown (@0xecb9c6)>'
#60   0x0000000000c0798c: '<unknown (@0xc0798c)>'
#61   0x0000000000f26a11: '<unknown (@0xf26a11)>'
#62   0x0000000000f6fda1: '<unknown (@0xf6fda1)>'
#63   0x0000000000f3c4cd: '<unknown (@0xf3c4cd)>'
#64   0x0000000000f3c805: '<unknown (@0xf3c805)>'
#65   0x0000000000dff3e6: '<unknown (@0xdff3e6)>'
#66   0x00000000008a6c5b: '<unknown (@0x8a6c5b)>'
# End of Stack Trace

*\* Fatal: (SIGSEGV) Bad pointer access. Closing vsimk.
*\* Fatal: vsimk is exiting with code 211.
(Exit codes are defined in the QuestaSim messages appendix
of the QuestaSim User's Manual.)

*\* Fatal: Trouble with Simulation Kernel.
#0.00ns INFO     cocotb.gpi                                  gpi_embed.c:237  in embed_sim_init                  Running on ModelSim for Questa-64 version 10.2c_5 2013.11
#0.00ns INFO     cocotb.gpi                                  gpi_embed.c:238  in embed_sim_init                  Python interpreter initialised and cocotb loaded!
#0.00ns INFO     cocotb                                      **init**.py:109  in _initialise_testbench           Unable to determine Cocotb version from Unknown
#0.00ns INFO     cocotb                                      **init**.py:128  in _initialise_testbench           Seeding Python random module with 1441619189
# DBG: RegressionManager: **init**: modules=['fpga_tb1']
#0.00ns CRITICAL cocotb.gpi                                  VpiImpl.cpp:194  in get_root_handle                 VPI: Couldn't find root handle fpga_tb_v1

make[1]: **\* [simulation] Error 15



Discussion:

Resolving patch:
diff --git a/cocotb/regression.py b/cocotb/regression.py
--- a/cocotb/regression.py
+++ b/cocotb/regression.py
@@ -101,8 +101,10 @@ def initialise(self):
             self._cov = coverage.coverage(branch=True, omit=["*cocotb*"])
             self._cov.start()
 
-        self._dut = cocotb.handle.SimHandle(simulator.get_root_handle(
-                                            self._root_name))
+        handle = simulator.get_root_handle(self._root_name)
+
+        self._dut = cocotb.handle.SimHandle(handle) if handle else None
+
         if self._dut is None:
             raise AttributeError("Can not find Root Handle (%s)" %
                                  self._root_name)


Test patch: