From c7dff41e56e5d5646b865b1763ec8468a3a40bc1 Mon Sep 17 00:00:00 2001 From: Anshul Data Date: Fri, 20 Sep 2024 10:34:58 +0530 Subject: [PATCH] Enable substrait extension unit test debugging via debugger --- CMakeLists.txt | 175 ++++++++++++++++---------------- extension_config.cmake | 1 + test/c/CMakeLists.txt | 9 +- test/c/test_substrait_c_api.cpp | 16 +-- 4 files changed, 108 insertions(+), 93 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f180c46..6d279fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,96 +10,100 @@ include_directories(src/include) include_directories(third_party/substrait) include_directories(third_party/) +# refer source by absolute path. So that we can use the same source in the child profile too (i.e. test/c) +set(THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party") set(PROTOBUF_SOURCES - third_party/google/protobuf/any.cc - third_party/google/protobuf/any.pb.cc - third_party/google/protobuf/any_lite.cc - third_party/google/protobuf/arena.cc - third_party/google/protobuf/arenastring.cc - third_party/google/protobuf/descriptor.cc - third_party/google/protobuf/descriptor.pb.cc - third_party/google/protobuf/descriptor_database.cc - third_party/google/protobuf/dynamic_message.cc - third_party/google/protobuf/empty.pb.cc - third_party/google/protobuf/extension_set.cc - third_party/google/protobuf/extension_set_heavy.cc - third_party/google/protobuf/generated_enum_util.cc - third_party/google/protobuf/generated_message_bases.cc - third_party/google/protobuf/generated_message_reflection.cc - third_party/google/protobuf/generated_message_table_driven.cc - third_party/google/protobuf/generated_message_table_driven_lite.cc - third_party/google/protobuf/generated_message_util.cc - third_party/google/protobuf/implicit_weak_message.cc - third_party/google/protobuf/inlined_string_field.cc - third_party/google/protobuf/map.cc - third_party/google/protobuf/map_field.cc - third_party/google/protobuf/message.cc - third_party/google/protobuf/message_lite.cc - third_party/google/protobuf/parse_context.cc - third_party/google/protobuf/port_def.inc - third_party/google/protobuf/port_undef.inc - third_party/google/protobuf/reflection_ops.cc - third_party/google/protobuf/repeated_field.cc - third_party/google/protobuf/repeated_ptr_field.cc - third_party/google/protobuf/text_format.cc - third_party/google/protobuf/unknown_field_set.cc - third_party/google/protobuf/wire_format.cc - third_party/google/protobuf/wire_format_lite.cc - third_party/google/protobuf/io/coded_stream.cc - third_party/google/protobuf/io/io_win32.cc - third_party/google/protobuf/io/strtod.cc - third_party/google/protobuf/io/tokenizer.cc - third_party/google/protobuf/io/zero_copy_stream.cc - third_party/google/protobuf/io/zero_copy_stream_impl.cc - third_party/google/protobuf/io/zero_copy_stream_impl_lite.cc - third_party/google/protobuf/stubs/common.cc - third_party/google/protobuf/stubs/int128.cc - third_party/google/protobuf/stubs/status.cc - third_party/google/protobuf/stubs/stringpiece.cc - third_party/google/protobuf/stubs/stringprintf.cc - third_party/google/protobuf/stubs/structurally_valid.cc - third_party/google/protobuf/stubs/strutil.cc - third_party/google/protobuf/stubs/substitute.cc - third_party/google/protobuf/stubs/bytestream.cc - third_party/google/protobuf/util/json_util.cc - third_party/google/protobuf/util/internal/datapiece.cc - third_party/google/protobuf/util/internal/default_value_objectwriter.cc - third_party/google/protobuf/util/internal/error_listener.cc - third_party/google/protobuf/util/internal/json_escaping.cc - third_party/google/protobuf/util/internal/json_objectwriter.cc - third_party/google/protobuf/util/internal/json_stream_parser.cc - third_party/google/protobuf/util/json_util.cc - third_party/google/protobuf/util/internal/object_writer.cc - third_party/google/protobuf/util/internal/proto_writer.cc - third_party/google/protobuf/util/internal/protostream_objectsource.cc - third_party/google/protobuf/util/internal/protostream_objectwriter.cc - third_party/google/protobuf/source_context.pb.cc - third_party/google/protobuf/stubs/statusor.cc - third_party/google/protobuf/stubs/time.cc - third_party/google/protobuf/type.pb.cc - third_party/google/protobuf/wrappers.pb.cc - third_party/google/protobuf/struct.pb.cc - third_party/google/protobuf/util/internal/type_info.cc - third_party/google/protobuf/util/internal/field_mask_utility.cc - third_party/google/protobuf/util/type_resolver_util.cc - third_party/google/protobuf/util/internal/utility.cc) + ${THIRD_PARTY_DIR}/google/protobuf/any.cc + ${THIRD_PARTY_DIR}/google/protobuf/any.pb.cc + ${THIRD_PARTY_DIR}/google/protobuf/any_lite.cc + ${THIRD_PARTY_DIR}/google/protobuf/arena.cc + ${THIRD_PARTY_DIR}/google/protobuf/arenastring.cc + ${THIRD_PARTY_DIR}/google/protobuf/descriptor.cc + ${THIRD_PARTY_DIR}/google/protobuf/descriptor.pb.cc + ${THIRD_PARTY_DIR}/google/protobuf/descriptor_database.cc + ${THIRD_PARTY_DIR}/google/protobuf/dynamic_message.cc + ${THIRD_PARTY_DIR}/google/protobuf/empty.pb.cc + ${THIRD_PARTY_DIR}/google/protobuf/extension_set.cc + ${THIRD_PARTY_DIR}/google/protobuf/extension_set_heavy.cc + ${THIRD_PARTY_DIR}/google/protobuf/generated_enum_util.cc + ${THIRD_PARTY_DIR}/google/protobuf/generated_message_bases.cc + ${THIRD_PARTY_DIR}/google/protobuf/generated_message_reflection.cc + ${THIRD_PARTY_DIR}/google/protobuf/generated_message_table_driven.cc + ${THIRD_PARTY_DIR}/google/protobuf/generated_message_table_driven_lite.cc + ${THIRD_PARTY_DIR}/google/protobuf/generated_message_util.cc + ${THIRD_PARTY_DIR}/google/protobuf/implicit_weak_message.cc + ${THIRD_PARTY_DIR}/google/protobuf/inlined_string_field.cc + ${THIRD_PARTY_DIR}/google/protobuf/map.cc + ${THIRD_PARTY_DIR}/google/protobuf/map_field.cc + ${THIRD_PARTY_DIR}/google/protobuf/message.cc + ${THIRD_PARTY_DIR}/google/protobuf/message_lite.cc + ${THIRD_PARTY_DIR}/google/protobuf/parse_context.cc + ${THIRD_PARTY_DIR}/google/protobuf/port_def.inc + ${THIRD_PARTY_DIR}/google/protobuf/port_undef.inc + ${THIRD_PARTY_DIR}/google/protobuf/reflection_ops.cc + ${THIRD_PARTY_DIR}/google/protobuf/repeated_field.cc + ${THIRD_PARTY_DIR}/google/protobuf/repeated_ptr_field.cc + ${THIRD_PARTY_DIR}/google/protobuf/text_format.cc + ${THIRD_PARTY_DIR}/google/protobuf/unknown_field_set.cc + ${THIRD_PARTY_DIR}/google/protobuf/wire_format.cc + ${THIRD_PARTY_DIR}/google/protobuf/wire_format_lite.cc + ${THIRD_PARTY_DIR}/google/protobuf/io/coded_stream.cc + ${THIRD_PARTY_DIR}/google/protobuf/io/io_win32.cc + ${THIRD_PARTY_DIR}/google/protobuf/io/strtod.cc + ${THIRD_PARTY_DIR}/google/protobuf/io/tokenizer.cc + ${THIRD_PARTY_DIR}/google/protobuf/io/zero_copy_stream.cc + ${THIRD_PARTY_DIR}/google/protobuf/io/zero_copy_stream_impl.cc + ${THIRD_PARTY_DIR}/google/protobuf/io/zero_copy_stream_impl_lite.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/common.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/int128.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/status.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/stringpiece.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/stringprintf.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/structurally_valid.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/strutil.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/substitute.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/bytestream.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/json_util.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/datapiece.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/default_value_objectwriter.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/error_listener.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/json_escaping.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/json_objectwriter.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/json_stream_parser.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/json_util.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/object_writer.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/proto_writer.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/protostream_objectsource.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/protostream_objectwriter.cc + ${THIRD_PARTY_DIR}/google/protobuf/source_context.pb.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/statusor.cc + ${THIRD_PARTY_DIR}/google/protobuf/stubs/time.cc + ${THIRD_PARTY_DIR}/google/protobuf/type.pb.cc + ${THIRD_PARTY_DIR}/google/protobuf/wrappers.pb.cc + ${THIRD_PARTY_DIR}/google/protobuf/struct.pb.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/type_info.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/field_mask_utility.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/type_resolver_util.cc + ${THIRD_PARTY_DIR}/google/protobuf/util/internal/utility.cc) set(SUBSTRAIT_SOURCES - third_party/substrait/substrait/algebra.pb.cc - third_party/substrait/substrait/capabilities.pb.cc - third_party/substrait/substrait/function.pb.cc - third_party/substrait/substrait/parameterized_types.pb.cc - third_party/substrait/substrait/plan.pb.cc - third_party/substrait/substrait/type.pb.cc - third_party/substrait/substrait/type_expressions.pb.cc - third_party/substrait/substrait/extensions/extensions.pb.cc) + ${THIRD_PARTY_DIR}/substrait/substrait/algebra.pb.cc + ${THIRD_PARTY_DIR}/substrait/substrait/capabilities.pb.cc + ${THIRD_PARTY_DIR}/substrait/substrait/function.pb.cc + ${THIRD_PARTY_DIR}/substrait/substrait/parameterized_types.pb.cc + ${THIRD_PARTY_DIR}/substrait/substrait/plan.pb.cc + ${THIRD_PARTY_DIR}/substrait/substrait/type.pb.cc + ${THIRD_PARTY_DIR}/substrait/substrait/type_expressions.pb.cc + ${THIRD_PARTY_DIR}/substrait/substrait/extensions/extensions.pb.cc) +# refer source by absolute path. So that we can use the same source in the child profile too (i.e. test/c) +set(EXTENSION_SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") set(EXTENSION_SOURCES - src/to_substrait.cpp - src/from_substrait.cpp - src/substrait_extension.cpp - src/custom_extensions.cpp - src/custom_extensions_generated.cpp + ${EXTENSION_SOURCES_DIR}/to_substrait.cpp + ${EXTENSION_SOURCES_DIR}/from_substrait.cpp + ${EXTENSION_SOURCES_DIR}/substrait_extension.cpp + ${EXTENSION_SOURCES_DIR}/custom_extensions.cpp + ${EXTENSION_SOURCES_DIR}/custom_extensions_generated.cpp ${SUBSTRAIT_SOURCES} ${PROTOBUF_SOURCES}) @@ -107,6 +111,7 @@ add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES}) set(PARAMETERS "-warnings") build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${EXTENSION_SOURCES}) +add_subdirectory(test/c) install( TARGETS ${EXTENSION_NAME} diff --git a/extension_config.cmake b/extension_config.cmake index 7665aeb..1051573 100644 --- a/extension_config.cmake +++ b/extension_config.cmake @@ -5,4 +5,5 @@ duckdb_extension_load(substrait SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/include LOAD_TESTS + DONT_LINK ) diff --git a/test/c/CMakeLists.txt b/test/c/CMakeLists.txt index e84f702..1660f20 100644 --- a/test/c/CMakeLists.txt +++ b/test/c/CMakeLists.txt @@ -12,10 +12,15 @@ include_directories(../../duckdb/src/include) include_directories(../../duckdb/test/include) include_directories(../../duckdb/third_party/catch) -set(ALL_SOURCES test_substrait_c_api.cpp) +# get all source files from test/helpers +file(GLOB TEST_HELPER_SOURCES "../../duckdb/test/helpers/*.cpp") +set(ALL_SOURCES ${EXTENSION_SOURCES} ${TEST_HELPER_SOURCES} test_substrait_c_api.cpp) +# this add_executable is needed to make unit test a target +add_executable(test_substrait test_substrait_c_api.cpp ${ALL_SOURCES}) +# add duckdb static library to the test so that duckdb symbols are available +target_link_libraries(test_substrait duckdb_static) -add_library_unity(test_substrait OBJECT ${ALL_SOURCES}) set(ALL_OBJECT_FILES ${ALL_OBJECT_FILES} $ PARENT_SCOPE) diff --git a/test/c/test_substrait_c_api.cpp b/test/c/test_substrait_c_api.cpp index 3f97646..9a6e579 100644 --- a/test/c/test_substrait_c_api.cpp +++ b/test/c/test_substrait_c_api.cpp @@ -1,19 +1,22 @@ +#define CATCH_CONFIG_RUNNER #include "catch.hpp" #include "test_helpers.hpp" -#include "duckdb/parser/parser.hpp" -#include "duckdb/planner/logical_operator.hpp" #include "duckdb/main/connection_manager.hpp" #include "substrait_extension.hpp" -#include -#include using namespace duckdb; using namespace std; +int main(int argc, char* argv[]) { + // Call Catch2's session to run tests + return Catch::Session().run(argc, argv); +} + TEST_CASE("Test C Get and To Substrait API", "[substrait-api]") { DuckDB db(nullptr); - db.LoadExtension(); + SubstraitExtension substrait_extension; + substrait_extension.Load(db); Connection con(db); con.EnableQueryVerification(); // create the database @@ -33,7 +36,8 @@ TEST_CASE("Test C Get and To Substrait API", "[substrait-api]") { TEST_CASE("Test C Get and To Json-Substrait API", "[substrait-api]") { DuckDB db(nullptr); - db.LoadExtension(); + SubstraitExtension substrait_extension; + substrait_extension.Load(db); Connection con(db); con.EnableQueryVerification(); // create the database