object-introspection/test/CMakeLists.txt
Jake Hillion a014cdd4de tests: add ClangTypeParserTest
Currently there is no testing for ClangTypeParser even though it's used in
production. This is because adding integration tests is very hard: they require
testing the build time behaviour at runtime, or else they'd be build failures
intead of test failures. There's a PR available for integration tests but it's
incomplete.

In contrast ClangTypeParser can be sort of unit tested. This follows the
structure of `test/test_drgn_parser.cpp` with some differences. There is a
tonne of boilerplate for setting up the Clang tool, and this set of testing
operates on type names instead of OID functions. The new tests are also
incredibly slow as they compile the entire `integration_test_target.cpp` (which
is huge) for every test case. I don't think this is avoidable without
compromising the separation of the tests somewhat due to the way Clang tooling
forces the code to be structured.

Currently I can't run these tests locally on a Meta devserver due to some
weirdness with the internal build and the `compile_commands.json` file. They
run in the CI and on any other open source machine though so I'm happy to merge
it - it's still useful. I'm going to close the PR to change the devserver build
given I'll be unable to follow up if it ends up being bad.

Test plan:
- CI
2024-02-23 16:51:51 +00:00

142 lines
3.0 KiB
CMake

enable_testing()
include(GoogleTest)
function(cpp_unittest)
cmake_parse_arguments(
PARSE_ARGV 0
TEST
"" "NAME" "SRCS;DEPS;PROPERTIES"
)
add_executable(
${TEST_NAME}
${TEST_SRCS}
)
target_link_libraries(
${TEST_NAME}
GTest::gmock_main glog
${TEST_DEPS}
)
gtest_discover_tests(${TEST_NAME} PROPERTIES ${TEST_PROPERTIES})
endfunction()
add_executable(integration_mttest
integration_mttest.cpp
)
target_link_libraries(integration_mttest folly_headers)
add_executable(integration_sleepy
integration_sleepy.cpp
)
target_link_libraries(integration_sleepy folly_headers)
# Unit tests
add_executable(test_type_graph
main.cpp
test_add_children.cpp
test_add_padding.cpp
test_alignment_calc.cpp
test_codegen.cpp
test_drgn_parser.cpp
test_enforce_compatibility.cpp
test_flattener.cpp
test_identify_containers.cpp
test_key_capture.cpp
test_name_gen.cpp
test_node_tracker.cpp
test_prune.cpp
test_remove_members.cpp
test_remove_top_level_pointer.cpp
test_topo_sorter.cpp
test_type_identifier.cpp
type_graph_utils.cpp
TypeGraphParser.cpp
)
add_dependencies(test_type_graph integration_test_target)
target_compile_definitions(test_type_graph PRIVATE
TARGET_EXE_PATH="${CMAKE_CURRENT_BINARY_DIR}/integration/integration_test_target"
)
target_link_libraries(test_type_graph
codegen
container_info
type_graph
GTest::gmock_main
)
include(GoogleTest)
gtest_discover_tests(test_type_graph)
add_executable(test_clang_type_parser
main.cpp
../oi/type_graph/ClangTypeParserTest.cpp
)
add_dependencies(test_clang_type_parser integration_test_target)
target_compile_definitions(test_clang_type_parser PRIVATE
TARGET_CPP_PATH="${CMAKE_CURRENT_BINARY_DIR}/integration/integration_test_target.cpp"
BUILD_DIR="${CMAKE_BINARY_DIR}"
)
target_link_libraries(test_clang_type_parser
codegen
container_info
type_graph
range-v3
GTest::gmock_main
)
if (FORCE_LLVM_STATIC)
target_link_libraries(test_clang_type_parser clangTooling ${llvm_libs})
else()
target_link_libraries(test_clang_type_parser clang-cpp LLVM)
endif()
gtest_discover_tests(test_clang_type_parser)
cpp_unittest(
NAME test_parser
SRCS test_parser.cpp
DEPS oid_parser
)
cpp_unittest(
NAME test_compiler
SRCS test_compiler.cpp
DEPS oicore
)
cpp_unittest(
NAME test_container_info
SRCS test_container_info.cpp
DEPS oicore
)
cpp_unittest(
NAME types_static_test
SRCS ../oi/types/test/StaticTest.cpp
DEPS oicore
)
cpp_unittest(
NAME type_checking_walker_test
SRCS ../oi/exporters/test/TypeCheckingWalkerTest.cpp
DEPS treebuilder
)
# Integration tests
if (WITH_FLAKY_TESTS)
add_test(
NAME integration_py
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/integration.py
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_tests_properties(integration_py PROPERTIES
TIMEOUT 90
ENVIRONMENT "OID=$<TARGET_FILE:oid>"
)
endif()
include_directories("${PROJECT_SOURCE_DIR}/extern/drgn/build")
add_subdirectory("integration")