Apollo  6.0
Open source self driving car software
planning_test_base.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #include <map>
18 #include <memory>
19 #include <string>
20 
21 #include "gtest/gtest.h"
22 
23 #include "modules/planning/proto/traffic_rule_config.pb.h"
24 
25 // TODO(all) #include "modules/planning/navi_planning.h"
28 
29 namespace apollo {
30 namespace planning {
31 
32 #define RUN_GOLDEN_TEST(sub_case_num) \
33  { \
34  const ::testing::TestInfo* const test_info = \
35  ::testing::UnitTest::GetInstance()->current_test_info(); \
36  bool no_trajectory_point = false; \
37  bool run_planning_success = \
38  RunPlanning(test_info->name(), sub_case_num, no_trajectory_point); \
39  EXPECT_TRUE(run_planning_success); \
40  }
41 
42 #define RUN_GOLDEN_TEST_DECISION(sub_case_num) \
43  { \
44  const ::testing::TestInfo* const test_info = \
45  ::testing::UnitTest::GetInstance()->current_test_info(); \
46  bool no_trajectory_point = true; \
47  bool run_planning_success = \
48  RunPlanning(test_info->name(), sub_case_num, no_trajectory_point); \
49  EXPECT_TRUE(run_planning_success); \
50  }
51 
52 #define TMAIN \
53  int main(int argc, char** argv) { \
54  ::apollo::cyber::Init("planning_test"); \
55  ::testing::InitGoogleTest(&argc, argv); \
56  ::google::ParseCommandLineFlags(&argc, &argv, true); \
57  return RUN_ALL_TESTS(); \
58  }
59 
60 #define ENABLE_RULE(RULE_ID, ENABLED) this->rule_enabled_[RULE_ID] = ENABLED
61 
62 DECLARE_string(test_routing_response_file);
63 DECLARE_string(test_localization_file);
64 DECLARE_string(test_chassis_file);
65 DECLARE_string(test_data_dir);
66 DECLARE_string(test_prediction_file);
67 DECLARE_string(test_traffic_light_file);
68 DECLARE_string(test_relative_map_file);
69 DECLARE_string(test_previous_planning_file);
70 
71 class PlanningTestBase : public ::testing::Test {
72  public:
73  virtual ~PlanningTestBase() = default;
74 
75  static void SetUpTestCase();
76  virtual void SetUp();
77  void UpdateData();
78 
84  bool RunPlanning(const std::string& test_case_name, int case_num,
85  bool no_trajectory_point);
86 
87  TrafficRuleConfig* GetTrafficRuleConfig(
88  const TrafficRuleConfig::RuleId& rule_id);
89 
90  protected:
91  void TrimPlanning(ADCTrajectory* origin, bool no_trajectory_point);
92  bool FeedTestData();
93  bool IsValidTrajectory(const ADCTrajectory& trajectory);
94 
95  protected:
96  std::unique_ptr<PlanningBase> planning_ = nullptr;
97  std::map<TrafficRuleConfig::RuleId, bool> rule_enabled_;
98  ADCTrajectory adc_trajectory_;
100  PlanningConfig config_;
101  std::shared_ptr<DependencyInjector> injector_;
102 };
103 
104 } // namespace planning
105 } // namespace apollo
Definition: planning_test_base.h:71
void TrimPlanning(ADCTrajectory *origin, bool no_trajectory_point)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::shared_ptr< DependencyInjector > injector_
Definition: planning_test_base.h:101
Planning module main class. It processes GPS and IMU as input, to generate planning info...
PlanningConfig config_
Definition: planning_test_base.h:100
bool IsValidTrajectory(const ADCTrajectory &trajectory)
DECLARE_string(test_routing_response_file)
std::map< TrafficRuleConfig::RuleId, bool > rule_enabled_
Definition: planning_test_base.h:97
ADCTrajectory adc_trajectory_
Definition: planning_test_base.h:98
bool RunPlanning(const std::string &test_case_name, int case_num, bool no_trajectory_point)
Definition: local_view.h:38
LocalView local_view_
Definition: planning_test_base.h:99
TrafficRuleConfig * GetTrafficRuleConfig(const TrafficRuleConfig::RuleId &rule_id)
std::unique_ptr< PlanningBase > planning_
Definition: planning_test_base.h:96