open-simulation-platform / libcosimc

OSP C co-simulation API
Mozilla Public License 2.0
12 stars 2 forks source link

Tests are not compilable on branch feature/conan-2 (Linux environment) #56

Closed simfaucher closed 5 months ago

simfaucher commented 9 months ago

Hello, We have the following error when compiling libcosimc on branch feature/conan-2:

[ 12%] Building C object CMakeFiles/execution_from_ssp_test.dir/tests/execution_from_ssp_test.c.o
[ 19%] Built target inital_values_test
[ 25%] Building C object CMakeFiles/execution_from_ssp_custom_algo_test.dir/tests/execution_from_ssp_custom_algo_test.c.o
[ 35%] Built target connections_test
[ 35%] Built target load_config_and_teardown_test
[ 41%] Built target execution_from_osp_config_test
[ 48%] Built target observer_can_buffer_samples
[ 54%] Built target multiple_fmus_execution_test
[ 61%] Built target observer_multiple_slaves_test
[ 77%] Built target observer_initial_samples_test
[ 77%] Built target simulation_error_handling_test
[ 80%] Built target single_fmu_execution_test
[ 87%] Built target time_series_observer_test
[ 93%] Built target variable_metadata_test
In file included from /usr/include/string.h:535,
                 from /home/developper/DGA/libcosimc/tests/execution_from_ssp_test.c:6:
In function ‘strcpy’,
    inlined from ‘main’ at /home/developper/DGA/libcosimc/tests/execution_from_ssp_test.c:63:9:
In file included from /usr/include/string.h:535,
                 from /home/developper/DGA/libcosimc/tests/execution_from_ssp_custom_algo_test.c:6:
In function ‘strcpy’,
    inlined from ‘main’ at /home/developper/DGA/libcosimc/tests/execution_from_ssp_custom_algo_test.c:72:9:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:79:10: error: ‘__builtin___stpcpy_chk’ offset 2056 is out of the bounds [0, 2056] of object ‘infos’ with type ‘cosim_slave_info[2]’ [-Werror=array-bounds]
   79 |   return __builtin___strcpy_chk (__dest, __src, __glibc_objsize (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:79:10: error: ‘__builtin___stpcpy_chk’ offset 2056 is out of the bounds [0, 2056] of object ‘infos’ with type ‘cosim_slave_info[2]’ [-Werror=array-bounds]
   79 |   return __builtin___strcpy_chk (__dest, __src, __glibc_objsize (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/developper/DGA/libcosimc/tests/execution_from_ssp_test.c: In function ‘main’:
/home/developper/DGA/libcosimc/tests/execution_from_ssp_custom_algo_test.c: In function ‘main’:
/home/developper/DGA/libcosimc/tests/execution_from_ssp_test.c:57:22: note: ‘infos’ declared here
   57 |     cosim_slave_info infos[2];
      |                      ^~~~~
/home/developper/DGA/libcosimc/tests/execution_from_ssp_custom_algo_test.c:66:22: note: ‘infos’ declared here
   66 |     cosim_slave_info infos[2];
      |                      ^~~~~
cc1: all warnings being treated as errors
cc1: all warnings being treated as errors
gmake[2]: *** [CMakeFiles/execution_from_ssp_custom_algo_test.dir/build.make:76: CMakeFiles/execution_from_ssp_custom_algo_test.dir/tests/execution_from_ssp_custom_algo_test.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:244: CMakeFiles/execution_from_ssp_custom_algo_test.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
gmake[2]: *** [CMakeFiles/execution_from_ssp_test.dir/build.make:76: CMakeFiles/execution_from_ssp_test.dir/tests/execution_from_ssp_test.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:270: CMakeFiles/execution_from_ssp_test.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2

The solution is very simple and present on pull request #52 :

for tests execution_from_ssp_custom_algo_test.c, line 66, replace :

cosim_slave_info infos[2];

with

cosim_slave_info infos[3];

The same for execution_from_ssp_test.c, line 57

Could you fix it please? Thank you!

kyllingstad commented 5 months ago

This is strange. As you can see from our CI builds compilation succeeds with GCC 9. I can also compile it just fine locally with GCC 13. However, a colleague of mine experienced the same issue with GCC 12. So it seems to be specific to a certain GCC version range.

I also checked the test code. The current size of infos (2) is correct. This is the number of subsimulators listed in the SSP files used for the test, and it can be verified by printing the numSlaves variable. Furthermore, both the size of name and infos[i].name are the same (SLAVE_NAME_MAX_SIZE), and the subsimulator names given in the SSP files are well within the size bound.

I suspect that this is a GCC bug, perhaps related to issue 89689 or 91890.

I am therefore closing this, but please feel free to reopen if you can point more precisely to what is wrong in our test code.

kyllingstad commented 5 months ago

I can also compile it just fine locally with GCC 13.

Sorry, I spoke too soon. I can reproduce the issue with GCC 13 if I compile with the release build type. But to me, this indicates even more that this is a GCC bug which is related to side effects of compiler optimisations.