Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 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 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 17 | #define LOG_TAG "GnssHalTest" |
| 18 | |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 19 | #include "gnss_hal_test.h" |
| 20 | #include <hidl/ServiceManagement.h> |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 21 | #include <algorithm> |
| 22 | #include <cmath> |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 23 | #include "Utils.h" |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 24 | |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 25 | using android::hardware::gnss::GnssClock; |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 26 | using android::hardware::gnss::GnssConstellationType; |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 27 | using android::hardware::gnss::GnssData; |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 28 | using android::hardware::gnss::GnssLocation; |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 29 | using android::hardware::gnss::GnssMeasurement; |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 30 | using android::hardware::gnss::IGnss; |
| 31 | using android::hardware::gnss::IGnssCallback; |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 32 | using android::hardware::gnss::IGnssMeasurementInterface; |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 33 | using android::hardware::gnss::common::Utils; |
| 34 | using GnssConstellationTypeV2_0 = android::hardware::gnss::V2_0::GnssConstellationType; |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 35 | |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 36 | namespace { |
| 37 | // The difference between the mean of the received intervals and the requested interval should not |
| 38 | // be larger mInterval * ALLOWED_MEAN_ERROR_RATIO |
| 39 | constexpr double ALLOWED_MEAN_ERROR_RATIO = 0.25; |
| 40 | |
| 41 | // The standard deviation computed for the deltas should not be bigger |
| 42 | // than mInterval * ALLOWED_STDEV_ERROR_RATIO or MIN_STDEV_MS, whichever is higher. |
| 43 | constexpr double ALLOWED_STDEV_ERROR_RATIO = 0.50; |
| 44 | constexpr double MIN_STDEV_MS = 1000; |
| 45 | |
| 46 | double computeMean(std::vector<int>& deltas) { |
| 47 | long accumulator = 0; |
| 48 | for (auto& d : deltas) { |
| 49 | accumulator += d; |
| 50 | } |
| 51 | return accumulator / deltas.size(); |
| 52 | } |
| 53 | |
| 54 | double computeStdev(double mean, std::vector<int>& deltas) { |
| 55 | double accumulator = 0; |
| 56 | for (auto& d : deltas) { |
| 57 | double diff = d - mean; |
| 58 | accumulator += diff * diff; |
| 59 | } |
| 60 | return std::sqrt(accumulator / (deltas.size() - 1)); |
| 61 | } |
| 62 | |
| 63 | } // anonymous namespace |
| 64 | |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 65 | void GnssHalTest::SetUp() { |
| 66 | // Get AIDL handle |
| 67 | aidl_gnss_hal_ = android::waitForDeclaredService<IGnssAidl>(String16(GetParam().c_str())); |
| 68 | ASSERT_NE(aidl_gnss_hal_, nullptr); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 69 | ALOGD("AIDL Interface Version = %d", aidl_gnss_hal_->getInterfaceVersion()); |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 70 | |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 71 | if (aidl_gnss_hal_->getInterfaceVersion() <= 1) { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 72 | const auto& hidlInstanceNames = android::hardware::getAllHalInstanceNames( |
| 73 | android::hardware::gnss::V2_1::IGnss::descriptor); |
| 74 | gnss_hal_ = IGnss_V2_1::getService(hidlInstanceNames[0]); |
| 75 | ASSERT_NE(gnss_hal_, nullptr); |
| 76 | } |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 77 | |
| 78 | SetUpGnssCallback(); |
| 79 | } |
| 80 | |
| 81 | void GnssHalTest::SetUpGnssCallback() { |
| 82 | aidl_gnss_cb_ = new GnssCallbackAidl(); |
| 83 | ASSERT_NE(aidl_gnss_cb_, nullptr); |
| 84 | |
| 85 | auto status = aidl_gnss_hal_->setCallback(aidl_gnss_cb_); |
| 86 | if (!status.isOk()) { |
| 87 | ALOGE("Failed to setCallback"); |
| 88 | } |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 89 | ASSERT_TRUE(status.isOk()); |
| 90 | |
| 91 | /* |
| 92 | * Capabilities callback should trigger. |
| 93 | */ |
| 94 | EXPECT_TRUE(aidl_gnss_cb_->capabilities_cbq_.retrieve(aidl_gnss_cb_->last_capabilities_, |
| 95 | TIMEOUT_SEC)); |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 96 | EXPECT_EQ(aidl_gnss_cb_->capabilities_cbq_.calledCount(), 1); |
| 97 | |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 98 | if (aidl_gnss_hal_->getInterfaceVersion() <= 1) { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 99 | // Invoke the super method. |
| 100 | GnssHalTestTemplate<IGnss_V2_1>::SetUpGnssCallback(); |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 101 | } else { |
| 102 | /* |
| 103 | * SystemInfo callback should trigger |
| 104 | */ |
| 105 | EXPECT_TRUE(aidl_gnss_cb_->info_cbq_.retrieve(aidl_gnss_cb_->last_info_, TIMEOUT_SEC)); |
| 106 | EXPECT_EQ(aidl_gnss_cb_->info_cbq_.calledCount(), 1); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
| 110 | void GnssHalTest::CheckLocation(const GnssLocation& location, bool check_speed) { |
| 111 | Utils::checkLocation(location, check_speed, /* check_more_accuracies= */ true); |
| 112 | } |
| 113 | |
| 114 | void GnssHalTest::SetPositionMode(const int min_interval_msec, const bool low_power_mode) { |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 115 | if (aidl_gnss_hal_->getInterfaceVersion() <= 1) { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 116 | // Invoke the super method. |
| 117 | return GnssHalTestTemplate<IGnss_V2_1>::SetPositionMode(min_interval_msec, low_power_mode); |
| 118 | } |
| 119 | |
| 120 | const int kPreferredAccuracy = 0; // Ideally perfect (matches GnssLocationProvider) |
| 121 | const int kPreferredTimeMsec = 0; // Ideally immediate |
| 122 | |
Yu-Han Yang | 75934f7 | 2022-01-24 15:35:25 -0800 | [diff] [blame] | 123 | IGnss::PositionModeOptions options; |
| 124 | options.mode = IGnss::GnssPositionMode::MS_BASED; |
| 125 | options.recurrence = IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC; |
| 126 | options.minIntervalMs = min_interval_msec; |
| 127 | options.preferredAccuracyMeters = kPreferredAccuracy; |
| 128 | options.preferredTimeMs = kPreferredTimeMsec; |
| 129 | options.lowPowerMode = low_power_mode; |
| 130 | auto status = aidl_gnss_hal_->setPositionMode(options); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 131 | |
| 132 | ASSERT_TRUE(status.isOk()); |
| 133 | } |
| 134 | |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 135 | bool GnssHalTest::StartAndCheckFirstLocation(const int min_interval_msec, const bool low_power_mode, |
| 136 | const bool start_sv_status, const bool start_nmea) { |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 137 | if (aidl_gnss_hal_->getInterfaceVersion() <= 1) { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 138 | // Invoke the super method. |
| 139 | return GnssHalTestTemplate<IGnss_V2_1>::StartAndCheckFirstLocation(min_interval_msec, |
| 140 | low_power_mode); |
| 141 | } |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 142 | SetPositionMode(min_interval_msec, low_power_mode); |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 143 | |
Yu-Han Yang | 69f0f8b | 2022-01-21 13:03:32 -0800 | [diff] [blame] | 144 | auto status = aidl_gnss_hal_->start(); |
| 145 | EXPECT_TRUE(status.isOk()); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 146 | |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 147 | if (start_sv_status) { |
| 148 | status = aidl_gnss_hal_->startSvStatus(); |
| 149 | EXPECT_TRUE(status.isOk()); |
| 150 | } |
| 151 | if (start_nmea) { |
| 152 | status = aidl_gnss_hal_->startNmea(); |
| 153 | EXPECT_TRUE(status.isOk()); |
| 154 | } |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * GnssLocationProvider support of AGPS SUPL & XtraDownloader is not available in VTS, |
| 158 | * so allow time to demodulate ephemeris over the air. |
| 159 | */ |
| 160 | const int kFirstGnssLocationTimeoutSeconds = 75; |
| 161 | |
| 162 | EXPECT_TRUE(aidl_gnss_cb_->location_cbq_.retrieve(aidl_gnss_cb_->last_location_, |
| 163 | kFirstGnssLocationTimeoutSeconds)); |
| 164 | int locationCalledCount = aidl_gnss_cb_->location_cbq_.calledCount(); |
| 165 | EXPECT_EQ(locationCalledCount, 1); |
| 166 | |
| 167 | if (locationCalledCount > 0) { |
| 168 | // don't require speed on first fix |
| 169 | CheckLocation(aidl_gnss_cb_->last_location_, false); |
| 170 | return true; |
| 171 | } |
| 172 | return false; |
| 173 | } |
| 174 | |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 175 | bool GnssHalTest::StartAndCheckFirstLocation(const int min_interval_msec, |
| 176 | const bool low_power_mode) { |
| 177 | return StartAndCheckFirstLocation(min_interval_msec, low_power_mode, |
| 178 | /* start_sv_status= */ true, /* start_nmea= */ true); |
| 179 | } |
| 180 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 181 | void GnssHalTest::StopAndClearLocations() { |
| 182 | ALOGD("StopAndClearLocations"); |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 183 | if (aidl_gnss_hal_->getInterfaceVersion() <= 1) { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 184 | // Invoke the super method. |
| 185 | return GnssHalTestTemplate<IGnss_V2_1>::StopAndClearLocations(); |
| 186 | } |
Yu-Han Yang | 69f0f8b | 2022-01-21 13:03:32 -0800 | [diff] [blame] | 187 | auto status = aidl_gnss_hal_->stopSvStatus(); |
| 188 | EXPECT_TRUE(status.isOk()); |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 189 | status = aidl_gnss_hal_->stopNmea(); |
| 190 | EXPECT_TRUE(status.isOk()); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 191 | |
Yu-Han Yang | 69f0f8b | 2022-01-21 13:03:32 -0800 | [diff] [blame] | 192 | status = aidl_gnss_hal_->stop(); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 193 | EXPECT_TRUE(status.isOk()); |
| 194 | |
| 195 | /* |
| 196 | * Clear notify/waiting counter, allowing up till the timeout after |
| 197 | * the last reply for final startup messages to arrive (esp. system |
| 198 | * info.) |
| 199 | */ |
| 200 | while (aidl_gnss_cb_->location_cbq_.retrieve(aidl_gnss_cb_->last_location_, TIMEOUT_SEC)) { |
| 201 | } |
| 202 | aidl_gnss_cb_->location_cbq_.reset(); |
| 203 | } |
| 204 | |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 205 | void GnssHalTest::StartAndCheckLocations(const int count, const bool start_sv_status, |
| 206 | const bool start_nmea) { |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 207 | if (aidl_gnss_hal_->getInterfaceVersion() <= 1) { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 208 | // Invoke the super method. |
| 209 | return GnssHalTestTemplate<IGnss_V2_1>::StartAndCheckLocations(count); |
| 210 | } |
| 211 | const int kMinIntervalMsec = 500; |
| 212 | const int kLocationTimeoutSubsequentSec = 2; |
| 213 | const bool kLowPowerMode = false; |
| 214 | |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 215 | EXPECT_TRUE(StartAndCheckFirstLocation(kMinIntervalMsec, kLowPowerMode, start_sv_status, |
| 216 | start_nmea)); |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 217 | |
| 218 | for (int i = 1; i < count; i++) { |
| 219 | EXPECT_TRUE(aidl_gnss_cb_->location_cbq_.retrieve(aidl_gnss_cb_->last_location_, |
| 220 | kLocationTimeoutSubsequentSec)); |
| 221 | int locationCalledCount = aidl_gnss_cb_->location_cbq_.calledCount(); |
| 222 | EXPECT_EQ(locationCalledCount, i + 1); |
| 223 | // Don't cause confusion by checking details if no location yet |
| 224 | if (locationCalledCount > 0) { |
| 225 | // Should be more than 1 location by now, but if not, still don't check first fix speed |
| 226 | CheckLocation(aidl_gnss_cb_->last_location_, locationCalledCount > 1); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 231 | void GnssHalTest::StartAndCheckLocations(const int count) { |
| 232 | StartAndCheckLocations(count, /* start_sv_status= */ true, /* start_nmea= */ true); |
| 233 | } |
| 234 | |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 235 | std::list<std::vector<IGnssCallback::GnssSvInfo>> GnssHalTest::convertToAidl( |
| 236 | const std::list<hidl_vec<IGnssCallback_2_1::GnssSvInfo>>& sv_info_list) { |
| 237 | std::list<std::vector<IGnssCallback::GnssSvInfo>> aidl_sv_info_list; |
| 238 | for (const auto& sv_info_vec : sv_info_list) { |
| 239 | std::vector<IGnssCallback::GnssSvInfo> aidl_sv_info_vec; |
| 240 | for (const auto& sv_info : sv_info_vec) { |
| 241 | IGnssCallback::GnssSvInfo aidl_sv_info; |
| 242 | aidl_sv_info.svid = sv_info.v2_0.v1_0.svid; |
| 243 | aidl_sv_info.constellation = |
| 244 | static_cast<GnssConstellationType>(sv_info.v2_0.constellation); |
| 245 | aidl_sv_info.cN0Dbhz = sv_info.v2_0.v1_0.cN0Dbhz; |
| 246 | aidl_sv_info.basebandCN0DbHz = sv_info.basebandCN0DbHz; |
| 247 | aidl_sv_info.elevationDegrees = sv_info.v2_0.v1_0.elevationDegrees; |
| 248 | aidl_sv_info.azimuthDegrees = sv_info.v2_0.v1_0.azimuthDegrees; |
| 249 | aidl_sv_info.carrierFrequencyHz = (int64_t)sv_info.v2_0.v1_0.carrierFrequencyHz; |
| 250 | aidl_sv_info.svFlag = (int)sv_info.v2_0.v1_0.svFlag; |
| 251 | aidl_sv_info_vec.push_back(aidl_sv_info); |
| 252 | } |
| 253 | aidl_sv_info_list.push_back(aidl_sv_info_vec); |
| 254 | } |
| 255 | return aidl_sv_info_list; |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * FindStrongFrequentNonGpsSource: |
| 260 | * |
| 261 | * Search through a GnssSvStatus list for the strongest non-GPS satellite observed enough times |
| 262 | * |
| 263 | * returns the strongest source, |
| 264 | * or a source with constellation == UNKNOWN if none are found sufficient times |
| 265 | */ |
| 266 | BlocklistedSource GnssHalTest::FindStrongFrequentNonGpsSource( |
| 267 | const std::list<hidl_vec<IGnssCallback_2_1::GnssSvInfo>> sv_info_list, |
| 268 | const int min_observations) { |
| 269 | return FindStrongFrequentNonGpsSource(convertToAidl(sv_info_list), min_observations); |
| 270 | } |
| 271 | |
| 272 | BlocklistedSource GnssHalTest::FindStrongFrequentNonGpsSource( |
| 273 | const std::list<std::vector<IGnssCallback::GnssSvInfo>> sv_info_list, |
| 274 | const int min_observations) { |
| 275 | std::map<ComparableBlocklistedSource, SignalCounts> mapSignals; |
| 276 | |
| 277 | for (const auto& sv_info_vec : sv_info_list) { |
| 278 | for (uint32_t iSv = 0; iSv < sv_info_vec.size(); iSv++) { |
| 279 | const auto& gnss_sv = sv_info_vec[iSv]; |
| 280 | if ((gnss_sv.svFlag & (int)IGnssCallback::GnssSvFlags::USED_IN_FIX) && |
| 281 | (gnss_sv.constellation != GnssConstellationType::GPS)) { |
| 282 | ComparableBlocklistedSource source; |
| 283 | source.id.svid = gnss_sv.svid; |
| 284 | source.id.constellation = gnss_sv.constellation; |
| 285 | |
| 286 | const auto& itSignal = mapSignals.find(source); |
| 287 | if (itSignal == mapSignals.end()) { |
| 288 | SignalCounts counts; |
| 289 | counts.observations = 1; |
| 290 | counts.max_cn0_dbhz = gnss_sv.cN0Dbhz; |
| 291 | mapSignals.insert( |
| 292 | std::pair<ComparableBlocklistedSource, SignalCounts>(source, counts)); |
| 293 | } else { |
| 294 | itSignal->second.observations++; |
| 295 | if (itSignal->second.max_cn0_dbhz < gnss_sv.cN0Dbhz) { |
| 296 | itSignal->second.max_cn0_dbhz = gnss_sv.cN0Dbhz; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | float max_cn0_dbhz_with_sufficient_count = 0.; |
| 304 | int total_observation_count = 0; |
| 305 | int blocklisted_source_count_observation = 0; |
| 306 | |
| 307 | ComparableBlocklistedSource source_to_blocklist; // initializes to zero = UNKNOWN constellation |
| 308 | for (auto const& pairSignal : mapSignals) { |
| 309 | total_observation_count += pairSignal.second.observations; |
| 310 | if ((pairSignal.second.observations >= min_observations) && |
| 311 | (pairSignal.second.max_cn0_dbhz > max_cn0_dbhz_with_sufficient_count)) { |
| 312 | source_to_blocklist = pairSignal.first; |
| 313 | blocklisted_source_count_observation = pairSignal.second.observations; |
| 314 | max_cn0_dbhz_with_sufficient_count = pairSignal.second.max_cn0_dbhz; |
| 315 | } |
| 316 | } |
| 317 | ALOGD("Among %d observations, chose svid %d, constellation %d, " |
| 318 | "with %d observations at %.1f max CNo", |
| 319 | total_observation_count, source_to_blocklist.id.svid, |
| 320 | (int)source_to_blocklist.id.constellation, blocklisted_source_count_observation, |
| 321 | max_cn0_dbhz_with_sufficient_count); |
| 322 | |
| 323 | return source_to_blocklist.id; |
| 324 | } |
| 325 | |
| 326 | GnssConstellationType GnssHalTest::startLocationAndGetNonGpsConstellation( |
| 327 | const int locations_to_await, const int gnss_sv_info_list_timeout) { |
Yu-Han Yang | 4165ed1 | 2022-02-09 14:47:50 -0800 | [diff] [blame] | 328 | if (aidl_gnss_hal_->getInterfaceVersion() <= 1) { |
Yu-Han Yang | 1afbd5f | 2021-11-24 16:39:13 -0800 | [diff] [blame] | 329 | return static_cast<GnssConstellationType>( |
| 330 | GnssHalTestTemplate<IGnss_V2_1>::startLocationAndGetNonGpsConstellation( |
| 331 | locations_to_await, gnss_sv_info_list_timeout)); |
| 332 | } |
| 333 | aidl_gnss_cb_->location_cbq_.reset(); |
| 334 | StartAndCheckLocations(locations_to_await); |
| 335 | const int location_called_count = aidl_gnss_cb_->location_cbq_.calledCount(); |
| 336 | |
| 337 | // Tolerate 1 less sv status to handle edge cases in reporting. |
| 338 | int sv_info_list_cbq_size = aidl_gnss_cb_->sv_info_list_cbq_.size(); |
| 339 | EXPECT_GE(sv_info_list_cbq_size + 1, locations_to_await); |
| 340 | ALOGD("Observed %d GnssSvInfo, while awaiting %d Locations (%d received)", |
| 341 | sv_info_list_cbq_size, locations_to_await, location_called_count); |
| 342 | |
| 343 | // Find first non-GPS constellation to blocklist |
| 344 | GnssConstellationType constellation_to_blocklist = GnssConstellationType::UNKNOWN; |
| 345 | for (int i = 0; i < sv_info_list_cbq_size; ++i) { |
| 346 | std::vector<IGnssCallback::GnssSvInfo> sv_info_vec; |
| 347 | aidl_gnss_cb_->sv_info_list_cbq_.retrieve(sv_info_vec, gnss_sv_info_list_timeout); |
| 348 | for (uint32_t iSv = 0; iSv < sv_info_vec.size(); iSv++) { |
| 349 | auto& gnss_sv = sv_info_vec[iSv]; |
| 350 | if ((gnss_sv.svFlag & (uint32_t)IGnssCallback::GnssSvFlags::USED_IN_FIX) && |
| 351 | (gnss_sv.constellation != GnssConstellationType::UNKNOWN) && |
| 352 | (gnss_sv.constellation != GnssConstellationType::GPS)) { |
| 353 | // found a non-GPS constellation |
| 354 | constellation_to_blocklist = gnss_sv.constellation; |
| 355 | break; |
| 356 | } |
| 357 | } |
| 358 | if (constellation_to_blocklist != GnssConstellationType::UNKNOWN) { |
| 359 | break; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if (constellation_to_blocklist == GnssConstellationType::UNKNOWN) { |
| 364 | ALOGI("No non-GPS constellations found, constellation blocklist test less effective."); |
| 365 | // Proceed functionally to blocklist something. |
| 366 | constellation_to_blocklist = GnssConstellationType::GLONASS; |
| 367 | } |
| 368 | |
| 369 | return constellation_to_blocklist; |
Yu-Han Yang | 1e1a676 | 2020-09-30 17:01:53 -0700 | [diff] [blame] | 370 | } |
Yu-Han Yang | 19a32b6 | 2022-04-27 09:57:01 -0700 | [diff] [blame] | 371 | |
| 372 | void GnssHalTest::checkGnssMeasurementClockFields(const GnssData& measurement) { |
| 373 | Utils::checkElapsedRealtime(measurement.elapsedRealtime); |
| 374 | ASSERT_TRUE(measurement.clock.gnssClockFlags >= 0 && |
| 375 | measurement.clock.gnssClockFlags <= |
| 376 | (GnssClock::HAS_LEAP_SECOND | GnssClock::HAS_TIME_UNCERTAINTY | |
| 377 | GnssClock::HAS_FULL_BIAS | GnssClock::HAS_BIAS | |
| 378 | GnssClock::HAS_BIAS_UNCERTAINTY | GnssClock::HAS_DRIFT | |
| 379 | GnssClock::HAS_DRIFT_UNCERTAINTY)); |
| 380 | } |
| 381 | |
| 382 | void GnssHalTest::checkGnssMeasurementFlags(const GnssMeasurement& measurement) { |
| 383 | ASSERT_TRUE(measurement.flags >= 0 && |
| 384 | measurement.flags <= |
| 385 | (GnssMeasurement::HAS_SNR | GnssMeasurement::HAS_CARRIER_FREQUENCY | |
| 386 | GnssMeasurement::HAS_CARRIER_CYCLES | GnssMeasurement::HAS_CARRIER_PHASE | |
| 387 | GnssMeasurement::HAS_CARRIER_PHASE_UNCERTAINTY | |
| 388 | GnssMeasurement::HAS_AUTOMATIC_GAIN_CONTROL | |
| 389 | GnssMeasurement::HAS_FULL_ISB | GnssMeasurement::HAS_FULL_ISB_UNCERTAINTY | |
| 390 | GnssMeasurement::HAS_SATELLITE_ISB | |
| 391 | GnssMeasurement::HAS_SATELLITE_ISB_UNCERTAINTY | |
| 392 | GnssMeasurement::HAS_SATELLITE_PVT | |
| 393 | GnssMeasurement::HAS_CORRELATION_VECTOR)); |
| 394 | } |
| 395 | |
| 396 | void GnssHalTest::checkGnssMeasurementFields(const GnssMeasurement& measurement, |
| 397 | const GnssData& data) { |
| 398 | checkGnssMeasurementFlags(measurement); |
| 399 | // Verify CodeType is valid. |
| 400 | ASSERT_NE(measurement.signalType.codeType, ""); |
| 401 | // Verify basebandCn0DbHz is valid. |
| 402 | ASSERT_TRUE(measurement.basebandCN0DbHz > 0.0 && measurement.basebandCN0DbHz <= 65.0); |
| 403 | |
| 404 | if (((measurement.flags & GnssMeasurement::HAS_FULL_ISB) > 0) && |
| 405 | ((measurement.flags & GnssMeasurement::HAS_FULL_ISB_UNCERTAINTY) > 0) && |
| 406 | ((measurement.flags & GnssMeasurement::HAS_SATELLITE_ISB) > 0) && |
| 407 | ((measurement.flags & GnssMeasurement::HAS_SATELLITE_ISB_UNCERTAINTY) > 0)) { |
| 408 | GnssConstellationType referenceConstellation = |
| 409 | data.clock.referenceSignalTypeForIsb.constellation; |
| 410 | double carrierFrequencyHz = data.clock.referenceSignalTypeForIsb.carrierFrequencyHz; |
| 411 | std::string codeType = data.clock.referenceSignalTypeForIsb.codeType; |
| 412 | |
| 413 | ASSERT_TRUE(referenceConstellation >= GnssConstellationType::UNKNOWN && |
| 414 | referenceConstellation <= GnssConstellationType::IRNSS); |
| 415 | ASSERT_TRUE(carrierFrequencyHz > 0); |
| 416 | ASSERT_NE(codeType, ""); |
| 417 | |
| 418 | ASSERT_TRUE(std::abs(measurement.fullInterSignalBiasNs) < 1.0e6); |
| 419 | ASSERT_TRUE(measurement.fullInterSignalBiasUncertaintyNs >= 0); |
| 420 | ASSERT_TRUE(std::abs(measurement.satelliteInterSignalBiasNs) < 1.0e6); |
| 421 | ASSERT_TRUE(measurement.satelliteInterSignalBiasUncertaintyNs >= 0); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | void GnssHalTest::startMeasurementWithInterval( |
| 426 | int intervalMs, const sp<IGnssMeasurementInterface>& iGnssMeasurement, |
| 427 | sp<GnssMeasurementCallbackAidl>& callback) { |
| 428 | ALOGD("Start requesting measurement at interval of %d millis.", intervalMs); |
| 429 | IGnssMeasurementInterface::Options options; |
| 430 | options.intervalMs = intervalMs; |
| 431 | auto status = iGnssMeasurement->setCallbackWithOptions(callback, options); |
| 432 | ASSERT_TRUE(status.isOk()); |
| 433 | } |
| 434 | |
| 435 | void GnssHalTest::collectMeasurementIntervals(const sp<GnssMeasurementCallbackAidl>& callback, |
| 436 | const int numMeasurementEvents, |
| 437 | const int timeoutSeconds, |
| 438 | std::vector<int>& deltasMs) { |
| 439 | int64_t lastElapsedRealtimeMillis = 0; |
| 440 | for (int i = 0; i < numMeasurementEvents; i++) { |
| 441 | GnssData lastGnssData; |
| 442 | ASSERT_TRUE(callback->gnss_data_cbq_.retrieve(lastGnssData, timeoutSeconds)); |
| 443 | EXPECT_EQ(callback->gnss_data_cbq_.calledCount(), i + 1); |
| 444 | ASSERT_TRUE(lastGnssData.measurements.size() > 0); |
| 445 | |
| 446 | // Validity check GnssData fields |
| 447 | checkGnssMeasurementClockFields(lastGnssData); |
| 448 | for (const auto& measurement : lastGnssData.measurements) { |
| 449 | checkGnssMeasurementFields(measurement, lastGnssData); |
| 450 | } |
| 451 | |
| 452 | long currentElapsedRealtimeMillis = lastGnssData.elapsedRealtime.timestampNs * 1e-6; |
| 453 | if (lastElapsedRealtimeMillis != 0) { |
| 454 | deltasMs.push_back(currentElapsedRealtimeMillis - lastElapsedRealtimeMillis); |
| 455 | } |
| 456 | lastElapsedRealtimeMillis = currentElapsedRealtimeMillis; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | void GnssHalTest::assertMeanAndStdev(int intervalMs, std::vector<int>& deltasMs) { |
| 461 | double mean = computeMean(deltasMs); |
| 462 | double stdev = computeStdev(mean, deltasMs); |
| 463 | EXPECT_TRUE(std::abs(mean - intervalMs) <= intervalMs * ALLOWED_MEAN_ERROR_RATIO) |
| 464 | << "Test failed, because the mean of intervals is " << mean |
| 465 | << " millis. The test requires that abs(" << mean << " - " << intervalMs |
| 466 | << ") <= " << intervalMs * ALLOWED_MEAN_ERROR_RATIO |
| 467 | << " millis, when the requested interval is " << intervalMs << " millis."; |
| 468 | |
| 469 | double maxStdev = std::max(MIN_STDEV_MS, intervalMs * ALLOWED_STDEV_ERROR_RATIO); |
| 470 | EXPECT_TRUE(stdev <= maxStdev) |
| 471 | << "Test failed, because the stdev of intervals is " << stdev |
| 472 | << " millis, which must be <= " << maxStdev |
| 473 | << " millis, when the requested interval is " << intervalMs << " millis."; |
| 474 | ALOGD("Mean of interval deltas in millis: %.1lf", mean); |
| 475 | ALOGD("Stdev of interval deltas in millis: %.1lf", stdev); |
| 476 | } |