code_coverage.cmake 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. function(check_ubuntu_version)
  4. # ubuntu 2204 is the recommended environment for collecting coverage data for now
  5. # otherwise, there will be ERRORs, when using 2404, like below and
  6. #
  7. # geninfo: ERROR: ('mismatch') mismatched end line for _ZN63compilation_aot_emit_memory_test_aot_check_memory_overflow_Test8TestBodyEv at /workspaces/wasm-micro-runtime/tests/unit/compilation/aot_emit_memory_test.cc:96: 96 -> 106
  8. # (use "geninfo --ignore-errors mismatch,mismatch ..." to suppress this warning)
  9. # geninfo: ERROR: ('negative') Unexpected negative count '-3' for /workspaces/wasm-micro-runtime/core/iwasm/interpreter/wasm_interp_classic.c:5473.
  10. # Perhaps you need to compile with '-fprofile-update=atomic
  11. # (use "geninfo --ignore-errors negative,negative ..." to suppress this warning)
  12. #
  13. # For sure, `--ignore-errors` can be used to ignore these errors, but better to use the recommended environment.
  14. file(READ "/etc/os-release" OS_RELEASE_CONTENT)
  15. string(REGEX MATCH "VERSION_ID=\"([0-9]+)\\.([0-9]+)\"" _ ${OS_RELEASE_CONTENT})
  16. if(NOT DEFINED CMAKE_MATCH_1 OR NOT DEFINED CMAKE_MATCH_2)
  17. message(WARNING "Unable to detect Ubuntu version. Please ensure you are using Ubuntu 22.04.")
  18. return()
  19. endif()
  20. set(UBUNTU_MAJOR_VERSION ${CMAKE_MATCH_1})
  21. set(UBUNTU_MINOR_VERSION ${CMAKE_MATCH_2})
  22. if(NOT (UBUNTU_MAJOR_VERSION EQUAL 22 AND UBUNTU_MINOR_VERSION EQUAL 04))
  23. message(WARNING "Ubuntu ${UBUNTU_MAJOR_VERSION}.${UBUNTU_MINOR_VERSION} detected. Ubuntu 22.04 is recommended for collecting coverage data.")
  24. else()
  25. message(STATUS "Ubuntu 22.04 detected. Proceeding with coverage data collection.")
  26. endif()
  27. endfunction()
  28. check_ubuntu_version()
  29. # add compile options for code coverage globally
  30. add_compile_options(--coverage -O0 -g)
  31. link_libraries(gcov)
  32. add_definitions (-DCOLLECT_CODE_COVERAGE)