Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing header in mocked version #486

Open
JuPrgn opened this issue Oct 24, 2024 · 4 comments
Open

Missing header in mocked version #486

JuPrgn opened this issue Oct 24, 2024 · 4 comments

Comments

@JuPrgn
Copy link

JuPrgn commented Oct 24, 2024

Hi,

I am currently switching from Ceedling 0.31 to 1.0.0 on a project that is already fully tested.

Usually my modules are arranged like that :

  • Module.c (all functions definitions)
  • Module.h ("public" functions declarations and typedef struct...)
  • Module_private.h (STATIC functions)
  • test_Module.c (test "public" functions while mocking "private" functions)
  • test_Module_private.c (test "private" functions)

Module.c includes both Module.h and Module_private.h
Module_private.h include Module.h to get specific typedef

On my test files test_Module.c include Module.h and mock Module_private.h

This configurations was working with previous versions but on latest CMock (2.6.0) Module.h is not included in the mocked Module_private.h and the compiler complains about some types that are not defined (typedef structs from Module.h).

I generated a new project with latestCeedling pre-release to get default configuration yaml and then applied my old configuration following new documentation, maybe I missed something there ? Or this is no more achievable and there is now a better way to do it ?

# =========================================================================
#   Ceedling - Test-Centered Build System for C
#   ThrowTheSwitch.org
#   Copyright (c) 2010-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
#   SPDX-License-Identifier: MIT
# =========================================================================

---
:project:
  :which_ceedling: vendor/ceedling
  :ceedling_version: 1.0.0

  :use_mocks: TRUE
  :use_test_preprocessor: :all
  :use_backtrace: :simple
  :use_decorators: :auto #Decorate Ceedling's output text. Your options are :auto, :all, or :none

  :build_root: build_test
  :test_file_prefix: test_
  :default_tasks:
    - test:all

  :test_threads: 8
  :compile_threads: 8
  :release_build: FALSE

:mixins:
  :enabled: []
  :load_paths: []

:test_build:
  :use_assembly: FALSE
  
:release_build:
  :output: MyApp.out
  :use_assembly: FALSE
  :artifacts: []

:plugins:
  :load_paths: []
  :enabled:
    - report_tests_pretty_stdout
    - report_tests_raw_output_log

:extension:
  :executable: .hex

:paths:
  :test:
    - +:test/**
    - -:test/support
  :source:
    - src/**
  :include:
    - src/** # In simple projects, this entry often duplicates :source
    - test/support 
  :support:
    - test/support
  :libraries: []

:files:
  :test: []
  :source: []

:defines:
  :commmon: &common_defines
    - UNITY_INT_WIDTH=16
    - CMOCK_MEM_INDEX_TYPE=uint16_t
    # - CMOCK_MEM_PTR_AS_INT=uint16_t # segmentation fault avec GCC dès l'utilisation de ExpectAndReturn si spécifié
    - CMOCK_MEM_ALIGN=1
    - CMOCK_MEM_SIZE=4096
  :test:
    - *common_defines
    - TEST # Simple list option to add symbol 'TEST' to compilation of all files in all test executables
    # - __eds__=
  :test_preprocess:
    - *common_defines
    - TEST
  :release: []

  # Enable to inject name of a test as a unique compilation symbol into its respective executable build. 
  :use_test_definition: FALSE 

:cmock:
  # Core conffiguration
  :plugins:                        # What plugins should be used by CMock?
    - :ignore
    - :callback
  :verbosity:  2                   # the options being 0 errors only, 1 warnings and errors, 2 normal info, 3 verbose
  :when_no_prototypes:  :warn      # the options being :ignore, :warn, or :erro

  # File configuration
  :skeleton_path:  ''              # Subdirectory to store stubs when generated (default: '')
  :mock_prefix:  'mock_'           # Prefix to append to filenames for mocks
  :mock_suffix:  ''                # Suffix to append to filenames for mocks

  # Parser configuration
  :strippables:  ['(?:__attribute__\s*\([ (]*.*?[ )]*\)+)']
  :attributes:
     - __ramfunc
     - __irq
     - __fiq
     - register
     - extern
  :c_calling_conventions:
     - __stdcall
     - __cdecl
     - __fastcall
  :treat_externs:  :exclude        # the options being :include or :exclude
  :treat_inlines:  :include        # the options being :include or :exclude

  # Type handling configuration
  #:unity_helper_path: ''          # specify a string of where to find a unity_helper.h file to discover custom type assertions
  :treat_as:                       # optionally add additional types to map custom types
    uint8:    HEX8
    uint16:   HEX16
    uint32:   UINT32
    uint64:   UINT64
    int8:     INT8
    bool:     UINT8
  #:treat_as_array:  {}            # hint to cmock that these types are pointers to something
  #:treat_as_void:  []             # hint to cmock that these types are actually aliases of void
  :memcmp_if_unknown:  true        # allow cmock to use the memory comparison assertions for unknown types
  :when_ptr:  :compare_data        # hint to cmock how to handle pointers in general, the options being :compare_ptr, :compare_data, or :smart

  # Mock generation configuration
  :weak:  ''                       # Symbol to use to declare weak functions
  :enforce_strict_ordering: true   # Do we want cmock to enforce ordering of all function calls?
  :fail_on_unexpected_calls: true  # Do we want cmock to fail when it encounters a function call that wasn't expected?
  :callback_include_count: true    # Do we want cmock to include the number of calls to this callback, when using callbacks?
  :callback_after_arg_check: false # Do we want cmock to enforce an argument check first when using a callback?
  #:includes: []                   # You can add additional includes here, or specify the location with the options below
  :includes_h_pre_orig_header: [] 
  #:includes_h_post_orig_header: []
  #:includes_c_pre_header:  []
  #:includes_c_post_header:  []
  #:array_size_type:  []            # Specify a type or types that should be used for array lengths
  #:array_size_name:  'size|len'    # Specify a name or names that CMock might automatically recognize as the length of an array
  :exclude_setjmp_h:  false        # Don't use setjmp when running CMock. Note that this might result in late reporting or out-of-order failures.
...

@JuPrgn
Copy link
Author

JuPrgn commented Oct 24, 2024

Using previous Ceedling there was no Module_private.h on test/mocks/ something strange is that this file now contains a single header clock.h that is included in others included headers on the original files but the others header are not included :

  • Module.h include : Error.h and MyTypes.h
  • MyTypes.h include : MyConfig.h, LoadAnalysis.h, include clock.h and pins.h

If I disable prepocessor on my configuration, only Module.h is now included in this test/mocks/Module_private.h but my STATIC functions are not parsed to remove the static keyword. #define STATIC using this #ifdef TEST trick to remove static on tests.

@JuPrgn
Copy link
Author

JuPrgn commented Oct 25, 2024

I did a small example to reproduce this if you want to give it a try. On this example there is no more clock.h but the only header included in test/mocks/Timer_private.h is MyTypes.h instead of Timer.h
SimpleTest.zip

@JuPrgn
Copy link
Author

JuPrgn commented Oct 29, 2024

I've tried a lot with different configurations and haven't found a solution, if anyone uses a similar module structure and you have a tip I'm interested =)

@JuPrgn
Copy link
Author

JuPrgn commented Nov 1, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant