2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "sensors_hidl_hal_test"
18 #include <android-base/logging.h>
19 #include <android/hardware/sensors/1.0/ISensors.h>
20 #include <android/hardware/sensors/1.0/types.h>
21 #include <android/log.h>
22 #include <cutils/ashmem.h>
23 #include <utils/SystemClock.h>
24 #include <VtsHalHidlTargetTestBase.h>
25 #include <hardware/sensors.h> // for sensor type strings
33 #include <unordered_set>
39 using ::android::hardware::Return;
40 using ::android::hardware::Void;
41 using ::android::hardware::hidl_string;
43 using namespace ::android::hardware::sensors::V1_0;
45 // Test environment for sensors
46 class SensorsHidlTest;
47 class SensorsHidlEnvironment : public ::testing::Environment {
49 // get the test environment singleton
50 static SensorsHidlEnvironment* Instance() {
51 static SensorsHidlEnvironment* instance = new SensorsHidlEnvironment;
56 virtual void TearDown();
58 // Get and clear all events collected so far (like "cat" shell command).
59 // If output is nullptr, it clears all collected events.
60 void catEvents(std::vector<Event>* output);
62 // set sensor event collection status
63 void setCollection(bool enable);
66 friend SensorsHidlTest;
67 // sensors hidl service
70 SensorsHidlEnvironment() {}
72 void addEvent(const Event& ev);
73 void startPollingThread();
75 static void pollingThread(SensorsHidlEnvironment* env, std::shared_ptr<bool> stop);
77 bool collectionEnabled;
78 std::shared_ptr<bool> stopThread;
79 std::thread pollThread;
80 std::vector<Event> events;
81 std::mutex events_mutex;
83 GTEST_DISALLOW_COPY_AND_ASSIGN_(SensorsHidlEnvironment);
86 void SensorsHidlEnvironment::SetUp() {
89 ASSERT_NE(sensors, nullptr) << "sensors is nullptr, cannot get hidl service";
91 collectionEnabled = false;
94 // In case framework just stopped for test and there is sensor events in the pipe,
95 // wait some time for those events to be cleared to avoid them messing up the test.
96 std::this_thread::sleep_for(std::chrono::seconds(3));
99 void SensorsHidlEnvironment::TearDown() {
106 void SensorsHidlEnvironment::resetHal() {
107 // wait upto 100ms * 10 = 1s for hidl service.
108 constexpr auto RETRY_DELAY = std::chrono::milliseconds(100);
111 bool succeed = false;
112 for (size_t retry = 10; retry > 0; --retry) {
113 // this do ... while is for easy error handling
115 step = "getService()";
116 sensors = ISensors::getService();
117 if (sensors == nullptr) {
121 step = "poll() check";
122 // Poke ISensor service. If it has lingering connection from previous generation of
123 // system server, it will kill itself. There is no intention to handle the poll result,
124 // which will be done since the size is 0.
125 if(!sensors->poll(0, [](auto, const auto &, const auto &) {}).isOk()) {
129 step = "getSensorList";
130 std::vector<SensorInfo> sensorList;
131 if (!sensors->getSensorsList(
132 [&] (const ::android::hardware::hidl_vec<SensorInfo> &list) {
133 sensorList.reserve(list.size());
134 for (size_t i = 0; i < list.size(); ++i) {
135 sensorList.push_back(list[i]);
141 // stop each sensor individually
142 step = "stop each sensor";
144 for (const auto &i : sensorList) {
145 if (!sensors->activate(i.sensorHandle, false).isOk()) {
163 // Delay 100ms before retry, hidl service is expected to come up in short time after crash.
164 ALOGI("%s unsuccessful, try again soon (remaining retry %zu).", step.c_str(), retry - 1);
165 std::this_thread::sleep_for(RETRY_DELAY);
171 void SensorsHidlEnvironment::catEvents(std::vector<Event>* output) {
172 std::lock_guard<std::mutex> lock(events_mutex);
174 output->insert(output->end(), events.begin(), events.end());
179 void SensorsHidlEnvironment::setCollection(bool enable) {
180 std::lock_guard<std::mutex> lock(events_mutex);
181 collectionEnabled = enable;
184 void SensorsHidlEnvironment::addEvent(const Event& ev) {
185 std::lock_guard<std::mutex> lock(events_mutex);
186 if (collectionEnabled) {
187 events.push_back(ev);
191 void SensorsHidlEnvironment::startPollingThread() {
192 stopThread = std::shared_ptr<bool>(new bool(false));
193 pollThread = std::thread(pollingThread, this, stopThread);
197 void SensorsHidlEnvironment::pollingThread(
198 SensorsHidlEnvironment* env, std::shared_ptr<bool> stop) {
199 ALOGD("polling thread start");
200 bool needExit = *stop;
203 env->sensors->poll(1,
204 [&](auto result, const auto &events, const auto &dynamicSensorsAdded) {
205 if (result != Result::OK
206 || (events.size() == 0 && dynamicSensorsAdded.size() == 0)
212 if (events.size() > 0) {
213 env->addEvent(events[0]);
217 ALOGD("polling thread end");
220 class SensorsTestSharedMemory {
222 static SensorsTestSharedMemory* create(SharedMemType type, size_t size);
223 SharedMemInfo getSharedMemInfo() const;
224 char * getBuffer() const;
225 std::vector<Event> parseEvents(int64_t lastCounter = -1, size_t offset = 0) const;
226 virtual ~SensorsTestSharedMemory();
228 SensorsTestSharedMemory(SharedMemType type, size_t size);
231 native_handle_t* mNativeHandle;
235 DISALLOW_COPY_AND_ASSIGN(SensorsTestSharedMemory);
238 SharedMemInfo SensorsTestSharedMemory::getSharedMemInfo() const {
239 SharedMemInfo mem = {
241 .format = SharedMemFormat::SENSORS_EVENT,
242 .size = static_cast<uint32_t>(mSize),
243 .memoryHandle = mNativeHandle
248 char * SensorsTestSharedMemory::getBuffer() const {
252 std::vector<Event> SensorsTestSharedMemory::parseEvents(int64_t lastCounter, size_t offset) const {
254 constexpr size_t kEventSize = static_cast<size_t>(SensorsEventFormatOffset::TOTAL_LENGTH);
255 constexpr size_t kOffsetSize = static_cast<size_t>(SensorsEventFormatOffset::SIZE_FIELD);
256 constexpr size_t kOffsetToken = static_cast<size_t>(SensorsEventFormatOffset::REPORT_TOKEN);
257 constexpr size_t kOffsetType = static_cast<size_t>(SensorsEventFormatOffset::SENSOR_TYPE);
258 constexpr size_t kOffsetAtomicCounter =
259 static_cast<size_t>(SensorsEventFormatOffset::ATOMIC_COUNTER);
260 constexpr size_t kOffsetTimestamp = static_cast<size_t>(SensorsEventFormatOffset::TIMESTAMP);
261 constexpr size_t kOffsetData = static_cast<size_t>(SensorsEventFormatOffset::DATA);
263 std::vector<Event> events;
264 std::vector<float> data(16);
266 while (offset + kEventSize <= mSize) {
267 int64_t atomicCounter = *reinterpret_cast<uint32_t *>(mBuffer + offset + kOffsetAtomicCounter);
268 if (atomicCounter <= lastCounter) {
272 int32_t size = *reinterpret_cast<int32_t *>(mBuffer + offset + kOffsetSize);
273 if (size != kEventSize) {
274 // unknown error, events parsed may be wrong, remove all
279 int32_t token = *reinterpret_cast<int32_t *>(mBuffer + offset + kOffsetToken);
280 int32_t type = *reinterpret_cast<int32_t *>(mBuffer + offset + kOffsetType);
281 int64_t timestamp = *reinterpret_cast<int64_t *>(mBuffer + offset + kOffsetTimestamp);
283 ALOGV("offset = %zu, cnt %" PRId64 ", token %" PRId32 ", type %" PRId32 ", timestamp %" PRId64,
284 offset, atomicCounter, token, type, timestamp);
287 .timestamp = timestamp,
288 .sensorHandle = token,
289 .sensorType = static_cast<SensorType>(type),
291 event.u.data = android::hardware::hidl_array<float, 16>
292 (reinterpret_cast<float*>(mBuffer + offset + kOffsetData));
294 events.push_back(event);
296 lastCounter = atomicCounter;
297 offset += kEventSize;
303 SensorsTestSharedMemory::SensorsTestSharedMemory(SharedMemType type, size_t size)
304 : mType(type), mSize(0), mBuffer(nullptr) {
305 native_handle_t *handle = nullptr;
306 char *buffer = nullptr;
308 case SharedMemType::ASHMEM: {
310 handle = ::native_handle_create(1 /*nFds*/, 0/*nInts*/);
311 if (handle != nullptr) {
312 handle->data[0] = fd = ::ashmem_create_region("SensorsTestSharedMemory", size);
313 if (handle->data[0] > 0) {
314 // memory is pinned by default
315 buffer = static_cast<char *>
316 (::mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
317 if (buffer != reinterpret_cast<char*>(MAP_FAILED)) {
320 ::native_handle_close(handle);
322 ::native_handle_delete(handle);
327 case SharedMemType::GRALLOC: {
335 if (buffer != nullptr) {
336 mNativeHandle = handle;
342 SensorsTestSharedMemory::~SensorsTestSharedMemory() {
344 case SharedMemType::ASHMEM: {
346 ::munmap(mBuffer, mSize);
349 ::native_handle_close(mNativeHandle);
350 ::native_handle_delete(mNativeHandle);
352 mNativeHandle = nullptr;
358 if (mNativeHandle != nullptr || mSize != 0 || mBuffer != nullptr) {
359 ALOGE("SensorsTestSharedMemory %p not properly destructed: "
360 "type %d, native handle %p, size %zu, buffer %p",
361 this, static_cast<int>(mType), mNativeHandle, mSize, mBuffer);
368 SensorsTestSharedMemory* SensorsTestSharedMemory::create(SharedMemType type, size_t size) {
369 constexpr size_t kMaxSize = 128*1024*1024; // sensor test should not need more than 128M
370 if (size == 0 || size >= kMaxSize) {
374 auto m = new SensorsTestSharedMemory(type, size);
375 if (m->mSize != size || m->mBuffer == nullptr) {
382 class SensorEventsChecker {
384 virtual bool check(const std::vector<Event> &events, std::string *out) const = 0;
385 virtual ~SensorEventsChecker() {}
388 class NullChecker : public SensorEventsChecker {
390 virtual bool check(const std::vector<Event> &, std::string *) const {
395 class SensorEventPerEventChecker : public SensorEventsChecker {
397 virtual bool checkEvent(const Event &event, std::string *out) const = 0;
398 virtual bool check(const std::vector<Event> &events, std::string *out) const {
399 for (const auto &e : events) {
400 if (!checkEvent(e, out)) {
408 class Vec3NormChecker : public SensorEventPerEventChecker {
410 Vec3NormChecker(float min, float max) : mRange(min, max) {}
411 static Vec3NormChecker byNominal(float nominal, float allowedError) {
412 return Vec3NormChecker(nominal - allowedError, nominal + allowedError);
415 virtual bool checkEvent(const Event &event, std::string *out) const {
416 Vec3 v = event.u.vec3;
417 float norm = std::sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
418 if (norm < mRange.first || norm > mRange.second) {
419 if (out != nullptr) {
420 std::ostringstream ss;
421 ss << "Event @ " << event.timestamp << " (" << v.x << ", " << v.y << ", " << v.z << ")"
422 << " has norm " << norm << ", which is beyond range"
423 << " [" << mRange.first << ", " << mRange.second << "]";
431 std::pair<float, float> mRange;
434 // The main test class for SENSORS HIDL HAL.
435 class SensorsHidlTest : public ::testing::VtsHalHidlTargetTestBase {
437 virtual void SetUp() override {
440 virtual void TearDown() override {
442 for (auto s : mSensorHandles) {
443 S()->activate(s, false);
445 mSensorHandles.clear();
447 // stop all direct report and channels
448 for (auto c : mDirectChannelHandles) {
449 // disable all reports
450 S()->configDirectReport(-1, c, RateLevel::STOP, [] (auto, auto){});
451 S()->unregisterDirectChannel(c);
453 mDirectChannelHandles.clear();
457 SensorInfo defaultSensorByType(SensorType type);
458 std::vector<SensorInfo> getSensorsList();
459 std::vector<Event> collectEvents(useconds_t timeLimitUs, size_t nEventLimit,
460 bool clearBeforeStart = true, bool changeCollection = true);
462 // implementation wrapper
463 Return<void> getSensorsList(ISensors::getSensorsList_cb _hidl_cb) {
464 return S()->getSensorsList(_hidl_cb);
467 Return<Result> activate(
468 int32_t sensorHandle, bool enabled);
470 Return<Result> batch(
471 int32_t sensorHandle,
472 int64_t samplingPeriodNs,
473 int64_t maxReportLatencyNs) {
474 return S()->batch(sensorHandle, samplingPeriodNs, maxReportLatencyNs);
477 Return<Result> flush(int32_t sensorHandle) {
478 return S()->flush(sensorHandle);
481 Return<Result> injectSensorData(const Event& event) {
482 return S()->injectSensorData(event);
485 Return<void> registerDirectChannel(
486 const SharedMemInfo& mem, ISensors::registerDirectChannel_cb _hidl_cb);
488 Return<Result> unregisterDirectChannel(int32_t channelHandle) {
489 return S()->unregisterDirectChannel(channelHandle);
492 Return<void> configDirectReport(
493 int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
494 ISensors::configDirectReport_cb _hidl_cb) {
495 return S()->configDirectReport(sensorHandle, channelHandle, rate, _hidl_cb);
498 inline sp<ISensors>& S() {
499 return SensorsHidlEnvironment::Instance()->sensors;
502 inline static SensorFlagBits extractReportMode(uint64_t flag) {
503 return (SensorFlagBits) (flag
504 & ((uint64_t) SensorFlagBits::CONTINUOUS_MODE
505 | (uint64_t) SensorFlagBits::ON_CHANGE_MODE
506 | (uint64_t) SensorFlagBits::ONE_SHOT_MODE
507 | (uint64_t) SensorFlagBits::SPECIAL_REPORTING_MODE));
510 inline static bool isMetaSensorType(SensorType type) {
511 return (type == SensorType::META_DATA
512 || type == SensorType::DYNAMIC_SENSOR_META
513 || type == SensorType::ADDITIONAL_INFO);
516 inline static bool isValidType(SensorType type) {
517 return (int32_t) type > 0;
520 void testStreamingOperation(SensorType type,
521 std::chrono::nanoseconds samplingPeriod,
522 std::chrono::seconds duration,
523 const SensorEventsChecker &checker);
524 void testSamplingRateHotSwitchOperation(SensorType type);
525 void testBatchingOperation(SensorType type);
526 void testDirectReportOperation(
527 SensorType type, SharedMemType memType, RateLevel rate, const SensorEventsChecker &checker);
529 static void assertTypeMatchStringType(SensorType type, const hidl_string& stringType);
530 static void assertTypeMatchReportMode(SensorType type, SensorFlagBits reportMode);
531 static void assertDelayMatchReportMode(
532 int32_t minDelay, int32_t maxDelay, SensorFlagBits reportMode);
533 static SensorFlagBits expectedReportModeForType(SensorType type);
534 static bool isDirectReportRateSupported(SensorInfo sensor, RateLevel rate);
535 static bool isDirectChannelTypeSupported(SensorInfo sensor, SharedMemType type);
538 static const Vec3NormChecker sAccelNormChecker;
539 static const Vec3NormChecker sGyroNormChecker;
541 // all sensors and direct channnels used
542 std::unordered_set<int32_t> mSensorHandles;
543 std::unordered_set<int32_t> mDirectChannelHandles;
546 const Vec3NormChecker SensorsHidlTest::sAccelNormChecker(
547 Vec3NormChecker::byNominal(GRAVITY_EARTH, 0.5f/*m/s^2*/));
548 const Vec3NormChecker SensorsHidlTest::sGyroNormChecker(
549 Vec3NormChecker::byNominal(0.f, 0.1f/*rad/s*/));
551 Return<Result> SensorsHidlTest::activate(int32_t sensorHandle, bool enabled) {
552 // If activating a sensor, add the handle in a set so that when test fails it can be turned off.
553 // The handle is not removed when it is deactivating on purpose so that it is not necessary to
554 // check the return value of deactivation. Deactivating a sensor more than once does not have
557 mSensorHandles.insert(sensorHandle);
559 return S()->activate(sensorHandle, enabled);
562 Return<void> SensorsHidlTest::registerDirectChannel(
563 const SharedMemInfo& mem, ISensors::registerDirectChannel_cb cb) {
564 // If registeration of a channel succeeds, add the handle of channel to a set so that it can be
565 // unregistered when test fails. Unregister a channel does not remove the handle on purpose.
566 // Unregistering a channel more than once should not have negative effect.
567 S()->registerDirectChannel(mem,
568 [&] (auto result, auto channelHandle) {
569 if (result == Result::OK) {
570 mDirectChannelHandles.insert(channelHandle);
572 cb(result, channelHandle);
577 std::vector<Event> SensorsHidlTest::collectEvents(useconds_t timeLimitUs, size_t nEventLimit,
578 bool clearBeforeStart, bool changeCollection) {
579 std::vector<Event> events;
580 constexpr useconds_t SLEEP_GRANULARITY = 100*1000; //granularity 100 ms
582 ALOGI("collect max of %zu events for %d us, clearBeforeStart %d",
583 nEventLimit, timeLimitUs, clearBeforeStart);
585 if (changeCollection) {
586 SensorsHidlEnvironment::Instance()->setCollection(true);
588 if (clearBeforeStart) {
589 SensorsHidlEnvironment::Instance()->catEvents(nullptr);
592 while (timeLimitUs > 0) {
593 useconds_t duration = std::min(SLEEP_GRANULARITY, timeLimitUs);
595 timeLimitUs -= duration;
597 SensorsHidlEnvironment::Instance()->catEvents(&events);
598 if (events.size() >= nEventLimit) {
601 ALOGV("time to go = %d, events to go = %d",
602 (int)timeLimitUs, (int)(nEventLimit - events.size()));
605 if (changeCollection) {
606 SensorsHidlEnvironment::Instance()->setCollection(false);
611 void SensorsHidlTest::assertTypeMatchStringType(SensorType type, const hidl_string& stringType) {
613 if (type >= SensorType::DEVICE_PRIVATE_BASE) {
618 #define CHECK_TYPE_STRING_FOR_SENSOR_TYPE(type) \
619 case SensorType::type: ASSERT_STREQ(SENSOR_STRING_TYPE_ ## type, stringType); break;
620 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(ACCELEROMETER);
621 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(ACCELEROMETER_UNCALIBRATED);
622 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(ADDITIONAL_INFO);
623 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(AMBIENT_TEMPERATURE);
624 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(DEVICE_ORIENTATION);
625 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(DYNAMIC_SENSOR_META);
626 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(GAME_ROTATION_VECTOR);
627 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(GEOMAGNETIC_ROTATION_VECTOR);
628 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(GLANCE_GESTURE);
629 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(GRAVITY);
630 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(GYROSCOPE);
631 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(GYROSCOPE_UNCALIBRATED);
632 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(HEART_BEAT);
633 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(HEART_RATE);
634 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(LIGHT);
635 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(LINEAR_ACCELERATION);
636 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(LOW_LATENCY_OFFBODY_DETECT);
637 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(MAGNETIC_FIELD);
638 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(MAGNETIC_FIELD_UNCALIBRATED);
639 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(MOTION_DETECT);
640 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(ORIENTATION);
641 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(PICK_UP_GESTURE);
642 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(POSE_6DOF);
643 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(PRESSURE);
644 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(PROXIMITY);
645 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(RELATIVE_HUMIDITY);
646 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(ROTATION_VECTOR);
647 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(SIGNIFICANT_MOTION);
648 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(STATIONARY_DETECT);
649 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(STEP_COUNTER);
650 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(STEP_DETECTOR);
651 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(TEMPERATURE);
652 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(TILT_DETECTOR);
653 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(WAKE_GESTURE);
654 CHECK_TYPE_STRING_FOR_SENSOR_TYPE(WRIST_TILT_GESTURE);
656 FAIL() << "Type " << static_cast<int>(type) << " in android defined range is not checked, "
657 << "stringType = " << stringType;
658 #undef CHECK_TYPE_STRING_FOR_SENSOR_TYPE
662 void SensorsHidlTest::assertTypeMatchReportMode(SensorType type, SensorFlagBits reportMode) {
663 if (type >= SensorType::DEVICE_PRIVATE_BASE) {
667 SensorFlagBits expected = expectedReportModeForType(type);
669 ASSERT_TRUE(expected == (SensorFlagBits) -1 || expected == reportMode)
670 << "reportMode=" << static_cast<int>(reportMode)
671 << "expected=" << static_cast<int>(expected);
674 void SensorsHidlTest::assertDelayMatchReportMode(
675 int32_t minDelay, int32_t maxDelay, SensorFlagBits reportMode) {
677 case SensorFlagBits::CONTINUOUS_MODE:
678 ASSERT_LT(0, minDelay);
679 ASSERT_LE(0, maxDelay);
681 case SensorFlagBits::ON_CHANGE_MODE:
682 ASSERT_LE(0, minDelay);
683 ASSERT_LE(0, maxDelay);
685 case SensorFlagBits::ONE_SHOT_MODE:
686 ASSERT_EQ(-1, minDelay);
687 ASSERT_EQ(0, maxDelay);
689 case SensorFlagBits::SPECIAL_REPORTING_MODE:
690 // do not enforce anything for special reporting mode
693 FAIL() << "Report mode " << static_cast<int>(reportMode) << " not checked";
697 // return -1 means no expectation for this type
698 SensorFlagBits SensorsHidlTest::expectedReportModeForType(SensorType type) {
700 case SensorType::ACCELEROMETER:
701 case SensorType::GYROSCOPE:
702 case SensorType::MAGNETIC_FIELD:
703 case SensorType::ORIENTATION:
704 case SensorType::PRESSURE:
705 case SensorType::TEMPERATURE:
706 case SensorType::GRAVITY:
707 case SensorType::LINEAR_ACCELERATION:
708 case SensorType::ROTATION_VECTOR:
709 case SensorType::MAGNETIC_FIELD_UNCALIBRATED:
710 case SensorType::GAME_ROTATION_VECTOR:
711 case SensorType::GYROSCOPE_UNCALIBRATED:
712 case SensorType::GEOMAGNETIC_ROTATION_VECTOR:
713 case SensorType::POSE_6DOF:
714 case SensorType::HEART_BEAT:
715 return SensorFlagBits::CONTINUOUS_MODE;
717 case SensorType::LIGHT:
718 case SensorType::PROXIMITY:
719 case SensorType::RELATIVE_HUMIDITY:
720 case SensorType::AMBIENT_TEMPERATURE:
721 case SensorType::HEART_RATE:
722 case SensorType::DEVICE_ORIENTATION:
723 case SensorType::MOTION_DETECT:
724 case SensorType::STEP_COUNTER:
725 return SensorFlagBits::ON_CHANGE_MODE;
727 case SensorType::SIGNIFICANT_MOTION:
728 case SensorType::WAKE_GESTURE:
729 case SensorType::GLANCE_GESTURE:
730 case SensorType::PICK_UP_GESTURE:
731 return SensorFlagBits::ONE_SHOT_MODE;
733 case SensorType::STEP_DETECTOR:
734 case SensorType::TILT_DETECTOR:
735 case SensorType::WRIST_TILT_GESTURE:
736 case SensorType::DYNAMIC_SENSOR_META:
737 return SensorFlagBits::SPECIAL_REPORTING_MODE;
740 ALOGW("Type %d is not implemented in expectedReportModeForType", (int)type);
741 return (SensorFlagBits)-1;
745 bool SensorsHidlTest::isDirectReportRateSupported(SensorInfo sensor, RateLevel rate) {
747 static_cast<unsigned int>(sensor.flags & SensorFlagBits::MASK_DIRECT_REPORT)
748 >> static_cast<unsigned int>(SensorFlagShift::DIRECT_REPORT);
749 return r >= static_cast<unsigned int>(rate);
752 bool SensorsHidlTest::isDirectChannelTypeSupported(SensorInfo sensor, SharedMemType type) {
754 case SharedMemType::ASHMEM:
755 return (sensor.flags & SensorFlagBits::DIRECT_CHANNEL_ASHMEM) != 0;
756 case SharedMemType::GRALLOC:
757 return (sensor.flags & SensorFlagBits::DIRECT_CHANNEL_GRALLOC) != 0;
763 SensorInfo SensorsHidlTest::defaultSensorByType(SensorType type) {
766 ret.type = (SensorType) -1;
768 [&] (const auto &list) {
769 const size_t count = list.size();
770 for (size_t i = 0; i < count; ++i) {
771 if (list[i].type == type) {
781 std::vector<SensorInfo> SensorsHidlTest::getSensorsList() {
782 std::vector<SensorInfo> ret;
785 [&] (const auto &list) {
786 const size_t count = list.size();
787 ret.reserve(list.size());
788 for (size_t i = 0; i < count; ++i) {
789 ret.push_back(list[i]);
796 // Test if sensor list returned is valid
797 TEST_F(SensorsHidlTest, SensorListValid) {
799 [&] (const auto &list) {
800 const size_t count = list.size();
801 for (size_t i = 0; i < count; ++i) {
802 const auto &s = list[i];
803 SCOPED_TRACE(::testing::Message() << i << "/" << count << ": "
804 << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
805 << s.sensorHandle << std::dec
806 << " type=" << static_cast<int>(s.type)
807 << " name=" << s.name);
809 // Test non-empty type string
810 EXPECT_FALSE(s.typeAsString.empty());
812 // Test defined type matches defined string type
813 EXPECT_NO_FATAL_FAILURE(assertTypeMatchStringType(s.type, s.typeAsString));
815 // Test if all sensor has name and vendor
816 EXPECT_FALSE(s.name.empty());
817 EXPECT_FALSE(s.vendor.empty());
819 // Test power > 0, maxRange > 0
820 EXPECT_LE(0, s.power);
821 EXPECT_LT(0, s.maxRange);
823 // Info type, should have no sensor
825 s.type == SensorType::ADDITIONAL_INFO
826 || s.type == SensorType::META_DATA);
828 // Test fifoMax >= fifoReserved
829 EXPECT_GE(s.fifoMaxEventCount, s.fifoReservedEventCount)
830 << "max=" << s.fifoMaxEventCount << " reserved=" << s.fifoReservedEventCount;
832 // Test Reporting mode valid
833 EXPECT_NO_FATAL_FAILURE(assertTypeMatchReportMode(s.type, extractReportMode(s.flags)));
835 // Test min max are in the right order
836 EXPECT_LE(s.minDelay, s.maxDelay);
837 // Test min/max delay matches reporting mode
838 EXPECT_NO_FATAL_FAILURE(
839 assertDelayMatchReportMode(s.minDelay, s.maxDelay, extractReportMode(s.flags)));
844 // Test if sensor list returned is valid
845 TEST_F(SensorsHidlTest, SetOperationMode) {
846 std::vector<SensorInfo> sensorList = getSensorsList();
848 bool needOperationModeSupport =
849 std::any_of(sensorList.begin(), sensorList.end(),
851 return (s.flags & SensorFlagBits::DATA_INJECTION) != 0;
853 if (!needOperationModeSupport) {
857 ASSERT_EQ(Result::OK, S()->setOperationMode(OperationMode::NORMAL));
858 ASSERT_EQ(Result::OK, S()->setOperationMode(OperationMode::DATA_INJECTION));
859 ASSERT_EQ(Result::OK, S()->setOperationMode(OperationMode::NORMAL));
862 // Test if sensor list returned is valid
863 TEST_F(SensorsHidlTest, InjectSensorEventData) {
864 std::vector<SensorInfo> sensorList = getSensorsList();
865 std::vector<SensorInfo> sensorSupportInjection;
867 bool needOperationModeSupport =
868 std::any_of(sensorList.begin(), sensorList.end(),
869 [&sensorSupportInjection] (const auto& s) {
870 bool ret = (s.flags & SensorFlagBits::DATA_INJECTION) != 0;
872 sensorSupportInjection.push_back(s);
876 if (!needOperationModeSupport) {
880 ASSERT_EQ(Result::OK, S()->setOperationMode(OperationMode::NORMAL));
881 ASSERT_EQ(Result::OK, S()->setOperationMode(OperationMode::DATA_INJECTION));
883 for (const auto &s : sensorSupportInjection) {
885 case SensorType::ACCELEROMETER:
886 case SensorType::GYROSCOPE:
887 case SensorType::MAGNETIC_FIELD: {
888 usleep(100000); // sleep 100ms
891 dummy.timestamp = android::elapsedRealtimeNano();
892 dummy.sensorType = s.type;
893 dummy.sensorHandle = s.sensorHandle;
894 Vec3 v = {1, 2, 3, SensorStatus::ACCURACY_HIGH};
897 EXPECT_EQ(Result::OK, S()->injectSensorData(dummy));
904 ASSERT_EQ(Result::OK, S()->setOperationMode(OperationMode::NORMAL));
907 void SensorsHidlTest::testStreamingOperation(SensorType type,
908 std::chrono::nanoseconds samplingPeriod,
909 std::chrono::seconds duration,
910 const SensorEventsChecker &checker) {
911 std::vector<Event> events;
913 const int64_t samplingPeriodInNs = samplingPeriod.count();
914 const int64_t batchingPeriodInNs = 0; // no batching
915 const useconds_t minTimeUs = std::chrono::microseconds(duration).count();
916 const size_t minNEvent = duration / samplingPeriod;
918 SensorInfo sensor = defaultSensorByType(type);
920 if (!isValidType(sensor.type)) {
921 // no default sensor of this type
925 if (std::chrono::microseconds(sensor.minDelay) > samplingPeriod) {
926 // rate not supported
930 int32_t handle = sensor.sensorHandle;
932 ASSERT_EQ(batch(handle, samplingPeriodInNs, batchingPeriodInNs), Result::OK);
933 ASSERT_EQ(activate(handle, 1), Result::OK);
934 events = collectEvents(minTimeUs, minNEvent, true /*clearBeforeStart*/);
935 ASSERT_EQ(activate(handle, 0), Result::OK);
937 ALOGI("Collected %zu samples", events.size());
939 ASSERT_GT(events.size(), 0u);
941 size_t nRealEvent = 0;
942 bool handleMismatchReported = false;
943 bool metaSensorTypeErrorReported = false;
944 for (auto & e : events) {
945 if (e.sensorType == type) {
946 // avoid generating hundreds of error
947 if (!handleMismatchReported) {
948 EXPECT_EQ(e.sensorHandle, handle)
949 << (handleMismatchReported = true,
950 "Event of the same type must come from the sensor registered");
954 // avoid generating hundreds of error
955 if (!metaSensorTypeErrorReported) {
956 EXPECT_TRUE(isMetaSensorType(e.sensorType))
957 << (metaSensorTypeErrorReported = true,
958 "Only meta types are allowed besides the type registered");
964 EXPECT_TRUE(checker.check(events, &s)) << s;
966 EXPECT_GE(nRealEvent, minNEvent / 2); // make sure returned events are not all meta
969 // Test if sensor hal can do UI speed accelerometer streaming properly
970 TEST_F(SensorsHidlTest, AccelerometerStreamingOperationSlow) {
971 testStreamingOperation(SensorType::ACCELEROMETER,
972 std::chrono::milliseconds(200),
973 std::chrono::seconds(5),
977 // Test if sensor hal can do normal speed accelerometer streaming properly
978 TEST_F(SensorsHidlTest, AccelerometerStreamingOperationNormal) {
979 testStreamingOperation(SensorType::ACCELEROMETER,
980 std::chrono::milliseconds(20),
981 std::chrono::seconds(5),
985 // Test if sensor hal can do game speed accelerometer streaming properly
986 TEST_F(SensorsHidlTest, AccelerometerStreamingOperationFast) {
987 testStreamingOperation(SensorType::ACCELEROMETER,
988 std::chrono::milliseconds(5),
989 std::chrono::seconds(5),
993 // Test if sensor hal can do UI speed gyroscope streaming properly
994 TEST_F(SensorsHidlTest, GyroscopeStreamingOperationSlow) {
995 testStreamingOperation(SensorType::GYROSCOPE,
996 std::chrono::milliseconds(200),
997 std::chrono::seconds(5),
1001 // Test if sensor hal can do normal speed gyroscope streaming properly
1002 TEST_F(SensorsHidlTest, GyroscopeStreamingOperationNormal) {
1003 testStreamingOperation(SensorType::GYROSCOPE,
1004 std::chrono::milliseconds(20),
1005 std::chrono::seconds(5),
1009 // Test if sensor hal can do game speed gyroscope streaming properly
1010 TEST_F(SensorsHidlTest, GyroscopeStreamingOperationFast) {
1011 testStreamingOperation(SensorType::GYROSCOPE,
1012 std::chrono::milliseconds(5),
1013 std::chrono::seconds(5),
1017 // Test if sensor hal can do UI speed magnetometer streaming properly
1018 TEST_F(SensorsHidlTest, MagnetometerStreamingOperationSlow) {
1019 testStreamingOperation(SensorType::MAGNETIC_FIELD,
1020 std::chrono::milliseconds(200),
1021 std::chrono::seconds(5),
1025 // Test if sensor hal can do normal speed magnetometer streaming properly
1026 TEST_F(SensorsHidlTest, MagnetometerStreamingOperationNormal) {
1027 testStreamingOperation(SensorType::MAGNETIC_FIELD,
1028 std::chrono::milliseconds(20),
1029 std::chrono::seconds(5),
1033 // Test if sensor hal can do game speed magnetometer streaming properly
1034 TEST_F(SensorsHidlTest, MagnetometerStreamingOperationFast) {
1035 testStreamingOperation(SensorType::MAGNETIC_FIELD,
1036 std::chrono::milliseconds(5),
1037 std::chrono::seconds(5),
1041 void SensorsHidlTest::testSamplingRateHotSwitchOperation(SensorType type) {
1042 std::vector<Event> events1, events2;
1044 constexpr int64_t batchingPeriodInNs = 0; // no batching
1045 constexpr size_t minNEvent = 50;
1047 SensorInfo sensor = defaultSensorByType(type);
1049 if (!isValidType(sensor.type)) {
1050 // no default sensor of this type
1054 int32_t handle = sensor.sensorHandle;
1055 int64_t minSamplingPeriodInNs = sensor.minDelay * 1000ll;
1056 int64_t maxSamplingPeriodInNs = sensor.maxDelay * 1000ll;
1058 if (minSamplingPeriodInNs == maxSamplingPeriodInNs) {
1059 // only support single rate
1063 ASSERT_EQ(batch(handle, minSamplingPeriodInNs, batchingPeriodInNs), Result::OK);
1064 ASSERT_EQ(activate(handle, 1), Result::OK);
1066 usleep(500000); // sleep 0.5 sec to wait for change rate to happen
1067 events1 = collectEvents(sensor.minDelay * minNEvent, minNEvent, true /*clearBeforeStart*/);
1069 ASSERT_EQ(batch(handle, maxSamplingPeriodInNs, batchingPeriodInNs), Result::OK);
1071 usleep(500000); // sleep 0.5 sec to wait for change rate to happen
1072 events2 = collectEvents(sensor.maxDelay * minNEvent, minNEvent, true /*clearBeforeStart*/);
1074 ASSERT_EQ(activate(handle, 0), Result::OK);
1076 ALOGI("Collected %zu fast samples and %zu slow samples", events1.size(), events2.size());
1078 ASSERT_GT(events1.size(), 0u);
1079 ASSERT_GT(events2.size(), 0u);
1081 int64_t minDelayAverageInterval, maxDelayAverageInterval;
1084 int64_t prevTimestamp = -1;
1085 int64_t timestampInterval = 0;
1086 for (auto & e : events1) {
1087 if (e.sensorType == type) {
1088 ASSERT_EQ(e.sensorHandle, handle);
1089 if (prevTimestamp > 0) {
1090 timestampInterval += e.timestamp - prevTimestamp;
1092 prevTimestamp = e.timestamp;
1096 ASSERT_GT(nEvent, 2u);
1097 minDelayAverageInterval = timestampInterval / (nEvent - 1);
1101 timestampInterval = 0;
1102 for (auto & e : events2) {
1103 if (e.sensorType == type) {
1104 ASSERT_EQ(e.sensorHandle, handle);
1105 if (prevTimestamp > 0) {
1106 timestampInterval += e.timestamp - prevTimestamp;
1108 prevTimestamp = e.timestamp;
1112 ASSERT_GT(nEvent, 2u);
1113 maxDelayAverageInterval = timestampInterval / (nEvent - 1);
1115 // change of rate is significant.
1116 EXPECT_GT((maxDelayAverageInterval - minDelayAverageInterval), minDelayAverageInterval / 10);
1118 // fastest rate sampling time is close to spec
1119 ALOGI("minDelayAverageInterval = %" PRId64, minDelayAverageInterval);
1120 EXPECT_LT(std::abs(minDelayAverageInterval - minSamplingPeriodInNs),
1121 minSamplingPeriodInNs / 10);
1124 // Test if sensor hal can do accelerometer sampling rate switch properly when sensor is active
1125 TEST_F(SensorsHidlTest, AccelerometerSamplingPeriodHotSwitchOperation) {
1126 testSamplingRateHotSwitchOperation(SensorType::ACCELEROMETER);
1129 // Test if sensor hal can do gyroscope sampling rate switch properly when sensor is active
1130 TEST_F(SensorsHidlTest, GyroscopeSamplingPeriodHotSwitchOperation) {
1131 testSamplingRateHotSwitchOperation(SensorType::GYROSCOPE);
1134 // Test if sensor hal can do magnetometer sampling rate switch properly when sensor is active
1135 TEST_F(SensorsHidlTest, MagnetometerSamplingPeriodHotSwitchOperation) {
1136 testSamplingRateHotSwitchOperation(SensorType::MAGNETIC_FIELD);
1139 void SensorsHidlTest::testBatchingOperation(SensorType type) {
1140 std::vector<Event> events;
1142 constexpr int64_t maxBatchingTestTimeNs = 30ull * 1000 * 1000 * 1000;
1143 constexpr int64_t oneSecondInNs = 1ull * 1000 * 1000 * 1000;
1145 SensorInfo sensor = defaultSensorByType(type);
1147 if (!isValidType(sensor.type)) {
1148 // no default sensor of this type
1152 int32_t handle = sensor.sensorHandle;
1153 int64_t minSamplingPeriodInNs = sensor.minDelay * 1000ll;
1154 uint32_t minFifoCount = sensor.fifoReservedEventCount;
1155 int64_t batchingPeriodInNs = minFifoCount * minSamplingPeriodInNs;
1157 if (batchingPeriodInNs < oneSecondInNs) {
1158 // batching size too small to test reliably
1162 batchingPeriodInNs = std::min(batchingPeriodInNs, maxBatchingTestTimeNs);
1164 ALOGI("Test batching for %d ms", (int)(batchingPeriodInNs / 1000 / 1000));
1166 int64_t allowedBatchDeliverTimeNs =
1167 std::max(oneSecondInNs, batchingPeriodInNs / 10);
1169 ASSERT_EQ(batch(handle, minSamplingPeriodInNs, INT64_MAX), Result::OK);
1170 ASSERT_EQ(activate(handle, 1), Result::OK);
1172 usleep(500000); // sleep 0.5 sec to wait for initialization
1173 ASSERT_EQ(flush(handle), Result::OK);
1175 // wait for 80% of the reserved batching period
1176 // there should not be any significant amount of events
1177 // since collection is not enabled all events will go down the drain
1178 usleep(batchingPeriodInNs / 1000 * 8 / 10);
1180 SensorsHidlEnvironment::Instance()->setCollection(true);
1181 // 0.8 + 0.3 times the batching period
1182 // plus some time for the event to deliver
1183 events = collectEvents(
1184 batchingPeriodInNs / 1000 * 3 / 10,
1185 minFifoCount, true /*clearBeforeStart*/, false /*change collection*/);
1187 ASSERT_EQ(flush(handle), Result::OK);
1189 events = collectEvents(allowedBatchDeliverTimeNs / 1000,
1190 minFifoCount, true /*clearBeforeStart*/, false /*change collection*/);
1192 SensorsHidlEnvironment::Instance()->setCollection(false);
1193 ASSERT_EQ(activate(handle, 0), Result::OK);
1196 for (auto & e : events) {
1197 if (e.sensorType == type && e.sensorHandle == handle) {
1202 // at least reach 90% of advertised capacity
1203 ASSERT_GT(nEvent, (size_t)(batchingPeriodInNs / minSamplingPeriodInNs * 9 / 10));
1206 // Test if sensor hal can do accelerometer batching properly
1207 TEST_F(SensorsHidlTest, AccelerometerBatchingOperation) {
1208 testBatchingOperation(SensorType::ACCELEROMETER);
1211 // Test if sensor hal can do gyroscope batching properly
1212 TEST_F(SensorsHidlTest, GyroscopeBatchingOperation) {
1213 testBatchingOperation(SensorType::GYROSCOPE);
1216 // Test if sensor hal can do magnetometer batching properly
1217 TEST_F(SensorsHidlTest, MagnetometerBatchingOperation) {
1218 testBatchingOperation(SensorType::MAGNETIC_FIELD);
1221 void SensorsHidlTest::testDirectReportOperation(
1222 SensorType type, SharedMemType memType, RateLevel rate, const SensorEventsChecker &checker) {
1223 constexpr size_t kEventSize = static_cast<size_t>(SensorsEventFormatOffset::TOTAL_LENGTH);
1224 constexpr size_t kNEvent = 500;
1225 constexpr size_t kMemSize = kEventSize * kNEvent;
1227 constexpr float kNormalNominal = 50;
1228 constexpr float kFastNominal = 200;
1229 constexpr float kVeryFastNominal = 800;
1231 constexpr float kNominalTestTimeSec = 1.f;
1232 constexpr float kMaxTestTimeSec = kNominalTestTimeSec + 0.5f; // 0.5 second for initialization
1234 SensorInfo sensor = defaultSensorByType(type);
1236 if (!isDirectReportRateSupported(sensor, rate)) {
1240 if (!isDirectChannelTypeSupported(sensor, memType)) {
1244 std::unique_ptr<SensorsTestSharedMemory>
1245 mem(SensorsTestSharedMemory::create(memType, kMemSize));
1246 ASSERT_NE(mem, nullptr);
1248 char* buffer = mem->getBuffer();
1249 // fill memory with data
1250 for (size_t i = 0; i < kMemSize; ++i) {
1254 int32_t channelHandle;
1255 registerDirectChannel(mem->getSharedMemInfo(),
1256 [&channelHandle] (auto result, auto channelHandle_) {
1257 ASSERT_EQ(result, Result::OK);
1258 channelHandle = channelHandle_;
1261 // check memory is zeroed
1262 for (size_t i = 0; i < kMemSize; ++i) {
1263 ASSERT_EQ(buffer[i], '\0');
1267 configDirectReport(sensor.sensorHandle, channelHandle, rate,
1268 [&eventToken] (auto result, auto token) {
1269 ASSERT_EQ(result, Result::OK);
1273 usleep(static_cast<useconds_t>(kMaxTestTimeSec * 1e6f));
1274 auto events = mem->parseEvents();
1276 // find norminal rate
1277 float nominalFreq = 0.f;
1279 case RateLevel::NORMAL:
1280 nominalFreq = kNormalNominal;
1282 case RateLevel::FAST:
1283 nominalFreq = kFastNominal;
1285 case RateLevel::VERY_FAST:
1286 nominalFreq = kVeryFastNominal;
1288 case RateLevel::STOP:
1292 // allowed to be between 55% and 220% of nominal freq
1293 ASSERT_GT(events.size(), static_cast<size_t>(nominalFreq * 0.55f * kNominalTestTimeSec));
1294 ASSERT_LT(events.size(), static_cast<size_t>(nominalFreq * 2.2f * kMaxTestTimeSec));
1296 int64_t lastTimestamp = 0;
1297 bool typeErrorReported = false;
1298 bool tokenErrorReported = false;
1299 bool timestampErrorReported = false;
1300 for (auto &e : events) {
1301 if (!typeErrorReported) {
1302 EXPECT_EQ(type, e.sensorType)
1303 << (typeErrorReported = true, "Type in event does not match type of sensor registered.");
1305 if (!tokenErrorReported) {
1306 EXPECT_EQ(eventToken, e.sensorHandle)
1307 << (tokenErrorReported = true,
1308 "Event token does not match that retured from configDirectReport");
1310 if (!timestampErrorReported) {
1311 EXPECT_GT(e.timestamp, lastTimestamp)
1312 << (timestampErrorReported = true, "Timestamp not monotonically increasing");
1314 lastTimestamp = e.timestamp;
1318 EXPECT_TRUE(checker.check(events, &s)) << s;
1320 // stop sensor and unregister channel
1321 configDirectReport(sensor.sensorHandle, channelHandle, RateLevel::STOP,
1322 [&eventToken] (auto result, auto) {
1323 EXPECT_EQ(result, Result::OK);
1325 EXPECT_EQ(unregisterDirectChannel(channelHandle), Result::OK);
1328 // Test sensor event direct report with ashmem for accel sensor at normal rate
1329 TEST_F(SensorsHidlTest, AccelerometerAshmemDirectReportOperationNormal) {
1330 testDirectReportOperation(SensorType::ACCELEROMETER, SharedMemType::ASHMEM, RateLevel::NORMAL,
1334 // Test sensor event direct report with ashmem for accel sensor at fast rate
1335 TEST_F(SensorsHidlTest, AccelerometerAshmemDirectReportOperationFast) {
1336 testDirectReportOperation(SensorType::ACCELEROMETER, SharedMemType::ASHMEM, RateLevel::FAST,
1340 // Test sensor event direct report with ashmem for accel sensor at very fast rate
1341 TEST_F(SensorsHidlTest, AccelerometerAshmemDirectReportOperationVeryFast) {
1342 testDirectReportOperation(SensorType::ACCELEROMETER, SharedMemType::ASHMEM, RateLevel::VERY_FAST,
1346 // Test sensor event direct report with ashmem for gyro sensor at normal rate
1347 TEST_F(SensorsHidlTest, GyroscopeAshmemDirectReportOperationNormal) {
1348 testDirectReportOperation(SensorType::GYROSCOPE, SharedMemType::ASHMEM, RateLevel::NORMAL,
1352 // Test sensor event direct report with ashmem for gyro sensor at fast rate
1353 TEST_F(SensorsHidlTest, GyroscopeAshmemDirectReportOperationFast) {
1354 testDirectReportOperation(SensorType::GYROSCOPE, SharedMemType::ASHMEM, RateLevel::FAST,
1358 // Test sensor event direct report with ashmem for gyro sensor at very fast rate
1359 TEST_F(SensorsHidlTest, GyroscopeAshmemDirectReportOperationVeryFast) {
1360 testDirectReportOperation(SensorType::GYROSCOPE, SharedMemType::ASHMEM, RateLevel::VERY_FAST,
1364 // Test sensor event direct report with ashmem for mag sensor at normal rate
1365 TEST_F(SensorsHidlTest, MagnetometerAshmemDirectReportOperationNormal) {
1366 testDirectReportOperation(SensorType::MAGNETIC_FIELD, SharedMemType::ASHMEM, RateLevel::NORMAL,
1370 // Test sensor event direct report with ashmem for mag sensor at fast rate
1371 TEST_F(SensorsHidlTest, MagnetometerAshmemDirectReportOperationFast) {
1372 testDirectReportOperation(SensorType::MAGNETIC_FIELD, SharedMemType::ASHMEM, RateLevel::FAST,
1376 // Test sensor event direct report with ashmem for mag sensor at very fast rate
1377 TEST_F(SensorsHidlTest, MagnetometerAshmemDirectReportOperationVeryFast) {
1378 testDirectReportOperation(
1379 SensorType::MAGNETIC_FIELD, SharedMemType::ASHMEM, RateLevel::VERY_FAST, NullChecker());
1382 int main(int argc, char **argv) {
1383 ::testing::AddGlobalTestEnvironment(SensorsHidlEnvironment::Instance());
1384 ::testing::InitGoogleTest(&argc, argv);
1385 int status = RUN_ALL_TESTS();
1386 ALOGI("Test result = %d", status);
1389 // vim: set ts=2 sw=2