Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a shared library linked to integration_test_target #124

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions test/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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", []))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we just use the same "includes" for the shared lib? It'd simplify writing the test configs and the worst that'll happen is that we'll get unnecessary includes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, "includes_shlib" should be documented too

add_headers(f, custom_headers=headers, thrift_headers=[])

from textwrap import dedent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀
nice


for config in test_configs:
ns = config["suite"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ns = config["suite"]
ns = get_namespace(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