From 325b6b333ab2229a39d2f0b3a9b219b9b7c1fdd6 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 29 Jan 2021 10:06:08 -0500 Subject: [PATCH 1/3] Revert "Revert "CMock can now compile without setjmp.h present on the platform"" This reverts commit 3eccb8e3d42233b44c98854be16dbd7703795a0e. --- docs/CMock_Summary.md | 7 +++++++ lib/cmock_config.rb | 1 + lib/cmock_generator.rb | 9 +++++++-- lib/cmock_generator_plugin_cexception.rb | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md index efd50a37..9a896347 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*\(+.*?\)+)']` +* `: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: false + + * `: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 9515481c..716a0c55 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, + :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 b4428954..fdc29b1f 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -19,6 +19,7 @@ def initialize(config, file_writer, utils, plugins) @ordered = @config.enforce_strict_ordering @framework = @config.framework.to_s @fail_on_unexpected_calls = @config.fail_on_unexpected_calls + @exclude_setjmp_h = @config.exclude_setjmp_h @subdir = @config.subdir @folder = nil @@ -182,7 +183,9 @@ def create_source_header_section(file, filename, functions) file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless functions.empty? file << "#include \n" file << "#include \n" - file << "#include \n" + unless @exclude_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" @@ -218,7 +221,9 @@ def create_instance_structure(file, functions) end def create_extern_declarations(file) - file << "extern jmp_buf AbortFrame;\n" + unless @exclude_setjmp_h + file << "extern jmp_buf AbortFrame;\n" + end if @ordered file << "extern int GlobalExpectCount;\n" file << "extern int GlobalVerifyOrder;\n" diff --git a/lib/cmock_generator_plugin_cexception.rb b/lib/cmock_generator_plugin_cexception.rb index a757669e..7e2d7b62 100644 --- a/lib/cmock_generator_plugin_cexception.rb +++ b/lib/cmock_generator_plugin_cexception.rb @@ -12,6 +12,7 @@ def initialize(config, utils) @config = config @utils = utils @priority = 7 + raise 'Error: cexception is not supported without setjmp support' if @config.exclude_setjmp_h end def include_files From aa5113e012a27f6489897aaf627e61b37910d8b9 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 29 Jan 2021 10:12:40 -0500 Subject: [PATCH 2/3] Update apt-get in the hopes that this makes multilib happy. --- .github/workflows/main.yml | 1 + src/cmock.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cdc68ef6..1737d97c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,7 @@ jobs: # Install Multilib - name: Install Multilib run: | + sudo apt-get update --assume-yes sudo apt-get install --assume-yes --quiet gcc-multilib # Checks out repository under $GITHUB_WORKSPACE diff --git a/src/cmock.h b/src/cmock.h index 027a12f0..eb198ca5 100644 --- a/src/cmock.h +++ b/src/cmock.h @@ -11,7 +11,7 @@ #define CMOCK_VERSION_MAJOR 2 #define CMOCK_VERSION_MINOR 5 -#define CMOCK_VERSION_BUILD 2 +#define CMOCK_VERSION_BUILD 3 #define CMOCK_VERSION ((CMOCK_VERSION_MAJOR << 16) | (CMOCK_VERSION_MINOR << 8) | CMOCK_VERSION_BUILD) /* should be big enough to index full range of CMOCK_MEM_MAX */ From dd00b96f0dee92519d440daaba5166ebff3fda30 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 29 Jan 2021 10:47:52 -0500 Subject: [PATCH 3/3] Fix broken tests for supporting exclude_setjmp. Verify cexception won't be run when this is enabled. --- test/unit/cmock_generator_main_test.rb | 3 +++ test/unit/cmock_generator_plugin_cexception_test.rb | 12 ++++++++++++ test/unit/cmock_plugin_manager_test.rb | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/unit/cmock_generator_main_test.rb b/test/unit/cmock_generator_main_test.rb index 84624125..ca72fe47 100644 --- a/test/unit/cmock_generator_main_test.rb +++ b/test/unit/cmock_generator_main_test.rb @@ -55,6 +55,7 @@ def mock_implementation(name, args) @config.expect :subdir, nil @config.expect :fail_on_unexpected_calls, true @config.expect :treat_inlines, :exclude + @config.expect :exclude_setjmp_h, false @cmock_generator = CMockGenerator.new(@config, @file_writer, @utils, @plugins) @cmock_generator.module_name = @module_name @cmock_generator.module_ext = '.h' @@ -75,6 +76,7 @@ def mock_implementation(name, args) @config.expect :subdir, nil @config.expect :fail_on_unexpected_calls, true @config.expect :treat_inlines, :exclude + @config.expect :exclude_setjmp_h, false @cmock_generator_strict = CMockGenerator.new(@config, @file_writer, @utils, @plugins) @cmock_generator_strict.module_name = @module_name @cmock_generator_strict.module_ext = '.h' @@ -145,6 +147,7 @@ def helper_create_header_top_with_opt_incldues_form_config_and_plugin(ext) @config.expect :subdir, nil @config.expect :fail_on_unexpected_calls, true @config.expect :treat_inlines, :exclude + @config.expect :exclude_setjmp_h, false @cmock_generator2 = CMockGenerator.new(@config, @file_writer, @utils, @plugins) @cmock_generator2.module_name = "Pout-Pout Fish" @cmock_generator2.module_ext = '.h' diff --git a/test/unit/cmock_generator_plugin_cexception_test.rb b/test/unit/cmock_generator_plugin_cexception_test.rb index 19699ea3..8bd2c926 100644 --- a/test/unit/cmock_generator_plugin_cexception_test.rb +++ b/test/unit/cmock_generator_plugin_cexception_test.rb @@ -11,6 +11,9 @@ before do create_mocks :config, :utils + + @config.expect :exclude_setjmp_h, false + @cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils) end @@ -93,4 +96,13 @@ assert_equal(expected, returned) end + it "should throw an exception if we try to use this plugin when setjmp disabled" do + + @config.expect :exclude_setjmp_h, true + + assert_raises RuntimeError do + @cmock_generator_plugin_cexception = CMockGeneratorPluginCexception.new(@config, @utils) + end + end + end diff --git a/test/unit/cmock_plugin_manager_test.rb b/test/unit/cmock_plugin_manager_test.rb index f9f0e640..abe012ab 100644 --- a/test/unit/cmock_plugin_manager_test.rb +++ b/test/unit/cmock_plugin_manager_test.rb @@ -18,7 +18,8 @@ :respond_to => true, :when_ptr => :compare_data, :enforce_strict_ordering => false, - :ignore => :args_and_calls + :ignore => :args_and_calls, + :exclude_setjmp_h => false ) def @config.plugins