Merge changes from topics "adtFunctionsNoBitMask", "audioArraysStaticCheck", "mvSystemAudioTests", "rmDeviceTypeBitMaskUsage"

am: cc82581159

Change-Id: I8efd1d6d1d341253074aa22fc76409fe3efa540c
gugelfrei
jiabin 5 years ago committed by android-build-merger
commit 48a787c6fe

@ -19,6 +19,9 @@
#define LOG_TAG "AudioFlinger"
//#define LOG_NDEBUG 0
// Define AUDIO_ARRAYS_STATIC_CHECK to check all audio arrays are correct
#define AUDIO_ARRAYS_STATIC_CHECK 1
#include "Configuration.h"
#include <dirent.h>
#include <math.h>

@ -2,9 +2,6 @@
"presubmit": [
{
"name": "audiopolicy_tests"
},
{
"name": "systemaudio_tests"
}
]
}

@ -42,14 +42,6 @@ static const uint32_t SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY = 5000;
// Do not limit channel count otherwise
#define MAX_MIXER_CHANNEL_COUNT FCC_8
/**
* A device mask for all audio input and output devices where matching inputs/outputs on device
* type alone is not enough: the address must match too
*/
#define APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL (AUDIO_DEVICE_OUT_REMOTE_SUBMIX|AUDIO_DEVICE_OUT_BUS)
#define APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX|AUDIO_DEVICE_IN_BUS)
/**
* Alias to AUDIO_DEVICE_OUT_DEFAULT defined for clarification when this value is used by volume
* control APIs (e.g setStreamVolumeIndex().
@ -70,6 +62,34 @@ static inline bool is_state_in_call(int state)
return (state == AUDIO_MODE_IN_CALL) || (state == AUDIO_MODE_IN_COMMUNICATION);
}
/**
* Check whether the output device type is one
* where addresses are used to distinguish between one connected device and another
*
* @param[in] device to consider
*
* @return true if the device needs distinguish on address, false otherwise..
*/
static inline bool apm_audio_out_device_distinguishes_on_address(audio_devices_t device)
{
return device == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
device == AUDIO_DEVICE_OUT_BUS;
}
/**
* Check whether the input device type is one
* where addresses are used to distinguish between one connected device and another
*
* @param[in] device to consider
*
* @return true if the device needs distinguish on address, false otherwise..
*/
static inline bool apm_audio_in_device_distinguishes_on_address(audio_devices_t device)
{
return device == AUDIO_DEVICE_IN_REMOTE_SUBMIX ||
device == AUDIO_DEVICE_IN_BUS;
}
/**
* Check whether the device type is one
* where addresses are used to distinguish between one connected device and another
@ -80,10 +100,8 @@ static inline bool is_state_in_call(int state)
*/
static inline bool device_distinguishes_on_address(audio_devices_t device)
{
return (((device & AUDIO_DEVICE_BIT_IN) != 0) &&
((~AUDIO_DEVICE_BIT_IN & device & APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL) != 0)) ||
(((device & AUDIO_DEVICE_BIT_IN) == 0) &&
((device & APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL) != 0));
return apm_audio_in_device_distinguishes_on_address(device) ||
apm_audio_out_device_distinguishes_on_address(device);
}
/**
@ -95,10 +113,7 @@ static inline bool device_distinguishes_on_address(audio_devices_t device)
*/
static inline bool device_has_encoding_capability(audio_devices_t device)
{
if (device & AUDIO_DEVICE_OUT_ALL_A2DP) {
return true;
}
return false;
return audio_is_a2dp_out_device(device);
}
/**

@ -39,22 +39,27 @@ cc_test {
}
// system/audio.h utilities test
cc_test {
name: "systemaudio_tests",
name: "audio_health_tests",
shared_libs: [
"libaudiofoundation",
"libbase",
"libaudioclient",
"libaudiopolicymanagerdefault",
"liblog",
"libmedia_helper",
"libutils",
],
header_libs: ["libmedia_headers"],
static_libs: ["libaudiopolicycomponents"],
header_libs: [
"libaudiopolicyengine_interface_headers",
"libaudiopolicymanager_interface_headers",
],
srcs: ["systemaudio_tests.cpp"],
srcs: ["audio_health_tests.cpp"],
cflags: [
"-Werror",

@ -0,0 +1,112 @@
/*
* 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 <map>
#include <system/audio.h>
#include <utils/Log.h>
#include <utils/String8.h>
#include "AudioPolicyTestClient.h"
namespace android {
class AudioPolicyManagerTestClient : public AudioPolicyTestClient {
public:
// AudioPolicyClientInterface implementation
audio_module_handle_t loadHwModule(const char * /*name*/) override {
return mNextModuleHandle++;
}
status_t openOutput(audio_module_handle_t module,
audio_io_handle_t *output,
audio_config_t * /*config*/,
audio_devices_t * /*devices*/,
const String8 & /*address*/,
uint32_t * /*latencyMs*/,
audio_output_flags_t /*flags*/) override {
if (module >= mNextModuleHandle) {
ALOGE("%s: Module handle %d has not been allocated yet (next is %d)",
__func__, module, mNextModuleHandle);
return BAD_VALUE;
}
*output = mNextIoHandle++;
return NO_ERROR;
}
audio_io_handle_t openDuplicateOutput(audio_io_handle_t /*output1*/,
audio_io_handle_t /*output2*/) override {
audio_io_handle_t id = mNextIoHandle++;
return id;
}
status_t openInput(audio_module_handle_t module,
audio_io_handle_t *input,
audio_config_t * /*config*/,
audio_devices_t * /*device*/,
const String8 & /*address*/,
audio_source_t /*source*/,
audio_input_flags_t /*flags*/) override {
if (module >= mNextModuleHandle) {
ALOGE("%s: Module handle %d has not been allocated yet (next is %d)",
__func__, module, mNextModuleHandle);
return BAD_VALUE;
}
*input = mNextIoHandle++;
return NO_ERROR;
}
status_t createAudioPatch(const struct audio_patch *patch,
audio_patch_handle_t *handle,
int /*delayMs*/) override {
*handle = mNextPatchHandle++;
mActivePatches.insert(std::make_pair(*handle, *patch));
return NO_ERROR;
}
status_t releaseAudioPatch(audio_patch_handle_t handle,
int /*delayMs*/) override {
if (mActivePatches.erase(handle) != 1) {
if (handle >= mNextPatchHandle) {
ALOGE("%s: Patch handle %d has not been allocated yet (next is %d)",
__func__, handle, mNextPatchHandle);
} else {
ALOGE("%s: Attempt to release patch %d twice", __func__, handle);
}
return BAD_VALUE;
}
return NO_ERROR;
}
// Helper methods for tests
size_t getActivePatchesCount() const { return mActivePatches.size(); }
const struct audio_patch *getLastAddedPatch() const {
if (mActivePatches.empty()) {
return nullptr;
}
auto it = --mActivePatches.end();
return &it->second;
};
private:
audio_module_handle_t mNextModuleHandle = AUDIO_MODULE_HANDLE_NONE + 1;
audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1;
audio_patch_handle_t mNextPatchHandle = AUDIO_PATCH_HANDLE_NONE + 1;
std::map<audio_patch_handle_t, struct audio_patch> mActivePatches;
};
} // namespace android

@ -24,6 +24,7 @@ class AudioPolicyTestManager : public AudioPolicyManager {
explicit AudioPolicyTestManager(AudioPolicyClientInterface *clientInterface)
: AudioPolicyManager(clientInterface, true /*forTesting*/) { }
using AudioPolicyManager::getConfig;
using AudioPolicyManager::loadConfig;
using AudioPolicyManager::initialize;
};

@ -0,0 +1,76 @@
/*
* 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.
*/
#define LOG_TAG "AudioPolicy_Boot_Test"
#include <unordered_set>
#include <gtest/gtest.h>
#include <media/AudioSystem.h>
#include <system/audio.h>
#include <utils/Log.h>
#include "AudioPolicyManagerTestClient.h"
#include "AudioPolicyTestManager.h"
using namespace android;
TEST(AudioHealthTest, AttachedDeviceFound) {
unsigned int numPorts;
unsigned int generation1;
unsigned int generation;
struct audio_port *audioPorts = NULL;
int attempts = 10;
do {
if (attempts-- < 0) {
free(audioPorts);
GTEST_FAIL() << "Query audio ports time out";
}
numPorts = 0;
ASSERT_EQ(NO_ERROR, AudioSystem::listAudioPorts(
AUDIO_PORT_ROLE_NONE, AUDIO_PORT_TYPE_DEVICE, &numPorts, NULL, &generation1));
if (numPorts == 0) {
free(audioPorts);
GTEST_FAIL() << "Number of audio ports should not be zero";
}
audioPorts = (struct audio_port *)realloc(audioPorts, numPorts * sizeof(struct audio_port));
status_t status = AudioSystem::listAudioPorts(
AUDIO_PORT_ROLE_NONE, AUDIO_PORT_TYPE_DEVICE, &numPorts, audioPorts, &generation);
if (status != NO_ERROR) {
free(audioPorts);
GTEST_FAIL() << "Query audio ports failed";
}
} while (generation1 != generation);
std::unordered_set<audio_devices_t> attachedDevices;
for (int i = 0 ; i < numPorts; i++) {
attachedDevices.insert(audioPorts[i].ext.device.type);
}
free(audioPorts);
AudioPolicyManagerTestClient client;
AudioPolicyTestManager manager(&client);
manager.loadConfig();
ASSERT_NE("AudioPolicyConfig::setDefault", manager.getConfig().getSource());
for (auto desc : manager.getConfig().getAvailableInputDevices()) {
ASSERT_NE(attachedDevices.end(), attachedDevices.find(desc->type()));
}
for (auto desc : manager.getConfig().getAvailableOutputDevices()) {
ASSERT_NE(attachedDevices.end(), attachedDevices.find(desc->type()));
}
}

@ -14,7 +14,6 @@
* limitations under the License.
*/
#include <map>
#include <memory>
#include <string>
#include <sys/wait.h>
@ -32,6 +31,7 @@
#include <utils/Vector.h>
#include "AudioPolicyInterface.h"
#include "AudioPolicyManagerTestClient.h"
#include "AudioPolicyTestClient.h"
#include "AudioPolicyTestManager.h"
@ -57,91 +57,6 @@ TEST(AudioPolicyManagerTestInit, ClientFailure) {
}
class AudioPolicyManagerTestClient : public AudioPolicyTestClient {
public:
// AudioPolicyClientInterface implementation
audio_module_handle_t loadHwModule(const char* /*name*/) override {
return mNextModuleHandle++;
}
status_t openOutput(audio_module_handle_t module,
audio_io_handle_t* output,
audio_config_t* /*config*/,
audio_devices_t* /*devices*/,
const String8& /*address*/,
uint32_t* /*latencyMs*/,
audio_output_flags_t /*flags*/) override {
if (module >= mNextModuleHandle) {
ALOGE("%s: Module handle %d has not been allocated yet (next is %d)",
__func__, module, mNextModuleHandle);
return BAD_VALUE;
}
*output = mNextIoHandle++;
return NO_ERROR;
}
audio_io_handle_t openDuplicateOutput(audio_io_handle_t /*output1*/,
audio_io_handle_t /*output2*/) override {
audio_io_handle_t id = mNextIoHandle++;
return id;
}
status_t openInput(audio_module_handle_t module,
audio_io_handle_t* input,
audio_config_t* /*config*/,
audio_devices_t* /*device*/,
const String8& /*address*/,
audio_source_t /*source*/,
audio_input_flags_t /*flags*/) override {
if (module >= mNextModuleHandle) {
ALOGE("%s: Module handle %d has not been allocated yet (next is %d)",
__func__, module, mNextModuleHandle);
return BAD_VALUE;
}
*input = mNextIoHandle++;
return NO_ERROR;
}
status_t createAudioPatch(const struct audio_patch* patch,
audio_patch_handle_t* handle,
int /*delayMs*/) override {
*handle = mNextPatchHandle++;
mActivePatches.insert(std::make_pair(*handle, *patch));
return NO_ERROR;
}
status_t releaseAudioPatch(audio_patch_handle_t handle,
int /*delayMs*/) override {
if (mActivePatches.erase(handle) != 1) {
if (handle >= mNextPatchHandle) {
ALOGE("%s: Patch handle %d has not been allocated yet (next is %d)",
__func__, handle, mNextPatchHandle);
} else {
ALOGE("%s: Attempt to release patch %d twice", __func__, handle);
}
return BAD_VALUE;
}
return NO_ERROR;
}
// Helper methods for tests
size_t getActivePatchesCount() const { return mActivePatches.size(); }
const struct audio_patch* getLastAddedPatch() const {
if (mActivePatches.empty()) {
return nullptr;
}
auto it = --mActivePatches.end();
return &it->second;
};
private:
audio_module_handle_t mNextModuleHandle = AUDIO_MODULE_HANDLE_NONE + 1;
audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1;
audio_patch_handle_t mNextPatchHandle = AUDIO_PATCH_HANDLE_NONE + 1;
std::map<audio_patch_handle_t, struct audio_patch> mActivePatches;
};
class PatchCountCheck {
public:
explicit PatchCountCheck(AudioPolicyManagerTestClient *client)

@ -1,117 +0,0 @@
/*
* Copyright (C) 2018 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 <gtest/gtest.h>
#define LOG_TAG "SysAudio_Test"
#include <log/log.h>
#include <media/PatchBuilder.h>
#include <system/audio.h>
using namespace android;
TEST(SystemAudioTest, PatchInvalid) {
audio_patch patch{};
ASSERT_FALSE(audio_patch_is_valid(&patch));
patch.num_sources = AUDIO_PATCH_PORTS_MAX + 1;
patch.num_sinks = 1;
ASSERT_FALSE(audio_patch_is_valid(&patch));
patch.num_sources = 1;
patch.num_sinks = AUDIO_PATCH_PORTS_MAX + 1;
ASSERT_FALSE(audio_patch_is_valid(&patch));
patch.num_sources = 0;
patch.num_sinks = 1;
ASSERT_FALSE(audio_patch_is_valid(&patch));
}
TEST(SystemAudioTest, PatchValid) {
const audio_port_config src = {
.id = 1, .role = AUDIO_PORT_ROLE_SOURCE, .type = AUDIO_PORT_TYPE_DEVICE };
// It's OK not to have sinks.
ASSERT_TRUE(audio_patch_is_valid((PatchBuilder{}).addSource(src).patch()));
const audio_port_config sink = {
.id = 2, .role = AUDIO_PORT_ROLE_SINK, .type = AUDIO_PORT_TYPE_DEVICE };
ASSERT_TRUE(audio_patch_is_valid((PatchBuilder{}).addSource(src).addSink(sink).patch()));
ASSERT_TRUE(audio_patch_is_valid(
(PatchBuilder{}).addSource(src).addSource(src).addSink(sink).patch()));
ASSERT_TRUE(audio_patch_is_valid(
(PatchBuilder{}).addSource(src).addSink(sink).addSink(sink).patch()));
ASSERT_TRUE(audio_patch_is_valid(
(PatchBuilder{}).addSource(src).addSource(src).
addSink(sink).addSink(sink).patch()));
}
TEST(SystemAudioTest, PatchHwAvSync) {
audio_port_config device_src_cfg = {
.id = 1, .role = AUDIO_PORT_ROLE_SOURCE, .type = AUDIO_PORT_TYPE_DEVICE };
ASSERT_FALSE(audio_port_config_has_hw_av_sync(&device_src_cfg));
device_src_cfg.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
ASSERT_FALSE(audio_port_config_has_hw_av_sync(&device_src_cfg));
device_src_cfg.flags.input = AUDIO_INPUT_FLAG_HW_AV_SYNC;
ASSERT_TRUE(audio_port_config_has_hw_av_sync(&device_src_cfg));
audio_port_config device_sink_cfg = {
.id = 1, .role = AUDIO_PORT_ROLE_SINK, .type = AUDIO_PORT_TYPE_DEVICE };
ASSERT_FALSE(audio_port_config_has_hw_av_sync(&device_sink_cfg));
device_sink_cfg.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
ASSERT_FALSE(audio_port_config_has_hw_av_sync(&device_sink_cfg));
device_sink_cfg.flags.output = AUDIO_OUTPUT_FLAG_HW_AV_SYNC;
ASSERT_TRUE(audio_port_config_has_hw_av_sync(&device_sink_cfg));
audio_port_config mix_sink_cfg = {
.id = 1, .role = AUDIO_PORT_ROLE_SINK, .type = AUDIO_PORT_TYPE_MIX };
ASSERT_FALSE(audio_port_config_has_hw_av_sync(&mix_sink_cfg));
mix_sink_cfg.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
ASSERT_FALSE(audio_port_config_has_hw_av_sync(&mix_sink_cfg));
mix_sink_cfg.flags.input = AUDIO_INPUT_FLAG_HW_AV_SYNC;
ASSERT_TRUE(audio_port_config_has_hw_av_sync(&mix_sink_cfg));
audio_port_config mix_src_cfg = {
.id = 1, .role = AUDIO_PORT_ROLE_SOURCE, .type = AUDIO_PORT_TYPE_MIX };
ASSERT_FALSE(audio_port_config_has_hw_av_sync(&mix_src_cfg));
mix_src_cfg.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
ASSERT_FALSE(audio_port_config_has_hw_av_sync(&mix_src_cfg));
mix_src_cfg.flags.output = AUDIO_OUTPUT_FLAG_HW_AV_SYNC;
ASSERT_TRUE(audio_port_config_has_hw_av_sync(&mix_src_cfg));
}
TEST(SystemAudioTest, PatchEqual) {
const audio_patch patch1{}, patch2{};
// Invalid patches are not equal.
ASSERT_FALSE(audio_patches_are_equal(&patch1, &patch2));
const audio_port_config src = {
.id = 1, .role = AUDIO_PORT_ROLE_SOURCE, .type = AUDIO_PORT_TYPE_DEVICE };
const audio_port_config sink = {
.id = 2, .role = AUDIO_PORT_ROLE_SINK, .type = AUDIO_PORT_TYPE_DEVICE };
ASSERT_FALSE(audio_patches_are_equal(
(PatchBuilder{}).addSource(src).patch(),
(PatchBuilder{}).addSource(src).addSink(sink).patch()));
ASSERT_TRUE(audio_patches_are_equal(
(PatchBuilder{}).addSource(src).addSink(sink).patch(),
(PatchBuilder{}).addSource(src).addSink(sink).patch()));
ASSERT_FALSE(audio_patches_are_equal(
(PatchBuilder{}).addSource(src).addSink(sink).patch(),
(PatchBuilder{}).addSource(src).addSource(src).addSink(sink).patch()));
audio_port_config sink_hw_av_sync = sink;
sink_hw_av_sync.config_mask |= AUDIO_PORT_CONFIG_FLAGS;
sink_hw_av_sync.flags.output = AUDIO_OUTPUT_FLAG_HW_AV_SYNC;
ASSERT_FALSE(audio_patches_are_equal(
(PatchBuilder{}).addSource(src).addSink(sink).patch(),
(PatchBuilder{}).addSource(src).addSink(sink_hw_av_sync).patch()));
ASSERT_TRUE(audio_patches_are_equal(
(PatchBuilder{}).addSource(src).addSink(sink_hw_av_sync).patch(),
(PatchBuilder{}).addSource(src).addSink(sink_hw_av_sync).patch()));
}
Loading…
Cancel
Save