diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index 68300b86..407d74b4 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -68,6 +68,7 @@ list(TRANSFORM INTEGRATION_TEST_CONFIGS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie") set(INTEGRATION_TEST_TARGET_SRC integration_test_target.cpp) +set(INTEGRATION_TEST_TARGET_SHLIB_SRC integration_test_target_shlib.cpp) set(INTEGRATION_TEST_RUNNER_SRC integration_test_runner.cpp) find_program(PYTHON_CMD NAMES python3.6 python3) @@ -81,19 +82,25 @@ list(TRANSFORM INTEGRATION_TEST_THRIFT_SRCS APPEND ".thrift") add_custom_command( OUTPUT ${INTEGRATION_TEST_TARGET_SRC} + ${INTEGRATION_TEST_TARGET_SHLIB_SRC} ${INTEGRATION_TEST_RUNNER_SRC} ${INTEGRATION_TEST_THRIFT_SRCS} COMMAND ${PYTHON_CMD} ${CMAKE_CURRENT_SOURCE_DIR}/gen_tests.py ${INTEGRATION_TEST_TARGET_SRC} + ${INTEGRATION_TEST_TARGET_SHLIB_SRC} ${INTEGRATION_TEST_RUNNER_SRC} ${INTEGRATION_TEST_CONFIGS} MAIN_DEPENDENCY gen_tests.py DEPENDS ${INTEGRATION_TEST_CONFIGS}) +add_library(integration_test_target_shlib SHARED ${INTEGRATION_TEST_TARGET_SHLIB_SRC}) +target_compile_options(integration_test_target_shlib PRIVATE -O1) +target_link_libraries(integration_test_target_shlib PRIVATE oil Boost::headers ${Boost_LIBRARIES}) + add_executable(integration_test_target ${INTEGRATION_TEST_TARGET_SRC}) target_compile_options(integration_test_target PRIVATE -O1) -target_link_libraries(integration_test_target PRIVATE oil Boost::headers ${Boost_LIBRARIES}) +target_link_libraries(integration_test_target PRIVATE oil integration_test_target_shlib Boost::headers ${Boost_LIBRARIES}) add_executable(integration_test_runner ${INTEGRATION_TEST_RUNNER_SRC} runner_common.cpp) target_include_directories(integration_test_runner PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/test/integration/README.md b/test/integration/README.md index 1d2b2f55..ee293ca6 100644 --- a/test/integration/README.md +++ b/test/integration/README.md @@ -112,6 +112,13 @@ definitions = ''' required for a specific test to compile, avoiding the need to add new dependencies to the build system for one-off tests. +- `definitions_shlib`, `raw_definitions_shlib` + + Same as above, but the definitions are put into a shared library linked with the target program. + It enables testing how Object Introspection handles shared libraries. + + **WARNING:** The shared library doesn't handle Thrift definitions. + - `cases` **Required** A list of individual test cases, each with their own setup, OI probe diff --git a/test/integration/gen_tests.py b/test/integration/gen_tests.py index 8f22e168..17d0fa3d 100644 --- a/test/integration/gen_tests.py +++ b/test/integration/gen_tests.py @@ -250,6 +250,32 @@ def gen_target(output_target_name, test_configs): add_footer(f) +def gen_target_shlib(output_target_name, test_configs): + with open(output_target_name, "w") as f: + headers = set() + for config in test_configs: + headers.update(config.get("includes_shlib", [])) + add_headers(f, custom_headers=headers, thrift_headers=[]) + + from textwrap import dedent + + for config in test_configs: + ns = config["suite"] + f.write( + dedent( + f""" + {config.get("raw_definitions_shlib", "")} + namespace {ns} {{ + #pragma clang diagnostic push + #pragma clang diagnostic ignored \"-Wunused-private-field\" + {config.get("definitions_shlib", "")} + #pragma clang diagnostic pop + }} // namespace {ns} + """ + ) + ) + + def get_probe_name(probe_type, test_suite, test_case, args): func_name = get_target_oid_func_name(test_suite, test_case) return probe_type + ":" + func_name + ":" + args @@ -447,15 +473,19 @@ def gen_thrift(test_configs): def main(): - if len(sys.argv) < 4: - print("Usage: gen_tests.py OUTPUT_TARGET OUTPUT_RUNNER INPUT1 [INPUT2 ...]") + if len(sys.argv) < 5: + print( + "Usage: gen_tests.py OUTPUT_TARGET OUTPUT_SHLIB OUTPUT_RUNNER INPUT1 [INPUT2 ...]" + ) exit(1) output_target = sys.argv[1] - output_runner = sys.argv[2] - inputs = sys.argv[3:] + output_target_shlib = sys.argv[2] + output_runner = sys.argv[3] + inputs = sys.argv[4:] print(f"Output target: {output_target}") + print(f"Output shlib: {output_target_shlib}") print(f"Output runner: {output_runner}") print(f"Input files: {inputs}") @@ -484,6 +514,7 @@ def main(): ) gen_target(output_target, test_configs) + gen_target_shlib(output_target_shlib, test_configs) gen_runner(output_runner, test_configs) gen_thrift(test_configs)