Skip to content

Commit

Permalink
Merge pull request #346 from ThrowTheSwitch/reapply_329
Browse files Browse the repository at this point in the history
Revert "Revert "CMock can now compile without setjmp.h present on the…
  • Loading branch information
mvandervoord authored Jan 29, 2021
2 parents 73fd659 + dd00b96 commit 9d09289
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/CMock_Summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <setjmp.h> 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/`.
Expand Down
1 change: 1 addition & 0 deletions lib/cmock_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 7 additions & 2 deletions lib/cmock_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -182,7 +183,9 @@ def create_source_header_section(file, filename, functions)
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n" unless functions.empty?
file << "#include <string.h>\n"
file << "#include <stdlib.h>\n"
file << "#include <setjmp.h>\n"
unless @exclude_setjmp_h
file << "#include <setjmp.h>\n"
end
file << "#include \"cmock.h\"\n"
@includes_c_pre_header.each { |inc| file << "#include #{inc}\n" }
file << "#include \"#{header_file}\"\n"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lib/cmock_generator_plugin_cexception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
3 changes: 3 additions & 0 deletions test/unit/cmock_generator_main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
12 changes: 12 additions & 0 deletions test/unit/cmock_generator_plugin_cexception_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/unit/cmock_plugin_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9d09289

Please sign in to comment.