diff --git a/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp b/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp index 237e8ec9d8..699ce9af14 100644 --- a/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp +++ b/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp @@ -134,13 +134,30 @@ class GnssHalTest : public testing::TestWithParam { return status; } + /* + * SetPositionMode: + * Helper function to set positioning mode and verify output + */ + void SetPositionMode(const int min_interval_msec) { + const int kPreferredAccuracy = 0; // Ideally perfect (matches GnssLocationProvider) + const int kPreferredTimeMsec = 0; // Ideally immediate + + auto result = gnss_hal_->setPositionMode( + IGnss::GnssPositionMode::MS_BASED, IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, + min_interval_msec, kPreferredAccuracy, kPreferredTimeMsec); + + ASSERT_TRUE(result.isOk()); + EXPECT_TRUE(result); + } + /* * StartAndGetSingleLocation: * Helper function to get one Location and check fields * * returns true if a location was successfully generated */ - bool StartAndGetSingleLocation(bool checkAccuracies) { + bool StartAndGetSingleLocation(const bool checkAccuracies, const int min_interval_msec) { + SetPositionMode(min_interval_msec); auto result = gnss_hal_->start(); EXPECT_TRUE(result.isOk()); @@ -349,37 +366,24 @@ TEST_P(GnssHalTest, SetCallbackCapabilitiesCleanup) {} * and checks them for reasonable validity. */ TEST_P(GnssHalTest, GetLocation) { -#define MIN_INTERVAL_MSEC 500 -#define PREFERRED_ACCURACY 0 // Ideally perfect (matches GnssLocationProvider) -#define PREFERRED_TIME_MSEC 0 // Ideally immediate + const int kMinIntervalMsec = 500; + const int kLocationTimeoutSubsequentSec = 3; + const int kLocationsToCheck = 5; -#define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3 -#define LOCATIONS_TO_CHECK 5 + bool checkMoreAccuracies = (info_called_count_ > 0 && last_info_.yearOfHw >= 2017); - bool checkMoreAccuracies = - (info_called_count_ > 0 && last_info_.yearOfHw >= 2017); + /* + * GPS signals initially optional for this test, so don't expect timeout yet. + */ + bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies, kMinIntervalMsec); - auto result = gnss_hal_->setPositionMode( - IGnss::GnssPositionMode::MS_BASED, - IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, MIN_INTERVAL_MSEC, - PREFERRED_ACCURACY, PREFERRED_TIME_MSEC); - - ASSERT_TRUE(result.isOk()); - EXPECT_TRUE(result); - - /* - * GPS signals initially optional for this test, so don't expect no timeout - * yet - */ - bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies); - - if (gotLocation) { - for (int i = 1; i < LOCATIONS_TO_CHECK; i++) { - EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC)); - EXPECT_EQ(location_called_count_, i + 1); - CheckLocation(last_location_, checkMoreAccuracies, true); + if (gotLocation) { + for (int i = 1; i < kLocationsToCheck; i++) { + EXPECT_EQ(std::cv_status::no_timeout, wait(kLocationTimeoutSubsequentSec)); + EXPECT_EQ(location_called_count_, i + 1); + CheckLocation(last_location_, checkMoreAccuracies, true); + } } - } StopAndClearLocations(); } @@ -410,7 +414,7 @@ TEST_P(GnssHalTest, InjectDelete) { ASSERT_TRUE(resultVoid.isOk()); // Ensure we can get a good location after a bad injection has been deleted - StartAndGetSingleLocation(false); + StartAndGetSingleLocation(false, /* min_interval_sec= */ 1000); StopAndClearLocations(); } @@ -430,7 +434,7 @@ TEST_P(GnssHalTest, InjectSeedLocation) { ASSERT_TRUE(result.isOk()); EXPECT_TRUE(result); - StartAndGetSingleLocation(false); + StartAndGetSingleLocation(false, /* min_interval_msec= */ 1000); // Ensure we don't get a location anywhere within 111km (1 degree of lat or lng) of the seed // location. diff --git a/gnss/1.1/vts/functional/gnss_hal_test.cpp b/gnss/1.1/vts/functional/gnss_hal_test.cpp index 52aaa69753..6663a19abf 100644 --- a/gnss/1.1/vts/functional/gnss_hal_test.cpp +++ b/gnss/1.1/vts/functional/gnss_hal_test.cpp @@ -99,7 +99,9 @@ void GnssHalTest::SetPositionMode(const int min_interval_msec, const bool low_po EXPECT_TRUE(result); } -bool GnssHalTest::StartAndCheckFirstLocation(bool strict) { +bool GnssHalTest::StartAndCheckFirstLocation(const bool strict, const int min_interval_msec, + const bool low_power_mode) { + SetPositionMode(min_interval_msec, low_power_mode); auto result = gnss_hal_->start(); EXPECT_TRUE(result.isOk()); @@ -141,7 +143,9 @@ void GnssHalTest::StartAndCheckLocations(int count) { SetPositionMode(kMinIntervalMsec, kLowPowerMode); - EXPECT_TRUE(StartAndCheckFirstLocation(/* strict= */ true)); + EXPECT_TRUE(StartAndCheckFirstLocation(/* strict= */ true, + /* min_interval_msec= */ 1000, + /* low_power_mode= */ false)); for (int i = 1; i < count; i++) { EXPECT_TRUE(gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_, diff --git a/gnss/1.1/vts/functional/gnss_hal_test.h b/gnss/1.1/vts/functional/gnss_hal_test.h index 75c4216e4a..c6420287c1 100644 --- a/gnss/1.1/vts/functional/gnss_hal_test.h +++ b/gnss/1.1/vts/functional/gnss_hal_test.h @@ -106,7 +106,8 @@ class GnssHalTest : public testing::TestWithParam { * * returns true if a location was successfully generated */ - bool StartAndCheckFirstLocation(bool strict); + bool StartAndCheckFirstLocation(const bool strict, const int min_interval_msec, + const bool low_power_mode); /* * CheckLocation: diff --git a/gnss/1.1/vts/functional/gnss_hal_test_cases.cpp b/gnss/1.1/vts/functional/gnss_hal_test_cases.cpp index e6a51eb731..ef64324aad 100644 --- a/gnss/1.1/vts/functional/gnss_hal_test_cases.cpp +++ b/gnss/1.1/vts/functional/gnss_hal_test_cases.cpp @@ -90,10 +90,8 @@ TEST_P(GnssHalTest, GetLocationLowPower) { gnss_cb_->location_cbq_.reset(); // Start of Low Power Mode test - SetPositionMode(kMinIntervalMsec, kLowPowerMode); - // Don't expect true - as without AGPS access - if (!StartAndCheckFirstLocation(/* strict= */ false)) { + if (!StartAndCheckFirstLocation(/* strict= */ false, kMinIntervalMsec, kLowPowerMode)) { ALOGW("GetLocationLowPower test - no first low power location received."); } diff --git a/gnss/2.0/vts/functional/gnss_hal_test.cpp b/gnss/2.0/vts/functional/gnss_hal_test.cpp index 1cb44c5761..522769313e 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test.cpp +++ b/gnss/2.0/vts/functional/gnss_hal_test.cpp @@ -97,7 +97,9 @@ void GnssHalTest::SetPositionMode(const int min_interval_msec, const bool low_po EXPECT_TRUE(result); } -bool GnssHalTest::StartAndCheckFirstLocation(bool strict) { +bool GnssHalTest::StartAndCheckFirstLocation(const bool strict, const int min_interval_msec, + const bool low_power_mode) { + SetPositionMode(min_interval_msec, low_power_mode); const auto result = gnss_hal_->start(); EXPECT_TRUE(result.isOk()); @@ -137,7 +139,9 @@ void GnssHalTest::StartAndCheckLocations(int count) { SetPositionMode(kMinIntervalMsec, kLowPowerMode); - EXPECT_TRUE(StartAndCheckFirstLocation(/* strict= */ true)); + EXPECT_TRUE(StartAndCheckFirstLocation(/* strict= */ true, + /* min_interval_msec= */ 1000, + /* low_power_mode= */ false)); for (int i = 1; i < count; i++) { EXPECT_TRUE(gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_, diff --git a/gnss/2.0/vts/functional/gnss_hal_test.h b/gnss/2.0/vts/functional/gnss_hal_test.h index 7fbd7350eb..28a19792b6 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test.h +++ b/gnss/2.0/vts/functional/gnss_hal_test.h @@ -159,7 +159,8 @@ class GnssHalTest : public testing::TestWithParam { * * returns true if a location was successfully generated */ - bool StartAndCheckFirstLocation(bool strict); + bool StartAndCheckFirstLocation(const bool strict, const int min_interval_msec, + const bool low_power_mode); /* * CheckLocation: diff --git a/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp b/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp index 3e0058fa05..f17336bc25 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp +++ b/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp @@ -403,7 +403,9 @@ TEST_P(GnssHalTest, TestGnssDataElapsedRealtimeFlags) { } TEST_P(GnssHalTest, TestGnssLocationElapsedRealtime) { - StartAndCheckFirstLocation(/* strict= */ true); + StartAndCheckFirstLocation(/* strict= */ true, + /* min_interval_msec= */ 1000, + /* low_power_mode= */ false); ASSERT_TRUE((int)gnss_cb_->last_location_.elapsedRealtime.flags <= (int)(ElapsedRealtimeFlags::HAS_TIMESTAMP_NS | @@ -419,7 +421,9 @@ TEST_P(GnssHalTest, TestGnssLocationElapsedRealtime) { // This test only verify that injectBestLocation_2_0 does not crash. TEST_P(GnssHalTest, TestInjectBestLocation_2_0) { - StartAndCheckFirstLocation(/* strict= */ true); + StartAndCheckFirstLocation(/* strict= */ true, + /* min_interval_msec= */ 1000, + /* low_power_mode= */ false); gnss_hal_->injectBestLocation_2_0(gnss_cb_->last_location_); StopAndClearLocations(); } @@ -463,7 +467,9 @@ TEST_P(GnssHalTest, GetLocationLowPower) { SetPositionMode(kMinIntervalMsec, kLowPowerMode); // Don't expect true - as without AGPS access - if (!StartAndCheckFirstLocation(/* strict= */ false)) { + if (!StartAndCheckFirstLocation(/* strict= */ false, + /* min_interval_msec= */ 1000, + /* low_power_mode= */ false)) { ALOGW("GetLocationLowPower test - no first low power location received."); } diff --git a/gnss/2.1/vts/functional/gnss_hal_test_cases.cpp b/gnss/2.1/vts/functional/gnss_hal_test_cases.cpp index deb80e8a0b..fcab8c4a04 100644 --- a/gnss/2.1/vts/functional/gnss_hal_test_cases.cpp +++ b/gnss/2.1/vts/functional/gnss_hal_test_cases.cpp @@ -254,7 +254,7 @@ TEST_P(GnssHalTest, TestGnssAntennaInfo) { */ TEST_P(GnssHalTest, TestGnssSvInfoFields) { gnss_cb_->location_cbq_.reset(); - StartAndCheckFirstLocation(); + StartAndCheckFirstLocation(/* min_interval_msec= */ 1000, /* low_power_mode= */ false); int location_called_count = gnss_cb_->location_cbq_.calledCount(); // Tolerate 1 less sv status to handle edge cases in reporting. diff --git a/gnss/aidl/vts/gnss_hal_test_cases.cpp b/gnss/aidl/vts/gnss_hal_test_cases.cpp index 9086b3d966..0fc2ff8a38 100644 --- a/gnss/aidl/vts/gnss_hal_test_cases.cpp +++ b/gnss/aidl/vts/gnss_hal_test_cases.cpp @@ -201,7 +201,7 @@ TEST_P(GnssHalTest, TestGnssPowerIndication) { // Get a location and request another GnssPowerStats gnss_cb_->location_cbq_.reset(); - StartAndCheckFirstLocation(); + StartAndCheckFirstLocation(/* min_interval_msec= */ 1000, /* low_power_mode= */ false); // Request and verify the 2nd GnssPowerStats has larger values than the 1st one iGnssPowerIndication->requestGnssPowerStats(); diff --git a/gnss/common/utils/vts/include/v2_1/gnss_hal_test_template.h b/gnss/common/utils/vts/include/v2_1/gnss_hal_test_template.h index fec3503cd6..03166be8d7 100644 --- a/gnss/common/utils/vts/include/v2_1/gnss_hal_test_template.h +++ b/gnss/common/utils/vts/include/v2_1/gnss_hal_test_template.h @@ -107,7 +107,7 @@ class GnssHalTestTemplate : public testing::TestWithParam { * * returns true if a location was successfully generated */ - bool StartAndCheckFirstLocation(); + bool StartAndCheckFirstLocation(const int min_interval_msec, const bool low_power_mode); /* * CheckLocation: @@ -234,7 +234,9 @@ void GnssHalTestTemplate::SetPositionMode(const int min_interval_msec, } template -bool GnssHalTestTemplate::StartAndCheckFirstLocation() { +bool GnssHalTestTemplate::StartAndCheckFirstLocation(const int min_interval_msec, + const bool low_power_mode) { + SetPositionMode(min_interval_msec, low_power_mode); const auto result = gnss_hal_->start(); EXPECT_TRUE(result.isOk()); @@ -274,9 +276,7 @@ void GnssHalTestTemplate::StartAndCheckLocations(int count) { const int kLocationTimeoutSubsequentSec = 2; const bool kLowPowerMode = false; - SetPositionMode(kMinIntervalMsec, kLowPowerMode); - - EXPECT_TRUE(StartAndCheckFirstLocation()); + EXPECT_TRUE(StartAndCheckFirstLocation(kMinIntervalMsec, kLowPowerMode)); for (int i = 1; i < count; i++) { EXPECT_TRUE(gnss_cb_->location_cbq_.retrieve(gnss_cb_->last_location_,