From c6decd5b7b26288792ea90d8e0e741b7f942ffc6 Mon Sep 17 00:00:00 2001 From: gaschler Date: Mon, 18 Dec 2017 11:52:17 +0100 Subject: [PATCH] Test MapBuilderServer (#762) Test to start and stop the MapBuilderServer. Moves test helper functions in common with MapBuilderTest to internal/mapping. --- cartographer/internal/mapping/test_helpers.cc | 41 ++++++++++++ cartographer/internal/mapping/test_helpers.h | 35 +++++++++++ cartographer/mapping/map_builder_test.cc | 19 +----- cartographer_grpc/client_server_test.cc | 62 +++++++++++++++++++ 4 files changed, 141 insertions(+), 16 deletions(-) create mode 100644 cartographer/internal/mapping/test_helpers.cc create mode 100644 cartographer/internal/mapping/test_helpers.h create mode 100644 cartographer_grpc/client_server_test.cc diff --git a/cartographer/internal/mapping/test_helpers.cc b/cartographer/internal/mapping/test_helpers.cc new file mode 100644 index 0000000..6825871 --- /dev/null +++ b/cartographer/internal/mapping/test_helpers.cc @@ -0,0 +1,41 @@ +/* + * Copyright 2017 The Cartographer Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cartographer/internal/mapping/test_helpers.h" + +#include "cartographer/common/config.h" +#include "cartographer/common/configuration_file_resolver.h" +#include "cartographer/common/lua_parameter_dictionary_test_helpers.h" +#include "cartographer/common/make_unique.h" + +namespace cartographer { +namespace mapping { +namespace test { + +std::unique_ptr<::cartographer::common::LuaParameterDictionary> +ResolveLuaParameters(const std::string& lua_code) { + auto file_resolver = ::cartographer::common::make_unique< + ::cartographer::common::ConfigurationFileResolver>( + std::vector{ + std::string(::cartographer::common::kSourceDirectory) + + "/configuration_files"}); + return common::make_unique<::cartographer::common::LuaParameterDictionary>( + lua_code, std::move(file_resolver)); +} + +} // namespace test +} // namespace mapping +} // namespace cartographer diff --git a/cartographer/internal/mapping/test_helpers.h b/cartographer/internal/mapping/test_helpers.h new file mode 100644 index 0000000..db7b4a8 --- /dev/null +++ b/cartographer/internal/mapping/test_helpers.h @@ -0,0 +1,35 @@ +/* + * Copyright 2017 The Cartographer Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CARTOGRAPHER_INTERNAL_MAPPING_TEST_HELPERS_H_ +#define CARTOGRAPHER_INTERNAL_MAPPING_TEST_HELPERS_H_ + +#include + +#include "cartographer/common/lua_parameter_dictionary.h" + +namespace cartographer { +namespace mapping { +namespace test { + +std::unique_ptr<::cartographer::common::LuaParameterDictionary> +ResolveLuaParameters(const std::string& lua_code); + +} // namespace test +} // namespace mapping +} // namespace cartographer + +#endif // CARTOGRAPHER_INTERNAL_MAPPING_TEST_HELPERS_H_ diff --git a/cartographer/mapping/map_builder_test.cc b/cartographer/mapping/map_builder_test.cc index c8c5cf3..4ecf6f2 100644 --- a/cartographer/mapping/map_builder_test.cc +++ b/cartographer/mapping/map_builder_test.cc @@ -21,9 +21,7 @@ #include #include "cartographer/common/config.h" -#include "cartographer/common/configuration_file_resolver.h" -#include "cartographer/common/lua_parameter_dictionary_test_helpers.h" -#include "cartographer/common/make_unique.h" +#include "cartographer/internal/mapping/test_helpers.h" #include "cartographer/mapping/trajectory_builder_interface.h" #include "gtest/gtest.h" @@ -61,17 +59,6 @@ std::vector GenerateFakeRangeMeasurements() { return measurements; } -std::unique_ptr<::cartographer::common::LuaParameterDictionary> -ResolveLuaParameters(const std::string& lua_code) { - auto file_resolver = ::cartographer::common::make_unique< - ::cartographer::common::ConfigurationFileResolver>( - std::vector{ - std::string(::cartographer::common::kSourceDirectory) + - "/configuration_files"}); - return common::make_unique<::cartographer::common::LuaParameterDictionary>( - lua_code, std::move(file_resolver)); -} - class MapBuilderTest : public ::testing::Test { protected: void SetUp() override { @@ -81,7 +68,7 @@ class MapBuilderTest : public ::testing::Test { MAP_BUILDER.use_trajectory_builder_2d = true MAP_BUILDER.pose_graph.optimize_every_n_nodes = 0 return MAP_BUILDER)text"; - auto map_builder_parameters = ResolveLuaParameters(kMapBuilderLua); + auto map_builder_parameters = test::ResolveLuaParameters(kMapBuilderLua); map_builder_options_ = CreateMapBuilderOptions(map_builder_parameters.get()); // Multiple submaps are created because of a small 'num_range_data'. @@ -92,7 +79,7 @@ class MapBuilderTest : public ::testing::Test { TRAJECTORY_BUILDER.trajectory_builder_3d.submaps.num_range_data = 4 return TRAJECTORY_BUILDER)text"; auto trajectory_builder_parameters = - ResolveLuaParameters(kTrajectoryBuilderLua); + test::ResolveLuaParameters(kTrajectoryBuilderLua); trajectory_builder_options_ = CreateTrajectoryBuilderOptions(trajectory_builder_parameters.get()); } diff --git a/cartographer_grpc/client_server_test.cc b/cartographer_grpc/client_server_test.cc new file mode 100644 index 0000000..2b9c9f2 --- /dev/null +++ b/cartographer_grpc/client_server_test.cc @@ -0,0 +1,62 @@ +/* + * Copyright 2017 The Cartographer Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cartographer/internal/mapping/test_helpers.h" +#include "cartographer_grpc/map_builder_server.h" +#include "cartographer_grpc/map_builder_server_options.h" +#include "cartographer_grpc/mapping/map_builder_stub.h" +#include "glog/logging.h" +#include "gtest/gtest.h" + +namespace cartographer_grpc { +namespace { + +class ClientServerTest : public ::testing::Test { + protected: + void SetUp() override { + // TODO(cschuet): Due to the hard-coded addresses these tests will become + // flaky when run in parallel. + const std::string kMapBuilderServerLua = R"text( + include "map_builder_server.lua" + MAP_BUILDER.use_trajectory_builder_2d = true + MAP_BUILDER.pose_graph.optimize_every_n_nodes = 0 + MAP_BUILDER_SERVER = { + server_address = "0.0.0.0:50051", + num_event_threads = 1, + num_grpc_threads = 1, + map_builder = MAP_BUILDER, + } + return MAP_BUILDER_SERVER)text"; + auto map_builder_server_parameters = + cartographer::mapping::test::ResolveLuaParameters(kMapBuilderServerLua); + auto map_builder_server_options = + CreateMapBuilderServerOptions(map_builder_server_parameters.get()); + server_ = cartographer::common::make_unique( + map_builder_server_options); + EXPECT_TRUE(server_ != nullptr); + } + + std::unique_ptr server_; + std::unique_ptr stub_; +}; + +TEST_F(ClientServerTest, StartAndStopServer) { + server_->Start(); + server_->Shutdown(); +} + +} // namespace +} // namespace cartographer_grpc