19#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
20#include "modules/common_msgs/localization_msgs/localization.pb.h"
21#include "modules/common_msgs/perception_msgs/traffic_light_detection.pb.h"
22#include "modules/common_msgs/prediction_msgs/prediction_obstacle.pb.h"
23#include "modules/common_msgs/routing_msgs/routing.pb.h"
42 "true to update decision golden log file.");
43DEFINE_string(test_routing_response_file,
"",
"The routing file used in test");
46DEFINE_string(test_planning_config_file,
"",
"planning config file for test");
47DEFINE_string(test_prediction_file,
"",
"The prediction module test file");
48DEFINE_string(test_traffic_light_file,
"",
"The traffic light test file");
51 "The previous planning test file");
54 FLAGS_use_multi_thread_to_add_obstacles =
false;
55 FLAGS_traffic_rule_config_filename =
56 "/apollo/modules/planning/planning_component/conf/"
57 "traffic_rule_config.pb.txt";
58 FLAGS_smoother_config_filename =
59 "/apollo/modules/planning/planning_component/conf/"
60 "qp_spline_smoother_config.pb.txt";
61 FLAGS_map_dir =
"/apollo/modules/planning/planning_base/testdata";
62 FLAGS_test_localization_file =
"";
63 FLAGS_test_chassis_file =
"";
64 FLAGS_test_routing_response_file =
"";
65 FLAGS_test_planning_config_file =
66 "/apollo/modules/planning/planning_component/conf/planning_config.pb.txt";
67 FLAGS_test_previous_planning_file =
"";
68 FLAGS_test_prediction_file =
"";
69 FLAGS_align_prediction_time =
false;
70 FLAGS_enable_reference_line_provider_thread =
false;
73 FLAGS_enable_trajectory_check =
false;
79 if (FLAGS_test_chassis_file.empty()) {
80 AERROR <<
"Requires FLAGS_test_chassis_file to be set";
84 FLAGS_test_data_dir +
"/" + FLAGS_test_chassis_file, &chassis)) {
85 AERROR <<
"failed to load file: " << FLAGS_test_chassis_file;
89 if (FLAGS_test_localization_file.empty()) {
90 AERROR <<
"Requires FLAGS_test_localization_file to be set";
95 FLAGS_test_data_dir +
"/" + FLAGS_test_localization_file,
97 AERROR <<
"failed to load file: " << FLAGS_test_localization_file;
104 if (FLAGS_test_prediction_file.empty()) {
105 AERROR <<
"Requires FLAGS_test_prediction_file to be set";
110 FLAGS_test_data_dir +
"/" + FLAGS_test_prediction_file,
112 AERROR <<
"failed to load file: " << FLAGS_test_prediction_file;
116 if (FLAGS_test_routing_response_file.empty()) {
117 AERROR <<
"Requires FLAGS_test_routing_response_file";
122 FLAGS_test_data_dir +
"/" + FLAGS_test_routing_response_file,
123 &routing_response)) {
124 AERROR <<
"failed to load file: " << FLAGS_test_routing_response_file;
131 FLAGS_test_data_dir +
"/" + FLAGS_test_traffic_light_file,
132 &traffic_light_detection)) {
133 AERROR <<
"failed to load file: " << FLAGS_test_traffic_light_file;
138 std::make_shared<PredictionObstacles>(prediction);
141 std::make_shared<LocalizationEstimate>(localization);
143 std::make_shared<TrafficLightDetection>(traffic_light_detection);
145 AINFO <<
"Successfully feed proto files.";
150 injector_ = std::make_shared<DependencyInjector>();
152 if (FLAGS_use_navigation_mode) {
163 <<
"failed to load planning config file "
164 << FLAGS_test_planning_config_file;
174 bool no_trajectory_point) {
175 origin->clear_latency_stats();
176 origin->clear_debug();
183 if (no_trajectory_point) {
184 origin->clear_total_path_length();
185 origin->clear_total_path_time();
186 origin->clear_trajectory_point();
191 int case_num,
bool no_trajectory_point) {
192 const std::string golden_result_file =
193 absl::StrCat(
"result_", test_case_name,
"_", case_num,
".pb.txt");
195 std::string full_golden_path = FLAGS_test_data_dir +
"/" + golden_result_file;
201 AERROR <<
"Fail to pass trajectory check.";
207 if (FLAGS_test_update_golden_log) {
208 AINFO <<
"The golden file is regenerated:" << full_golden_path;
217 char tmp_fname[100] =
"/tmp/XXXXXX";
218 int fd = mkstemp(tmp_fname);
220 AERROR <<
"Failed to create temporary file: " << tmp_fname;
224 AERROR <<
"Failed to write to file: " << tmp_fname;
226 AERROR <<
"found error\ndiff -y " << tmp_fname <<
" " << full_golden_path;
227 AERROR <<
"to override error\nmv " << tmp_fname <<
" "
229 AERROR <<
"to visualize\n/usr/bin/python "
230 "modules/tools/plot_trace/plot_planning_result.py "
231 << tmp_fname <<
" " << full_golden_path;
239 for (
int i = 0; i < trajectory.trajectory_point_size(); ++i) {
242 const double kMaxAccelThreshold =
243 FLAGS_longitudinal_acceleration_upper_bound;
244 const double kMinAccelThreshold =
245 FLAGS_longitudinal_acceleration_lower_bound;
246 if (point.a() > kMaxAccelThreshold || point.a() < kMinAccelThreshold) {
247 AERROR <<
"Invalid trajectory point because accel out of range: "
248 << point.DebugString();
252 if (!point.has_path_point()) {
253 AERROR <<
"Invalid trajectory point because NO path_point in "
255 << point.DebugString();
260 const double kPathSEpsilon = 1e-3;
262 if (point.path_point().s() + kPathSEpsilon <
263 last_point.path_point().s()) {
264 AERROR <<
"Invalid trajectory point because s value error. last point: "
265 << last_point.DebugString()
266 <<
", curr point: " << point.DebugString();
a singleton clock that can be used to get the current timestamp.
static void SetNowInSeconds(const double seconds)
This is for mock clock mode only.
static void SetMode(ClockMode mode)
void TrimPlanning(ADCTrajectory *origin, bool no_trajectory_point)
bool RunPlanning(const std::string &test_case_name, int case_num, bool no_trajectory_point)
Execute the planning code.
bool IsValidTrajectory(const ADCTrajectory &trajectory)
ADCTrajectory adc_trajectory_
static void SetUpTestCase()
std::shared_ptr< DependencyInjector > injector_
std::unique_ptr< PlanningBase > planning_
Planning module main class.
bool IsProtoEqual(const ProtoA &a, const ProtoB &b)
bool GetProtoFromASCIIFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as ascii representation of protobufs,...
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
bool SetProtoToASCIIFile(const google::protobuf::Message &message, int file_descriptor)
DEFINE_bool(test_update_golden_log, false, "true to update decision golden log file.")
DEFINE_string(test_data_dir, "", "the test data folder")
optional apollo::common::Header header
repeated apollo::common::TrajectoryPoint trajectory_point
std::shared_ptr< localization::LocalizationEstimate > localization_estimate
std::shared_ptr< prediction::PredictionObstacles > prediction_obstacles
std::shared_ptr< canbus::Chassis > chassis
std::shared_ptr< perception::TrafficLightDetection > traffic_light