Skip to content

Commit

Permalink
Merge branch 'gz-transport12' into srmainwaring/12/node-abstract-request
Browse files Browse the repository at this point in the history
  • Loading branch information
caguero authored Jan 4, 2024
2 parents d5aabc8 + 1db0afe commit c3898f4
Show file tree
Hide file tree
Showing 54 changed files with 1,041 additions and 1,288 deletions.
131 changes: 131 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load(
"@gz//bazel/lint:lint.bzl",
"add_lint_tests",
)

package(
default_visibility = GZ_VISIBILITY,
features = GZ_FEATURES,
)

licenses(["notice"]) # Apache-2.0

exports_files(["LICENSE"])

gz_configure_header(
name = "transport_config_hh",
src = "include/gz/transport/config.hh.in",
cmakelists = ["CMakeLists.txt"],
package = "transport",
)

gz_export_header(
name = "include/gz/transport/Export.hh",
export_base = "GZ_TRANSPORT",
lib_name = "gz-transport",
visibility = ["//visibility:private"],
)

public_headers_no_gen = glob([
"include/gz/transport/*.h",
"include/gz/transport/*.hh",
"include/gz/transport/detail/*.hh",
])

private_headers = glob(["src/*.hh"])

sources = glob(
["src/*.cc"],
exclude = [
"src/*_TEST.cc",
],
)

gz_include_header(
name = "transport_hh_genrule",
out = "include/gz/transport.hh",
hdrs = public_headers_no_gen + [
"include/gz/transport/config.hh",
"include/gz/transport/Export.hh",
],
)

public_headers = public_headers_no_gen + [
"include/gz/transport/config.hh",
"include/gz/transport/Export.hh",
"include/gz/transport.hh",
]

cc_library(
name = "transport",
srcs = sources + private_headers,
hdrs = public_headers,
copts = [
"-Wno-deprecated-declarations",
],
includes = ["include"],
deps = [
GZ_ROOT + "msgs",
"@uuid",
"@zmq",
],
)

cc_binary(
name = "topic",
srcs = [
"src/cmd/gz.cc",
"src/cmd/gz.hh",
"src/cmd/topic_main.cc",
],
includes = ["src/cmd"],
deps = [
":transport",
GZ_ROOT + "utils/cli",
],
)

cc_binary(
name = "service",
srcs = [
"src/cmd/gz.cc",
"src/cmd/gz.hh",
"src/cmd/service_main.cc",
],
includes = ["src/cmd"],
deps = [
":transport",
GZ_ROOT + "utils/cli",
],
)

test_sources = glob(
include = ["src/*_TEST.cc"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "transport",
},
deps = [
":transport",
GZ_ROOT + "common/testing",
GZ_ROOT + "transport/test:utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]

add_lint_tests()
91 changes: 91 additions & 0 deletions log/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
load(
"@gz//bazel/skylark:build_defs.bzl",
"GZ_FEATURES",
"GZ_ROOT",
"GZ_VISIBILITY",
"cmake_configure_file",
"gz_configure_header",
"gz_export_header",
"gz_include_header",
)
load(
"@gz//bazel/lint:lint.bzl",
"add_lint_tests",
)

cmake_configure_file(
name = "build_config",
src = "src/build_config.hh.in",
out = "include/build_config.hh",
cmakelists = ["src/CMakeLists.txt"],
defines = [
"SCHEMA_INSTALL_PATH=transport/log/sql",
],
)

gz_export_header(
name = "include/gz/transport/log/Export.hh",
export_base = "GZ_TRANSPORT_LOG",
lib_name = "gz-transport-log",
visibility = ["//visibility:private"],
)

public_headers_no_gen = glob([
"include/gz/transport/log/*.hh",
"include/gz/transport/log/detail/*.hh",
])

private_headers = glob(["src/*.hh"])

sources = glob(
["src/*.cc"],
exclude = [
"src/*_TEST.cc",
],
)

public_headers = public_headers_no_gen + [
"include/gz/transport/log/Export.hh",
]

cc_library(
name = "log",
srcs = sources + private_headers + ["include/build_config.hh"],
hdrs = public_headers,
data = ["sql/0.1.0.sql"],
includes = ["include"],
deps = [
GZ_ROOT + "transport",
"@sqlite3",
],
)

test_sources = glob(
include = ["src/*_TEST.cc"],
exclude = ["src/LogCommandAPI_TEST.cc"],
)

[cc_test(
name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
srcs = [src],
data = [
"test/data/state.tlog",
],
defines = [
'GZ_TRANSPORT_LOG_TEST_PATH=\\"transport/log/test\\"',
'CORRUPT_DB_TEST_PATH=\\"transport/log/test/data/state.tlog\\"',
],
env = {
"GZ_BAZEL": "1",
"GZ_BAZEL_PATH": "transport",
},
deps = [
":log",
GZ_ROOT + "common/testing",
GZ_ROOT + "transport/test:utils",
"@gtest",
"@gtest//:gtest_main",
],
) for src in test_sources]

add_lint_tests()
11 changes: 5 additions & 6 deletions log/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ endif()
gz_build_tests(
TYPE "UNIT"
SOURCES ${gtest_sources}
LIB_DEPS ${log_lib_target} ${EXTRA_TEST_LIB_DEPS}
LIB_DEPS ${log_lib_target} ${EXTRA_TEST_LIB_DEPS} test_config
TEST_LIST logging_tests
)

foreach(test_target ${logging_tests})

set_tests_properties(${logging_tests} PROPERTIES
set_tests_properties(${test_target} PROPERTIES
ENVIRONMENT GZ_TRANSPORT_LOG_SQL_PATH=${PROJECT_SOURCE_DIR}/log/sql)
target_compile_definitions(${test_target} PRIVATE
"CORRUPT_DB_TEST_PATH=\"${CMAKE_SOURCE_DIR}/log/test/data/state.tlog\""
)

endforeach()

Expand All @@ -46,9 +48,6 @@ install(DIRECTORY ../sql DESTINATION ${SCHEMA_INSTALL_BASE})
set(SCHEMA_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/${SCHEMA_INSTALL_BASE}/sql)
configure_file(build_config.hh.in build_config.hh @ONLY)


message(STATUS "CMAKE_CURRENT_SOURCE_DIR:${CMAKE_CURRENT_SOURCE_DIR}")

target_include_directories(${log_lib_target}
PUBLIC
# Add this component's include directory to the build interface include
Expand Down
15 changes: 8 additions & 7 deletions log/src/Log_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@
* limitations under the License.
*
*/
#include "gtest/gtest.h"

#include <chrono>
#include <ios>
#include <string>
#include <unordered_set>

#include "gz/transport/log/Log.hh"
#include "test_config.hh"
#include "log/test_config.hh"
#include "gtest/gtest.h"

#include "test_utils.hh"

using namespace gz;
using namespace gz::transport;
using namespace std::chrono_literals;

namespace {
constexpr const char * kCorruptDbTestPath = CORRUPT_DB_TEST_PATH;
}

//////////////////////////////////////////////////
TEST(Log, OpenMemoryDatabase)
{
Expand Down Expand Up @@ -251,10 +255,7 @@ TEST(Log, NullDescriptorUnopenedLog)
TEST(Log, OpenCorruptDatabase)
{
log::Log logFile;
std::string path =
testing::portablePathUnion(GZ_TRANSPORT_LOG_TEST_PATH, "data");
path = testing::portablePathUnion(path, "state.tlog");
logFile.Open(path);
logFile.Open(kCorruptDbTestPath);
EXPECT_GT(logFile.EndTime(), 0ns) << "logFile.EndTime() == "
<< logFile.EndTime().count() << "ns";;
}
4 changes: 0 additions & 4 deletions log/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
configure_file (test_config.hh.in
${PROJECT_BINARY_DIR}/include/log/test_config.hh
)

add_subdirectory(integration)
47 changes: 11 additions & 36 deletions log/test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Integration tests


add_library(ChirpParams STATIC ./ChirpParams.cc)
target_link_libraries(ChirpParams PUBLIC ${PROJECT_LIBRARY_TARGET_NAME}-log ${EXTRA_TEST_LIB_DEPS})
target_compile_definitions(ChirpParams
PRIVATE TOPIC_CHIRP_EXE="$<TARGET_FILE:topicChirp_aux>")

gz_add_executable(topicChirp_aux topicChirp_aux.cc)
target_link_libraries(topicChirp_aux ChirpParams)

gz_build_tests(
TYPE "INTEGRATION"
TEST_LIST logging_tests
Expand All @@ -8,8 +17,10 @@ gz_build_tests(
playback.cc
query.cc
LIB_DEPS
ChirpParams
${PROJECT_LIBRARY_TARGET_NAME}-log
${EXTRA_TEST_LIB_DEPS}
test_config
INCLUDE_DIRS
${CMAKE_BINARY_DIR}/test/
)
Expand All @@ -21,48 +32,12 @@ if (UNIX AND NOT APPLE)
endif()

foreach(test_target ${logging_tests})

set_tests_properties(${test_target} PROPERTIES
ENVIRONMENT GZ_TRANSPORT_LOG_SQL_PATH=${PROJECT_SOURCE_DIR}/log/sql)
target_compile_definitions(${test_target}
PRIVATE GZ_TRANSPORT_LOG_SQL_PATH="${PROJECT_SOURCE_DIR}/log/sql")
target_compile_definitions(${test_target}
PRIVATE GZ_TRANSPORT_LOG_BUILD_PATH="$<TARGET_FILE_DIR:${test_target}>")

endforeach()

set (aux
topicChirp_aux.cc
)

foreach(source_file ${aux})
string(REGEX REPLACE ".cc" "" AUX_EXECUTABLE ${source_file})
set(BINARY_NAME ${TEST_TYPE}_${AUX_EXECUTABLE})

gz_add_executable(${BINARY_NAME} ${AUX_EXECUTABLE}.cc)

# Include the interface directories that we always need.
gz_target_interface_include_directories(${BINARY_NAME}
${PROJECT_LIBRARY_TARGET_NAME})

# Link the libraries that we always need.
target_link_libraries(${BINARY_NAME}
PRIVATE
${PROJECT_LIBRARY_TARGET_NAME}
${log_lib_target}
gtest
${EXTRA_TEST_LIB_DEPS}
)

if(UNIX)
# pthread is only available on Unix machines
target_link_libraries(${BINARY_NAME}
PRIVATE pthread)
endif()

target_compile_definitions(${BINARY_NAME}
PRIVATE GZ_TRANSPORT_LOG_BUILD_PATH="$<TARGET_FILE_DIR:${BINARY_NAME}>")
endforeach()

# gz log CLI test
if (HAVE_GZ_TOOLS)
Expand Down
Loading

0 comments on commit c3898f4

Please sign in to comment.