gcov.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. require 'ceedling/plugin'
  2. require 'ceedling/constants'
  3. require 'gcov_constants'
  4. class Gcov < Plugin
  5. attr_reader :config
  6. def setup
  7. @result_list = []
  8. @config = {
  9. project_test_build_output_path: GCOV_BUILD_OUTPUT_PATH,
  10. project_test_build_output_c_path: GCOV_BUILD_OUTPUT_PATH,
  11. project_test_results_path: GCOV_RESULTS_PATH,
  12. project_test_dependencies_path: GCOV_DEPENDENCIES_PATH,
  13. defines_test: DEFINES_TEST + ['CODE_COVERAGE'],
  14. gcov_html_report_filter: GCOV_FILTER_EXCLUDE
  15. }
  16. @plugin_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
  17. @coverage_template_all = @ceedling[:file_wrapper].read(File.join(@plugin_root, 'assets/template.erb'))
  18. end
  19. def generate_coverage_object_file(source, object)
  20. lib_args = @ceedling[:test_invoker].convert_libraries_to_arguments()
  21. compile_command =
  22. @ceedling[:tool_executor].build_command_line(
  23. TOOLS_GCOV_COMPILER,
  24. @ceedling[:flaginator].flag_down(OPERATION_COMPILE_SYM, GCOV_SYM, source),
  25. source,
  26. object,
  27. @ceedling[:file_path_utils].form_test_build_list_filepath(object),
  28. lib_args
  29. )
  30. @ceedling[:streaminator].stdout_puts("Compiling #{File.basename(source)} with coverage...")
  31. @ceedling[:tool_executor].exec(compile_command[:line], compile_command[:options])
  32. end
  33. def post_test_fixture_execute(arg_hash)
  34. result_file = arg_hash[:result_file]
  35. if (result_file =~ /#{GCOV_RESULTS_PATH}/) && !@result_list.include?(result_file)
  36. @result_list << arg_hash[:result_file]
  37. end
  38. end
  39. def post_build
  40. return unless @ceedling[:task_invoker].invoked?(/^#{GCOV_TASK_ROOT}/)
  41. # test results
  42. results = @ceedling[:plugin_reportinator].assemble_test_results(@result_list)
  43. hash = {
  44. header: GCOV_ROOT_NAME.upcase,
  45. results: results
  46. }
  47. @ceedling[:plugin_reportinator].run_test_results_report(hash) do
  48. message = ''
  49. message = 'Unit test failures.' if results[:counts][:failed] > 0
  50. message
  51. end
  52. report_per_file_coverage_results(@ceedling[:test_invoker].sources)
  53. end
  54. def summary
  55. result_list = @ceedling[:file_path_utils].form_pass_results_filelist(GCOV_RESULTS_PATH, COLLECTION_ALL_TESTS)
  56. # test results
  57. # get test results for only those tests in our configuration and of those only tests with results on disk
  58. hash = {
  59. header: GCOV_ROOT_NAME.upcase,
  60. results: @ceedling[:plugin_reportinator].assemble_test_results(result_list, boom: false)
  61. }
  62. @ceedling[:plugin_reportinator].run_test_results_report(hash)
  63. end
  64. private ###################################
  65. def report_per_file_coverage_results(sources)
  66. banner = @ceedling[:plugin_reportinator].generate_banner "#{GCOV_ROOT_NAME.upcase}: CODE COVERAGE SUMMARY"
  67. @ceedling[:streaminator].stdout_puts "\n" + banner
  68. coverage_sources = sources.clone
  69. coverage_sources.delete_if { |item| item =~ /#{CMOCK_MOCK_PREFIX}.+#{EXTENSION_SOURCE}$/ }
  70. coverage_sources.delete_if { |item| item =~ /#{GCOV_IGNORE_SOURCES.join('|')}#{EXTENSION_SOURCE}$/ }
  71. coverage_sources.each do |source|
  72. basename = File.basename(source)
  73. command = @ceedling[:tool_executor].build_command_line(TOOLS_GCOV_REPORT, [], [basename])
  74. shell_results = @ceedling[:tool_executor].exec(command[:line], command[:options])
  75. coverage_results = shell_results[:output]
  76. if coverage_results.strip =~ /(File\s+'#{Regexp.escape(source)}'.+$)/m
  77. report = Regexp.last_match(1).lines.to_a[1..-1].map { |line| basename + ' ' + line }.join('')
  78. @ceedling[:streaminator].stdout_puts(report + "\n\n")
  79. end
  80. end
  81. COLLECTION_ALL_SOURCE.each do |source|
  82. unless coverage_sources.include?(source)
  83. @ceedling[:streaminator].stdout_puts("Could not find coverage results for " + source + "\n")
  84. end
  85. end
  86. end
  87. end
  88. # end blocks always executed following rake run
  89. END {
  90. # cache our input configurations to use in comparison upon next execution
  91. @ceedling[:cacheinator].cache_test_config(@ceedling[:setupinator].config_hash) if @ceedling[:task_invoker].invoked?(/^#{GCOV_TASK_ROOT}/)
  92. }