Branch data Line data Source code
1 : : // ----------------- BEGIN LICENSE BLOCK --------------------------------- 2 : : // 3 : : // Copyright (C) 2018-2021 Intel Corporation 4 : : // 5 : : // SPDX-License-Identifier: LGPL-2.1-only 6 : : // 7 : : // ----------------- END LICENSE BLOCK ----------------------------------- 8 : : 9 : : #include "RssCheckTestBaseT.hpp" 10 : : 11 : : namespace ad { 12 : : namespace rss { 13 : : namespace core { 14 : : 15 : : template <class TESTBASE> class RssCheckIntersectionTestBase : public TESTBASE 16 : : { 17 : : protected: 18 : : using TESTBASE::worldModel; 19 : 154 : world::Object &getEgoObject() override 20 : : { 21 : 154 : return TESTBASE::objectOnSegment0; 22 : : } 23 : : 24 : 154 : world::Object &getConstellationObject(uint32_t) override 25 : : { 26 : 154 : return TESTBASE::objectOnSegment8; 27 : : } 28 : : 29 : : virtual bool isBrakeExpected(uint32_t i) = 0; 30 : : 31 : 4 : void performIntersectionTest() 32 : : { 33 : 4 : state::ProperResponse properResponse; 34 [ + - ]: 4 : core::RssCheck rssCheck; 35 [ + + ]: 12 : for (auto egoVehicleSegmentId : {world::LaneSegmentId(0), world::LaneSegmentId(3)}) 36 : : { 37 [ + + ]: 16 : for (auto &constellation : worldModel.constellations) 38 : : { 39 : 8 : constellation.ego_vehicle.occupied_regions[0].segment_id = egoVehicleSegmentId; 40 : : } 41 [ + + ]: 736 : for (uint32_t i = 0; i <= 90; i++) 42 : : { 43 [ + + ]: 1456 : for (auto &constellation : worldModel.constellations) 44 : : { 45 : 728 : constellation.ego_vehicle.occupied_regions[0].lon_range.minimum = ParametricValue(0.01 * i); 46 : 728 : constellation.ego_vehicle.occupied_regions[0].lon_range.maximum = ParametricValue(0.01 * i + 0.1); 47 : : } 48 : 728 : worldModel.time_index++; 49 : : 50 [ + - - + : 728 : ASSERT_TRUE(rssCheck.calculateProperResponse(worldModel, properResponse)); - - - - - - - - + - ] 51 : : 52 : : #if RSS_CHECK_TEST_DEBUG_OUT 53 : : std::cout << "Testing: segment[" << egoVehicleSegmentId << "] range min=" << i 54 : : << " brake?=" << isBrakeExpected(i) << std::endl; 55 : : #endif 56 [ + - + + ]: 728 : if (isBrakeExpected(i)) 57 : : { 58 [ + - ]: 180 : TESTBASE::testRestrictions(properResponse.acceleration_restrictions, state::LongitudinalResponse::BrakeMin); 59 : : } 60 : : else 61 : : { 62 [ + - ]: 548 : TESTBASE::testRestrictions(properResponse.acceleration_restrictions); 63 : : } 64 : : } 65 : : } 66 [ + - + - ]: 4 : } 67 : : }; 68 : : 69 : : template <class TESTBASE> 70 : : class RssCheckIntersectionEgoHasPriorityTestBase : public RssCheckIntersectionTestBase<TESTBASE> 71 : : { 72 : : protected: 73 : 104 : world::ConstellationType getConstellationType() override 74 : : { 75 : 104 : return world::ConstellationType::IntersectionEgoHasPriority; 76 : : } 77 : : 78 : 364 : bool isBrakeExpected(uint32_t i) override 79 : : { 80 : 364 : bool const egoVehicleFaraway = (i < 11) 81 [ + + + + ]: 364 : || (TESTBASE::worldModel.constellations[0].ego_vehicle.occupied_regions[0].segment_id == world::LaneSegmentId(0)); 82 : 364 : bool const egoVehicleInFront = (i > 64) 83 [ + + + + ]: 364 : && (TESTBASE::worldModel.constellations[0].ego_vehicle.occupied_regions[0].segment_id == world::LaneSegmentId(3)); 84 : : 85 [ + + + + ]: 364 : return !egoVehicleFaraway && !egoVehicleInFront; 86 : : } 87 : : }; 88 : : 89 : : using RssCheckIntersectionEgoHasPriorityTest = RssCheckIntersectionEgoHasPriorityTestBase<RssCheckTestBase>; 90 : : 91 : : using RssCheckIntersectionEgoHasPriorityOutOfMemoryTest 92 : : = RssCheckIntersectionEgoHasPriorityTestBase<RssCheckOutOfMemoryTestBase>; 93 [ + - + - : 101 : TEST_P(RssCheckIntersectionEgoHasPriorityOutOfMemoryTest, outOfMemoryAnyTime) + - + - + - + - + - ] 94 : : { 95 [ + - ]: 50 : performOutOfMemoryTest(); 96 : 50 : } 97 [ - + - - : 51 : INSTANTIATE_TEST_CASE_P(Range, - - ] 98 : : RssCheckIntersectionEgoHasPriorityOutOfMemoryTest, 99 : : ::testing::Range(uint64_t(0u), uint64_t(50u), 1u)); 100 : : 101 : 4 : TEST_F(RssCheckIntersectionEgoHasPriorityTest, IntersectionTest) 102 : : { 103 : 1 : performIntersectionTest(); 104 : 1 : } 105 : : 106 : 4 : TEST_F(RssCheckIntersectionEgoHasPriorityTest, IntersectionDescriptionIsExtended) 107 : : { 108 : 1 : worldModel.constellations[0].ego_vehicle_road.push_back(worldModel.constellations[0].ego_vehicle_road.front()); 109 : 1 : performIntersectionTest(); 110 : 1 : } 111 : : 112 : : template <class TESTBASE> 113 : : class RssCheckIntersectionObjectHasPriorityTestBase : public RssCheckIntersectionTestBase<TESTBASE> 114 : : { 115 : : protected: 116 : 153 : world::ConstellationType getConstellationType() override 117 : : { 118 : 153 : return world::ConstellationType::IntersectionObjectHasPriority; 119 : : } 120 : : 121 : 182 : bool isBrakeExpected(uint32_t i) override 122 : : { 123 : 182 : bool const egoVehicleNearEnough 124 : 182 : = (TESTBASE::worldModel.constellations[0].ego_vehicle.occupied_regions[0].segment_id == world::LaneSegmentId(3)) 125 [ + + + + ]: 182 : && (i > 54); 126 : : 127 : 182 : return egoVehicleNearEnough; 128 : : } 129 : : }; 130 : : 131 : : using RssCheckIntersectionObjectHasPriorityTest = RssCheckIntersectionObjectHasPriorityTestBase<RssCheckTestBase>; 132 : : 133 : : using RssCheckIntersectionObjectHasPriorityOutOfMemoryTest 134 : : = RssCheckIntersectionObjectHasPriorityTestBase<RssCheckOutOfMemoryTestBase>; 135 [ + - + - : 101 : TEST_P(RssCheckIntersectionObjectHasPriorityOutOfMemoryTest, outOfMemoryAnyTime) + - + - + - + - + - ] 136 : : { 137 [ + - ]: 50 : performOutOfMemoryTest(); 138 : 50 : } 139 [ - + - - : 51 : INSTANTIATE_TEST_CASE_P(Range, - - ] 140 : : RssCheckIntersectionObjectHasPriorityOutOfMemoryTest, 141 : : ::testing::Range(uint64_t(0u), uint64_t(50u), 1u)); 142 : : 143 : 4 : TEST_F(RssCheckIntersectionObjectHasPriorityTest, IntersectionTest) 144 : : { 145 : 1 : performIntersectionTest(); 146 : 1 : } 147 : : 148 : : template <class TESTBASE> class RssCheckIntersectionSamePriorityTestBase : public RssCheckIntersectionTestBase<TESTBASE> 149 : : { 150 : : protected: 151 : 204 : world::ConstellationType getConstellationType() override 152 : : { 153 : 204 : return world::ConstellationType::IntersectionSamePriority; 154 : : } 155 : : 156 : 182 : bool isBrakeExpected(uint32_t i) override 157 : : { 158 : 182 : return (TESTBASE::worldModel.constellations[0].ego_vehicle.occupied_regions[0].segment_id 159 : : == world::LaneSegmentId(3)) 160 [ + + + + ]: 182 : && (i > 54); 161 : : } 162 : : }; 163 : : 164 : : using RssCheckIntersectionSamePriorityTest = RssCheckIntersectionSamePriorityTestBase<RssCheckTestBase>; 165 : : 166 : : using RssCheckIntersectionSamePriorityOutOfMemoryTest 167 : : = RssCheckIntersectionSamePriorityTestBase<RssCheckOutOfMemoryTestBase>; 168 [ + - + - : 101 : TEST_P(RssCheckIntersectionSamePriorityOutOfMemoryTest, outOfMemoryAnyTime) + - + - + - + - + - ] 169 : : { 170 [ + - ]: 50 : performOutOfMemoryTest(); 171 : 50 : } 172 [ - + - - : 51 : INSTANTIATE_TEST_CASE_P(Range, - - ] 173 : : RssCheckIntersectionSamePriorityOutOfMemoryTest, 174 : : ::testing::Range(uint64_t(0u), uint64_t(50u), 1u)); 175 : : 176 : 4 : TEST_F(RssCheckIntersectionSamePriorityTest, IntersectionTest) 177 : : { 178 : 1 : performIntersectionTest(); 179 : 1 : } 180 : : 181 : : } // namespace core 182 : : } // namespace rss 183 : : } // namespace ad