Skip to content

Commit 59db4f7

Browse files
committed
Generate a shared library linked to integration_test_target
1 parent f47628a commit 59db4f7

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

test/integration/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ list(TRANSFORM INTEGRATION_TEST_CONFIGS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
6868
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie")
6969

7070
set(INTEGRATION_TEST_TARGET_SRC integration_test_target.cpp)
71+
set(INTEGRATION_TEST_TARGET_SHLIB_SRC integration_test_target_shlib.cpp)
7172
set(INTEGRATION_TEST_RUNNER_SRC integration_test_runner.cpp)
7273

7374
find_program(PYTHON_CMD NAMES python3.6 python3)
@@ -81,19 +82,25 @@ list(TRANSFORM INTEGRATION_TEST_THRIFT_SRCS APPEND ".thrift")
8182
add_custom_command(
8283
OUTPUT
8384
${INTEGRATION_TEST_TARGET_SRC}
85+
${INTEGRATION_TEST_TARGET_SHLIB_SRC}
8486
${INTEGRATION_TEST_RUNNER_SRC}
8587
${INTEGRATION_TEST_THRIFT_SRCS}
8688
COMMAND ${PYTHON_CMD}
8789
${CMAKE_CURRENT_SOURCE_DIR}/gen_tests.py
8890
${INTEGRATION_TEST_TARGET_SRC}
91+
${INTEGRATION_TEST_TARGET_SHLIB_SRC}
8992
${INTEGRATION_TEST_RUNNER_SRC}
9093
${INTEGRATION_TEST_CONFIGS}
9194
MAIN_DEPENDENCY gen_tests.py
9295
DEPENDS ${INTEGRATION_TEST_CONFIGS})
9396

97+
add_library(integration_test_target_shlib SHARED ${INTEGRATION_TEST_TARGET_SHLIB_SRC})
98+
target_compile_options(integration_test_target_shlib PRIVATE -O1)
99+
target_link_libraries(integration_test_target_shlib PRIVATE oil Boost::headers ${Boost_LIBRARIES})
100+
94101
add_executable(integration_test_target ${INTEGRATION_TEST_TARGET_SRC})
95102
target_compile_options(integration_test_target PRIVATE -O1)
96-
target_link_libraries(integration_test_target PRIVATE oil Boost::headers ${Boost_LIBRARIES})
103+
target_link_libraries(integration_test_target PRIVATE oil integration_test_target_shlib Boost::headers ${Boost_LIBRARIES})
97104

98105
add_executable(integration_test_runner ${INTEGRATION_TEST_RUNNER_SRC} runner_common.cpp)
99106
target_include_directories(integration_test_runner PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

test/integration/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ definitions = '''
112112
required for a specific test to compile, avoiding the need to add new
113113
dependencies to the build system for one-off tests.
114114
115+
- `definitions_shlib`, `raw_definitions_shlib`
116+
117+
Same as above, but the definitions are put into a shared library linked with the target program.
118+
It enables testing how Object Introspection handles shared libraries.
119+
120+
**WARNING:** The shared library doesn't handle Thrift definitions.
121+
115122
- `cases` **Required**
116123

117124
A list of individual test cases, each with their own setup, OI probe

test/integration/gen_tests.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,32 @@ def gen_target(output_target_name, test_configs):
250250
add_footer(f)
251251

252252

253+
def gen_target_shlib(output_target_name, test_configs):
254+
with open(output_target_name, "w") as f:
255+
headers = set()
256+
for config in test_configs:
257+
headers.update(config.get("includes_shlib", []))
258+
add_headers(f, custom_headers=headers, thrift_headers=[])
259+
260+
from textwrap import dedent
261+
262+
for config in test_configs:
263+
ns = config["suite"]
264+
f.write(
265+
dedent(
266+
f"""
267+
{config.get("raw_definitions_shlib", "")}
268+
namespace {ns} {{
269+
#pragma clang diagnostic push
270+
#pragma clang diagnostic ignored \"-Wunused-private-field\"
271+
{config.get("definitions_shlib", "")}
272+
#pragma clang diagnostic pop
273+
}} // namespace {ns}
274+
"""
275+
)
276+
)
277+
278+
253279
def get_probe_name(probe_type, test_suite, test_case, args):
254280
func_name = get_target_oid_func_name(test_suite, test_case)
255281
return probe_type + ":" + func_name + ":" + args
@@ -447,15 +473,19 @@ def gen_thrift(test_configs):
447473

448474

449475
def main():
450-
if len(sys.argv) < 4:
451-
print("Usage: gen_tests.py OUTPUT_TARGET OUTPUT_RUNNER INPUT1 [INPUT2 ...]")
476+
if len(sys.argv) < 5:
477+
print(
478+
"Usage: gen_tests.py OUTPUT_TARGET OUTPUT_SHLIB OUTPUT_RUNNER INPUT1 [INPUT2 ...]"
479+
)
452480
exit(1)
453481

454482
output_target = sys.argv[1]
455-
output_runner = sys.argv[2]
456-
inputs = sys.argv[3:]
483+
output_target_shlib = sys.argv[2]
484+
output_runner = sys.argv[3]
485+
inputs = sys.argv[4:]
457486

458487
print(f"Output target: {output_target}")
488+
print(f"Output shlib: {output_target_shlib}")
459489
print(f"Output runner: {output_runner}")
460490
print(f"Input files: {inputs}")
461491

@@ -484,6 +514,7 @@ def main():
484514
)
485515

486516
gen_target(output_target, test_configs)
517+
gen_target_shlib(output_target_shlib, test_configs)
487518
gen_runner(output_runner, test_configs)
488519
gen_thrift(test_configs)
489520

0 commit comments

Comments
 (0)