Test MapBuilderServer (#762)

Test to start and stop the MapBuilderServer.
Moves test helper functions in common with MapBuilderTest
to internal/mapping.
master
gaschler 2017-12-18 11:52:17 +01:00 committed by Wally B. Feed
parent 89b49dfefb
commit c6decd5b7b
4 changed files with 141 additions and 16 deletions

View File

@ -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>{
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

View File

@ -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 <memory>
#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_

View File

@ -21,9 +21,7 @@
#include <vector> #include <vector>
#include "cartographer/common/config.h" #include "cartographer/common/config.h"
#include "cartographer/common/configuration_file_resolver.h" #include "cartographer/internal/mapping/test_helpers.h"
#include "cartographer/common/lua_parameter_dictionary_test_helpers.h"
#include "cartographer/common/make_unique.h"
#include "cartographer/mapping/trajectory_builder_interface.h" #include "cartographer/mapping/trajectory_builder_interface.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -61,17 +59,6 @@ std::vector<sensor::TimedPointCloudData> GenerateFakeRangeMeasurements() {
return measurements; 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>{
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 { class MapBuilderTest : public ::testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
@ -81,7 +68,7 @@ class MapBuilderTest : public ::testing::Test {
MAP_BUILDER.use_trajectory_builder_2d = true MAP_BUILDER.use_trajectory_builder_2d = true
MAP_BUILDER.pose_graph.optimize_every_n_nodes = 0 MAP_BUILDER.pose_graph.optimize_every_n_nodes = 0
return MAP_BUILDER)text"; return MAP_BUILDER)text";
auto map_builder_parameters = ResolveLuaParameters(kMapBuilderLua); auto map_builder_parameters = test::ResolveLuaParameters(kMapBuilderLua);
map_builder_options_ = map_builder_options_ =
CreateMapBuilderOptions(map_builder_parameters.get()); CreateMapBuilderOptions(map_builder_parameters.get());
// Multiple submaps are created because of a small 'num_range_data'. // 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 TRAJECTORY_BUILDER.trajectory_builder_3d.submaps.num_range_data = 4
return TRAJECTORY_BUILDER)text"; return TRAJECTORY_BUILDER)text";
auto trajectory_builder_parameters = auto trajectory_builder_parameters =
ResolveLuaParameters(kTrajectoryBuilderLua); test::ResolveLuaParameters(kTrajectoryBuilderLua);
trajectory_builder_options_ = trajectory_builder_options_ =
CreateTrajectoryBuilderOptions(trajectory_builder_parameters.get()); CreateTrajectoryBuilderOptions(trajectory_builder_parameters.get());
} }

View File

@ -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<MapBuilderServer>(
map_builder_server_options);
EXPECT_TRUE(server_ != nullptr);
}
std::unique_ptr<MapBuilderServer> server_;
std::unique_ptr<mapping::MapBuilderStub> stub_;
};
TEST_F(ClientServerTest, StartAndStopServer) {
server_->Start();
server_->Shutdown();
}
} // namespace
} // namespace cartographer_grpc