Skip to content

Commit

Permalink
Generate a shared library linked to integration_test_target
Browse files Browse the repository at this point in the history
  • Loading branch information
ttreyer committed Apr 18, 2023
1 parent f47628a commit 390f0fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
9 changes: 8 additions & 1 deletion test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})
Expand Down
39 changes: 35 additions & 4 deletions test/integration/gen_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 390f0fc

Please sign in to comment.