提交 a946e824 编写于 作者: D Dong Li 提交者: lianglia-apollo

planning: added end to end comparision in integration tests.

上级 53b1e0f1
...@@ -116,7 +116,10 @@ bool ControlTestBase::test_control() { ...@@ -116,7 +116,10 @@ bool ControlTestBase::test_control() {
} }
void ControlTestBase::trim_control_command(ControlCommand *origin) { void ControlTestBase::trim_control_command(ControlCommand *origin) {
origin->mutable_header()->clear_radar_timestamp();
origin->mutable_header()->clear_lidar_timestamp();
origin->mutable_header()->clear_timestamp_sec(); origin->mutable_header()->clear_timestamp_sec();
origin->mutable_header()->clear_camera_timestamp();
} }
bool ControlTestBase::test_control(const std::string &test_case_name, bool ControlTestBase::test_control(const std::string &test_case_name,
......
...@@ -37,7 +37,6 @@ class SimpleControlTest : public ControlTestBase { ...@@ -37,7 +37,6 @@ class SimpleControlTest : public ControlTestBase {
public: public:
virtual void SetUp() { virtual void SetUp() {
FLAGS_test_data_dir = "modules/control/testdata/simple_control_test/"; FLAGS_test_data_dir = "modules/control/testdata/simple_control_test/";
ControlTestBase::SetUp();
} }
}; };
...@@ -47,6 +46,7 @@ TEST_F(SimpleControlTest, simple_test) { ...@@ -47,6 +46,7 @@ TEST_F(SimpleControlTest, simple_test) {
FLAGS_test_pad_file = "1_pad.pb.txt"; FLAGS_test_pad_file = "1_pad.pb.txt";
FLAGS_test_planning_file = "1_planning.pb.txt"; FLAGS_test_planning_file = "1_planning.pb.txt";
FLAGS_test_chassis_file = "1_chassis.pb.txt"; FLAGS_test_chassis_file = "1_chassis.pb.txt";
ControlTestBase::SetUp();
RUN_GOLDEN_TEST; RUN_GOLDEN_TEST;
} }
...@@ -55,6 +55,7 @@ TEST_F(SimpleControlTest, state_exact_match) { ...@@ -55,6 +55,7 @@ TEST_F(SimpleControlTest, state_exact_match) {
FLAGS_test_pad_file = "1_pad.pb.txt"; FLAGS_test_pad_file = "1_pad.pb.txt";
FLAGS_test_planning_file = "1_planning.pb.txt"; FLAGS_test_planning_file = "1_planning.pb.txt";
FLAGS_test_chassis_file = "1_chassis.pb.txt"; FLAGS_test_chassis_file = "1_chassis.pb.txt";
ControlTestBase::SetUp();
RUN_GOLDEN_TEST; RUN_GOLDEN_TEST;
} }
...@@ -63,6 +64,7 @@ TEST_F(SimpleControlTest, pad_reset) { ...@@ -63,6 +64,7 @@ TEST_F(SimpleControlTest, pad_reset) {
FLAGS_test_pad_file = "2_pad.pb.txt"; FLAGS_test_pad_file = "2_pad.pb.txt";
FLAGS_test_planning_file = "1_planning.pb.txt"; FLAGS_test_planning_file = "1_planning.pb.txt";
FLAGS_test_chassis_file = "1_chassis.pb.txt"; FLAGS_test_chassis_file = "1_chassis.pb.txt";
ControlTestBase::SetUp();
RUN_GOLDEN_TEST; RUN_GOLDEN_TEST;
} }
...@@ -72,6 +74,7 @@ TEST_F(SimpleControlTest, monitor_fatal) { ...@@ -72,6 +74,7 @@ TEST_F(SimpleControlTest, monitor_fatal) {
FLAGS_test_planning_file = "1_planning.pb.txt"; FLAGS_test_planning_file = "1_planning.pb.txt";
FLAGS_test_chassis_file = "1_chassis.pb.txt"; FLAGS_test_chassis_file = "1_chassis.pb.txt";
FLAGS_test_monitor_file = "1_monitor.pb.txt"; FLAGS_test_monitor_file = "1_monitor.pb.txt";
ControlTestBase::SetUp();
RUN_GOLDEN_TEST; RUN_GOLDEN_TEST;
} }
......
...@@ -41,6 +41,7 @@ class GarageTest : public PlanningTestBase { ...@@ -41,6 +41,7 @@ class GarageTest : public PlanningTestBase {
public: public:
virtual void SetUp() { virtual void SetUp() {
FLAGS_map_file_path = "modules/planning/testdata/base_map.txt"; FLAGS_map_file_path = "modules/planning/testdata/base_map.txt";
FLAGS_test_data_dir = "modules/planning/testdata/garage_test/";
} }
}; };
...@@ -54,10 +55,8 @@ TEST_F(GarageTest, Stop) { ...@@ -54,10 +55,8 @@ TEST_F(GarageTest, Stop) {
FLAGS_test_chassis_file = FLAGS_test_chassis_file =
"modules/planning/testdata/garage_test/" "modules/planning/testdata/garage_test/"
"stop_obstacle_chassis.pb.txt"; "stop_obstacle_chassis.pb.txt";
// EXPECT_DEATH(PlanningTestBase::SetUp(), ".*SetUpAdapters.*");
PlanningTestBase::SetUp(); PlanningTestBase::SetUp();
RunPlanning(); RUN_GOLDEN_TEST;
ASSERT_TRUE(adc_trajectory_ != nullptr);
} }
} // namespace planning } // namespace planning
......
...@@ -24,6 +24,9 @@ namespace planning { ...@@ -24,6 +24,9 @@ namespace planning {
using common::adapter::AdapterManager; using common::adapter::AdapterManager;
DEFINE_string(test_data_dir, "", "the test data folder");
DEFINE_bool(test_update_golden_log, false,
"true to update decision golden log file.");
DEFINE_string(test_routing_response_file, DEFINE_string(test_routing_response_file,
"modules/planning/testdata/garage_routing.pb.txt", "modules/planning/testdata/garage_routing.pb.txt",
"The routing file used in test"); "The routing file used in test");
...@@ -45,7 +48,8 @@ void PlanningTestBase::SetUpTestCase() { ...@@ -45,7 +48,8 @@ void PlanningTestBase::SetUpTestCase() {
FLAGS_test_localization_file = FLAGS_test_localization_file =
"modules/planning/testdata/garage_localization.pb.txt"; "modules/planning/testdata/garage_localization.pb.txt";
FLAGS_test_chassis_file = "modules/planning/testdata/garage_chassis.pb.txt", FLAGS_test_chassis_file = "modules/planning/testdata/garage_chassis.pb.txt",
FLAGS_test_prediction_file = "modules/planning/testdata/garage_prediction.pb.txt", FLAGS_test_prediction_file =
"modules/planning/testdata/garage_prediction.pb.txt",
FLAGS_v = 4; FLAGS_v = 4;
} }
...@@ -91,9 +95,55 @@ void PlanningTestBase::SetUp() { ...@@ -91,9 +95,55 @@ void PlanningTestBase::SetUp() {
planning_.Init(); planning_.Init();
} }
void PlanningTestBase::RunPlanning() { void PlanningTestBase::TrimPlanning(ADCTrajectory* origin) {
origin->mutable_latency_stats()->Clear();
origin->mutable_header()->clear_radar_timestamp();
origin->mutable_header()->clear_lidar_timestamp();
origin->mutable_header()->clear_timestamp_sec();
origin->mutable_header()->clear_camera_timestamp();
}
bool PlanningTestBase::RunPlanning(const std::string& test_case_name,
int case_num) {
const std::string golden_result_file = apollo::common::util::StrCat(
"result_", test_case_name, "_", case_num, ".pb.txt");
std::string tmp_golden_path = "/tmp/" + golden_result_file;
std::string full_golden_path = FLAGS_test_data_dir + "/" + golden_result_file;
planning_.RunOnce(); planning_.RunOnce();
adc_trajectory_ = AdapterManager::GetPlanning()->GetLatestPublished(); adc_trajectory_ = AdapterManager::GetPlanning()->GetLatestPublished();
if (!adc_trajectory_) {
AERROR << " did not get latest adc trajectory";
return false;
}
TrimPlanning(adc_trajectory_);
if (FLAGS_test_update_golden_log) {
AINFO << "The golden file is " << tmp_golden_path << " Remember to:\n"
<< "mv " << tmp_golden_path << " " << FLAGS_test_data_dir << "\n"
<< "git add " << FLAGS_test_data_dir << "/" << golden_result_file;
::apollo::common::util::SetProtoToASCIIFile(*adc_trajectory_,
golden_result_file);
} else {
ADCTrajectory golden_result;
bool load_success = ::apollo::common::util::GetProtoFromASCIIFile(
full_golden_path, &golden_result);
if (!load_success) {
AERROR << "Failed to load golden file: " << full_golden_path;
::apollo::common::util::SetProtoToASCIIFile(*adc_trajectory_,
tmp_golden_path);
AINFO << "Current result is written to " << tmp_golden_path;
return false;
}
bool same_result =
::apollo::common::util::IsProtoEqual(golden_result, *adc_trajectory_);
if (!same_result) {
std::string tmp_planning_file = tmp_golden_path + ".tmp";
::apollo::common::util::SetProtoToASCIIFile(*adc_trajectory_,
tmp_planning_file);
AERROR << "found diff " << tmp_planning_file << " " << full_golden_path;
return false;
}
}
return true;
} }
void PlanningTestBase::export_sl_points( void PlanningTestBase::export_sl_points(
......
...@@ -35,9 +35,18 @@ namespace planning { ...@@ -35,9 +35,18 @@ namespace planning {
using common::adapter::AdapterManager; using common::adapter::AdapterManager;
#define RUN_GOLDEN_TEST \
{ \
const ::testing::TestInfo* const test_info = \
::testing::UnitTest::GetInstance()->current_test_info(); \
bool run_planning_success = RunPlanning(test_info->name(), 0); \
EXPECT_TRUE(run_planning_success); \
}
DECLARE_string(test_routing_response_file); DECLARE_string(test_routing_response_file);
DECLARE_string(test_localization_file); DECLARE_string(test_localization_file);
DECLARE_string(test_chassis_file); DECLARE_string(test_chassis_file);
DECLARE_string(test_data_dir);
DECLARE_string(test_prediction_file); DECLARE_string(test_prediction_file);
class PlanningTestBase : public ::testing::Test { class PlanningTestBase : public ::testing::Test {
...@@ -51,7 +60,7 @@ class PlanningTestBase : public ::testing::Test { ...@@ -51,7 +60,7 @@ class PlanningTestBase : public ::testing::Test {
* @return true if planning is success. The ADCTrajectory will be used to * @return true if planning is success. The ADCTrajectory will be used to
* store the planing results. Otherwise false. * store the planing results. Otherwise false.
*/ */
void RunPlanning(); bool RunPlanning(const std::string& test_case_name, int case_num);
/** /**
* @brief Print out the points to a file for debug and visualization purpose. * @brief Print out the points to a file for debug and visualization purpose.
...@@ -66,7 +75,9 @@ class PlanningTestBase : public ::testing::Test { ...@@ -66,7 +75,9 @@ class PlanningTestBase : public ::testing::Test {
const std::string& filename); const std::string& filename);
protected: protected:
void TrimPlanning(ADCTrajectory* origin);
bool SetUpAdapters(); bool SetUpAdapters();
Planning planning_; Planning planning_;
ADCTrajectory* adc_trajectory_ = nullptr; ADCTrajectory* adc_trajectory_ = nullptr;
}; };
......
...@@ -66,14 +66,7 @@ class DpRoadGraphTest : public PlanningTestBase { ...@@ -66,14 +66,7 @@ class DpRoadGraphTest : public PlanningTestBase {
} }
virtual void SetUp() { virtual void SetUp() {
google::InitGoogleLogging("DpRoadGraphTest"); FLAGS_test_data_dir = "modules/planning/testdata/dp_road_graph_test";
PlanningTestBase::SetUp();
RunPlanning();
SetInitPoint();
SetSpeedDataWithConstVeolocity(10.0);
const auto* frame = planning_.GetFrame();
ASSERT_TRUE(frame != nullptr);
reference_line_ = &(frame->reference_line());
} }
protected: protected:
...@@ -84,6 +77,16 @@ class DpRoadGraphTest : public PlanningTestBase { ...@@ -84,6 +77,16 @@ class DpRoadGraphTest : public PlanningTestBase {
}; };
TEST_F(DpRoadGraphTest, speed_road_graph) { TEST_F(DpRoadGraphTest, speed_road_graph) {
PlanningTestBase::SetUp();
RUN_GOLDEN_TEST;
// specialized tests
SetInitPoint();
SetSpeedDataWithConstVeolocity(10.0);
const auto* frame = planning_.GetFrame();
ASSERT_TRUE(frame != nullptr);
reference_line_ = &(frame->reference_line());
DpPolyPathConfig dp_poly_path_config; // default values DpPolyPathConfig dp_poly_path_config; // default values
DPRoadGraph road_graph(dp_poly_path_config, *reference_line_, speed_data_); DPRoadGraph road_graph(dp_poly_path_config, *reference_line_, speed_data_);
ASSERT_TRUE(reference_line_ != nullptr); ASSERT_TRUE(reference_line_ != nullptr);
......
...@@ -58,12 +58,7 @@ class DpStSpeedTest : public PlanningTestBase { ...@@ -58,12 +58,7 @@ class DpStSpeedTest : public PlanningTestBase {
} }
virtual void SetUp() { virtual void SetUp() {
google::InitGoogleLogging("DpStSpeedTest"); FLAGS_test_data_dir = "modules/planning/testdata/dp_st_speed_test";
PlanningTestBase::SetUp();
RunPlanning();
const auto* frame = planning_.GetFrame();
reference_line_ = &(frame->reference_line());
SetPathDataWithStraightLine();
} }
protected: protected:
...@@ -74,6 +69,9 @@ class DpStSpeedTest : public PlanningTestBase { ...@@ -74,6 +69,9 @@ class DpStSpeedTest : public PlanningTestBase {
}; };
TEST_F(DpStSpeedTest, dp_st_graph_test) { TEST_F(DpStSpeedTest, dp_st_graph_test) {
PlanningTestBase::SetUp();
RUN_GOLDEN_TEST;
DpStSpeedConfig dp_st_speed_config; DpStSpeedConfig dp_st_speed_config;
const auto& veh_param = const auto& veh_param =
common::VehicleConfigHelper::GetConfig().vehicle_param(); common::VehicleConfigHelper::GetConfig().vehicle_param();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册