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