blob: 237e8ec9d8877fe187a344b0773d490551c85cdc [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
Tyler Trephan0d9206a2020-09-28 22:03:18 -070042/*
43 * Since Utils.cpp depends on Gnss Hal 2.0, the tests for Gnss Hal 1.0 will use
44 * there own version of IsAutomotiveDevice() instead of the common version.
45 */
Johan Ankner2fd5c7c2019-12-17 10:30:30 +010046static bool IsAutomotiveDevice() {
Patrick Berny40dcf012020-01-31 18:29:05 -080047 char buffer[PROPERTY_VALUE_MAX] = {0};
48 property_get("ro.hardware.type", buffer, "");
49 return strncmp(buffer, "automotive", PROPERTY_VALUE_MAX) == 0;
Johan Ankner2fd5c7c2019-12-17 10:30:30 +010050}
51
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -070052#define TIMEOUT_SEC 2 // for basic commands/responses
Wyatt Riley6c26ed72017-02-21 17:21:53 -080053
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -070054// for command line argument on how strictly to run the test
55bool sAgpsIsPresent = false; // if SUPL or XTRA assistance available
Wyatt Riley94c7a042017-06-15 17:16:24 -070056bool sSignalIsWeak = false; // if GNSS signals are weak (e.g. light indoor)
Wyatt Rileyc1399592017-03-22 14:08:26 -070057
Wyatt Riley6c26ed72017-02-21 17:21:53 -080058// The main test class for GNSS HAL.
Dan Shi47e47832019-10-10 11:17:22 -070059class GnssHalTest : public testing::TestWithParam<std::string> {
Wyatt Riley6c26ed72017-02-21 17:21:53 -080060 public:
61 virtual void SetUp() override {
Wyatt Riley917640b2017-03-16 16:25:55 -070062 // Clean between tests
63 capabilities_called_count_ = 0;
64 location_called_count_ = 0;
65 info_called_count_ = 0;
Wyatt Riley6ec696b2017-06-19 14:42:34 -070066 notify_count_ = 0;
Wyatt Riley6c26ed72017-02-21 17:21:53 -080067
Dan Shi47e47832019-10-10 11:17:22 -070068 gnss_hal_ = IGnss::getService(GetParam());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080069 ASSERT_NE(gnss_hal_, nullptr);
70
71 gnss_cb_ = new GnssCallback(*this);
72 ASSERT_NE(gnss_cb_, nullptr);
73
74 auto result = gnss_hal_->setCallback(gnss_cb_);
75 if (!result.isOk()) {
Wyatt Riley917640b2017-03-16 16:25:55 -070076 ALOGE("result of failed setCallback %s", result.description().c_str());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080077 }
78
79 ASSERT_TRUE(result.isOk());
80 ASSERT_TRUE(result);
81
Wyatt Riley917640b2017-03-16 16:25:55 -070082 /*
83 * At least one callback should trigger - it may be capabilites, or
84 * system info first, so wait again if capabilities not received.
Wyatt Riley6c26ed72017-02-21 17:21:53 -080085 */
Wyatt Riley917640b2017-03-16 16:25:55 -070086 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
87 if (capabilities_called_count_ == 0) {
88 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
89 }
90
91 /*
92 * Generally should be 1 capabilites callback -
93 * or possibly 2 in some recovery cases (default cached & refreshed)
94 */
95 EXPECT_GE(capabilities_called_count_, 1);
96 EXPECT_LE(capabilities_called_count_, 2);
97
98 /*
99 * Clear notify/waiting counter, allowing up till the timeout after
100 * the last reply for final startup messages to arrive (esp. system
101 * info.)
102 */
103 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
104 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800105 }
106
107 virtual void TearDown() override {
108 if (gnss_hal_ != nullptr) {
109 gnss_hal_->cleanup();
110 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700111 if (notify_count_ > 0) {
112 ALOGW("%d unprocessed callbacks discarded", notify_count_);
113 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800114 }
115
116 /* Used as a mechanism to inform the test that a callback has occurred */
117 inline void notify() {
118 std::unique_lock<std::mutex> lock(mtx_);
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700119 notify_count_++;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800120 cv_.notify_one();
121 }
122
123 /* Test code calls this function to wait for a callback */
124 inline std::cv_status wait(int timeoutSeconds) {
125 std::unique_lock<std::mutex> lock(mtx_);
126
127 std::cv_status status = std::cv_status::no_timeout;
128 auto now = std::chrono::system_clock::now();
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700129 while (notify_count_ == 0) {
130 status = cv_.wait_until(lock, now + std::chrono::seconds(timeoutSeconds));
131 if (status == std::cv_status::timeout) return status;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800132 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700133 notify_count_--;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800134 return status;
135 }
136
Wyatt Riley94c7a042017-06-15 17:16:24 -0700137 /*
138 * StartAndGetSingleLocation:
139 * Helper function to get one Location and check fields
140 *
141 * returns true if a location was successfully generated
142 */
143 bool StartAndGetSingleLocation(bool checkAccuracies) {
144 auto result = gnss_hal_->start();
145
146 EXPECT_TRUE(result.isOk());
147 EXPECT_TRUE(result);
148
149 /*
150 * GPS signals initially optional for this test, so don't expect fast fix,
151 * or no timeout, unless signal is present
152 */
153 int firstGnssLocationTimeoutSeconds = sAgpsIsPresent ? 15 : 45;
154 if (sSignalIsWeak) {
155 // allow more time for weak signals
156 firstGnssLocationTimeoutSeconds += 30;
157 }
158
159 wait(firstGnssLocationTimeoutSeconds);
160 if (sAgpsIsPresent) {
161 EXPECT_EQ(location_called_count_, 1);
162 }
163 if (location_called_count_ > 0) {
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700164 // don't require speed on first fix
165 CheckLocation(last_location_, checkAccuracies, false);
Wyatt Riley94c7a042017-06-15 17:16:24 -0700166 return true;
167 }
168 return false;
169 }
170
171 /*
172 * StopAndClearLocations:
173 * Helper function to stop locations
174 *
175 * returns true if a location was successfully generated
176 */
177 void StopAndClearLocations() {
178 auto result = gnss_hal_->stop();
179
180 EXPECT_TRUE(result.isOk());
181 EXPECT_TRUE(result);
182
183 /*
184 * Clear notify/waiting counter, allowing up till the timeout after
185 * the last reply for final startup messages to arrive (esp. system
186 * info.)
187 */
188 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
189 }
190 }
191
192 /*
193 * CheckLocation:
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700194 * Helper function to vet Location fields
Wyatt Riley94c7a042017-06-15 17:16:24 -0700195 */
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700196 void CheckLocation(GnssLocation& location, bool checkAccuracies, bool checkSpeed) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700197 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
198 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700199 if (checkSpeed) {
200 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
201 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700202 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
203 // New uncertainties available in O must be provided,
204 // at least when paired with modern hardware (2017+)
205 if (checkAccuracies) {
206 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700207 if (checkSpeed) {
208 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
209 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
210 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
211 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700212 }
213 }
214 EXPECT_GE(location.latitudeDegrees, -90.0);
215 EXPECT_LE(location.latitudeDegrees, 90.0);
216 EXPECT_GE(location.longitudeDegrees, -180.0);
217 EXPECT_LE(location.longitudeDegrees, 180.0);
218 EXPECT_GE(location.altitudeMeters, -1000.0);
219 EXPECT_LE(location.altitudeMeters, 30000.0);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700220 if (checkSpeed) {
221 EXPECT_GE(location.speedMetersPerSec, 0.0);
222 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
Wyatt Riley94c7a042017-06-15 17:16:24 -0700223
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700224 // Non-zero speeds must be reported with an associated bearing
225 if (location.speedMetersPerSec > 0.0) {
226 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
227 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700228 }
229
230 /*
231 * Tolerating some especially high values for accuracy estimate, in case of
232 * first fix with especially poor geometry (happens occasionally)
233 */
234 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
235 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
236
237 /*
238 * Some devices may define bearing as -180 to +180, others as 0 to 360.
239 * Both are okay & understandable.
240 */
241 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
242 EXPECT_GE(location.bearingDegrees, -180.0);
243 EXPECT_LE(location.bearingDegrees, 360.0);
244 }
245 if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
246 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
247 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
248 }
249 if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
250 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
251 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
252 }
253 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
254 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
255 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
256 }
257
258 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
259 EXPECT_GT(location.timestamp, 1.48e12);
260 }
261
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800262 /* Callback class for data & Event. */
263 class GnssCallback : public IGnssCallback {
Wyatt Riley917640b2017-03-16 16:25:55 -0700264 public:
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800265 GnssHalTest& parent_;
266
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800267 GnssCallback(GnssHalTest& parent) : parent_(parent){};
268
269 virtual ~GnssCallback() = default;
270
271 // Dummy callback handlers
272 Return<void> gnssStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800273 const IGnssCallback::GnssStatusValue /* status */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800274 return Void();
275 }
276 Return<void> gnssSvStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800277 const IGnssCallback::GnssSvStatus& /* svStatus */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800278 return Void();
279 }
280 Return<void> gnssNmeaCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800281 int64_t /* timestamp */,
282 const android::hardware::hidl_string& /* nmea */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800283 return Void();
284 }
285 Return<void> gnssAcquireWakelockCb() override { return Void(); }
286 Return<void> gnssReleaseWakelockCb() override { return Void(); }
287 Return<void> gnssRequestTimeCb() override { return Void(); }
288
289 // Actual (test) callback handlers
290 Return<void> gnssLocationCb(const GnssLocation& location) override {
291 ALOGI("Location received");
292 parent_.location_called_count_++;
293 parent_.last_location_ = location;
294 parent_.notify();
295 return Void();
296 }
297
298 Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override {
299 ALOGI("Capabilities received %d", capabilities);
300 parent_.capabilities_called_count_++;
301 parent_.last_capabilities_ = capabilities;
302 parent_.notify();
303 return Void();
304 }
305
306 Return<void> gnssSetSystemInfoCb(
307 const IGnssCallback::GnssSystemInfo& info) override {
308 ALOGI("Info received, year %d", info.yearOfHw);
309 parent_.info_called_count_++;
310 parent_.last_info_ = info;
311 parent_.notify();
312 return Void();
313 }
314 };
315
316 sp<IGnss> gnss_hal_; // GNSS HAL to call into
317 sp<IGnssCallback> gnss_cb_; // Primary callback interface
318
319 /* Count of calls to set the following items, and the latest item (used by
320 * test.)
321 */
322 int capabilities_called_count_;
323 uint32_t last_capabilities_;
324
325 int location_called_count_;
326 GnssLocation last_location_;
327
328 int info_called_count_;
329 IGnssCallback::GnssSystemInfo last_info_;
330
331 private:
332 std::mutex mtx_;
333 std::condition_variable cv_;
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700334 int notify_count_;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800335};
336
337/*
338 * SetCallbackCapabilitiesCleanup:
339 * Sets up the callback, awaits the capabilities, and calls cleanup
340 *
341 * Since this is just the basic operation of SetUp() and TearDown(),
Wyatt Riley917640b2017-03-16 16:25:55 -0700342 * the function definition is intentionally empty
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800343 */
Dan Shi47e47832019-10-10 11:17:22 -0700344TEST_P(GnssHalTest, SetCallbackCapabilitiesCleanup) {}
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800345
Wyatt Riley917640b2017-03-16 16:25:55 -0700346/*
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800347 * GetLocation:
348 * Turns on location, waits 45 second for at least 5 locations,
349 * and checks them for reasonable validity.
350 */
Dan Shi47e47832019-10-10 11:17:22 -0700351TEST_P(GnssHalTest, GetLocation) {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800352#define MIN_INTERVAL_MSEC 500
353#define PREFERRED_ACCURACY 0 // Ideally perfect (matches GnssLocationProvider)
354#define PREFERRED_TIME_MSEC 0 // Ideally immediate
355
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800356#define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3
357#define LOCATIONS_TO_CHECK 5
358
Wyatt Riley917640b2017-03-16 16:25:55 -0700359 bool checkMoreAccuracies =
360 (info_called_count_ > 0 && last_info_.yearOfHw >= 2017);
361
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800362 auto result = gnss_hal_->setPositionMode(
363 IGnss::GnssPositionMode::MS_BASED,
364 IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, MIN_INTERVAL_MSEC,
365 PREFERRED_ACCURACY, PREFERRED_TIME_MSEC);
366
367 ASSERT_TRUE(result.isOk());
Wyatt Rileyc1399592017-03-22 14:08:26 -0700368 EXPECT_TRUE(result);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800369
Wyatt Rileyc1399592017-03-22 14:08:26 -0700370 /*
371 * GPS signals initially optional for this test, so don't expect no timeout
372 * yet
373 */
Wyatt Riley94c7a042017-06-15 17:16:24 -0700374 bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800375
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700376 if (gotLocation) {
377 for (int i = 1; i < LOCATIONS_TO_CHECK; i++) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700378 EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC));
379 EXPECT_EQ(location_called_count_, i + 1);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700380 CheckLocation(last_location_, checkMoreAccuracies, true);
Wyatt Riley917640b2017-03-16 16:25:55 -0700381 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800382 }
383
Wyatt Riley94c7a042017-06-15 17:16:24 -0700384 StopAndClearLocations();
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800385}
386
Wyatt Rileyc1399592017-03-22 14:08:26 -0700387/*
388 * InjectDelete:
389 * Ensures that calls to inject and/or delete information state are handled.
Wyatt Rileyc1399592017-03-22 14:08:26 -0700390 */
Dan Shi47e47832019-10-10 11:17:22 -0700391TEST_P(GnssHalTest, InjectDelete) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700392 // confidently, well north of Alaska
393 auto result = gnss_hal_->injectLocation(80.0, -170.0, 1000.0);
394
Wyatt Rileyc1399592017-03-22 14:08:26 -0700395 ASSERT_TRUE(result.isOk());
396 EXPECT_TRUE(result);
397
398 // fake time, but generally reasonable values (time in Aug. 2018)
399 result = gnss_hal_->injectTime(1534567890123L, 123456L, 10000L);
400
401 ASSERT_TRUE(result.isOk());
402 EXPECT_TRUE(result);
403
Yu-Han Yang66fb7a12018-07-02 10:41:28 -0700404 auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_POSITION);
405
406 ASSERT_TRUE(resultVoid.isOk());
407
408 resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_TIME);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700409
410 ASSERT_TRUE(resultVoid.isOk());
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700411
412 // Ensure we can get a good location after a bad injection has been deleted
Wyatt Riley94c7a042017-06-15 17:16:24 -0700413 StartAndGetSingleLocation(false);
414
415 StopAndClearLocations();
Wyatt Rileyc1399592017-03-22 14:08:26 -0700416}
417
418/*
Yu-Han Yangb20389e2019-11-19 22:11:11 -0800419 * InjectSeedLocation:
420 * Injects a seed location and ensures the injected seed location is not fused in the resulting
421 * GNSS location.
422 */
423TEST_P(GnssHalTest, InjectSeedLocation) {
424 // An arbitrary position in North Pacific Ocean (where no VTS labs will ever likely be located).
425 const double seedLatDegrees = 32.312894;
426 const double seedLngDegrees = -172.954117;
427 const float seedAccuracyMeters = 150.0;
428
429 auto result = gnss_hal_->injectLocation(seedLatDegrees, seedLngDegrees, seedAccuracyMeters);
430 ASSERT_TRUE(result.isOk());
431 EXPECT_TRUE(result);
432
433 StartAndGetSingleLocation(false);
434
435 // Ensure we don't get a location anywhere within 111km (1 degree of lat or lng) of the seed
436 // location.
437 EXPECT_TRUE(std::abs(last_location_.latitudeDegrees - seedLatDegrees) > 1.0 ||
438 std::abs(last_location_.longitudeDegrees - seedLngDegrees) > 1.0);
439
440 StopAndClearLocations();
441
442 auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_POSITION);
443 ASSERT_TRUE(resultVoid.isOk());
444}
445
446/*
Wyatt Rileyc1399592017-03-22 14:08:26 -0700447 * GetAllExtentions:
448 * Tries getting all optional extensions, and ensures a valid return
449 * null or actual extension, no crash.
450 * Confirms year-based required extensions (Measurement & Debug) are present
451 */
Dan Shi47e47832019-10-10 11:17:22 -0700452TEST_P(GnssHalTest, GetAllExtensions) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700453 // Basic call-is-handled checks
454 auto gnssXtra = gnss_hal_->getExtensionXtra();
455 ASSERT_TRUE(gnssXtra.isOk());
456
457 auto gnssRil = gnss_hal_->getExtensionAGnssRil();
458 ASSERT_TRUE(gnssRil.isOk());
459
460 auto gnssAgnss = gnss_hal_->getExtensionAGnss();
461 ASSERT_TRUE(gnssAgnss.isOk());
462
463 auto gnssNi = gnss_hal_->getExtensionGnssNi();
464 ASSERT_TRUE(gnssNi.isOk());
465
466 auto gnssNavigationMessage = gnss_hal_->getExtensionGnssNavigationMessage();
467 ASSERT_TRUE(gnssNavigationMessage.isOk());
468
469 auto gnssConfiguration = gnss_hal_->getExtensionGnssConfiguration();
470 ASSERT_TRUE(gnssConfiguration.isOk());
471
472 auto gnssGeofencing = gnss_hal_->getExtensionGnssGeofencing();
473 ASSERT_TRUE(gnssGeofencing.isOk());
474
475 auto gnssBatching = gnss_hal_->getExtensionGnssBatching();
476 ASSERT_TRUE(gnssBatching.isOk());
477
478 // Verifying, in some cases, that these return actual extensions
479 auto gnssMeasurement = gnss_hal_->getExtensionGnssMeasurement();
480 ASSERT_TRUE(gnssMeasurement.isOk());
481 if (last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS) {
482 sp<IGnssMeasurement> iGnssMeas = gnssMeasurement;
483 EXPECT_NE(iGnssMeas, nullptr);
484 }
485
486 auto gnssDebug = gnss_hal_->getExtensionGnssDebug();
487 ASSERT_TRUE(gnssDebug.isOk());
Johan Ankner2fd5c7c2019-12-17 10:30:30 +0100488 if (!IsAutomotiveDevice() && info_called_count_ > 0 && last_info_.yearOfHw >= 2017) {
489 sp<IGnssDebug> iGnssDebug = gnssDebug;
490 EXPECT_NE(iGnssDebug, nullptr);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700491 }
492}
493
494/*
495 * MeasurementCapabilities:
496 * Verifies that modern hardware supports measurement capabilities.
497 */
Dan Shi47e47832019-10-10 11:17:22 -0700498TEST_P(GnssHalTest, MeasurementCapabilites) {
Tyler Trephan0d9206a2020-09-28 22:03:18 -0700499 if (!IsAutomotiveDevice() && info_called_count_ > 0 && last_info_.yearOfHw >= 2016) {
500 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS);
501 }
Wyatt Rileyc1399592017-03-22 14:08:26 -0700502}
503
Vishal Agarwal2910e642018-06-05 18:42:01 -0700504/*
505 * SchedulingCapabilities:
506 * Verifies that 2018+ hardware supports Scheduling capabilities.
507 */
Dan Shi47e47832019-10-10 11:17:22 -0700508TEST_P(GnssHalTest, SchedulingCapabilities) {
Vishal Agarwal2910e642018-06-05 18:42:01 -0700509 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2018) {
510 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::SCHEDULING);
511 }
512}
513
Dan Shiba4d5322020-07-28 13:09:30 -0700514GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GnssHalTest);
Dan Shi47e47832019-10-10 11:17:22 -0700515INSTANTIATE_TEST_SUITE_P(
516 PerInstance, GnssHalTest,
517 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IGnss::descriptor)),
518 android::hardware::PrintInstanceNameToString);
519
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800520int main(int argc, char** argv) {
521 ::testing::InitGoogleTest(&argc, argv);
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700522 /*
523 * These arguments not used by automated VTS testing.
524 * Only for use in manual testing, when wanting to run
525 * stronger tests that require the presence of GPS signal.
526 */
527 for (int i = 1; i < argc; i++) {
Zhuoyao Zhang989afba2018-02-08 20:53:56 -0800528 if (strcmp(argv[i], "-agps") == 0) {
529 sAgpsIsPresent = true;
530 } else if (strcmp(argv[i], "-weak") == 0) {
531 sSignalIsWeak = true;
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700532 }
533 }
Dan Shi47e47832019-10-10 11:17:22 -0700534
535 return RUN_ALL_TESTS();
Tyler Trephan0d9206a2020-09-28 22:03:18 -0700536}