summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhuoyao Zhang2018-01-24 17:00:08 -0600
committerandroid-build-merger2018-01-24 17:00:08 -0600
commitb6371e782db1c82bc2b3261579c4f25c31a9c1b1 (patch)
tree2e3bdab6a3e87f87dda4d67cfd65b3e9625b7718 /sensors
parent21bd732f226c38a1c35419afaa768166dfdf7087 (diff)
parent2ec4182501e7639212403f47c0b11ae46265e6dd (diff)
downloadplatform-hardware-interfaces-b6371e782db1c82bc2b3261579c4f25c31a9c1b1.tar.gz
platform-hardware-interfaces-b6371e782db1c82bc2b3261579c4f25c31a9c1b1.tar.xz
platform-hardware-interfaces-b6371e782db1c82bc2b3261579c4f25c31a9c1b1.zip
Merge "Convert sensors HAL test to use VtsHalHidlTargetTestEnvBase" am: edf1e2f589 am: a4b6a6da27
am: 2ec4182501 Change-Id: I339d8312c2321a56e263d8b9a6836639762c58ad
Diffstat (limited to 'sensors')
-rw-r--r--sensors/1.0/vts/functional/VtsHalSensorsV1_0TargetTest.cpp93
1 files changed, 49 insertions, 44 deletions
diff --git a/sensors/1.0/vts/functional/VtsHalSensorsV1_0TargetTest.cpp b/sensors/1.0/vts/functional/VtsHalSensorsV1_0TargetTest.cpp
index ca3d3e4f..24b58a78 100644
--- a/sensors/1.0/vts/functional/VtsHalSensorsV1_0TargetTest.cpp
+++ b/sensors/1.0/vts/functional/VtsHalSensorsV1_0TargetTest.cpp
@@ -15,8 +15,8 @@
15 */ 15 */
16 16
17#define LOG_TAG "sensors_hidl_hal_test" 17#define LOG_TAG "sensors_hidl_hal_test"
18#include "GrallocWrapper.h"
19#include <VtsHalHidlTargetTestBase.h> 18#include <VtsHalHidlTargetTestBase.h>
19#include <VtsHalHidlTargetTestEnvBase.h>
20#include <android-base/logging.h> 20#include <android-base/logging.h>
21#include <android/hardware/sensors/1.0/ISensors.h> 21#include <android/hardware/sensors/1.0/ISensors.h>
22#include <android/hardware/sensors/1.0/types.h> 22#include <android/hardware/sensors/1.0/types.h>
@@ -24,6 +24,7 @@
24#include <hardware/sensors.h> // for sensor type strings 24#include <hardware/sensors.h> // for sensor type strings
25#include <log/log.h> 25#include <log/log.h>
26#include <utils/SystemClock.h> 26#include <utils/SystemClock.h>
27#include "GrallocWrapper.h"
27 28
28#include <algorithm> 29#include <algorithm>
29#include <cinttypes> 30#include <cinttypes>
@@ -46,63 +47,65 @@ using namespace ::android::hardware::sensors::V1_0;
46 47
47// Test environment for sensors 48// Test environment for sensors
48class SensorsHidlTest; 49class SensorsHidlTest;
49class SensorsHidlEnvironment : public ::testing::Environment { 50class SensorsHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
50 public: 51 public:
51 // get the test environment singleton 52 // get the test environment singleton
52 static SensorsHidlEnvironment* Instance() { 53 static SensorsHidlEnvironment* Instance() {
53 static SensorsHidlEnvironment* instance = new SensorsHidlEnvironment; 54 static SensorsHidlEnvironment* instance = new SensorsHidlEnvironment;
54 return instance; 55 return instance;
55 } 56 }
56 57
57 virtual void SetUp(); 58 virtual void HidlSetUp() override;
58 virtual void TearDown(); 59 virtual void HidlTearDown() override;
59 60
60 // Get and clear all events collected so far (like "cat" shell command). 61 virtual void registerTestServices() override { registerTestService<ISensors>(); }
61 // If output is nullptr, it clears all collected events.
62 void catEvents(std::vector<Event>* output);
63 62
64 // set sensor event collection status 63 // Get and clear all events collected so far (like "cat" shell command).
65 void setCollection(bool enable); 64 // If output is nullptr, it clears all collected events.
65 void catEvents(std::vector<Event>* output);
66 66
67 private: 67 // set sensor event collection status
68 friend SensorsHidlTest; 68 void setCollection(bool enable);
69 // sensors hidl service
70 sp<ISensors> sensors;
71 69
72 SensorsHidlEnvironment() {} 70 private:
71 friend SensorsHidlTest;
72 // sensors hidl service
73 sp<ISensors> sensors;
73 74
74 void addEvent(const Event& ev); 75 SensorsHidlEnvironment() {}
75 void startPollingThread();
76 void resetHal();
77 static void pollingThread(SensorsHidlEnvironment* env, std::shared_ptr<bool> stop);
78 76
79 bool collectionEnabled; 77 void addEvent(const Event& ev);
80 std::shared_ptr<bool> stopThread; 78 void startPollingThread();
81 std::thread pollThread; 79 void resetHal();
82 std::vector<Event> events; 80 static void pollingThread(SensorsHidlEnvironment* env, std::shared_ptr<bool> stop);
83 std::mutex events_mutex; 81
82 bool collectionEnabled;
83 std::shared_ptr<bool> stopThread;
84 std::thread pollThread;
85 std::vector<Event> events;
86 std::mutex events_mutex;
84 87
85 GTEST_DISALLOW_COPY_AND_ASSIGN_(SensorsHidlEnvironment); 88 GTEST_DISALLOW_COPY_AND_ASSIGN_(SensorsHidlEnvironment);
86}; 89};
87 90
88void SensorsHidlEnvironment::SetUp() { 91void SensorsHidlEnvironment::HidlSetUp() {
89 resetHal(); 92 resetHal();
90 93
91 ASSERT_NE(sensors, nullptr) << "sensors is nullptr, cannot get hidl service"; 94 ASSERT_NE(sensors, nullptr) << "sensors is nullptr, cannot get hidl service";
92 95
93 collectionEnabled = false; 96 collectionEnabled = false;
94 startPollingThread(); 97 startPollingThread();
95 98
96 // In case framework just stopped for test and there is sensor events in the pipe, 99 // In case framework just stopped for test and there is sensor events in the pipe,
97 // wait some time for those events to be cleared to avoid them messing up the test. 100 // wait some time for those events to be cleared to avoid them messing up the test.
98 std::this_thread::sleep_for(std::chrono::seconds(3)); 101 std::this_thread::sleep_for(std::chrono::seconds(3));
99} 102}
100 103
101void SensorsHidlEnvironment::TearDown() { 104void SensorsHidlEnvironment::HidlTearDown() {
102 if (stopThread) { 105 if (stopThread) {
103 *stopThread = true; 106 *stopThread = true;
104 } 107 }
105 pollThread.detach(); 108 pollThread.detach();
106} 109}
107 110
108void SensorsHidlEnvironment::resetHal() { 111void SensorsHidlEnvironment::resetHal() {
@@ -115,7 +118,8 @@ void SensorsHidlEnvironment::resetHal() {
115 // this do ... while is for easy error handling 118 // this do ... while is for easy error handling
116 do { 119 do {
117 step = "getService()"; 120 step = "getService()";
118 sensors = ISensors::getService(); 121 sensors = ISensors::getService(
122 SensorsHidlEnvironment::Instance()->getServiceName<ISensors>());
119 if (sensors == nullptr) { 123 if (sensors == nullptr) {
120 break; 124 break;
121 } 125 }
@@ -1500,6 +1504,7 @@ TEST_F(SensorsHidlTest, MagnetometerGrallocDirectReportOperationVeryFast) {
1500int main(int argc, char **argv) { 1504int main(int argc, char **argv) {
1501 ::testing::AddGlobalTestEnvironment(SensorsHidlEnvironment::Instance()); 1505 ::testing::AddGlobalTestEnvironment(SensorsHidlEnvironment::Instance());
1502 ::testing::InitGoogleTest(&argc, argv); 1506 ::testing::InitGoogleTest(&argc, argv);
1507 SensorsHidlEnvironment::Instance()->init(&argc, argv);
1503 int status = RUN_ALL_TESTS(); 1508 int status = RUN_ALL_TESTS();
1504 ALOGI("Test result = %d", status); 1509 ALOGI("Test result = %d", status);
1505 return status; 1510 return status;