Specify minInterval in StartAndCheckFirstLocation

Bug: 186499722
Test: on device
Change-Id: Ie7cdc958333351863d71dccc89b2034c225d060a
This commit is contained in:
Yu-Han Yang 2021-05-03 14:39:45 -07:00
parent f10c36654b
commit 6c1aaa7ed0
10 changed files with 67 additions and 49 deletions

View file

@ -134,13 +134,30 @@ class GnssHalTest : public testing::TestWithParam<std::string> {
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.

View file

@ -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_,

View file

@ -106,7 +106,8 @@ class GnssHalTest : public testing::TestWithParam<std::string> {
*
* 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:

View file

@ -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.");
}

View file

@ -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_,

View file

@ -159,7 +159,8 @@ class GnssHalTest : public testing::TestWithParam<std::string> {
*
* 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:

View file

@ -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.");
}

View file

@ -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.

View file

@ -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();

View file

@ -107,7 +107,7 @@ class GnssHalTestTemplate : public testing::TestWithParam<std::string> {
*
* 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<T_IGnss>::SetPositionMode(const int min_interval_msec,
}
template <class T_IGnss>
bool GnssHalTestTemplate<T_IGnss>::StartAndCheckFirstLocation() {
bool GnssHalTestTemplate<T_IGnss>::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<T_IGnss>::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_,