提交 d707ca95 编写于 作者: S siyangy 提交者: Liangliang Zhang

Switch unit test in simulation mode (#326)

上级 73db043d
......@@ -18,6 +18,8 @@
#include <cmath>
#include "cybertron/blocker/blocker_manager.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
......@@ -32,6 +34,7 @@ using apollo::common::time::Clock;
using apollo::localization::LocalizationEstimate;
using apollo::planning::ADCTrajectory;
using apollo::routing::RoutingResponse;
using apollo::cybertron::blocker::BlockerManager;
namespace apollo {
namespace dreamview {
......@@ -39,8 +42,7 @@ namespace dreamview {
class SimControlTest : public ::testing::Test {
public:
static void SetUpTestCase() {
// init cybertron framework
apollo::cybertron::Init("simulation_world_service_test");
cybertron::GlobalData::Instance()->EnableSimulationMode();
}
virtual void SetUp() {
......@@ -49,19 +51,9 @@ class SimControlTest : public ::testing::Test {
map_service_.reset(new MapService(false));
sim_control_.reset(new SimControl(map_service_.get()));
node_ = cybertron::CreateNode("sim_control_test");
chassis_reader_ = node_->CreateReader<Chassis>(FLAGS_chassis_topic);
localization_reader_ =
node_->CreateReader<LocalizationEstimate>(FLAGS_localization_topic);
}
protected:
std::shared_ptr<cybertron::Node> node_;
std::shared_ptr<cybertron::Reader<Chassis>> chassis_reader_;
std::shared_ptr<cybertron::Reader<LocalizationEstimate>> localization_reader_;
std::unique_ptr<MapService> map_service_;
std::unique_ptr<SimControl> sim_control_;
};
......@@ -124,23 +116,14 @@ TEST_F(SimControlTest, Test) {
Clock::SetNow(timestamp.time_since_epoch());
sim_control_->RunOnce();
node_->Observe();
int32_t count = 100;
while (count-- > 0 && nullptr == chassis_reader_->GetLatestObserved()) {
usleep(10000);
continue;
}
count = 100;
while (count-- > 0 &&
nullptr == localization_reader_->GetLatestObserved()) {
usleep(10000);
continue;
}
const auto chassis = chassis_reader_->GetLatestObserved();
const auto localization = localization_reader_->GetLatestObserved();
ASSERT_TRUE(chassis != nullptr);
ASSERT_TRUE(localization != nullptr);
BlockerManager::Instance()->Observe();
auto localization =
BlockerManager::Instance()
->GetBlocker<LocalizationEstimate>(FLAGS_localization_topic)
->GetLatestObservedPtr();
auto chassis = BlockerManager::Instance()
->GetBlocker<Chassis>(FLAGS_chassis_topic)
->GetLatestObservedPtr();
EXPECT_TRUE(chassis->engine_started());
EXPECT_EQ(Chassis::COMPLETE_AUTO_DRIVE, chassis->driving_mode());
......
......@@ -27,6 +27,8 @@
using apollo::canbus::Chassis;
using apollo::common::TrajectoryPoint;
using apollo::common::monitor::MonitorMessage;
using apollo::common::util::StrCat;
using apollo::cybertron::blocker::BlockerManager;
using apollo::localization::LocalizationEstimate;
using apollo::perception::PerceptionObstacle;
using apollo::perception::PerceptionObstacles;
......@@ -35,8 +37,6 @@ using apollo::planning::DecisionResult;
using apollo::prediction::PredictionObstacle;
using apollo::prediction::PredictionObstacles;
using apollo::common::util::StrCat;
namespace apollo {
namespace dreamview {
......@@ -45,8 +45,7 @@ const float kEpsilon = 0.01;
class SimulationWorldServiceTest : public ::testing::Test {
public:
static void SetUpTestCase() {
// init cybertron framework
apollo::cybertron::Init("simulation_world_service_test");
cybertron::GlobalData::Instance()->EnableSimulationMode();
}
virtual void SetUp() {
......@@ -454,11 +453,7 @@ TEST_F(SimulationWorldServiceTest, UpdateRouting) {
sim_world_service_.reset(
new SimulationWorldService(map_service_.get(), true));
// Wait until the message has been published
while (sim_world_service_->routing_response_reader_->Empty()) {
sleep(1);
sim_world_service_->routing_response_reader_->Observe();
}
BlockerManager::Instance()->Observe();
sim_world_service_->UpdateWithLatestObserved(
sim_world_service_->routing_response_reader_.get());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册