coverage.cmake 3.0 KB

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