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

Commit fdd62ff6 authored by Harish Mahendrakar's avatar Harish Mahendrakar
Browse files

C2 Vts: Avoid using strings to pass integer and bool values

In order to display parameters as index, tests were currently
using android::hardware::PrintInstanceTupleNameToString which
required all the parameters to be of the same type.
This limitation required passing integers and booleans as strings
and had to be converted back and forth.

This is now fixed by implementing a custom
PrintInstanceTupleNameToString that handles mixed variable types
in a tuple.

Bug: 155354751
Test: atest VtsHalMediaC2V1_0TargetAudioDecTest \
      VtsHalMediaC2V1_0TargetAudioEncTest \
      VtsHalMediaC2V1_0TargetVideoDecTest \
      VtsHalMediaC2V1_0TargetVideoEncTest \
      VtsHalMediaC2V1_0TargetComponentTest \
      VtsHalMediaC2V1_0TargetMasterTest

Change-Id: I49e63cd03ad7f5f691f6e8f32f40054f8c1e037e
parent b58afa74
Loading
Loading
Loading
Loading
+22 −27
Original line number Diff line number Diff line
@@ -33,11 +33,11 @@
using android::C2AllocatorIon;

#include "media_c2_hidl_test_common.h"
using DecodeTestParameters = std::tuple<std::string, std::string, uint32_t, bool>;
static std::vector<DecodeTestParameters> kDecodeTestParameters;

static std::vector<std::tuple<std::string, std::string, std::string, std::string>>
        kDecodeTestParameters;

static std::vector<std::tuple<std::string, std::string, std::string>> kCsdFlushTestParameters;
using CsdFlushTestParameters = std::tuple<std::string, std::string, bool>;
static std::vector<CsdFlushTestParameters> kCsdFlushTestParameters;

struct CompToURL {
    std::string mime;
@@ -202,9 +202,8 @@ class Codec2AudioDecHidlTestBase : public ::testing::Test {
    }
};

class Codec2AudioDecHidlTest
    : public Codec2AudioDecHidlTestBase,
      public ::testing::WithParamInterface<std::tuple<std::string, std::string>> {
class Codec2AudioDecHidlTest : public Codec2AudioDecHidlTestBase,
                               public ::testing::WithParamInterface<TestParameters> {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
@@ -428,10 +427,8 @@ TEST_P(Codec2AudioDecHidlTest, configComp) {
    ASSERT_EQ(mComponent->stop(), C2_OK);
}

class Codec2AudioDecDecodeTest
    : public Codec2AudioDecHidlTestBase,
      public ::testing::WithParamInterface<
              std::tuple<std::string, std::string, std::string, std::string>> {
class Codec2AudioDecDecodeTest : public Codec2AudioDecHidlTestBase,
                                 public ::testing::WithParamInterface<DecodeTestParameters> {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
@@ -442,9 +439,8 @@ TEST_P(Codec2AudioDecDecodeTest, DecodeTest) {
    description("Decodes input file");
    if (mDisableTest) GTEST_SKIP() << "Test is disabled";

    uint32_t streamIndex = std::stoi(std::get<2>(GetParam()));
    ;
    bool signalEOS = !std::get<3>(GetParam()).compare("true");
    uint32_t streamIndex = std::get<2>(GetParam());
    bool signalEOS = std::get<3>(GetParam());
    mTimestampDevTest = true;
    char mURL[512], info[512];
    android::Vector<FrameInfo> Info;
@@ -761,9 +757,8 @@ TEST_P(Codec2AudioDecHidlTest, DecodeTestEmptyBuffersInserted) {
    ASSERT_EQ(mComponent->stop(), C2_OK);
}

class Codec2AudioDecCsdInputTests
    : public Codec2AudioDecHidlTestBase,
      public ::testing::WithParamInterface<std::tuple<std::string, std::string, std::string>> {
class Codec2AudioDecCsdInputTests : public Codec2AudioDecHidlTestBase,
                                    public ::testing::WithParamInterface<CsdFlushTestParameters> {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
@@ -809,7 +804,7 @@ TEST_P(Codec2AudioDecCsdInputTests, CSDFlushTest) {
    ASSERT_EQ(eleStream.is_open(), true);

    bool signalEOS = false;
    bool flushCsd = !std::get<2>(GetParam()).compare("true");
    bool flushCsd = std::get<2>(GetParam());
    ALOGV("sending %d csd data ", numCsds);
    int framesToDecode = numCsds;
    ASSERT_NO_FATAL_FAILURE(decodeNFrames(mComponent, mQueueLock, mQueueCondition, mWorkQueue,
@@ -865,16 +860,16 @@ TEST_P(Codec2AudioDecCsdInputTests, CSDFlushTest) {
}

INSTANTIATE_TEST_SUITE_P(PerInstance, Codec2AudioDecHidlTest, testing::ValuesIn(kTestParameters),
                         android::hardware::PrintInstanceTupleNameToString<>);
                         PrintInstanceTupleNameToString<>);

// DecodeTest with StreamIndex and EOS / No EOS
INSTANTIATE_TEST_SUITE_P(StreamIndexAndEOS, Codec2AudioDecDecodeTest,
                         testing::ValuesIn(kDecodeTestParameters),
                         android::hardware::PrintInstanceTupleNameToString<>);
                         PrintInstanceTupleNameToString<>);

INSTANTIATE_TEST_SUITE_P(CsdInputs, Codec2AudioDecCsdInputTests,
                         testing::ValuesIn(kCsdFlushTestParameters),
                         android::hardware::PrintInstanceTupleNameToString<>);
                         PrintInstanceTupleNameToString<>);

}  // anonymous namespace

@@ -883,18 +878,18 @@ int main(int argc, char** argv) {
    kTestParameters = getTestParameters(C2Component::DOMAIN_AUDIO, C2Component::KIND_DECODER);
    for (auto params : kTestParameters) {
        kDecodeTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "0", "false"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), 0, false));
        kDecodeTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "0", "true"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), 0, true));
        kDecodeTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "1", "false"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), 1, false));
        kDecodeTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "1", "true"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), 1, true));

        kCsdFlushTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "true"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), true));
        kCsdFlushTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "false"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), false));
    }

    ::testing::InitGoogleTest(&argc, argv);
+15 −17
Original line number Diff line number Diff line
@@ -35,8 +35,9 @@ using android::C2AllocatorIon;

#include "media_c2_hidl_test_common.h"

static std::vector<std::tuple<std::string, std::string, std::string, std::string>>
        kEncodeTestParameters;
using EncodeTestParameters = std::tuple<std::string, std::string, bool, int32_t>;

static std::vector<EncodeTestParameters> kEncodeTestParameters;

class LinearBuffer : public C2Buffer {
  public:
@@ -170,9 +171,8 @@ class Codec2AudioEncHidlTestBase : public ::testing::Test {
    }
};

class Codec2AudioEncHidlTest
    : public Codec2AudioEncHidlTestBase,
      public ::testing::WithParamInterface<std::tuple<std::string, std::string>> {
class Codec2AudioEncHidlTest : public Codec2AudioEncHidlTestBase,
                               public ::testing::WithParamInterface<TestParameters> {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
@@ -362,10 +362,8 @@ TEST_P(Codec2AudioEncHidlTest, validateCompName) {
    ASSERT_EQ(mDisableTest, false);
}

class Codec2AudioEncEncodeTest
    : public Codec2AudioEncHidlTestBase,
      public ::testing::WithParamInterface<
              std::tuple<std::string, std::string, std::string, std::string>> {
class Codec2AudioEncEncodeTest : public Codec2AudioEncHidlTestBase,
                                 public ::testing::WithParamInterface<EncodeTestParameters> {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
@@ -378,9 +376,9 @@ TEST_P(Codec2AudioEncEncodeTest, EncodeTest) {
    char mURL[512];
    strcpy(mURL, sResourceDir.c_str());
    GetURLForComponent(mURL);
    bool signalEOS = !std::get<2>(GetParam()).compare("true");
    bool signalEOS = std::get<2>(GetParam());
    // Ratio w.r.t to mInputMaxBufSize
    int32_t inputMaxBufRatio = std::stoi(std::get<3>(GetParam()));
    int32_t inputMaxBufRatio = std::get<3>(GetParam());

    int32_t nChannels;
    int32_t nSampleRate;
@@ -751,13 +749,13 @@ TEST_P(Codec2AudioEncHidlTest, MultiSampleRateTest) {
}

INSTANTIATE_TEST_SUITE_P(PerInstance, Codec2AudioEncHidlTest, testing::ValuesIn(kTestParameters),
                         android::hardware::PrintInstanceTupleNameToString<>);
                         PrintInstanceTupleNameToString<>);

// EncodeTest with EOS / No EOS and inputMaxBufRatio
// inputMaxBufRatio is ratio w.r.t. to mInputMaxBufSize
INSTANTIATE_TEST_SUITE_P(EncodeTest, Codec2AudioEncEncodeTest,
                         testing::ValuesIn(kEncodeTestParameters),
                         android::hardware::PrintInstanceTupleNameToString<>);
                         PrintInstanceTupleNameToString<>);

}  // anonymous namespace

@@ -766,13 +764,13 @@ int main(int argc, char** argv) {
    kTestParameters = getTestParameters(C2Component::DOMAIN_AUDIO, C2Component::KIND_ENCODER);
    for (auto params : kTestParameters) {
        kEncodeTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "false", "1"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), false, 1));
        kEncodeTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "false", "2"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), false, 2));
        kEncodeTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "true", "1"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), true, 1));
        kEncodeTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "true", "2"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), true, 2));
    }

    ::testing::InitGoogleTest(&argc, argv);
+4 −4
Original line number Diff line number Diff line
@@ -176,15 +176,15 @@ int64_t getNowUs() {
}

// Return all test parameters, a list of tuple of <instance, component>
const std::vector<std::tuple<std::string, std::string>>& getTestParameters() {
const std::vector<TestParameters>& getTestParameters() {
    return getTestParameters(C2Component::DOMAIN_OTHER, C2Component::KIND_OTHER);
}

// Return all test parameters, a list of tuple of <instance, component> with matching domain and
// kind.
const std::vector<std::tuple<std::string, std::string>>& getTestParameters(
        C2Component::domain_t domain, C2Component::kind_t kind) {
    static std::vector<std::tuple<std::string, std::string>> parameters;
const std::vector<TestParameters>& getTestParameters(C2Component::domain_t domain,
                                                     C2Component::kind_t kind) {
    static std::vector<TestParameters> parameters;

    auto instances = android::Codec2Client::GetServiceNames();
    for (std::string instance : instances) {
+17 −4
Original line number Diff line number Diff line
@@ -40,7 +40,8 @@ using ::android::hardware::Void;

using namespace ::std::chrono;

static std::vector<std::tuple<std::string, std::string>> kTestParameters;
using TestParameters = std::tuple<std::string, std::string>;
static std::vector<TestParameters> kTestParameters;

// Resource directory
extern std::string sResourceDir;
@@ -54,6 +55,18 @@ struct FrameInfo {
    int64_t timestamp;
};

template <typename... T>
static inline std::string PrintInstanceTupleNameToString(
        const testing::TestParamInfo<std::tuple<T...>>& info) {
    std::stringstream ss;
    std::apply([&ss](auto&&... elems) { ((ss << elems << '_'), ...); }, info.param);
    ss << info.index;
    std::string param_string = ss.str();
    auto isNotAlphaNum = [](char c) { return !std::isalnum(c); };
    std::replace_if(param_string.begin(), param_string.end(), isNotAlphaNum, '_');
    return param_string;
}

/*
 * Handle Callback functions onWorkDone(), onTripped(),
 * onError(), onDeath(), onFramesRendered()
@@ -114,12 +127,12 @@ struct CodecListener : public android::Codec2Client::Listener {
void parseArgs(int argc, char** argv);

// Return all test parameters, a list of tuple of <instance, component>.
const std::vector<std::tuple<std::string, std::string>>& getTestParameters();
const std::vector<TestParameters>& getTestParameters();

// Return all test parameters, a list of tuple of <instance, component> with matching domain and
// kind.
const std::vector<std::tuple<std::string, std::string>>& getTestParameters(
        C2Component::domain_t domain, C2Component::kind_t kind);
const std::vector<TestParameters>& getTestParameters(C2Component::domain_t domain,
                                                     C2Component::kind_t kind);

/*
 * common functions declarations
+18 −26
Original line number Diff line number Diff line
@@ -53,9 +53,8 @@
    }

namespace {

static std::vector<std::tuple<std::string, std::string, std::string, std::string>>
        kInputTestParameters;
using InputTestParameters = std::tuple<std::string, std::string, uint32_t, bool>;
static std::vector<InputTestParameters> kInputTestParameters;

// google.codec2 Component test setup
class Codec2ComponentHidlTestBase : public ::testing::Test {
@@ -120,9 +119,8 @@ class Codec2ComponentHidlTestBase : public ::testing::Test {
    }
};

class Codec2ComponentHidlTest
    : public Codec2ComponentHidlTestBase,
      public ::testing::WithParamInterface<std::tuple<std::string, std::string>> {
class Codec2ComponentHidlTest : public Codec2ComponentHidlTestBase,
                                public ::testing::WithParamInterface<TestParameters> {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
@@ -317,10 +315,8 @@ TEST_P(Codec2ComponentHidlTest, Timeout) {
    ASSERT_EQ(err, C2_OK);
}

class Codec2ComponentInputTests
    : public Codec2ComponentHidlTestBase,
      public ::testing::WithParamInterface<
              std::tuple<std::string, std::string, std::string, std::string>> {
class Codec2ComponentInputTests : public Codec2ComponentHidlTestBase,
                                  public ::testing::WithParamInterface<InputTestParameters> {
    void getParams() {
        mInstanceName = std::get<0>(GetParam());
        mComponentName = std::get<1>(GetParam());
@@ -330,8 +326,8 @@ class Codec2ComponentInputTests
TEST_P(Codec2ComponentInputTests, InputBufferTest) {
    description("Tests for different inputs");

    uint32_t flags = std::stoul(std::get<2>(GetParam()));
    bool isNullBuffer = !std::get<3>(GetParam()).compare("true");
    uint32_t flags = std::get<2>(GetParam());
    bool isNullBuffer = std::get<3>(GetParam());
    if (isNullBuffer)
        ALOGD("Testing for null input buffer with flag : %u", flags);
    else
@@ -350,11 +346,10 @@ TEST_P(Codec2ComponentInputTests, InputBufferTest) {
}

INSTANTIATE_TEST_SUITE_P(PerInstance, Codec2ComponentHidlTest, testing::ValuesIn(kTestParameters),
                         android::hardware::PrintInstanceTupleNameToString<>);
                         PrintInstanceTupleNameToString<>);

INSTANTIATE_TEST_CASE_P(NonStdInputs, Codec2ComponentInputTests,
                        testing::ValuesIn(kInputTestParameters),
                        android::hardware::PrintInstanceTupleNameToString<>);
                        testing::ValuesIn(kInputTestParameters), PrintInstanceTupleNameToString<>);
}  // anonymous namespace

// TODO: Add test for Invalid work,
@@ -364,18 +359,15 @@ int main(int argc, char** argv) {
    kTestParameters = getTestParameters();
    for (auto params : kTestParameters) {
        kInputTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "0", "true"));
        kInputTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params),
                                std::to_string(C2FrameData::FLAG_END_OF_STREAM), "true"));
        kInputTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params), "0", "false"));
        kInputTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params),
                                std::to_string(C2FrameData::FLAG_CODEC_CONFIG), "false"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), 0, true));
        kInputTestParameters.push_back(std::make_tuple(std::get<0>(params), std::get<1>(params),
                                                       C2FrameData::FLAG_END_OF_STREAM, true));
        kInputTestParameters.push_back(
                std::make_tuple(std::get<0>(params), std::get<1>(params),
                                std::to_string(C2FrameData::FLAG_END_OF_STREAM), "false"));
                std::make_tuple(std::get<0>(params), std::get<1>(params), 0, false));
        kInputTestParameters.push_back(std::make_tuple(std::get<0>(params), std::get<1>(params),
                                                       C2FrameData::FLAG_CODEC_CONFIG, false));
        kInputTestParameters.push_back(std::make_tuple(std::get<0>(params), std::get<1>(params),
                                                       C2FrameData::FLAG_END_OF_STREAM, false));
    }

    ::testing::InitGoogleTest(&argc, argv);
Loading