blob: 0541c9038cf2451ec8f7873b2bd0fc222bb86dfb [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>
Steven Moreland4e7a3072017-04-06 12:15:23 -070019#include <log/log.h>
Wyatt Riley6c26ed72017-02-21 17:21:53 -080020
Yuexi Maed2bb4e2017-03-10 00:44:45 -080021#include <VtsHalHidlTargetTestBase.h>
Zhuoyao Zhang989afba2018-02-08 20:53:56 -080022#include <VtsHalHidlTargetTestEnvBase.h>
Wyatt Riley6c26ed72017-02-21 17:21:53 -080023
24#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
Zhuoyao Zhang989afba2018-02-08 20:53:56 -080053// Test environment for GNSS HIDL HAL.
54class GnssHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
55 public:
56 // get the test environment singleton
57 static GnssHidlEnvironment* Instance() {
58 static GnssHidlEnvironment* instance = new GnssHidlEnvironment;
59 return instance;
60 }
61
62 virtual void registerTestServices() override { registerTestService<IGnss>(); }
63
64 private:
65 GnssHidlEnvironment() {}
66};
67
Wyatt Riley6c26ed72017-02-21 17:21:53 -080068// The main test class for GNSS HAL.
Yuexi Maed2bb4e2017-03-10 00:44:45 -080069class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase {
Wyatt Riley6c26ed72017-02-21 17:21:53 -080070 public:
71 virtual void SetUp() override {
Wyatt Riley917640b2017-03-16 16:25:55 -070072 // Clean between tests
73 capabilities_called_count_ = 0;
74 location_called_count_ = 0;
75 info_called_count_ = 0;
Wyatt Riley6ec696b2017-06-19 14:42:34 -070076 notify_count_ = 0;
Wyatt Riley6c26ed72017-02-21 17:21:53 -080077
Zhuoyao Zhang989afba2018-02-08 20:53:56 -080078 gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService<IGnss>(
79 GnssHidlEnvironment::Instance()->getServiceName<IGnss>());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080080 ASSERT_NE(gnss_hal_, nullptr);
81
82 gnss_cb_ = new GnssCallback(*this);
83 ASSERT_NE(gnss_cb_, nullptr);
84
85 auto result = gnss_hal_->setCallback(gnss_cb_);
86 if (!result.isOk()) {
Wyatt Riley917640b2017-03-16 16:25:55 -070087 ALOGE("result of failed setCallback %s", result.description().c_str());
Wyatt Riley6c26ed72017-02-21 17:21:53 -080088 }
89
90 ASSERT_TRUE(result.isOk());
91 ASSERT_TRUE(result);
92
Wyatt Riley917640b2017-03-16 16:25:55 -070093 /*
94 * At least one callback should trigger - it may be capabilites, or
95 * system info first, so wait again if capabilities not received.
Wyatt Riley6c26ed72017-02-21 17:21:53 -080096 */
Wyatt Riley917640b2017-03-16 16:25:55 -070097 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
98 if (capabilities_called_count_ == 0) {
99 EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC));
100 }
101
102 /*
103 * Generally should be 1 capabilites callback -
104 * or possibly 2 in some recovery cases (default cached & refreshed)
105 */
106 EXPECT_GE(capabilities_called_count_, 1);
107 EXPECT_LE(capabilities_called_count_, 2);
108
109 /*
110 * Clear notify/waiting counter, allowing up till the timeout after
111 * the last reply for final startup messages to arrive (esp. system
112 * info.)
113 */
114 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
115 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800116 }
117
118 virtual void TearDown() override {
119 if (gnss_hal_ != nullptr) {
120 gnss_hal_->cleanup();
121 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700122 if (notify_count_ > 0) {
123 ALOGW("%d unprocessed callbacks discarded", notify_count_);
124 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800125 }
126
127 /* Used as a mechanism to inform the test that a callback has occurred */
128 inline void notify() {
129 std::unique_lock<std::mutex> lock(mtx_);
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700130 notify_count_++;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800131 cv_.notify_one();
132 }
133
134 /* Test code calls this function to wait for a callback */
135 inline std::cv_status wait(int timeoutSeconds) {
136 std::unique_lock<std::mutex> lock(mtx_);
137
138 std::cv_status status = std::cv_status::no_timeout;
139 auto now = std::chrono::system_clock::now();
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700140 while (notify_count_ == 0) {
141 status = cv_.wait_until(lock, now + std::chrono::seconds(timeoutSeconds));
142 if (status == std::cv_status::timeout) return status;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800143 }
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700144 notify_count_--;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800145 return status;
146 }
147
Wyatt Riley94c7a042017-06-15 17:16:24 -0700148 /*
149 * StartAndGetSingleLocation:
150 * Helper function to get one Location and check fields
151 *
152 * returns true if a location was successfully generated
153 */
154 bool StartAndGetSingleLocation(bool checkAccuracies) {
155 auto result = gnss_hal_->start();
156
157 EXPECT_TRUE(result.isOk());
158 EXPECT_TRUE(result);
159
160 /*
161 * GPS signals initially optional for this test, so don't expect fast fix,
162 * or no timeout, unless signal is present
163 */
164 int firstGnssLocationTimeoutSeconds = sAgpsIsPresent ? 15 : 45;
165 if (sSignalIsWeak) {
166 // allow more time for weak signals
167 firstGnssLocationTimeoutSeconds += 30;
168 }
169
170 wait(firstGnssLocationTimeoutSeconds);
171 if (sAgpsIsPresent) {
172 EXPECT_EQ(location_called_count_, 1);
173 }
174 if (location_called_count_ > 0) {
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700175 // don't require speed on first fix
176 CheckLocation(last_location_, checkAccuracies, false);
Wyatt Riley94c7a042017-06-15 17:16:24 -0700177 return true;
178 }
179 return false;
180 }
181
182 /*
183 * StopAndClearLocations:
184 * Helper function to stop locations
185 *
186 * returns true if a location was successfully generated
187 */
188 void StopAndClearLocations() {
189 auto result = gnss_hal_->stop();
190
191 EXPECT_TRUE(result.isOk());
192 EXPECT_TRUE(result);
193
194 /*
195 * Clear notify/waiting counter, allowing up till the timeout after
196 * the last reply for final startup messages to arrive (esp. system
197 * info.)
198 */
199 while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) {
200 }
201 }
202
203 /*
204 * CheckLocation:
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700205 * Helper function to vet Location fields
Wyatt Riley94c7a042017-06-15 17:16:24 -0700206 */
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700207 void CheckLocation(GnssLocation& location, bool checkAccuracies, bool checkSpeed) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700208 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG);
209 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700210 if (checkSpeed) {
211 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED);
212 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700213 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY);
214 // New uncertainties available in O must be provided,
215 // at least when paired with modern hardware (2017+)
216 if (checkAccuracies) {
217 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700218 if (checkSpeed) {
219 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY);
220 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
221 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY);
222 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700223 }
224 }
225 EXPECT_GE(location.latitudeDegrees, -90.0);
226 EXPECT_LE(location.latitudeDegrees, 90.0);
227 EXPECT_GE(location.longitudeDegrees, -180.0);
228 EXPECT_LE(location.longitudeDegrees, 180.0);
229 EXPECT_GE(location.altitudeMeters, -1000.0);
230 EXPECT_LE(location.altitudeMeters, 30000.0);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700231 if (checkSpeed) {
232 EXPECT_GE(location.speedMetersPerSec, 0.0);
233 EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary.
Wyatt Riley94c7a042017-06-15 17:16:24 -0700234
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700235 // Non-zero speeds must be reported with an associated bearing
236 if (location.speedMetersPerSec > 0.0) {
237 EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING);
238 }
Wyatt Riley94c7a042017-06-15 17:16:24 -0700239 }
240
241 /*
242 * Tolerating some especially high values for accuracy estimate, in case of
243 * first fix with especially poor geometry (happens occasionally)
244 */
245 EXPECT_GT(location.horizontalAccuracyMeters, 0.0);
246 EXPECT_LE(location.horizontalAccuracyMeters, 250.0);
247
248 /*
249 * Some devices may define bearing as -180 to +180, others as 0 to 360.
250 * Both are okay & understandable.
251 */
252 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) {
253 EXPECT_GE(location.bearingDegrees, -180.0);
254 EXPECT_LE(location.bearingDegrees, 360.0);
255 }
256 if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) {
257 EXPECT_GT(location.verticalAccuracyMeters, 0.0);
258 EXPECT_LE(location.verticalAccuracyMeters, 500.0);
259 }
260 if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) {
261 EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0);
262 EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0);
263 }
264 if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) {
265 EXPECT_GT(location.bearingAccuracyDegrees, 0.0);
266 EXPECT_LE(location.bearingAccuracyDegrees, 360.0);
267 }
268
269 // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+)
270 EXPECT_GT(location.timestamp, 1.48e12);
271 }
272
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800273 /* Callback class for data & Event. */
274 class GnssCallback : public IGnssCallback {
Wyatt Riley917640b2017-03-16 16:25:55 -0700275 public:
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800276 GnssHalTest& parent_;
277
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800278 GnssCallback(GnssHalTest& parent) : parent_(parent){};
279
280 virtual ~GnssCallback() = default;
281
282 // Dummy callback handlers
283 Return<void> gnssStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800284 const IGnssCallback::GnssStatusValue /* status */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800285 return Void();
286 }
287 Return<void> gnssSvStatusCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800288 const IGnssCallback::GnssSvStatus& /* svStatus */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800289 return Void();
290 }
291 Return<void> gnssNmeaCb(
Steven Moreland4b523952017-03-08 19:20:30 -0800292 int64_t /* timestamp */,
293 const android::hardware::hidl_string& /* nmea */) override {
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800294 return Void();
295 }
296 Return<void> gnssAcquireWakelockCb() override { return Void(); }
297 Return<void> gnssReleaseWakelockCb() override { return Void(); }
298 Return<void> gnssRequestTimeCb() override { return Void(); }
299
300 // Actual (test) callback handlers
301 Return<void> gnssLocationCb(const GnssLocation& location) override {
302 ALOGI("Location received");
303 parent_.location_called_count_++;
304 parent_.last_location_ = location;
305 parent_.notify();
306 return Void();
307 }
308
309 Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override {
310 ALOGI("Capabilities received %d", capabilities);
311 parent_.capabilities_called_count_++;
312 parent_.last_capabilities_ = capabilities;
313 parent_.notify();
314 return Void();
315 }
316
317 Return<void> gnssSetSystemInfoCb(
318 const IGnssCallback::GnssSystemInfo& info) override {
319 ALOGI("Info received, year %d", info.yearOfHw);
320 parent_.info_called_count_++;
321 parent_.last_info_ = info;
322 parent_.notify();
323 return Void();
324 }
325 };
326
327 sp<IGnss> gnss_hal_; // GNSS HAL to call into
328 sp<IGnssCallback> gnss_cb_; // Primary callback interface
329
330 /* Count of calls to set the following items, and the latest item (used by
331 * test.)
332 */
333 int capabilities_called_count_;
334 uint32_t last_capabilities_;
335
336 int location_called_count_;
337 GnssLocation last_location_;
338
339 int info_called_count_;
340 IGnssCallback::GnssSystemInfo last_info_;
341
342 private:
343 std::mutex mtx_;
344 std::condition_variable cv_;
Wyatt Riley6ec696b2017-06-19 14:42:34 -0700345 int notify_count_;
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800346};
347
348/*
349 * SetCallbackCapabilitiesCleanup:
350 * Sets up the callback, awaits the capabilities, and calls cleanup
351 *
352 * Since this is just the basic operation of SetUp() and TearDown(),
Wyatt Riley917640b2017-03-16 16:25:55 -0700353 * the function definition is intentionally empty
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800354 */
355TEST_F(GnssHalTest, SetCallbackCapabilitiesCleanup) {}
356
Wyatt Riley917640b2017-03-16 16:25:55 -0700357/*
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800358 * GetLocation:
359 * Turns on location, waits 45 second for at least 5 locations,
360 * and checks them for reasonable validity.
361 */
362TEST_F(GnssHalTest, GetLocation) {
363#define MIN_INTERVAL_MSEC 500
364#define PREFERRED_ACCURACY 0 // Ideally perfect (matches GnssLocationProvider)
365#define PREFERRED_TIME_MSEC 0 // Ideally immediate
366
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800367#define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3
368#define LOCATIONS_TO_CHECK 5
369
Wyatt Riley917640b2017-03-16 16:25:55 -0700370 bool checkMoreAccuracies =
371 (info_called_count_ > 0 && last_info_.yearOfHw >= 2017);
372
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800373 auto result = gnss_hal_->setPositionMode(
374 IGnss::GnssPositionMode::MS_BASED,
375 IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, MIN_INTERVAL_MSEC,
376 PREFERRED_ACCURACY, PREFERRED_TIME_MSEC);
377
378 ASSERT_TRUE(result.isOk());
Wyatt Rileyc1399592017-03-22 14:08:26 -0700379 EXPECT_TRUE(result);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800380
Wyatt Rileyc1399592017-03-22 14:08:26 -0700381 /*
382 * GPS signals initially optional for this test, so don't expect no timeout
383 * yet
384 */
Wyatt Riley94c7a042017-06-15 17:16:24 -0700385 bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies);
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800386
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700387 if (gotLocation) {
388 for (int i = 1; i < LOCATIONS_TO_CHECK; i++) {
Wyatt Riley94c7a042017-06-15 17:16:24 -0700389 EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC));
390 EXPECT_EQ(location_called_count_, i + 1);
Wyatt Rileyadca98d2017-10-26 16:37:30 -0700391 CheckLocation(last_location_, checkMoreAccuracies, true);
Wyatt Riley917640b2017-03-16 16:25:55 -0700392 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800393 }
394
Wyatt Riley94c7a042017-06-15 17:16:24 -0700395 StopAndClearLocations();
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800396}
397
Wyatt Rileyc1399592017-03-22 14:08:26 -0700398/*
399 * InjectDelete:
400 * Ensures that calls to inject and/or delete information state are handled.
Wyatt Rileyc1399592017-03-22 14:08:26 -0700401 */
402TEST_F(GnssHalTest, InjectDelete) {
403 // confidently, well north of Alaska
404 auto result = gnss_hal_->injectLocation(80.0, -170.0, 1000.0);
405
Wyatt Rileyc1399592017-03-22 14:08:26 -0700406 ASSERT_TRUE(result.isOk());
407 EXPECT_TRUE(result);
408
409 // fake time, but generally reasonable values (time in Aug. 2018)
410 result = gnss_hal_->injectTime(1534567890123L, 123456L, 10000L);
411
412 ASSERT_TRUE(result.isOk());
413 EXPECT_TRUE(result);
414
Yu-Han Yang66fb7a12018-07-02 10:41:28 -0700415 auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_POSITION);
416
417 ASSERT_TRUE(resultVoid.isOk());
418
419 resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_TIME);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700420
421 ASSERT_TRUE(resultVoid.isOk());
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700422
423 // Ensure we can get a good location after a bad injection has been deleted
Wyatt Riley94c7a042017-06-15 17:16:24 -0700424 StartAndGetSingleLocation(false);
425
426 StopAndClearLocations();
Wyatt Rileyc1399592017-03-22 14:08:26 -0700427}
428
429/*
430 * GetAllExtentions:
431 * Tries getting all optional extensions, and ensures a valid return
432 * null or actual extension, no crash.
433 * Confirms year-based required extensions (Measurement & Debug) are present
434 */
435TEST_F(GnssHalTest, GetAllExtensions) {
436 // Basic call-is-handled checks
437 auto gnssXtra = gnss_hal_->getExtensionXtra();
438 ASSERT_TRUE(gnssXtra.isOk());
439
440 auto gnssRil = gnss_hal_->getExtensionAGnssRil();
441 ASSERT_TRUE(gnssRil.isOk());
442
443 auto gnssAgnss = gnss_hal_->getExtensionAGnss();
444 ASSERT_TRUE(gnssAgnss.isOk());
445
446 auto gnssNi = gnss_hal_->getExtensionGnssNi();
447 ASSERT_TRUE(gnssNi.isOk());
448
449 auto gnssNavigationMessage = gnss_hal_->getExtensionGnssNavigationMessage();
450 ASSERT_TRUE(gnssNavigationMessage.isOk());
451
452 auto gnssConfiguration = gnss_hal_->getExtensionGnssConfiguration();
453 ASSERT_TRUE(gnssConfiguration.isOk());
454
455 auto gnssGeofencing = gnss_hal_->getExtensionGnssGeofencing();
456 ASSERT_TRUE(gnssGeofencing.isOk());
457
458 auto gnssBatching = gnss_hal_->getExtensionGnssBatching();
459 ASSERT_TRUE(gnssBatching.isOk());
460
461 // Verifying, in some cases, that these return actual extensions
462 auto gnssMeasurement = gnss_hal_->getExtensionGnssMeasurement();
463 ASSERT_TRUE(gnssMeasurement.isOk());
464 if (last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS) {
465 sp<IGnssMeasurement> iGnssMeas = gnssMeasurement;
466 EXPECT_NE(iGnssMeas, nullptr);
467 }
468
469 auto gnssDebug = gnss_hal_->getExtensionGnssDebug();
470 ASSERT_TRUE(gnssDebug.isOk());
Johan Ankner2fd5c7c2019-12-17 10:30:30 +0100471 if (!IsAutomotiveDevice() && info_called_count_ > 0 && last_info_.yearOfHw >= 2017) {
472 sp<IGnssDebug> iGnssDebug = gnssDebug;
473 EXPECT_NE(iGnssDebug, nullptr);
Wyatt Rileyc1399592017-03-22 14:08:26 -0700474 }
475}
476
477/*
478 * MeasurementCapabilities:
479 * Verifies that modern hardware supports measurement capabilities.
480 */
481TEST_F(GnssHalTest, MeasurementCapabilites) {
482 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2016) {
483 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS);
484 }
485}
486
Vishal Agarwal2910e642018-06-05 18:42:01 -0700487/*
488 * SchedulingCapabilities:
489 * Verifies that 2018+ hardware supports Scheduling capabilities.
490 */
491TEST_F(GnssHalTest, SchedulingCapabilities) {
492 if (info_called_count_ > 0 && last_info_.yearOfHw >= 2018) {
493 EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::SCHEDULING);
494 }
495}
496
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800497int main(int argc, char** argv) {
Zhuoyao Zhang989afba2018-02-08 20:53:56 -0800498 ::testing::AddGlobalTestEnvironment(GnssHidlEnvironment::Instance());
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800499 ::testing::InitGoogleTest(&argc, argv);
Zhuoyao Zhang989afba2018-02-08 20:53:56 -0800500 GnssHidlEnvironment::Instance()->init(&argc, argv);
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700501 /*
502 * These arguments not used by automated VTS testing.
503 * Only for use in manual testing, when wanting to run
504 * stronger tests that require the presence of GPS signal.
505 */
506 for (int i = 1; i < argc; i++) {
Zhuoyao Zhang989afba2018-02-08 20:53:56 -0800507 if (strcmp(argv[i], "-agps") == 0) {
508 sAgpsIsPresent = true;
509 } else if (strcmp(argv[i], "-weak") == 0) {
510 sSignalIsWeak = true;
Wyatt Riley0ee0cfb2017-04-04 12:34:53 -0700511 }
512 }
Wyatt Riley6c26ed72017-02-21 17:21:53 -0800513 int status = RUN_ALL_TESTS();
514 ALOGI("Test result = %d", status);
515 return status;
Wyatt Riley94c7a042017-06-15 17:16:24 -0700516}