Add LoadState() test case to ClientServerTest. (#1189)
parent
849f2a66ac
commit
42c1288e66
|
@ -20,6 +20,7 @@
|
||||||
#include "cartographer/cloud/client/map_builder_stub.h"
|
#include "cartographer/cloud/client/map_builder_stub.h"
|
||||||
#include "cartographer/cloud/internal/map_builder_server.h"
|
#include "cartographer/cloud/internal/map_builder_server.h"
|
||||||
#include "cartographer/cloud/map_builder_server_options.h"
|
#include "cartographer/cloud/map_builder_server_options.h"
|
||||||
|
#include "cartographer/io/testing/test_helpers.h"
|
||||||
#include "cartographer/mapping/internal/testing/mock_map_builder.h"
|
#include "cartographer/mapping/internal/testing/mock_map_builder.h"
|
||||||
#include "cartographer/mapping/internal/testing/mock_pose_graph.h"
|
#include "cartographer/mapping/internal/testing/mock_pose_graph.h"
|
||||||
#include "cartographer/mapping/internal/testing/mock_trajectory_builder.h"
|
#include "cartographer/mapping/internal/testing/mock_trajectory_builder.h"
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
using ::cartographer::io::testing::ProtoReaderFromStrings;
|
||||||
using ::cartographer::mapping::MapBuilder;
|
using ::cartographer::mapping::MapBuilder;
|
||||||
using ::cartographer::mapping::MapBuilderInterface;
|
using ::cartographer::mapping::MapBuilderInterface;
|
||||||
using ::cartographer::mapping::PoseGraphInterface;
|
using ::cartographer::mapping::PoseGraphInterface;
|
||||||
|
@ -49,6 +51,28 @@ constexpr double kDuration = 4.; // Seconds.
|
||||||
constexpr double kTimeStep = 0.1; // Seconds.
|
constexpr double kTimeStep = 0.1; // Seconds.
|
||||||
constexpr double kTravelDistance = 1.2; // Meters.
|
constexpr double kTravelDistance = 1.2; // Meters.
|
||||||
|
|
||||||
|
constexpr char kSerializationHeaderProtoString[] = "format_version: 1";
|
||||||
|
constexpr char kUnsupportedSerializationHeaderProtoString[] =
|
||||||
|
"format_version: 123";
|
||||||
|
constexpr char kPoseGraphProtoString[] = R"(pose_graph {
|
||||||
|
trajectory: {
|
||||||
|
trajectory_id: 0
|
||||||
|
node: {}
|
||||||
|
submap: {}
|
||||||
|
}
|
||||||
|
})";
|
||||||
|
constexpr char kAllTrajectoryBuilderOptionsProtoString[] =
|
||||||
|
R"(all_trajectory_builder_options {
|
||||||
|
options_with_sensor_ids: {}
|
||||||
|
})";
|
||||||
|
constexpr char kSubmapProtoString[] = "submap {}";
|
||||||
|
constexpr char kNodeProtoString[] = "node {}";
|
||||||
|
constexpr char kTrajectoryDataProtoString[] = "trajectory_data {}";
|
||||||
|
constexpr char kImuDataProtoString[] = "imu_data {}";
|
||||||
|
constexpr char kOdometryDataProtoString[] = "odometry_data {}";
|
||||||
|
constexpr char kFixedFramePoseDataProtoString[] = "fixed_frame_pose_data {}";
|
||||||
|
constexpr char kLandmarkDataProtoString[] = "landmark_data {}";
|
||||||
|
|
||||||
class ClientServerTest : public ::testing::Test {
|
class ClientServerTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
|
@ -399,6 +423,31 @@ TEST_F(ClientServerTest, LocalSlam2DWithUploadingServer) {
|
||||||
server_->Shutdown();
|
server_->Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ClientServerTest, LoadState) {
|
||||||
|
InitializeRealServer();
|
||||||
|
server_->Start();
|
||||||
|
InitializeStub();
|
||||||
|
|
||||||
|
// Load text proto into in_memory_reader.
|
||||||
|
auto reader =
|
||||||
|
ProtoReaderFromStrings(kSerializationHeaderProtoString,
|
||||||
|
{
|
||||||
|
kPoseGraphProtoString,
|
||||||
|
kAllTrajectoryBuilderOptionsProtoString,
|
||||||
|
kSubmapProtoString,
|
||||||
|
kNodeProtoString,
|
||||||
|
kTrajectoryDataProtoString,
|
||||||
|
kImuDataProtoString,
|
||||||
|
kOdometryDataProtoString,
|
||||||
|
kFixedFramePoseDataProtoString,
|
||||||
|
kLandmarkDataProtoString,
|
||||||
|
});
|
||||||
|
|
||||||
|
stub_->LoadState(reader.get(), true);
|
||||||
|
EXPECT_TRUE(stub_->pose_graph()->IsTrajectoryFrozen(0));
|
||||||
|
server_->Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace cloud
|
} // namespace cloud
|
||||||
} // namespace cartographer
|
} // namespace cartographer
|
||||||
|
|
|
@ -40,7 +40,6 @@ void LoadStateHandler::OnRequest(const proto::LoadStateRequest& request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadStateHandler::OnReadsDone() {
|
void LoadStateHandler::OnReadsDone() {
|
||||||
LOG(INFO) << "OnReadsDone";
|
|
||||||
GetContext<MapBuilderContextInterface>()->map_builder().LoadState(&reader_,
|
GetContext<MapBuilderContextInterface>()->map_builder().LoadState(&reader_,
|
||||||
true);
|
true);
|
||||||
Send(common::make_unique<google::protobuf::Empty>());
|
Send(common::make_unique<google::protobuf::Empty>());
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "cartographer/io/internal/in_memory_proto_stream.h"
|
#include "cartographer/io/internal/in_memory_proto_stream.h"
|
||||||
#include "cartographer/io/proto_stream_deserializer.h"
|
#include "cartographer/io/proto_stream_deserializer.h"
|
||||||
|
#include "cartographer/io/testing/test_helpers.h"
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "google/protobuf/text_format.h"
|
#include "google/protobuf/text_format.h"
|
||||||
|
@ -29,6 +30,8 @@ namespace io {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using ::cartographer::common::make_unique;
|
using ::cartographer::common::make_unique;
|
||||||
|
using ::cartographer::io::testing::ProtoFromStringOrDie;
|
||||||
|
using ::cartographer::io::testing::ProtoReaderFromStrings;
|
||||||
using ::cartographer::mapping::proto::SerializationHeader;
|
using ::cartographer::mapping::proto::SerializationHeader;
|
||||||
using ::cartographer::mapping::proto::SerializedData;
|
using ::cartographer::mapping::proto::SerializedData;
|
||||||
using ::google::protobuf::Message;
|
using ::google::protobuf::Message;
|
||||||
|
@ -50,35 +53,15 @@ constexpr char kOdometryDataProtoString[] = "odometry_data {}";
|
||||||
constexpr char kFixedFramePoseDataProtoString[] = "fixed_frame_pose_data {}";
|
constexpr char kFixedFramePoseDataProtoString[] = "fixed_frame_pose_data {}";
|
||||||
constexpr char kLandmarkDataProtoString[] = "landmark_data {}";
|
constexpr char kLandmarkDataProtoString[] = "landmark_data {}";
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T ProtoFromStringOrDie(const std::string& proto_string) {
|
|
||||||
T msg;
|
|
||||||
CHECK(google::protobuf::TextFormat::ParseFromString(proto_string, &msg));
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProtoStreamDeserializerTest : public ::testing::Test {
|
class ProtoStreamDeserializerTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void InitializeProtoReader(
|
|
||||||
const std::string& header_textpb,
|
|
||||||
const std::initializer_list<std::string>& data_textpbs) {
|
|
||||||
std::queue<std::unique_ptr<Message>> proto_queue;
|
|
||||||
proto_queue.emplace(make_unique<SerializationHeader>(
|
|
||||||
ProtoFromStringOrDie<SerializationHeader>(header_textpb)));
|
|
||||||
for (const std::string& data_textpb : data_textpbs) {
|
|
||||||
proto_queue.emplace(make_unique<SerializedData>(
|
|
||||||
ProtoFromStringOrDie<SerializedData>(data_textpb)));
|
|
||||||
}
|
|
||||||
reader_ = make_unique<InMemoryProtoStreamReader>(std::move(proto_queue));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<InMemoryProtoStreamReader> reader_;
|
std::unique_ptr<InMemoryProtoStreamReader> reader_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This test checks if the serialization works.
|
// This test checks if the serialization works.
|
||||||
TEST_F(ProtoStreamDeserializerTest, WorksOnGoldenTextStream) {
|
TEST_F(ProtoStreamDeserializerTest, WorksOnGoldenTextStream) {
|
||||||
// Load text proto into in_memory_reader.
|
// Load text proto into in_memory_reader.
|
||||||
InitializeProtoReader(kSerializationHeaderProtoString,
|
reader_ = ProtoReaderFromStrings(kSerializationHeaderProtoString,
|
||||||
{
|
{
|
||||||
kPoseGraphProtoString,
|
kPoseGraphProtoString,
|
||||||
kAllTrajectoryBuilderOptionsProtoString,
|
kAllTrajectoryBuilderOptionsProtoString,
|
||||||
|
@ -149,7 +132,8 @@ TEST_F(ProtoStreamDeserializerTest, WorksOnGoldenTextStream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ProtoStreamDeserializerTest, FailsIfVersionNotSupported) {
|
TEST_F(ProtoStreamDeserializerTest, FailsIfVersionNotSupported) {
|
||||||
InitializeProtoReader(kUnsupportedSerializationHeaderProtoString, {});
|
reader_ =
|
||||||
|
ProtoReaderFromStrings(kUnsupportedSerializationHeaderProtoString, {});
|
||||||
EXPECT_DEATH(common::make_unique<ProtoStreamDeserializer>(reader_.get()),
|
EXPECT_DEATH(common::make_unique<ProtoStreamDeserializer>(reader_.get()),
|
||||||
"Unsupported serialization format");
|
"Unsupported serialization format");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 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/io/testing/test_helpers.h"
|
||||||
|
#include "cartographer/mapping/proto/serialization.pb.h"
|
||||||
|
|
||||||
|
namespace cartographer {
|
||||||
|
namespace io {
|
||||||
|
namespace testing {
|
||||||
|
|
||||||
|
std::unique_ptr<InMemoryProtoStreamReader> ProtoReaderFromStrings(
|
||||||
|
const std::string &header_textpb,
|
||||||
|
const std::initializer_list<std::string> &data_textpbs) {
|
||||||
|
std::queue<std::unique_ptr<::google::protobuf::Message>> proto_queue;
|
||||||
|
proto_queue.emplace(common::make_unique<
|
||||||
|
::cartographer::mapping::proto::SerializationHeader>(
|
||||||
|
ProtoFromStringOrDie<::cartographer::mapping::proto::SerializationHeader>(
|
||||||
|
header_textpb)));
|
||||||
|
for (const std::string &data_textpb : data_textpbs) {
|
||||||
|
proto_queue.emplace(
|
||||||
|
common::make_unique<::cartographer::mapping::proto::SerializedData>(
|
||||||
|
ProtoFromStringOrDie<
|
||||||
|
::cartographer::mapping::proto::SerializedData>(data_textpb)));
|
||||||
|
}
|
||||||
|
return common::make_unique<InMemoryProtoStreamReader>(std::move(proto_queue));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace io
|
||||||
|
} // namespace cartographer
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 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_IO_TESTING_TEST_HELPERS_H_
|
||||||
|
#define CARTOGRAPHER_IO_TESTING_TEST_HELPERS_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "cartographer/io/internal/in_memory_proto_stream.h"
|
||||||
|
#include "glog/logging.h"
|
||||||
|
#include "google/protobuf/text_format.h"
|
||||||
|
|
||||||
|
namespace cartographer {
|
||||||
|
namespace io {
|
||||||
|
namespace testing {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T ProtoFromStringOrDie(const std::string &proto_string) {
|
||||||
|
T msg;
|
||||||
|
CHECK(google::protobuf::TextFormat::ParseFromString(proto_string, &msg));
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<InMemoryProtoStreamReader> ProtoReaderFromStrings(
|
||||||
|
const std::string &header_textpb,
|
||||||
|
const std::initializer_list<std::string> &data_textpbs);
|
||||||
|
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace io
|
||||||
|
} // namespace cartographer
|
||||||
|
|
||||||
|
#endif // CARTOGRAPHER_IO_TESTING_TEST_HELPERS_H_
|
Loading…
Reference in New Issue