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 | |
Johan Ankner | 2fd5c7c | 2019-12-17 10:30:30 +0100 | [diff] [blame^] | 28 | #include <cutils/properties.h> |
| 29 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 30 | using android::hardware::Return; |
| 31 | using android::hardware::Void; |
| 32 | |
| 33 | using android::hardware::gnss::V1_0::GnssLocation; |
| 34 | using android::hardware::gnss::V1_0::GnssLocationFlags; |
| 35 | using android::hardware::gnss::V1_0::IGnss; |
| 36 | using android::hardware::gnss::V1_0::IGnssCallback; |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 37 | using android::hardware::gnss::V1_0::IGnssDebug; |
| 38 | using android::hardware::gnss::V1_0::IGnssMeasurement; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 39 | using android::sp; |
| 40 | |
Johan Ankner | 2fd5c7c | 2019-12-17 10:30:30 +0100 | [diff] [blame^] | 41 | static 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 Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 47 | #define TIMEOUT_SEC 2 // for basic commands/responses |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 48 | |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 49 | // for command line argument on how strictly to run the test |
| 50 | bool sAgpsIsPresent = false; // if SUPL or XTRA assistance available |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 51 | bool sSignalIsWeak = false; // if GNSS signals are weak (e.g. light indoor) |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 52 | |
Zhuoyao Zhang | 989afba | 2018-02-08 20:53:56 -0800 | [diff] [blame] | 53 | // Test environment for GNSS HIDL HAL. |
| 54 | class 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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 68 | // The main test class for GNSS HAL. |
Yuexi Ma | ed2bb4e | 2017-03-10 00:44:45 -0800 | [diff] [blame] | 69 | class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 70 | public: |
| 71 | virtual void SetUp() override { |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 72 | // Clean between tests |
| 73 | capabilities_called_count_ = 0; |
| 74 | location_called_count_ = 0; |
| 75 | info_called_count_ = 0; |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 76 | notify_count_ = 0; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 77 | |
Zhuoyao Zhang | 989afba | 2018-02-08 20:53:56 -0800 | [diff] [blame] | 78 | gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService<IGnss>( |
| 79 | GnssHidlEnvironment::Instance()->getServiceName<IGnss>()); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 80 | 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 Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 87 | ALOGE("result of failed setCallback %s", result.description().c_str()); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | ASSERT_TRUE(result.isOk()); |
| 91 | ASSERT_TRUE(result); |
| 92 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 93 | /* |
| 94 | * At least one callback should trigger - it may be capabilites, or |
| 95 | * system info first, so wait again if capabilities not received. |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 96 | */ |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 97 | 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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | virtual void TearDown() override { |
| 119 | if (gnss_hal_ != nullptr) { |
| 120 | gnss_hal_->cleanup(); |
| 121 | } |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 122 | if (notify_count_ > 0) { |
| 123 | ALOGW("%d unprocessed callbacks discarded", notify_count_); |
| 124 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 125 | } |
| 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 Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 130 | notify_count_++; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 131 | 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 Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 140 | 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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 143 | } |
Wyatt Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 144 | notify_count_--; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 145 | return status; |
| 146 | } |
| 147 | |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 148 | /* |
| 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 Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 175 | // don't require speed on first fix |
| 176 | CheckLocation(last_location_, checkAccuracies, false); |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 177 | 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 Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 205 | * Helper function to vet Location fields |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 206 | */ |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 207 | void CheckLocation(GnssLocation& location, bool checkAccuracies, bool checkSpeed) { |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 208 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_LAT_LONG); |
| 209 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_ALTITUDE); |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 210 | if (checkSpeed) { |
| 211 | EXPECT_TRUE(location.gnssLocationFlags & GnssLocationFlags::HAS_SPEED); |
| 212 | } |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 213 | 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 Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 218 | 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 Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 223 | } |
| 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 Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 231 | if (checkSpeed) { |
| 232 | EXPECT_GE(location.speedMetersPerSec, 0.0); |
| 233 | EXPECT_LE(location.speedMetersPerSec, 5.0); // VTS tests are stationary. |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 234 | |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 235 | // 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 Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 239 | } |
| 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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 273 | /* Callback class for data & Event. */ |
| 274 | class GnssCallback : public IGnssCallback { |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 275 | public: |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 276 | GnssHalTest& parent_; |
| 277 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 278 | GnssCallback(GnssHalTest& parent) : parent_(parent){}; |
| 279 | |
| 280 | virtual ~GnssCallback() = default; |
| 281 | |
| 282 | // Dummy callback handlers |
| 283 | Return<void> gnssStatusCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 284 | const IGnssCallback::GnssStatusValue /* status */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 285 | return Void(); |
| 286 | } |
| 287 | Return<void> gnssSvStatusCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 288 | const IGnssCallback::GnssSvStatus& /* svStatus */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 289 | return Void(); |
| 290 | } |
| 291 | Return<void> gnssNmeaCb( |
Steven Moreland | 4b52395 | 2017-03-08 19:20:30 -0800 | [diff] [blame] | 292 | int64_t /* timestamp */, |
| 293 | const android::hardware::hidl_string& /* nmea */) override { |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 294 | 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 Riley | 6ec696b | 2017-06-19 14:42:34 -0700 | [diff] [blame] | 345 | int notify_count_; |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 346 | }; |
| 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 Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 353 | * the function definition is intentionally empty |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 354 | */ |
| 355 | TEST_F(GnssHalTest, SetCallbackCapabilitiesCleanup) {} |
| 356 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 357 | /* |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 358 | * GetLocation: |
| 359 | * Turns on location, waits 45 second for at least 5 locations, |
| 360 | * and checks them for reasonable validity. |
| 361 | */ |
| 362 | TEST_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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 367 | #define LOCATION_TIMEOUT_SUBSEQUENT_SEC 3 |
| 368 | #define LOCATIONS_TO_CHECK 5 |
| 369 | |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 370 | bool checkMoreAccuracies = |
| 371 | (info_called_count_ > 0 && last_info_.yearOfHw >= 2017); |
| 372 | |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 373 | 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 Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 379 | EXPECT_TRUE(result); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 380 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 381 | /* |
| 382 | * GPS signals initially optional for this test, so don't expect no timeout |
| 383 | * yet |
| 384 | */ |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 385 | bool gotLocation = StartAndGetSingleLocation(checkMoreAccuracies); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 386 | |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 387 | if (gotLocation) { |
| 388 | for (int i = 1; i < LOCATIONS_TO_CHECK; i++) { |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 389 | EXPECT_EQ(std::cv_status::no_timeout, wait(LOCATION_TIMEOUT_SUBSEQUENT_SEC)); |
| 390 | EXPECT_EQ(location_called_count_, i + 1); |
Wyatt Riley | adca98d | 2017-10-26 16:37:30 -0700 | [diff] [blame] | 391 | CheckLocation(last_location_, checkMoreAccuracies, true); |
Wyatt Riley | 917640b | 2017-03-16 16:25:55 -0700 | [diff] [blame] | 392 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 393 | } |
| 394 | |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 395 | StopAndClearLocations(); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 396 | } |
| 397 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 398 | /* |
| 399 | * InjectDelete: |
| 400 | * Ensures that calls to inject and/or delete information state are handled. |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 401 | */ |
| 402 | TEST_F(GnssHalTest, InjectDelete) { |
| 403 | // confidently, well north of Alaska |
| 404 | auto result = gnss_hal_->injectLocation(80.0, -170.0, 1000.0); |
| 405 | |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 406 | 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 Yang | 66fb7a1 | 2018-07-02 10:41:28 -0700 | [diff] [blame] | 415 | 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 Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 420 | |
| 421 | ASSERT_TRUE(resultVoid.isOk()); |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 422 | |
| 423 | // 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] | 424 | StartAndGetSingleLocation(false); |
| 425 | |
| 426 | StopAndClearLocations(); |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 427 | } |
| 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 | */ |
| 435 | TEST_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 Ankner | 2fd5c7c | 2019-12-17 10:30:30 +0100 | [diff] [blame^] | 471 | if (!IsAutomotiveDevice() && info_called_count_ > 0 && last_info_.yearOfHw >= 2017) { |
| 472 | sp<IGnssDebug> iGnssDebug = gnssDebug; |
| 473 | EXPECT_NE(iGnssDebug, nullptr); |
Wyatt Riley | c139959 | 2017-03-22 14:08:26 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | /* |
| 478 | * MeasurementCapabilities: |
| 479 | * Verifies that modern hardware supports measurement capabilities. |
| 480 | */ |
| 481 | TEST_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 Agarwal | 2910e64 | 2018-06-05 18:42:01 -0700 | [diff] [blame] | 487 | /* |
| 488 | * SchedulingCapabilities: |
| 489 | * Verifies that 2018+ hardware supports Scheduling capabilities. |
| 490 | */ |
| 491 | TEST_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 Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 497 | int main(int argc, char** argv) { |
Zhuoyao Zhang | 989afba | 2018-02-08 20:53:56 -0800 | [diff] [blame] | 498 | ::testing::AddGlobalTestEnvironment(GnssHidlEnvironment::Instance()); |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 499 | ::testing::InitGoogleTest(&argc, argv); |
Zhuoyao Zhang | 989afba | 2018-02-08 20:53:56 -0800 | [diff] [blame] | 500 | GnssHidlEnvironment::Instance()->init(&argc, argv); |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 501 | /* |
| 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 Zhang | 989afba | 2018-02-08 20:53:56 -0800 | [diff] [blame] | 507 | if (strcmp(argv[i], "-agps") == 0) { |
| 508 | sAgpsIsPresent = true; |
| 509 | } else if (strcmp(argv[i], "-weak") == 0) { |
| 510 | sSignalIsWeak = true; |
Wyatt Riley | 0ee0cfb | 2017-04-04 12:34:53 -0700 | [diff] [blame] | 511 | } |
| 512 | } |
Wyatt Riley | 6c26ed7 | 2017-02-21 17:21:53 -0800 | [diff] [blame] | 513 | int status = RUN_ALL_TESTS(); |
| 514 | ALOGI("Test result = %d", status); |
| 515 | return status; |
Wyatt Riley | 94c7a04 | 2017-06-15 17:16:24 -0700 | [diff] [blame] | 516 | } |