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

ceedling gcov:all Fails for Mixed C and C++ Files #993

Open
sujit-dhs opened this issue Jan 16, 2025 · 4 comments
Open

ceedling gcov:all Fails for Mixed C and C++ Files #993

sujit-dhs opened this issue Jan 16, 2025 · 4 comments

Comments

@sujit-dhs
Copy link

I'm encountering an issue with Ceedling when running code coverage (ceedling gcov:all) on a project that includes both C and C++ files. My project contains headers and source files with a mix of C and C++ code, and I've configured the test_compiler and test_linker in project.yml to use g++.

Running ceedling test:all works perfectly, but when I try to generate coverage reports using ceedling gcov:all, the process fails, and no report is generated. Below is a summary of my setup and configuration:

:tools:
:gcov:
:executable: gcov
:name: 'gcov'
:args:
- -r
- .
- --html
- --html-details
:arguments:
- --coverage
:test_compiler:
:executable: g++
:arguments:
- "-m32"
- "-Wall"
- "-Werror"
- "-std=c++11"
- -I"/usr/local/bundle/gems/ceedling-1.0.0/vendor/unity/src"
- -I"/usr/local/bundle/gems/ceedling-1.0.0/vendor/cmock/src"
- -I"test/mocks"
- -I"test/mocks/test_pwm"
- -I"test/mocks/test_comm"
- -I"test/mocks/test_control"
- -I"test/mocks/test_commands"
- -I"test"
- -I"test/support"
- -I"app/src"
- -I"base/src"
- -I"gui/src"
- -DTEST
- -DUNIT_TEST=1
- -DGNU_COMPILER
- -g
- -fprofile-arcs
- -ftest-coverage
- -fno-exceptions
- -c
- ${1}
- -o ${2}
- -MMD
- -MF ${3}
- -Wno-sign-compare # Disable sign comparison warning
- -Wno-unused-variable
#- -Wno-int-to-pointer-cast
- -fpermissive
:before_compile:
echo "#ifdef __cplusplus" > ${1}.cpp
echo "extern "C" {" >> ${1}.cpp
cat ${1} >> ${1}.cpp
echo "}" >> ${1}.cpp
echo "#endif" >> ${1}.cpp
:test_linker:
:executable: g++
:arguments:
- "-m32"
- "-Wall"
- "-Werror"
- -o ${2}
- ${1}
- -g
- -lm
- -lgcov

  Error:
  Linking test_buck_txbits.out...
         🧨 EXCEPTION: 'Default Gcov Linker' (gcc) terminated with exit code [1] and output >>
          /usr/bin/ld: 
          Runner files give error as undefined reference to all test functions that are available in test file.
  Questions:
        What additional configuration is required in project.yml to support code coverage for a project with both C and C++ code?
         Is there a specific way to handle mixed-language files when using gcov with Ceedling?
@Letme
Copy link
Contributor

Letme commented Jan 16, 2025

Gcov does not use test_compiler and test_linker, but gcov_compiler and gcov_linker (at least in older Ceedling versions it was like that). While migrating it, I did not have an option to port arguments, so what I did is not define arguments and migrated it all to flags. Then you can just define:

:gcov_compiler:
  :executable: g++
:gcov_linker:
  :executable: g++

And let the Ceedling add the flags and includes automatically (meaning you need to port your -Wno- stuff to :flags:, -D stuff to :defines: and -I stuff to :includes:.

@sujit-dhs
Copy link
Author

Thanks for your reply.
After updating my Ceedling configuration to address previous issues, I encountered a new problem when running ceedling gcov:all. The steps for Mocking, Generating Test Runners, and other initial processes are successful. However, the process fails at the "Building Objects" stage with the following error:
🧨 EXCEPTION: can't modify frozen String: "-g"
🌱 Ceedling could not complete operations because of errors

@mkarlesky
Copy link
Member

Hi, @sujit-dhs. Thank you for this report and sorry for the trouble. Thank you @Letme for suggesting the fix you did with the new Ceedling feature.

@sujit-dhs Can you kindly run with verbosity increased (--verbosity debug or -v 5)? The error is saying that a command line flag string that cannot be modified is being modified. We need to know where in order to fix it.

@sujit-dhs
Copy link
Author

I ran the command with --verbosity debug (ceedling gcov:all --verbosity debug) to gather more details, and the logs are as follows:

👟 Test Runners

Generating runner for test_buck_txbits.c...
Generating runner for test_pwm.c...
Generating runner for test_sweep.c...
Generating runner for test_tx_drive.c...

👟 Determining Artifacts to Be Built...

👟 Building Objects

Plugin | Gcov > :pre_compile_execute...
Compiling test_buck_txbits.c with coverage...
🧨 EXCEPTION: can't modify frozen String: "-g"

Debug Backtrace ==>
/usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/tool_executor.rb:150:in sub!': (FrozenError) /usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/tool_executor.rb:150:in expandify_element'
/usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/tool_executor.rb:115:in block in build_arguments' /usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/tool_executor.rb:109:in each'
/usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/tool_executor.rb:109:in build_arguments' /usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/tool_executor.rb:37:in build_command_line'
/usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/generator.rb:157:in generate_object_file_c' /usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/test_invoker.rb:475:in compile_test_component'
/usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/test_invoker.rb:373:in block (3 levels) in setup_and_invoke' /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/file_list.rb:79:in each'
/usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/file_list.rb:79:in each' /usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/test_invoker.rb:371:in block (2 levels) in setup_and_invoke'
/usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/test_invoker.rb:370:in each' /usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/test_invoker.rb:370:in block in setup_and_invoke'
/usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/build_batchinator.rb:26:in build_step' /usr/local/bundle/gems/ceedling-1.0.0/lib/ceedling/test_invoker.rb:369:in setup_and_invoke'
/usr/local/bundle/gems/ceedling-1.0.0/plugins/gcov/gcov.rake:29:in block (2 levels) in <top (required)>' /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in block in execute'
/usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in each' /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in execute'
/usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in block in invoke_with_call_chain' /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in synchronize'
/usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in invoke_with_call_chain' /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in invoke'
/usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in invoke_task' /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in block (2 levels) in top_level'
/usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in each' /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in block in top_level'
/usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in run_with_threads' /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in top_level'
/usr/local/bundle/gems/ceedling-1.0.0/bin/cli_helper.rb:255:in run_rake_tasks' /usr/local/bundle/gems/ceedling-1.0.0/bin/cli_handler.rb:237:in build'
/usr/local/bundle/gems/ceedling-1.0.0/bin/cli.rb:371:in build' /usr/local/bundle/gems/thor-1.3.2/lib/thor/command.rb:28:in run'
/usr/local/bundle/gems/thor-1.3.2/lib/thor/invocation.rb:127:in invoke_command' /usr/local/bundle/gems/thor-1.3.2/lib/thor.rb:538:in dispatch'
/usr/local/bundle/gems/ceedling-1.0.0/bin/cli.rb:93:in start' /usr/local/bundle/gems/ceedling-1.0.0/bin/ceedling:144:in rescue in <top (required)>'
/usr/local/bundle/gems/ceedling-1.0.0/bin/ceedling:49:in <top (required)>' /usr/local/bundle/bin/ceedling:25:in load'
/usr/local/bundle/bin/ceedling:25:in `

'

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

No branches or pull requests

3 participants