From 72b356b97d723a8bb9e331ef65af26c472bf7417 Mon Sep 17 00:00:00 2001 From: Jean Rubillon Date: Tue, 8 Sep 2020 20:50:48 +0100 Subject: [PATCH 1/4] Added option to remove setjmp.h from generated mock files as not supported on all embedded systems --- docs/CMock_Summary.md | 7 +++++++ lib/cmock_config.rb | 1 + lib/cmock_generator.rb | 9 +++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index efd50a3..4e700e0 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -477,6 +477,13 @@ from the defaults. We've tried to specify what the defaults are below. * default: `['(?:__attribute__\s*\(+.*?\)+)']` +* `:has_setjmp_h`: + Some embedded systems don't have available. Setting this to false + removes references to this header file and the ability to use cexception. + + * default: true + + * `:subdir`: This is a relative subdirectory for your mocks. Set this to e.g. "sys" in order to create a mock for `sys/types.h` in `(:mock_path)/sys/`. diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 9515481..2a3e5f8 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -41,6 +41,7 @@ class CMockConfig :array_size_type => [], :array_size_name => 'size|len', :skeleton => false, + :has_setjmp_h => true, # Format to look for inline functions. # This is a combination of "static" and "inline" keywords ("static inline", "inline static", "inline", "static") diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index f08cadd..f0372a3 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -19,6 +19,7 @@ class CMockGenerator @ordered = @config.enforce_strict_ordering @framework = @config.framework.to_s @fail_on_unexpected_calls = @config.fail_on_unexpected_calls + @has_setjmp_h = @config.has_setjmp_h @subdir = @config.subdir @@ -169,7 +170,9 @@ class CMockGenerator file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless functions.empty? file << "#include \n" file << "#include \n" - file << "#include \n" + if @has_setjmp_h + file << "#include \n" + end file << "#include \"cmock.h\"\n" @includes_c_pre_header.each { |inc| file << "#include #{inc}\n" } file << "#include \"#{header_file}\"\n" @@ -205,7 +208,9 @@ class CMockGenerator end def create_extern_declarations(file) - file << "extern jmp_buf AbortFrame;\n" + if @has_setjmp_h + file << "extern jmp_buf AbortFrame;\n" + end if @ordered file << "extern int GlobalExpectCount;\n" file << "extern int GlobalVerifyOrder;\n" From 21d181380f2de2a01c3020c490281a6d2f754628 Mon Sep 17 00:00:00 2001 From: Jean Rubillon Date: Tue, 8 Sep 2020 21:04:21 +0100 Subject: [PATCH 2/4] Signal that cexception needs setjmp to be supported. --- lib/cmock_generator_plugin_cexception.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cmock_generator_plugin_cexception.rb b/lib/cmock_generator_plugin_cexception.rb index a757669..b3ea13a 100644 --- a/lib/cmock_generator_plugin_cexception.rb +++ b/lib/cmock_generator_plugin_cexception.rb @@ -12,6 +12,7 @@ class CMockGeneratorPluginCexception @config = config @utils = utils @priority = 7 + raise 'Error: cexception is not supported without setjmp support' unless @config.has_setjmp_h end def include_files From 4ae268dbbed5d51e8dc51bda515b58daacf72517 Mon Sep 17 00:00:00 2001 From: Jean Rubillon Date: Wed, 27 Jan 2021 18:56:02 +0000 Subject: [PATCH 3/4] Changed has_setjmp_h option to exclude_setjmp_h --- docs/CMock_Summary.md | 6 +++--- lib/cmock_config.rb | 2 +- lib/cmock_generator.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index 4e700e0..9a89634 100644 --- a/docs/CMock_Summary.md +++ b/docs/CMock_Summary.md @@ -477,11 +477,11 @@ from the defaults. We've tried to specify what the defaults are below. * default: `['(?:__attribute__\s*\(+.*?\)+)']` -* `:has_setjmp_h`: - Some embedded systems don't have available. Setting this to false +* `:exclude_setjmp_h`: + Some embedded systems don't have available. Setting this to true removes references to this header file and the ability to use cexception. - * default: true + * default: false * `:subdir`: diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 2a3e5f8..716a0c5 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -41,7 +41,7 @@ class CMockConfig :array_size_type => [], :array_size_name => 'size|len', :skeleton => false, - :has_setjmp_h => true, + :exclude_setjmp_h => false, # Format to look for inline functions. # This is a combination of "static" and "inline" keywords ("static inline", "inline static", "inline", "static") diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index f0372a3..ec06ab4 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -170,7 +170,7 @@ class CMockGenerator file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless functions.empty? file << "#include \n" file << "#include \n" - if @has_setjmp_h + unless @exclude_setjmp_h file << "#include \n" end file << "#include \"cmock.h\"\n" @@ -208,7 +208,7 @@ class CMockGenerator end def create_extern_declarations(file) - if @has_setjmp_h + unless @exclude_setjmp_h file << "extern jmp_buf AbortFrame;\n" end if @ordered From 9e1c6c068d4b5a35ba4f91042e23e1cb75bed131 Mon Sep 17 00:00:00 2001 From: Jean Rubillon Date: Thu, 28 Jan 2021 12:57:02 +0000 Subject: [PATCH 4/4] Fix missed has_setjmp_h convert to exclude_setjmp_h --- lib/cmock_generator.rb | 2 +- lib/cmock_generator_plugin_cexception.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index ec06ab4..92f3289 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -19,7 +19,7 @@ class CMockGenerator @ordered = @config.enforce_strict_ordering @framework = @config.framework.to_s @fail_on_unexpected_calls = @config.fail_on_unexpected_calls - @has_setjmp_h = @config.has_setjmp_h + @exclude_setjmp_h = @config.exclude_setjmp_h @subdir = @config.subdir diff --git a/lib/cmock_generator_plugin_cexception.rb b/lib/cmock_generator_plugin_cexception.rb index b3ea13a..7e2d7b6 100644 --- a/lib/cmock_generator_plugin_cexception.rb +++ b/lib/cmock_generator_plugin_cexception.rb @@ -12,7 +12,7 @@ class CMockGeneratorPluginCexception @config = config @utils = utils @priority = 7 - raise 'Error: cexception is not supported without setjmp support' unless @config.has_setjmp_h + raise 'Error: cexception is not supported without setjmp support' if @config.exclude_setjmp_h end def include_files