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> |
Steven Moreland | 4e7a307 | 2017-04-06 12:15:23 -0700 | [diff] [blame] | 19 | #include <log/log.h> |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 20 | |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 21 | #include <VtsHalHidlTargetTestBase.h> |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 22 | |
| 23 | #include <chrono> |
| 24 | #include <condition_variable> |
| 25 | #include <mutex> |
| 26 | |
| 27 | using android::hardware::Return; |
| 28 | using android::hardware::Void; |
| 29 | |
| 30 | using android::hardware::gnss::V1_0::GnssLocation; |
| 31 | using android::hardware::gnss::V1_0::GnssLocationFlags; |
| 32 | using android::hardware::gnss::V1_0::IGnss; |
| 33 | using android::hardware::gnss::V1_0::IGnssCallback; |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 34 | using android::hardware::gnss::V1_0::IGnssDebug; |
| 35 | using android::hardware::gnss::V1_0::IGnssMeasurement; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 36 | using android::sp; |
| 37 | |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 38 | #define TIMEOUT_SEC 2 // for basic commands/responses |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 39 | |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 40 | // for command line argument on how strictly to run the test |
| 41 | bool sAgpsIsPresent = false; // if SUPL or XTRA assistance available |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 42 | bool sSignalIsWeak = false; // if GNSS signals are weak (e.g. light indoor) |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 43 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 44 | // The main test class for GNSS HAL. |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 45 | class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 46 | public: |
| 47 | virtual void SetUp() override { |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 48 | // Clean between tests |
| 49 | capabilities_called_count_ = 0; |
| 50 | location_called_count_ = 0; |
| 51 | info_called_count_ = 0; |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 52 | notify_count_ = 0; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 53 | |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 54 | gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService<IGnss>(); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 55 | ASSERT_NE(gnss_hal_, nullptr); |
| 56 | |
| 57 | gnss_cb_ = new GnssCallback(*this); |
| 58 | ASSERT_NE(gnss_cb_, nullptr); |
| 59 | |
| 60 | auto result = gnss_hal_->setCallback(gnss_cb_); |
| 61 | if (!result.isOk()) { |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 62 | ALOGE("result of failed setCallback %s", result.description().c_str()); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | ASSERT_TRUE(result.isOk()); |
| 66 | ASSERT_TRUE(result); |
| 67 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 68 | /* |
| 69 | * At least one callback should trigger - it may be capabilites, or |
| 70 | * system info first, so wait again if capabilities not received. |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 71 | */ |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 72 | EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC)); |
| 73 | if (capabilities_called_count_ == 0) { |
| 74 | EXPECT_EQ(std::cv_status::no_timeout, wait(TIMEOUT_SEC)); |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Generally should be 1 capabilites callback - |
| 79 | * or possibly 2 in some recovery cases (default cached & refreshed) |
| 80 | */ |
| 81 | EXPECT_GE(capabilities_called_count_, 1); |
| 82 | EXPECT_LE(capabilities_called_count_, 2); |
| 83 | |
| 84 | /* |
| 85 | * Clear notify/waiting counter, allowing up till the timeout after |
| 86 | * the last reply for final startup messages to arrive (esp. system |
| 87 | * info.) |
| 88 | */ |
| 89 | while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) { |
| 90 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | virtual void TearDown() override { |
| 94 | if (gnss_hal_ != nullptr) { |
| 95 | gnss_hal_->cleanup(); |
| 96 | } |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 97 | if (notify_count_ > 0) { |
| 98 | ALOGW("%d unprocessed callbacks discarded", notify_count_); |
| 99 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* Used as a mechanism to inform the test that a callback has occurred */ |
| 103 | inline void notify() { |
| 104 | std::unique_lock<std::mutex> lock(mtx_); |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 105 | notify_count_++; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 106 | cv_.notify_one(); |
| 107 | } |
| 108 | |
| 109 | /* Test code calls this function to wait for a callback */ |
| 110 | inline std::cv_status wait(int timeoutSeconds) { |
| 111 | std::unique_lock<std::mutex> lock(mtx_); |
| 112 | |
| 113 | std::cv_status status = std::cv_status::no_timeout; |
| 114 | auto now = std::chrono::system_clock::now(); |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 115 | while (notify_count_ == 0) { |
| 116 | status = cv_.wait_until(lock, now + std::chrono::seconds(timeoutSeconds)); |
| 117 | if (status == std::cv_status::timeout) return status; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 118 | } |
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 | return status; |
| 121 | } |
| 122 | |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 123 | /* |
| 124 | * StartAndGetSingleLocation: |
| 125 | * Helper function to get one Location and check fields |
| 126 | * |
| 127 | * returns true if a location was successfully generated |
| 128 | */ |
| 129 | bool StartAndGetSingleLocation(bool checkAccuracies) { |
| 130 | auto result = gnss_hal_->start(); |
| 131 | |
| 132 | EXPECT_TRUE(result.isOk()); |
| 133 | EXPECT_TRUE(result); |
| 134 | |
| 135 | /* |
| 136 | * GPS signals initially optional for this test, so don't expect fast fix, |
| 137 | * or no timeout, unless signal is present |
| 138 | */ |
| 139 | int firstGnssLocationTimeoutSeconds = sAgpsIsPresent ? 15 : 45; |
| 140 | if (sSignalIsWeak) { |
| 141 | // allow more time for weak signals |
| 142 | firstGnssLocationTimeoutSeconds += 30; |
| 143 | } |
| 144 | |
| 145 | wait(firstGnssLocationTimeoutSeconds); |
| 146 | if (sAgpsIsPresent) { |
| 147 | EXPECT_EQ(location_called_count_, 1); |
| 148 | } |
| 149 | if (location_called_count_ > 0) { |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame^] | 150 | // don't require speed on first fix |
| 151 | CheckLocation(last_location_, checkAccuracies, false); |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 152 | return true; |
| 153 | } |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * StopAndClearLocations: |
| 159 | * Helper function to stop locations |
| 160 | * |
| 161 | * returns true if a location was successfully generated |
| 162 | */ |
| 163 | void StopAndClearLocations() { |
| 164 | auto result = gnss_hal_->stop(); |
| 165 | |
| 166 | EXPECT_TRUE(result.isOk()); |
| 167 | EXPECT_TRUE(result); |
| 168 | |
| 169 | /* |
| 170 | * Clear notify/waiting counter, allowing up till the timeout after |
| 171 | * the last reply for final startup messages to arrive (esp. system |
| 172 | * info.) |
| 173 | */ |
| 174 | while (wait(TIMEOUT_SEC) == std::cv_status::no_timeout) { |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * CheckLocation: |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame^] | 180 | * Helper function to vet Location fields |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 181 | */ |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame^] | 182 | void CheckLocation(GnssLocation& location, bool checkAccuracies, bool checkSpeed) { |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 183 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG); |
| 184 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE); |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame^] | 185 | if (checkSpeed) { |
| 186 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED); |
| 187 | } |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 188 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_HORIZONTAL_ACCURACY); |
| 189 | // New uncertainties available in O must be provided, |
| 190 | // at least when paired with modern hardware (2017+) |
| 191 | if (checkAccuracies) { |
| 192 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY); |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame^] | 193 | if (checkSpeed) { |
| 194 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY); |
| 195 | if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) { |
| 196 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY); |
| 197 | } |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | EXPECT_GE(location.latitudeDegrees, -90.0); |
| 201 | EXPECT_LE(location.latitudeDegrees, 90.0); |
| 202 | EXPECT_GE(location.longitudeDegrees, -180.0); |
| 203 | EXPECT_LE(location.longitudeDegrees, 180.0); |
| 204 | EXPECT_GE(location.altitudeMeters, -1000.0); |
| 205 | EXPECT_LE(location.altitudeMeters, 30000.0); |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame^] | 206 | if (checkSpeed) { |
| 207 | EXPECT_GE(location.speedMetersPerSec, 0.0); |
| 208 | EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary. |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 209 | |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame^] | 210 | // Non-zero speeds must be reported with an associated bearing |
| 211 | if (location.speedMetersPerSec > 0.0) { |
| 212 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING); |
| 213 | } |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Tolerating some especially high values for accuracy estimate, in case of |
| 218 | * first fix with especially poor geometry (happens occasionally) |
| 219 | */ |
| 220 | EXPECT_GT(location.horizontalAccuracyMeters, 0.0); |
| 221 | EXPECT_LE(location.horizontalAccuracyMeters, 250.0); |
| 222 | |
| 223 | /* |
| 224 | * Some devices may define bearing as -180 to +180, others as 0 to 360. |
| 225 | * Both are okay & understandable. |
| 226 | */ |
| 227 | if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING) { |
| 228 | EXPECT_GE(location.bearingDegrees, -180.0); |
| 229 | EXPECT_LE(location.bearingDegrees, 360.0); |
| 230 | } |
| 231 | if (location.gnssLocationFlags & GnssLocationFlags::HAS_VERTICAL_ACCURACY) { |
| 232 | EXPECT_GT(location.verticalAccuracyMeters, 0.0); |
| 233 | EXPECT_LE(location.verticalAccuracyMeters, 500.0); |
| 234 | } |
| 235 | if (location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED_ACCURACY) { |
| 236 | EXPECT_GT(location.speedAccuracyMetersPerSecond, 0.0); |
| 237 | EXPECT_LE(location.speedAccuracyMetersPerSecond, 50.0); |
| 238 | } |
| 239 | if (location.gnssLocationFlags & GnssLocationFlags::HAS_BEARING_ACCURACY) { |
| 240 | EXPECT_GT(location.bearingAccuracyDegrees, 0.0); |
| 241 | EXPECT_LE(location.bearingAccuracyDegrees, 360.0); |
| 242 | } |
| 243 | |
| 244 | // Check timestamp > 1.48e12 (47 years in msec - 1970->2017+) |
| 245 | EXPECT_GT(location.timestamp, 1.48e12); |
| 246 | } |
| 247 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 248 | /* Callback class for data & Event. */ |
| 249 | class GnssCallback : public IGnssCallback { |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 250 | public: |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 251 | GnssHalTest& parent_; |
| 252 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 253 | GnssCallback(GnssHalTest& parent) : parent_(parent){}; |
| 254 | |
| 255 | virtual ~GnssCallback() = default; |
| 256 | |
| 257 | // Dummy callback handlers |
| 258 | Return<void> gnssStatusCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 259 | const IGnssCallback::GnssStatusValue /* status */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 260 | return Void(); |
| 261 | } |
| 262 | Return<void> gnssSvStatusCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 263 | const IGnssCallback::GnssSvStatus& /* svStatus */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 264 | return Void(); |
| 265 | } |
| 266 | Return<void> gnssNmeaCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 267 | int64_t /* timestamp */, |
| 268 | const android::hardware::hidl_string& /* nmea */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 269 | return Void(); |
| 270 | } |
| 271 | Return<void> gnssAcquireWakelockCb() override { return Void(); } |
| 272 | Return<void> gnssReleaseWakelockCb() override { return Void(); } |
| 273 | Return<void> gnssRequestTimeCb() override { return Void(); } |
| 274 | |
| 275 | // Actual (test) callback handlers |
| 276 | Return<void> gnssLocationCb(const GnssLocation& location) override { |
| 277 | ALOGI("Location received"); |
| 278 | parent_.location_called_count_++; |
| 279 | parent_.last_location_ = location; |
| 280 | parent_.notify(); |
| 281 | return Void(); |
| 282 | } |
| 283 | |
| 284 | Return<void> gnssSetCapabilitesCb(uint32_t capabilities) override { |
| 285 | ALOGI("Capabilities received %d", capabilities); |
| 286 | parent_.capabilities_called_count_++; |
| 287 | parent_.last_capabilities_ = capabilities; |
| 288 | parent_.notify(); |
| 289 | return Void(); |
| 290 | } |
| 291 | |
| 292 | Return<void> gnssSetSystemInfoCb( |
| 293 | const IGnssCallback::GnssSystemInfo& info) override { |
| 294 | ALOGI("Info received, year %d", info.yearOfHw); |
| 295 | parent_.info_called_count_++; |
| 296 | parent_.last_info_ = info; |
| 297 | parent_.notify(); |
| 298 | return Void(); |
| 299 | } |
| 300 | }; |
| 301 | |
| 302 | sp<IGnss> gnss_hal_; // GNSS HAL to call into |
| 303 | sp<IGnssCallback> gnss_cb_; // Primary callback interface |
| 304 | |
| 305 | /* Count of calls to set the following items, and the latest item (used by |
| 306 | * test.) |
| 307 | */ |
| 308 | int capabilities_called_count_; |
| 309 | uint32_t last_capabilities_; |
| 310 | |
| 311 | int location_called_count_; |
| 312 | GnssLocation last_location_; |
| 313 | |
| 314 | int info_called_count_; |
| 315 | IGnssCallback::GnssSystemInfo last_info_; |
| 316 | |
| 317 | private: |
| 318 | std::mutex mtx_; |
| 319 | std::condition_variable cv_; |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 320 | int notify_count_; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | /* |
| 324 | * SetCallbackCapabilitiesCleanup: |
| 325 | * Sets up the callback, awaits the capabilities, and calls cleanup |
| 326 | * |
| 327 | * Since this is just the basic operation of SetUp() and TearDown(), |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 328 | * the function definition is intentionally empty |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 329 | */ |
| 330 | TEST_F(GnssHalTest, SetCallbackCapabilitiesCleanup) {} |
| 331 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 332 | /* |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 333 | * GetLocation: |
| 334 | * Turns on location, waits 45 second for at least 5 locations, |
| 335 | * and checks them for reasonable validity. |
| 336 | */ |
| 337 | TEST_F(GnssHalTest, GetLocation) { |
| 338 | #define MIN_INTERVAL_MSEC 500 |
| 339 | #define PREFERRED_ACCURACY 0 // Ideally perfect (matches GnssLocationProvider) |
| 340 | #define PREFERRED_TIME_MSEC 0 // Ideally immediate |
| 341 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 342 | #define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3 |
| 343 | #define LOCATIONS_TO_CHECK 5 |
| 344 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 345 | bool checkMoreAccuracies = |
| 346 | (info_called_count_ > 0 && last_info_.yearOfHw >= 2017); |
| 347 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 348 | auto result = gnss_hal_->setPositionMode( |
| 349 | IGnss::GnssPositionMode::MS_BASED, |
| 350 | IGnss::GnssPositionRecurrence::RECURRENCE_PERIODIC, MIN_INTERVAL_MSEC, |
| 351 | PREFERRED_ACCURACY, PREFERRED_TIME_MSEC); |
| 352 | |
| 353 | ASSERT_TRUE(result.isOk()); |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 354 | EXPECT_TRUE(result); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 355 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 356 | /* |
| 357 | * GPS signals initially optional for this test, so don't expect no timeout |
| 358 | * yet |
| 359 | */ |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 360 | bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 361 | |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 362 | if (gotLocation) { |
| 363 | for (int i = 1; i < LOCATIONS_TO_CHECK; i++) { |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 364 | EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC)); |
| 365 | EXPECT_EQ(location_called_count_, i + 1); |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame^] | 366 | CheckLocation(last_location_, checkMoreAccuracies, true); |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 367 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 370 | StopAndClearLocations(); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 373 | /* |
| 374 | * InjectDelete: |
| 375 | * Ensures that calls to inject and/or delete information state are handled. |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 376 | */ |
| 377 | TEST_F(GnssHalTest, InjectDelete) { |
| 378 | // confidently, well north of Alaska |
| 379 | auto result = gnss_hal_->injectLocation(80.0, -170.0, 1000.0); |
| 380 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 381 | ASSERT_TRUE(result.isOk()); |
| 382 | EXPECT_TRUE(result); |
| 383 | |
| 384 | // fake time, but generally reasonable values (time in Aug. 2018) |
| 385 | result = gnss_hal_->injectTime(1534567890123L, 123456L, 10000L); |
| 386 | |
| 387 | ASSERT_TRUE(result.isOk()); |
| 388 | EXPECT_TRUE(result); |
| 389 | |
| 390 | auto resultVoid = gnss_hal_->deleteAidingData(IGnss::GnssAidingData::DELETE_ALL); |
| 391 | |
| 392 | ASSERT_TRUE(resultVoid.isOk()); |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 393 | |
| 394 | // 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] | 395 | StartAndGetSingleLocation(false); |
| 396 | |
| 397 | StopAndClearLocations(); |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /* |
| 401 | * GetAllExtentions: |
| 402 | * Tries getting all optional extensions, and ensures a valid return |
| 403 | * null or actual extension, no crash. |
| 404 | * Confirms year-based required extensions (Measurement & Debug) are present |
| 405 | */ |
| 406 | TEST_F(GnssHalTest, GetAllExtensions) { |
| 407 | // Basic call-is-handled checks |
| 408 | auto gnssXtra = gnss_hal_->getExtensionXtra(); |
| 409 | ASSERT_TRUE(gnssXtra.isOk()); |
| 410 | |
| 411 | auto gnssRil = gnss_hal_->getExtensionAGnssRil(); |
| 412 | ASSERT_TRUE(gnssRil.isOk()); |
| 413 | |
| 414 | auto gnssAgnss = gnss_hal_->getExtensionAGnss(); |
| 415 | ASSERT_TRUE(gnssAgnss.isOk()); |
| 416 | |
| 417 | auto gnssNi = gnss_hal_->getExtensionGnssNi(); |
| 418 | ASSERT_TRUE(gnssNi.isOk()); |
| 419 | |
| 420 | auto gnssNavigationMessage = gnss_hal_->getExtensionGnssNavigationMessage(); |
| 421 | ASSERT_TRUE(gnssNavigationMessage.isOk()); |
| 422 | |
| 423 | auto gnssConfiguration = gnss_hal_->getExtensionGnssConfiguration(); |
| 424 | ASSERT_TRUE(gnssConfiguration.isOk()); |
| 425 | |
| 426 | auto gnssGeofencing = gnss_hal_->getExtensionGnssGeofencing(); |
| 427 | ASSERT_TRUE(gnssGeofencing.isOk()); |
| 428 | |
| 429 | auto gnssBatching = gnss_hal_->getExtensionGnssBatching(); |
| 430 | ASSERT_TRUE(gnssBatching.isOk()); |
| 431 | |
| 432 | // Verifying, in some cases, that these return actual extensions |
| 433 | auto gnssMeasurement = gnss_hal_->getExtensionGnssMeasurement(); |
| 434 | ASSERT_TRUE(gnssMeasurement.isOk()); |
| 435 | if (last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS) { |
| 436 | sp<IGnssMeasurement> iGnssMeas = gnssMeasurement; |
| 437 | EXPECT_NE(iGnssMeas, nullptr); |
| 438 | } |
| 439 | |
| 440 | auto gnssDebug = gnss_hal_->getExtensionGnssDebug(); |
| 441 | ASSERT_TRUE(gnssDebug.isOk()); |
| 442 | if (info_called_count_ > 0 && last_info_.yearOfHw >= 2017) { |
| 443 | sp<IGnssDebug> iGnssDebug = gnssDebug; |
| 444 | EXPECT_NE(iGnssDebug, nullptr); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | /* |
| 449 | * MeasurementCapabilities: |
| 450 | * Verifies that modern hardware supports measurement capabilities. |
| 451 | */ |
| 452 | TEST_F(GnssHalTest, MeasurementCapabilites) { |
| 453 | if (info_called_count_ > 0 && last_info_.yearOfHw >= 2016) { |
| 454 | EXPECT_TRUE(last_capabilities_ & IGnssCallback::Capabilities::MEASUREMENTS); |
| 455 | } |
| 456 | } |
| 457 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 458 | int main(int argc, char** argv) { |
| 459 | ::testing::InitGoogleTest(&argc, argv); |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 460 | /* |
| 461 | * These arguments not used by automated VTS testing. |
| 462 | * Only for use in manual testing, when wanting to run |
| 463 | * stronger tests that require the presence of GPS signal. |
| 464 | */ |
| 465 | for (int i = 1; i < argc; i++) { |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 466 | if (strcmp(argv[i], "-agps") == 0) { |
| 467 | sAgpsIsPresent = true; |
| 468 | } else if (strcmp(argv[i], "-weak") == 0) { |
| 469 | sSignalIsWeak = true; |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 472 | int status = RUN_ALL_TESTS(); |
| 473 | ALOGI("Test result = %d", status); |
| 474 | return status; |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 475 | } |