Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4820f0db authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Cherrypicker Worker
Browse files

libaudiohal@aidl: Fix port config matching in findOrCreatePortConfig

The condition for determining that there is no existing port
config was not correct.

Also, clarify the output produced by audiosystem_tests to make
it easier to analyze.

Bug: 298175108
Test: atest audiosystem_tests
(cherry picked from https://android-review.googlesource.com/q/commit:61ccb486307410177ce565f960d989e42bb6d972)
Merged-In: I1ae46d99fa1617f1ad4f508a78660bb63d66be8e
Change-Id: I1ae46d99fa1617f1ad4f508a78660bb63d66be8e
parent 7c25dd0e
Loading
Loading
Loading
Loading
+34 −6
Original line number Original line Diff line number Diff line
@@ -21,9 +21,9 @@
#include <set>
#include <set>


#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <log/log.h>
#include <media/AidlConversionCppNdk.h>
#include <media/AidlConversionCppNdk.h>
#include <media/IAudioFlinger.h>
#include <media/IAudioFlinger.h>
#include <utils/Log.h>


#include "audio_test_utils.h"
#include "audio_test_utils.h"


@@ -277,23 +277,30 @@ TEST_F(AudioSystemTest, CreateAndReleaseAudioPatch) {
        GTEST_SKIP() << "No output devices returned by the audio system";
        GTEST_SKIP() << "No output devices returned by the audio system";
    }
    }


    bool sourceFound = false, sinkFound = false;
    for (const auto& port : ports) {
    for (const auto& port : ports) {
        if (port.role == AUDIO_PORT_ROLE_SOURCE && port.type == AUDIO_PORT_TYPE_DEVICE) {
        if (port.role == AUDIO_PORT_ROLE_SOURCE && port.type == AUDIO_PORT_TYPE_DEVICE) {
            sourcePort = port;
            sourcePort = port;
            sourceFound = true;
        }
        }
        if (port.role == AUDIO_PORT_ROLE_SINK && port.type == AUDIO_PORT_TYPE_DEVICE &&
        if (port.role == AUDIO_PORT_ROLE_SINK && port.type == AUDIO_PORT_TYPE_DEVICE &&
            port.ext.device.type == AUDIO_DEVICE_OUT_SPEAKER) {
            port.ext.device.type == AUDIO_DEVICE_OUT_SPEAKER) {
            sinkPort = port;
            sinkPort = port;
            sinkFound = true;
        }
        if (sourceFound && sinkFound) break;
    }
    }
    if (!sourceFound || !sinkFound) {
        GTEST_SKIP() << "No ports suitable for testing";
    }
    }


    audioPatch.sources[0] = sourcePort.active_config;
    audioPatch.sources[0] = sourcePort.active_config;
    audioPatch.sinks[0] = sinkPort.active_config;
    audioPatch.sinks[0] = sinkPort.active_config;


    status = AudioSystem::createAudioPatch(&audioPatch, &audioPatchHandle);
    status = AudioSystem::createAudioPatch(&audioPatch, &audioPatchHandle);
    EXPECT_EQ(OK, status) << "AudioSystem::createAudiopatch failed between source "
    EXPECT_EQ(OK, status) << "AudioSystem::createAudioPatch failed between source "
                          << sourcePort.ext.device.address << " and sink "
                          << audio_device_to_string(sourcePort.ext.device.type) << " and sink "
                          << sinkPort.ext.device.address;
                          << audio_device_to_string(sinkPort.ext.device.type);


    // verify that patch is established between source and the sink.
    // verify that patch is established between source and the sink.
    ASSERT_NO_FATAL_FAILURE(anyPatchContainsInputDevice(sourcePort.id, patchFound));
    ASSERT_NO_FATAL_FAILURE(anyPatchContainsInputDevice(sourcePort.id, patchFound));
@@ -302,8 +309,8 @@ TEST_F(AudioSystemTest, CreateAndReleaseAudioPatch) {
    EXPECT_NE(AUDIO_PORT_HANDLE_NONE, audioPatchHandle);
    EXPECT_NE(AUDIO_PORT_HANDLE_NONE, audioPatchHandle);
    status = AudioSystem::releaseAudioPatch(audioPatchHandle);
    status = AudioSystem::releaseAudioPatch(audioPatchHandle);
    EXPECT_EQ(OK, status) << "AudioSystem::releaseAudioPatch failed between source "
    EXPECT_EQ(OK, status) << "AudioSystem::releaseAudioPatch failed between source "
                          << sourcePort.ext.device.address << " and sink "
                          << audio_device_to_string(sourcePort.ext.device.type) << " and sink "
                          << sinkPort.ext.device.address;
                          << audio_device_to_string(sinkPort.ext.device.type);


    // verify that no patch is established between source and the sink after releaseAudioPatch.
    // verify that no patch is established between source and the sink after releaseAudioPatch.
    ASSERT_NO_FATAL_FAILURE(anyPatchContainsInputDevice(sourcePort.id, patchFound));
    ASSERT_NO_FATAL_FAILURE(anyPatchContainsInputDevice(sourcePort.id, patchFound));
@@ -689,3 +696,24 @@ TEST_F(AudioSystemTest, SetDeviceConnectedState) {
        EXPECT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, deviceState);
        EXPECT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, deviceState);
    }
    }
}
}

class TestExecutionTracer : public ::testing::EmptyTestEventListener {
  public:
    void OnTestStart(const ::testing::TestInfo& test_info) override {
        TraceTestState("Started", test_info);
    }
    void OnTestEnd(const ::testing::TestInfo& test_info) override {
        TraceTestState("Completed", test_info);
    }

  private:
    static void TraceTestState(const std::string& state, const ::testing::TestInfo& test_info) {
        ALOGI("%s %s::%s", state.c_str(), test_info.test_suite_name(), test_info.name());
    }
};

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
    return RUN_ALL_TESTS();
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -1535,7 +1535,7 @@ status_t DeviceHalAidl::findOrCreatePortConfig(
        }
        }
        RETURN_STATUS_IF_ERROR(createOrUpdatePortConfig(requestedPortConfig, &portConfigIt,
        RETURN_STATUS_IF_ERROR(createOrUpdatePortConfig(requestedPortConfig, &portConfigIt,
                created));
                created));
    } else if (!flags.has_value()) {
    } else if (portConfigIt == mPortConfigs.end() && !flags.has_value()) {
        ALOGW("%s: mix port config for %s, handle %d not found in the module %s, "
        ALOGW("%s: mix port config for %s, handle %d not found in the module %s, "
                "and was not created as flags are not specified",
                "and was not created as flags are not specified",
                __func__, config.toString().c_str(), ioHandle, mInstance.c_str());
                __func__, config.toString().c_str(), ioHandle, mInstance.c_str());