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