blob: c04b4d0df234f4a4351c39af622d87ef3b4a3dcd [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
Johan Ankner2fd5c7c2019-12-17 10:30:30 +010029#include <cutils/properties.h>
30
Wyatt Riley6c26ed72017-02-21 17:21:53 -080031using android::hardware::Return;
32using android::hardware::Void;
33
34using android::hardware::gnss::V1_0::GnssLocation;
35using android::hardware::gnss::V1_0::GnssLocationFlags;
36using android::hardware::gnss::V1_0::IGnss;
37using android::hardware::gnss::V1_0::IGnssCallback;
Wyatt Rileyc1399592017-03-22 14:08:26 -070038using android::hardware::gnss::V1_0::IGnssDebug;
39using android::hardware::gnss::V1_0::IGnssMeasurement;
Wyatt Riley6c26ed72017-02-21 17:21:53 -080040using android::sp;
41
Johan Ankner2fd5c7c2019-12-17 10:30:30 +010042static bool IsAutomotiveDevice() {
Patrick Berny40dcf012020-01-31 18:29:05 -080043 char buffer[PROPERTY_VALUE_MAX] = {0};
44 property_get("ro.hardware.type", buffer, "");
45 return strncmp(buffer, "automotive", PROPERTY_VALUE_MAX) == 0;
Johan Ankner2fd5c7c2019-12-17 10:30:30 +010046}
47
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -070048#define TIMEOUT_SEC 2 // for basic commands/responses
Wyatt Riley6c26ed72017-02-21 17:21:53 -080049
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -070050// for command line argument on how strictly to run the test
51bool sAgpsIsPresent = false; // if SUPL or XTRA assistance available
Wyatt Riley94c7a042017-06-15 17:16:24 -070052bool sSignalIsWeak = false; // if GNSS signals are weak (e.g. light indoor)
Wyatt Rileyc1399592017-03-22 14:08:26 -070053
Wyatt Riley6c26ed72017-02-21 17:21:53 -080054// The main test class for GNSS HAL.
Dan Shi47e47832019-10-10 11:17:22 -070055class GnssHalTest : public testing::TestWithParam<std::string> {
Wyatt Riley6c26ed72017-02-21 17:21:53 -080056 public:
57 virtual void SetUp() override {
Wyatt Riley917640b2017-03-16 16:25:55 -070058 // Clean between tests
59 capabilities_called_count_ = 0;
60 location_called_count_ = 0;
61 info_called_count_ = 0;
Wyatt Riley6ec696b2017-06-19 14:42:34 -070062 notify_count_ = 0;
Wyatt Riley6c26ed72017-02-21 17:21:53 -080063
Dan Shi47e47832019-10-10 11:17:22 -070064 gnss_hal_ = IGnss::getService(GetParam());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080065 ASSERT_NE(gnss_hal_, nullptr);
66
67 gnss_cb_ = new GnssCallback(*this);
68 ASSERT_NE(gnss_cb_, nullptr);
69
70 auto result = gnss_hal_->setCallback(gnss_cb_);
71 if (!result.isOk()) {
Wyatt Riley917640b2017-03-16 16:25:55 -070072 ALOGE("result of failed setCallback %s", result.description().c_str());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080073 }
74
75 ASSERT_TRUE(result.isOk());
76 ASSERT_TRUE(result);
77
Wyatt Riley917640b2017-03-16 16:25:55 -070078 /*
79 * At least one callback should trigger - it may be capabilites, or
80 * system info first, so wait again if capabilities not received.
Wyatt Riley6c26ed72017-02-21 17:21:53 -080081 */
Wyatt Riley917640b2017-03-16 16:25:55 -070082 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
83 if (capabilities_called_count_ == 0) {
84 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
85 }
86
87 /*
88 * Generally should be 1 capabilites callback -
89 * or possibly 2 in some recovery cases (default cached & refreshed)
90 */
91 EXPECT_GE(capabilities_called_count_, 1);
92 EXPECT_LE(capabilities_called_count_, 2);
93
94 /*
95 * Clear notify/waiting counter, allowing up till the timeout after
96 * the last reply for final startup messages to arrive (esp. system
97 * info.)
98 */
99 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
100 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800101 }
102
103 virtual void TearDown() override {
104 if (gnss_hal_ != nullptr) {
105 gnss_hal_->cleanup();
106 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700107 if (notify_count_ > 0) {
108 ALOGW("%d unprocessed callbacks discarded", notify_count_);
109 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800110 }
111
112 /* Used as a mechanism to inform the test that a callback has occurred */
113 inline void notify() {
114 std::unique_lock<std::mutex> lock(mtx_);
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700115 notify_count_++;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800116 cv_.notify_one();
117 }
118
119 /* Test code calls this function to wait for a callback */
120 inline std::cv_status wait(int timeoutSeconds) {
121 std::unique_lock<std::mutex> lock(mtx_);
122
123 std::cv_status status = std::cv_status::no_timeout;
124 auto now = std::chrono::system_clock::now();
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700125 while (notify_count_ == 0) {
126 status = cv_.wait_until(lock, now + std::chrono::seconds(timeoutSeconds));
127 if (status == std::cv_status::timeout) return status;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800128 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700129 notify_count_--;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800130 return status;
131 }
132
Wyatt Riley94c7a042017-06-15 17:16:24 -0700133 /*
134 * StartAndGetSingleLocation:
135 * Helper function to get one Location and check fields
136 *
137 * returns true if a location was successfully generated
138 */
139 bool StartAndGetSingleLocation(bool checkAccuracies) {
140 auto result = gnss_hal_->start();
141
142 EXPECT_TRUE(result.isOk());
143 EXPECT_TRUE(result);
144
145 /*
146 * GPS signals initially optional for this test, so don't expect fast fix,
147 * or no timeout, unless signal is present
148 */
149 int firstGnssLocationTimeoutSeconds = sAgpsIsPresent ? 15 : 45;
150 if (sSignalIsWeak) {
151 // allow more time for weak signals
152 firstGnssLocationTimeoutSeconds += 30;
153 }
154
155 wait(firstGnssLocationTimeoutSeconds);
156 if (sAgpsIsPresent) {
157 EXPECT_EQ(location_called_count_, 1);
158 }
159 if (location_called_count_ > 0) {
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700160 // don't require speed on first fix
161 CheckLocation(last_location_, checkAccuracies, false);
Wyatt Riley94c7a042017-06-15 17:16:24 -0700162 return true;
163 }
164 return false;
165 }
166
167 /*
168 * StopAndClearLocations:
169 * Helper function to stop locations
170 *
171 * returns true if a location was successfully generated
172 */
173 void StopAndClearLocations() {
174 auto result = gnss_hal_->stop();
175
176 EXPECT_TRUE(result.isOk());
177 EXPECT_TRUE(result);
178
179 /*
180 * Clear notify/waiting counter, allowing up till the timeout after
181 * the last reply for final startup messages to arrive (esp. system
182 * info.)
183 */
184 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
185 }
186 }
187
188 /*
189 * CheckLocation:
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700190 * Helper function to vet Location fields
Wyatt Riley94c7a042017-06-15 17:16:24 -0700191 */
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700192 void CheckLocation(GnssLocation& location, bool checkAccuracies, bool checkSpeed) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700193 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
194 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700195 if (checkSpeed) {
196 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
197 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700198 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
199 // New uncertainties available in O must be provided,
200 // at least when paired with modern hardware (2017+)
201 if (checkAccuracies) {
202 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700203 if (checkSpeed) {
204 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
205 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
206 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
207 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700208 }
209 }
210 EXPECT_GE(location.latitudeDegrees, -90.0);
211 EXPECT_LE(location.latitudeDegrees, 90.0);
212 EXPECT_GE(location.longitudeDegrees, -180.0);
213 EXPECT_LE(location.longitudeDegrees, 180.0);
214 EXPECT_GE(location.altitudeMeters, -1000.0);
215 EXPECT_LE(location.altitudeMeters, 30000.0);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700216 if (checkSpeed) {
217 EXPECT_GE(location.speedMetersPerSec, 0.0);
218 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
Wyatt Riley94c7a042017-06-15 17:16:24 -0700219
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700220 // Non-zero speeds must be reported with an associated bearing
221 if (location.speedMetersPerSec > 0.0) {
222 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
223 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700224 }
225
226 /*
227 * Tolerating some especially high values for accuracy estimate, in case of
228 * first fix with especially poor geometry (happens occasionally)
229 */
230 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
231 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
232
233 /*
234 * Some devices may define bearing as -180 to +180, others as 0 to 360.
235 * Both are okay & understandable.
236 */
237 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
238 EXPECT_GE(location.bearingDegrees, -180.0);
239 EXPECT_LE(location.bearingDegrees, 360.0);
240 }
241 if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
242 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
243 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
244 }
245 if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
246 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
247 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
248 }
249 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
250 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
251 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
252 }
253
254 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
255 EXPECT_GT(location.timestamp, 1.48e12);
256 }
257
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800258 /* Callback class for data & Event. */
259 class GnssCallback : public IGnssCallback {
Wyatt Riley917640b2017-03-16 16:25:55 -0700260 public:
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800261 GnssHalTest& parent_;
262
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800263 GnssCallback(GnssHalTest& parent) : parent_(parent){};
264
265 virtual ~GnssCallback() = default;
266
267 // Dummy callback handlers
268 Return<void> gnssStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800269 const IGnssCallback::GnssStatusValue /* status */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800270 return Void();
271 }
272 Return<void> gnssSvStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800273 const IGnssCallback::GnssSvStatus& /* svStatus */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800274 return Void();
275 }
276 Return<void> gnssNmeaCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800277 int64_t /* timestamp */,
278 const android::hardware::hidl_string& /* nmea */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800279 return Void();
280 }
281 Return<void> gnssAcquireWakelockCb() override { return Void(); }
282 Return<void> gnssReleaseWakelockCb() override { return Void(); }
283 Return<void> gnssRequestTimeCb() override { return Void(); }
284
285 // Actual (test) callback handlers
286 Return<void> gnssLocationCb(const GnssLocation& location) override {
287 ALOGI("Location received");
288 parent_.location_called_count_++;
289 parent_.last_location_ = location;
290 parent_.notify();
291 return Void();
292 }
293
294 Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override {
295 ALOGI("Capabilities received %d", capabilities);
296 parent_.capabilities_called_count_++;
297 parent_.last_capabilities_ = capabilities;
298 parent_.notify();
299 return Void();
300 }
301
302 Return<void> gnssSetSystemInfoCb(
303 const IGnssCallback::GnssSystemInfo& info) override {
304 ALOGI("Info received, year %d", info.yearOfHw);
305 parent_.info_called_count_++;
306 parent_.last_info_ = info;
307 parent_.notify();
308 return Void();
309 }
310 };
311
312 sp<IGnss> gnss_hal_; // GNSS HAL to call into
313 sp<IGnssCallback> gnss_cb_; // Primary callback interface
314
315 /* Count of calls to set the following items, and the latest item (used by
316 * test.)
317 */
318 int capabilities_called_count_;
319 uint32_t last_capabilities_;
320
321 int location_called_count_;
322 GnssLocation last_location_;
323
324 int info_called_count_;
325 IGnssCallback::GnssSystemInfo last_info_;
326
327 private:
328 std::mutex mtx_;
329 std::condition_variable cv_;
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700330 int notify_count_;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800331};
332
333/*
334 * SetCallbackCapabilitiesCleanup:
335 * Sets up the callback, awaits the capabilities, and calls cleanup
336 *
337 * Since this is just the basic operation of SetUp() and TearDown(),
Wyatt Riley917640b2017-03-16 16:25:55 -0700338 * the function definition is intentionally empty
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800339 */
Dan Shi47e47832019-10-10 11:17:22 -0700340TEST_P(GnssHalTest, SetCallbackCapabilitiesCleanup) {}
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800341
Wyatt Riley917640b2017-03-16 16:25:55 -0700342/*
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800343 * GetLocation:
344 * Turns on location, waits 45 second for at least 5 locations,
345 * and checks them for reasonable validity.
346 */
Dan Shi47e47832019-10-10 11:17:22 -0700347TEST_P(GnssHalTest, GetLocation) {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800348#define MIN_INTERVAL_MSEC 500
349#define PREFERRED_ACCURACY 0 // Ideally perfect (matches GnssLocationProvider)
350#define PREFERRED_TIME_MSEC 0 // Ideally immediate
351
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800352#define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3
353#define LOCATIONS_TO_CHECK 5
354
Wyatt Riley917640b2017-03-16 16:25:55 -0700355 bool checkMoreAccuracies =
356 (info_called_count_ > 0 && last_info_.yearOfHw >= 2017);
357
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800358 auto result = gnss_hal_->setPositionMode(
359 IGnss::GnssPositionMode::MS_BASED,
360 IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, MIN_INTERVAL_MSEC,
361 PREFERRED_ACCURACY, PREFERRED_TIME_MSEC);
362
363 ASSERT_TRUE(result.isOk());
Wyatt Rileyc1399592017-03-22 14:08:26 -0700364 EXPECT_TRUE(result);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800365
Wyatt Rileyc1399592017-03-22 14:08:26 -0700366 /*
367 * GPS signals initially optional for this test, so don't expect no timeout
368 * yet
369 */
Wyatt Riley94c7a042017-06-15 17:16:24 -0700370 bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800371
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700372 if (gotLocation) {
373 for (int i = 1; i < LOCATIONS_TO_CHECK; i++) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700374 EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC));
375 EXPECT_EQ(location_called_count_, i + 1);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700376 CheckLocation(last_location_, checkMoreAccuracies, true);
Wyatt Riley917640b2017-03-16 16:25:55 -0700377 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800378 }
379
Wyatt Riley94c7a042017-06-15 17:16:24 -0700380 StopAndClearLocations();
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800381}
382
Wyatt Rileyc1399592017-03-22 14:08:26 -0700383/*
384 * InjectDelete:
385 * Ensures that calls to inject and/or delete information state are handled.
Wyatt Rileyc1399592017-03-22 14:08:26 -0700386 */
Dan Shi47e47832019-10-10 11:17:22 -0700387TEST_P(GnssHalTest, InjectDelete) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700388 // confidently, well north of Alaska
389 auto result = gnss_hal_->injectLocation(80.0, -170.0, 1000.0);
390
Wyatt Rileyc1399592017-03-22 14:08:26 -0700391 ASSERT_TRUE(result.isOk());
392 EXPECT_TRUE(result);
393
394 // fake time, but generally reasonable values (time in Aug. 2018)
395 result = gnss_hal_->injectTime(1534567890123L, 123456L, 10000L);
396
397 ASSERT_TRUE(result.isOk());
398 EXPECT_TRUE(result);
399
Yu-Han Yang66fb7a12018-07-02 10:41:28 -0700400 auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_POSITION);
401
402 ASSERT_TRUE(resultVoid.isOk());
403
404 resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_TIME);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700405
406 ASSERT_TRUE(resultVoid.isOk());
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700407
408 // Ensure we can get a good location after a bad injection has been deleted
Wyatt Riley94c7a042017-06-15 17:16:24 -0700409 StartAndGetSingleLocation(false);
410
411 StopAndClearLocations();
Wyatt Rileyc1399592017-03-22 14:08:26 -0700412}
413
414/*
Yu-Han Yangb20389e2019-11-19 22:11:11 -0800415 * InjectSeedLocation:
416 * Injects a seed location and ensures the injected seed location is not fused in the resulting
417 * GNSS location.
418 */
419TEST_P(GnssHalTest, InjectSeedLocation) {
420 // An arbitrary position in North Pacific Ocean (where no VTS labs will ever likely be located).
421 const double seedLatDegrees = 32.312894;
422 const double seedLngDegrees = -172.954117;
423 const float seedAccuracyMeters = 150.0;
424
425 auto result = gnss_hal_->injectLocation(seedLatDegrees, seedLngDegrees, seedAccuracyMeters);
426 ASSERT_TRUE(result.isOk());
427 EXPECT_TRUE(result);
428
429 StartAndGetSingleLocation(false);
430
431 // Ensure we don't get a location anywhere within 111km (1 degree of lat or lng) of the seed
432 // location.
433 EXPECT_TRUE(std::abs(last_location_.latitudeDegrees - seedLatDegrees) > 1.0 ||
434 std::abs(last_location_.longitudeDegrees - seedLngDegrees) > 1.0);
435
436 StopAndClearLocations();
437
438 auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_POSITION);
439 ASSERT_TRUE(resultVoid.isOk());
440}
441
442/*
Wyatt Rileyc1399592017-03-22 14:08:26 -0700443 * GetAllExtentions:
444 * Tries getting all optional extensions, and ensures a valid return
445 * null or actual extension, no crash.
446 * Confirms year-based required extensions (Measurement & Debug) are present
447 */
Dan Shi47e47832019-10-10 11:17:22 -0700448TEST_P(GnssHalTest, GetAllExtensions) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700449 // Basic call-is-handled checks
450 auto gnssXtra = gnss_hal_->getExtensionXtra();
451 ASSERT_TRUE(gnssXtra.isOk());
452
453 auto gnssRil = gnss_hal_->getExtensionAGnssRil();
454 ASSERT_TRUE(gnssRil.isOk());
455
456 auto gnssAgnss = gnss_hal_->getExtensionAGnss();
457 ASSERT_TRUE(gnssAgnss.isOk());
458
459 auto gnssNi = gnss_hal_->getExtensionGnssNi();
460 ASSERT_TRUE(gnssNi.isOk());
461
462 auto gnssNavigationMessage = gnss_hal_->getExtensionGnssNavigationMessage();
463 ASSERT_TRUE(gnssNavigationMessage.isOk());
464
465 auto gnssConfiguration = gnss_hal_->getExtensionGnssConfiguration();
466 ASSERT_TRUE(gnssConfiguration.isOk());
467
468 auto gnssGeofencing = gnss_hal_->getExtensionGnssGeofencing();
469 ASSERT_TRUE(gnssGeofencing.isOk());
470
471 auto gnssBatching = gnss_hal_->getExtensionGnssBatching();
472 ASSERT_TRUE(gnssBatching.isOk());
473
474 // Verifying, in some cases, that these return actual extensions
475 auto gnssMeasurement = gnss_hal_->getExtensionGnssMeasurement();
476 ASSERT_TRUE(gnssMeasurement.isOk());
477 if (last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS) {
478 sp<IGnssMeasurement> iGnssMeas = gnssMeasurement;
479 EXPECT_NE(iGnssMeas, nullptr);
480 }
481
482 auto gnssDebug = gnss_hal_->getExtensionGnssDebug();
483 ASSERT_TRUE(gnssDebug.isOk());
Johan Ankner2fd5c7c2019-12-17 10:30:30 +0100484 if (!IsAutomotiveDevice() && info_called_count_ > 0 && last_info_.yearOfHw >= 2017) {
485 sp<IGnssDebug> iGnssDebug = gnssDebug;
486 EXPECT_NE(iGnssDebug, nullptr);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700487 }
488}
489
490/*
491 * MeasurementCapabilities:
492 * Verifies that modern hardware supports measurement capabilities.
493 */
Dan Shi47e47832019-10-10 11:17:22 -0700494TEST_P(GnssHalTest, MeasurementCapabilites) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700495 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2016) {
496 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS);
497 }
498}
499
Vishal Agarwal2910e642018-06-05 18:42:01 -0700500/*
501 * SchedulingCapabilities:
502 * Verifies that 2018+ hardware supports Scheduling capabilities.
503 */
Dan Shi47e47832019-10-10 11:17:22 -0700504TEST_P(GnssHalTest, SchedulingCapabilities) {
Vishal Agarwal2910e642018-06-05 18:42:01 -0700505 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2018) {
506 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::SCHEDULING);
507 }
508}
509
Dan Shi47e47832019-10-10 11:17:22 -0700510INSTANTIATE_TEST_SUITE_P(
511 PerInstance, GnssHalTest,
512 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IGnss::descriptor)),
513 android::hardware::PrintInstanceNameToString);
514
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800515int main(int argc, char** argv) {
516 ::testing::InitGoogleTest(&argc, argv);
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700517 /*
518 * These arguments not used by automated VTS testing.
519 * Only for use in manual testing, when wanting to run
520 * stronger tests that require the presence of GPS signal.
521 */
522 for (int i = 1; i < argc; i++) {
Zhuoyao Zhang989afba2018-02-08 20:53:56 -0800523 if (strcmp(argv[i], "-agps") == 0) {
524 sAgpsIsPresent = true;
525 } else if (strcmp(argv[i], "-weak") == 0) {
526 sSignalIsWeak = true;
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700527 }
528 }
Dan Shi47e47832019-10-10 11:17:22 -0700529
530 return RUN_ALL_TESTS();
531}