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