blob: a6c2940fb86128a58b1529620f1507273d4f0cd7 [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>
25#include <condition_variable>
26#include <mutex>
27
Johan Ankner2fd5c7c2019-12-17 10:30:30 +010028#include <cutils/properties.h>
29
Wyatt Riley6c26ed72017-02-21 17:21:53 -080030using android::hardware::Return;
31using android::hardware::Void;
32
33using android::hardware::gnss::V1_0::GnssLocation;
34using android::hardware::gnss::V1_0::GnssLocationFlags;
35using android::hardware::gnss::V1_0::IGnss;
36using android::hardware::gnss::V1_0::IGnssCallback;
Wyatt Rileyc1399592017-03-22 14:08:26 -070037using android::hardware::gnss::V1_0::IGnssDebug;
38using android::hardware::gnss::V1_0::IGnssMeasurement;
Wyatt Riley6c26ed72017-02-21 17:21:53 -080039using android::sp;
40
Johan Ankner2fd5c7c2019-12-17 10:30:30 +010041static bool IsAutomotiveDevice() {
42 char buffer[PROPERTY_VALUE_MAX] = {0};
43 property_get("ro.hardware.type", buffer, "");
44 return strncmp(buffer, "automotive", PROPERTY_VALUE_MAX) == 0;
45}
46
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -070047#define TIMEOUT_SEC 2 // for basic commands/responses
Wyatt Riley6c26ed72017-02-21 17:21:53 -080048
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -070049// for command line argument on how strictly to run the test
50bool sAgpsIsPresent = false; // if SUPL or XTRA assistance available
Wyatt Riley94c7a042017-06-15 17:16:24 -070051bool sSignalIsWeak = false; // if GNSS signals are weak (e.g. light indoor)
Wyatt Rileyc1399592017-03-22 14:08:26 -070052
Wyatt Riley6c26ed72017-02-21 17:21:53 -080053// The main test class for GNSS HAL.
Dan Shi47e47832019-10-10 11:17:22 -070054class GnssHalTest : public testing::TestWithParam<std::string> {
Wyatt Riley6c26ed72017-02-21 17:21:53 -080055 public:
56 virtual void SetUp() override {
Wyatt Riley917640b2017-03-16 16:25:55 -070057 // Clean between tests
58 capabilities_called_count_ = 0;
59 location_called_count_ = 0;
60 info_called_count_ = 0;
Wyatt Riley6ec696b2017-06-19 14:42:34 -070061 notify_count_ = 0;
Wyatt Riley6c26ed72017-02-21 17:21:53 -080062
Dan Shi47e47832019-10-10 11:17:22 -070063 gnss_hal_ = IGnss::getService(GetParam());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080064 ASSERT_NE(gnss_hal_, nullptr);
65
66 gnss_cb_ = new GnssCallback(*this);
67 ASSERT_NE(gnss_cb_, nullptr);
68
69 auto result = gnss_hal_->setCallback(gnss_cb_);
70 if (!result.isOk()) {
Wyatt Riley917640b2017-03-16 16:25:55 -070071 ALOGE("result of failed setCallback %s", result.description().c_str());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080072 }
73
74 ASSERT_TRUE(result.isOk());
75 ASSERT_TRUE(result);
76
Wyatt Riley917640b2017-03-16 16:25:55 -070077 /*
78 * At least one callback should trigger - it may be capabilites, or
79 * system info first, so wait again if capabilities not received.
Wyatt Riley6c26ed72017-02-21 17:21:53 -080080 */
Wyatt Riley917640b2017-03-16 16:25:55 -070081 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
82 if (capabilities_called_count_ == 0) {
83 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
84 }
85
86 /*
87 * Generally should be 1 capabilites callback -
88 * or possibly 2 in some recovery cases (default cached & refreshed)
89 */
90 EXPECT_GE(capabilities_called_count_, 1);
91 EXPECT_LE(capabilities_called_count_, 2);
92
93 /*
94 * Clear notify/waiting counter, allowing up till the timeout after
95 * the last reply for final startup messages to arrive (esp. system
96 * info.)
97 */
98 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
99 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800100 }
101
102 virtual void TearDown() override {
103 if (gnss_hal_ != nullptr) {
104 gnss_hal_->cleanup();
105 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700106 if (notify_count_ > 0) {
107 ALOGW("%d unprocessed callbacks discarded", notify_count_);
108 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800109 }
110
111 /* Used as a mechanism to inform the test that a callback has occurred */
112 inline void notify() {
113 std::unique_lock<std::mutex> lock(mtx_);
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700114 notify_count_++;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800115 cv_.notify_one();
116 }
117
118 /* Test code calls this function to wait for a callback */
119 inline std::cv_status wait(int timeoutSeconds) {
120 std::unique_lock<std::mutex> lock(mtx_);
121
122 std::cv_status status = std::cv_status::no_timeout;
123 auto now = std::chrono::system_clock::now();
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700124 while (notify_count_ == 0) {
125 status = cv_.wait_until(lock, now + std::chrono::seconds(timeoutSeconds));
126 if (status == std::cv_status::timeout) return status;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800127 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700128 notify_count_--;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800129 return status;
130 }
131
Wyatt Riley94c7a042017-06-15 17:16:24 -0700132 /*
133 * StartAndGetSingleLocation:
134 * Helper function to get one Location and check fields
135 *
136 * returns true if a location was successfully generated
137 */
138 bool StartAndGetSingleLocation(bool checkAccuracies) {
139 auto result = gnss_hal_->start();
140
141 EXPECT_TRUE(result.isOk());
142 EXPECT_TRUE(result);
143
144 /*
145 * GPS signals initially optional for this test, so don't expect fast fix,
146 * or no timeout, unless signal is present
147 */
148 int firstGnssLocationTimeoutSeconds = sAgpsIsPresent ? 15 : 45;
149 if (sSignalIsWeak) {
150 // allow more time for weak signals
151 firstGnssLocationTimeoutSeconds += 30;
152 }
153
154 wait(firstGnssLocationTimeoutSeconds);
155 if (sAgpsIsPresent) {
156 EXPECT_EQ(location_called_count_, 1);
157 }
158 if (location_called_count_ > 0) {
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700159 // don't require speed on first fix
160 CheckLocation(last_location_, checkAccuracies, false);
Wyatt Riley94c7a042017-06-15 17:16:24 -0700161 return true;
162 }
163 return false;
164 }
165
166 /*
167 * StopAndClearLocations:
168 * Helper function to stop locations
169 *
170 * returns true if a location was successfully generated
171 */
172 void StopAndClearLocations() {
173 auto result = gnss_hal_->stop();
174
175 EXPECT_TRUE(result.isOk());
176 EXPECT_TRUE(result);
177
178 /*
179 * Clear notify/waiting counter, allowing up till the timeout after
180 * the last reply for final startup messages to arrive (esp. system
181 * info.)
182 */
183 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
184 }
185 }
186
187 /*
188 * CheckLocation:
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700189 * Helper function to vet Location fields
Wyatt Riley94c7a042017-06-15 17:16:24 -0700190 */
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700191 void CheckLocation(GnssLocation& location, bool checkAccuracies, bool checkSpeed) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700192 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
193 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700194 if (checkSpeed) {
195 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
196 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700197 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
198 // New uncertainties available in O must be provided,
199 // at least when paired with modern hardware (2017+)
200 if (checkAccuracies) {
201 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700202 if (checkSpeed) {
203 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
204 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
205 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
206 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700207 }
208 }
209 EXPECT_GE(location.latitudeDegrees, -90.0);
210 EXPECT_LE(location.latitudeDegrees, 90.0);
211 EXPECT_GE(location.longitudeDegrees, -180.0);
212 EXPECT_LE(location.longitudeDegrees, 180.0);
213 EXPECT_GE(location.altitudeMeters, -1000.0);
214 EXPECT_LE(location.altitudeMeters, 30000.0);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700215 if (checkSpeed) {
216 EXPECT_GE(location.speedMetersPerSec, 0.0);
217 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
Wyatt Riley94c7a042017-06-15 17:16:24 -0700218
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700219 // Non-zero speeds must be reported with an associated bearing
220 if (location.speedMetersPerSec > 0.0) {
221 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
222 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700223 }
224
225 /*
226 * Tolerating some especially high values for accuracy estimate, in case of
227 * first fix with especially poor geometry (happens occasionally)
228 */
229 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
230 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
231
232 /*
233 * Some devices may define bearing as -180 to +180, others as 0 to 360.
234 * Both are okay & understandable.
235 */
236 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
237 EXPECT_GE(location.bearingDegrees, -180.0);
238 EXPECT_LE(location.bearingDegrees, 360.0);
239 }
240 if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
241 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
242 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
243 }
244 if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
245 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
246 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
247 }
248 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
249 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
250 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
251 }
252
253 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
254 EXPECT_GT(location.timestamp, 1.48e12);
255 }
256
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800257 /* Callback class for data & Event. */
258 class GnssCallback : public IGnssCallback {
Wyatt Riley917640b2017-03-16 16:25:55 -0700259 public:
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800260 GnssHalTest& parent_;
261
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800262 GnssCallback(GnssHalTest& parent) : parent_(parent){};
263
264 virtual ~GnssCallback() = default;
265
266 // Dummy callback handlers
267 Return<void> gnssStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800268 const IGnssCallback::GnssStatusValue /* status */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800269 return Void();
270 }
271 Return<void> gnssSvStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800272 const IGnssCallback::GnssSvStatus& /* svStatus */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800273 return Void();
274 }
275 Return<void> gnssNmeaCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800276 int64_t /* timestamp */,
277 const android::hardware::hidl_string& /* nmea */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800278 return Void();
279 }
280 Return<void> gnssAcquireWakelockCb() override { return Void(); }
281 Return<void> gnssReleaseWakelockCb() override { return Void(); }
282 Return<void> gnssRequestTimeCb() override { return Void(); }
283
284 // Actual (test) callback handlers
285 Return<void> gnssLocationCb(const GnssLocation& location) override {
286 ALOGI("Location received");
287 parent_.location_called_count_++;
288 parent_.last_location_ = location;
289 parent_.notify();
290 return Void();
291 }
292
293 Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override {
294 ALOGI("Capabilities received %d", capabilities);
295 parent_.capabilities_called_count_++;
296 parent_.last_capabilities_ = capabilities;
297 parent_.notify();
298 return Void();
299 }
300
301 Return<void> gnssSetSystemInfoCb(
302 const IGnssCallback::GnssSystemInfo& info) override {
303 ALOGI("Info received, year %d", info.yearOfHw);
304 parent_.info_called_count_++;
305 parent_.last_info_ = info;
306 parent_.notify();
307 return Void();
308 }
309 };
310
311 sp<IGnss> gnss_hal_; // GNSS HAL to call into
312 sp<IGnssCallback> gnss_cb_; // Primary callback interface
313
314 /* Count of calls to set the following items, and the latest item (used by
315 * test.)
316 */
317 int capabilities_called_count_;
318 uint32_t last_capabilities_;
319
320 int location_called_count_;
321 GnssLocation last_location_;
322
323 int info_called_count_;
324 IGnssCallback::GnssSystemInfo last_info_;
325
326 private:
327 std::mutex mtx_;
328 std::condition_variable cv_;
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700329 int notify_count_;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800330};
331
332/*
333 * SetCallbackCapabilitiesCleanup:
334 * Sets up the callback, awaits the capabilities, and calls cleanup
335 *
336 * Since this is just the basic operation of SetUp() and TearDown(),
Wyatt Riley917640b2017-03-16 16:25:55 -0700337 * the function definition is intentionally empty
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800338 */
Dan Shi47e47832019-10-10 11:17:22 -0700339TEST_P(GnssHalTest, SetCallbackCapabilitiesCleanup) {}
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800340
Wyatt Riley917640b2017-03-16 16:25:55 -0700341/*
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800342 * GetLocation:
343 * Turns on location, waits 45 second for at least 5 locations,
344 * and checks them for reasonable validity.
345 */
Dan Shi47e47832019-10-10 11:17:22 -0700346TEST_P(GnssHalTest, GetLocation) {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800347#define MIN_INTERVAL_MSEC 500
348#define PREFERRED_ACCURACY 0 // Ideally perfect (matches GnssLocationProvider)
349#define PREFERRED_TIME_MSEC 0 // Ideally immediate
350
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800351#define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3
352#define LOCATIONS_TO_CHECK 5
353
Wyatt Riley917640b2017-03-16 16:25:55 -0700354 bool checkMoreAccuracies =
355 (info_called_count_ > 0 && last_info_.yearOfHw >= 2017);
356
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800357 auto result = gnss_hal_->setPositionMode(
358 IGnss::GnssPositionMode::MS_BASED,
359 IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, MIN_INTERVAL_MSEC,
360 PREFERRED_ACCURACY, PREFERRED_TIME_MSEC);
361
362 ASSERT_TRUE(result.isOk());
Wyatt Rileyc1399592017-03-22 14:08:26 -0700363 EXPECT_TRUE(result);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800364
Wyatt Rileyc1399592017-03-22 14:08:26 -0700365 /*
366 * GPS signals initially optional for this test, so don't expect no timeout
367 * yet
368 */
Wyatt Riley94c7a042017-06-15 17:16:24 -0700369 bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800370
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700371 if (gotLocation) {
372 for (int i = 1; i < LOCATIONS_TO_CHECK; i++) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700373 EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC));
374 EXPECT_EQ(location_called_count_, i + 1);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700375 CheckLocation(last_location_, checkMoreAccuracies, true);
Wyatt Riley917640b2017-03-16 16:25:55 -0700376 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800377 }
378
Wyatt Riley94c7a042017-06-15 17:16:24 -0700379 StopAndClearLocations();
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800380}
381
Wyatt Rileyc1399592017-03-22 14:08:26 -0700382/*
383 * InjectDelete:
384 * Ensures that calls to inject and/or delete information state are handled.
Wyatt Rileyc1399592017-03-22 14:08:26 -0700385 */
Dan Shi47e47832019-10-10 11:17:22 -0700386TEST_P(GnssHalTest, InjectDelete) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700387 // confidently, well north of Alaska
388 auto result = gnss_hal_->injectLocation(80.0, -170.0, 1000.0);
389
Wyatt Rileyc1399592017-03-22 14:08:26 -0700390 ASSERT_TRUE(result.isOk());
391 EXPECT_TRUE(result);
392
393 // fake time, but generally reasonable values (time in Aug. 2018)
394 result = gnss_hal_->injectTime(1534567890123L, 123456L, 10000L);
395
396 ASSERT_TRUE(result.isOk());
397 EXPECT_TRUE(result);
398
Yu-Han Yang66fb7a12018-07-02 10:41:28 -0700399 auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_POSITION);
400
401 ASSERT_TRUE(resultVoid.isOk());
402
403 resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_TIME);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700404
405 ASSERT_TRUE(resultVoid.isOk());
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700406
407 // Ensure we can get a good location after a bad injection has been deleted
Wyatt Riley94c7a042017-06-15 17:16:24 -0700408 StartAndGetSingleLocation(false);
409
410 StopAndClearLocations();
Wyatt Rileyc1399592017-03-22 14:08:26 -0700411}
412
413/*
414 * GetAllExtentions:
415 * Tries getting all optional extensions, and ensures a valid return
416 * null or actual extension, no crash.
417 * Confirms year-based required extensions (Measurement & Debug) are present
418 */
Dan Shi47e47832019-10-10 11:17:22 -0700419TEST_P(GnssHalTest, GetAllExtensions) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700420 // Basic call-is-handled checks
421 auto gnssXtra = gnss_hal_->getExtensionXtra();
422 ASSERT_TRUE(gnssXtra.isOk());
423
424 auto gnssRil = gnss_hal_->getExtensionAGnssRil();
425 ASSERT_TRUE(gnssRil.isOk());
426
427 auto gnssAgnss = gnss_hal_->getExtensionAGnss();
428 ASSERT_TRUE(gnssAgnss.isOk());
429
430 auto gnssNi = gnss_hal_->getExtensionGnssNi();
431 ASSERT_TRUE(gnssNi.isOk());
432
433 auto gnssNavigationMessage = gnss_hal_->getExtensionGnssNavigationMessage();
434 ASSERT_TRUE(gnssNavigationMessage.isOk());
435
436 auto gnssConfiguration = gnss_hal_->getExtensionGnssConfiguration();
437 ASSERT_TRUE(gnssConfiguration.isOk());
438
439 auto gnssGeofencing = gnss_hal_->getExtensionGnssGeofencing();
440 ASSERT_TRUE(gnssGeofencing.isOk());
441
442 auto gnssBatching = gnss_hal_->getExtensionGnssBatching();
443 ASSERT_TRUE(gnssBatching.isOk());
444
445 // Verifying, in some cases, that these return actual extensions
446 auto gnssMeasurement = gnss_hal_->getExtensionGnssMeasurement();
447 ASSERT_TRUE(gnssMeasurement.isOk());
448 if (last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS) {
449 sp<IGnssMeasurement> iGnssMeas = gnssMeasurement;
450 EXPECT_NE(iGnssMeas, nullptr);
451 }
452
453 auto gnssDebug = gnss_hal_->getExtensionGnssDebug();
454 ASSERT_TRUE(gnssDebug.isOk());
Johan Ankner2fd5c7c2019-12-17 10:30:30 +0100455 if (!IsAutomotiveDevice() && info_called_count_ > 0 && last_info_.yearOfHw >= 2017) {
456 sp<IGnssDebug> iGnssDebug = gnssDebug;
457 EXPECT_NE(iGnssDebug, nullptr);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700458 }
459}
460
461/*
462 * MeasurementCapabilities:
463 * Verifies that modern hardware supports measurement capabilities.
464 */
Dan Shi47e47832019-10-10 11:17:22 -0700465TEST_P(GnssHalTest, MeasurementCapabilites) {
Wyatt Rileyc1399592017-03-22 14:08:26 -0700466 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2016) {
467 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS);
468 }
469}
470
Vishal Agarwal2910e642018-06-05 18:42:01 -0700471/*
472 * SchedulingCapabilities:
473 * Verifies that 2018+ hardware supports Scheduling capabilities.
474 */
Dan Shi47e47832019-10-10 11:17:22 -0700475TEST_P(GnssHalTest, SchedulingCapabilities) {
Vishal Agarwal2910e642018-06-05 18:42:01 -0700476 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2018) {
477 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::SCHEDULING);
478 }
479}
480
Dan Shiba4d5322020-07-28 13:09:30 -0700481GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GnssHalTest);
Dan Shi47e47832019-10-10 11:17:22 -0700482INSTANTIATE_TEST_SUITE_P(
483 PerInstance, GnssHalTest,
484 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IGnss::descriptor)),
485 android::hardware::PrintInstanceNameToString);
486
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800487int main(int argc, char** argv) {
488 ::testing::InitGoogleTest(&argc, argv);
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700489 /*
490 * These arguments not used by automated VTS testing.
491 * Only for use in manual testing, when wanting to run
492 * stronger tests that require the presence of GPS signal.
493 */
494 for (int i = 1; i < argc; i++) {
Zhuoyao Zhang989afba2018-02-08 20:53:56 -0800495 if (strcmp(argv[i], "-agps") == 0) {
496 sAgpsIsPresent = true;
497 } else if (strcmp(argv[i], "-weak") == 0) {
498 sSignalIsWeak = true;
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700499 }
500 }
Dan Shi47e47832019-10-10 11:17:22 -0700501
502 return RUN_ALL_TESTS();
503}