Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp +20 −10 Original line number Original line Diff line number Diff line Loading @@ -124,6 +124,17 @@ class DefaultVhalImplTest : public ::testing::Test { android::ConcurrentQueue<VehiclePropValuePtr> mEventQueue; android::ConcurrentQueue<VehiclePropValuePtr> mEventQueue; android::ConcurrentQueue<VehiclePropValuePtr> mHeartBeatQueue; android::ConcurrentQueue<VehiclePropValuePtr> mHeartBeatQueue; // Wait until receive enough events in receivedEvents. void waitForEvents(std::vector<VehiclePropValuePtr>* receivedEvents, size_t count) { while (receivedEvents->size() < count) { mEventQueue.waitForItems(); auto newEvents = mEventQueue.flush(); for (size_t i = 0; i < newEvents.size(); i++) { receivedEvents->push_back(std::move(newEvents[i])); } } } private: private: void onHalEvent(VehiclePropValuePtr v) { void onHalEvent(VehiclePropValuePtr v) { if (v->prop != toInt(VehicleProperty::VHAL_HEARTBEAT)) { if (v->prop != toInt(VehicleProperty::VHAL_HEARTBEAT)) { Loading Loading @@ -314,26 +325,25 @@ TEST_F(DefaultVhalImplTest, testSubscribe) { ASSERT_EQ(StatusCode::OK, status); ASSERT_EQ(StatusCode::OK, status); std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::vector<VehiclePropValuePtr> receivedEvents; waitForEvents(&receivedEvents, 5); // Modify the speed after 0.5 seconds. // Modify the speed after 5 events arrive. VehiclePropValue value; VehiclePropValue value; value.prop = toInt(VehicleProperty::PERF_VEHICLE_SPEED); value.prop = toInt(VehicleProperty::PERF_VEHICLE_SPEED); value.value.floatValues.resize(1); value.value.floatValues.resize(1); value.value.floatValues[0] = 1.0f; value.value.floatValues[0] = 1.0f; ASSERT_EQ(StatusCode::OK, mHal->set(value)); ASSERT_EQ(StatusCode::OK, mHal->set(value)); std::this_thread::sleep_for(std::chrono::milliseconds(500)); waitForEvents(&receivedEvents, 10); auto events = mEventQueue.flush(); ASSERT_LE((size_t)10, events.size()); // The first event should be the default value. // The first event should be the default value. ASSERT_EQ((size_t)1, events[0]->value.floatValues.size()); ASSERT_EQ((size_t)1, receivedEvents[0]->value.floatValues.size()); EXPECT_EQ(0.0f, events[0]->value.floatValues[0]); EXPECT_EQ(0.0f, receivedEvents[0]->value.floatValues[0]); // The last event should be the value after update. // The last event should be the value after update. ASSERT_EQ((size_t)1, events[events.size() - 1]->value.floatValues.size()); const auto& lastEvent = receivedEvents[receivedEvents.size() - 1]; EXPECT_EQ(1.0f, events[events.size() - 1]->value.floatValues[0]); ASSERT_EQ((size_t)1, lastEvent->value.floatValues.size()); EXPECT_EQ(1.0f, lastEvent->value.floatValues[0]); } } TEST_F(DefaultVhalImplTest, testSubscribeInvalidProp) { TEST_F(DefaultVhalImplTest, testSubscribeInvalidProp) { Loading automotive/vehicle/2.0/default/tests/RecurrentTimer_test.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -69,7 +69,7 @@ TEST(RecurrentTimerTest, multipleIntervals) { std::this_thread::sleep_for(milliseconds(100)); std::this_thread::sleep_for(milliseconds(100)); // This test is unstable, so set the tolerance to 50. // This test is unstable, so set the tolerance to 50. ASSERT_EQ_WITH_TOLERANCE(100, counter1ms.load(), 50); ASSERT_EQ_WITH_TOLERANCE(100, counter1ms.load(), 50); ASSERT_EQ_WITH_TOLERANCE(20, counter5ms.load(), 5); ASSERT_EQ_WITH_TOLERANCE(20, counter5ms.load(), 10); } } } // anonymous namespace } // anonymous namespace Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/tests/DefaultVhalImpl_test.cpp +20 −10 Original line number Original line Diff line number Diff line Loading @@ -124,6 +124,17 @@ class DefaultVhalImplTest : public ::testing::Test { android::ConcurrentQueue<VehiclePropValuePtr> mEventQueue; android::ConcurrentQueue<VehiclePropValuePtr> mEventQueue; android::ConcurrentQueue<VehiclePropValuePtr> mHeartBeatQueue; android::ConcurrentQueue<VehiclePropValuePtr> mHeartBeatQueue; // Wait until receive enough events in receivedEvents. void waitForEvents(std::vector<VehiclePropValuePtr>* receivedEvents, size_t count) { while (receivedEvents->size() < count) { mEventQueue.waitForItems(); auto newEvents = mEventQueue.flush(); for (size_t i = 0; i < newEvents.size(); i++) { receivedEvents->push_back(std::move(newEvents[i])); } } } private: private: void onHalEvent(VehiclePropValuePtr v) { void onHalEvent(VehiclePropValuePtr v) { if (v->prop != toInt(VehicleProperty::VHAL_HEARTBEAT)) { if (v->prop != toInt(VehicleProperty::VHAL_HEARTBEAT)) { Loading Loading @@ -314,26 +325,25 @@ TEST_F(DefaultVhalImplTest, testSubscribe) { ASSERT_EQ(StatusCode::OK, status); ASSERT_EQ(StatusCode::OK, status); std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::vector<VehiclePropValuePtr> receivedEvents; waitForEvents(&receivedEvents, 5); // Modify the speed after 0.5 seconds. // Modify the speed after 5 events arrive. VehiclePropValue value; VehiclePropValue value; value.prop = toInt(VehicleProperty::PERF_VEHICLE_SPEED); value.prop = toInt(VehicleProperty::PERF_VEHICLE_SPEED); value.value.floatValues.resize(1); value.value.floatValues.resize(1); value.value.floatValues[0] = 1.0f; value.value.floatValues[0] = 1.0f; ASSERT_EQ(StatusCode::OK, mHal->set(value)); ASSERT_EQ(StatusCode::OK, mHal->set(value)); std::this_thread::sleep_for(std::chrono::milliseconds(500)); waitForEvents(&receivedEvents, 10); auto events = mEventQueue.flush(); ASSERT_LE((size_t)10, events.size()); // The first event should be the default value. // The first event should be the default value. ASSERT_EQ((size_t)1, events[0]->value.floatValues.size()); ASSERT_EQ((size_t)1, receivedEvents[0]->value.floatValues.size()); EXPECT_EQ(0.0f, events[0]->value.floatValues[0]); EXPECT_EQ(0.0f, receivedEvents[0]->value.floatValues[0]); // The last event should be the value after update. // The last event should be the value after update. ASSERT_EQ((size_t)1, events[events.size() - 1]->value.floatValues.size()); const auto& lastEvent = receivedEvents[receivedEvents.size() - 1]; EXPECT_EQ(1.0f, events[events.size() - 1]->value.floatValues[0]); ASSERT_EQ((size_t)1, lastEvent->value.floatValues.size()); EXPECT_EQ(1.0f, lastEvent->value.floatValues[0]); } } TEST_F(DefaultVhalImplTest, testSubscribeInvalidProp) { TEST_F(DefaultVhalImplTest, testSubscribeInvalidProp) { Loading
automotive/vehicle/2.0/default/tests/RecurrentTimer_test.cpp +1 −1 Original line number Original line Diff line number Diff line Loading @@ -69,7 +69,7 @@ TEST(RecurrentTimerTest, multipleIntervals) { std::this_thread::sleep_for(milliseconds(100)); std::this_thread::sleep_for(milliseconds(100)); // This test is unstable, so set the tolerance to 50. // This test is unstable, so set the tolerance to 50. ASSERT_EQ_WITH_TOLERANCE(100, counter1ms.load(), 50); ASSERT_EQ_WITH_TOLERANCE(100, counter1ms.load(), 50); ASSERT_EQ_WITH_TOLERANCE(20, counter5ms.load(), 5); ASSERT_EQ_WITH_TOLERANCE(20, counter5ms.load(), 10); } } } // anonymous namespace } // anonymous namespace