OpenModelica / OMSimulator

The OpenModelica FMI & SSP-based co-simulation environment.
Other
71 stars 50 forks source link

Catch segmentation fault for broken FMU #787

Closed AnHeuermann closed 4 years ago

AnHeuermann commented 4 years ago

Description

When testing Rectifier.fmu from FMI Cross-Check we get a segmentation fault. This happens in other tools as well and the FMU is marked as notCompliantWithLatestRules.

Steps to reproduce the behavior

To simulate FMU Rectifier.fmu with OMSimulator run

$ OMSimulator Rectifier.lua

Lua file:

-- Lua file for Rectifier.fmu
oms_setTempDirectory("temp")
oms_newModel("model")
oms_addSystem("model.root", oms_system_wc)

-- instantiate FMU
oms_addSubModel("model.root.fmu", "Rectifier.fmu")

-- Simulation settings
oms_setSignalFilter("model", ".*")
oms_setResultFile("model", "Rectifier_out.csv")
oms_setStartTime("model", 0.0)
oms_setStopTime("model", 0.1)
oms_setTolerance("model", 1e-8)
initialStepSize, minimumStepSize, maximumStepSize, status = oms_getVariableStepSize("model")
oms_setVariableStepSize("model", 1e-07, minimumStepSize, 1e-07)
oms_setFixedStepSize("model", 1e-07)

-- Instantiate, initialize and simulate
oms_instantiate("model")
oms_initialize("model")
oms_simulate("model")
oms_terminate("model")
oms_delete("model")

Expected behavior

If possible I would like to be able to catch this error before failing with a segmentation fault and reporting a helpful error message to the user.

Output from gdb

When running it with gdb we get:

$ gdb OMSimulator 
(gdb) r Rectifier.lua
Starting program: /home/aheuermann1/workspace/OpenModelica/build/bin/OMSimulator Rectifier.lua
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
info:    Set temp directory to    "/home/aheuermann1/workspace/OpenModelica/OMSimulator/testsuite/fmi-cross-check/fmi-cross-check/results/2.0/cs/linux64/OMSimulator/v2.1.0/MapleSim/2016.1/Rectifier"
info:    Set working directory to "/home/aheuermann1/workspace/OpenModelica/OMSimulator/testsuite/fmi-cross-check/fmi-cross-check/results/2.0/cs/linux64/OMSimulator/v2.1.0/MapleSim/2016.1/Rectifier"
info:    Set temp directory to    "/home/aheuermann1/workspace/OpenModelica/OMSimulator/testsuite/fmi-cross-check/fmi-cross-check/results/2.0/cs/linux64/OMSimulator/v2.1.0/MapleSim/2016.1/Rectifier/temp"
info:    New model "model" with corresponding temp directory "/home/aheuermann1/workspace/OpenModelica/OMSimulator/testsuite/fmi-cross-check/fmi-cross-check/results/2.0/cs/linux64/OMSimulator/v2.1.0/MapleSim/2016.1/Rectifier/temp/model-8yutriof"
error:   [fmiLogger] module FMI2XML: Start attribute is required for this causality, variability and initial combination

Program received signal SIGSEGV, Segmentation fault.
oms::Variable::getCausality (this=0xe2d20000086d13c0) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/Variable.cpp:88
88        switch (causality)
(gdb) bt
#0  oms::Variable::getCausality (this=0xe2d20000086d13c0) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/Variable.cpp:88
#1  0x0000000000568e7b in oms::Variable::makeConnector (this=0xe2d20000086d13c0) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/../OMSimulatorLib/Variable.h:90
#2  oms::ComponentFMUCS::initializeDependencyGraph_initialUnknowns (this=<optimized out>) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/ComponentFMUCS.cpp:380
#3  0x0000000000568227 in oms::ComponentFMUCS::NewComponent (cref=..., parentSystem=<optimized out>, fmuPath=...) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/ComponentFMUCS.cpp:240
#4  0x00000000004e1e13 in oms::System::addSubModel (this=0x9f8910, cref=..., Python Exception <class 'gdb.error'> There is no member named _M_dataplus.:
path=) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/System.cpp:286
#5  0x00000000004b6030 in oms_addSubModel (cref=<optimized out>, fmuPath=0x9eda58 "../../../../../../../../../fmus/2.0/cs/linux64/MapleSim/2016.1/Rectifier/Rectifier.fmu") at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/OMSimulator.cpp:807
#6  0x000000000049f521 in OMSimulatorLua_oms_addSubModel (L=0x9edac8) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/../OMSimulatorLua/OMSimulatorLua.c:895
#7  0x000000000063fa16 in luaD_precall (L=0x9edac8, func=0x9ed1f0, nresults=0) at ldo.c:434
#8  0x000000000064b2ed in luaV_execute (L=0x9edac8) at lvm.c:1134
#9  0x000000000063fc74 in luaD_call (L=0x9edac8, func=<optimized out>, nResults=<optimized out>) at ldo.c:499
#10 luaD_callnoyield (L=0x9edac8, func=<optimized out>, nResults=<optimized out>) at ldo.c:509
#11 0x000000000063eeae in luaD_rawrunprotected (L=0x9edac8, f=0x63d3d0 <f_call>, ud=0x7fffffffd890) at ldo.c:142
#12 0x000000000064024b in luaD_pcall (L=0x9edac8, func=0x9c4010, u=0x9c4010, old_top=16, ef=0) at ldo.c:729
#13 0x000000000063d340 in lua_pcallk (L=0x9edac8, nargs=<optimized out>, nresults=0, errfunc=<optimized out>, ctx=<optimized out>, k=0x335b4341692e3172) at lapi.c:968
#14 0x00000000004bc886 in oms_RunFile (filename_=<optimized out>) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/OMSimulator.cpp:1101
#15 0x000000000059b5b8 in oms::Flags::SetCommandLineOption (cmd=...) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/Flags.cpp:168
#16 0x00000000004a72fc in oms_setCommandLineOption (cmd=0x7fffffffdbf8 "Rectifier.lua") at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulatorLib/OMSimulator.cpp:373
#17 0x000000000049e12e in main (argc=<optimized out>, argv=0x7fffffffdd18) at /home/aheuermann1/workspace/OpenModelica/OMSimulator/src/OMSimulator/main.cpp:45

OMSimulator/src/OMSimulatorLib/Variable.cpp:

oms_causality_enu_t oms::Variable::getCausality() const
{
  switch (causality)
  {
  case fmi2_causality_enu_input:
    return oms_causality_input;

  case fmi2_causality_enu_output:
    return oms_causality_output;

  case fmi2_causality_enu_parameter:
    return oms_causality_parameter;

  default:
    return oms_causality_undefined;
  }
}

Version and OS

superlou commented 4 years ago

Any chance this is related to #767? The seg. fault seems to be a different mechanism, but maybe the root cause is similar.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.