coverage.cmake 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 branch_coverage=1
  17. --output-file=${CMAKE_BINARY_DIR}/base_coverage.info
  18. --include "*source*"
  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 branch_coverage=1
  44. --base-directory ${CMAKE_BINARY_DIR}
  45. --directory ${CMAKE_BINARY_DIR}
  46. --output-file ${CMAKE_BINARY_DIR}/second_coverage.info
  47. --include "*source*"
  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 branch_coverage=1
  58. --include "*source*"
  59. --exclude "*dependency*"
  60. )
  61. execute_process(
  62. COMMAND genhtml --rc branch_coverage=1
  63. --branch-coverage
  64. --output-directory ${CMAKE_BINARY_DIR}/coverage
  65. ${CMAKE_BINARY_DIR}/coverage.info
  66. )