Remove vibrator@1.4 from VNDK.
am: 1784b9a3cf
Change-Id: Iabef3d7791d0019700aea416a716f0cca1455e46
diff --git a/audio/6.0/IDevice.hal b/audio/6.0/IDevice.hal
index 42a545b..e885fe2 100644
--- a/audio/6.0/IDevice.hal
+++ b/audio/6.0/IDevice.hal
@@ -260,7 +260,8 @@
/**
* Returns an array with available microphones in device.
*
- * @return retval INVALID_STATE if the call is not successful,
+ * @return retval NOT_SUPPORTED if there are no microphones on this device
+ * INVALID_STATE if the call is not successful,
* OK otherwise.
*
* @return microphones array with microphones info
diff --git a/audio/6.0/IStream.hal b/audio/6.0/IStream.hal
index f4c91f8..451e116 100644
--- a/audio/6.0/IStream.hal
+++ b/audio/6.0/IStream.hal
@@ -123,9 +123,11 @@
* equivalent to getting AUDIO_PARAMETER_STREAM_SUP_FORMATS on the legacy
* HAL.
*
+ * @return retval operation completion status.
* @return formats supported audio formats.
+ * Must be non empty if retval is OK.
*/
- getSupportedFormats() generates (vec<AudioFormat> formats);
+ getSupportedFormats() generates (Result retval, vec<AudioFormat> formats);
/**
* Sets the audio format of the stream. Calling this method is equivalent to
diff --git a/audio/common/all-versions/test/utility/include/utility/EnvironmentTearDown.h b/audio/common/all-versions/test/utility/include/utility/EnvironmentTearDown.h
index 0e416f3..2b240ce 100644
--- a/audio/common/all-versions/test/utility/include/utility/EnvironmentTearDown.h
+++ b/audio/common/all-versions/test/utility/include/utility/EnvironmentTearDown.h
@@ -20,9 +20,6 @@
#include <functional>
#include <list>
-#include <VtsHalHidlTargetTestEnvBase.h>
-#include <gtest/gtest.h>
-
namespace android {
namespace hardware {
namespace audio {
@@ -34,18 +31,20 @@
* Avoid destroying static objects after main return.
* Post main return destruction leads to incorrect gtest timing measurements as
* well as harder debuging if anything goes wrong during destruction. */
-class Environment : public ::testing::VtsHalHidlTargetTestEnvBase {
- public:
+class EnvironmentTearDown {
+ public:
using TearDownFunc = std::function<void()>;
void registerTearDown(TearDownFunc&& tearDown) { tearDowns.push_front(std::move(tearDown)); }
- private:
- void HidlTearDown() override {
+ protected:
+ void executeAllTearDowns() {
// Call the tear downs in reverse order of insertion
for (auto& tearDown : tearDowns) {
tearDown();
}
}
+
+ private:
std::list<TearDownFunc> tearDowns;
};
diff --git a/audio/core/all-versions/default/Stream.cpp b/audio/core/all-versions/default/Stream.cpp
index e62f6d3..5f24a5d 100644
--- a/audio/core/all-versions/default/Stream.cpp
+++ b/audio/core/all-versions/default/Stream.cpp
@@ -175,8 +175,17 @@
for (size_t i = 0; i < halFormats.size(); ++i) {
formats[i] = AudioFormat(halFormats[i]);
}
+ // Legacy get_parameter does not return a status_t, thus can not advertise of failure.
+ // Note that the method must not return an empty list if this capability is supported.
+ if (formats.size() == 0) {
+ result = Result::NOT_SUPPORTED;
+ }
}
+#if MAJOR_VERSION <= 5
_hidl_cb(formats);
+#elif MAJOR_VERSION >= 6
+ _hidl_cb(result, formats);
+#endif
return Void();
}
diff --git a/audio/core/all-versions/vts/functional/2.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/2.0/AudioPrimaryHidlHalTest.cpp
index 7906bf1..c189464 100644
--- a/audio/core/all-versions/vts/functional/2.0/AudioPrimaryHidlHalTest.cpp
+++ b/audio/core/all-versions/vts/functional/2.0/AudioPrimaryHidlHalTest.cpp
@@ -60,19 +60,20 @@
"deconnection",
testConnectedState(stream.get()))
-TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail", ASSERT_IS_OK(device->getHwAvSync()));
+TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail",
+ ASSERT_IS_OK(getDevice()->getHwAvSync()));
-TEST_F(AudioPrimaryHidlTest, setMode) {
+TEST_P(AudioPrimaryHidlTest, setMode) {
doc::test("Make sure setMode always succeeds if mode is valid and fails otherwise");
// Test Invalid values
for (AudioMode mode : {AudioMode::INVALID, AudioMode::CURRENT, AudioMode::CNT}) {
SCOPED_TRACE("mode=" + toString(mode));
- ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setMode(mode));
+ ASSERT_RESULT(Result::INVALID_ARGUMENTS, getDevice()->setMode(mode));
}
// Test valid values
for (AudioMode mode : {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION, AudioMode::RINGTONE,
AudioMode::NORMAL /* Make sure to leave the test in normal mode */}) {
SCOPED_TRACE("mode=" + toString(mode));
- ASSERT_OK(device->setMode(mode));
+ ASSERT_OK(getDevice()->setMode(mode));
}
}
diff --git a/audio/core/all-versions/vts/functional/2.0/EnvironmentTearDown.h b/audio/core/all-versions/vts/functional/2.0/EnvironmentTearDown.h
new file mode 100644
index 0000000..6373e39
--- /dev/null
+++ b/audio/core/all-versions/vts/functional/2.0/EnvironmentTearDown.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HARDWARE_AUDIO_CORE_2_0_ENVIRONMENT_TEARDOWN_H
+#define ANDROID_HARDWARE_AUDIO_CORE_2_0_ENVIRONMENT_TEARDOWN_H
+
+#include <VtsHalHidlTargetTestEnvBase.h>
+#include <gtest/gtest.h>
+
+#include "utility/EnvironmentTearDown.h"
+
+class Environment : public ::android::hardware::audio::common::test::utility::EnvironmentTearDown,
+ public ::testing::VtsHalHidlTargetTestEnvBase {
+ private:
+ void HidlTearDown() override {
+ executeAllTearDowns();
+ VtsHalHidlTargetTestEnvBase::HidlTearDown();
+ }
+};
+
+#endif // ANDROID_HARDWARE_AUDIO_CORE_2_0_ENVIRONMENT_TEARDOWN_H
diff --git a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp
index 15be3bf..e267a5e 100644
--- a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp
+++ b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp
@@ -16,28 +16,18 @@
#include "AudioPrimaryHidlHalTest.h"
-static void waitForDeviceDestruction() {
- // FIXME: there is no way to know when the remote IDevice is being destroyed
- // Binder does not support testing if an object is alive, thus
- // wait for 100ms to let the binder destruction propagates and
- // the remote device has the time to be destroyed.
- // flushCommand makes sure all local command are sent, thus should reduce
- // the latency between local and remote destruction.
- IPCThreadState::self()->flushCommands();
- usleep(100 * 1000);
-}
-
-TEST_F(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) {
+TEST_P(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) {
doc::test("Calling openDevice(\"primary\") should return the primary device.");
+ if (getDeviceName() != DeviceManager::kPrimaryDevice) {
+ GTEST_SKIP() << "No primary device on this factory"; // returns
+ }
+
struct WaitExecutor {
- ~WaitExecutor() { waitForDeviceDestruction(); }
+ ~WaitExecutor() { DeviceManager::waitForInstanceDestruction(); }
} waitExecutor; // Make sure we wait for the device destruction on exiting from the test.
Result result;
sp<IDevice> baseDevice;
- ASSERT_OK(devicesFactory->openDevice("primary", returnIn(result, baseDevice)));
- if (result != Result::OK && isPrimaryDeviceOptional()) {
- GTEST_SKIP() << "No primary device on this factory"; // returns
- }
+ ASSERT_OK(getDevicesFactory()->openDevice("primary", returnIn(result, baseDevice)));
ASSERT_OK(result);
ASSERT_TRUE(baseDevice != nullptr);
@@ -50,10 +40,13 @@
/////////////////////////// get(Active)Microphones ///////////////////////////
//////////////////////////////////////////////////////////////////////////////
-TEST_F(AudioPrimaryHidlTest, GetMicrophonesTest) {
+TEST_P(AudioHidlDeviceTest, GetMicrophonesTest) {
doc::test("Make sure getMicrophones always succeeds");
hidl_vec<MicrophoneInfo> microphones;
- ASSERT_OK(device->getMicrophones(returnIn(res, microphones)));
+ ASSERT_OK(getDevice()->getMicrophones(returnIn(res, microphones)));
+ if (res == Result::NOT_SUPPORTED) {
+ GTEST_SKIP() << "getMicrophones is not supported"; // returns
+ }
ASSERT_OK(res);
if (microphones.size() > 0) {
// When there is microphone on the phone, try to open an input stream
@@ -75,15 +68,15 @@
}
sp<IStreamIn> stream;
AudioConfig suggestedConfig{};
- ASSERT_OK(device->openInputStream(ioHandle, microphone.deviceAddress, config, flags,
- initMetadata,
- returnIn(res, stream, suggestedConfig)));
+ ASSERT_OK(getDevice()->openInputStream(ioHandle, microphone.deviceAddress, config,
+ flags, initMetadata,
+ returnIn(res, stream, suggestedConfig)));
if (res != Result::OK) {
ASSERT_TRUE(stream == nullptr);
AudioConfig suggestedConfigRetry{};
- ASSERT_OK(device->openInputStream(ioHandle, microphone.deviceAddress,
- suggestedConfig, flags, initMetadata,
- returnIn(res, stream, suggestedConfigRetry)));
+ ASSERT_OK(getDevice()->openInputStream(
+ ioHandle, microphone.deviceAddress, suggestedConfig, flags, initMetadata,
+ returnIn(res, stream, suggestedConfigRetry)));
}
ASSERT_OK(res);
hidl_vec<MicrophoneInfo> activeMicrophones;
@@ -131,7 +124,7 @@
}
}
-TEST_F(AudioPrimaryHidlTest, SetConnectedState) {
+TEST_P(AudioHidlDeviceTest, SetConnectedState) {
doc::test("Check that the HAL can be notified of device connection and deconnection");
using AD = AudioDevice;
for (auto deviceType : {AD::OUT_HDMI, AD::OUT_WIRED_HEADPHONE, AD::IN_USB_HEADSET}) {
@@ -140,7 +133,7 @@
SCOPED_TRACE("state=" + ::testing::PrintToString(state));
DeviceAddress address = {};
address.device = deviceType;
- auto ret = device->setConnectedState(address, state);
+ auto ret = getDevice()->setConnectedState(address, state);
ASSERT_TRUE(ret.isOk());
if (ret == Result::NOT_SUPPORTED) {
doc::partialTest("setConnectedState is not supported");
@@ -153,9 +146,7 @@
// Because there is no way of knowing if the devices were connected before
// calling setConnectedState, there is no way to restore the HAL to its
// initial state. To workaround this, destroy the HAL at the end of this test.
- device.clear();
- waitForDeviceDestruction();
- ASSERT_NO_FATAL_FAILURE(initPrimaryDevice());
+ ASSERT_TRUE(resetDevice());
}
static void testGetDevices(IStream* stream, AudioDevice expectedDevice) {
@@ -181,9 +172,10 @@
DeviceAddress otherAddress = address;
otherAddress.device = (address.device & AudioDevice::BIT_IN) == 0 ? AudioDevice::OUT_SPEAKER
: AudioDevice::IN_BUILTIN_MIC;
- EXPECT_OK(stream->setDevices({otherAddress}));
+ EXPECT_RESULT(okOrNotSupported, stream->setDevices({otherAddress}));
- ASSERT_OK(stream->setDevices({address})); // Go back to the original value
+ ASSERT_RESULT(okOrNotSupported,
+ stream->setDevices({address})); // Go back to the original value
}
TEST_IO_STREAM(SetDevices, "Check that the stream can be rerouted to SPEAKER or BUILTIN_MIC",
@@ -199,7 +191,7 @@
}
ASSERT_OK(res);
}
-TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail", checkGetHwAVSync(device.get()));
+TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail", checkGetHwAVSync(getDevice().get()));
TEST_P(InputStreamTest, updateSinkMetadata) {
doc::test("The HAL should not crash on metadata change");
@@ -259,58 +251,58 @@
ASSERT_OK(stream->updateSourceMetadata(initMetadata));
}
-TEST_F(AudioPrimaryHidlTest, setMode) {
+TEST_P(AudioPrimaryHidlTest, setMode) {
doc::test("Make sure setMode always succeeds if mode is valid and fails otherwise");
// Test Invalid values
for (int mode : {-2, -1, int(AudioMode::IN_COMMUNICATION) + 1}) {
- ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setMode(AudioMode(mode)))
- << "mode=" << mode;
+ ASSERT_RESULT(Result::INVALID_ARGUMENTS, getDevice()->setMode(AudioMode(mode)))
+ << "mode=" << mode;
}
// Test valid values
for (AudioMode mode : {AudioMode::IN_CALL, AudioMode::IN_COMMUNICATION, AudioMode::RINGTONE,
AudioMode::NORMAL /* Make sure to leave the test in normal mode */}) {
- ASSERT_OK(device->setMode(mode)) << "mode=" << toString(mode);
+ ASSERT_OK(getDevice()->setMode(mode)) << "mode=" << toString(mode);
}
}
-TEST_F(AudioPrimaryHidlTest, setBtHfpSampleRate) {
+TEST_P(AudioPrimaryHidlTest, setBtHfpSampleRate) {
doc::test(
"Make sure setBtHfpSampleRate either succeeds or "
"indicates that it is not supported at all, or that the provided value is invalid");
for (auto samplingRate : {8000, 16000, 22050, 24000}) {
- ASSERT_RESULT(okOrNotSupportedOrInvalidArgs, device->setBtHfpSampleRate(samplingRate));
+ ASSERT_RESULT(okOrNotSupportedOrInvalidArgs, getDevice()->setBtHfpSampleRate(samplingRate));
}
}
-TEST_F(AudioPrimaryHidlTest, setBtHfpVolume) {
+TEST_P(AudioPrimaryHidlTest, setBtHfpVolume) {
doc::test(
"Make sure setBtHfpVolume is either not supported or "
"only succeed if volume is in [0,1]");
- auto ret = device->setBtHfpVolume(0.0);
+ auto ret = getDevice()->setBtHfpVolume(0.0);
ASSERT_TRUE(ret.isOk());
if (ret == Result::NOT_SUPPORTED) {
doc::partialTest("setBtHfpVolume is not supported");
return;
}
- testUnitaryGain([](float volume) { return device->setBtHfpVolume(volume); });
+ testUnitaryGain([this](float volume) { return getDevice()->setBtHfpVolume(volume); });
}
-TEST_F(AudioPrimaryHidlTest, setBtScoHeadsetDebugName) {
+TEST_P(AudioPrimaryHidlTest, setBtScoHeadsetDebugName) {
doc::test(
"Make sure setBtScoHeadsetDebugName either succeeds or "
"indicates that it is not supported");
- ASSERT_RESULT(okOrNotSupported, device->setBtScoHeadsetDebugName("test"));
+ ASSERT_RESULT(okOrNotSupported, getDevice()->setBtScoHeadsetDebugName("test"));
}
-TEST_F(AudioPrimaryHidlTest, updateRotation) {
+TEST_P(AudioPrimaryHidlTest, updateRotation) {
doc::test("Check that the hal can receive the current rotation");
for (Rotation rotation : {Rotation::DEG_0, Rotation::DEG_90, Rotation::DEG_180,
Rotation::DEG_270, Rotation::DEG_0}) {
- ASSERT_RESULT(okOrNotSupported, device->updateRotation(rotation));
+ ASSERT_RESULT(okOrNotSupported, getDevice()->updateRotation(rotation));
}
}
-TEST_F(BoolAccessorPrimaryHidlTest, setGetBtHfpEnabled) {
+TEST_P(BoolAccessorPrimaryHidlTest, setGetBtHfpEnabled) {
doc::test("Query and set the BT HFP state");
testAccessors<OPTIONAL>("BtHfpEnabled", Initial{false, OPTIONAL}, {true},
&IPrimaryDevice::setBtHfpEnabled, &IPrimaryDevice::getBtHfpEnabled);
diff --git a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h
index 8415053..7a52d0e 100644
--- a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h
+++ b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h
@@ -75,11 +75,18 @@
return res;
}
+#if MAJOR_VERSION <= 5
static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
- // TODO: this should be an optional function
return Result::OK;
}
+#elif MAJOR_VERSION >= 6
+ static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
+ Result res;
+ EXPECT_OK(stream->getSupportedFormats(returnIn(res, capabilities)));
+ return res;
+ }
+#endif
};
template <class T>
diff --git a/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp
index 6314ea7..30f8a7a 100644
--- a/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp
+++ b/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp
@@ -16,3 +16,131 @@
// pull in all the <= 5.0 tests
#include "5.0/AudioPrimaryHidlHalTest.cpp"
+
+const std::vector<DeviceParameter>& getDeviceParametersForFactoryTests() {
+ static std::vector<DeviceParameter> parameters = [] {
+ std::vector<DeviceParameter> result;
+ const auto factories =
+ ::android::hardware::getAllHalInstanceNames(IDevicesFactory::descriptor);
+ for (const auto& factoryName : factories) {
+ result.emplace_back(factoryName,
+ DeviceManager::getInstance().getPrimary(factoryName) != nullptr
+ ? DeviceManager::kPrimaryDevice
+ : "");
+ }
+ return result;
+ }();
+ return parameters;
+}
+
+const std::vector<DeviceParameter>& getDeviceParametersForPrimaryDeviceTests() {
+ static std::vector<DeviceParameter> parameters = [] {
+ std::vector<DeviceParameter> result;
+ const auto primary = std::find_if(
+ getDeviceParameters().begin(), getDeviceParameters().end(), [](const auto& elem) {
+ return std::get<PARAM_DEVICE_NAME>(elem) == DeviceManager::kPrimaryDevice;
+ });
+ if (primary != getDeviceParameters().end()) result.push_back(*primary);
+ return result;
+ }();
+ return parameters;
+}
+
+const std::vector<DeviceParameter>& getDeviceParameters() {
+ static std::vector<DeviceParameter> parameters = [] {
+ std::vector<DeviceParameter> result;
+ const auto factories =
+ ::android::hardware::getAllHalInstanceNames(IDevicesFactory::descriptor);
+ const auto devices = getCachedPolicyConfig().getModulesWithDevicesNames();
+ result.reserve(devices.size());
+ for (const auto& factoryName : factories) {
+ for (const auto& deviceName : devices) {
+ if (DeviceManager::getInstance().get(factoryName, deviceName) != nullptr) {
+ result.emplace_back(factoryName, deviceName);
+ }
+ }
+ }
+ return result;
+ }();
+ return parameters;
+}
+
+const std::vector<DeviceConfigParameter>& getOutputDeviceConfigParameters() {
+ static std::vector<DeviceConfigParameter> parameters = [] {
+ std::vector<DeviceConfigParameter> result;
+ for (const auto& device : getDeviceParameters()) {
+ auto module =
+ getCachedPolicyConfig().getModuleFromName(std::get<PARAM_DEVICE_NAME>(device));
+ for (const auto& ioProfile : module->getOutputProfiles()) {
+ for (const auto& profile : ioProfile->getAudioProfiles()) {
+ const auto& channels = profile->getChannels();
+ const auto& sampleRates = profile->getSampleRates();
+ auto configs = ConfigHelper::combineAudioConfig(
+ vector<audio_channel_mask_t>(channels.begin(), channels.end()),
+ vector<uint32_t>(sampleRates.begin(), sampleRates.end()),
+ profile->getFormat());
+ auto flags = ioProfile->getFlags();
+ for (auto& config : configs) {
+ // Some combinations of flags declared in the config file require special
+ // treatment.
+ bool special = false;
+ if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
+ config.offloadInfo.sampleRateHz = config.sampleRateHz;
+ config.offloadInfo.channelMask = config.channelMask;
+ config.offloadInfo.format = config.format;
+ config.offloadInfo.streamType = AudioStreamType::MUSIC;
+ config.offloadInfo.bitRatePerSecond = 320;
+ config.offloadInfo.durationMicroseconds = -1;
+ config.offloadInfo.bitWidth = 16;
+ config.offloadInfo.bufferSize = 256; // arbitrary value
+ config.offloadInfo.usage = AudioUsage::MEDIA;
+ result.emplace_back(
+ device, config,
+ AudioOutputFlag(AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD));
+ special = true;
+ }
+ if ((flags & AUDIO_OUTPUT_FLAG_DIRECT) &&
+ !(flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC)) {
+ result.emplace_back(device, config,
+ AudioOutputFlag(AUDIO_OUTPUT_FLAG_DIRECT));
+ special = true;
+ }
+ if (flags & AUDIO_OUTPUT_FLAG_PRIMARY) { // ignore the flag
+ flags &= ~AUDIO_OUTPUT_FLAG_PRIMARY;
+ }
+ if (!special) {
+ result.emplace_back(device, config, AudioOutputFlag(flags));
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }();
+ return parameters;
+}
+
+const std::vector<DeviceConfigParameter>& getInputDeviceConfigParameters() {
+ static std::vector<DeviceConfigParameter> parameters = [] {
+ std::vector<DeviceConfigParameter> result;
+ for (const auto& device : getDeviceParameters()) {
+ auto module =
+ getCachedPolicyConfig().getModuleFromName(std::get<PARAM_DEVICE_NAME>(device));
+ for (const auto& ioProfile : module->getInputProfiles()) {
+ for (const auto& profile : ioProfile->getAudioProfiles()) {
+ const auto& channels = profile->getChannels();
+ const auto& sampleRates = profile->getSampleRates();
+ auto configs = ConfigHelper::combineAudioConfig(
+ vector<audio_channel_mask_t>(channels.begin(), channels.end()),
+ vector<uint32_t>(sampleRates.begin(), sampleRates.end()),
+ profile->getFormat());
+ for (const auto& config : configs) {
+ result.emplace_back(device, config, AudioInputFlag(ioProfile->getFlags()));
+ }
+ }
+ }
+ }
+ return result;
+ }();
+ return parameters;
+}
diff --git a/audio/core/all-versions/vts/functional/6.0/EnvironmentTearDown.h b/audio/core/all-versions/vts/functional/6.0/EnvironmentTearDown.h
new file mode 100644
index 0000000..593759f
--- /dev/null
+++ b/audio/core/all-versions/vts/functional/6.0/EnvironmentTearDown.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HARDWARE_AUDIO_CORE_6_0_ENVIRONMENT_TEARDOWN_H
+#define ANDROID_HARDWARE_AUDIO_CORE_6_0_ENVIRONMENT_TEARDOWN_H
+
+#include <gtest/gtest.h>
+
+#include "utility/EnvironmentTearDown.h"
+
+class Environment : public ::android::hardware::audio::common::test::utility::EnvironmentTearDown,
+ public ::testing::Environment {
+ public:
+ void init(int* /*argc*/, char** /*argv*/) {} // emulate VtsHalHidlTargetTestEnvBase
+ private:
+ void TearDown() override { executeAllTearDowns(); }
+};
+
+// FIXME: Will be removed while making getDeviceParameters to use the config
+static constexpr const char* kDefaultServiceName = "default";
+
+#endif // ANDROID_HARDWARE_AUDIO_CORE_6_0_ENVIRONMENT_TEARDOWN_H
diff --git a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
index 6c51c1b..468f9b2 100644
--- a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
+++ b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
@@ -23,7 +23,10 @@
#include <initializer_list>
#include <limits>
#include <list>
+#include <map>
+#include <set>
#include <string>
+#include <variant>
#include <vector>
#include <fcntl.h>
@@ -31,7 +34,9 @@
#include <hwbinder/IPCThreadState.h>
+#if MAJOR_VERSION <= 5
#include <VtsHalHidlTargetTestBase.h>
+#endif
#include <android-base/logging.h>
@@ -44,16 +49,25 @@
#include <Serializer.h>
#include <fmq/EventFlag.h>
#include <fmq/MessageQueue.h>
+#if MAJOR_VERSION >= 6
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
+#endif
#include <common/all-versions/VersionUtils.h>
#include "utility/AssertOk.h"
#include "utility/Documentation.h"
-#include "utility/EnvironmentTearDown.h"
#include "utility/PrettyPrintAudioTypes.h"
#include "utility/ReturnIn.h"
#include "utility/ValidateXml.h"
+#if MAJOR_VERSION <= 5
+#include "2.0/EnvironmentTearDown.h"
+#elif MAJOR_VERSION >= 6
+#include "6.0/EnvironmentTearDown.h"
+#endif
+
/** Provide version specific functions that are used in the generic tests */
#if MAJOR_VERSION == 2
#include "2.0/AudioPrimaryHidlHalUtils.h"
@@ -84,7 +98,9 @@
using ::android::hardware::MessageQueue;
using ::android::hardware::MQDescriptorSync;
using ::android::hardware::Return;
+using ::android::hardware::audio::common::utils::EnumBitfield;
using ::android::hardware::audio::common::utils::mkEnumBitfield;
+using ::android::hardware::details::toHexString;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::common::test::utility;
@@ -105,14 +121,43 @@
class AudioHidlTestEnvironment : public ::Environment {
public:
- virtual void registerTestServices() override { registerTestService<IDevicesFactory>(); }
+#if MAJOR_VERSION <= 5
+ void registerTestServices() override { registerTestService<IDevicesFactory>(); }
+#endif
};
// Instance to register global tearDown
static AudioHidlTestEnvironment* environment;
-class HidlTest : public ::testing::VtsHalHidlTargetTestBase {
- protected:
+#define AUDIO_PRIMARY_HIDL_HAL_TEST
+#include "DeviceManager.h"
+
+#if MAJOR_VERSION <= 5
+using HidlTestBase = ::testing::VtsHalHidlTargetTestBase;
+#elif MAJOR_VERSION >= 6
+using HidlTestBase = ::testing::Test;
+#endif
+
+class HidlTest : public HidlTestBase {
+ public:
+ virtual ~HidlTest() = default;
+
+ protected:
+ // Factory and device name getters to be overridden in subclasses.
+ virtual const std::string& getFactoryName() const = 0;
+ virtual const std::string& getDeviceName() const = 0;
+
+ sp<IDevicesFactory> getDevicesFactory() const {
+ return DevicesFactoryManager::getInstance().get(getFactoryName());
+ }
+ sp<IDevice> getDevice() const {
+ return DeviceManager::getInstance().get(getFactoryName(), getDeviceName());
+ }
+ bool resetDevice() const {
+ return DeviceManager::getInstance().reset(getFactoryName(), getDeviceName());
+ }
+ bool areAudioPatchesSupported() { return extract(getDevice()->supportsAudioPatches()); }
+
// Convenient member to store results
Result res;
};
@@ -158,7 +203,25 @@
}
mStatus = android::deserializeAudioPolicyFile(mFilePath.c_str(), this);
if (mStatus == OK) {
- mPrimaryModule = getHwModules().getModuleFromName("primary");
+ mPrimaryModule = getHwModules().getModuleFromName(DeviceManager::kPrimaryDevice);
+ // Available devices are not 'attached' to modules at this moment.
+ // Need to go over available devices and find their module.
+ for (const auto& device : availableOutputDevices) {
+ for (const auto& module : hwModules) {
+ if (module->getDeclaredDevices().indexOf(device) >= 0) {
+ mModulesWithDevicesNames.insert(module->getName());
+ break;
+ }
+ }
+ }
+ for (const auto& device : availableInputDevices) {
+ for (const auto& module : hwModules) {
+ if (module->getDeclaredDevices().indexOf(device) >= 0) {
+ mModulesWithDevicesNames.insert(module->getName());
+ break;
+ }
+ }
+ }
}
}
status_t getStatus() const { return mStatus; }
@@ -171,12 +234,19 @@
}
}
const std::string& getFilePath() const { return mFilePath; }
+ sp<const HwModule> getModuleFromName(const std::string& name) const {
+ return getHwModules().getModuleFromName(name.c_str());
+ }
sp<const HwModule> getPrimaryModule() const { return mPrimaryModule; }
+ const std::set<std::string>& getModulesWithDevicesNames() const {
+ return mModulesWithDevicesNames;
+ }
private:
status_t mStatus = NO_INIT;
std::string mFilePath;
sp<HwModule> mPrimaryModule = nullptr;
+ std::set<std::string> mModulesWithDevicesNames;
};
// Cached policy config after parsing for faster test startup
@@ -189,61 +259,113 @@
return *policyConfig;
}
-class AudioPolicyConfigTest : public HidlTest {
- public:
+class AudioPolicyConfigTest : public HidlTestBase {
+ public:
void SetUp() override {
- ASSERT_NO_FATAL_FAILURE(HidlTest::SetUp()); // setup base
-
+ ASSERT_NO_FATAL_FAILURE(HidlTestBase::SetUp()); // setup base
auto& policyConfig = getCachedPolicyConfig();
ASSERT_EQ(0, policyConfig.getStatus()) << policyConfig.getError();
-
- mPrimaryConfig = policyConfig.getPrimaryModule();
- ASSERT_TRUE(mPrimaryConfig) << "Could not find primary module in configuration file: "
- << policyConfig.getFilePath();
}
- sp<const HwModule> mPrimaryConfig = nullptr;
};
TEST_F(AudioPolicyConfigTest, LoadAudioPolicyXMLConfiguration) {
doc::test("Test parsing audio_policy_configuration.xml (called in SetUp)");
}
+TEST_F(AudioPolicyConfigTest, HasPrimaryModule) {
+ auto& policyConfig = getCachedPolicyConfig();
+ ASSERT_TRUE(policyConfig.getPrimaryModule() != nullptr)
+ << "Could not find primary module in configuration file: "
+ << policyConfig.getFilePath();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+//////////////////// Test parameter types and definitions ////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+enum { PARAM_FACTORY_NAME, PARAM_DEVICE_NAME };
+using DeviceParameter = std::tuple<std::string, std::string>;
+
+static inline std::string DeviceParameterToString(
+ const ::testing::TestParamInfo<DeviceParameter>& info) {
+ const auto& deviceName = std::get<PARAM_DEVICE_NAME>(info.param);
+#if MAJOR_VERSION <= 5
+ return !deviceName.empty() ? deviceName : std::to_string(info.index);
+#elif MAJOR_VERSION >= 6
+ const auto factoryName =
+ ::android::hardware::PrintInstanceNameToString(::testing::TestParamInfo<std::string>{
+ std::get<PARAM_FACTORY_NAME>(info.param), info.index});
+ return !deviceName.empty() ? factoryName + "_" + deviceName : factoryName;
+#endif
+}
+
+#if MAJOR_VERSION <= 5
+// For V2..5 the factory is looked up using the instance name passed
+// in the environment, only one factory is returned. This is because the VTS
+// framework will call the test for each instance. Only the primary device of
+// the default service factory can be tested.
+
+// Return a pair of <"default", "primary"> or <[non-default name], "">
+// This is used to parametrize device factory tests.
+// The device name is used to indicate whether IPrimaryDevice is required.
+const std::vector<DeviceParameter>& getDeviceParametersForFactoryTests() {
+ static std::vector<DeviceParameter> parameters = {
+ {environment->getServiceName<IDevicesFactory>(),
+ environment->getServiceName<IDevicesFactory>() == kDefaultServiceName
+ ? DeviceManager::kPrimaryDevice
+ : ""}};
+ return parameters;
+}
+// Return a pair of <"default", "primary"> or nothing.
+// This is used to parametrize primary device tests.
+const std::vector<DeviceParameter>& getDeviceParametersForPrimaryDeviceTests() {
+ static std::vector<DeviceParameter> parameters =
+ !std::get<PARAM_DEVICE_NAME>(*getDeviceParametersForFactoryTests().begin()).empty()
+ ? getDeviceParametersForFactoryTests()
+ : std::vector<DeviceParameter>{};
+ return parameters;
+}
+// In V2..5 device tests must only test the primary device.
+// No device tests are executed for non-primary devices.
+const std::vector<DeviceParameter>& getDeviceParameters() {
+ return getDeviceParametersForPrimaryDeviceTests();
+}
+#elif MAJOR_VERSION >= 6
+// For V6 and above these functions are implemented in 6.0/AudioPrimaryHidlHalTest.cpp
+const std::vector<DeviceParameter>& getDeviceParametersForFactoryTests();
+const std::vector<DeviceParameter>& getDeviceParametersForPrimaryDeviceTests();
+const std::vector<DeviceParameter>& getDeviceParameters();
+#endif
+
+class AudioHidlTestWithDeviceParameter : public HidlTest,
+ public ::testing::WithParamInterface<DeviceParameter> {
+ protected:
+ const std::string& getFactoryName() const override {
+ return std::get<PARAM_FACTORY_NAME>(GetParam());
+ }
+ const std::string& getDeviceName() const override {
+ return std::get<PARAM_DEVICE_NAME>(GetParam());
+ }
+};
+
//////////////////////////////////////////////////////////////////////////////
////////////////////// getService audio_devices_factory //////////////////////
//////////////////////////////////////////////////////////////////////////////
-// Test all audio devices
-class AudioHidlTest : public AudioPolicyConfigTest {
- public:
- static void SetUpTestSuite() {
- devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>(
- environment->getServiceName<IDevicesFactory>());
- }
-
- static void TearDownTestSuite() { devicesFactory.clear(); }
-
- void SetUp() override {
- ASSERT_NO_FATAL_FAILURE(AudioPolicyConfigTest::SetUp()); // setup base
- // Failures during SetUpTestSuite do not cause test termination.
- ASSERT_TRUE(devicesFactory != nullptr);
- }
-
- protected:
- // Cache the devicesFactory retrieval to speed up each test by ~0.5s
- static sp<IDevicesFactory> devicesFactory;
-
- static bool isPrimaryDeviceOptional() {
- // It's OK not to have "primary" device on non-default audio HAL service.
- return environment->getServiceName<IDevicesFactory>() != kDefaultServiceName;
+// Test audio devices factory
+class AudioHidlTest : public AudioHidlTestWithDeviceParameter {
+ public:
+ void SetUp() override {
+ ASSERT_NO_FATAL_FAILURE(AudioHidlTestWithDeviceParameter::SetUp()); // setup base
+ ASSERT_TRUE(getDevicesFactory() != nullptr);
}
};
-sp<IDevicesFactory> AudioHidlTest::devicesFactory;
-TEST_F(AudioHidlTest, GetAudioDevicesFactoryService) {
+TEST_P(AudioHidlTest, GetAudioDevicesFactoryService) {
doc::test("Test the getService");
}
-TEST_F(AudioHidlTest, OpenDeviceInvalidParameter) {
+TEST_P(AudioHidlTest, OpenDeviceInvalidParameter) {
doc::test("Test passing an invalid parameter to openDevice");
Result result;
sp<IDevice> device;
@@ -252,82 +374,80 @@
#elif MAJOR_VERSION >= 4
auto invalidDevice = "Non existing device";
#endif
- ASSERT_OK(devicesFactory->openDevice(invalidDevice, returnIn(result, device)));
+ ASSERT_OK(getDevicesFactory()->openDevice(invalidDevice, returnIn(result, device)));
ASSERT_EQ(Result::INVALID_ARGUMENTS, result);
ASSERT_TRUE(device == nullptr);
}
+INSTANTIATE_TEST_CASE_P(AudioHidl, AudioHidlTest,
+ ::testing::ValuesIn(getDeviceParametersForFactoryTests()),
+ &DeviceParameterToString);
+
+//////////////////////////////////////////////////////////////////////////////
+/////////////////////////////// openDevice ///////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+// Test all audio devices
+class AudioHidlDeviceTest : public AudioHidlTest {
+ public:
+ void SetUp() override {
+ ASSERT_NO_FATAL_FAILURE(AudioHidlTest::SetUp()); // setup base
+ ASSERT_TRUE(getDevice() != nullptr);
+ }
+};
+
+TEST_P(AudioHidlDeviceTest, OpenDevice) {
+ doc::test("Test openDevice (called during setup)");
+}
+
+TEST_P(AudioHidlDeviceTest, Init) {
+ doc::test("Test that the audio hal initialized correctly");
+ ASSERT_OK(getDevice()->initCheck());
+}
+
+INSTANTIATE_TEST_CASE_P(AudioHidlDevice, AudioHidlDeviceTest,
+ ::testing::ValuesIn(getDeviceParameters()), &DeviceParameterToString);
+
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////// openDevice primary ///////////////////////////
//////////////////////////////////////////////////////////////////////////////
// Test the primary device
-class AudioPrimaryHidlTest : public AudioHidlTest {
- public:
- static void SetUpTestSuite() {
- ASSERT_NO_FATAL_FAILURE(AudioHidlTest::SetUpTestSuite());
- ASSERT_NO_FATAL_FAILURE(initPrimaryDevice());
- }
-
- static void TearDownTestSuite() {
- device.clear();
- AudioHidlTest::TearDownTestSuite();
- }
-
+class AudioPrimaryHidlTest : public AudioHidlDeviceTest {
+ public:
void SetUp() override {
- ASSERT_NO_FATAL_FAILURE(AudioHidlTest::SetUp()); // setup base
- if (device == nullptr && isPrimaryDeviceOptional()) {
- GTEST_SKIP() << "No primary device on this factory";
- }
- ASSERT_TRUE(device != nullptr);
+ ASSERT_NO_FATAL_FAILURE(AudioHidlDeviceTest::SetUp()); // setup base
+ ASSERT_TRUE(getDevice() != nullptr);
}
- protected:
- // Cache the device opening to speed up each test by ~0.5s
- static sp<IPrimaryDevice> device;
-
- static void initPrimaryDevice() {
- // Failures during test suite set up do not cause test termination.
- ASSERT_TRUE(devicesFactory != nullptr);
- Result result;
-#if MAJOR_VERSION == 2
- sp<IDevice> baseDevice;
- ASSERT_OK(devicesFactory->openDevice(IDevicesFactory::Device::PRIMARY,
- returnIn(result, baseDevice)));
- ASSERT_OK(result);
- ASSERT_TRUE(baseDevice != nullptr);
-
- device = IPrimaryDevice::castFrom(baseDevice);
-#elif MAJOR_VERSION >= 4
- ASSERT_OK(devicesFactory->openPrimaryDevice(returnIn(result, device)));
- ASSERT_OK(result);
-#endif
+ protected:
+ sp<IPrimaryDevice> getDevice() const {
+ return DeviceManager::getInstance().getPrimary(getFactoryName());
}
};
-sp<IPrimaryDevice> AudioPrimaryHidlTest::device;
-TEST_F(AudioPrimaryHidlTest, OpenPrimaryDevice) {
- doc::test("Test the openDevice (called during setup)");
+TEST_P(AudioPrimaryHidlTest, OpenPrimaryDevice) {
+ doc::test("Test openPrimaryDevice (called during setup)");
}
-TEST_F(AudioPrimaryHidlTest, Init) {
- doc::test("Test that the audio primary hal initialized correctly");
- ASSERT_OK(device->initCheck());
-}
+INSTANTIATE_TEST_CASE_P(AudioPrimaryHidl, AudioPrimaryHidlTest,
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ &DeviceParameterToString);
//////////////////////////////////////////////////////////////////////////////
///////////////////// {set,get}{Master,Mic}{Mute,Volume} /////////////////////
//////////////////////////////////////////////////////////////////////////////
-template <class Property>
-class AccessorPrimaryHidlTest : public AudioPrimaryHidlTest {
- protected:
+template <class Property, class BaseTestClass = AudioHidlDeviceTest>
+class AccessorHidlTest : public BaseTestClass {
+ protected:
enum Optionality { REQUIRED, OPTIONAL };
struct Initial { // Initial property value
Initial(Property value, Optionality check = REQUIRED) : value(value), check(check) {}
Property value;
Optionality check; // If this initial value should be checked
};
+ using BaseTestClass::res;
/** Test a property getter and setter.
* The getter and/or the setter may return NOT_SUPPORTED if optionality == OPTIONAL.
*/
@@ -339,7 +459,7 @@
optionality == OPTIONAL ? Result::NOT_SUPPORTED : Result::OK};
Property initialValue = expectedInitial.value;
- ASSERT_OK((device.get()->*getter)(returnIn(res, initialValue)));
+ ASSERT_OK((BaseTestClass::getDevice().get()->*getter)(returnIn(res, initialValue)));
ASSERT_RESULT(expectedResults, res);
if (res == Result::OK && expectedInitial.check == REQUIRED) {
EXPECT_EQ(expectedInitial.value, initialValue);
@@ -350,7 +470,7 @@
for (Property setValue : valuesToTest) {
SCOPED_TRACE("Test " + propertyName + " getter and setter for " +
testing::PrintToString(setValue));
- auto ret = (device.get()->*setter)(setValue);
+ auto ret = (BaseTestClass::getDevice().get()->*setter)(setValue);
ASSERT_RESULT(expectedResults, ret);
if (ret == Result::NOT_SUPPORTED) {
doc::partialTest(propertyName + " setter is not supported");
@@ -358,7 +478,7 @@
}
Property getValue;
// Make sure the getter returns the same value just set
- ASSERT_OK((device.get()->*getter)(returnIn(res, getValue)));
+ ASSERT_OK((BaseTestClass::getDevice().get()->*getter)(returnIn(res, getValue)));
ASSERT_RESULT(expectedResults, res);
if (res == Result::NOT_SUPPORTED) {
doc::partialTest(propertyName + " getter is not supported");
@@ -370,31 +490,40 @@
for (Property invalidValue : invalidValues) {
SCOPED_TRACE("Try to set " + propertyName + " with the invalid value " +
testing::PrintToString(invalidValue));
- EXPECT_RESULT(invalidArgsOrNotSupported, (device.get()->*setter)(invalidValue));
+ EXPECT_RESULT(invalidArgsOrNotSupported,
+ (BaseTestClass::getDevice().get()->*setter)(invalidValue));
}
// Restore initial value
- EXPECT_RESULT(expectedResults, (device.get()->*setter)(initialValue));
+ EXPECT_RESULT(expectedResults, (BaseTestClass::getDevice().get()->*setter)(initialValue));
}
};
-using BoolAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<bool>;
+using BoolAccessorHidlTest = AccessorHidlTest<bool>;
+using BoolAccessorPrimaryHidlTest = AccessorHidlTest<bool, AudioPrimaryHidlTest>;
-TEST_F(BoolAccessorPrimaryHidlTest, MicMuteTest) {
+TEST_P(BoolAccessorHidlTest, MicMuteTest) {
doc::test("Check that the mic can be muted and unmuted");
- testAccessors("mic mute", Initial{false}, {true}, &IDevice::setMicMute, &IDevice::getMicMute);
+ testAccessors<OPTIONAL>("mic mute", Initial{false}, {true}, &IDevice::setMicMute,
+ &IDevice::getMicMute);
// TODO: check that the mic is really muted (all sample are 0)
}
-TEST_F(BoolAccessorPrimaryHidlTest, MasterMuteTest) {
+TEST_P(BoolAccessorHidlTest, MasterMuteTest) {
doc::test("If master mute is supported, try to mute and unmute the master output");
testAccessors<OPTIONAL>("master mute", Initial{false}, {true}, &IDevice::setMasterMute,
&IDevice::getMasterMute);
// TODO: check that the master volume is really muted
}
-using FloatAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<float>;
-TEST_F(FloatAccessorPrimaryHidlTest, MasterVolumeTest) {
+INSTANTIATE_TEST_CASE_P(BoolAccessorHidl, BoolAccessorHidlTest,
+ ::testing::ValuesIn(getDeviceParameters()), &DeviceParameterToString);
+INSTANTIATE_TEST_CASE_P(BoolAccessorPrimaryHidl, BoolAccessorPrimaryHidlTest,
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ &DeviceParameterToString);
+
+using FloatAccessorHidlTest = AccessorHidlTest<float>;
+TEST_P(FloatAccessorHidlTest, MasterVolumeTest) {
doc::test("Test the master volume if supported");
testAccessors<OPTIONAL>(
"master volume", Initial{1}, {0, 0.5}, &IDevice::setMasterVolume, &IDevice::getMasterVolume,
@@ -402,121 +531,135 @@
// TODO: check that the master volume is really changed
}
+INSTANTIATE_TEST_CASE_P(FloatAccessorHidl, FloatAccessorHidlTest,
+ ::testing::ValuesIn(getDeviceParameters()), &DeviceParameterToString);
+
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////// AudioPatches ////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-class AudioPatchPrimaryHidlTest : public AudioPrimaryHidlTest {
- protected:
- bool areAudioPatchesSupported() { return extract(device->supportsAudioPatches()); }
+class AudioPatchHidlTest : public AudioHidlDeviceTest {
+ public:
+ void SetUp() override {
+ ASSERT_NO_FATAL_FAILURE(AudioHidlDeviceTest::SetUp()); // setup base
+ if (!areAudioPatchesSupported()) {
+ GTEST_SKIP() << "Audio patches are not supported";
+ }
+ }
};
-TEST_F(AudioPatchPrimaryHidlTest, AudioPatches) {
+TEST_P(AudioPatchHidlTest, AudioPatches) {
doc::test("Test if audio patches are supported");
- if (!areAudioPatchesSupported()) {
- doc::partialTest("Audio patches are not supported");
- return;
- }
// TODO: test audio patches
}
-//////////////////////////////////////////////////////////////////////////////
-//////////////// Required and recommended audio format support ///////////////
-// From:
-// https://source.android.com/compatibility/android-cdd.html#5_4_audio_recording
-// From:
-// https://source.android.com/compatibility/android-cdd.html#5_5_audio_playback
-/////////// TODO: move to the beginning of the file for easier update ////////
-//////////////////////////////////////////////////////////////////////////////
+INSTANTIATE_TEST_CASE_P(AudioPatchHidl, AudioPatchHidlTest,
+ ::testing::ValuesIn(getDeviceParameters()), &DeviceParameterToString);
-class AudioConfigPrimaryTest : public AudioPatchPrimaryHidlTest {
- public:
- // for retro compatibility only test the primary device IN_BUILTIN_MIC
- // FIXME: in the next audio HAL version, test all available devices
- static bool primaryHasMic() {
- auto& policyConfig = getCachedPolicyConfig();
- if (policyConfig.getStatus() != OK || policyConfig.getPrimaryModule() == nullptr) {
- return true; // Could not get the information, run all tests
- }
- auto getMic = [](auto& devs) { return devs.getDevice(
- AUDIO_DEVICE_IN_BUILTIN_MIC, {}, AUDIO_FORMAT_DEFAULT); };
- auto primaryMic = getMic(policyConfig.getPrimaryModule()->getDeclaredDevices());
- auto availableMic = getMic(policyConfig.getAvailableInputDevices());
+// Nesting a tuple in another tuple allows to use GTest Combine function to generate
+// all combinations of devices and configs.
+enum { PARAM_DEVICE, PARAM_CONFIG, PARAM_FLAGS };
+enum { INDEX_INPUT, INDEX_OUTPUT };
+using DeviceConfigParameter =
+ std::tuple<DeviceParameter, AudioConfig, std::variant<AudioInputFlag, AudioOutputFlag>>;
- return primaryMic != nullptr && primaryMic->equals(availableMic);
- }
+#if MAJOR_VERSION >= 6
+const std::vector<DeviceConfigParameter>& getInputDeviceConfigParameters();
+const std::vector<DeviceConfigParameter>& getOutputDeviceConfigParameters();
+#endif
- // Cache result ?
- static const vector<AudioConfig> getRequiredSupportPlaybackAudioConfig() {
- return combineAudioConfig({AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO},
- {8000, 11025, 16000, 22050, 32000, 44100},
- {AudioFormat::PCM_16_BIT});
+#if MAJOR_VERSION >= 4
+static string SanitizeStringForGTestName(const string& s) {
+ string result = s;
+ for (size_t i = 0; i < result.size(); i++) {
+ // gtest test names must only contain alphanumeric characters
+ if (!std::isalnum(result[i])) result[i] = '_';
}
-
- static const vector<AudioConfig> getRecommendedSupportPlaybackAudioConfig() {
- return combineAudioConfig({AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO},
- {24000, 48000}, {AudioFormat::PCM_16_BIT});
- }
-
- static const vector<AudioConfig> getSupportedPlaybackAudioConfig() {
- // TODO: retrieve audio config supported by the platform
- // as declared in the policy configuration
- return {};
- }
-
- static const vector<AudioConfig> getRequiredSupportCaptureAudioConfig() {
- if (!primaryHasMic()) return {};
- return combineAudioConfig({AudioChannelMask::IN_MONO}, {8000, 11025, 16000, 44100},
- {AudioFormat::PCM_16_BIT});
- }
- static const vector<AudioConfig> getRecommendedSupportCaptureAudioConfig() {
- if (!primaryHasMic()) return {};
- return combineAudioConfig({AudioChannelMask::IN_STEREO}, {22050, 48000},
- {AudioFormat::PCM_16_BIT});
- }
- static const vector<AudioConfig> getSupportedCaptureAudioConfig() {
- // TODO: retrieve audio config supported by the platform
- // as declared in the policy configuration
- return {};
- }
-
- private:
- static const vector<AudioConfig> combineAudioConfig(vector<AudioChannelMask> channelMasks,
- vector<uint32_t> sampleRates,
- vector<AudioFormat> formats) {
- vector<AudioConfig> configs;
- for (auto channelMask : channelMasks) {
- for (auto sampleRate : sampleRates) {
- for (auto format : formats) {
- AudioConfig config{};
- // leave offloadInfo to 0
- config.channelMask = mkEnumBitfield(channelMask);
- config.sampleRateHz = sampleRate;
- config.format = format;
- // FIXME: leave frameCount to 0 ?
- configs.push_back(config);
- }
- }
- }
- return configs;
- }
-};
+ return result;
+}
+#endif
/** Generate a test name based on an audio config.
*
* As the only parameter changing are channel mask and sample rate,
* only print those ones in the test name.
*/
-static string generateTestName(const testing::TestParamInfo<AudioConfig>& info) {
- const AudioConfig& config = info.param;
- return to_string(info.index) + "__" + to_string(config.sampleRateHz) + "_" +
+static string DeviceConfigParameterToString(
+ const testing::TestParamInfo<DeviceConfigParameter>& info) {
+ const AudioConfig& config = std::get<PARAM_CONFIG>(info.param);
+ const auto deviceName = DeviceParameterToString(::testing::TestParamInfo<DeviceParameter>{
+ std::get<PARAM_DEVICE>(info.param), info.index});
+ return (deviceName.empty() ? "" : deviceName + "_") + to_string(info.index) + "__" +
+ to_string(config.sampleRateHz) + "_" +
// "MONO" is more clear than "FRONT_LEFT"
((config.channelMask == mkEnumBitfield(AudioChannelMask::OUT_MONO) ||
config.channelMask == mkEnumBitfield(AudioChannelMask::IN_MONO))
- ? "MONO"
- : ::testing::PrintToString(config.channelMask));
+ ? "MONO"
+#if MAJOR_VERSION == 2
+ : ::testing::PrintToString(config.channelMask)
+#elif MAJOR_VERSION >= 4
+ // In V4 and above the channel mask is a bitfield.
+ // Printing its value using HIDL's toString for a bitfield emits a lot of extra
+ // text due to overlapping constant values. Instead, we print the bitfield value
+ // as if it was a single value + its hex representation
+ : SanitizeStringForGTestName(
+ ::testing::PrintToString(AudioChannelMask(config.channelMask)) + "_" +
+ toHexString(config.channelMask))
+#endif
+ ) +
+ "_" +
+#if MAJOR_VERSION == 2
+ std::visit([](auto&& arg) -> std::string { return ::testing::PrintToString(arg); },
+ std::get<PARAM_FLAGS>(info.param));
+#elif MAJOR_VERSION >= 4
+ SanitizeStringForGTestName(std::visit(
+ [](auto&& arg) -> std::string {
+ using T = std::decay_t<decltype(arg)>;
+ // Need to use FQN of toString to avoid confusing the compiler
+ return ::android::hardware::audio::common::CPP_VERSION::toString<T>(
+ hidl_bitfield<T>(arg));
+ },
+ std::get<PARAM_FLAGS>(info.param)));
+#endif
}
+class AudioHidlTestWithDeviceConfigParameter
+ : public HidlTest,
+ public ::testing::WithParamInterface<DeviceConfigParameter> {
+ protected:
+ void SetUp() override {
+ ASSERT_NO_FATAL_FAILURE(HidlTest::SetUp()); // setup base
+ ASSERT_TRUE(getDevicesFactory() != nullptr);
+ ASSERT_TRUE(getDevice() != nullptr);
+ }
+ const std::string& getFactoryName() const override {
+ return std::get<PARAM_FACTORY_NAME>(std::get<PARAM_DEVICE>(GetParam()));
+ }
+ const std::string& getDeviceName() const override {
+ return std::get<PARAM_DEVICE_NAME>(std::get<PARAM_DEVICE>(GetParam()));
+ }
+ const AudioConfig& getConfig() const { return std::get<PARAM_CONFIG>(GetParam()); }
+#if MAJOR_VERSION == 2
+ AudioInputFlag getInputFlags() const {
+ return std::get<INDEX_INPUT>(std::get<PARAM_FLAGS>(GetParam()));
+ }
+ AudioOutputFlag getOutputFlags() const {
+ return std::get<INDEX_OUTPUT>(std::get<PARAM_FLAGS>(GetParam()));
+ }
+#elif MAJOR_VERSION >= 4
+ hidl_bitfield<AudioInputFlag> getInputFlags() const {
+ return hidl_bitfield<AudioInputFlag>(
+ std::get<INDEX_INPUT>(std::get<PARAM_FLAGS>(GetParam())));
+ }
+ hidl_bitfield<AudioOutputFlag> getOutputFlags() const {
+ return hidl_bitfield<AudioOutputFlag>(
+ std::get<INDEX_OUTPUT>(std::get<PARAM_FLAGS>(GetParam())));
+ }
+#endif
+};
+
+#include "ConfigHelper.h"
+
//////////////////////////////////////////////////////////////////////////////
///////////////////////////// getInputBufferSize /////////////////////////////
//////////////////////////////////////////////////////////////////////////////
@@ -525,12 +668,11 @@
// android.hardware.microphone
// how to get this value ? is it a property ???
-class AudioCaptureConfigPrimaryTest : public AudioConfigPrimaryTest,
- public ::testing::WithParamInterface<AudioConfig> {
- protected:
+class AudioCaptureConfigTest : public AudioHidlTestWithDeviceConfigParameter {
+ protected:
void inputBufferSizeTest(const AudioConfig& audioConfig, bool supportRequired) {
uint64_t bufferSize;
- ASSERT_OK(device->getInputBufferSize(audioConfig, returnIn(res, bufferSize)));
+ ASSERT_OK(getDevice()->getInputBufferSize(audioConfig, returnIn(res, bufferSize)));
switch (res) {
case Result::INVALID_ARGUMENTS:
@@ -549,44 +691,60 @@
// Test that the required capture config and those declared in the policy are
// indeed supported
-class RequiredInputBufferSizeTest : public AudioCaptureConfigPrimaryTest {};
+class RequiredInputBufferSizeTest : public AudioCaptureConfigTest {};
TEST_P(RequiredInputBufferSizeTest, RequiredInputBufferSizeTest) {
doc::test(
"Input buffer size must be retrievable for a format with required "
"support.");
- inputBufferSizeTest(GetParam(), true);
+ inputBufferSizeTest(getConfig(), true);
}
-INSTANTIATE_TEST_CASE_P(
- RequiredInputBufferSize, RequiredInputBufferSizeTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getRequiredSupportCaptureAudioConfig()),
- &generateTestName);
-INSTANTIATE_TEST_CASE_P(
- SupportedInputBufferSize, RequiredInputBufferSizeTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getSupportedCaptureAudioConfig()),
- &generateTestName);
// Test that the recommended capture config are supported or lead to a
// INVALID_ARGUMENTS return
-class OptionalInputBufferSizeTest : public AudioCaptureConfigPrimaryTest {};
+class OptionalInputBufferSizeTest : public AudioCaptureConfigTest {};
TEST_P(OptionalInputBufferSizeTest, OptionalInputBufferSizeTest) {
doc::test(
- "Input buffer size should be retrievable for a format with recommended "
- "support.");
- inputBufferSizeTest(GetParam(), false);
+ "Input buffer size should be retrievable for a format with recommended "
+ "support.");
+ inputBufferSizeTest(getConfig(), false);
}
+
+#if MAJOR_VERSION <= 5
+// For V2..5 test the primary device according to CDD requirements.
INSTANTIATE_TEST_CASE_P(
- RecommendedCaptureAudioConfigSupport, OptionalInputBufferSizeTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getRecommendedSupportCaptureAudioConfig()),
- &generateTestName);
+ RequiredInputBufferSize, RequiredInputBufferSizeTest,
+ ::testing::Combine(
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ ::testing::ValuesIn(ConfigHelper::getRequiredSupportCaptureAudioConfig()),
+ ::testing::Values(AudioInputFlag::NONE)),
+ &DeviceConfigParameterToString);
+INSTANTIATE_TEST_CASE_P(
+ SupportedInputBufferSize, RequiredInputBufferSizeTest,
+ ::testing::Combine(::testing::ValuesIn(getDeviceParameters()),
+ ::testing::ValuesIn(ConfigHelper::getSupportedCaptureAudioConfig()),
+ ::testing::Values(AudioInputFlag::NONE)),
+ &DeviceConfigParameterToString);
+INSTANTIATE_TEST_CASE_P(
+ RecommendedCaptureAudioConfigSupport, OptionalInputBufferSizeTest,
+ ::testing::Combine(
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ ::testing::ValuesIn(ConfigHelper::getRecommendedSupportCaptureAudioConfig()),
+ ::testing::Values(AudioInputFlag::NONE)),
+ &DeviceConfigParameterToString);
+#elif MAJOR_VERSION >= 6
+INSTANTIATE_TEST_CASE_P(SupportedInputBufferSize, RequiredInputBufferSizeTest,
+ ::testing::ValuesIn(getInputDeviceConfigParameters()),
+ &DeviceConfigParameterToString);
+#endif
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////// setScreenState ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-TEST_F(AudioPrimaryHidlTest, setScreenState) {
+TEST_P(AudioHidlDeviceTest, setScreenState) {
doc::test("Check that the hal can receive the screen state");
for (bool turnedOn : {false, true, true, false, false}) {
- ASSERT_RESULT(okOrNotSupported, device->setScreenState(turnedOn));
+ ASSERT_RESULT(okOrNotSupported, getDevice()->setScreenState(turnedOn));
}
}
@@ -594,15 +752,16 @@
//////////////////////////// {get,set}Parameters /////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-TEST_F(AudioPrimaryHidlTest, getParameters) {
+TEST_P(AudioHidlDeviceTest, getParameters) {
doc::test("Check that the hal can set and get parameters");
hidl_vec<ParameterValue> context;
hidl_vec<hidl_string> keys;
hidl_vec<ParameterValue> values;
- ASSERT_OK(Parameters::get(device, keys, returnIn(res, values)));
- ASSERT_OK(Parameters::set(device, values));
+ ASSERT_OK(Parameters::get(getDevice(), keys, returnIn(res, values)));
+ ASSERT_RESULT(okOrNotSupported, res);
+ ASSERT_RESULT(okOrNotSupported, Parameters::set(getDevice(), values));
values.resize(0);
- ASSERT_OK(Parameters::set(device, values));
+ ASSERT_RESULT(okOrNotSupported, Parameters::set(getDevice(), values));
}
//////////////////////////////////////////////////////////////////////////////
@@ -643,14 +802,14 @@
EXPECT_EQ(0, close(fds[1])) << errno;
}
-TEST_F(AudioPrimaryHidlTest, DebugDump) {
+TEST_P(AudioHidlDeviceTest, DebugDump) {
doc::test("Check that the hal can dump its state without error");
- testDebugDump([](const auto& handle) { return dump(device, handle); });
+ testDebugDump([this](const auto& handle) { return dump(getDevice(), handle); });
}
-TEST_F(AudioPrimaryHidlTest, DebugDumpInvalidArguments) {
+TEST_P(AudioHidlDeviceTest, DebugDumpInvalidArguments) {
doc::test("Check that the hal dump doesn't crash on invalid arguments");
- ASSERT_OK(dump(device, hidl_handle()));
+ ASSERT_OK(dump(getDevice(), hidl_handle()));
}
//////////////////////////////////////////////////////////////////////////////
@@ -658,9 +817,8 @@
//////////////////////////////////////////////////////////////////////////////
template <class Stream>
-class OpenStreamTest : public AudioConfigPrimaryTest,
- public ::testing::WithParamInterface<AudioConfig> {
- protected:
+class OpenStreamTest : public AudioHidlTestWithDeviceConfigParameter {
+ protected:
template <class Open>
void testOpen(Open openStream, const AudioConfig& config) {
// FIXME: Open a stream without an IOHandle
@@ -701,7 +859,7 @@
return res;
}
- void waitForStreamDestruction() {
+ static void waitForStreamDestruction() {
// FIXME: there is no way to know when the remote IStream is being destroyed
// Binder does not support testing if an object is alive, thus
// wait for 100ms to let the binder destruction propagates and
@@ -712,12 +870,12 @@
usleep(100 * 1000);
}
- private:
+ private:
void TearDown() override {
if (open) {
ASSERT_OK(closeStream());
}
- AudioConfigPrimaryTest::TearDown();
+ AudioHidlTestWithDeviceConfigParameter::TearDown();
}
protected:
@@ -732,20 +890,19 @@
class OutputStreamTest : public OpenStreamTest<IStreamOut> {
void SetUp() override {
ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base
- if (IsSkipped()) return; // do not attempt to use 'device'
address.device = AudioDevice::OUT_DEFAULT;
- const AudioConfig& config = GetParam();
- // TODO: test all flag combination
- auto flags = mkEnumBitfield(AudioOutputFlag::NONE);
+ const AudioConfig& config = getConfig();
+ auto flags = getOutputFlags();
testOpen(
- [&](AudioIoHandle handle, AudioConfig config, auto cb) {
+ [&](AudioIoHandle handle, AudioConfig config, auto cb) {
#if MAJOR_VERSION == 2
- return device->openOutputStream(handle, address, config, flags, cb);
+ return getDevice()->openOutputStream(handle, address, config, flags, cb);
#elif MAJOR_VERSION >= 4
- return device->openOutputStream(handle, address, config, flags, initMetadata, cb);
+ return getDevice()->openOutputStream(handle, address, config, flags,
+ initMetadata, cb);
#endif
- },
- config);
+ },
+ config);
}
#if MAJOR_VERSION >= 4
@@ -762,35 +919,52 @@
"recommended config");
// Open done in SetUp
}
-INSTANTIATE_TEST_CASE_P(
- RequiredOutputStreamConfigSupport, OutputStreamTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getRequiredSupportPlaybackAudioConfig()),
- &generateTestName);
-INSTANTIATE_TEST_CASE_P(
- SupportedOutputStreamConfig, OutputStreamTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getSupportedPlaybackAudioConfig()),
- &generateTestName);
+#if MAJOR_VERSION <= 5
+// For V2..5 test the primary device according to CDD requirements.
INSTANTIATE_TEST_CASE_P(
- RecommendedOutputStreamConfigSupport, OutputStreamTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getRecommendedSupportPlaybackAudioConfig()),
- &generateTestName);
+ RequiredOutputStreamConfigSupport, OutputStreamTest,
+ ::testing::Combine(
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ ::testing::ValuesIn(ConfigHelper::getRequiredSupportPlaybackAudioConfig()),
+ ::testing::Values(AudioOutputFlag::NONE)),
+ &DeviceConfigParameterToString);
+INSTANTIATE_TEST_CASE_P(
+ SupportedOutputStreamConfig, OutputStreamTest,
+ ::testing::Combine(::testing::ValuesIn(getDeviceParameters()),
+ ::testing::ValuesIn(ConfigHelper::getSupportedPlaybackAudioConfig()),
+ ::testing::Values(AudioOutputFlag::NONE)),
+ &DeviceConfigParameterToString);
+INSTANTIATE_TEST_CASE_P(
+ RecommendedOutputStreamConfigSupport, OutputStreamTest,
+ ::testing::Combine(
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ ::testing::ValuesIn(ConfigHelper::getRecommendedSupportPlaybackAudioConfig()),
+ ::testing::Values(AudioOutputFlag::NONE)),
+ &DeviceConfigParameterToString);
+#elif MAJOR_VERSION >= 6
+// For V6 and above test according to the audio policy manager configuration.
+// This is more correct as CDD is written from the apps perspective.
+// Audio system provides necessary format conversions for the missing configurations.
+INSTANTIATE_TEST_CASE_P(DeclaredOutputStreamConfigSupport, OutputStreamTest,
+ ::testing::ValuesIn(getOutputDeviceConfigParameters()),
+ &DeviceConfigParameterToString);
+#endif
////////////////////////////// openInputStream //////////////////////////////
class InputStreamTest : public OpenStreamTest<IStreamIn> {
void SetUp() override {
ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base
- if (IsSkipped()) return; // do not attempt to use 'device'
address.device = AudioDevice::IN_DEFAULT;
- const AudioConfig& config = GetParam();
- // TODO: test all supported flags and source
- auto flags = mkEnumBitfield(AudioInputFlag::NONE);
+ const AudioConfig& config = getConfig();
+ auto flags = getInputFlags();
testOpen(
- [&](AudioIoHandle handle, AudioConfig config, auto cb) {
- return device->openInputStream(handle, address, config, flags, initMetadata, cb);
- },
- config);
+ [&](AudioIoHandle handle, AudioConfig config, auto cb) {
+ return getDevice()->openInputStream(handle, address, config, flags,
+ initMetadata, cb);
+ },
+ config);
}
protected:
@@ -807,19 +981,36 @@
"recommended config");
// Open done in setup
}
+#if MAJOR_VERSION <= 5
+// For V2..5 test the primary device according to CDD requirements.
INSTANTIATE_TEST_CASE_P(
- RequiredInputStreamConfigSupport, InputStreamTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getRequiredSupportCaptureAudioConfig()),
- &generateTestName);
+ RequiredInputStreamConfigSupport, InputStreamTest,
+ ::testing::Combine(
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ ::testing::ValuesIn(ConfigHelper::getRequiredSupportCaptureAudioConfig()),
+ ::testing::Values(AudioInputFlag::NONE)),
+ &DeviceConfigParameterToString);
INSTANTIATE_TEST_CASE_P(
- SupportedInputStreamConfig, InputStreamTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getSupportedCaptureAudioConfig()),
- &generateTestName);
-
+ SupportedInputStreamConfig, InputStreamTest,
+ ::testing::Combine(::testing::ValuesIn(getDeviceParameters()),
+ ::testing::ValuesIn(ConfigHelper::getSupportedCaptureAudioConfig()),
+ ::testing::Values(AudioInputFlag::NONE)),
+ &DeviceConfigParameterToString);
INSTANTIATE_TEST_CASE_P(
- RecommendedInputStreamConfigSupport, InputStreamTest,
- ::testing::ValuesIn(AudioConfigPrimaryTest::getRecommendedSupportCaptureAudioConfig()),
- &generateTestName);
+ RecommendedInputStreamConfigSupport, InputStreamTest,
+ ::testing::Combine(
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ ::testing::ValuesIn(ConfigHelper::getRecommendedSupportCaptureAudioConfig()),
+ ::testing::Values(AudioInputFlag::NONE)),
+ &DeviceConfigParameterToString);
+#elif MAJOR_VERSION >= 6
+// For V6 and above test according to the audio policy manager configuration.
+// This is more correct as CDD is written from the apps perspective.
+// Audio system provides necessary format conversions for the missing configurations.
+INSTANTIATE_TEST_CASE_P(DeclaredInputStreamConfigSupport, InputStreamTest,
+ ::testing::ValuesIn(getInputDeviceConfigParameters()),
+ &DeviceConfigParameterToString);
+#endif
//////////////////////////////////////////////////////////////////////////////
////////////////////////////// IStream getters ///////////////////////////////
@@ -1332,35 +1523,39 @@
/////////////////////////////// PrimaryDevice ////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-TEST_F(AudioPrimaryHidlTest, setVoiceVolume) {
+TEST_P(AudioPrimaryHidlTest, setVoiceVolume) {
doc::test("Make sure setVoiceVolume only succeed if volume is in [0,1]");
- testUnitaryGain([](float volume) { return device->setVoiceVolume(volume); });
+ testUnitaryGain([this](float volume) { return getDevice()->setVoiceVolume(volume); });
}
-TEST_F(BoolAccessorPrimaryHidlTest, BtScoNrecEnabled) {
+TEST_P(BoolAccessorPrimaryHidlTest, BtScoNrecEnabled) {
doc::test("Query and set the BT SCO NR&EC state");
testAccessors<OPTIONAL>("BtScoNrecEnabled", Initial{false, OPTIONAL}, {true},
&IPrimaryDevice::setBtScoNrecEnabled,
&IPrimaryDevice::getBtScoNrecEnabled);
}
-TEST_F(BoolAccessorPrimaryHidlTest, setGetBtScoWidebandEnabled) {
+TEST_P(BoolAccessorPrimaryHidlTest, setGetBtScoWidebandEnabled) {
doc::test("Query and set the SCO whideband state");
testAccessors<OPTIONAL>("BtScoWideband", Initial{false, OPTIONAL}, {true},
&IPrimaryDevice::setBtScoWidebandEnabled,
&IPrimaryDevice::getBtScoWidebandEnabled);
}
-using TtyModeAccessorPrimaryHidlTest = AccessorPrimaryHidlTest<IPrimaryDevice::TtyMode>;
-TEST_F(TtyModeAccessorPrimaryHidlTest, setGetTtyMode) {
+using TtyModeAccessorPrimaryHidlTest =
+ AccessorHidlTest<IPrimaryDevice::TtyMode, AudioPrimaryHidlTest>;
+TEST_P(TtyModeAccessorPrimaryHidlTest, setGetTtyMode) {
doc::test("Query and set the TTY mode state");
testAccessors<OPTIONAL>(
"TTY mode", Initial{IPrimaryDevice::TtyMode::OFF},
{IPrimaryDevice::TtyMode::HCO, IPrimaryDevice::TtyMode::VCO, IPrimaryDevice::TtyMode::FULL},
&IPrimaryDevice::setTtyMode, &IPrimaryDevice::getTtyMode);
}
+INSTANTIATE_TEST_CASE_P(TtyModeAccessorPrimaryHidl, TtyModeAccessorPrimaryHidlTest,
+ ::testing::ValuesIn(getDeviceParametersForPrimaryDeviceTests()),
+ &DeviceParameterToString);
-TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) {
+TEST_P(BoolAccessorPrimaryHidlTest, setGetHac) {
doc::test("Query and set the HAC state");
testAccessors<OPTIONAL>("HAC", Initial{false}, {true}, &IPrimaryDevice::setHacEnabled,
&IPrimaryDevice::getHacEnabled);
@@ -1372,9 +1567,13 @@
int main(int argc, char** argv) {
environment = new AudioHidlTestEnvironment;
+ // For V2..5 it's critical to initialize environment before GTest.
+ // The environment parses the service name from the command line,
+ // then it can be used in GTest parameter generators which are
+ // initialized during the call to InitGoogleTest.
+ environment->init(&argc, argv);
::testing::AddGlobalTestEnvironment(environment);
::testing::InitGoogleTest(&argc, argv);
- environment->init(&argc, argv);
int status = RUN_ALL_TESTS();
return status;
}
diff --git a/audio/core/all-versions/vts/functional/ConfigHelper.h b/audio/core/all-versions/vts/functional/ConfigHelper.h
new file mode 100644
index 0000000..48aae8c
--- /dev/null
+++ b/audio/core/all-versions/vts/functional/ConfigHelper.h
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Code in this file uses 'getCachedPolicyConfig'
+#ifndef AUDIO_PRIMARY_HIDL_HAL_TEST
+#error Must be included from AudioPrimaryHidlTest.h
+#endif
+
+//////////////////////////////////////////////////////////////////////////////
+//////////////// Required and recommended audio format support ///////////////
+// From:
+// https://source.android.com/compatibility/android-cdd.html#5_4_audio_recording
+// From:
+// https://source.android.com/compatibility/android-cdd.html#5_5_audio_playback
+/////////// TODO: move to the beginning of the file for easier update ////////
+//////////////////////////////////////////////////////////////////////////////
+
+struct ConfigHelper {
+ // for retro compatibility only test the primary device IN_BUILTIN_MIC
+ // FIXME: in the next audio HAL version, test all available devices
+ static bool primaryHasMic() {
+ auto& policyConfig = getCachedPolicyConfig();
+ if (policyConfig.getStatus() != OK || policyConfig.getPrimaryModule() == nullptr) {
+ return true; // Could not get the information, run all tests
+ }
+ auto getMic = [](auto& devs) {
+ return devs.getDevice(AUDIO_DEVICE_IN_BUILTIN_MIC, {}, AUDIO_FORMAT_DEFAULT);
+ };
+ auto primaryMic = getMic(policyConfig.getPrimaryModule()->getDeclaredDevices());
+ auto availableMic = getMic(policyConfig.getAvailableInputDevices());
+
+ return primaryMic != nullptr && primaryMic->equals(availableMic);
+ }
+
+ // Cache result ?
+ static const vector<AudioConfig> getRequiredSupportPlaybackAudioConfig() {
+ return combineAudioConfig({AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO},
+ {8000, 11025, 16000, 22050, 32000, 44100},
+ {AudioFormat::PCM_16_BIT});
+ }
+
+ static const vector<AudioConfig> getRecommendedSupportPlaybackAudioConfig() {
+ return combineAudioConfig({AudioChannelMask::OUT_STEREO, AudioChannelMask::OUT_MONO},
+ {24000, 48000}, {AudioFormat::PCM_16_BIT});
+ }
+
+ static const vector<AudioConfig> getSupportedPlaybackAudioConfig() {
+ // TODO: retrieve audio config supported by the platform
+ // as declared in the policy configuration
+ return {};
+ }
+
+ static const vector<AudioConfig> getRequiredSupportCaptureAudioConfig() {
+ if (!primaryHasMic()) return {};
+ return combineAudioConfig({AudioChannelMask::IN_MONO}, {8000, 11025, 16000, 44100},
+ {AudioFormat::PCM_16_BIT});
+ }
+ static const vector<AudioConfig> getRecommendedSupportCaptureAudioConfig() {
+ if (!primaryHasMic()) return {};
+ return combineAudioConfig({AudioChannelMask::IN_STEREO}, {22050, 48000},
+ {AudioFormat::PCM_16_BIT});
+ }
+ static const vector<AudioConfig> getSupportedCaptureAudioConfig() {
+ // TODO: retrieve audio config supported by the platform
+ // as declared in the policy configuration
+ return {};
+ }
+
+ static vector<AudioConfig> combineAudioConfig(vector<audio_channel_mask_t> channelMasks,
+ vector<uint32_t> sampleRates,
+ audio_format_t format) {
+ vector<AudioConfig> configs;
+ configs.reserve(channelMasks.size() * sampleRates.size());
+ for (auto channelMask : channelMasks) {
+ for (auto sampleRate : sampleRates) {
+ AudioConfig config{};
+ // leave offloadInfo to 0
+ config.channelMask = EnumBitfield<AudioChannelMask>(channelMask);
+ config.sampleRateHz = sampleRate;
+ config.format = AudioFormat(format);
+ configs.push_back(config);
+ }
+ }
+ return configs;
+ }
+
+ static vector<AudioConfig> combineAudioConfig(vector<AudioChannelMask> channelMasks,
+ vector<uint32_t> sampleRates,
+ vector<AudioFormat> formats) {
+ vector<AudioConfig> configs;
+ configs.reserve(channelMasks.size() * sampleRates.size() * formats.size());
+ for (auto channelMask : channelMasks) {
+ for (auto sampleRate : sampleRates) {
+ for (auto format : formats) {
+ AudioConfig config{};
+ // leave offloadInfo to 0
+ config.channelMask = mkEnumBitfield(channelMask);
+ config.sampleRateHz = sampleRate;
+ config.format = format;
+ // FIXME: leave frameCount to 0 ?
+ configs.push_back(config);
+ }
+ }
+ }
+ return configs;
+ }
+};
diff --git a/audio/core/all-versions/vts/functional/DeviceManager.h b/audio/core/all-versions/vts/functional/DeviceManager.h
new file mode 100644
index 0000000..b6e2db0
--- /dev/null
+++ b/audio/core/all-versions/vts/functional/DeviceManager.h
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Code in this file uses 'environment'
+#ifndef AUDIO_PRIMARY_HIDL_HAL_TEST
+#error Must be included from AudioPrimaryHidlTest.h
+#endif
+
+template <class Derived, class Key, class Interface>
+class InterfaceManager {
+ public:
+ sp<Interface> get(const Key& name) {
+ auto existing = instances.find(name);
+ if (existing != instances.end()) return existing->second;
+ auto [inserted, _] = instances.emplace(name, Derived::createInterfaceInstance(name));
+ if (inserted->second) {
+ environment->registerTearDown([name]() { (void)Derived::getInstance().reset(name); });
+ }
+ return inserted->second;
+ }
+
+ // The test must check that reset was successful. Reset failure means that the test code
+ // is holding a strong reference to the device.
+ bool reset(const Key& name) __attribute__((warn_unused_result)) {
+ auto iter = instances.find(name);
+ if (iter == instances.end()) return true;
+ ::android::wp<Interface> weak = iter->second;
+ instances.erase(iter);
+ if (weak.promote() != nullptr) return false;
+ waitForInstanceDestruction();
+ return true;
+ }
+
+ static void waitForInstanceDestruction() {
+ // FIXME: there is no way to know when the remote IDevice is being destroyed
+ // Binder does not support testing if an object is alive, thus
+ // wait for 100ms to let the binder destruction propagates and
+ // the remote device has the time to be destroyed.
+ // flushCommand makes sure all local command are sent, thus should reduce
+ // the latency between local and remote destruction.
+ IPCThreadState::self()->flushCommands();
+ usleep(100 * 1000);
+ }
+
+ protected:
+ std::map<Key, sp<Interface>> instances;
+};
+
+class DevicesFactoryManager
+ : public InterfaceManager<DevicesFactoryManager, std::string, IDevicesFactory> {
+ public:
+ static DevicesFactoryManager& getInstance() {
+ static DevicesFactoryManager instance;
+ return instance;
+ }
+ static sp<IDevicesFactory> createInterfaceInstance(const std::string& name) {
+#if MAJOR_VERSION <= 5
+ return ::testing::VtsHalHidlTargetTestBase::getService<IDevicesFactory>(name);
+#elif MAJOR_VERSION >= 6
+ return IDevicesFactory::getService(name);
+#endif
+ }
+};
+
+using FactoryAndDevice = std::tuple<std::string, std::string>;
+class DeviceManager : public InterfaceManager<DeviceManager, FactoryAndDevice, IDevice> {
+ public:
+ static DeviceManager& getInstance() {
+ static DeviceManager instance;
+ return instance;
+ }
+ static sp<IDevice> createInterfaceInstance(const FactoryAndDevice& factoryAndDevice) {
+ auto [factoryName, name] = factoryAndDevice;
+ sp<IDevicesFactory> factory = DevicesFactoryManager::getInstance().get(factoryName);
+ return name == kPrimaryDevice ? openPrimaryDevice(factory) : openDevice(factory, name);
+ }
+ using InterfaceManager::reset;
+
+ static constexpr const char* kPrimaryDevice = "primary";
+
+ sp<IDevice> get(const std::string& factoryName, const std::string& name) {
+ return InterfaceManager::get(std::make_tuple(factoryName, name));
+ }
+ sp<IPrimaryDevice> getPrimary(const std::string& factoryName) {
+ sp<IDevice> device = get(factoryName, kPrimaryDevice);
+ return device != nullptr ? IPrimaryDevice::castFrom(device) : nullptr;
+ }
+ bool reset(const std::string& factoryName, const std::string& name)
+ __attribute__((warn_unused_result)) {
+ return InterfaceManager::reset(std::make_tuple(factoryName, name));
+ }
+ bool resetPrimary(const std::string& factoryName) __attribute__((warn_unused_result)) {
+ return reset(factoryName, kPrimaryDevice);
+ }
+
+ private:
+ static sp<IDevice> openDevice(const sp<IDevicesFactory>& factory, const std::string& name) {
+ if (factory == nullptr) return nullptr;
+ sp<IDevice> device;
+#if MAJOR_VERSION >= 4
+ Result result;
+ auto ret = factory->openDevice(name, returnIn(result, device));
+ if (!ret.isOk() || result != Result::OK || device == nullptr) {
+ ALOGW("Device %s can not be opened, transaction: %s, result %d, device %p",
+ name.c_str(), ret.description().c_str(), result, device.get());
+ return nullptr;
+ }
+#else
+ (void)name;
+#endif
+ return device;
+ }
+
+ static sp<IDevice> openPrimaryDevice(const sp<IDevicesFactory>& factory) {
+ if (factory == nullptr) return nullptr;
+ Result result;
+ sp<IDevice> device;
+#if MAJOR_VERSION == 2
+ auto ret = factory->openDevice(IDevicesFactory::Device::PRIMARY, returnIn(result, device));
+#elif MAJOR_VERSION >= 4
+ auto ret = factory->openPrimaryDevice(returnIn(result, device));
+#endif
+ if (!ret.isOk() || result != Result::OK || device == nullptr) {
+ ALOGW("Primary device can not be opened, transaction: %s, result %d, device %p",
+ ret.description().c_str(), result, device.get());
+ return nullptr;
+ }
+ return device;
+ }
+};
diff --git a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp
index c4c7f7c..3c712b5 100644
--- a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp
+++ b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp
@@ -28,8 +28,14 @@
#include <common/all-versions/VersionUtils.h>
+#if MAJOR_VERSION <= 5
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
+#elif MAJOR_VERSION >= 6
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
+#endif
using ::android::sp;
using ::android::hardware::hidl_handle;
@@ -49,6 +55,11 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
#endif
+#if MAJOR_VERSION <= 5
+// For HAL versions 2..5 Vts Environment and Test base classes are used.
+// The tests are non-parametrized.
+#define EFFECT_TEST TEST_F
+
// Test environment for Audio Effects Factory HIDL HAL.
class AudioEffectsFactoryHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
@@ -71,6 +82,18 @@
ASSERT_NE(effectsFactory, nullptr);
}
+#elif MAJOR_VERSION >= 6
+// For HAL version 6 and above, standard GTest Environment and Test base classes are used.
+// The tests are parametrized by the IEffectsFactory instance name.
+#define EFFECT_TEST TEST_P
+
+class AudioEffectsFactoryHidlTest : public ::testing::TestWithParam<std::string> {
+ public:
+ void SetUp() override {
+ effectsFactory = IEffectsFactory::getService(GetParam());
+ ASSERT_NE(effectsFactory, nullptr);
+ }
+#endif // The rest of the AudioEffectsFactoryHidlTest class definition is the same.
void TearDown() override { effectsFactory.clear(); }
protected:
@@ -81,7 +104,7 @@
sp<IEffectsFactory> effectsFactory;
};
-TEST_F(AudioEffectsFactoryHidlTest, EnumerateEffects) {
+EFFECT_TEST(AudioEffectsFactoryHidlTest, EnumerateEffects) {
description("Verify that EnumerateEffects returns at least one effect");
Result retval = Result::NOT_INITIALIZED;
size_t effectCount = 0;
@@ -95,7 +118,7 @@
EXPECT_GT(effectCount, 0u);
}
-TEST_F(AudioEffectsFactoryHidlTest, CreateEffect) {
+EFFECT_TEST(AudioEffectsFactoryHidlTest, CreateEffect) {
description("Verify that an effect can be created via CreateEffect");
bool gotEffect = false;
Uuid effectUuid;
@@ -123,7 +146,7 @@
EXPECT_NE(nullptr, effect.get());
}
-TEST_F(AudioEffectsFactoryHidlTest, GetDescriptor) {
+EFFECT_TEST(AudioEffectsFactoryHidlTest, GetDescriptor) {
description(
"Verify that effects factory can provide an effect descriptor via "
"GetDescriptor");
@@ -146,7 +169,7 @@
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectsFactoryHidlTest, DebugDumpInvalidArgument) {
+EFFECT_TEST(AudioEffectsFactoryHidlTest, DebugDumpInvalidArgument) {
description("Verify that debugDump doesn't crash on invalid arguments");
#if MAJOR_VERSION == 2
Return<void> ret = effectsFactory->debugDump(hidl_handle());
@@ -168,10 +191,17 @@
std::array<uint8_t, 6>{{0x11, 0x26, 0x0e, 0xb6, 0x3c, 0xf1}}};
// The main test class for Audio Effect HIDL HAL.
+#if MAJOR_VERSION <= 5
class AudioEffectHidlTest : public ::testing::VtsHalHidlTargetTestBase {
public:
void SetUp() override {
effectsFactory = ::testing::VtsHalHidlTargetTestBase::getService<IEffectsFactory>();
+#elif MAJOR_VERSION >= 6
+class AudioEffectHidlTest : public ::testing::TestWithParam<std::string> {
+ public:
+ void SetUp() override {
+ effectsFactory = IEffectsFactory::getService(GetParam());
+#endif
ASSERT_NE(nullptr, effectsFactory.get());
findAndCreateEffect(getEffectType());
@@ -250,14 +280,14 @@
static_cast<audio_channel_mask_t>(currentConfig.outputCfg.channels));
}
-TEST_F(AudioEffectHidlTest, Close) {
+EFFECT_TEST(AudioEffectHidlTest, Close) {
description("Verify that an effect can be closed");
Return<Result> ret = effect->close();
EXPECT_TRUE(ret.isOk());
EXPECT_EQ(Result::OK, ret);
}
-TEST_F(AudioEffectHidlTest, GetDescriptor) {
+EFFECT_TEST(AudioEffectHidlTest, GetDescriptor) {
description("Verify that an effect can return its own descriptor via GetDescriptor");
Result retval = Result::NOT_INITIALIZED;
Uuid actualType;
@@ -272,7 +302,7 @@
EXPECT_EQ(getEffectType(), actualType);
}
-TEST_F(AudioEffectHidlTest, GetSetConfig) {
+EFFECT_TEST(AudioEffectHidlTest, GetSetConfig) {
description(
"Verify that it is possible to manipulate effect config via Get / "
"SetConfig");
@@ -291,26 +321,26 @@
EXPECT_EQ(Result::OK, ret2);
}
-TEST_F(AudioEffectHidlTest, GetConfigReverse) {
+EFFECT_TEST(AudioEffectHidlTest, GetConfigReverse) {
description("Verify that GetConfigReverse does not crash");
Return<void> ret = effect->getConfigReverse([&](Result, const EffectConfig&) {});
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, GetSupportedAuxChannelsConfigs) {
+EFFECT_TEST(AudioEffectHidlTest, GetSupportedAuxChannelsConfigs) {
description("Verify that GetSupportedAuxChannelsConfigs does not crash");
Return<void> ret = effect->getSupportedAuxChannelsConfigs(
0, [&](Result, const hidl_vec<EffectAuxChannelsConfig>&) {});
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, GetAuxChannelsConfig) {
+EFFECT_TEST(AudioEffectHidlTest, GetAuxChannelsConfig) {
description("Verify that GetAuxChannelsConfig does not crash");
Return<void> ret = effect->getAuxChannelsConfig([&](Result, const EffectAuxChannelsConfig&) {});
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, SetAuxChannelsConfig) {
+EFFECT_TEST(AudioEffectHidlTest, SetAuxChannelsConfig) {
description("Verify that SetAuxChannelsConfig does not crash");
Return<Result> ret = effect->setAuxChannelsConfig(EffectAuxChannelsConfig());
EXPECT_TRUE(ret.isOk());
@@ -349,7 +379,7 @@
} // namespace hardware
} // namespace android
-TEST_F(AudioEffectHidlTest, Reset) {
+EFFECT_TEST(AudioEffectHidlTest, Reset) {
description("Verify that Reset preserves effect configuration");
Result retval = Result::NOT_INITIALIZED;
EffectConfig originalConfig;
@@ -374,7 +404,7 @@
EXPECT_EQ(originalConfig, configAfterReset);
}
-TEST_F(AudioEffectHidlTest, DisableEnableDisable) {
+EFFECT_TEST(AudioEffectHidlTest, DisableEnableDisable) {
description("Verify Disable -> Enable -> Disable sequence for an effect");
Return<Result> ret = effect->disable();
EXPECT_TRUE(ret.isOk());
@@ -387,14 +417,14 @@
EXPECT_EQ(Result::OK, ret);
}
-TEST_F(AudioEffectHidlTest, SetDevice) {
+EFFECT_TEST(AudioEffectHidlTest, SetDevice) {
description("Verify that SetDevice works for an output chain effect");
Return<Result> ret = effect->setDevice(mkEnumBitfield(AudioDevice::OUT_SPEAKER));
EXPECT_TRUE(ret.isOk());
EXPECT_EQ(Result::OK, ret);
}
-TEST_F(AudioEffectHidlTest, SetAndGetVolume) {
+EFFECT_TEST(AudioEffectHidlTest, SetAndGetVolume) {
description("Verify that SetAndGetVolume method works for an effect");
uint32_t channelCount;
getChannelCount(&channelCount);
@@ -410,7 +440,7 @@
EXPECT_EQ(Result::OK, retval);
}
-TEST_F(AudioEffectHidlTest, VolumeChangeNotification) {
+EFFECT_TEST(AudioEffectHidlTest, VolumeChangeNotification) {
description("Verify that effect accepts VolumeChangeNotification");
uint32_t channelCount;
getChannelCount(&channelCount);
@@ -424,32 +454,32 @@
EXPECT_EQ(Result::OK, ret);
}
-TEST_F(AudioEffectHidlTest, SetAudioMode) {
+EFFECT_TEST(AudioEffectHidlTest, SetAudioMode) {
description("Verify that SetAudioMode works for an effect");
Return<Result> ret = effect->setAudioMode(AudioMode::NORMAL);
EXPECT_TRUE(ret.isOk());
EXPECT_EQ(Result::OK, ret);
}
-TEST_F(AudioEffectHidlTest, SetConfigReverse) {
+EFFECT_TEST(AudioEffectHidlTest, SetConfigReverse) {
description("Verify that SetConfigReverse does not crash");
Return<Result> ret = effect->setConfigReverse(EffectConfig(), nullptr, nullptr);
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, SetInputDevice) {
+EFFECT_TEST(AudioEffectHidlTest, SetInputDevice) {
description("Verify that SetInputDevice does not crash");
Return<Result> ret = effect->setInputDevice(mkEnumBitfield(AudioDevice::IN_BUILTIN_MIC));
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, SetAudioSource) {
+EFFECT_TEST(AudioEffectHidlTest, SetAudioSource) {
description("Verify that SetAudioSource does not crash");
Return<Result> ret = effect->setAudioSource(AudioSource::MIC);
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, Offload) {
+EFFECT_TEST(AudioEffectHidlTest, Offload) {
description("Verify that calling Offload method does not crash");
EffectOffloadParameter offloadParam;
offloadParam.isOffload = false;
@@ -458,7 +488,7 @@
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, PrepareForProcessing) {
+EFFECT_TEST(AudioEffectHidlTest, PrepareForProcessing) {
description("Verify that PrepareForProcessing method works for an effect");
Result retval = Result::NOT_INITIALIZED;
Return<void> ret = effect->prepareForProcessing(
@@ -467,7 +497,7 @@
EXPECT_EQ(Result::OK, retval);
}
-TEST_F(AudioEffectHidlTest, SetProcessBuffers) {
+EFFECT_TEST(AudioEffectHidlTest, SetProcessBuffers) {
description("Verify that SetProcessBuffers works for an effect");
sp<IAllocator> ashmem = IAllocator::getService("ashmem");
ASSERT_NE(nullptr, ashmem.get());
@@ -486,41 +516,41 @@
EXPECT_EQ(Result::OK, ret2);
}
-TEST_F(AudioEffectHidlTest, Command) {
+EFFECT_TEST(AudioEffectHidlTest, Command) {
description("Verify that Command does not crash");
Return<void> ret =
effect->command(0, hidl_vec<uint8_t>(), 0, [&](int32_t, const hidl_vec<uint8_t>&) {});
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, SetParameter) {
+EFFECT_TEST(AudioEffectHidlTest, SetParameter) {
description("Verify that SetParameter does not crash");
Return<Result> ret = effect->setParameter(hidl_vec<uint8_t>(), hidl_vec<uint8_t>());
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, GetParameter) {
+EFFECT_TEST(AudioEffectHidlTest, GetParameter) {
description("Verify that GetParameter does not crash");
Return<void> ret =
effect->getParameter(hidl_vec<uint8_t>(), 0, [&](Result, const hidl_vec<uint8_t>&) {});
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, GetSupportedConfigsForFeature) {
+EFFECT_TEST(AudioEffectHidlTest, GetSupportedConfigsForFeature) {
description("Verify that GetSupportedConfigsForFeature does not crash");
Return<void> ret = effect->getSupportedConfigsForFeature(
0, 0, 0, [&](Result, uint32_t, const hidl_vec<uint8_t>&) {});
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, GetCurrentConfigForFeature) {
+EFFECT_TEST(AudioEffectHidlTest, GetCurrentConfigForFeature) {
description("Verify that GetCurrentConfigForFeature does not crash");
Return<void> ret =
effect->getCurrentConfigForFeature(0, 0, [&](Result, const hidl_vec<uint8_t>&) {});
EXPECT_TRUE(ret.isOk());
}
-TEST_F(AudioEffectHidlTest, SetCurrentConfigForFeature) {
+EFFECT_TEST(AudioEffectHidlTest, SetCurrentConfigForFeature) {
description("Verify that SetCurrentConfigForFeature does not crash");
Return<Result> ret = effect->setCurrentConfigForFeature(0, hidl_vec<uint8_t>());
EXPECT_TRUE(ret.isOk());
@@ -606,21 +636,21 @@
ASSERT_EQ(Result::OK, retval);
}
-TEST_F(EqualizerAudioEffectHidlTest, GetNumBands) {
+EFFECT_TEST(EqualizerAudioEffectHidlTest, GetNumBands) {
description("Verify that Equalizer effect reports at least one band");
uint16_t numBands = 0;
getNumBands(&numBands);
EXPECT_GT(numBands, 0);
}
-TEST_F(EqualizerAudioEffectHidlTest, GetLevelRange) {
+EFFECT_TEST(EqualizerAudioEffectHidlTest, GetLevelRange) {
description("Verify that Equalizer effect reports adequate band level range");
int16_t minLevel = 0x7fff, maxLevel = 0;
getLevelRange(&minLevel, &maxLevel);
EXPECT_GT(maxLevel, minLevel);
}
-TEST_F(EqualizerAudioEffectHidlTest, GetSetBandLevel) {
+EFFECT_TEST(EqualizerAudioEffectHidlTest, GetSetBandLevel) {
description("Verify that manipulating band levels works for Equalizer effect");
uint16_t numBands = 0;
getNumBands(&numBands);
@@ -649,7 +679,7 @@
}
}
-TEST_F(EqualizerAudioEffectHidlTest, GetBandCenterFrequencyAndRange) {
+EFFECT_TEST(EqualizerAudioEffectHidlTest, GetBandCenterFrequencyAndRange) {
description("Verify that Equalizer effect reports adequate band frequency range");
uint16_t numBands = 0;
getNumBands(&numBands);
@@ -664,7 +694,7 @@
}
}
-TEST_F(EqualizerAudioEffectHidlTest, GetBandForFrequency) {
+EFFECT_TEST(EqualizerAudioEffectHidlTest, GetBandForFrequency) {
description("Verify that Equalizer effect supports GetBandForFrequency correctly");
uint16_t numBands = 0;
getNumBands(&numBands);
@@ -693,14 +723,14 @@
}
}
-TEST_F(EqualizerAudioEffectHidlTest, GetPresetNames) {
+EFFECT_TEST(EqualizerAudioEffectHidlTest, GetPresetNames) {
description("Verify that Equalizer effect reports at least one preset");
size_t presetCount;
getPresetCount(&presetCount);
EXPECT_GT(presetCount, 0u);
}
-TEST_F(EqualizerAudioEffectHidlTest, GetSetCurrentPreset) {
+EFFECT_TEST(EqualizerAudioEffectHidlTest, GetSetCurrentPreset) {
description("Verify that manipulating the current preset for Equalizer effect");
size_t presetCount;
getPresetCount(&presetCount);
@@ -723,7 +753,7 @@
}
}
-TEST_F(EqualizerAudioEffectHidlTest, GetSetAllProperties) {
+EFFECT_TEST(EqualizerAudioEffectHidlTest, GetSetAllProperties) {
description(
"Verify that setting band levels and presets works via Get / "
"SetAllProperties for Equalizer effect");
@@ -787,7 +817,7 @@
sp<ILoudnessEnhancerEffect> enhancer;
};
-TEST_F(LoudnessEnhancerAudioEffectHidlTest, GetSetTargetGain) {
+EFFECT_TEST(LoudnessEnhancerAudioEffectHidlTest, GetSetTargetGain) {
description(
"Verify that manipulating the target gain works for Loudness Enhancer "
"effect");
@@ -808,6 +838,7 @@
EXPECT_EQ(gain, actualGain);
}
+#if MAJOR_VERSION <= 5
int main(int argc, char** argv) {
::testing::AddGlobalTestEnvironment(AudioEffectsFactoryHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv);
@@ -816,3 +847,17 @@
LOG(INFO) << "Test result = " << status;
return status;
}
+#elif MAJOR_VERSION >= 6
+INSTANTIATE_TEST_SUITE_P(
+ EffectsFactory, AudioEffectsFactoryHidlTest,
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(IEffectsFactory::descriptor)),
+ android::hardware::PrintInstanceNameToString);
+INSTANTIATE_TEST_SUITE_P(
+ Equalizer, EqualizerAudioEffectHidlTest,
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(IEffectsFactory::descriptor)),
+ android::hardware::PrintInstanceNameToString);
+INSTANTIATE_TEST_SUITE_P(
+ LoudnessEnhancer, LoudnessEnhancerAudioEffectHidlTest,
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(IEffectsFactory::descriptor)),
+ android::hardware::PrintInstanceNameToString);
+#endif
diff --git a/automotive/vehicle/2.0/default/Android.bp b/automotive/vehicle/2.0/default/Android.bp
index 3fd0539..ed09859 100644
--- a/automotive/vehicle/2.0/default/Android.bp
+++ b/automotive/vehicle/2.0/default/Android.bp
@@ -71,10 +71,10 @@
whole_static_libs: ["android.hardware.automotive.vehicle@2.0-manager-lib"],
shared_libs: [
"libbase",
+ "libjsoncpp",
"libprotobuf-cpp-lite",
],
static_libs: [
- "libjsoncpp",
"libqemu_pipe",
"android.hardware.automotive.vehicle@2.0-libproto-native",
],
@@ -106,13 +106,13 @@
srcs: ["VehicleService.cpp"],
shared_libs: [
"libbase",
+ "libjsoncpp",
"libprotobuf-cpp-lite",
],
static_libs: [
"android.hardware.automotive.vehicle@2.0-manager-lib",
"android.hardware.automotive.vehicle@2.0-default-impl-lib",
"android.hardware.automotive.vehicle@2.0-libproto-native",
- "libjsoncpp",
"libqemu_pipe",
],
}
diff --git a/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VmsUtils.h b/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VmsUtils.h
index d689e62..8ee3c54 100644
--- a/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VmsUtils.h
+++ b/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VmsUtils.h
@@ -153,7 +153,7 @@
std::unique_ptr<VehiclePropValue> createAvailabilityRequest();
// Creates a VehiclePropValue containing a message of type
-// VmsMessageType.AVAILABILITY_REQUEST.
+// VmsMessageType.SUBSCRIPTIONS_REQUEST.
std::unique_ptr<VehiclePropValue> createSubscriptionsRequest();
// Creates a VehiclePropValue containing a message of type VmsMessageType.DATA.
@@ -202,21 +202,21 @@
// Returns true if the new sequence number is greater than the last seen
// sequence number.
-bool isSequenceNumberNewer(const VehiclePropValue& subscription_change,
+bool isSequenceNumberNewer(const VehiclePropValue& subscriptions_state,
const int last_seen_sequence_number);
// Returns sequence number of the message.
-int32_t getSequenceNumberForSubscriptionsState(const VehiclePropValue& subscription_change);
+int32_t getSequenceNumberForSubscriptionsState(const VehiclePropValue& subscriptions_state);
-// Takes a subscription change message and returns the layers that have active
+// Takes a subscriptions state message and returns the layers that have active
// subscriptions of the layers that are offered by your HAL client/publisher.
//
-// A publisher can use this function when receiving a subscription change message
-// to determine which layers to publish data on.
+// A publisher can use this function when receiving a subscriptions response or subscriptions
+// change message to determine which layers to publish data on.
// The caller of this function can optionally decide to not consume these layers
// if the subscription change has the sequence number less than the last seen
// sequence number.
-std::vector<VmsLayer> getSubscribedLayers(const VehiclePropValue& subscription_change,
+std::vector<VmsLayer> getSubscribedLayers(const VehiclePropValue& subscriptions_state,
const VmsOffers& offers);
// Takes an availability change message and returns true if the parsed message implies that
diff --git a/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp b/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
index d346206..9eba905 100644
--- a/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
+++ b/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
@@ -194,32 +194,35 @@
return -1;
}
-bool isSequenceNumberNewer(const VehiclePropValue& subscription_change,
+bool isSequenceNumberNewer(const VehiclePropValue& subscriptions_state,
const int last_seen_sequence_number) {
- return (isValidVmsMessage(subscription_change) &&
- parseMessageType(subscription_change) == VmsMessageType::SUBSCRIPTIONS_CHANGE &&
- subscription_change.value.int32Values.size() > kSubscriptionStateSequenceNumberIndex &&
- subscription_change.value.int32Values[kSubscriptionStateSequenceNumberIndex] >
+ return (isValidVmsMessage(subscriptions_state) &&
+ (parseMessageType(subscriptions_state) == VmsMessageType::SUBSCRIPTIONS_CHANGE ||
+ parseMessageType(subscriptions_state) == VmsMessageType::SUBSCRIPTIONS_RESPONSE) &&
+ subscriptions_state.value.int32Values.size() > kSubscriptionStateSequenceNumberIndex &&
+ subscriptions_state.value.int32Values[kSubscriptionStateSequenceNumberIndex] >
last_seen_sequence_number);
}
-int32_t getSequenceNumberForSubscriptionsState(const VehiclePropValue& subscription_change) {
- if (isValidVmsMessage(subscription_change) &&
- parseMessageType(subscription_change) == VmsMessageType::SUBSCRIPTIONS_CHANGE &&
- subscription_change.value.int32Values.size() > kSubscriptionStateSequenceNumberIndex) {
- return subscription_change.value.int32Values[kSubscriptionStateSequenceNumberIndex];
+int32_t getSequenceNumberForSubscriptionsState(const VehiclePropValue& subscriptions_state) {
+ if (isValidVmsMessage(subscriptions_state) &&
+ (parseMessageType(subscriptions_state) == VmsMessageType::SUBSCRIPTIONS_CHANGE ||
+ parseMessageType(subscriptions_state) == VmsMessageType::SUBSCRIPTIONS_RESPONSE) &&
+ subscriptions_state.value.int32Values.size() > kSubscriptionStateSequenceNumberIndex) {
+ return subscriptions_state.value.int32Values[kSubscriptionStateSequenceNumberIndex];
}
return -1;
}
-std::vector<VmsLayer> getSubscribedLayers(const VehiclePropValue& subscription_change,
+std::vector<VmsLayer> getSubscribedLayers(const VehiclePropValue& subscriptions_state,
const VmsOffers& offers) {
- if (isValidVmsMessage(subscription_change) &&
- parseMessageType(subscription_change) == VmsMessageType::SUBSCRIPTIONS_CHANGE &&
- subscription_change.value.int32Values.size() > kSubscriptionStateSequenceNumberIndex) {
- const int32_t num_of_layers = subscription_change.value.int32Values[toInt(
+ if (isValidVmsMessage(subscriptions_state) &&
+ (parseMessageType(subscriptions_state) == VmsMessageType::SUBSCRIPTIONS_CHANGE ||
+ parseMessageType(subscriptions_state) == VmsMessageType::SUBSCRIPTIONS_RESPONSE) &&
+ subscriptions_state.value.int32Values.size() > kSubscriptionStateSequenceNumberIndex) {
+ const int32_t num_of_layers = subscriptions_state.value.int32Values[toInt(
VmsSubscriptionsStateIntegerValuesIndex::NUMBER_OF_LAYERS)];
- const int32_t num_of_associated_layers = subscription_change.value.int32Values[toInt(
+ const int32_t num_of_associated_layers = subscriptions_state.value.int32Values[toInt(
VmsSubscriptionsStateIntegerValuesIndex ::NUMBER_OF_ASSOCIATED_LAYERS)];
std::unordered_set<VmsLayer, VmsLayer::VmsLayerHashFunction> offered_layers;
@@ -231,9 +234,9 @@
int current_index = toInt(VmsSubscriptionsStateIntegerValuesIndex::SUBSCRIPTIONS_START);
// Add all subscribed layers which are offered by the current publisher.
for (int i = 0; i < num_of_layers; i++) {
- VmsLayer layer = VmsLayer(subscription_change.value.int32Values[current_index],
- subscription_change.value.int32Values[current_index + 1],
- subscription_change.value.int32Values[current_index + 2]);
+ VmsLayer layer = VmsLayer(subscriptions_state.value.int32Values[current_index],
+ subscriptions_state.value.int32Values[current_index + 1],
+ subscriptions_state.value.int32Values[current_index + 2]);
if (offered_layers.find(layer) != offered_layers.end()) {
subscribed_layers.push_back(layer);
}
@@ -243,15 +246,15 @@
// For this, we need to check if the associated layer has a publisher ID which is
// same as that of the current publisher.
for (int i = 0; i < num_of_associated_layers; i++) {
- VmsLayer layer = VmsLayer(subscription_change.value.int32Values[current_index],
- subscription_change.value.int32Values[current_index + 1],
- subscription_change.value.int32Values[current_index + 2]);
+ VmsLayer layer = VmsLayer(subscriptions_state.value.int32Values[current_index],
+ subscriptions_state.value.int32Values[current_index + 1],
+ subscriptions_state.value.int32Values[current_index + 2]);
current_index += kLayerSize;
if (offered_layers.find(layer) != offered_layers.end()) {
- int32_t num_of_publisher_ids = subscription_change.value.int32Values[current_index];
+ int32_t num_of_publisher_ids = subscriptions_state.value.int32Values[current_index];
current_index++;
for (int j = 0; j < num_of_publisher_ids; j++) {
- if (subscription_change.value.int32Values[current_index] ==
+ if (subscriptions_state.value.int32Values[current_index] ==
offers.publisher_id) {
subscribed_layers.push_back(layer);
}
diff --git a/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp b/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
index 7189212..8b547f1 100644
--- a/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
+++ b/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
@@ -214,57 +214,82 @@
EXPECT_EQ(parsePublisherIdResponse(*message), -1);
}
-TEST(VmsUtilsTest, validSequenceNumberForSubscriptionsState) {
+TEST(VmsUtilsTest, validSequenceNumberForSubscriptionsChange) {
auto message = createBaseVmsMessage(2);
message->value.int32Values =
hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_CHANGE), 1234};
EXPECT_EQ(getSequenceNumberForSubscriptionsState(*message), 1234);
}
+TEST(VmsUtilsTest, validSequenceNumberForSubscriptionsResponse) {
+ auto message = createBaseVmsMessage(2);
+ message->value.int32Values =
+ hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_RESPONSE), 1234};
+ EXPECT_EQ(getSequenceNumberForSubscriptionsState(*message), 1234);
+}
+
TEST(VmsUtilsTest, invalidSubscriptionsState) {
auto message = createBaseVmsMessage(1);
EXPECT_EQ(getSequenceNumberForSubscriptionsState(*message), -1);
}
-TEST(VmsUtilsTest, newSequenceNumberForExistingSmallerNumber) {
+TEST(VmsUtilsTest, newSequenceNumberForExistingSmallerNumberForChange) {
auto message = createBaseVmsMessage(2);
message->value.int32Values =
hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_CHANGE), 1234};
EXPECT_TRUE(isSequenceNumberNewer(*message, 1233));
}
-TEST(VmsUtilsTest, newSequenceNumberForExistingGreaterNumber) {
+TEST(VmsUtilsTest, newSequenceNumberForExistingSmallerNumberForResponse) {
+ auto message = createBaseVmsMessage(2);
+ message->value.int32Values =
+ hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_RESPONSE), 1234};
+ EXPECT_TRUE(isSequenceNumberNewer(*message, 1233));
+}
+
+TEST(VmsUtilsTest, newSequenceNumberForExistingGreaterNumberForChange) {
auto message = createBaseVmsMessage(2);
message->value.int32Values =
hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_CHANGE), 1234};
EXPECT_FALSE(isSequenceNumberNewer(*message, 1235));
}
-TEST(VmsUtilsTest, newSequenceNumberForSameNumber) {
+TEST(VmsUtilsTest, newSequenceNumberForExistingGreaterNumberForResponse) {
+ auto message = createBaseVmsMessage(2);
+ message->value.int32Values =
+ hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_RESPONSE), 1234};
+ EXPECT_FALSE(isSequenceNumberNewer(*message, 1235));
+}
+
+TEST(VmsUtilsTest, newSequenceNumberForSameNumberForChange) {
auto message = createBaseVmsMessage(2);
message->value.int32Values =
hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_CHANGE), 1234};
EXPECT_FALSE(isSequenceNumberNewer(*message, 1234));
}
-TEST(VmsUtilsTest, subscribedLayers) {
+TEST(VmsUtilsTest, newSequenceNumberForSameNumberForResponse) {
+ auto message = createBaseVmsMessage(2);
+ message->value.int32Values =
+ hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_RESPONSE), 1234};
+ EXPECT_FALSE(isSequenceNumberNewer(*message, 1234));
+}
+
+void testSubscribedLayers(VmsMessageType type) {
VmsOffers offers = {123,
{VmsLayerOffering(VmsLayer(1, 0, 1), {VmsLayer(4, 1, 1)}),
VmsLayerOffering(VmsLayer(2, 0, 1))}};
auto message = createBaseVmsMessage(2);
- message->value.int32Values = hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_CHANGE),
+ message->value.int32Values = hidl_vec<int32_t>{toInt(type),
1234, // sequence number
2, // number of layers
1, // number of associated layers
1, // layer 1
- 0,
- 1,
+ 0, 1,
4, // layer 2
- 1,
- 1,
+ 1, 1,
2, // associated layer
- 0,
- 1,
+ 0, 1,
2, // number of publisher IDs
111, // publisher IDs
123};
@@ -275,10 +300,18 @@
EXPECT_EQ(result.at(1), VmsLayer(2, 0, 1));
}
-TEST(VmsUtilsTest, subscribedLayersWithDifferentSubtype) {
+TEST(VmsUtilsTest, subscribedLayersForChange) {
+ testSubscribedLayers(VmsMessageType::SUBSCRIPTIONS_CHANGE);
+}
+
+TEST(VmsUtilsTest, subscribedLayersForResponse) {
+ testSubscribedLayers(VmsMessageType::SUBSCRIPTIONS_RESPONSE);
+}
+
+void testSubscribedLayersWithDifferentSubtype(VmsMessageType type) {
VmsOffers offers = {123, {VmsLayerOffering(VmsLayer(1, 0, 1))}};
auto message = createBaseVmsMessage(2);
- message->value.int32Values = hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_CHANGE),
+ message->value.int32Values = hidl_vec<int32_t>{toInt(type),
1234, // sequence number
1, // number of layers
0, // number of associated layers
@@ -289,36 +322,58 @@
EXPECT_TRUE(getSubscribedLayers(*message, offers).empty());
}
-TEST(VmsUtilsTest, subscribedLayersWithDifferentVersion) {
+TEST(VmsUtilsTest, subscribedLayersWithDifferentSubtypeForChange) {
+ testSubscribedLayersWithDifferentSubtype(VmsMessageType::SUBSCRIPTIONS_CHANGE);
+}
+
+TEST(VmsUtilsTest, subscribedLayersWithDifferentSubtypeForResponse) {
+ testSubscribedLayersWithDifferentSubtype(VmsMessageType::SUBSCRIPTIONS_RESPONSE);
+}
+
+void subscribedLayersWithDifferentVersion(VmsMessageType type) {
VmsOffers offers = {123, {VmsLayerOffering(VmsLayer(1, 0, 1))}};
auto message = createBaseVmsMessage(2);
- message->value.int32Values = hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_CHANGE),
- 1234, // sequence number
- 1, // number of layers
- 0, // number of associated layers
- 1, // layer 1
- 0,
- 2}; // different version
+ message->value.int32Values = hidl_vec<int32_t>{toInt(type),
+ 1234, // sequence number
+ 1, // number of layers
+ 0, // number of associated layers
+ 1, // layer 1
+ 0, 2}; // different version
EXPECT_TRUE(isValidVmsMessage(*message));
EXPECT_TRUE(getSubscribedLayers(*message, offers).empty());
}
-TEST(VmsUtilsTest, subscribedLayersWithDifferentPublisherId) {
+TEST(VmsUtilsTest, subscribedLayersWithDifferentVersionForChange) {
+ subscribedLayersWithDifferentVersion(VmsMessageType::SUBSCRIPTIONS_CHANGE);
+}
+
+TEST(VmsUtilsTest, subscribedLayersWithDifferentVersionForResponse) {
+ subscribedLayersWithDifferentVersion(VmsMessageType::SUBSCRIPTIONS_RESPONSE);
+}
+
+void subscribedLayersWithDifferentPublisherId(VmsMessageType type) {
VmsOffers offers = {123, {VmsLayerOffering(VmsLayer(1, 0, 1))}};
auto message = createBaseVmsMessage(2);
- message->value.int32Values = hidl_vec<int32_t>{toInt(VmsMessageType::SUBSCRIPTIONS_CHANGE),
+ message->value.int32Values = hidl_vec<int32_t>{toInt(type),
1234, // sequence number
0, // number of layers
1, // number of associated layers
1, // associated layer 1
- 0,
- 1,
+ 0, 1,
1, // number of publisher IDs
234}; // publisher ID 1
EXPECT_TRUE(isValidVmsMessage(*message));
EXPECT_TRUE(getSubscribedLayers(*message, offers).empty());
}
+TEST(VmsUtilsTest, subscribedLayersWithDifferentPublisherIdForChange) {
+ subscribedLayersWithDifferentPublisherId(VmsMessageType::SUBSCRIPTIONS_CHANGE);
+}
+
+TEST(VmsUtilsTest, subscribedLayersWithDifferentPublisherIdForResponse) {
+ subscribedLayersWithDifferentPublisherId(VmsMessageType::SUBSCRIPTIONS_RESPONSE);
+}
+
TEST(VmsUtilsTest, serviceNewlyStarted) {
auto message = createBaseVmsMessage(2);
message->value.int32Values = hidl_vec<int32_t>{toInt(VmsMessageType::AVAILABILITY_CHANGE), 0};
diff --git a/boot/1.1/vts/functional/VtsHalBootV1_1TargetTest.cpp b/boot/1.1/vts/functional/VtsHalBootV1_1TargetTest.cpp
index fba9a5e..7c58ef3 100644
--- a/boot/1.1/vts/functional/VtsHalBootV1_1TargetTest.cpp
+++ b/boot/1.1/vts/functional/VtsHalBootV1_1TargetTest.cpp
@@ -81,6 +81,6 @@
}
INSTANTIATE_TEST_SUITE_P(
- , BootHidlTest,
+ PerInstance, BootHidlTest,
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IBootControl::descriptor)),
android::hardware::PrintInstanceNameToString);
diff --git a/drm/1.0/default/CryptoPlugin.cpp b/drm/1.0/default/CryptoPlugin.cpp
index 666653b..8ddc380 100644
--- a/drm/1.0/default/CryptoPlugin.cpp
+++ b/drm/1.0/default/CryptoPlugin.cpp
@@ -101,11 +101,20 @@
std::unique_ptr<android::CryptoPlugin::SubSample[]> legacySubSamples =
std::make_unique<android::CryptoPlugin::SubSample[]>(subSamples.size());
+ size_t destSize = 0;
for (size_t i = 0; i < subSamples.size(); i++) {
- legacySubSamples[i].mNumBytesOfClearData
- = subSamples[i].numBytesOfClearData;
- legacySubSamples[i].mNumBytesOfEncryptedData
- = subSamples[i].numBytesOfEncryptedData;
+ uint32_t numBytesOfClearData = subSamples[i].numBytesOfClearData;
+ legacySubSamples[i].mNumBytesOfClearData = numBytesOfClearData;
+ uint32_t numBytesOfEncryptedData = subSamples[i].numBytesOfEncryptedData;
+ legacySubSamples[i].mNumBytesOfEncryptedData = numBytesOfEncryptedData;
+ if (__builtin_add_overflow(destSize, numBytesOfClearData, &destSize)) {
+ _hidl_cb(Status::BAD_VALUE, 0, "subsample clear size overflow");
+ return Void();
+ }
+ if (__builtin_add_overflow(destSize, numBytesOfEncryptedData, &destSize)) {
+ _hidl_cb(Status::BAD_VALUE, 0, "subsample encrypted size overflow");
+ return Void();
+ }
}
AString detailMessage;
@@ -137,11 +146,24 @@
_hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, 0, "invalid buffer size");
return Void();
}
+
+ if (destSize > destBuffer.size) {
+ _hidl_cb(Status::BAD_VALUE, 0, "subsample sum too large");
+ return Void();
+ }
+
destPtr = static_cast<void *>(base + destination.nonsecureMemory.offset);
} else if (destination.type == BufferType::NATIVE_HANDLE) {
+ if (!secure) {
+ _hidl_cb(Status::BAD_VALUE, 0, "native handle destination must be secure");
+ return Void();
+ }
native_handle_t *handle = const_cast<native_handle_t *>(
destination.secureMemory.getNativeHandle());
destPtr = static_cast<void *>(handle);
+ } else {
+ _hidl_cb(Status::BAD_VALUE, 0, "invalid destination type");
+ return Void();
}
ssize_t result = mLegacyPlugin->decrypt(secure, keyId.data(), iv.data(),
legacyMode, legacyPattern, srcPtr, legacySubSamples.get(),
diff --git a/graphics/composer/2.1/utils/hwc2on1adapter/Android.bp b/graphics/composer/2.1/utils/hwc2on1adapter/Android.bp
index 0af9745..ec7a0b9 100644
--- a/graphics/composer/2.1/utils/hwc2on1adapter/Android.bp
+++ b/graphics/composer/2.1/utils/hwc2on1adapter/Android.bp
@@ -22,40 +22,12 @@
"-Werror",
],
cppflags: [
- "-Weverything",
+ "-Wextra",
"-Wunused",
"-Wunreachable-code",
- // The static constructors and destructors in this library have not been noted to
- // introduce significant overheads
- "-Wno-exit-time-destructors",
- "-Wno-global-constructors",
-
- // We only care about compiling as C++14
- "-Wno-c++98-compat-pedantic",
-
- // android/sensors.h uses nested anonymous unions and anonymous structs
- "-Wno-nested-anon-types",
- "-Wno-gnu-anonymous-struct",
-
- // Don't warn about struct padding
- "-Wno-padded",
-
- // hwcomposer2.h features switch covering all cases.
- "-Wno-covered-switch-default",
-
- // hwcomposer.h features zero size array.
- "-Wno-zero-length-array",
-
// Disabling warning specific to hwc2on1adapter code
- "-Wno-double-promotion",
- "-Wno-sign-conversion",
- "-Wno-switch-enum",
- "-Wno-float-equal",
- "-Wno-shorten-64-to-32",
"-Wno-sign-compare",
- "-Wno-missing-prototypes",
- "-Wno-format-pedantic",
],
srcs: [
diff --git a/health/2.1/vts/functional/VtsHalHealthV2_1TargetTest.cpp b/health/2.1/vts/functional/VtsHalHealthV2_1TargetTest.cpp
index 7df4926..da9f5bb 100644
--- a/health/2.1/vts/functional/VtsHalHealthV2_1TargetTest.cpp
+++ b/health/2.1/vts/functional/VtsHalHealthV2_1TargetTest.cpp
@@ -252,7 +252,7 @@
}
INSTANTIATE_TEST_SUITE_P(
- , HealthHidlTest,
+ PerInstance, HealthHidlTest,
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IHealth::descriptor)),
android::hardware::PrintInstanceNameToString);
diff --git a/media/omx/1.0/vts/functional/README.md b/media/omx/1.0/vts/functional/README.md
index acffc42..274b30d 100644
--- a/media/omx/1.0/vts/functional/README.md
+++ b/media/omx/1.0/vts/functional/README.md
@@ -18,17 +18,17 @@
usage:
-VtsHalMediaOmxV1\_0TargetAudioDecTest -I default -C <comp name> -R audio_decoder.<comp class> -P /sdcard/media/
+VtsHalMediaOmxV1\_0TargetAudioDecTest -I default -C <comp name> -R audio_decoder.<comp class> -P /data/local/tmp/media/
-VtsHalMediaOmxV1\_0TargetAudioEncTest -I default -C <comp name> -R audio_encoder.<comp class> -P /sdcard/media/
+VtsHalMediaOmxV1\_0TargetAudioEncTest -I default -C <comp name> -R audio_encoder.<comp class> -P /data/local/tmp/media/
#### video :
This folder includes test fixtures associated with testing video encoder and decoder components such as simple encoding of a raw clip or decoding of an elementary stream, end of stream test, timestamp deviations test, flush test and so on. These tests are aimed towards testing the plugin that connects the component to the omx core.
usage:
-VtsHalMediaOmxV1\_0TargetVideoDecTest -I default -C <comp name> -R video_decoder.<comp class> -P /sdcard/media/
+VtsHalMediaOmxV1\_0TargetVideoDecTest -I default -C <comp name> -R video_decoder.<comp class> -P /data/local/tmp/media/
-VtsHalMediaOmxV1\_0TargetVideoEncTest -I default -C <comp name> -R video_encoder.<comp class> -P /sdcard/media/
+VtsHalMediaOmxV1\_0TargetVideoEncTest -I default -C <comp name> -R video_encoder.<comp class> -P /data/local/tmp/media/
-While tesing audio/video encoder, decoder components, test fixtures require input files. These input are files are present in the folder 'res'. Before running the tests all the files in 'res' have to be placed in '/media/sdcard/' or a path of your choice and this path needs to be provided as an argument to the test application
\ No newline at end of file
+While tesing audio/video encoder, decoder components, test fixtures require input files. These input are files are present in the folder 'res'. Before running the tests all the files in 'res' have to be placed in '/data/local/tmp/media' or a path of your choice and this path needs to be provided as an argument to the test application
diff --git a/media/omx/1.0/vts/functional/common/Android.bp b/media/omx/1.0/vts/functional/common/Android.bp
index cdc52fb..5a79e55 100644
--- a/media/omx/1.0/vts/functional/common/Android.bp
+++ b/media/omx/1.0/vts/functional/common/Android.bp
@@ -29,6 +29,21 @@
"android.hidl.memory@1.0",
"android.hardware.media.omx@1.0",
"android.hardware.graphics.allocator@2.0",
+ "android.hardware.graphics.allocator@3.0",
+ "android.hardware.graphics.common@1.0",
+ "android.hardware.graphics.common@1.1",
+ "android.hardware.graphics.common@1.2",
+ "android.hardware.graphics.mapper@2.0",
+ "android.hardware.graphics.mapper@3.0",
+ ],
+ export_static_lib_headers: [
+ "android.hardware.graphics.allocator@2.0",
+ "android.hardware.graphics.allocator@3.0",
+ "android.hardware.graphics.common@1.0",
+ "android.hardware.graphics.common@1.1",
+ "android.hardware.graphics.common@1.2",
+ "android.hardware.graphics.mapper@2.0",
+ "android.hardware.graphics.mapper@3.0",
],
}
@@ -40,7 +55,12 @@
static_libs: [
"VtsHalMediaOmxV1_0CommonUtil",
"android.hardware.graphics.allocator@2.0",
+ "android.hardware.graphics.allocator@3.0",
+ "android.hardware.graphics.common@1.0",
+ "android.hardware.graphics.common@1.1",
+ "android.hardware.graphics.common@1.2",
"android.hardware.graphics.mapper@2.0",
+ "android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.bufferqueue@1.0",
"android.hardware.graphics.common@1.0",
"android.hardware.media.omx@1.0",
diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp b/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
index f299e36..8d4c022 100644
--- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
+++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
@@ -22,8 +22,11 @@
#include <android-base/logging.h>
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
+#include <android/hardware/graphics/allocator/3.0/IAllocator.h>
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
#include <android/hardware/graphics/mapper/2.0/types.h>
+#include <android/hardware/graphics/mapper/3.0/IMapper.h>
+#include <android/hardware/graphics/mapper/3.0/types.h>
#include <android/hardware/media/omx/1.0/IOmx.h>
#include <android/hardware/media/omx/1.0/IOmxNode.h>
#include <android/hardware/media/omx/1.0/IOmxObserver.h>
@@ -31,7 +34,9 @@
#include <android/hidl/allocator/1.0/IAllocator.h>
#include <android/hidl/memory/1.0/IMapper.h>
#include <android/hidl/memory/1.0/IMemory.h>
-#include <cutils/atomic.h>
+
+#include <atomic>
+#include <variant>
using ::android::hardware::graphics::common::V1_0::BufferUsage;
using ::android::hardware::graphics::common::V1_0::PixelFormat;
@@ -195,67 +200,104 @@
BufferInfo* buffer, uint32_t nFrameWidth,
uint32_t nFrameHeight, int32_t* nStride,
int format) {
- android::hardware::media::omx::V1_0::Status status;
- sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator =
- android::hardware::graphics::allocator::V2_0::IAllocator::getService();
- ASSERT_NE(nullptr, allocator.get());
+ struct AllocatorV2 : public GrallocV2 {
+ sp<IAllocator> mAllocator;
+ sp<IMapper> mMapper;
+ AllocatorV2(sp<IAllocator>&& allocator, sp<IMapper>&& mapper)
+ : mAllocator{std::move(allocator)}, mMapper{std::move(mapper)} {}
+ AllocatorV2() = default;
+ };
+ struct AllocatorV3 : public GrallocV3 {
+ sp<IAllocator> mAllocator;
+ sp<IMapper> mMapper;
+ AllocatorV3(sp<IAllocator>&& allocator, sp<IMapper>&& mapper)
+ : mAllocator{std::move(allocator)}, mMapper{std::move(mapper)} {}
+ AllocatorV3() = default;
+ };
+ std::variant<AllocatorV2, AllocatorV3> grallocVar;
- sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
- android::hardware::graphics::mapper::V2_0::IMapper::getService();
- ASSERT_NE(mapper.get(), nullptr);
+ sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2{};
+ sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3{};
+ sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator2{};
+ sp<android::hardware::graphics::allocator::V3_0::IAllocator> allocator3 =
+ android::hardware::graphics::allocator::V3_0::IAllocator::getService();
+ if (allocator3) {
+ mapper3 =
+ android::hardware::graphics::mapper::V3_0::IMapper::getService();
+ ASSERT_NE(nullptr, mapper3.get());
+ grallocVar.emplace<AllocatorV3>(std::move(allocator3), std::move(mapper3));
+ } else {
+ allocator2 =
+ android::hardware::graphics::allocator::V2_0::IAllocator::getService();
+ ASSERT_NE(nullptr, allocator2.get());
+ mapper2 =
+ android::hardware::graphics::mapper::V2_0::IMapper::getService();
+ ASSERT_NE(nullptr, allocator2.get());
+ grallocVar.emplace<AllocatorV2>(std::move(allocator2), std::move(mapper2));
+ }
- android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo
- descriptorInfo;
- uint32_t usage;
-
- descriptorInfo.width = nFrameWidth;
- descriptorInfo.height = nFrameHeight;
- descriptorInfo.layerCount = 1;
- descriptorInfo.format = static_cast<PixelFormat>(format);
- descriptorInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN);
- omxNode->getGraphicBufferUsage(
+ android::hardware::media::omx::V1_0::Status status{};
+ uint64_t usage{};
+ ASSERT_TRUE(omxNode->getGraphicBufferUsage(
portIndex,
[&status, &usage](android::hardware::media::omx::V1_0::Status _s,
uint32_t _n1) {
status = _s;
usage = _n1;
- });
- if (status == android::hardware::media::omx::V1_0::Status::OK) {
- descriptorInfo.usage |= usage;
- }
+ }).isOk());
+ ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
- ::android::hardware::hidl_vec<uint32_t> descriptor;
- android::hardware::graphics::mapper::V2_0::Error error;
- mapper->createDescriptor(
- descriptorInfo, [&error, &descriptor](
- android::hardware::graphics::mapper::V2_0::Error _s,
- ::android::hardware::hidl_vec<uint32_t> _n1) {
- error = _s;
- descriptor = _n1;
- });
- ASSERT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
+ static std::atomic_int32_t bufferIdCounter{0};
- static volatile int32_t nextId = 0;
- uint64_t id = static_cast<uint64_t>(getpid()) << 32;
- allocator->allocate(
- descriptor, 1,
- [&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1,
- const ::android::hardware::hidl_vec<
- ::android::hardware::hidl_handle>& _n2) {
- ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE,
- _s);
- *nStride = _n1;
- buffer->omxBuffer.nativeHandle = _n2[0];
- buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth;
- buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight;
- buffer->omxBuffer.attr.anwBuffer.stride = _n1;
- buffer->omxBuffer.attr.anwBuffer.format = descriptorInfo.format;
- buffer->omxBuffer.attr.anwBuffer.usage = descriptorInfo.usage;
- buffer->omxBuffer.attr.anwBuffer.layerCount =
- descriptorInfo.layerCount;
- buffer->omxBuffer.attr.anwBuffer.id =
- id | static_cast<uint32_t>(android_atomic_inc(&nextId));
- });
+ std::visit([buffer, nFrameWidth, nFrameHeight, format, usage, nStride](auto&& gralloc) {
+ using Gralloc = std::remove_reference_t<decltype(gralloc)>;
+ using Descriptor = typename Gralloc::Descriptor;
+ using DescriptorInfo = typename Gralloc::DescriptorInfo;
+ using Error = typename Gralloc::Error;
+ using Format = typename Gralloc::Format;
+ using Usage = typename Gralloc::Usage;
+
+ Error error{};
+ Descriptor descriptor{};
+
+ DescriptorInfo descriptorInfo{};
+ descriptorInfo.width = nFrameWidth;
+ descriptorInfo.height = nFrameHeight;
+ descriptorInfo.layerCount = 1;
+ descriptorInfo.format = static_cast<Format>(format);
+ descriptorInfo.usage = usage | Usage(BufferUsage::CPU_READ_OFTEN);
+
+ gralloc.mMapper->createDescriptor(descriptorInfo,
+ [&error, &descriptor](
+ Error _s,
+ const Descriptor& _n1) {
+ error = _s;
+ descriptor = _n1;
+ });
+ ASSERT_EQ(error, Error::NONE);
+
+ gralloc.mAllocator->allocate(
+ descriptor, 1,
+ [&](Error _s, uint32_t _n1,
+ const ::android::hardware::hidl_vec<
+ ::android::hardware::hidl_handle>& _n2) {
+ ASSERT_EQ(Error::NONE, _s);
+ *nStride = _n1;
+ buffer->omxBuffer.nativeHandle = _n2[0];
+ buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth;
+ buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight;
+ buffer->omxBuffer.attr.anwBuffer.stride = _n1;
+ buffer->omxBuffer.attr.anwBuffer.format =
+ static_cast<PixelFormat>(descriptorInfo.format);
+ buffer->omxBuffer.attr.anwBuffer.usage =
+ static_cast<uint32_t>(descriptorInfo.usage);
+ buffer->omxBuffer.attr.anwBuffer.layerCount =
+ descriptorInfo.layerCount;
+ buffer->omxBuffer.attr.anwBuffer.id =
+ (static_cast<uint64_t>(getpid()) << 32) |
+ bufferIdCounter.fetch_add(1, std::memory_order_relaxed);
+ });
+ }, grallocVar);
}
// allocate buffers needed on a component port
diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
index 1575ba2..ac077a3 100644
--- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
+++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
@@ -22,6 +22,16 @@
#endif
#include <getopt.h>
+
+#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
+#include <android/hardware/graphics/allocator/3.0/IAllocator.h>
+#include <android/hardware/graphics/common/1.0/types.h>
+#include <android/hardware/graphics/common/1.1/types.h>
+#include <android/hardware/graphics/common/1.2/types.h>
+#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+#include <android/hardware/graphics/mapper/2.0/types.h>
+#include <android/hardware/graphics/mapper/3.0/IMapper.h>
+#include <android/hardware/graphics/mapper/3.0/types.h>
#include <media/stagefright/foundation/ALooper.h>
#include <utils/Condition.h>
#include <utils/List.h>
@@ -288,6 +298,36 @@
/*
* common functions declarations
*/
+struct GrallocV2 {
+ using Format = android::hardware::graphics::common::V1_0::PixelFormat;
+ using Usage = android::hardware::hidl_bitfield<
+ android::hardware::graphics::common::V1_0::BufferUsage>;
+
+ using IAllocator = android::hardware::graphics::allocator::V2_0::IAllocator;
+
+ using IMapper = android::hardware::graphics::mapper::V2_0::IMapper;
+ using Error = android::hardware::graphics::mapper::V2_0::Error;
+ using Descriptor = android::hardware::graphics::mapper::V2_0::BufferDescriptor;
+ using YCbCrLayout = android::hardware::graphics::mapper::V2_0::YCbCrLayout;
+ using DescriptorInfo = IMapper::BufferDescriptorInfo;
+ using Rect = IMapper::Rect;
+};
+
+struct GrallocV3 {
+ using Format = android::hardware::graphics::common::V1_2::PixelFormat;
+ using Usage = android::hardware::hidl_bitfield<
+ android::hardware::graphics::common::V1_2::BufferUsage>;
+
+ using IAllocator = android::hardware::graphics::allocator::V3_0::IAllocator;
+
+ using IMapper = android::hardware::graphics::mapper::V3_0::IMapper;
+ using Error = android::hardware::graphics::mapper::V3_0::Error;
+ using Descriptor = android::hardware::graphics::mapper::V3_0::BufferDescriptor;
+ using YCbCrLayout = android::hardware::graphics::mapper::V3_0::YCbCrLayout;
+ using DescriptorInfo = IMapper::BufferDescriptorInfo;
+ using Rect = IMapper::Rect;
+};
+
Return<android::hardware::media::omx::V1_0::Status> setRole(
sp<IOmxNode> omxNode, const char* role);
@@ -368,7 +408,7 @@
public:
virtual void registerTestServices() override { registerTestService<IOmx>(); }
- ComponentTestEnvironment() : res("/sdcard/media/") {}
+ ComponentTestEnvironment() : res("/data/local/tmp/media/") {}
void setComponent(const char* _component) { component = _component; }
diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
index a740a80..2280cee 100644
--- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
+++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
@@ -63,6 +63,7 @@
#include <media_video_hidl_test_common.h>
#include <system/window.h>
#include <fstream>
+#include <variant>
static ComponentTestEnvironment* gEnv = nullptr;
@@ -364,6 +365,61 @@
return Void();
};
+// Variant of mappers
+struct MapperV2 : public GrallocV2 {
+ sp<IMapper> mMapper;
+ MapperV2(sp<IMapper>&& mapper): mMapper{std::move(mapper)} {}
+ MapperV2() = default;
+ android::hardware::Return<void> lock(
+ void* buffer,
+ Usage usage,
+ const Rect& rect,
+ const android::hardware::hidl_handle& handle,
+ Error* error,
+ void** data) {
+ return mMapper->lock(buffer, usage, rect, handle,
+ [error, data](Error e, void* d) {
+ *error = e;
+ *data = d;
+ });
+ }
+};
+struct MapperV3 : public GrallocV3 {
+ sp<IMapper> mMapper;
+ MapperV3(sp<IMapper>&& mapper): mMapper{std::move(mapper)} {}
+ MapperV3() = default;
+ android::hardware::Return<void> lock(
+ void* buffer,
+ Usage usage,
+ const Rect& rect,
+ const android::hardware::hidl_handle& handle,
+ Error* error,
+ void** data) {
+ return mMapper->lock(buffer, usage, rect, handle,
+ [error, data](Error e, void* d, int32_t, int32_t) {
+ *error = e;
+ *data = d;
+ });
+ }
+};
+using MapperVar = std::variant<MapperV2, MapperV3>;
+// Initializes the MapperVar by trying services of different versions.
+bool initialize(MapperVar& mapperVar) {
+ sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3 =
+ android::hardware::graphics::mapper::V3_0::IMapper::getService();
+ if (mapper3) {
+ mapperVar.emplace<MapperV3>(std::move(mapper3));
+ return true;
+ }
+ sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2 =
+ android::hardware::graphics::mapper::V2_0::IMapper::getService();
+ if (mapper2) {
+ mapperVar.emplace<MapperV2>(std::move(mapper2));
+ return true;
+ }
+ return false;
+}
+
// request VOP refresh
void requestIDR(sp<IOmxNode> omxNode, OMX_U32 portIndex) {
android::hardware::media::omx::V1_0::Status status;
@@ -574,150 +630,166 @@
int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format,
std::ifstream& eleStream) {
- sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
- android::hardware::graphics::mapper::V2_0::IMapper::getService();
- EXPECT_NE(mapper.get(), nullptr);
- if (mapper.get() == nullptr) return 1;
-
- android::hardware::hidl_handle fence;
- android::hardware::graphics::mapper::V2_0::IMapper::Rect rect;
- android::hardware::graphics::mapper::V2_0::YCbCrLayout ycbcrLayout;
- android::hardware::graphics::mapper::V2_0::Error error;
- rect.left = 0;
- rect.top = 0;
- rect.width = buffer->omxBuffer.attr.anwBuffer.width;
- rect.height = buffer->omxBuffer.attr.anwBuffer.height;
-
- if (format == PixelFormat::YV12 || format == PixelFormat::YCRCB_420_SP ||
- format == PixelFormat::YCBCR_420_888) {
- mapper->lockYCbCr(
- buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence,
- [&](android::hardware::graphics::mapper::V2_0::Error _e,
- android::hardware::graphics::mapper::V2_0::YCbCrLayout _n1) {
- error = _e;
- ycbcrLayout = _n1;
- });
- EXPECT_EQ(error,
- android::hardware::graphics::mapper::V2_0::Error::NONE);
- if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
- return 1;
-
- int size = ((rect.width * rect.height * 3) >> 1);
- char* img = new char[size];
- if (img == nullptr) return 1;
- eleStream.read(img, size);
- if (eleStream.gcount() != size) {
- delete[] img;
- return 1;
- }
-
- char* imgTmp = img;
- char* ipBuffer = static_cast<char*>(ycbcrLayout.y);
- for (size_t y = rect.height; y > 0; --y) {
- memcpy(ipBuffer, imgTmp, rect.width);
- ipBuffer += ycbcrLayout.yStride;
- imgTmp += rect.width;
- }
-
- if (format == PixelFormat::YV12)
- EXPECT_EQ(ycbcrLayout.chromaStep, 1U);
- else if (format == PixelFormat::YCRCB_420_SP)
- EXPECT_EQ(ycbcrLayout.chromaStep, 2U);
-
- ipBuffer = static_cast<char*>(ycbcrLayout.cb);
- for (size_t y = rect.height >> 1; y > 0; --y) {
- for (int32_t x = 0; x < (rect.width >> 1); ++x) {
- ipBuffer[ycbcrLayout.chromaStep * x] = *imgTmp++;
- }
- ipBuffer += ycbcrLayout.cStride;
- }
- ipBuffer = static_cast<char*>(ycbcrLayout.cr);
- for (size_t y = rect.height >> 1; y > 0; --y) {
- for (int32_t x = 0; x < (rect.width >> 1); ++x) {
- ipBuffer[ycbcrLayout.chromaStep * x] = *imgTmp++;
- }
- ipBuffer += ycbcrLayout.cStride;
- }
-
- delete[] img;
-
- mapper->unlock(buff,
- [&](android::hardware::graphics::mapper::V2_0::Error _e,
- android::hardware::hidl_handle _n1) {
- error = _e;
- fence = _n1;
- });
- EXPECT_EQ(error,
- android::hardware::graphics::mapper::V2_0::Error::NONE);
- if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
- return 1;
- } else {
- void* data;
- mapper->lock(buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence,
- [&](android::hardware::graphics::mapper::V2_0::Error _e,
- void* _n1) {
- error = _e;
- data = _n1;
- });
- EXPECT_EQ(error,
- android::hardware::graphics::mapper::V2_0::Error::NONE);
- if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
- return 1;
-
- if (format == PixelFormat::BGRA_8888) {
- char* ipBuffer = static_cast<char*>(data);
- for (size_t y = rect.height; y > 0; --y) {
- eleStream.read(ipBuffer, rect.width * 4);
- if (eleStream.gcount() != rect.width * 4) return 1;
- ipBuffer += buffer->omxBuffer.attr.anwBuffer.stride * 4;
- }
- } else {
- EXPECT_TRUE(false) << "un expected pixel format";
- return 1;
- }
-
- mapper->unlock(buff,
- [&](android::hardware::graphics::mapper::V2_0::Error _e,
- android::hardware::hidl_handle _n1) {
- error = _e;
- fence = _n1;
- });
- EXPECT_EQ(error,
- android::hardware::graphics::mapper::V2_0::Error::NONE);
- if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
- return 1;
+ MapperVar mapperVar;
+ if (!initialize(mapperVar)) {
+ EXPECT_TRUE(false) << "failed to obtain mapper service";
+ return 1;
}
- return 0;
+ return std::visit([buffer, buff, format, &eleStream](auto&& mapper) -> int {
+ using Gralloc = std::remove_reference_t<decltype(mapper)>;
+ using Error = typename Gralloc::Error;
+ using Rect = typename Gralloc::Rect;
+ using Usage = typename Gralloc::Usage;
+ using YCbCrLayout = typename Gralloc::YCbCrLayout;
+
+ android::hardware::hidl_handle fence;
+ Rect rect;
+ YCbCrLayout ycbcrLayout;
+ Error error;
+ rect.left = 0;
+ rect.top = 0;
+ rect.width = buffer->omxBuffer.attr.anwBuffer.width;
+ rect.height = buffer->omxBuffer.attr.anwBuffer.height;
+
+ if (format == PixelFormat::YV12 || format == PixelFormat::YCRCB_420_SP ||
+ format == PixelFormat::YCBCR_420_888) {
+ mapper.mMapper->lockYCbCr(
+ buff,
+ static_cast<Usage>(
+ buffer->omxBuffer.attr.anwBuffer.usage),
+ rect,
+ fence,
+ [&](Error _e,
+ const YCbCrLayout& _n1) {
+ error = _e;
+ ycbcrLayout = _n1;
+ });
+ EXPECT_EQ(error, Error::NONE);
+ if (error != Error::NONE)
+ return 1;
+
+ int size = ((rect.width * rect.height * 3) >> 1);
+ char* img = new char[size];
+ if (img == nullptr) return 1;
+ eleStream.read(img, size);
+ if (eleStream.gcount() != size) {
+ delete[] img;
+ return 1;
+ }
+
+ char* imgTmp = img;
+ char* ipBuffer = static_cast<char*>(ycbcrLayout.y);
+ for (size_t y = rect.height; y > 0; --y) {
+ memcpy(ipBuffer, imgTmp, rect.width);
+ ipBuffer += ycbcrLayout.yStride;
+ imgTmp += rect.width;
+ }
+
+ if (format == PixelFormat::YV12)
+ EXPECT_EQ(ycbcrLayout.chromaStep, 1U);
+ else if (format == PixelFormat::YCRCB_420_SP)
+ EXPECT_EQ(ycbcrLayout.chromaStep, 2U);
+
+ ipBuffer = static_cast<char*>(ycbcrLayout.cb);
+ for (size_t y = rect.height >> 1; y > 0; --y) {
+ for (int32_t x = 0; x < (rect.width >> 1); ++x) {
+ ipBuffer[ycbcrLayout.chromaStep * x] = *imgTmp++;
+ }
+ ipBuffer += ycbcrLayout.cStride;
+ }
+ ipBuffer = static_cast<char*>(ycbcrLayout.cr);
+ for (size_t y = rect.height >> 1; y > 0; --y) {
+ for (int32_t x = 0; x < (rect.width >> 1); ++x) {
+ ipBuffer[ycbcrLayout.chromaStep * x] = *imgTmp++;
+ }
+ ipBuffer += ycbcrLayout.cStride;
+ }
+
+ delete[] img;
+
+ mapper.mMapper->unlock(buff,
+ [&](Error _e,
+ const android::hardware::hidl_handle& _n1) {
+ error = _e;
+ fence = _n1;
+ });
+ EXPECT_EQ(error, Error::NONE);
+ if (error != Error::NONE)
+ return 1;
+ } else {
+ void* data;
+ mapper.lock(
+ buff,
+ buffer->omxBuffer.attr.anwBuffer.usage,
+ rect,
+ fence,
+ &error,
+ &data);
+ EXPECT_EQ(error, Error::NONE);
+ if (error != Error::NONE)
+ return 1;
+
+ if (format == PixelFormat::BGRA_8888) {
+ char* ipBuffer = static_cast<char*>(data);
+ for (size_t y = rect.height; y > 0; --y) {
+ eleStream.read(ipBuffer, rect.width * 4);
+ if (eleStream.gcount() != rect.width * 4) return 1;
+ ipBuffer += buffer->omxBuffer.attr.anwBuffer.stride * 4;
+ }
+ } else {
+ EXPECT_TRUE(false) << "un expected pixel format";
+ return 1;
+ }
+
+ mapper.mMapper->unlock(
+ buff,
+ [&](Error _e, const android::hardware::hidl_handle& _n1) {
+ error = _e;
+ fence = _n1;
+ });
+ EXPECT_EQ(error, Error::NONE);
+ if (error != Error::NONE)
+ return 1;
+ }
+
+ return 0;
+ }, mapperVar);
}
int fillGraphicBuffer(BufferInfo* buffer, PixelFormat format,
std::ifstream& eleStream) {
- sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
- android::hardware::graphics::mapper::V2_0::IMapper::getService();
- EXPECT_NE(mapper.get(), nullptr);
- if (mapper.get() == nullptr) return 1;
-
- void* buff = nullptr;
- android::hardware::graphics::mapper::V2_0::Error error;
- mapper->importBuffer(
- buffer->omxBuffer.nativeHandle,
- [&](android::hardware::graphics::mapper::V2_0::Error _e, void* _n1) {
- error = _e;
- buff = _n1;
- });
- EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
- if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
+ MapperVar mapperVar;
+ if (!initialize(mapperVar)) {
+ EXPECT_TRUE(false) << "failed to obtain mapper service";
return 1;
+ }
- if (colorFormatConversion(buffer, buff, format, eleStream)) return 1;
+ return std::visit([buffer, format, &eleStream](auto&& mapper) -> int {
+ using Gralloc = std::remove_reference_t<decltype(mapper)>;
+ using Error = typename Gralloc::Error;
- error = mapper->freeBuffer(buff);
- EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
- if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
- return 1;
+ void* buff = nullptr;
+ Error error;
+ mapper.mMapper->importBuffer(
+ buffer->omxBuffer.nativeHandle,
+ [&](Error _e, void* _n1) {
+ error = _e;
+ buff = _n1;
+ });
+ EXPECT_EQ(error, Error::NONE);
+ if (error != Error::NONE)
+ return 1;
- return 0;
+ if (colorFormatConversion(buffer, buff, format, eleStream)) return 1;
+
+ error = mapper.mMapper->freeBuffer(buff);
+ EXPECT_EQ(error, Error::NONE);
+ if (error != Error::NONE)
+ return 1;
+
+ return 0;
+ }, mapperVar);
}
int dispatchGraphicBuffer(sp<IOmxNode> omxNode,
diff --git a/vibrator/aidl/android/hardware/vibrator/IVibrator.aidl b/vibrator/aidl/android/hardware/vibrator/IVibrator.aidl
index ceaa0a0..8c4fd05 100644
--- a/vibrator/aidl/android/hardware/vibrator/IVibrator.aidl
+++ b/vibrator/aidl/android/hardware/vibrator/IVibrator.aidl
@@ -51,7 +51,8 @@
/**
* Turn off vibrator
*
- * Cancel a previously-started vibration, if any.
+ * Cancel a previously-started vibration, if any. If a previously-started vibration is
+ * associated with a callback, then onComplete should still be called on that callback.
*/
void off();
@@ -62,6 +63,9 @@
* was canceled (through off()). A callback is only expected to be supported when
* getCapabilities CAP_ON_CALLBACK is specified.
*
+ * Doing this operation while the vibrator is already on is undefined behavior. Clients should
+ * explicitly call off.
+ *
* @param timeoutMs number of milliseconds to vibrate.
* @param callback A callback used to inform Frameworks of state change, if supported.
*/
@@ -73,6 +77,9 @@
* A callback is only expected to be supported when getCapabilities CAP_PERFORM_CALLBACK
* is specified.
*
+ * Doing this operation while the vibrator is already on is undefined behavior. Clients should
+ * explicitly call off.
+ *
* @param effect The type of haptic event to trigger.
* @param strength The intensity of haptic event to trigger.
* @param callback A callback used to inform Frameworks of state change, if supported.
diff --git a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
index aeb9b70..b6aa9e2 100644
--- a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
+++ b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
@@ -46,13 +46,13 @@
EffectStrength::STRONG};
const std::vector<Effect> kInvalidEffects = {
- static_cast<Effect>(static_cast<int32_t>(*kEffects.begin()) - 1),
- static_cast<Effect>(static_cast<int32_t>(*kEffects.end()) + 1),
+ static_cast<Effect>(static_cast<int32_t>(kEffects.front()) - 1),
+ static_cast<Effect>(static_cast<int32_t>(kEffects.back()) + 1),
};
const std::vector<EffectStrength> kInvalidEffectStrengths = {
- static_cast<EffectStrength>(static_cast<int8_t>(*kEffectStrengths.begin()) - 1),
- static_cast<EffectStrength>(static_cast<int8_t>(*kEffectStrengths.end()) + 1),
+ static_cast<EffectStrength>(static_cast<int8_t>(kEffectStrengths.front()) - 1),
+ static_cast<EffectStrength>(static_cast<int8_t>(kEffectStrengths.back()) + 1),
};
class CompletionCallback : public BnVibratorCallback {
@@ -119,10 +119,13 @@
Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs);
if (isEffectSupported) {
- EXPECT_TRUE(status.isOk());
+ EXPECT_TRUE(status.isOk())
+ << static_cast<int>(effect) << " " << static_cast<int>(strength);
EXPECT_GT(lengthMs, 0);
+ usleep(lengthMs * 1000);
} else {
- EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION);
+ EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION)
+ << static_cast<int>(effect) << " " << static_cast<int>(strength);
EXPECT_EQ(lengthMs, 0);
}
}
@@ -179,10 +182,19 @@
TEST_P(VibratorAidl, InvalidEffectsUnsupported) {
for (Effect effect : kInvalidEffects) {
+ for (EffectStrength strength : kEffectStrengths) {
+ int32_t lengthMs;
+ Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs);
+ EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION)
+ << static_cast<int>(effect) << " " << static_cast<int>(strength);
+ }
+ }
+ for (Effect effect : kEffects) {
for (EffectStrength strength : kInvalidEffectStrengths) {
int32_t lengthMs;
Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs);
- EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION);
+ EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION)
+ << static_cast<int>(effect) << " " << static_cast<int>(strength);
}
}
}
@@ -247,7 +259,7 @@
}
}
-INSTANTIATE_TEST_SUITE_P(, VibratorAidl,
+INSTANTIATE_TEST_SUITE_P(Vibrator, VibratorAidl,
testing::ValuesIn(android::getAidlHalInstanceNames(IVibrator::descriptor)),
android::PrintInstanceNameToString);
diff --git a/wifi/1.0/vts/functional/wifi_hidl_test_utils.cpp b/wifi/1.0/vts/functional/wifi_hidl_test_utils.cpp
index 97a371b..f89f7b4 100644
--- a/wifi/1.0/vts/functional/wifi_hidl_test_utils.cpp
+++ b/wifi/1.0/vts/functional/wifi_hidl_test_utils.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <android/log.h>
+
#include <VtsHalHidlTargetTestBase.h>
#include "wifi_hidl_call_util.h"
@@ -87,14 +89,21 @@
}
} // namespace
-sp<IWifi> getWifi() {
- sp<IWifi> wifi = ::testing::VtsHalHidlTargetTestBase::getService<IWifi>(
- gEnv->getServiceName<IWifi>());
- return wifi;
+sp<IWifi> getWifi(const std::string& instance_name) {
+ if ((!gEnv && instance_name.empty()) || (gEnv && !instance_name.empty())) {
+ ALOGE("instance_name and gEnv must have one and only one set.");
+ return nullptr;
+ }
+ if (gEnv) {
+ return ::testing::VtsHalHidlTargetTestBase::getService<IWifi>(
+ gEnv->getServiceName<IWifi>());
+ } else {
+ return IWifi::getService(instance_name);
+ }
}
-sp<IWifiChip> getWifiChip() {
- sp<IWifi> wifi = getWifi();
+sp<IWifiChip> getWifiChip(const std::string& instance_name) {
+ sp<IWifi> wifi = getWifi(instance_name);
if (!wifi.get()) {
return nullptr;
}
@@ -122,8 +131,8 @@
return status_and_chip.second;
}
-sp<IWifiApIface> getWifiApIface() {
- sp<IWifiChip> wifi_chip = getWifiChip();
+sp<IWifiApIface> getWifiApIface(const std::string& instance_name) {
+ sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
if (!wifi_chip.get()) {
return nullptr;
}
@@ -137,8 +146,8 @@
return status_and_iface.second;
}
-sp<IWifiNanIface> getWifiNanIface() {
- sp<IWifiChip> wifi_chip = getWifiChip();
+sp<IWifiNanIface> getWifiNanIface(const std::string& instance_name) {
+ sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
if (!wifi_chip.get()) {
return nullptr;
}
@@ -152,8 +161,8 @@
return status_and_iface.second;
}
-sp<IWifiP2pIface> getWifiP2pIface() {
- sp<IWifiChip> wifi_chip = getWifiChip();
+sp<IWifiP2pIface> getWifiP2pIface(const std::string& instance_name) {
+ sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
if (!wifi_chip.get()) {
return nullptr;
}
@@ -167,8 +176,8 @@
return status_and_iface.second;
}
-sp<IWifiStaIface> getWifiStaIface() {
- sp<IWifiChip> wifi_chip = getWifiChip();
+sp<IWifiStaIface> getWifiStaIface(const std::string& instance_name) {
+ sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
if (!wifi_chip.get()) {
return nullptr;
}
@@ -182,8 +191,8 @@
return status_and_iface.second;
}
-sp<IWifiRttController> getWifiRttController() {
- sp<IWifiChip> wifi_chip = getWifiChip();
+sp<IWifiRttController> getWifiRttController(const std::string& instance_name) {
+ sp<IWifiChip> wifi_chip = getWifiChip(instance_name);
if (!wifi_chip.get()) {
return nullptr;
}
@@ -206,8 +215,8 @@
configured_mode_id);
}
-void stopWifi() {
- sp<IWifi> wifi = getWifi();
+void stopWifi(const std::string& instance_name) {
+ sp<IWifi> wifi = getWifi(instance_name);
ASSERT_NE(wifi, nullptr);
HIDL_INVOKE(wifi, stop);
}
diff --git a/wifi/1.0/vts/functional/wifi_hidl_test_utils.h b/wifi/1.0/vts/functional/wifi_hidl_test_utils.h
index d430ce0..529b142 100644
--- a/wifi/1.0/vts/functional/wifi_hidl_test_utils.h
+++ b/wifi/1.0/vts/functional/wifi_hidl_test_utils.h
@@ -31,14 +31,21 @@
// Note: We only have a single instance of each of these objects currently.
// These helper functions should be modified to return vectors if we support
// multiple instances.
-android::sp<android::hardware::wifi::V1_0::IWifi> getWifi();
-android::sp<android::hardware::wifi::V1_0::IWifiChip> getWifiChip();
-android::sp<android::hardware::wifi::V1_0::IWifiApIface> getWifiApIface();
-android::sp<android::hardware::wifi::V1_0::IWifiNanIface> getWifiNanIface();
-android::sp<android::hardware::wifi::V1_0::IWifiP2pIface> getWifiP2pIface();
-android::sp<android::hardware::wifi::V1_0::IWifiStaIface> getWifiStaIface();
+// TODO(b/143892896): Remove the default value as part of the cleanup.
+android::sp<android::hardware::wifi::V1_0::IWifi> getWifi(
+ const std::string& instance_name = "");
+android::sp<android::hardware::wifi::V1_0::IWifiChip> getWifiChip(
+ const std::string& instance_name = "");
+android::sp<android::hardware::wifi::V1_0::IWifiApIface> getWifiApIface(
+ const std::string& instance_name = "");
+android::sp<android::hardware::wifi::V1_0::IWifiNanIface> getWifiNanIface(
+ const std::string& instance_name = "");
+android::sp<android::hardware::wifi::V1_0::IWifiP2pIface> getWifiP2pIface(
+ const std::string& instance_name = "");
+android::sp<android::hardware::wifi::V1_0::IWifiStaIface> getWifiStaIface(
+ const std::string& instance_name = "");
android::sp<android::hardware::wifi::V1_0::IWifiRttController>
-getWifiRttController();
+getWifiRttController(const std::string& instance_name = "");
// Configure the chip in a mode to support the creation of the provided
// iface type.
bool configureChipToSupportIfaceType(
@@ -46,7 +53,7 @@
android::hardware::wifi::V1_0::IfaceType type,
android::hardware::wifi::V1_0::ChipModeId* configured_mode_id);
// Used to trigger IWifi.stop() at the end of every test.
-void stopWifi();
+void stopWifi(const std::string& instance_name = "");
class WifiHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
protected:
diff --git a/wifi/hostapd/1.0/vts/functional/Android.bp b/wifi/hostapd/1.0/vts/functional/Android.bp
index 5645019..b53d002 100644
--- a/wifi/hostapd/1.0/vts/functional/Android.bp
+++ b/wifi/hostapd/1.0/vts/functional/Android.bp
@@ -49,5 +49,5 @@
"libwifi-system",
"libwifi-system-iface",
],
- test_suites: ["general-tests"],
+ test_suites: ["general-tests", "vts-core"],
}
diff --git a/wifi/hostapd/1.0/vts/functional/VtsHalWifiHostapdV1_0TargetTest.cpp b/wifi/hostapd/1.0/vts/functional/VtsHalWifiHostapdV1_0TargetTest.cpp
index 0303b20..4b62b15 100644
--- a/wifi/hostapd/1.0/vts/functional/VtsHalWifiHostapdV1_0TargetTest.cpp
+++ b/wifi/hostapd/1.0/vts/functional/VtsHalWifiHostapdV1_0TargetTest.cpp
@@ -14,36 +14,8 @@
* limitations under the License.
*/
-#include <android-base/logging.h>
-#include <android/hardware/wifi/1.0/IWifi.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
-#include "hostapd_hidl_test_utils.h"
-
-class WifiHostapdHidlEnvironment_1_0 : public WifiHostapdHidlEnvironment {
- public:
- // get the test environment singleton
- static WifiHostapdHidlEnvironment_1_0* Instance() {
- static WifiHostapdHidlEnvironment_1_0* instance =
- new WifiHostapdHidlEnvironment_1_0;
- return instance;
- }
-
- virtual void registerTestServices() override {
- registerTestService<::android::hardware::wifi::V1_0::IWifi>();
- registerTestService<android::hardware::wifi::hostapd::V1_0::IHostapd>();
- }
-
- private:
- WifiHostapdHidlEnvironment_1_0() {}
-};
-
-WifiHostapdHidlEnvironment* gEnv = WifiHostapdHidlEnvironment_1_0::Instance();
-
-int main(int argc, char** argv) {
- ::testing::AddGlobalTestEnvironment(gEnv);
- ::testing::InitGoogleTest(&argc, argv);
- gEnv->init(&argc, argv);
- int status = RUN_ALL_TESTS();
- LOG(INFO) << "Test result = " << status;
- return status;
-}
+// TODO(b/143892896): Remove this file after wifi_hidl_test_utils.cpp is
+// updated.
+::testing::VtsHalHidlTargetTestEnvBase* gEnv = nullptr;
diff --git a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test.cpp b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test.cpp
index 8ee71fb..5a978ca 100644
--- a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test.cpp
+++ b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test.cpp
@@ -17,18 +17,22 @@
#include <android-base/logging.h>
#include <cutils/properties.h>
-#include <VtsHalHidlTargetTestBase.h>
-
+#include <android/hardware/wifi/1.0/IWifi.h>
#include <android/hardware/wifi/hostapd/1.0/IHostapd.h>
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
+
#include "hostapd_hidl_call_util.h"
#include "hostapd_hidl_test_utils.h"
using ::android::sp;
using ::android::hardware::hidl_vec;
-using ::android::hardware::wifi::hostapd::V1_0::IHostapd;
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatus;
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatusCode;
+using ::android::hardware::wifi::hostapd::V1_0::IHostapd;
+using ::android::hardware::wifi::V1_0::IWifi;
namespace {
constexpr unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1',
@@ -38,16 +42,20 @@
constexpr int kIfaceInvalidChannel = 567;
} // namespace
-class HostapdHidlTest : public ::testing::VtsHalHidlTargetTestBase {
+class HostapdHidlTest
+ : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
public:
virtual void SetUp() override {
- stopSupplicantIfNeeded();
- startHostapdAndWaitForHidlService();
- hostapd_ = getHostapd();
+ wifi_instance_name_ = std::get<0>(GetParam());
+ hostapd_instance_name_ = std::get<1>(GetParam());
+ stopSupplicantIfNeeded(wifi_instance_name_);
+ startHostapdAndWaitForHidlService(wifi_instance_name_,
+ hostapd_instance_name_);
+ hostapd_ = IHostapd::getService(hostapd_instance_name_);
ASSERT_NE(hostapd_.get(), nullptr);
}
- virtual void TearDown() override { stopHostapd(); }
+ virtual void TearDown() override { stopHostapd(wifi_instance_name_); }
protected:
std::string getPrimaryWlanIfaceName() {
@@ -121,6 +129,8 @@
}
// IHostapd object used for all tests in this fixture.
sp<IHostapd> hostapd_;
+ std::string wifi_instance_name_;
+ std::string hostapd_instance_name_;
};
/*
@@ -128,17 +138,19 @@
* Ensures that an instance of the IHostapd proxy object is
* successfully created.
*/
-TEST(HostapdHidlTestNoFixture, Create) {
- startHostapdAndWaitForHidlService();
- EXPECT_NE(nullptr, getHostapd().get());
- stopHostapd();
+TEST_P(HostapdHidlTest, Create) {
+ stopHostapd(wifi_instance_name_);
+ startHostapdAndWaitForHidlService(wifi_instance_name_,
+ hostapd_instance_name_);
+ sp<IHostapd> hostapd = IHostapd::getService(hostapd_instance_name_);
+ EXPECT_NE(nullptr, hostapd.get());
}
/**
* Adds an access point with PSK network config & ACS enabled.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddPskAccessPointWithAcs) {
+TEST_P(HostapdHidlTest, AddPskAccessPointWithAcs) {
if (!is_1_1(hostapd_)) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
getIfaceParamsWithAcs(), getPskNwParams());
@@ -151,7 +163,7 @@
* Adds an access point with Open network config & ACS enabled.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddOpenAccessPointWithAcs) {
+TEST_P(HostapdHidlTest, AddOpenAccessPointWithAcs) {
if (!is_1_1(hostapd_)) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
getIfaceParamsWithAcs(), getOpenNwParams());
@@ -164,7 +176,7 @@
* Adds an access point with PSK network config & ACS disabled.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
+TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
if (!is_1_1(hostapd_)) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
getIfaceParamsWithoutAcs(), getPskNwParams());
@@ -176,7 +188,7 @@
* Adds an access point with Open network config & ACS disabled.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
+TEST_P(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
if (!is_1_1(hostapd_)) {
auto status =
HIDL_INVOKE(hostapd_, addAccessPoint, getIfaceParamsWithoutAcs(),
@@ -189,7 +201,7 @@
* Adds & then removes an access point with PSK network config & ACS enabled.
* Access point creation & removal should pass.
*/
-TEST_F(HostapdHidlTest, RemoveAccessPointWithAcs) {
+TEST_P(HostapdHidlTest, RemoveAccessPointWithAcs) {
if (!is_1_1(hostapd_)) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
getIfaceParamsWithAcs(), getPskNwParams());
@@ -207,7 +219,7 @@
* Adds & then removes an access point with PSK network config & ACS disabled.
* Access point creation & removal should pass.
*/
-TEST_F(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
+TEST_P(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
if (!is_1_1(hostapd_)) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint,
getIfaceParamsWithoutAcs(), getPskNwParams());
@@ -222,7 +234,7 @@
* Adds an access point with invalid channel.
* Access point creation should fail.
*/
-TEST_F(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
+TEST_P(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
if (!is_1_1(hostapd_)) {
auto status =
HIDL_INVOKE(hostapd_, addAccessPoint,
@@ -235,7 +247,7 @@
* Adds an access point with invalid PSK network config.
* Access point creation should fail.
*/
-TEST_F(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
+TEST_P(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
if (!is_1_1(hostapd_)) {
auto status =
HIDL_INVOKE(hostapd_, addAccessPoint, getIfaceParamsWithoutAcs(),
@@ -248,6 +260,13 @@
* Terminate
* This terminates the service.
*/
-TEST_F(HostapdHidlTest, Terminate) {
- hostapd_->terminate();
-}
+TEST_P(HostapdHidlTest, Terminate) { hostapd_->terminate(); }
+
+INSTANTIATE_TEST_SUITE_P(
+ PerInstance, HostapdHidlTest,
+ testing::Combine(
+ testing::ValuesIn(
+ android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
+ testing::ValuesIn(
+ android::hardware::getAllHalInstanceNames(IHostapd::descriptor))),
+ android::hardware::PrintInstanceTupleNameToString<>);
diff --git a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp
index cdbf1ab..6058fd2 100644
--- a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp
+++ b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.cpp
@@ -44,13 +44,11 @@
using ::android::wifi_system::HostapdManager;
using ::android::wifi_system::SupplicantManager;
-extern WifiHostapdHidlEnvironment* gEnv;
-
namespace {
// Helper function to initialize the driver and firmware to AP mode
// using the vendor HAL HIDL interface.
-void initilializeDriverAndFirmware() {
- sp<IWifiChip> wifi_chip = getWifiChip();
+void initilializeDriverAndFirmware(const std::string& wifi_instance_name) {
+ sp<IWifiChip> wifi_chip = getWifiChip(wifi_instance_name);
ChipModeId mode_id;
EXPECT_TRUE(configureChipToSupportIfaceType(
wifi_chip, ::android::hardware::wifi::V1_0::IfaceType::AP, &mode_id));
@@ -58,7 +56,9 @@
// Helper function to deinitialize the driver and firmware
// using the vendor HAL HIDL interface.
-void deInitilializeDriverAndFirmware() { stopWifi(); }
+void deInitilializeDriverAndFirmware(const std::string& wifi_instance_name) {
+ stopWifi(wifi_instance_name);
+}
} // namespace
// Utility class to wait for wpa_hostapd's HIDL service registration.
@@ -110,45 +110,42 @@
std::condition_variable condition_;
};
-void stopSupplicantIfNeeded() {
+void stopSupplicantIfNeeded(const std::string& instance_name) {
SupplicantManager supplicant_manager;
if (supplicant_manager.IsSupplicantRunning()) {
LOG(INFO) << "Supplicant is running, stop supplicant first.";
ASSERT_TRUE(supplicant_manager.StopSupplicant());
- deInitilializeDriverAndFirmware();
+ deInitilializeDriverAndFirmware(instance_name);
ASSERT_FALSE(supplicant_manager.IsSupplicantRunning());
}
}
-void stopHostapd() {
+void stopHostapd(const std::string& instance_name) {
HostapdManager hostapd_manager;
ASSERT_TRUE(hostapd_manager.StopHostapd());
- deInitilializeDriverAndFirmware();
+ deInitilializeDriverAndFirmware(instance_name);
}
-void startHostapdAndWaitForHidlService() {
- initilializeDriverAndFirmware();
+void startHostapdAndWaitForHidlService(
+ const std::string& wifi_instance_name,
+ const std::string& hostapd_instance_name) {
+ initilializeDriverAndFirmware(wifi_instance_name);
android::sp<ServiceNotificationListener> notification_listener =
new ServiceNotificationListener();
- string service_name = gEnv->getServiceName<IHostapd>();
ASSERT_TRUE(notification_listener->registerForHidlServiceNotifications(
- service_name));
+ hostapd_instance_name));
HostapdManager hostapd_manager;
ASSERT_TRUE(hostapd_manager.StartHostapd());
- ASSERT_TRUE(notification_listener->waitForHidlService(500, service_name));
+ ASSERT_TRUE(
+ notification_listener->waitForHidlService(500, hostapd_instance_name));
}
bool is_1_1(const sp<IHostapd>& hostapd) {
sp<::android::hardware::wifi::hostapd::V1_1::IHostapd> hostapd_1_1 =
::android::hardware::wifi::hostapd::V1_1::IHostapd::castFrom(hostapd);
return hostapd_1_1.get() != nullptr;
-}
-
-sp<IHostapd> getHostapd() {
- return ::testing::VtsHalHidlTargetTestBase::getService<IHostapd>(
- gEnv->getServiceName<IHostapd>());
-}
+}
\ No newline at end of file
diff --git a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.h b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.h
index 9b3df42..5cb4f01 100644
--- a/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.h
+++ b/wifi/hostapd/1.0/vts/functional/hostapd_hidl_test_utils.h
@@ -20,32 +20,18 @@
#include <android/hardware/wifi/hostapd/1.0/IHostapd.h>
#include <android/hardware/wifi/hostapd/1.1/IHostapd.h>
-#include <VtsHalHidlTargetTestEnvBase.h>
-
// Used to stop the android wifi framework before every test.
-void stopWifiFramework();
-void startWifiFramework();
-void stopSupplicantIfNeeded();
-void stopHostapd();
+void stopWifiFramework(const std::string& instance_name);
+void startWifiFramework(const std::string& instance_name);
+void stopSupplicantIfNeeded(const std::string& instance_name);
+void stopHostapd(const std::string& instance_name);
// Used to configure the chip, driver and start wpa_hostapd before every
// test.
-void startHostapdAndWaitForHidlService();
+void startHostapdAndWaitForHidlService(
+ const std::string& wifi_instance_name,
+ const std::string& hostapd_instance_name);
-// Helper functions to obtain references to the various HIDL interface objects.
-// Note: We only have a single instance of each of these objects currently.
-// These helper functions should be modified to return vectors if we support
-// multiple instances.
-android::sp<android::hardware::wifi::hostapd::V1_0::IHostapd> getHostapd();
bool is_1_1(const android::sp<android::hardware::wifi::hostapd::V1_0::IHostapd>&
hostapd);
-class WifiHostapdHidlEnvironment
- : public ::testing::VtsHalHidlTargetTestEnvBase {
- public:
- virtual void HidlSetUp() override { stopHostapd(); }
- virtual void HidlTearDown() override {
- startHostapdAndWaitForHidlService();
- }
-};
-
#endif /* HOSTAPD_HIDL_TEST_UTILS_H */
diff --git a/wifi/hostapd/1.1/vts/functional/Android.bp b/wifi/hostapd/1.1/vts/functional/Android.bp
index 02ec2e6..c963fe3 100644
--- a/wifi/hostapd/1.1/vts/functional/Android.bp
+++ b/wifi/hostapd/1.1/vts/functional/Android.bp
@@ -14,25 +14,6 @@
// limitations under the License.
//
-cc_library_static {
- name: "VtsHalWifiHostapdV1_1TargetTestUtil",
- defaults: ["VtsHalTargetTestDefaults"],
- srcs: ["hostapd_hidl_test_utils_1_1.cpp"],
- export_include_dirs: [
- "."
- ],
- static_libs: [
- "VtsHalWifiV1_0TargetTestUtil",
- "VtsHalWifiHostapdV1_0TargetTestUtil",
- "android.hardware.wifi.hostapd@1.0",
- "android.hardware.wifi.hostapd@1.1",
- "android.hardware.wifi@1.0",
- "libgmock",
- "libwifi-system",
- "libwifi-system-iface",
- ],
-}
-
cc_test {
name: "VtsHalWifiHostapdV1_1TargetTest",
defaults: ["VtsHalTargetTestDefaults"],
@@ -43,7 +24,6 @@
static_libs: [
"VtsHalWifiV1_0TargetTestUtil",
"VtsHalWifiHostapdV1_0TargetTestUtil",
- "VtsHalWifiHostapdV1_1TargetTestUtil",
"android.hardware.wifi.hostapd@1.0",
"android.hardware.wifi.hostapd@1.1",
"android.hardware.wifi@1.0",
@@ -51,6 +31,6 @@
"libwifi-system",
"libwifi-system-iface",
],
- test_suites: ["general-tests"],
+ test_suites: ["general-tests", "vts-core"],
}
diff --git a/wifi/hostapd/1.1/vts/functional/VtsHalWifiHostapdV1_1TargetTest.cpp b/wifi/hostapd/1.1/vts/functional/VtsHalWifiHostapdV1_1TargetTest.cpp
index 6916db2..7e0f3cd 100644
--- a/wifi/hostapd/1.1/vts/functional/VtsHalWifiHostapdV1_1TargetTest.cpp
+++ b/wifi/hostapd/1.1/vts/functional/VtsHalWifiHostapdV1_1TargetTest.cpp
@@ -14,38 +14,8 @@
* limitations under the License.
*/
-#include <android-base/logging.h>
-#include <android/hardware/wifi/1.0/IWifi.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
-#include "hostapd_hidl_test_utils.h"
-#include "hostapd_hidl_test_utils_1_1.h"
-
-class WifiHostapdHidlEnvironment_1_1 : public WifiHostapdHidlEnvironment {
- public:
- // get the test environment singleton
- static WifiHostapdHidlEnvironment_1_1* Instance() {
- static WifiHostapdHidlEnvironment_1_1* instance =
- new WifiHostapdHidlEnvironment_1_1;
- return instance;
- }
-
- virtual void registerTestServices() override {
- registerTestService<::android::hardware::wifi::V1_0::IWifi>();
- registerTestService<android::hardware::wifi::hostapd::V1_0::IHostapd>();
- registerTestService<android::hardware::wifi::hostapd::V1_1::IHostapd>();
- }
-
- private:
- WifiHostapdHidlEnvironment_1_1() {}
-};
-
-WifiHostapdHidlEnvironment* gEnv = WifiHostapdHidlEnvironment_1_1::Instance();
-
-int main(int argc, char** argv) {
- ::testing::AddGlobalTestEnvironment(gEnv);
- ::testing::InitGoogleTest(&argc, argv);
- gEnv->init(&argc, argv);
- int status = RUN_ALL_TESTS();
- LOG(INFO) << "Test result = " << status;
- return status;
-}
+// TODO(b/143892896): Remove this file after wifi_hidl_test_utils.cpp is
+// updated.
+::testing::VtsHalHidlTargetTestEnvBase* gEnv = nullptr;
\ No newline at end of file
diff --git a/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test.cpp b/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test.cpp
index b053549..1804d8c 100644
--- a/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test.cpp
+++ b/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test.cpp
@@ -17,13 +17,15 @@
#include <android-base/logging.h>
#include <cutils/properties.h>
-#include <VtsHalHidlTargetTestBase.h>
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
+#include <android/hardware/wifi/1.0/IWifi.h>
#include <android/hardware/wifi/hostapd/1.1/IHostapd.h>
#include "hostapd_hidl_call_util.h"
#include "hostapd_hidl_test_utils.h"
-#include "hostapd_hidl_test_utils_1_1.h"
using ::android::sp;
using ::android::hardware::hidl_string;
@@ -33,6 +35,7 @@
using ::android::hardware::wifi::hostapd::V1_0::HostapdStatusCode;
using ::android::hardware::wifi::hostapd::V1_1::IHostapd;
using ::android::hardware::wifi::hostapd::V1_1::IHostapdCallback;
+using ::android::hardware::wifi::V1_0::IWifi;
namespace {
constexpr unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1',
@@ -42,16 +45,20 @@
constexpr int kIfaceInvalidChannel = 567;
} // namespace
-class HostapdHidlTest : public ::testing::VtsHalHidlTargetTestBase {
+class HostapdHidlTest
+ : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {
public:
virtual void SetUp() override {
- stopSupplicantIfNeeded();
- startHostapdAndWaitForHidlService();
- hostapd_ = getHostapd_1_1();
+ wifi_instance_name_ = std::get<0>(GetParam());
+ hostapd_instance_name_ = std::get<1>(GetParam());
+ stopSupplicantIfNeeded(wifi_instance_name_);
+ startHostapdAndWaitForHidlService(wifi_instance_name_,
+ hostapd_instance_name_);
+ hostapd_ = IHostapd::getService(hostapd_instance_name_);
ASSERT_NE(hostapd_.get(), nullptr);
}
- virtual void TearDown() override { stopHostapd(); }
+ virtual void TearDown() override { stopHostapd(wifi_instance_name_); }
protected:
std::string getPrimaryWlanIfaceName() {
@@ -152,6 +159,8 @@
// IHostapd object used for all tests in this fixture.
sp<IHostapd> hostapd_;
+ std::string wifi_instance_name_;
+ std::string hostapd_instance_name_;
};
class IfaceCallback : public IHostapdCallback {
@@ -164,7 +173,7 @@
/*
* RegisterCallback
*/
-TEST_F(HostapdHidlTest, registerCallback) {
+TEST_P(HostapdHidlTest, registerCallback) {
hostapd_->registerCallback(
new IfaceCallback(), [](const HostapdStatus& status) {
EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
@@ -175,7 +184,7 @@
* Adds an access point with PSK network config & ACS enabled.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddPskAccessPointWithAcs) {
+TEST_P(HostapdHidlTest, AddPskAccessPointWithAcs) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithAcs(), getPskNwParams());
// TODO: b/140172237, fix this in R.
@@ -186,7 +195,7 @@
* Adds an access point with PSK network config, ACS enabled & channel Range.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddPskAccessPointWithAcsAndChannelRange) {
+TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndChannelRange) {
auto status =
HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithAcsAndChannelRange(), getPskNwParams());
@@ -198,7 +207,7 @@
* Adds an access point with invalid channel range.
* Access point creation should fail.
*/
-TEST_F(HostapdHidlTest, AddPskAccessPointWithAcsAndInvalidChannelRange) {
+TEST_P(HostapdHidlTest, AddPskAccessPointWithAcsAndInvalidChannelRange) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithAcsAndInvalidChannelRange(),
getPskNwParams());
@@ -210,7 +219,7 @@
* Adds an access point with Open network config & ACS enabled.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddOpenAccessPointWithAcs) {
+TEST_P(HostapdHidlTest, AddOpenAccessPointWithAcs) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithAcs(), getOpenNwParams());
// TODO: b/140172237, fix this in R
@@ -221,7 +230,7 @@
* Adds an access point with PSK network config & ACS disabled.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
+TEST_P(HostapdHidlTest, AddPskAccessPointWithoutAcs) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithoutAcs(), getPskNwParams());
EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
@@ -231,7 +240,7 @@
* Adds an access point with Open network config & ACS disabled.
* Access point creation should pass.
*/
-TEST_F(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
+TEST_P(HostapdHidlTest, AddOpenAccessPointWithoutAcs) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithoutAcs(), getOpenNwParams());
EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
@@ -241,7 +250,7 @@
* Adds & then removes an access point with PSK network config & ACS enabled.
* Access point creation & removal should pass.
*/
-TEST_F(HostapdHidlTest, RemoveAccessPointWithAcs) {
+TEST_P(HostapdHidlTest, RemoveAccessPointWithAcs) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithAcs(), getPskNwParams());
// TODO: b/140172237, fix this in R
@@ -257,7 +266,7 @@
* Adds & then removes an access point with PSK network config & ACS disabled.
* Access point creation & removal should pass.
*/
-TEST_F(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
+TEST_P(HostapdHidlTest, RemoveAccessPointWithoutAcs) {
auto status = HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithoutAcs(), getPskNwParams());
EXPECT_EQ(HostapdStatusCode::SUCCESS, status.code);
@@ -270,7 +279,7 @@
* Adds an access point with invalid channel.
* Access point creation should fail.
*/
-TEST_F(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
+TEST_P(HostapdHidlTest, AddPskAccessPointWithInvalidChannel) {
auto status =
HIDL_INVOKE(hostapd_, addAccessPoint_1_1,
getIfaceParamsWithInvalidChannel(), getPskNwParams());
@@ -281,9 +290,18 @@
* Adds an access point with invalid PSK network config.
* Access point creation should fail.
*/
-TEST_F(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
+TEST_P(HostapdHidlTest, AddInvalidPskAccessPointWithoutAcs) {
auto status =
HIDL_INVOKE(hostapd_, addAccessPoint_1_1, getIfaceParamsWithoutAcs(),
getInvalidPskNwParams());
EXPECT_NE(HostapdStatusCode::SUCCESS, status.code);
}
+
+INSTANTIATE_TEST_CASE_P(
+ PerInstance, HostapdHidlTest,
+ testing::Combine(
+ testing::ValuesIn(
+ android::hardware::getAllHalInstanceNames(IWifi::descriptor)),
+ testing::ValuesIn(android::hardware::getAllHalInstanceNames(
+ android::hardware::wifi::hostapd::V1_1::IHostapd::descriptor))),
+ android::hardware::PrintInstanceTupleNameToString<>);
diff --git a/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test_utils_1_1.cpp b/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test_utils_1_1.cpp
deleted file mode 100644
index 8bb72a1..0000000
--- a/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test_utils_1_1.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <VtsHalHidlTargetTestBase.h>
-#include <android-base/logging.h>
-
-#include "hostapd_hidl_test_utils.h"
-#include "hostapd_hidl_test_utils_1_1.h"
-
-using ::android::sp;
-using ::android::hardware::wifi::hostapd::V1_1::IHostapd;
-
-sp<IHostapd> getHostapd_1_1() { return IHostapd::castFrom(getHostapd()); }
diff --git a/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test_utils_1_1.h b/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test_utils_1_1.h
deleted file mode 100644
index c43ddfa..0000000
--- a/wifi/hostapd/1.1/vts/functional/hostapd_hidl_test_utils_1_1.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef HOSTAPD_HIDL_TEST_UTILS_1_1_H
-#define HOSTAPD_HIDL_TEST_UTILS_1_1_H
-
-#include <android/hardware/wifi/hostapd/1.1/IHostapd.h>
-
-#include <VtsHalHidlTargetTestEnvBase.h>
-
-// Helper functions to obtain references to the various HIDL interface objects.
-// Note: We only have a single instance of each of these objects currently.
-// These helper functions should be modified to return vectors if we support
-// multiple instances.
-android::sp<android::hardware::wifi::hostapd::V1_1::IHostapd> getHostapd_1_1();
-
-#endif /* HOSTAPD_HIDL_TEST_UTILS_1_1_H */