blob: 6183a1ae2872cd0b673124923ac7aaef90e880bf [file] [log] [blame]
Wyatt Riley6c26ed72017-02-21 17:21:53 -08001/*
2 * Copyright (C) 2017 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
17#define LOG_TAG "VtsHalGnssV1_0TargetTest"
18#include <android/hardware/gnss/1.0/IGnss.h>
Dan Shi47e47832019-10-10 11:17:22 -070019#include <gtest/gtest.h>
20#include <hidl/GtestPrinter.h>
21#include <hidl/ServiceManagement.h>
Steven Moreland4e7a3072017-04-06 12:15:23 -070022#include <log/log.h>
Wyatt Riley6c26ed72017-02-21 17:21:53 -080023
Wyatt Riley6c26ed72017-02-21 17:21:53 -080024#include <chrono>
Yu-Han Yangb20389e2019-11-19 22:11:11 -080025#include <cmath>
Wyatt Riley6c26ed72017-02-21 17:21:53 -080026#include <condition_variable>
27#include <mutex>
28
29using android::hardware::Return;
30using android::hardware::Void;
31
32using android::hardware::gnss::V1_0::GnssLocation;
33using android::hardware::gnss::V1_0::GnssLocationFlags;
34using android::hardware::gnss::V1_0::IGnss;
35using android::hardware::gnss::V1_0::IGnssCallback;
Wyatt Rileyc1399592017-03-22 14:08:26 -070036using android::hardware::gnss::V1_0::IGnssDebug;
37using android::hardware::gnss::V1_0::IGnssMeasurement;
Wyatt Riley6c26ed72017-02-21 17:21:53 -080038using android::sp;
39
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -070040#define TIMEOUT_SEC 2 // for basic commands/responses
Wyatt Riley6c26ed72017-02-21 17:21:53 -080041
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -070042// for command line argument on how strictly to run the test
43bool sAgpsIsPresent = false; // if SUPL or XTRA assistance available
Wyatt Riley94c7a042017-06-15 17:16:24 -070044bool sSignalIsWeak = false; // if GNSS signals are weak (e.g. light indoor)
Wyatt Rileyc1399592017-03-22 14:08:26 -070045
Wyatt Riley6c26ed72017-02-21 17:21:53 -080046// The main test class for GNSS HAL.
Dan Shi47e47832019-10-10 11:17:22 -070047class GnssHalTest : public testing::TestWithParam<std::string> {
Wyatt Riley6c26ed72017-02-21 17:21:53 -080048 public:
49 virtual void SetUp() override {
Wyatt Riley917640b2017-03-16 16:25:55 -070050 // Clean between tests
51 capabilities_called_count_ = 0;
52 location_called_count_ = 0;
53 info_called_count_ = 0;
Wyatt Riley6ec696b2017-06-19 14:42:34 -070054 notify_count_ = 0;
Wyatt Riley6c26ed72017-02-21 17:21:53 -080055
Dan Shi47e47832019-10-10 11:17:22 -070056 gnss_hal_ = IGnss::getService(GetParam());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080057 ASSERT_NE(gnss_hal_, nullptr);
58
59 gnss_cb_ = new GnssCallback(*this);
60 ASSERT_NE(gnss_cb_, nullptr);
61
62 auto result = gnss_hal_->setCallback(gnss_cb_);
63 if (!result.isOk()) {
Wyatt Riley917640b2017-03-16 16:25:55 -070064 ALOGE("result of failed setCallback %s", result.description().c_str());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080065 }
66
67 ASSERT_TRUE(result.isOk());
68 ASSERT_TRUE(result);
69
Wyatt Riley917640b2017-03-16 16:25:55 -070070 /*
71 * At least one callback should trigger - it may be capabilites, or
72 * system info first, so wait again if capabilities not received.
Wyatt Riley6c26ed72017-02-21 17:21:53 -080073 */
Wyatt Riley917640b2017-03-16 16:25:55 -070074 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
75 if (capabilities_called_count_ == 0) {
76 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
77 }
78
79 /*
80 * Generally should be 1 capabilites callback -
81 * or possibly 2 in some recovery cases (default cached & refreshed)
82 */
83 EXPECT_GE(capabilities_called_count_, 1);
84 EXPECT_LE(capabilities_called_count_, 2);
85
86 /*
87 * Clear notify/waiting counter, allowing up till the timeout after
88 * the last reply for final startup messages to arrive (esp. system
89 * info.)
90 */
91 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
92 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -080093 }
94
95 virtual void TearDown() override {
96 if (gnss_hal_ != nullptr) {
97 gnss_hal_->cleanup();
98 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -070099 if (notify_count_ > 0) {
100 ALOGW("%d unprocessed callbacks discarded", notify_count_);
101 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800102 }
103
104 /* Used as a mechanism to inform the test that a callback has occurred */
105 inline void notify() {
106 std::unique_lock<std::mutex> lock(mtx_);
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700107 notify_count_++;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800108 cv_.notify_one();
109 }
110
111 /* Test code calls this function to wait for a callback */
112 inline std::cv_status wait(int timeoutSeconds) {
113 std::unique_lock<std::mutex> lock(mtx_);
114
115 std::cv_status status = std::cv_status::no_timeout;
116 auto now = std::chrono::system_clock::now();
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700117 while (notify_count_ == 0) {
118 status = cv_.wait_until(lock, now + std::chrono::seconds(timeoutSeconds));
119 if (status == std::cv_status::timeout) return status;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800120 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700121 notify_count_--;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800122 return status;
123 }
124
Wyatt Riley94c7a042017-06-15 17:16:24 -0700125 /*
126 * StartAndGetSingleLocation:
127 * Helper function to get one Location and check fields
128 *
129 * returns true if a location was successfully generated
130 */
131 bool StartAndGetSingleLocation(bool checkAccuracies) {
132 auto result = gnss_hal_->start();
133
134 EXPECT_TRUE(result.isOk());
135 EXPECT_TRUE(result);
136
137 /*
138 * GPS signals initially optional for this test, so don't expect fast fix,
139 * or no timeout, unless signal is present
140 */
141 int firstGnssLocationTimeoutSeconds = sAgpsIsPresent ? 15 : 45;
142 if (sSignalIsWeak) {
143 // allow more time for weak signals
144 firstGnssLocationTimeoutSeconds += 30;
145 }
146
147 wait(firstGnssLocationTimeoutSeconds);
148 if (sAgpsIsPresent) {
149 EXPECT_EQ(location_called_count_, 1);
150 }
151 if (location_called_count_ > 0) {
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700152 // don't require speed on first fix
153 CheckLocation(last_location_, checkAccuracies, false);
Wyatt Riley94c7a042017-06-15 17:16:24 -0700154 return true;
155 }
156 return false;
157 }
158
159 /*
160 * StopAndClearLocations:
161 * Helper function to stop locations
162 *
163 * returns true if a location was successfully generated
164 */
165 void StopAndClearLocations() {
166 auto result = gnss_hal_->stop();
167
168 EXPECT_TRUE(result.isOk());
169 EXPECT_TRUE(result);
170
171 /*
172 * Clear notify/waiting counter, allowing up till the timeout after
173 * the last reply for final startup messages to arrive (esp. system
174 * info.)
175 */
176 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
177 }
178 }
179
180 /*
181 * CheckLocation:
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700182 * Helper function to vet Location fields
Wyatt Riley94c7a042017-06-15 17:16:24 -0700183 */
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700184 void CheckLocation(GnssLocation& location, bool checkAccuracies, bool checkSpeed) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700185 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
186 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700187 if (checkSpeed) {
188 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
189 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700190 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
191 // New uncertainties available in O must be provided,
192 // at least when paired with modern hardware (2017+)
193 if (checkAccuracies) {
194 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700195 if (checkSpeed) {
196 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
197 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
198 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
199 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700200 }
201 }
202 EXPECT_GE(location.latitudeDegrees, -90.0);
203 EXPECT_LE(location.latitudeDegrees, 90.0);
204 EXPECT_GE(location.longitudeDegrees, -180.0);
205 EXPECT_LE(location.longitudeDegrees, 180.0);
206 EXPECT_GE(location.altitudeMeters, -1000.0);
207 EXPECT_LE(location.altitudeMeters, 30000.0);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700208 if (checkSpeed) {
209 EXPECT_GE(location.speedMetersPerSec, 0.0);
210 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
Wyatt Riley94c7a042017-06-15 17:16:24 -0700211
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700212 // Non-zero speeds must be reported with an associated bearing
213 if (location.speedMetersPerSec > 0.0) {
214 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
215 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700216 }
217
218 /*
219 * Tolerating some especially high values for accuracy estimate, in case of
220 * first fix with especially poor geometry (happens occasionally)
221 */
222 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
223 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
224
225 /*
226 * Some devices may define bearing as -180 to +180, others as 0 to 360.
227 * Both are okay & understandable.
228 */
229 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
230 EXPECT_GE(location.bearingDegrees, -180.0);
231 EXPECT_LE(location.bearingDegrees, 360.0);
232 }
233 if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
234 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
235 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
236 }
237 if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
238 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
239 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
240 }
241 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
242 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
243 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
244 }
245
246 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
247 EXPECT_GT(location.timestamp, 1.48e12);
248 }
249
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800250 /* Callback class for data & Event. */
251 class GnssCallback : public IGnssCallback {
Wyatt Riley917640b2017-03-16 16:25:55 -0700252 public:
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800253 GnssHalTest& parent_;
254
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800255 GnssCallback(GnssHalTest& parent) : parent_(parent){};
256
257 virtual ~GnssCallback() = default;
258
259 // Dummy callback handlers
260 Return<void> gnssStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800261 const IGnssCallback::GnssStatusValue /* status */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800262 return Void();
263 }
264 Return<void> gnssSvStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800265 const IGnssCallback::GnssSvStatus& /* svStatus */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800266 return Void();
267 }
268 Return<void> gnssNmeaCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800269 int64_t /* timestamp */,
270 const android::hardware::hidl_string& /* nmea */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800271 return Void();
272 }
273 Return<void> gnssAcquireWakelockCb() override { return Void(); }
274 Return<void> gnssReleaseWakelockCb() override { return Void(); }
275 Return<void> gnssRequestTimeCb() override { return Void(); }
276
277 // Actual (test) callback handlers
278 Return<void> gnssLocationCb(const GnssLocation& location) override {
279 ALOGI("Location received");
280 parent_.location_called_count_++;
281 parent_.last_location_ = location;
282 parent_.notify();
283 return Void();
284 }
285
286 Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override {
287 ALOGI("Capabilities received %d", capabilities);
288 parent_.capabilities_called_count_++;
289 parent_.last_capabilities_ = capabilities;
290 parent_.notify();
291 return Void();
292 }
293
294 Return<void> gnssSetSystemInfoCb(
295 const IGnssCallback::GnssSystemInfo& info) override {
296 ALOGI("Info received, year %d", info.yearOfHw);
297 parent_.info_called_count_++;
298 parent_.last_info_ = info;
299 parent_.notify();
300 return Void();
301 }
302 };
303
304 sp<IGnss> gnss_hal_; // GNSS HAL to call into
305 sp<IGnssCallback> gnss_cb_; // Primary callback interface
306
307 /* Count of calls to set the following items, and the latest item (used by
308 * test.)
309 */
310 int capabilities_called_count_;
311 uint32_t last_capabilities_;
312
313 int location_called_count_;
314 GnssLocation last_location_;
315
316 int info_called_count_;
317 IGnssCallback::GnssSystemInfo last_info_;
318
319 private:
320 std::mutex mtx_;
321 std::condition_variable cv_;
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700322 int notify_count_;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800323};
324
325/*
326 * SetCallbackCapabilitiesCleanup:
327 * Sets up the callback, awaits the capabilities, and calls cleanup
328 *
329 * Since this is just the basic operation of SetUp() and TearDown(),
Wyatt Riley917640b2017-03-16 16:25:55 -0700330 * the function definition is intentionally empty
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800331 */
Dan Shi47e47832019-10-10 11:17:22 -0700332TEST_P(GnssHalTest, SetCallbackCapabilitiesCleanup) {}
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800333
Wyatt Riley917640b2017-03-16 16:25:55 -0700334/*
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800335 * GetLocation:
336 * Turns on location, waits 45 second for at least 5 locations,
337 * and checks them for reasonable validity.
338 */
Dan Shi47e47832019-10-10 11:17:22 -0700339TEST_P(GnssHalTest, GetLocation) {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800340#define MIN_INTERVAL_MSEC 500
341#define PREFERRED_ACCURACY 0 // Ideally perfect (matches GnssLocationProvider)
342#define PREFERRED_TIME_MSEC 0 // Ideally immediate
343
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800344#define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3
345#define LOCATIONS_TO_CHECK 5
346
Wyatt Riley917640b2017-03-16 16:25:55 -0700347 bool checkMoreAccuracies =
348 (info_called_count_ > 0 && last_info_.yearOfHw >= 2017);
349
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800350 auto result = gnss_hal_->setPositionMode(
351 IGnss::GnssPositionMode::MS_BASED,
352 IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, MIN_INTERVAL_MSEC,
353 PREFERRED_ACCURACY, PREFERRED_TIME_MSEC);
354
355 ASSERT_TRUE(result.isOk());
Wyatt Rileyc1399592017-03-22 14:08:26 -0700356 EXPECT_TRUE(result);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800357
Wyatt Rileyc1399592017-03-22 14:08:26 -0700358 /*
359 * GPS signals initially optional for this test, so don't expect no timeout
360 * yet
361 */
Wyatt Riley94c7a042017-06-15 17:16:24 -0700362 bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800363
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700364 if (gotLocation) {
365 for (int i = 1; i < LOCATIONS_TO_CHECK; i++) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700366 EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC));
367 EXPECT_EQ(location_called_count_, i + 1);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700368 CheckLocation(last_location_, checkMoreAccuracies, true);
Wyatt Riley917640b2017-03-16 16:25:55 -0700369 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800370 }
371
Wyatt Riley94c7a042017-06-15 17:16:24 -0700372 StopAndClearLocations();
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800373}
374
Wyatt Rileyc1399592017-03-22 14:08:26 -0700375/*
376 * InjectDelete:
377 * Ensures that calls to inject and/or delete information state are handled.
Wyatt Rileyc1399592017-03-22 14:08:26 -0700378 */
Dan Shi47e47832019-10-10 11:17:22 -0700379TEST_P(GnssHalTest, InjectDelete) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700380 // confidently, well north of Alaska
381 auto result = gnss_hal_->injectLocation(80.0, -170.0, 1000.0);
382
Wyatt Rileyc1399592017-03-22 14:08:26 -0700383 ASSERT_TRUE(result.isOk());
384 EXPECT_TRUE(result);
385
386 // fake time, but generally reasonable values (time in Aug. 2018)
387 result = gnss_hal_->injectTime(1534567890123L, 123456L, 10000L);
388
389 ASSERT_TRUE(result.isOk());
390 EXPECT_TRUE(result);
391
Yu-Han Yang66fb7a12018-07-02 10:41:28 -0700392 auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_POSITION);
393
394 ASSERT_TRUE(resultVoid.isOk());
395
396 resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_TIME);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700397
398 ASSERT_TRUE(resultVoid.isOk());
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700399
400 // Ensure we can get a good location after a bad injection has been deleted
Wyatt Riley94c7a042017-06-15 17:16:24 -0700401 StartAndGetSingleLocation(false);
402
403 StopAndClearLocations();
Wyatt Rileyc1399592017-03-22 14:08:26 -0700404}
405
406/*
Yu-Han Yangb20389e2019-11-19 22:11:11 -0800407 * InjectSeedLocation:
408 * Injects a seed location and ensures the injected seed location is not fused in the resulting
409 * GNSS location.
410 */
411TEST_P(GnssHalTest, InjectSeedLocation) {
412 // An arbitrary position in North Pacific Ocean (where no VTS labs will ever likely be located).
413 const double seedLatDegrees = 32.312894;
414 const double seedLngDegrees = -172.954117;
415 const float seedAccuracyMeters = 150.0;
416
417 auto result = gnss_hal_->injectLocation(seedLatDegrees, seedLngDegrees, seedAccuracyMeters);
418 ASSERT_TRUE(result.isOk());
419 EXPECT_TRUE(result);
420
421 StartAndGetSingleLocation(false);
422
423 // Ensure we don't get a location anywhere within 111km (1 degree of lat or lng) of the seed
424 // location.
425 EXPECT_TRUE(std::abs(last_location_.latitudeDegrees - seedLatDegrees) > 1.0 ||
426 std::abs(last_location_.longitudeDegrees - seedLngDegrees) > 1.0);
427
428 StopAndClearLocations();
429
430 auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_POSITION);
431 ASSERT_TRUE(resultVoid.isOk());
432}
433
434/*
Wyatt Rileyc1399592017-03-22 14:08:26 -0700435 * GetAllExtentions:
436 * Tries getting all optional extensions, and ensures a valid return
437 * null or actual extension, no crash.
438 * Confirms year-based required extensions (Measurement & Debug) are present
439 */
Dan Shi47e47832019-10-10 11:17:22 -0700440TEST_P(GnssHalTest, GetAllExtensions) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700441 // Basic call-is-handled checks
442 auto gnssXtra = gnss_hal_->getExtensionXtra();
443 ASSERT_TRUE(gnssXtra.isOk());
444
445 auto gnssRil = gnss_hal_->getExtensionAGnssRil();
446 ASSERT_TRUE(gnssRil.isOk());
447
448 auto gnssAgnss = gnss_hal_->getExtensionAGnss();
449 ASSERT_TRUE(gnssAgnss.isOk());
450
451 auto gnssNi = gnss_hal_->getExtensionGnssNi();
452 ASSERT_TRUE(gnssNi.isOk());
453
454 auto gnssNavigationMessage = gnss_hal_->getExtensionGnssNavigationMessage();
455 ASSERT_TRUE(gnssNavigationMessage.isOk());
456
457 auto gnssConfiguration = gnss_hal_->getExtensionGnssConfiguration();
458 ASSERT_TRUE(gnssConfiguration.isOk());
459
460 auto gnssGeofencing = gnss_hal_->getExtensionGnssGeofencing();
461 ASSERT_TRUE(gnssGeofencing.isOk());
462
463 auto gnssBatching = gnss_hal_->getExtensionGnssBatching();
464 ASSERT_TRUE(gnssBatching.isOk());
465
466 // Verifying, in some cases, that these return actual extensions
467 auto gnssMeasurement = gnss_hal_->getExtensionGnssMeasurement();
468 ASSERT_TRUE(gnssMeasurement.isOk());
469 if (last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS) {
470 sp<IGnssMeasurement> iGnssMeas = gnssMeasurement;
471 EXPECT_NE(iGnssMeas, nullptr);
472 }
473
474 auto gnssDebug = gnss_hal_->getExtensionGnssDebug();
475 ASSERT_TRUE(gnssDebug.isOk());
476 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2017) {
477 sp<IGnssDebug> iGnssDebug = gnssDebug;
478 EXPECT_NE(iGnssDebug, nullptr);
479 }
480}
481
482/*
483 * MeasurementCapabilities:
484 * Verifies that modern hardware supports measurement capabilities.
485 */
Dan Shi47e47832019-10-10 11:17:22 -0700486TEST_P(GnssHalTest, MeasurementCapabilites) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700487 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2016) {
488 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS);
489 }
490}
491
Vishal Agarwal2910e642018-06-05 18:42:01 -0700492/*
493 * SchedulingCapabilities:
494 * Verifies that 2018+ hardware supports Scheduling capabilities.
495 */
Dan Shi47e47832019-10-10 11:17:22 -0700496TEST_P(GnssHalTest, SchedulingCapabilities) {
Vishal Agarwal2910e642018-06-05 18:42:01 -0700497 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2018) {
498 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::SCHEDULING);
499 }
500}
501
Dan Shi47e47832019-10-10 11:17:22 -0700502INSTANTIATE_TEST_SUITE_P(
503 PerInstance, GnssHalTest,
504 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IGnss::descriptor)),
505 android::hardware::PrintInstanceNameToString);
506
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800507int main(int argc, char** argv) {
508 ::testing::InitGoogleTest(&argc, argv);
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700509 /*
510 * These arguments not used by automated VTS testing.
511 * Only for use in manual testing, when wanting to run
512 * stronger tests that require the presence of GPS signal.
513 */
514 for (int i = 1; i < argc; i++) {
Zhuoyao Zhang989afba2018-02-08 20:53:56 -0800515 if (strcmp(argv[i], "-agps") == 0) {
516 sAgpsIsPresent = true;
517 } else if (strcmp(argv[i], "-weak") == 0) {
518 sSignalIsWeak = true;
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700519 }
520 }
Dan Shi47e47832019-10-10 11:17:22 -0700521
522 return RUN_ALL_TESTS();
523}