Why do my inline functions not show coverage even though they are being called and I have turned on the option "Provide code coverage in header files?"
Or is there any Bullseye options?
Related
We are working with a tool that generates C-code. For example, the C-code could be for the logic: "if a sensor is activated, turn on the LED bulb". The code can be saved into a function that can be called from outside. What is the best way to embed this kind of external C-code into the rest of the Modelica model? How can we compile this code along with the rest of the .mo files preferably using OM Shell script and omc?
You can directly put C code in external functions or link with a library.
See:
https://specification.modelica.org/v3.4/Ch12.html#external-function-interface
https://specification.modelica.org/v3.4/Ch12.html#external-objects
As examples see some of our tests from the testsuite:
https://github.com/OpenModelica/OpenModelica/blob/master/testsuite/simulation/modelica/
Simple example:
https://github.com/OpenModelica/OpenModelica/blob/master/testsuite/simulation/modelica/external_functions/ExternalLibraries.mo
https://github.com/OpenModelica/OpenModelica/blob/master/testsuite/simulation/modelica/external_functions/ExternalLibraries.mos
https://github.com/OpenModelica/OpenModelica/blob/master/testsuite/simulation/modelica/external_functions/ExternalFunc1.c
https://github.com/OpenModelica/OpenModelica/blob/master/testsuite/simulation/modelica/external_functions/ExternalFunc2.c
Some advanced libraries:
https://github.com/modelica-3rdparty/Modelica_DeviceDrivers
https://github.com/modelica-3rdparty/ExternData
Using Dymola, I'm looking for a way to automatically execute a script when loading a library. The intention is to define additional displayUnits using the defineUnitConversion() command, which are specific to the library that is loaded. Still I think there are quite some other cases where this could be helpful.
What I figured out in this regard:
I know that it is possible to add conversions to the file in DymolaInstallDir/insert/displayUnits.mos but this comes with the disadvantage that is has to be done again on every new computer or after an update of Dymola. I would like to avoid this.
Other than that I only found the libraryinfo.mos file, which seems to be read during the start-up of Dymola. Therefore I assume it is not the right place to put the conversions, as it contains general information about the library and should only contain the respective functions.
Dymola 2022 has a new (tool-specific) feature that covers exactly this use-case. It is mentioned in the Dymola 2022 release notes in the section "Library startup script" on page 24.
It basically introduces the a new annotation, which allows to specify a path to a .mos script, which is executed, when the respective library is loaded. Here is the example from the release notes:
package ThisPack
annotation(__Dymola_startup =
"modelica://ThisPack/Resources/Scripts/Dymola/startup.mos");
end ThisPack;
The annotation can also be set via the UI...
I have common files in several projects and I need to stop from compiling some lines and functions for project A, meanwhile it should be compiled for project B.
I know that I can use preprocessor. But it's not convenient for me. Is there any way to stop lines of code from compiling with condition like below?
#if PhotosModuleSettings.type == .documents
... do not commpile
#endif
What's not convenient about using the preprocessor? You can specify the preprocessor macros in build settings of each target, or you can use .xcconfig files to specify them.
There's another simple way to do it, however. Separate the lines and functions that you want to conditionally compile into separate files. Maybe by using Swift extensions or subclassing or just separate global functions, etc..whatever. Then just choose which target(s) and/or project(s) you want those files added as membership.
Depending on your desire to refactor your code to make such a file separation, the preprocessor macros may be the better way to go, though.
You will need to make use of pre processor macros.
Add a configuration for your project, and use that in the pre processor macros.
You can set the value for these configuration in the pre processor macros section for your targets based on your build configuration.
Here is a detailed blog related to the same concept
I've got a bunch of C# code that's covered by both unit tests and system tests. I'd like to find those parts of the code that are covered by both, by only the unit tests and by only the system tests.
I've can generate coverage reports for the two sets (unit tests vs system tests) by using JetBrains dotCover.
How do I compare these two coverage reports?
I've got NDepend, if that helps.
Roger, with NDepend you can still import several DotCover coverage xml files (with the right DotCover XML for NDepend setting).
I'd like to find those parts of the code that are covered by both
Use the Merge Option AND as shown on the screenshot below. This will help, it will tell you which method are covered by both tests sets.
If you need to zoom at line by line level covered by both tests sets, unless NCover has tooling for that, you'll need to programatically do the merge of the two coverage files by yourself (it should be not that hard).
I have a workspace built using MS-Visual Studio 2005 with all C code.In that i see many functions which are not called but they are still compiled(they are not under any compile time macro to disable them from compiling).
I set following optimization settings for the MS-VS2005 project to remove that unused code:-
Optimization level - /Ox
Enable whole program optimization - /GL
I tried both Favor speed /Ot and Favor Size /Os
Inspite of all these options, when i see the linker generated map file, I see the symbols(unsed functions) names present in the map file.
Am I missing something? I want to completely remove the unused code.
How do I do this?
The compiler compiles C files one-at-a-time. Therefore, while compiling a C-file that does contains an unused function, the compiler cannot be sure that it will not be called from another file and hence it will compile that function too. However, if that function were declared as static (file-scope), then the compiler would know it is not used and hence remove it.
Even with whole program optimization, I think it would still not be done since the compilation could be for a library.
Linkers do something similar to what you are looking for. If your code links against a library containing multiple objects, then any objects that do not contain functions used by your code (directly or indirectly) would not be included in the final executable.
One option would be to separate your code into individual libraries and object files.
PS - This is just my guess. The behavior of the compiler (with whole program optimization) or linker essentially depends on the design choices of that particular compiler or linker
On our projects we have a flag set under the project properties\Linker\Refrences. We set it to Eliminate Unreferenced Data (/OPT:REF), according to the description this is supposed to remove function calls or data that are never used. I am just going by the description, I have never tested this or worked with it. But I just happened to see it within the last hour and figured it might be something you could try.