Merge "Wifi: Handle invalid error values from vendor HAL"
diff --git a/biometrics/fingerprint/2.1/vts/functional/Android.bp b/biometrics/fingerprint/2.1/vts/functional/Android.bp
index 60228f2..c418032 100644
--- a/biometrics/fingerprint/2.1/vts/functional/Android.bp
+++ b/biometrics/fingerprint/2.1/vts/functional/Android.bp
@@ -19,6 +19,6 @@
defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalBiometricsFingerprintV2_1TargetTest.cpp"],
static_libs: ["android.hardware.biometrics.fingerprint@2.1"],
- test_suites: ["general-tests"],
+ test_suites: ["general-tests", "vts-core"],
}
diff --git a/configstore/1.0/vts/functional/Android.bp b/configstore/1.0/vts/functional/Android.bp
index 008b59d..31d4b1c 100644
--- a/configstore/1.0/vts/functional/Android.bp
+++ b/configstore/1.0/vts/functional/Android.bp
@@ -19,6 +19,6 @@
defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalConfigstoreV1_0TargetTest.cpp"],
static_libs: ["android.hardware.configstore@1.0"],
- test_suites: ["general-tests"],
+ test_suites: ["general-tests", "vts-core"],
}
diff --git a/configstore/1.0/vts/functional/VtsHalConfigstoreV1_0TargetTest.cpp b/configstore/1.0/vts/functional/VtsHalConfigstoreV1_0TargetTest.cpp
index 70b5830..8a1a313 100644
--- a/configstore/1.0/vts/functional/VtsHalConfigstoreV1_0TargetTest.cpp
+++ b/configstore/1.0/vts/functional/VtsHalConfigstoreV1_0TargetTest.cpp
@@ -16,11 +16,12 @@
#define LOG_TAG "ConfigstoreHidlHalTest"
-#include <VtsHalHidlTargetTestBase.h>
-#include <VtsHalHidlTargetTestEnvBase.h>
#include <android-base/logging.h>
#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
#include <android/hardware/configstore/1.0/types.h>
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
#include <unistd.h>
using ::android::hardware::configstore::V1_0::ISurfaceFlingerConfigs;
@@ -35,25 +36,12 @@
#define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
#define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk())
-// Test environment for Configstore HIDL HAL.
-class ConfigstoreHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
- public:
- // get the test environment singleton
- static ConfigstoreHidlEnvironment* Instance() {
- static ConfigstoreHidlEnvironment* instance = new ConfigstoreHidlEnvironment;
- return instance;
- }
-
- virtual void registerTestServices() override { registerTestService<ISurfaceFlingerConfigs>(); }
-};
-
-class ConfigstoreHidlTest : public ::testing::VtsHalHidlTargetTestBase {
+class ConfigstoreHidlTest : public ::testing::TestWithParam<std::string> {
public:
sp<ISurfaceFlingerConfigs> sfConfigs;
virtual void SetUp() override {
- sfConfigs = ::testing::VtsHalHidlTargetTestBase::getService<ISurfaceFlingerConfigs>(
- ConfigstoreHidlEnvironment::Instance()->getServiceName<ISurfaceFlingerConfigs>());
+ sfConfigs = ISurfaceFlingerConfigs::getService(GetParam());
ASSERT_NE(sfConfigs, nullptr);
}
@@ -63,7 +51,7 @@
/**
* Ensure all ISurfaceFlingerConfigs.hal function calls are successful.
*/
-TEST_F(ConfigstoreHidlTest, TestFunctionCalls) {
+TEST_P(ConfigstoreHidlTest, TestFunctionCalls) {
bool tmp;
Return<void> status = sfConfigs->vsyncEventPhaseOffsetNs(
@@ -118,7 +106,7 @@
/**
* Ensure repeated call to the same function returns the same result.
*/
-TEST_F(ConfigstoreHidlTest, TestSameReturnValue) {
+TEST_P(ConfigstoreHidlTest, TestSameReturnValue) {
int64_t original_ret;
Return<void> status = sfConfigs->vsyncEventPhaseOffsetNs(
[&original_ret](OptionalInt64 arg) { original_ret = arg.value; });
@@ -135,7 +123,7 @@
* Make sure the constrains of hasWideColorDisplay, hasHDRDisplay
* are enforced.
*/
-TEST_F(ConfigstoreHidlTest, TestColorConstrainsBasic) {
+TEST_P(ConfigstoreHidlTest, TestColorConstrainsBasic) {
bool hasWideColorDisplay;
bool hasHDRDisplay;
@@ -152,11 +140,7 @@
}
}
-int main(int argc, char** argv) {
- ::testing::AddGlobalTestEnvironment(ConfigstoreHidlEnvironment::Instance());
- ::testing::InitGoogleTest(&argc, argv);
- ConfigstoreHidlEnvironment::Instance()->init(&argc, argv);
- int status = RUN_ALL_TESTS();
- LOG(INFO) << "Test result = " << status;
- return status;
-}
+INSTANTIATE_TEST_SUITE_P(
+ PerInstance, ConfigstoreHidlTest,
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISurfaceFlingerConfigs::descriptor)),
+ android::hardware::PrintInstanceNameToString);
diff --git a/memtrack/1.0/vts/functional/Android.bp b/memtrack/1.0/vts/functional/Android.bp
index d682e0b..9e5cf6d 100644
--- a/memtrack/1.0/vts/functional/Android.bp
+++ b/memtrack/1.0/vts/functional/Android.bp
@@ -19,5 +19,5 @@
defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalMemtrackV1_0TargetTest.cpp"],
static_libs: ["android.hardware.memtrack@1.0"],
- test_suites: ["general-tests"],
+ test_suites: ["general-tests", "vts-core"],
}
diff --git a/memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp b/memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp
index 691ecca..cccedca 100644
--- a/memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp
+++ b/memtrack/1.0/vts/functional/VtsHalMemtrackV1_0TargetTest.cpp
@@ -20,8 +20,9 @@
#include <android/hardware/memtrack/1.0/IMemtrack.h>
-#include <VtsHalHidlTargetTestBase.h>
-#include <VtsHalHidlTargetTestEnvBase.h>
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
#include <fcntl.h>
#include <algorithm>
@@ -39,23 +40,10 @@
using std::vector;
using std::count_if;
-// Test environment for Memtrack HIDL HAL.
-class MemtrackHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
- public:
- // get the test environment singleton
- static MemtrackHidlEnvironment* Instance() {
- static MemtrackHidlEnvironment* instance = new MemtrackHidlEnvironment;
- return instance;
- }
-
- virtual void registerTestServices() override { registerTestService<IMemtrack>(); }
-};
-
-class MemtrackHidlTest : public ::testing::VtsHalHidlTargetTestBase {
+class MemtrackHidlTest : public ::testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
- memtrack = ::testing::VtsHalHidlTargetTestBase::getService<IMemtrack>(
- MemtrackHidlEnvironment::Instance()->getServiceName<IMemtrack>());
+ memtrack = IMemtrack::getService(GetParam());
ASSERT_NE(memtrack, nullptr);
}
@@ -93,7 +81,7 @@
/* Sanity check results when getMemory() is passed a negative PID
*/
-TEST_F(MemtrackHidlTest, BadPidTest) {
+TEST_P(MemtrackHidlTest, BadPidTest) {
MemtrackStatus s;
hidl_vec<MemtrackRecord> v;
auto cb = generate_cb(&s, &v);
@@ -108,7 +96,7 @@
/* Sanity check results when getMemory() is passed a bad memory usage type
*/
-TEST_F(MemtrackHidlTest, BadTypeTest) {
+TEST_P(MemtrackHidlTest, BadTypeTest) {
MemtrackStatus s;
hidl_vec<MemtrackRecord> v;
auto cb = generate_cb(&s, &v);
@@ -121,7 +109,7 @@
* for all memory types, including valid flag combinations for every
* MemtrackRecord returned.
*/
-TEST_F(MemtrackHidlTest, GetMemoryTest) {
+TEST_P(MemtrackHidlTest, GetMemoryTest) {
/* Opening this device causes the kernel to provide memtrack with memory
* info for this process.
*/
@@ -172,11 +160,7 @@
static_cast<uint32_t>(MemtrackType::NUM_TYPES));
}
-int main(int argc, char **argv) {
- ::testing::AddGlobalTestEnvironment(MemtrackHidlEnvironment::Instance());
- ::testing::InitGoogleTest(&argc, argv);
- MemtrackHidlEnvironment::Instance()->init(&argc, argv);
- int status = RUN_ALL_TESTS();
- LOG(INFO) << "Test result = " << status;
- return status;
-}
+INSTANTIATE_TEST_SUITE_P(
+ PerInstance, MemtrackHidlTest,
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(IMemtrack::descriptor)),
+ android::hardware::PrintInstanceNameToString);
diff --git a/sensors/2.0/multihal/HalProxy.cpp b/sensors/2.0/multihal/HalProxy.cpp
index b78806a..49c5a0d 100644
--- a/sensors/2.0/multihal/HalProxy.cpp
+++ b/sensors/2.0/multihal/HalProxy.cpp
@@ -330,7 +330,7 @@
Return<void> HalProxy::onDynamicSensorsDisconnected(
const hidl_vec<int32_t>& dynamicSensorHandlesRemoved, int32_t subHalIndex) {
- // TODO: Block this call until all pending events are flushed from queue
+ // TODO(b/143302327): Block this call until all pending events are flushed from queue
std::vector<int32_t> sensorHandles;
{
std::lock_guard<std::mutex> lock(mDynamicSensorsMutex);
@@ -457,7 +457,8 @@
}
void HalProxy::handlePendingWrites() {
- // TODO: Find a way to optimize locking strategy maybe using two mutexes instead of one.
+ // TODO(b/143302327): Find a way to optimize locking strategy maybe using two mutexes instead of
+ // one.
std::unique_lock<std::mutex> lock(mEventQueueWriteMutex);
while (mThreadsRun.load()) {
mEventQueueWriteCV.wait(
@@ -485,8 +486,8 @@
}
lock.lock();
if (pendingWriteEvents.size() > eventQueueSize) {
- // TODO: Check if this erase operation is too inefficient. It will copy all the
- // events ahead of it down to fill gap off array at front after the erase.
+ // TODO(b/143302327): Check if this erase operation is too inefficient. It will copy
+ // all the events ahead of it down to fill gap off array at front after the erase.
pendingWriteEvents.erase(pendingWriteEvents.begin(),
pendingWriteEvents.begin() + eventQueueSize);
} else {
@@ -554,8 +555,8 @@
numToWrite = std::min(events.size(), mEventQueue->availableToWrite());
if (numToWrite > 0) {
if (mEventQueue->write(events.data(), numToWrite)) {
- // TODO: While loop if mEventQueue->avaiableToWrite > 0 to possibly fit in more
- // writes immediately
+ // TODO(b/143302327): While loop if mEventQueue->avaiableToWrite > 0 to possibly fit
+ // in more writes immediately
mEventQueueFlag->wake(static_cast<uint32_t>(EventQueueFlagBits::READ_AND_PROCESS));
} else {
numToWrite = 0;
@@ -563,8 +564,8 @@
}
}
if (numToWrite < events.size()) {
- // TODO: Bound the mPendingWriteEventsQueue so that we do not trigger OOMs if framework
- // stalls
+ // TODO(b/143302327): Bound the mPendingWriteEventsQueue so that we do not trigger OOMs if
+ // framework stalls
std::vector<Event> eventsLeft(events.begin() + numToWrite, events.end());
mPendingWriteEventsQueue.push({eventsLeft, numWakeupEvents});
mEventQueueWriteCV.notify_one();
@@ -655,7 +656,7 @@
" w/ index %zu.",
mSubHalIndex);
}
- mHalProxy->postEventsToMessageQueue(events, numWakeupEvents, std::move(wakelock));
+ mHalProxy->postEventsToMessageQueue(processedEvents, numWakeupEvents, std::move(wakelock));
}
ScopedWakelock HalProxyCallback::createScopedWakelock(bool lock) {
diff --git a/sensors/2.0/multihal/tests/Android.bp b/sensors/2.0/multihal/tests/Android.bp
index 50a55f9..e7f9499 100644
--- a/sensors/2.0/multihal/tests/Android.bp
+++ b/sensors/2.0/multihal/tests/Android.bp
@@ -27,6 +27,7 @@
"android.hardware.sensors@2.0",
"libcutils",
"libfmq",
+ "libhardware",
"libhidlbase",
"liblog",
"libpower",
@@ -85,6 +86,7 @@
"libbase",
"libcutils",
"libfmq",
+ "libhardware",
"libhidlbase",
"liblog",
"libpower",
diff --git a/sensors/2.0/multihal/tests/HalProxy_test.cpp b/sensors/2.0/multihal/tests/HalProxy_test.cpp
index 75a4c22..1fd35d1 100644
--- a/sensors/2.0/multihal/tests/HalProxy_test.cpp
+++ b/sensors/2.0/multihal/tests/HalProxy_test.cpp
@@ -692,6 +692,38 @@
EXPECT_EQ(proxy.injectSensorData(event), Result::BAD_VALUE);
}
+TEST(HalProxyTest, PostedEventSensorHandleSubHalIndexValid) {
+ constexpr size_t kQueueSize = 5;
+ constexpr int32_t subhal1Index = 0;
+ constexpr int32_t subhal2Index = 1;
+ AllSensorsSubHal subhal1;
+ AllSensorsSubHal subhal2;
+ std::vector<ISensorsSubHal*> subHals{&subhal1, &subhal2};
+
+ std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
+ std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
+ ::android::sp<ISensorsCallback> callback = new SensorsCallback();
+ HalProxy proxy(subHals);
+ proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
+
+ int32_t sensorHandleToPost = 0x00000001;
+ Event eventIn = makeAccelerometerEvent();
+ eventIn.sensorHandle = sensorHandleToPost;
+ std::vector<Event> eventsToPost{eventIn};
+ subhal1.postEvents(eventsToPost, false);
+
+ Event eventOut;
+ EXPECT_TRUE(eventQueue->read(&eventOut));
+
+ EXPECT_EQ(eventOut.sensorHandle, (subhal1Index << 24) | sensorHandleToPost);
+
+ subhal2.postEvents(eventsToPost, false);
+
+ EXPECT_TRUE(eventQueue->read(&eventOut));
+
+ EXPECT_EQ(eventOut.sensorHandle, (subhal2Index << 24) | sensorHandleToPost);
+}
+
// Helper implementations follow
void testSensorsListFromProxyAndSubHal(const std::vector<SensorInfo>& proxySensorsList,
const std::vector<SensorInfo>& subHalSensorsList) {
diff --git a/sensors/2.0/multihal/tests/fake_subhal/Sensor.cpp b/sensors/2.0/multihal/tests/fake_subhal/Sensor.cpp
index 4d53665..de89a00 100644
--- a/sensors/2.0/multihal/tests/fake_subhal/Sensor.cpp
+++ b/sensors/2.0/multihal/tests/fake_subhal/Sensor.cpp
@@ -16,6 +16,7 @@
#include "Sensor.h"
+#include <hardware/sensors.h>
#include <utils/SystemClock.h>
#include <cmath>
@@ -31,14 +32,21 @@
using ::android::hardware::sensors::V1_0::SensorFlagBits;
using ::android::hardware::sensors::V1_0::SensorStatus;
-static constexpr float kDefaultMaxDelayUs = 10 * 1000 * 1000;
-
-Sensor::Sensor(ISensorsEventCallback* callback)
+Sensor::Sensor(int32_t sensorHandle, ISensorsEventCallback* callback)
: mIsEnabled(false),
mSamplingPeriodNs(0),
mLastSampleTimeNs(0),
mCallback(callback),
mMode(OperationMode::NORMAL) {
+ mSensorInfo.sensorHandle = sensorHandle;
+ mSensorInfo.vendor = "Vendor String";
+ mSensorInfo.version = 1;
+ constexpr float kDefaultMaxDelayUs = 1000 * 1000;
+ mSensorInfo.maxDelay = kDefaultMaxDelayUs;
+ mSensorInfo.fifoReservedEventCount = 0;
+ mSensorInfo.fifoMaxEventCount = 0;
+ mSensorInfo.requiredPermission = "";
+ mSensorInfo.flags = 0;
mRunThread = std::thread(startThread, this);
}
@@ -171,8 +179,10 @@
return result;
}
-OnChangeSensor::OnChangeSensor(ISensorsEventCallback* callback)
- : Sensor(callback), mPreviousEventSet(false) {}
+OnChangeSensor::OnChangeSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
+ : Sensor(sensorHandle, callback), mPreviousEventSet(false) {
+ mSensorInfo.flags |= SensorFlagBits::ON_CHANGE_MODE;
+}
void OnChangeSensor::activate(bool enable) {
Sensor::activate(enable);
@@ -196,175 +206,139 @@
return outputEvents;
}
-AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+ContinuousSensor::ContinuousSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
+ : Sensor(sensorHandle, callback) {
+ mSensorInfo.flags |= SensorFlagBits::CONTINUOUS_MODE;
+}
+
+AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
+ : ContinuousSensor(sensorHandle, callback) {
mSensorInfo.name = "Accel Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::ACCELEROMETER;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_ACCELEROMETER;
mSensorInfo.maxRange = 78.4f; // +/- 8g
mSensorInfo.resolution = 1.52e-5;
mSensorInfo.power = 0.001f; // mA
mSensorInfo.minDelay = 20 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::DATA_INJECTION);
-};
+ mSensorInfo.flags |= SensorFlagBits::DATA_INJECTION;
+}
+
+std::vector<Event> AccelSensor::readEvents() {
+ std::vector<Event> events;
+ Event event;
+ event.sensorHandle = mSensorInfo.sensorHandle;
+ event.sensorType = mSensorInfo.type;
+ event.timestamp = ::android::elapsedRealtimeNano();
+ event.u.vec3.x = 0;
+ event.u.vec3.y = 0;
+ event.u.vec3.z = -9.815;
+ event.u.vec3.status = SensorStatus::ACCURACY_HIGH;
+ events.push_back(event);
+ return events;
+}
PressureSensor::PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
- : Sensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+ : ContinuousSensor(sensorHandle, callback) {
mSensorInfo.name = "Pressure Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::PRESSURE;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_PRESSURE;
mSensorInfo.maxRange = 1100.0f; // hPa
mSensorInfo.resolution = 0.005f; // hPa
mSensorInfo.power = 0.001f; // mA
mSensorInfo.minDelay = 100 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = 0;
-};
+}
MagnetometerSensor::MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
- : Sensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+ : ContinuousSensor(sensorHandle, callback) {
mSensorInfo.name = "Magnetic Field Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::MAGNETIC_FIELD;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_MAGNETIC_FIELD;
mSensorInfo.maxRange = 1300.0f;
mSensorInfo.resolution = 0.01f;
mSensorInfo.power = 0.001f; // mA
mSensorInfo.minDelay = 20 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = 0;
-};
+}
LightSensor::LightSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
- : OnChangeSensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+ : OnChangeSensor(sensorHandle, callback) {
mSensorInfo.name = "Light Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::LIGHT;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_LIGHT;
mSensorInfo.maxRange = 43000.0f;
mSensorInfo.resolution = 10.0f;
mSensorInfo.power = 0.001f; // mA
mSensorInfo.minDelay = 200 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE);
-};
+}
ProximitySensor::ProximitySensor(int32_t sensorHandle, ISensorsEventCallback* callback)
- : OnChangeSensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+ : OnChangeSensor(sensorHandle, callback) {
mSensorInfo.name = "Proximity Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::PROXIMITY;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_PROXIMITY;
mSensorInfo.maxRange = 5.0f;
mSensorInfo.resolution = 1.0f;
mSensorInfo.power = 0.012f; // mA
mSensorInfo.minDelay = 200 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags =
- static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE | SensorFlagBits::WAKE_UP);
-};
+ mSensorInfo.flags |= SensorFlagBits::WAKE_UP;
+}
-GyroSensor::GyroSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+GyroSensor::GyroSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
+ : ContinuousSensor(sensorHandle, callback) {
mSensorInfo.name = "Gyro Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::GYROSCOPE;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_GYROSCOPE;
mSensorInfo.maxRange = 1000.0f * M_PI / 180.0f;
mSensorInfo.resolution = 1000.0f * M_PI / (180.0f * 32768.0f);
mSensorInfo.power = 0.001f;
mSensorInfo.minDelay = 2.5f * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = 0;
-};
+}
+
+std::vector<Event> GyroSensor::readEvents() {
+ std::vector<Event> events;
+ Event event;
+ event.sensorHandle = mSensorInfo.sensorHandle;
+ event.sensorType = mSensorInfo.type;
+ event.timestamp = ::android::elapsedRealtimeNano();
+ event.u.vec3.x = 0;
+ event.u.vec3.y = 0;
+ event.u.vec3.z = 0;
+ event.u.vec3.status = SensorStatus::ACCURACY_HIGH;
+ events.push_back(event);
+ return events;
+}
AmbientTempSensor::AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
- : OnChangeSensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+ : OnChangeSensor(sensorHandle, callback) {
mSensorInfo.name = "Ambient Temp Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::AMBIENT_TEMPERATURE;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE;
mSensorInfo.maxRange = 80.0f;
mSensorInfo.resolution = 0.01f;
mSensorInfo.power = 0.001f;
mSensorInfo.minDelay = 40 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE);
-};
+}
DeviceTempSensor::DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback)
- : OnChangeSensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+ : ContinuousSensor(sensorHandle, callback) {
mSensorInfo.name = "Device Temp Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::TEMPERATURE;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_TEMPERATURE;
mSensorInfo.maxRange = 80.0f;
mSensorInfo.resolution = 0.01f;
mSensorInfo.power = 0.001f;
mSensorInfo.minDelay = 40 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE);
}
RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle,
ISensorsEventCallback* callback)
- : OnChangeSensor(callback) {
- mSensorInfo.sensorHandle = sensorHandle;
+ : OnChangeSensor(sensorHandle, callback) {
mSensorInfo.name = "Relative Humidity Sensor";
- mSensorInfo.vendor = "Vendor String";
- mSensorInfo.version = 1;
mSensorInfo.type = SensorType::RELATIVE_HUMIDITY;
- mSensorInfo.typeAsString = "";
+ mSensorInfo.typeAsString = SENSOR_STRING_TYPE_RELATIVE_HUMIDITY;
mSensorInfo.maxRange = 100.0f;
mSensorInfo.resolution = 0.1f;
mSensorInfo.power = 0.001f;
mSensorInfo.minDelay = 40 * 1000; // microseconds
- mSensorInfo.maxDelay = kDefaultMaxDelayUs;
- mSensorInfo.fifoReservedEventCount = 0;
- mSensorInfo.fifoMaxEventCount = 0;
- mSensorInfo.requiredPermission = "";
- mSensorInfo.flags = static_cast<uint32_t>(SensorFlagBits::ON_CHANGE_MODE);
}
} // namespace implementation
diff --git a/sensors/2.0/multihal/tests/fake_subhal/Sensor.h b/sensors/2.0/multihal/tests/fake_subhal/Sensor.h
index 980ea54..60f5d3d 100644
--- a/sensors/2.0/multihal/tests/fake_subhal/Sensor.h
+++ b/sensors/2.0/multihal/tests/fake_subhal/Sensor.h
@@ -45,7 +45,7 @@
class Sensor {
public:
- Sensor(ISensorsEventCallback* callback);
+ Sensor(int32_t sensorHandle, ISensorsEventCallback* callback);
virtual ~Sensor();
const SensorInfo& getSensorInfo() const;
@@ -81,7 +81,7 @@
class OnChangeSensor : public Sensor {
public:
- OnChangeSensor(ISensorsEventCallback* callback);
+ OnChangeSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
virtual void activate(bool enable) override;
@@ -93,14 +93,40 @@
bool mPreviousEventSet;
};
-class AccelSensor : public Sensor {
+class ContinuousSensor : public Sensor {
public:
- AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
+ ContinuousSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
};
-class GyroSensor : public Sensor {
+class AccelSensor : public ContinuousSensor {
+ public:
+ AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
+
+ protected:
+ std::vector<Event> readEvents() override;
+};
+
+class GyroSensor : public ContinuousSensor {
public:
GyroSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
+
+ protected:
+ std::vector<Event> readEvents() override;
+};
+
+class DeviceTempSensor : public ContinuousSensor {
+ public:
+ DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
+};
+
+class PressureSensor : public ContinuousSensor {
+ public:
+ PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
+};
+
+class MagnetometerSensor : public ContinuousSensor {
+ public:
+ MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
};
class AmbientTempSensor : public OnChangeSensor {
@@ -108,21 +134,6 @@
AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
};
-class DeviceTempSensor : public OnChangeSensor {
- public:
- DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
-};
-
-class PressureSensor : public Sensor {
- public:
- PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
-};
-
-class MagnetometerSensor : public Sensor {
- public:
- MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
-};
-
class LightSensor : public OnChangeSensor {
public:
LightSensor(int32_t sensorHandle, ISensorsEventCallback* callback);
diff --git a/sensors/2.0/multihal/tests/fake_subhal/SensorsSubHal.cpp b/sensors/2.0/multihal/tests/fake_subhal/SensorsSubHal.cpp
index 0da4246..ff5ff38 100644
--- a/sensors/2.0/multihal/tests/fake_subhal/SensorsSubHal.cpp
+++ b/sensors/2.0/multihal/tests/fake_subhal/SensorsSubHal.cpp
@@ -172,11 +172,11 @@
AddSensor<GyroSensor>();
AddSensor<MagnetometerSensor>();
AddSensor<PressureSensor>();
+ AddSensor<DeviceTempSensor>();
}
OnChangeSensorsSubHal::OnChangeSensorsSubHal() {
AddSensor<AmbientTempSensor>();
- AddSensor<DeviceTempSensor>();
AddSensor<LightSensor>();
AddSensor<ProximitySensor>();
AddSensor<RelativeHumiditySensor>();
@@ -187,8 +187,8 @@
AddSensor<GyroSensor>();
AddSensor<MagnetometerSensor>();
AddSensor<PressureSensor>();
- AddSensor<AmbientTempSensor>();
AddSensor<DeviceTempSensor>();
+ AddSensor<AmbientTempSensor>();
AddSensor<LightSensor>();
AddSensor<ProximitySensor>();
AddSensor<RelativeHumiditySensor>();
diff --git a/weaver/1.0/vts/functional/Android.bp b/weaver/1.0/vts/functional/Android.bp
index 9fdbb18..3942deb 100644
--- a/weaver/1.0/vts/functional/Android.bp
+++ b/weaver/1.0/vts/functional/Android.bp
@@ -19,5 +19,5 @@
defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalWeaverV1_0TargetTest.cpp"],
static_libs: ["android.hardware.weaver@1.0"],
- test_suites: ["general-tests"],
+ test_suites: ["general-tests", "vts-core"],
}
diff --git a/weaver/1.0/vts/functional/VtsHalWeaverV1_0TargetTest.cpp b/weaver/1.0/vts/functional/VtsHalWeaverV1_0TargetTest.cpp
index de2a1de..ae92c36 100644
--- a/weaver/1.0/vts/functional/VtsHalWeaverV1_0TargetTest.cpp
+++ b/weaver/1.0/vts/functional/VtsHalWeaverV1_0TargetTest.cpp
@@ -15,12 +15,12 @@
*/
#include <android/hardware/weaver/1.0/IWeaver.h>
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
#include <limits>
-#include <VtsHalHidlTargetTestBase.h>
-#include <VtsHalHidlTargetTestEnvBase.h>
-
using ::android::hardware::weaver::V1_0::IWeaver;
using ::android::hardware::weaver::V1_0::WeaverConfig;
using ::android::hardware::weaver::V1_0::WeaverReadStatus;
@@ -34,22 +34,9 @@
const std::vector<uint8_t> VALUE{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
const std::vector<uint8_t> OTHER_VALUE{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 255, 255};
-// Test environment for Weaver HIDL HAL.
-class WeaverHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
- public:
- // get the test environment singleton
- static WeaverHidlEnvironment* Instance() {
- static WeaverHidlEnvironment* instance = new WeaverHidlEnvironment;
- return instance;
- }
-
- virtual void registerTestServices() override { registerTestService<IWeaver>(); }
-};
-
-struct WeaverHidlTest : public ::testing::VtsHalHidlTargetTestBase {
+struct WeaverHidlTest : public ::testing::TestWithParam<std::string> {
virtual void SetUp() override {
- weaver = ::testing::VtsHalHidlTargetTestBase::getService<IWeaver>(
- WeaverHidlEnvironment::Instance()->getServiceName<IWeaver>());
+ weaver = IWeaver::getService(GetParam());
ASSERT_NE(weaver, nullptr);
}
@@ -61,7 +48,7 @@
/*
* Checks config values are suitably large
*/
-TEST_F(WeaverHidlTest, GetConfig) {
+TEST_P(WeaverHidlTest, GetConfig) {
WeaverStatus status;
WeaverConfig config;
@@ -83,7 +70,7 @@
/*
* Gets the config twice and checks they are the same
*/
-TEST_F(WeaverHidlTest, GettingConfigMultipleTimesGivesSameResult) {
+TEST_P(WeaverHidlTest, GettingConfigMultipleTimesGivesSameResult) {
WeaverConfig config1;
WeaverConfig config2;
@@ -114,7 +101,7 @@
/*
* Gets the number of slots from the config and writes a key and value to the last one
*/
-TEST_F(WeaverHidlTest, WriteToLastSlot) {
+TEST_P(WeaverHidlTest, WriteToLastSlot) {
WeaverStatus status;
WeaverConfig config;
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
@@ -134,7 +121,7 @@
* Writes a key and value to a slot
* Reads the slot with the same key and receives the value that was previously written
*/
-TEST_F(WeaverHidlTest, WriteFollowedByReadGivesTheSameValue) {
+TEST_P(WeaverHidlTest, WriteFollowedByReadGivesTheSameValue) {
constexpr uint32_t slotId = 0;
const auto ret = weaver->write(slotId, KEY, VALUE);
ASSERT_TRUE(ret.isOk());
@@ -162,7 +149,7 @@
* Overwrites the slot with a new key and value
* Reads the slot with the new key and receives the new value
*/
-TEST_F(WeaverHidlTest, OverwritingSlotUpdatesTheValue) {
+TEST_P(WeaverHidlTest, OverwritingSlotUpdatesTheValue) {
constexpr uint32_t slotId = 0;
const auto initialWriteRet = weaver->write(slotId, WRONG_KEY, VALUE);
ASSERT_TRUE(initialWriteRet.isOk());
@@ -193,7 +180,7 @@
* Writes a key and value to a slot
* Reads the slot with a different key so does not receive the value
*/
-TEST_F(WeaverHidlTest, WriteFollowedByReadWithWrongKeyDoesNotGiveTheValue) {
+TEST_P(WeaverHidlTest, WriteFollowedByReadWithWrongKeyDoesNotGiveTheValue) {
constexpr uint32_t slotId = 0;
const auto ret = weaver->write(slotId, KEY, VALUE);
ASSERT_TRUE(ret.isOk());
@@ -217,7 +204,7 @@
/*
* Writing to an invalid slot fails
*/
-TEST_F(WeaverHidlTest, WritingToInvalidSlotFails) {
+TEST_P(WeaverHidlTest, WritingToInvalidSlotFails) {
WeaverStatus status;
WeaverConfig config;
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
@@ -240,7 +227,7 @@
/*
* Reading from an invalid slot fails rather than incorrect key
*/
-TEST_F(WeaverHidlTest, ReadingFromInvalidSlotFails) {
+TEST_P(WeaverHidlTest, ReadingFromInvalidSlotFails) {
WeaverStatus status;
WeaverConfig config;
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
@@ -276,7 +263,7 @@
/*
* Writing a key that is too large fails
*/
-TEST_F(WeaverHidlTest, WriteWithTooLargeKeyFails) {
+TEST_P(WeaverHidlTest, WriteWithTooLargeKeyFails) {
WeaverStatus status;
WeaverConfig config;
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
@@ -297,7 +284,7 @@
/*
* Writing a value that is too large fails
*/
-TEST_F(WeaverHidlTest, WriteWithTooLargeValueFails) {
+TEST_P(WeaverHidlTest, WriteWithTooLargeValueFails) {
WeaverStatus status;
WeaverConfig config;
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
@@ -318,7 +305,7 @@
/*
* Reading with a key that is loo large fails
*/
-TEST_F(WeaverHidlTest, ReadWithTooLargeKeyFails) {
+TEST_P(WeaverHidlTest, ReadWithTooLargeKeyFails) {
WeaverStatus status;
WeaverConfig config;
const auto configRet = weaver->getConfig([&](WeaverStatus s, WeaverConfig c) {
@@ -349,11 +336,7 @@
EXPECT_EQ(timeout, 0u);
}
-int main(int argc, char** argv) {
- ::testing::AddGlobalTestEnvironment(WeaverHidlEnvironment::Instance());
- ::testing::InitGoogleTest(&argc, argv);
- WeaverHidlEnvironment::Instance()->init(&argc, argv);
- int status = RUN_ALL_TESTS();
- ALOGI("Test result = %d", status);
- return status;
-}
+INSTANTIATE_TEST_SUITE_P(
+ PerInstance, WeaverHidlTest,
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(IWeaver::descriptor)),
+ android::hardware::PrintInstanceNameToString);