From 6cf8fb9b71b97b6b628c933b666b80a641ccb567 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Mon, 13 Nov 2023 22:33:16 -0500 Subject: [PATCH] Fix to incorrect handling of static inlines. Fix to Ruby deprecated interfaces. Fix to keep up with new C standards. --- docs/CMock_Summary.md | 6 +++++- lib/cmock_config.rb | 2 +- test/.ruby-version | 1 + test/rakefile | 2 +- test/rakefile_helper.rb | 2 +- test/system/test_compilation/osek.h | 2 +- test/system/test_interactions/skeleton_update.yml | 2 +- 7 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 test/.ruby-version diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index e63a065..7c517e7 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -608,17 +608,19 @@ from the defaults. We've tried to specify what the defaults are below. - "static inline" - "inline static" - "inline" - - "static" + You can override these patterns, check out :inline_function_patterns. Enabling this feature does require a change in the build system that is using CMock. To understand why, we need to give some more info on how we are handling inline functions internally. + Let's say we want to mock a header called example.h. example.h contains inline functions, we cannot include this header in the mocks or test code if we want to mock the inline functions simply because the inline functions contain an implementation that we want to override in our mocks! + So, to circumvent this, we generate a new header, also named example.h, in the same directory as mock_example.h/c . This newly generated header should/is exactly the same as the original header, @@ -626,11 +628,13 @@ from the defaults. We've tried to specify what the defaults are below. functions declarations. Placing the new header in the same directory as mock_example.h/c ensures that they will include the new header and not the old one. + However, CMock has no control in how the build system is configured and which include paths the test code is compiled with. In order for the test code to also see the newly generated header ,and not the old header with inline functions, the build system has to add the mock folder to the include paths. + Furthermore, we need to keep the order of include paths in mind. We have to set the mock folder before the other includes to avoid the test code including the original header instead of the newly diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 16d917b..b2df4cd 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -50,7 +50,7 @@ class CMockConfig # - The keywords can appear before or after the return type (this is a compiler warning but people do weird stuff), # so we check for word boundaries when searching for them # - We first remove "static inline" combinations and boil down to single inline or static statements - :inline_function_patterns => ['(static\s+inline|inline\s+static)\s*', '(\bstatic\b|\binline\b)\s*', '(?:static\s*)?(?:__inline__)?__attribute__\s*\([ (]*always_inline[ )]*\)', 'static __inline__'] # Last part (\s*) is just to remove whitespaces (only to prettify the output) + :inline_function_patterns => ['(static\s+inline|inline\s+static)\s*', '(\binline\b)\s*', '(?:static\s*)?(?:__inline__)?__attribute__\s*\([ (]*always_inline[ )]*\)', 'static __inline__'] # Last part (\s*) is just to remove whitespaces (only to prettify the output) }.freeze def initialize(options = nil) diff --git a/test/.ruby-version b/test/.ruby-version new file mode 100644 index 0000000..944880f --- /dev/null +++ b/test/.ruby-version @@ -0,0 +1 @@ +3.2.0 diff --git a/test/rakefile b/test/rakefile index c57c715..0169eaa 100644 --- a/test/rakefile +++ b/test/rakefile @@ -140,7 +140,7 @@ namespace :style do end task :clean do - File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml") + File.delete(".rubocop_todo.yml") if File.exist?(".rubocop_todo.yml") end end diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 1ce0865..bffb3ad 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -66,7 +66,7 @@ module RakefileHelpers def find_source_file(header, paths) paths.each do |dir| src_file = dir + header.ext(C_EXTENSION) - if (File.exists?(src_file)) + if (File.exist?(src_file)) return src_file end end diff --git a/test/system/test_compilation/osek.h b/test/system/test_compilation/osek.h index f3abe7b..8db9cb8 100644 --- a/test/system/test_compilation/osek.h +++ b/test/system/test_compilation/osek.h @@ -242,7 +242,7 @@ void OSEKOSStartupEnable(void); void OSEKOSNop(void); unsigned int OSEKOSV850CheckIsrSwitch(void); void OSEKOSV850InitInterrupts(void); -void OSEKOSV850SetupInterrupts(); +void OSEKOSV850SetupInterrupts(void); void OSEKOSV850SyncContextLoad(OSEKOSSaveType); void OSEKOSV850SyncContextLoadFromIRQ(OSEKOSSaveType); void OSEKOSV850ASyncContextLoad(OSEKOSSaveType); diff --git a/test/system/test_interactions/skeleton_update.yml b/test/system/test_interactions/skeleton_update.yml index 757e8b1..e4031e8 100644 --- a/test/system/test_interactions/skeleton_update.yml +++ b/test/system/test_interactions/skeleton_update.yml @@ -37,7 +37,7 @@ :common: | void setUp(void) {} void tearDown(void) {} - extern int function_d(); + extern int function_d(void); :units: - :pass: TRUE