coverage.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Taken from amazon-freertos repository
  2. cmake_minimum_required(VERSION 3.13)
  3. set(BINARY_DIR ${CMAKE_BINARY_DIR})
  4. # reset coverage counters
  5. execute_process(
  6. COMMAND lcov --directory ${CMAKE_BINARY_DIR}
  7. --base-directory ${CMAKE_BINARY_DIR}
  8. --zerocounters
  9. COMMAND mkdir -p ${CMAKE_BINARY_DIR}/coverage
  10. )
  11. # make the initial/baseline capture a zeroed out files
  12. execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
  13. --base-directory ${CMAKE_BINARY_DIR}
  14. --initial
  15. --capture
  16. --rc lcov_branch_coverage=1
  17. --rc genhtml_branch_coverage=1
  18. --output-file=${CMAKE_BINARY_DIR}/base_coverage.info
  19. )
  20. file(GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*")
  21. set(REPORT_FILE ${CMAKE_BINARY_DIR}/utest_report.txt)
  22. file(WRITE ${REPORT_FILE} "")
  23. # execute all files in bin directory, gathering the output to show it in CI
  24. foreach(testname ${files})
  25. get_filename_component(test
  26. ${testname}
  27. NAME_WLE
  28. )
  29. message("Running ${testname}")
  30. execute_process(COMMAND ${testname} OUTPUT_FILE ${CMAKE_BINARY_DIR}/${test}_out.txt)
  31. file(READ ${CMAKE_BINARY_DIR}/${test}_out.txt CONTENTS)
  32. file(APPEND ${REPORT_FILE} "${CONTENTS}")
  33. endforeach()
  34. # generate Junit style xml output
  35. execute_process(COMMAND ruby
  36. ${CMOCK_DIR}/vendor/unity/auto/parse_output.rb
  37. -xml ${REPORT_FILE}
  38. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  39. )
  40. # capture data after running the tests
  41. execute_process(
  42. COMMAND lcov --capture
  43. --rc lcov_branch_coverage=1
  44. --rc genhtml_branch_coverage=1
  45. --base-directory ${CMAKE_BINARY_DIR}
  46. --directory ${CMAKE_BINARY_DIR}
  47. --output-file ${CMAKE_BINARY_DIR}/second_coverage.info
  48. )
  49. # combile baseline results (zeros) with the one after running the tests
  50. execute_process(
  51. COMMAND lcov --base-directory ${CMAKE_BINARY_DIR}
  52. --directory ${CMAKE_BINARY_DIR}
  53. --add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info
  54. --add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info
  55. --output-file ${CMAKE_BINARY_DIR}/coverage.info
  56. --no-external
  57. --rc lcov_branch_coverage=1
  58. )
  59. execute_process(
  60. COMMAND genhtml --rc lcov_branch_coverage=1
  61. --branch-coverage
  62. --output-directory ${CMAKE_BINARY_DIR}/coverage
  63. ${CMAKE_BINARY_DIR}/coverage.info
  64. )