Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 1 | /* |
| 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 Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
| 20 | #include <hidl/GtestPrinter.h> |
| 21 | #include <hidl/ServiceManagement.h> |
Steven Moreland | 4e7a307 | 2017-04-06 12:15:23 -0700 | [diff] [blame] | 22 | #include <log/log.h> |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 23 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 24 | #include <chrono> |
Yu-Han Yang | b20389e | 2019-11-19 22:11:11 -0800 | [diff] [blame] | 25 | #include <cmath> |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 26 | #include <condition_variable> |
| 27 | #include <mutex> |
| 28 | |
Johan Ankner | 2fd5c7c | 2019-12-17 10:30:30 +0100 | [diff] [blame] | 29 | #include <cutils/properties.h> |
| 30 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 31 | using android::hardware::Return; |
| 32 | using android::hardware::Void; |
| 33 | |
| 34 | using android::hardware::gnss::V1_0::GnssLocation; |
| 35 | using android::hardware::gnss::V1_0::GnssLocationFlags; |
| 36 | using android::hardware::gnss::V1_0::IGnss; |
| 37 | using android::hardware::gnss::V1_0::IGnssCallback; |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 38 | using android::hardware::gnss::V1_0::IGnssDebug; |
| 39 | using android::hardware::gnss::V1_0::IGnssMeasurement; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 40 | using android::sp; |
| 41 | |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 42 | /* |
| 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 Ankner | 2fd5c7c | 2019-12-17 10:30:30 +0100 | [diff] [blame] | 46 | static bool IsAutomotiveDevice() { |
Patrick Berny | 40dcf01 | 2020-01-31 18:29:05 -0800 | [diff] [blame] | 47 | char buffer[PROPERTY_VALUE_MAX] = {0}; |
| 48 | property_get("ro.hardware.type", buffer, ""); |
| 49 | return strncmp(buffer, "automotive", PROPERTY_VALUE_MAX) == 0; |
Johan Ankner | 2fd5c7c | 2019-12-17 10:30:30 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 52 | #define TIMEOUT_SEC 2 // for basic commands/responses |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 53 | |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 54 | // for command line argument on how strictly to run the test |
| 55 | bool sAgpsIsPresent = false; // if SUPL or XTRA assistance available |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 56 | bool sSignalIsWeak = false; // if GNSS signals are weak (e.g. light indoor) |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 57 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 58 | // The main test class for GNSS HAL. |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 59 | class GnssHalTest : public testing::TestWithParam<std::string> { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 60 | public: |
| 61 | virtual void SetUp() override { |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 62 | // Clean between tests |
| 63 | capabilities_called_count_ = 0; |
| 64 | location_called_count_ = 0; |
| 65 | info_called_count_ = 0; |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 66 | notify_count_ = 0; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 67 | |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 68 | gnss_hal_ = IGnss::getService(GetParam()); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 69 | 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 Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 76 | ALOGE("result of failed setCallback %s", result.description().c_str()); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | ASSERT_TRUE(result.isOk()); |
| 80 | ASSERT_TRUE(result); |
| 81 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 82 | /* |
| 83 | * At least one callback should trigger - it may be capabilites, or |
| 84 | * system info first, so wait again if capabilities not received. |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 85 | */ |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 86 | 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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | virtual void TearDown() override { |
| 108 | if (gnss_hal_ != nullptr) { |
| 109 | gnss_hal_->cleanup(); |
| 110 | } |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 111 | if (notify_count_ > 0) { |
| 112 | ALOGW("%d unprocessed callbacks discarded", notify_count_); |
| 113 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 114 | } |
| 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 Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 119 | notify_count_++; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 120 | 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 Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 129 | 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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 132 | } |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 133 | notify_count_--; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 134 | return status; |
| 135 | } |
| 136 | |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 137 | /* |
| 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 Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 164 | // don't require speed on first fix |
| 165 | CheckLocation(last_location_, checkAccuracies, false); |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 166 | 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 Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 194 | * Helper function to vet Location fields |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 195 | */ |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 196 | void CheckLocation(GnssLocation& location, bool checkAccuracies, bool checkSpeed) { |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 197 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG); |
| 198 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE); |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 199 | if (checkSpeed) { |
| 200 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED); |
| 201 | } |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 202 | 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 Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 207 | 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 Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 212 | } |
| 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 Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 220 | if (checkSpeed) { |
| 221 | EXPECT_GE(location.speedMetersPerSec, 0.0); |
| 222 | EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary. |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 223 | |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 224 | // 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 Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 228 | } |
| 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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 262 | /* Callback class for data & Event. */ |
| 263 | class GnssCallback : public IGnssCallback { |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 264 | public: |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 265 | GnssHalTest& parent_; |
| 266 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 267 | GnssCallback(GnssHalTest& parent) : parent_(parent){}; |
| 268 | |
| 269 | virtual ~GnssCallback() = default; |
| 270 | |
| 271 | // Dummy callback handlers |
| 272 | Return<void> gnssStatusCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 273 | const IGnssCallback::GnssStatusValue /* status */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 274 | return Void(); |
| 275 | } |
| 276 | Return<void> gnssSvStatusCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 277 | const IGnssCallback::GnssSvStatus& /* svStatus */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 278 | return Void(); |
| 279 | } |
| 280 | Return<void> gnssNmeaCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 281 | int64_t /* timestamp */, |
| 282 | const android::hardware::hidl_string& /* nmea */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 283 | 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 Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 334 | int notify_count_; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 335 | }; |
| 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 Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 342 | * the function definition is intentionally empty |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 343 | */ |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 344 | TEST_P(GnssHalTest, SetCallbackCapabilitiesCleanup) {} |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 345 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 346 | /* |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 347 | * GetLocation: |
| 348 | * Turns on location, waits 45 second for at least 5 locations, |
| 349 | * and checks them for reasonable validity. |
| 350 | */ |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 351 | TEST_P(GnssHalTest, GetLocation) { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 352 | #define MIN_INTERVAL_MSEC 500 |
| 353 | #define PREFERRED_ACCURACY 0 // Ideally perfect (matches GnssLocationProvider) |
| 354 | #define PREFERRED_TIME_MSEC 0 // Ideally immediate |
| 355 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 356 | #define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3 |
| 357 | #define LOCATIONS_TO_CHECK 5 |
| 358 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 359 | bool checkMoreAccuracies = |
| 360 | (info_called_count_ > 0 && last_info_.yearOfHw >= 2017); |
| 361 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 362 | 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 Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 368 | EXPECT_TRUE(result); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 369 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 370 | /* |
| 371 | * GPS signals initially optional for this test, so don't expect no timeout |
| 372 | * yet |
| 373 | */ |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 374 | bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 375 | |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 376 | if (gotLocation) { |
| 377 | for (int i = 1; i < LOCATIONS_TO_CHECK; i++) { |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 378 | EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC)); |
| 379 | EXPECT_EQ(location_called_count_, i + 1); |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 380 | CheckLocation(last_location_, checkMoreAccuracies, true); |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 381 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 384 | StopAndClearLocations(); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 387 | /* |
| 388 | * InjectDelete: |
| 389 | * Ensures that calls to inject and/or delete information state are handled. |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 390 | */ |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 391 | TEST_P(GnssHalTest, InjectDelete) { |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 392 | // confidently, well north of Alaska |
| 393 | auto result = gnss_hal_->injectLocation(80.0, -170.0, 1000.0); |
| 394 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 395 | 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 Yang | 66fb7a1 | 2018-07-02 10:41:28 -0700 | [diff] [blame] | 404 | 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 Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 409 | |
| 410 | ASSERT_TRUE(resultVoid.isOk()); |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 411 | |
| 412 | // Ensure we can get a good location after a bad injection has been deleted |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 413 | StartAndGetSingleLocation(false); |
| 414 | |
| 415 | StopAndClearLocations(); |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /* |
Yu-Han Yang | b20389e | 2019-11-19 22:11:11 -0800 | [diff] [blame] | 419 | * InjectSeedLocation: |
| 420 | * Injects a seed location and ensures the injected seed location is not fused in the resulting |
| 421 | * GNSS location. |
| 422 | */ |
| 423 | TEST_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 Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 447 | * 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 Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 452 | TEST_P(GnssHalTest, GetAllExtensions) { |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 453 | // 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 Ankner | 2fd5c7c | 2019-12-17 10:30:30 +0100 | [diff] [blame] | 488 | if (!IsAutomotiveDevice() && info_called_count_ > 0 && last_info_.yearOfHw >= 2017) { |
| 489 | sp<IGnssDebug> iGnssDebug = gnssDebug; |
| 490 | EXPECT_NE(iGnssDebug, nullptr); |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * MeasurementCapabilities: |
| 496 | * Verifies that modern hardware supports measurement capabilities. |
| 497 | */ |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 498 | TEST_P(GnssHalTest, MeasurementCapabilites) { |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 499 | if (!IsAutomotiveDevice() && info_called_count_ > 0 && last_info_.yearOfHw >= 2016) { |
| 500 | EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS); |
| 501 | } |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Vishal Agarwal | 2910e64 | 2018-06-05 18:42:01 -0700 | [diff] [blame] | 504 | /* |
| 505 | * SchedulingCapabilities: |
| 506 | * Verifies that 2018+ hardware supports Scheduling capabilities. |
| 507 | */ |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 508 | TEST_P(GnssHalTest, SchedulingCapabilities) { |
Vishal Agarwal | 2910e64 | 2018-06-05 18:42:01 -0700 | [diff] [blame] | 509 | if (info_called_count_ > 0 && last_info_.yearOfHw >= 2018) { |
| 510 | EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::SCHEDULING); |
| 511 | } |
| 512 | } |
| 513 | |
Dan Shi | ba4d532 | 2020-07-28 13:09:30 -0700 | [diff] [blame] | 514 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GnssHalTest); |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 515 | INSTANTIATE_TEST_SUITE_P( |
| 516 | PerInstance, GnssHalTest, |
| 517 | testing::ValuesIn(android::hardware::getAllHalInstanceNames(IGnss::descriptor)), |
| 518 | android::hardware::PrintInstanceNameToString); |
| 519 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 520 | int main(int argc, char** argv) { |
| 521 | ::testing::InitGoogleTest(&argc, argv); |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 522 | /* |
| 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 Zhang | 989afba | 2018-02-08 20:53:56 -0800 | [diff] [blame] | 528 | if (strcmp(argv[i], "-agps") == 0) { |
| 529 | sAgpsIsPresent = true; |
| 530 | } else if (strcmp(argv[i], "-weak") == 0) { |
| 531 | sSignalIsWeak = true; |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 532 | } |
| 533 | } |
Dan Shi | 47e4783 | 2019-10-10 11:17:22 -0700 | [diff] [blame] | 534 | |
| 535 | return RUN_ALL_TESTS(); |
Tyler Trephan | 0d9206a | 2020-09-28 22:03:18 -0700 | [diff] [blame] | 536 | } |