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

Commit 4e0d98bb authored by Manisha Jajoo's avatar Manisha Jajoo
Browse files

Writer Test: Add MultiStartStopPauseTest

Test: writerTest -P /data/local/tmp/

Bug: 144317323

Change-Id: Iac61103874047b83973072f19ec3b1390851cff0
parent e17f0c1c
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -26,5 +26,5 @@ adb push $ANDROID_BUILD_TOP/frameworks/av/media/codec2/hidl/1.0/vts/functional/


usage: writerTest -P \<path_to_res_folder\>
usage: writerTest -P \<path_to_res_folder\>
```
```
adb shell /data/local/tmp/writerTest -P /sdcard/res/
adb shell /data/local/tmp/writerTest -P /data/local/tmp/
```
```
+67 −0
Original line number Original line Diff line number Diff line
@@ -375,6 +375,73 @@ TEST_P(WriterTest, PauseWriterTest) {
    close(fd);
    close(fd);
}
}


TEST_P(WriterTest, MultiStartStopPauseTest) {
    // TODO: (b/144821804)
    // Enable the test for MPE2TS writer
    if (mDisableTest || mWriterName == standardWriters::MPEG2TS) return;
    ALOGV("Test writers for multiple start, stop and pause calls");

    string outputFile = OUTPUT_FILE_NAME;
    int32_t fd =
            open(outputFile.c_str(), O_CREAT | O_LARGEFILE | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
    ASSERT_GE(fd, 0) << "Cannot open output file to dump writer's data";

    string writerFormat = GetParam().first;
    int32_t status = createWriter(fd);
    ASSERT_EQ(status, (status_t)OK) << "Failed to create writer for output format:" << writerFormat;

    string inputFile = gEnv->getRes();
    string inputInfo = gEnv->getRes();
    configFormat param;
    bool isAudio;
    int32_t inputFileIdx = GetParam().second;
    getFileDetails(inputFile, inputInfo, param, isAudio, inputFileIdx);
    ASSERT_NE(inputFile.compare(gEnv->getRes()), 0) << "No input file specified";

    getInputBufferInfo(inputFile, inputInfo);
    status = addWriterSource(isAudio, param);
    ASSERT_EQ((status_t)OK, status) << "Failed to add source for " << writerFormat << "Writer";

    // first start should succeed.
    status = mWriter->start(mFileMeta.get());
    ASSERT_EQ((status_t)OK, status) << "Couldn't start the writer";

    // Multiple start() may/may not succeed.
    // Writers are expected to not crash on multiple start() calls.
    for (int32_t count = 0; count < kMaxCount; count++) {
        mWriter->start(mFileMeta.get());
    }

    (void)sendBuffersToWriter(mInputStream, mBufferInfo, mInputFrameId, mCurrentTrack, 0,
                              mBufferInfo.size() / 4);
    for (int32_t count = 0; count < kMaxCount; count++) {
        mWriter->pause();
        mWriter->start(mFileMeta.get());
    }

    mWriter->pause();
    int32_t numFramesPaused = mBufferInfo.size() / 4;
    (void)sendBuffersToWriter(mInputStream, mBufferInfo, mInputFrameId, mCurrentTrack,
                              mInputFrameId, numFramesPaused, true);
    for (int32_t count = 0; count < kMaxCount; count++) {
        mWriter->start(mFileMeta.get());
    }

    (void)sendBuffersToWriter(mInputStream, mBufferInfo, mInputFrameId, mCurrentTrack,
                              mInputFrameId, mBufferInfo.size());
    mCurrentTrack->stop();

    // first stop should succeed.
    status = mWriter->stop();
    ASSERT_EQ((status_t)OK, status) << "Couldn't stop the writer";
    // Multiple stop() may/may not succeed.
    // Writers are expected to not crash on multiple stop() calls.
    for (int32_t count = 0; count < kMaxCount; count++) {
        mWriter->stop();
    }
    close(fd);
}

// TODO: (b/144476164)
// TODO: (b/144476164)
// Add AAC_ADTS, FLAC, AV1 input
// Add AAC_ADTS, FLAC, AV1 input
INSTANTIATE_TEST_SUITE_P(WriterTestAll, WriterTest,
INSTANTIATE_TEST_SUITE_P(WriterTestAll, WriterTest,
+1 −1
Original line number Original line Diff line number Diff line
@@ -25,7 +25,7 @@ using namespace std;


class WriterTestEnvironment : public ::testing::Environment {
class WriterTestEnvironment : public ::testing::Environment {
  public:
  public:
    WriterTestEnvironment() : res("/sdcard/media/") {}
    WriterTestEnvironment() : res("/data/local/tmp/") {}


    // Parses the command line arguments
    // Parses the command line arguments
    int initFromOptions(int argc, char **argv);
    int initFromOptions(int argc, char **argv);
+1 −1
Original line number Original line Diff line number Diff line
@@ -26,7 +26,7 @@ int32_t sendBuffersToWriter(ifstream &inputStream, vector<BufferInfo> &bufferInf
                            int32_t &inputFrameId, sp<MediaAdapter> &currentTrack, int32_t offset,
                            int32_t &inputFrameId, sp<MediaAdapter> &currentTrack, int32_t offset,
                            int32_t range, bool isPaused) {
                            int32_t range, bool isPaused) {
    while (1) {
    while (1) {
        if (inputFrameId == (int)bufferInfo.size() || inputFrameId >= (offset + range)) break;
        if (inputFrameId >= (int)bufferInfo.size() || inputFrameId >= (offset + range)) break;
        int32_t size = bufferInfo[inputFrameId].size;
        int32_t size = bufferInfo[inputFrameId].size;
        char *data = (char *)malloc(size);
        char *data = (char *)malloc(size);
        if (!data) {
        if (!data) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ using namespace std;
#define CODEC_CONFIG_FLAG 32
#define CODEC_CONFIG_FLAG 32


constexpr uint32_t kMaxCSDStrlen = 16;
constexpr uint32_t kMaxCSDStrlen = 16;
constexpr uint32_t kMaxCount = 20;


struct BufferInfo {
struct BufferInfo {
    int32_t size;
    int32_t size;