106f6ba60Sopenharmony_ci/*
206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License.
506f6ba60Sopenharmony_ci * You may obtain a copy of the License at
606f6ba60Sopenharmony_ci *
706f6ba60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
806f6ba60Sopenharmony_ci *
906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and
1306f6ba60Sopenharmony_ci * limitations under the License.
1406f6ba60Sopenharmony_ci */
1506f6ba60Sopenharmony_ci
1606f6ba60Sopenharmony_ci#include <dlfcn.h>
1706f6ba60Sopenharmony_ci#include <gtest/gtest.h>
1806f6ba60Sopenharmony_ci#include <iomanip>
1906f6ba60Sopenharmony_ci#include <sys/time.h>
2006f6ba60Sopenharmony_ci#include <sys/types.h>
2106f6ba60Sopenharmony_ci#include <ctime>
2206f6ba60Sopenharmony_ci#include <unistd.h>
2306f6ba60Sopenharmony_ci#include <vector>
2406f6ba60Sopenharmony_ci
2506f6ba60Sopenharmony_ci#include "logging.h"
2606f6ba60Sopenharmony_ci#include "memory_data_plugin.h"
2706f6ba60Sopenharmony_ci#include "plugin_module_api.h"
2806f6ba60Sopenharmony_ci#include "sample_plugin.h"
2906f6ba60Sopenharmony_ci#include "stream_plugin.h"
3006f6ba60Sopenharmony_ci
3106f6ba60Sopenharmony_ciusing namespace testing::ext;
3206f6ba60Sopenharmony_ci
3306f6ba60Sopenharmony_cinamespace {
3406f6ba60Sopenharmony_ciconstexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024;
3506f6ba60Sopenharmony_cistd::mutex g_taskMutex;
3606f6ba60Sopenharmony_cistd::unique_ptr<MemoryDataPlugin> memoryPlugin = nullptr;
3706f6ba60Sopenharmony_cistd::unique_ptr<StreamPlugin> streamPlugin = nullptr;
3806f6ba60Sopenharmony_cistd::unique_ptr<SamplePlugin> samplePlugin = nullptr;
3906f6ba60Sopenharmony_ci
4006f6ba60Sopenharmony_ciclass PluginModuleApiTest : public ::testing::Test {
4106f6ba60Sopenharmony_cipublic:
4206f6ba60Sopenharmony_ci    PluginModuleCallbacks* memoryCallbacks_;
4306f6ba60Sopenharmony_ci    PluginModuleCallbacks* sampleCallbacks_;
4406f6ba60Sopenharmony_ci    PluginModuleCallbacks* streamCallbacks_;
4506f6ba60Sopenharmony_ci
4606f6ba60Sopenharmony_ci    PluginModuleStruct memoryModule_;
4706f6ba60Sopenharmony_ci    PluginModuleStruct sampleModule_;
4806f6ba60Sopenharmony_ci    PluginModuleStruct streamModule_;
4906f6ba60Sopenharmony_ci
5006f6ba60Sopenharmony_ci    WriterStruct* writer_;
5106f6ba60Sopenharmony_ciprotected:
5206f6ba60Sopenharmony_ci    static void SetUpTestCase() {}
5306f6ba60Sopenharmony_ci    static void TearDownTestCase() {}
5406f6ba60Sopenharmony_ci
5506f6ba60Sopenharmony_ci    void SetUp()
5606f6ba60Sopenharmony_ci    {
5706f6ba60Sopenharmony_ci        memoryCallbacks_ = nullptr;
5806f6ba60Sopenharmony_ci        sampleCallbacks_ = nullptr;
5906f6ba60Sopenharmony_ci        streamCallbacks_ = nullptr;
6006f6ba60Sopenharmony_ci        memoryModule_ = {memoryCallbacks_, "memory-plugin", "1.01", MAX_BUFFER_SIZE};
6106f6ba60Sopenharmony_ci        sampleModule_ = {sampleCallbacks_, "sample-plugin", "1.01", MAX_BUFFER_SIZE};
6206f6ba60Sopenharmony_ci        streamModule_ = {streamCallbacks_, "stream-plugin", "1.01", MAX_BUFFER_SIZE};
6306f6ba60Sopenharmony_ci        writer_ = nullptr;
6406f6ba60Sopenharmony_ci    }
6506f6ba60Sopenharmony_ci
6606f6ba60Sopenharmony_ci    bool PollPluginStub(MemoryDataPlugin& plugin, MemoryConfig& protoConfig, MemoryData& protoData);
6706f6ba60Sopenharmony_ci    bool StreamPluginStub(StreamPlugin& plugin, StreamConfig& protoConfig, StreamData& protoData);
6806f6ba60Sopenharmony_ci    // memory
6906f6ba60Sopenharmony_ci    static int MemDataPluginSessionStart(const uint8_t* configData, uint32_t configSize);
7006f6ba60Sopenharmony_ci    static int MemPluginReportResult(uint8_t* bufferData, uint32_t bufferSize);
7106f6ba60Sopenharmony_ci    static int MemPluginSessionStop();
7206f6ba60Sopenharmony_ci
7306f6ba60Sopenharmony_ci    // stream
7406f6ba60Sopenharmony_ci    static int StreamPluginSessionStart(const uint8_t* configData, uint32_t configSize);
7506f6ba60Sopenharmony_ci    static int StreamPluginSessionStop();
7606f6ba60Sopenharmony_ci    static int StreamRegisterWriterStruct(WriterStruct* writer);
7706f6ba60Sopenharmony_ci    static long Write(WriterStruct* writer, const void* data, size_t size);
7806f6ba60Sopenharmony_ci    static bool Flush(WriterStruct* writer);
7906f6ba60Sopenharmony_ci
8006f6ba60Sopenharmony_ci    // sample
8106f6ba60Sopenharmony_ci    static int SamplePluginSessionStart(const uint8_t* configData, uint32_t configSize);
8206f6ba60Sopenharmony_ci    static int SamplePluginReportResult(uint8_t* bufferData, uint32_t bufferSize);
8306f6ba60Sopenharmony_ci    static int SamplePluginSessionStop();
8406f6ba60Sopenharmony_ci    void SetSampleConfig(std::vector<uint8_t>& configData, uint32_t& configSize);
8506f6ba60Sopenharmony_ci    void SetMemoryConfig(std::vector<uint8_t>& configData, uint32_t& configSize);
8606f6ba60Sopenharmony_ci    void SetStreamConfig(std::vector<uint8_t>& configData, uint32_t& configSize);
8706f6ba60Sopenharmony_ci};
8806f6ba60Sopenharmony_ci
8906f6ba60Sopenharmony_ci// memory
9006f6ba60Sopenharmony_ciint PluginModuleApiTest::MemDataPluginSessionStart(const uint8_t* configData, uint32_t configSize)
9106f6ba60Sopenharmony_ci{
9206f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
9306f6ba60Sopenharmony_ci    memoryPlugin = std::make_unique<MemoryDataPlugin>();
9406f6ba60Sopenharmony_ci    return memoryPlugin->Start(configData, configSize);
9506f6ba60Sopenharmony_ci}
9606f6ba60Sopenharmony_ci
9706f6ba60Sopenharmony_ciint PluginModuleApiTest::MemPluginReportResult(uint8_t* bufferData, uint32_t bufferSize)
9806f6ba60Sopenharmony_ci{
9906f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
10006f6ba60Sopenharmony_ci    return memoryPlugin->Report(bufferData, bufferSize);
10106f6ba60Sopenharmony_ci}
10206f6ba60Sopenharmony_ci
10306f6ba60Sopenharmony_ciint PluginModuleApiTest::MemPluginSessionStop()
10406f6ba60Sopenharmony_ci{
10506f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
10606f6ba60Sopenharmony_ci    CHECK_TRUE(memoryPlugin != nullptr, -1, "memoryPlugin is null!!!");
10706f6ba60Sopenharmony_ci    memoryPlugin->Stop();
10806f6ba60Sopenharmony_ci    memoryPlugin = nullptr;
10906f6ba60Sopenharmony_ci    return 0;
11006f6ba60Sopenharmony_ci}
11106f6ba60Sopenharmony_ci
11206f6ba60Sopenharmony_ci// stream
11306f6ba60Sopenharmony_ciint PluginModuleApiTest::StreamPluginSessionStart(const uint8_t* configData, uint32_t configSize)
11406f6ba60Sopenharmony_ci{
11506f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
11606f6ba60Sopenharmony_ci    CHECK_TRUE(streamPlugin != nullptr, -1, "PluginStub::start plugin fail!!!");
11706f6ba60Sopenharmony_ci    return streamPlugin->Start(configData, configSize);
11806f6ba60Sopenharmony_ci}
11906f6ba60Sopenharmony_ci
12006f6ba60Sopenharmony_ciint PluginModuleApiTest::StreamPluginSessionStop()
12106f6ba60Sopenharmony_ci{
12206f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
12306f6ba60Sopenharmony_ci    streamPlugin->Stop();
12406f6ba60Sopenharmony_ci    streamPlugin = nullptr;
12506f6ba60Sopenharmony_ci    return 0;
12606f6ba60Sopenharmony_ci}
12706f6ba60Sopenharmony_ci
12806f6ba60Sopenharmony_ciint PluginModuleApiTest::StreamRegisterWriterStruct(WriterStruct* writer)
12906f6ba60Sopenharmony_ci{
13006f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
13106f6ba60Sopenharmony_ci    streamPlugin = std::make_unique<StreamPlugin>();
13206f6ba60Sopenharmony_ci    streamPlugin->SetWriter(writer);
13306f6ba60Sopenharmony_ci    return 0;
13406f6ba60Sopenharmony_ci}
13506f6ba60Sopenharmony_ci
13606f6ba60Sopenharmony_ci// write
13706f6ba60Sopenharmony_cilong PluginModuleApiTest::Write(WriterStruct* writer, const void* data, size_t size)
13806f6ba60Sopenharmony_ci{
13906f6ba60Sopenharmony_ci    PROFILER_LOG_INFO(LOG_CORE, "PluginModuleApiTest::Write no implementation !");
14006f6ba60Sopenharmony_ci    return 0;
14106f6ba60Sopenharmony_ci}
14206f6ba60Sopenharmony_ci
14306f6ba60Sopenharmony_cibool PluginModuleApiTest::Flush(WriterStruct* writer)
14406f6ba60Sopenharmony_ci{
14506f6ba60Sopenharmony_ci    PROFILER_LOG_INFO(LOG_CORE, "PluginModuleApiTest::Write no implementation !");
14606f6ba60Sopenharmony_ci    return true;
14706f6ba60Sopenharmony_ci}
14806f6ba60Sopenharmony_ci
14906f6ba60Sopenharmony_ci// sample
15006f6ba60Sopenharmony_ciint PluginModuleApiTest::SamplePluginSessionStart(const uint8_t* configData, uint32_t configSize)
15106f6ba60Sopenharmony_ci{
15206f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
15306f6ba60Sopenharmony_ci    samplePlugin = std::make_unique<SamplePlugin>();
15406f6ba60Sopenharmony_ci    return samplePlugin->Start(configData, configSize);
15506f6ba60Sopenharmony_ci}
15606f6ba60Sopenharmony_ci
15706f6ba60Sopenharmony_ciint PluginModuleApiTest::SamplePluginReportResult(uint8_t* bufferData, uint32_t bufferSize)
15806f6ba60Sopenharmony_ci{
15906f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
16006f6ba60Sopenharmony_ci    return samplePlugin->Report(bufferData, bufferSize);
16106f6ba60Sopenharmony_ci}
16206f6ba60Sopenharmony_ci
16306f6ba60Sopenharmony_ciint PluginModuleApiTest::SamplePluginSessionStop()
16406f6ba60Sopenharmony_ci{
16506f6ba60Sopenharmony_ci    std::lock_guard<std::mutex> guard(g_taskMutex);
16606f6ba60Sopenharmony_ci    samplePlugin->Stop();
16706f6ba60Sopenharmony_ci    samplePlugin = nullptr;
16806f6ba60Sopenharmony_ci    return 0;
16906f6ba60Sopenharmony_ci}
17006f6ba60Sopenharmony_ci
17106f6ba60Sopenharmony_civoid PluginModuleApiTest::SetSampleConfig(std::vector<uint8_t>& configData, uint32_t& configSize)
17206f6ba60Sopenharmony_ci{
17306f6ba60Sopenharmony_ci    SampleConfig protoConfig;
17406f6ba60Sopenharmony_ci    protoConfig.set_pid(1);
17506f6ba60Sopenharmony_ci    // serialize
17606f6ba60Sopenharmony_ci    protoConfig.SerializeToArray(configData.data(), configData.size());
17706f6ba60Sopenharmony_ci    configSize = protoConfig.ByteSizeLong();
17806f6ba60Sopenharmony_ci}
17906f6ba60Sopenharmony_ci
18006f6ba60Sopenharmony_civoid PluginModuleApiTest::SetMemoryConfig(std::vector<uint8_t>& configData, uint32_t& configSize)
18106f6ba60Sopenharmony_ci{
18206f6ba60Sopenharmony_ci    MemoryConfig protoConfig;
18306f6ba60Sopenharmony_ci    protoConfig.set_report_process_mem_info(true);
18406f6ba60Sopenharmony_ci    protoConfig.add_pid(1);
18506f6ba60Sopenharmony_ci    // serialize
18606f6ba60Sopenharmony_ci    protoConfig.SerializeToArray(configData.data(), configSize);
18706f6ba60Sopenharmony_ci    configSize = protoConfig.ByteSizeLong();
18806f6ba60Sopenharmony_ci}
18906f6ba60Sopenharmony_ci
19006f6ba60Sopenharmony_civoid PluginModuleApiTest::SetStreamConfig(std::vector<uint8_t>& configData, uint32_t& configSize)
19106f6ba60Sopenharmony_ci{
19206f6ba60Sopenharmony_ci    StreamConfig protoConfig;
19306f6ba60Sopenharmony_ci    protoConfig.set_pid(1);
19406f6ba60Sopenharmony_ci    // serialize
19506f6ba60Sopenharmony_ci    protoConfig.SerializeToArray(configData.data(), configSize);
19606f6ba60Sopenharmony_ci    configSize = protoConfig.ByteSizeLong();
19706f6ba60Sopenharmony_ci}
19806f6ba60Sopenharmony_ci
19906f6ba60Sopenharmony_ci// 流式调用写接口
20006f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, StreamPluginRegister1, TestSize.Level1)
20106f6ba60Sopenharmony_ci{
20206f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
20306f6ba60Sopenharmony_ci        StreamPluginSessionStart,
20406f6ba60Sopenharmony_ci        0,
20506f6ba60Sopenharmony_ci        StreamPluginSessionStop,
20606f6ba60Sopenharmony_ci        (RegisterWriterStructCallback)StreamRegisterWriterStruct,
20706f6ba60Sopenharmony_ci    };
20806f6ba60Sopenharmony_ci    streamCallbacks_ = &callbacks;
20906f6ba60Sopenharmony_ci
21006f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onRegisterWriterStruct, nullptr);
21106f6ba60Sopenharmony_ci    EXPECT_EQ(streamCallbacks_->onRegisterWriterStruct(writer_), 0);
21206f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin, nullptr);
21306f6ba60Sopenharmony_ci
21406f6ba60Sopenharmony_ci    EXPECT_EQ(streamPlugin->resultWriter_, nullptr);
21506f6ba60Sopenharmony_ci}
21606f6ba60Sopenharmony_ci
21706f6ba60Sopenharmony_ci// 流式调用写接口
21806f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, StreamPluginRegister2, TestSize.Level1)
21906f6ba60Sopenharmony_ci{
22006f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
22106f6ba60Sopenharmony_ci        StreamPluginSessionStart,
22206f6ba60Sopenharmony_ci        0,
22306f6ba60Sopenharmony_ci        StreamPluginSessionStop,
22406f6ba60Sopenharmony_ci        (RegisterWriterStructCallback)StreamRegisterWriterStruct,
22506f6ba60Sopenharmony_ci    };
22606f6ba60Sopenharmony_ci    streamCallbacks_ = &callbacks;
22706f6ba60Sopenharmony_ci
22806f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onRegisterWriterStruct, nullptr);
22906f6ba60Sopenharmony_ci    WriterStruct writer = {
23006f6ba60Sopenharmony_ci        Write,
23106f6ba60Sopenharmony_ci        Flush,
23206f6ba60Sopenharmony_ci    };
23306f6ba60Sopenharmony_ci    writer_ = &writer;
23406f6ba60Sopenharmony_ci    EXPECT_EQ(streamCallbacks_->onRegisterWriterStruct(writer_), 0);
23506f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin, nullptr);
23606f6ba60Sopenharmony_ci
23706f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin->resultWriter_, nullptr);
23806f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin->resultWriter_->write, nullptr);
23906f6ba60Sopenharmony_ci}
24006f6ba60Sopenharmony_ci
24106f6ba60Sopenharmony_ci// 流式调用写接口
24206f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, StreamPluginRegister3, TestSize.Level1)
24306f6ba60Sopenharmony_ci{
24406f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
24506f6ba60Sopenharmony_ci        StreamPluginSessionStart,
24606f6ba60Sopenharmony_ci        0,
24706f6ba60Sopenharmony_ci        StreamPluginSessionStop,
24806f6ba60Sopenharmony_ci        (RegisterWriterStructCallback)StreamRegisterWriterStruct,
24906f6ba60Sopenharmony_ci    };
25006f6ba60Sopenharmony_ci    streamCallbacks_ = &callbacks;
25106f6ba60Sopenharmony_ci
25206f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onRegisterWriterStruct, nullptr);
25306f6ba60Sopenharmony_ci    WriterStruct writer = {
25406f6ba60Sopenharmony_ci        Write,
25506f6ba60Sopenharmony_ci        Flush,
25606f6ba60Sopenharmony_ci    };
25706f6ba60Sopenharmony_ci    writer_ = &writer;
25806f6ba60Sopenharmony_ci    EXPECT_EQ(streamCallbacks_->onRegisterWriterStruct(writer_), 0);
25906f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin, nullptr);
26006f6ba60Sopenharmony_ci
26106f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin->resultWriter_, nullptr);
26206f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin->resultWriter_->write, nullptr);
26306f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin->resultWriter_->flush, nullptr);
26406f6ba60Sopenharmony_ci}
26506f6ba60Sopenharmony_ci
26606f6ba60Sopenharmony_ci// 轮询式调用写接口
26706f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, SamplePluginRegister, TestSize.Level1)
26806f6ba60Sopenharmony_ci{
26906f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
27006f6ba60Sopenharmony_ci        SamplePluginSessionStart,
27106f6ba60Sopenharmony_ci        SamplePluginReportResult,
27206f6ba60Sopenharmony_ci        SamplePluginSessionStop,
27306f6ba60Sopenharmony_ci        0,
27406f6ba60Sopenharmony_ci    };
27506f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
27606f6ba60Sopenharmony_ci
27706f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onRegisterWriterStruct, nullptr);
27806f6ba60Sopenharmony_ci    EXPECT_EQ(samplePlugin, nullptr);
27906f6ba60Sopenharmony_ci}
28006f6ba60Sopenharmony_ci
28106f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, MemPluginRegister, TestSize.Level1)
28206f6ba60Sopenharmony_ci{
28306f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
28406f6ba60Sopenharmony_ci        MemDataPluginSessionStart,
28506f6ba60Sopenharmony_ci        MemPluginReportResult,
28606f6ba60Sopenharmony_ci        MemPluginSessionStop,
28706f6ba60Sopenharmony_ci        0,
28806f6ba60Sopenharmony_ci    };
28906f6ba60Sopenharmony_ci    memoryCallbacks_ = &callbacks;
29006f6ba60Sopenharmony_ci
29106f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onRegisterWriterStruct, nullptr);
29206f6ba60Sopenharmony_ci    EXPECT_EQ(memoryPlugin, nullptr);
29306f6ba60Sopenharmony_ci}
29406f6ba60Sopenharmony_ci
29506f6ba60Sopenharmony_ci// 流式插件正常启动
29606f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, StreamPluginStartSucc, TestSize.Level1)
29706f6ba60Sopenharmony_ci{
29806f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
29906f6ba60Sopenharmony_ci        StreamPluginSessionStart,
30006f6ba60Sopenharmony_ci        0,
30106f6ba60Sopenharmony_ci        StreamPluginSessionStop,
30206f6ba60Sopenharmony_ci        (RegisterWriterStructCallback)StreamRegisterWriterStruct,
30306f6ba60Sopenharmony_ci    };
30406f6ba60Sopenharmony_ci    streamCallbacks_ = &callbacks;
30506f6ba60Sopenharmony_ci
30606f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onRegisterWriterStruct, nullptr);
30706f6ba60Sopenharmony_ci    WriterStruct writer = {
30806f6ba60Sopenharmony_ci        Write,
30906f6ba60Sopenharmony_ci        Flush,
31006f6ba60Sopenharmony_ci    };
31106f6ba60Sopenharmony_ci    writer_ = &writer;
31206f6ba60Sopenharmony_ci    streamCallbacks_->onRegisterWriterStruct(writer_);
31306f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin, nullptr);
31406f6ba60Sopenharmony_ci
31506f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onPluginSessionStart, nullptr);
31606f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
31706f6ba60Sopenharmony_ci    std::vector<uint8_t> configData(configLen);
31806f6ba60Sopenharmony_ci    SetStreamConfig(configData, configLen);
31906f6ba60Sopenharmony_ci    EXPECT_EQ(streamCallbacks_->onPluginSessionStart(configData.data(), configLen), 0);
32006f6ba60Sopenharmony_ci
32106f6ba60Sopenharmony_ci    streamCallbacks_->onPluginSessionStop();
32206f6ba60Sopenharmony_ci}
32306f6ba60Sopenharmony_ci
32406f6ba60Sopenharmony_ci// 流式异常启动
32506f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, StreamPluginStartFail, TestSize.Level1)
32606f6ba60Sopenharmony_ci{
32706f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
32806f6ba60Sopenharmony_ci        StreamPluginSessionStart,
32906f6ba60Sopenharmony_ci        0,
33006f6ba60Sopenharmony_ci        StreamPluginSessionStop,
33106f6ba60Sopenharmony_ci        (RegisterWriterStructCallback)StreamRegisterWriterStruct,
33206f6ba60Sopenharmony_ci    };
33306f6ba60Sopenharmony_ci    streamCallbacks_ = &callbacks;
33406f6ba60Sopenharmony_ci
33506f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onRegisterWriterStruct, nullptr);
33606f6ba60Sopenharmony_ci    WriterStruct writer;
33706f6ba60Sopenharmony_ci    writer_ = &writer;
33806f6ba60Sopenharmony_ci    streamCallbacks_->onRegisterWriterStruct(writer_);
33906f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin, nullptr);
34006f6ba60Sopenharmony_ci
34106f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onPluginSessionStart, nullptr);
34206f6ba60Sopenharmony_ci    std::vector<uint8_t> configData(MAX_BUFFER_SIZE);
34306f6ba60Sopenharmony_ci    EXPECT_EQ(streamCallbacks_->onPluginSessionStart(configData.data(), configData.size()), -1);
34406f6ba60Sopenharmony_ci}
34506f6ba60Sopenharmony_ci
34606f6ba60Sopenharmony_ci// 轮询式异常启动
34706f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, SamplePluginStartFail, TestSize.Level1)
34806f6ba60Sopenharmony_ci{
34906f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
35006f6ba60Sopenharmony_ci        SamplePluginSessionStart,
35106f6ba60Sopenharmony_ci        SamplePluginReportResult,
35206f6ba60Sopenharmony_ci        SamplePluginSessionStop,
35306f6ba60Sopenharmony_ci        0,
35406f6ba60Sopenharmony_ci    };
35506f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
35606f6ba60Sopenharmony_ci
35706f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStart, nullptr);
35806f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStart(nullptr, 0), -1);
35906f6ba60Sopenharmony_ci    EXPECT_NE(samplePlugin, nullptr);
36006f6ba60Sopenharmony_ci}
36106f6ba60Sopenharmony_ci
36206f6ba60Sopenharmony_ci// 轮询式插件正常启动
36306f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, SamplePluginStartSucc, TestSize.Level1)
36406f6ba60Sopenharmony_ci{
36506f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
36606f6ba60Sopenharmony_ci        SamplePluginSessionStart,
36706f6ba60Sopenharmony_ci        SamplePluginReportResult,
36806f6ba60Sopenharmony_ci        SamplePluginSessionStop,
36906f6ba60Sopenharmony_ci        0,
37006f6ba60Sopenharmony_ci    };
37106f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
37206f6ba60Sopenharmony_ci
37306f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStart, nullptr);
37406f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
37506f6ba60Sopenharmony_ci    std::vector<uint8_t> configData(configLen); // config
37606f6ba60Sopenharmony_ci    SetSampleConfig(configData, configLen);
37706f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStart(configData.data(), configLen), 0);
37806f6ba60Sopenharmony_ci    EXPECT_NE(samplePlugin, nullptr);
37906f6ba60Sopenharmony_ci
38006f6ba60Sopenharmony_ci    sampleCallbacks_->onPluginSessionStop();
38106f6ba60Sopenharmony_ci}
38206f6ba60Sopenharmony_ci
38306f6ba60Sopenharmony_ci// 多个插件启动
38406f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, MultPluginStart, TestSize.Level1)
38506f6ba60Sopenharmony_ci{
38606f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
38706f6ba60Sopenharmony_ci        SamplePluginSessionStart,
38806f6ba60Sopenharmony_ci        SamplePluginReportResult,
38906f6ba60Sopenharmony_ci        SamplePluginSessionStop,
39006f6ba60Sopenharmony_ci        0,
39106f6ba60Sopenharmony_ci    };
39206f6ba60Sopenharmony_ci    PluginModuleCallbacks memCallbacks = {
39306f6ba60Sopenharmony_ci        MemDataPluginSessionStart,
39406f6ba60Sopenharmony_ci        MemPluginReportResult,
39506f6ba60Sopenharmony_ci        MemPluginSessionStop,
39606f6ba60Sopenharmony_ci        0,
39706f6ba60Sopenharmony_ci    };
39806f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
39906f6ba60Sopenharmony_ci    memoryCallbacks_ = &memCallbacks;
40006f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
40106f6ba60Sopenharmony_ci
40206f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStart, nullptr);
40306f6ba60Sopenharmony_ci    std::vector<uint8_t> sampleConfigData(configLen);
40406f6ba60Sopenharmony_ci    SetSampleConfig(sampleConfigData, configLen);
40506f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStart(sampleConfigData.data(), configLen), 0);
40606f6ba60Sopenharmony_ci    EXPECT_NE(samplePlugin, nullptr);
40706f6ba60Sopenharmony_ci    sampleCallbacks_->onPluginSessionStop();
40806f6ba60Sopenharmony_ci
40906f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginSessionStart, nullptr);
41006f6ba60Sopenharmony_ci    configLen = MAX_BUFFER_SIZE;
41106f6ba60Sopenharmony_ci    std::vector<uint8_t> memoryConfigData(configLen);
41206f6ba60Sopenharmony_ci    SetMemoryConfig(memoryConfigData, configLen);
41306f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onPluginSessionStart(memoryConfigData.data(), configLen), 0);
41406f6ba60Sopenharmony_ci    EXPECT_NE(memoryPlugin, nullptr);
41506f6ba60Sopenharmony_ci    memoryCallbacks_->onPluginSessionStop();
41606f6ba60Sopenharmony_ci}
41706f6ba60Sopenharmony_ci
41806f6ba60Sopenharmony_ci// 流式上报
41906f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, StreamPluginReport, TestSize.Level1)
42006f6ba60Sopenharmony_ci{
42106f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
42206f6ba60Sopenharmony_ci        StreamPluginSessionStart,
42306f6ba60Sopenharmony_ci        0,
42406f6ba60Sopenharmony_ci        StreamPluginSessionStop,
42506f6ba60Sopenharmony_ci        (RegisterWriterStructCallback)StreamRegisterWriterStruct,
42606f6ba60Sopenharmony_ci    };
42706f6ba60Sopenharmony_ci    streamCallbacks_ = &callbacks;
42806f6ba60Sopenharmony_ci
42906f6ba60Sopenharmony_ci    EXPECT_EQ(streamCallbacks_->onPluginReportResult, nullptr);
43006f6ba60Sopenharmony_ci}
43106f6ba60Sopenharmony_ci
43206f6ba60Sopenharmony_ci// 轮询式上报
43306f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, SamplePluginReport, TestSize.Level1)
43406f6ba60Sopenharmony_ci{
43506f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
43606f6ba60Sopenharmony_ci        SamplePluginSessionStart,
43706f6ba60Sopenharmony_ci        SamplePluginReportResult,
43806f6ba60Sopenharmony_ci        SamplePluginSessionStop,
43906f6ba60Sopenharmony_ci        0,
44006f6ba60Sopenharmony_ci    };
44106f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
44206f6ba60Sopenharmony_ci
44306f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStart, nullptr);
44406f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
44506f6ba60Sopenharmony_ci    std::vector<uint8_t> configData(configLen);
44606f6ba60Sopenharmony_ci    SetSampleConfig(configData, configLen);
44706f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStart(configData.data(), configLen), 0);
44806f6ba60Sopenharmony_ci    EXPECT_NE(samplePlugin, nullptr);
44906f6ba60Sopenharmony_ci
45006f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginReportResult, nullptr);
45106f6ba60Sopenharmony_ci    std::vector<uint8_t> buffer(MAX_BUFFER_SIZE);
45206f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginReportResult(buffer.data(), buffer.size()), 0);
45306f6ba60Sopenharmony_ci    sampleCallbacks_->onPluginSessionStop();
45406f6ba60Sopenharmony_ci}
45506f6ba60Sopenharmony_ci
45606f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, MemoryPluginReport, TestSize.Level1)
45706f6ba60Sopenharmony_ci{
45806f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
45906f6ba60Sopenharmony_ci        MemDataPluginSessionStart,
46006f6ba60Sopenharmony_ci        MemPluginReportResult,
46106f6ba60Sopenharmony_ci        MemPluginSessionStop,
46206f6ba60Sopenharmony_ci        0,
46306f6ba60Sopenharmony_ci    };
46406f6ba60Sopenharmony_ci    memoryCallbacks_ = &callbacks;
46506f6ba60Sopenharmony_ci
46606f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginSessionStart, nullptr);
46706f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
46806f6ba60Sopenharmony_ci    std::vector<uint8_t> configData(configLen);
46906f6ba60Sopenharmony_ci    SetMemoryConfig(configData, configLen);
47006f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onPluginSessionStart(configData.data(), configLen), 0);
47106f6ba60Sopenharmony_ci    EXPECT_NE(memoryPlugin, nullptr);
47206f6ba60Sopenharmony_ci
47306f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginReportResult, nullptr);
47406f6ba60Sopenharmony_ci    std::vector<uint8_t> buffer(MAX_BUFFER_SIZE);
47506f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginReportResult(buffer.data(), buffer.size()), 0);
47606f6ba60Sopenharmony_ci    memoryCallbacks_->onPluginSessionStop();
47706f6ba60Sopenharmony_ci}
47806f6ba60Sopenharmony_ci
47906f6ba60Sopenharmony_ci// 多个插件上报
48006f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, MultPluginReport1, TestSize.Level1)
48106f6ba60Sopenharmony_ci{
48206f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
48306f6ba60Sopenharmony_ci        SamplePluginSessionStart,
48406f6ba60Sopenharmony_ci        SamplePluginReportResult,
48506f6ba60Sopenharmony_ci        SamplePluginSessionStop,
48606f6ba60Sopenharmony_ci        0,
48706f6ba60Sopenharmony_ci    };
48806f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
48906f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
49006f6ba60Sopenharmony_ci
49106f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStart, nullptr);
49206f6ba60Sopenharmony_ci    std::vector<uint8_t> sampleConfigData(configLen);
49306f6ba60Sopenharmony_ci    SetSampleConfig(sampleConfigData, configLen);
49406f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStart(sampleConfigData.data(), configLen), 0);
49506f6ba60Sopenharmony_ci    EXPECT_NE(samplePlugin, nullptr);
49606f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginReportResult, nullptr);
49706f6ba60Sopenharmony_ci    std::vector<uint8_t> sampleBuffer(MAX_BUFFER_SIZE);
49806f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginReportResult(sampleBuffer.data(), sampleBuffer.size()), 0);
49906f6ba60Sopenharmony_ci
50006f6ba60Sopenharmony_ci    PluginModuleCallbacks memCallbacks = {
50106f6ba60Sopenharmony_ci        MemDataPluginSessionStart,
50206f6ba60Sopenharmony_ci        MemPluginReportResult,
50306f6ba60Sopenharmony_ci        MemPluginSessionStop,
50406f6ba60Sopenharmony_ci        0,
50506f6ba60Sopenharmony_ci    };
50606f6ba60Sopenharmony_ci    memoryCallbacks_ = &memCallbacks;
50706f6ba60Sopenharmony_ci
50806f6ba60Sopenharmony_ci    configLen = MAX_BUFFER_SIZE;
50906f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginSessionStart, nullptr);
51006f6ba60Sopenharmony_ci    std::vector<uint8_t> memoryConfigData(configLen);
51106f6ba60Sopenharmony_ci    SetMemoryConfig(memoryConfigData, configLen);
51206f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onPluginSessionStart(memoryConfigData.data(), configLen), 0);
51306f6ba60Sopenharmony_ci    EXPECT_NE(memoryPlugin, nullptr);
51406f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginReportResult, nullptr);
51506f6ba60Sopenharmony_ci    std::vector<uint8_t> memoryBuffer(MAX_BUFFER_SIZE);
51606f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginReportResult(memoryBuffer.data(), memoryBuffer.size()), 0);
51706f6ba60Sopenharmony_ci
51806f6ba60Sopenharmony_ci    sampleCallbacks_->onPluginSessionStop();
51906f6ba60Sopenharmony_ci    memoryCallbacks_->onPluginSessionStop();
52006f6ba60Sopenharmony_ci}
52106f6ba60Sopenharmony_ci
52206f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, MultPluginReport2, TestSize.Level1)
52306f6ba60Sopenharmony_ci{
52406f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
52506f6ba60Sopenharmony_ci        SamplePluginSessionStart,
52606f6ba60Sopenharmony_ci        SamplePluginReportResult,
52706f6ba60Sopenharmony_ci        SamplePluginSessionStop,
52806f6ba60Sopenharmony_ci        0,
52906f6ba60Sopenharmony_ci    };
53006f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
53106f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
53206f6ba60Sopenharmony_ci
53306f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStart, nullptr);
53406f6ba60Sopenharmony_ci    std::vector<uint8_t> sampleConfigData(configLen);
53506f6ba60Sopenharmony_ci    SetSampleConfig(sampleConfigData, configLen);
53606f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStart(sampleConfigData.data(), configLen), 0);
53706f6ba60Sopenharmony_ci    EXPECT_NE(samplePlugin, nullptr);
53806f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginReportResult, nullptr);
53906f6ba60Sopenharmony_ci    std::vector<uint8_t> sampleBuffer(MAX_BUFFER_SIZE);
54006f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginReportResult(sampleBuffer.data(), sampleBuffer.size()), 0);
54106f6ba60Sopenharmony_ci
54206f6ba60Sopenharmony_ci    PluginModuleCallbacks streamCallbacks = {
54306f6ba60Sopenharmony_ci        StreamPluginSessionStart,
54406f6ba60Sopenharmony_ci        0,
54506f6ba60Sopenharmony_ci        StreamPluginSessionStop,
54606f6ba60Sopenharmony_ci        (RegisterWriterStructCallback)StreamRegisterWriterStruct,
54706f6ba60Sopenharmony_ci    };
54806f6ba60Sopenharmony_ci    streamCallbacks_ = &streamCallbacks;
54906f6ba60Sopenharmony_ci
55006f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onRegisterWriterStruct, nullptr);
55106f6ba60Sopenharmony_ci    WriterStruct writer = {
55206f6ba60Sopenharmony_ci        Write,
55306f6ba60Sopenharmony_ci        Flush,
55406f6ba60Sopenharmony_ci    };
55506f6ba60Sopenharmony_ci    writer_ = &writer;
55606f6ba60Sopenharmony_ci    streamCallbacks_->onRegisterWriterStruct(writer_);
55706f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin, nullptr);
55806f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin->resultWriter_, nullptr);
55906f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin->resultWriter_->write, nullptr);
56006f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin->resultWriter_->flush, nullptr);
56106f6ba60Sopenharmony_ci
56206f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onPluginSessionStart, nullptr);
56306f6ba60Sopenharmony_ci    configLen = MAX_BUFFER_SIZE;
56406f6ba60Sopenharmony_ci    std::vector<uint8_t> configData(configLen);
56506f6ba60Sopenharmony_ci    SetStreamConfig(configData, configLen);
56606f6ba60Sopenharmony_ci    EXPECT_EQ(streamCallbacks_->onPluginSessionStart(configData.data(), configLen), 0);
56706f6ba60Sopenharmony_ci
56806f6ba60Sopenharmony_ci    sampleCallbacks_->onPluginSessionStop();
56906f6ba60Sopenharmony_ci    streamCallbacks_->onPluginSessionStop();
57006f6ba60Sopenharmony_ci}
57106f6ba60Sopenharmony_ci
57206f6ba60Sopenharmony_ci// 流式插件停止
57306f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, StreamPluginStop, TestSize.Level1)
57406f6ba60Sopenharmony_ci{
57506f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
57606f6ba60Sopenharmony_ci        StreamPluginSessionStart,
57706f6ba60Sopenharmony_ci        0,
57806f6ba60Sopenharmony_ci        StreamPluginSessionStop,
57906f6ba60Sopenharmony_ci        (RegisterWriterStructCallback)StreamRegisterWriterStruct,
58006f6ba60Sopenharmony_ci    };
58106f6ba60Sopenharmony_ci    streamCallbacks_ = &callbacks;
58206f6ba60Sopenharmony_ci
58306f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onRegisterWriterStruct, nullptr);
58406f6ba60Sopenharmony_ci    streamCallbacks_->onRegisterWriterStruct(writer_);
58506f6ba60Sopenharmony_ci    EXPECT_NE(streamPlugin, nullptr);
58606f6ba60Sopenharmony_ci
58706f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onPluginSessionStart, nullptr);
58806f6ba60Sopenharmony_ci    std::vector<uint8_t> configData(1);
58906f6ba60Sopenharmony_ci    streamCallbacks_->onPluginSessionStart(configData.data(), configData.size());
59006f6ba60Sopenharmony_ci
59106f6ba60Sopenharmony_ci    EXPECT_NE(streamCallbacks_->onPluginSessionStop, nullptr);
59206f6ba60Sopenharmony_ci    EXPECT_EQ(streamCallbacks_->onPluginSessionStop(), 0);
59306f6ba60Sopenharmony_ci}
59406f6ba60Sopenharmony_ci
59506f6ba60Sopenharmony_ci// 轮询式插件停止
59606f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, SamplePluginStop, TestSize.Level1)
59706f6ba60Sopenharmony_ci{
59806f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
59906f6ba60Sopenharmony_ci        SamplePluginSessionStart,
60006f6ba60Sopenharmony_ci        SamplePluginReportResult,
60106f6ba60Sopenharmony_ci        SamplePluginSessionStop,
60206f6ba60Sopenharmony_ci        0,
60306f6ba60Sopenharmony_ci    };
60406f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
60506f6ba60Sopenharmony_ci
60606f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStart, nullptr);
60706f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
60806f6ba60Sopenharmony_ci    std::vector<uint8_t> configData(configLen);
60906f6ba60Sopenharmony_ci    SetSampleConfig(configData, configLen);
61006f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStart(configData.data(), configLen), 0);
61106f6ba60Sopenharmony_ci    EXPECT_NE(samplePlugin, nullptr);
61206f6ba60Sopenharmony_ci
61306f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStop, nullptr);
61406f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStop(), 0);
61506f6ba60Sopenharmony_ci}
61606f6ba60Sopenharmony_ci
61706f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, MemoryPluginStop, TestSize.Level1)
61806f6ba60Sopenharmony_ci{
61906f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
62006f6ba60Sopenharmony_ci        MemDataPluginSessionStart,
62106f6ba60Sopenharmony_ci        MemPluginReportResult,
62206f6ba60Sopenharmony_ci        MemPluginSessionStop,
62306f6ba60Sopenharmony_ci        0,
62406f6ba60Sopenharmony_ci    };
62506f6ba60Sopenharmony_ci    memoryCallbacks_ = &callbacks;
62606f6ba60Sopenharmony_ci
62706f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginSessionStart, nullptr);
62806f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
62906f6ba60Sopenharmony_ci    std::vector<uint8_t> memoryConfigData(configLen);
63006f6ba60Sopenharmony_ci    SetMemoryConfig(memoryConfigData, configLen);
63106f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onPluginSessionStart(memoryConfigData.data(), configLen), 0);
63206f6ba60Sopenharmony_ci    EXPECT_NE(memoryPlugin, nullptr);
63306f6ba60Sopenharmony_ci
63406f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginSessionStop, nullptr);
63506f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onPluginSessionStop(), 0);
63606f6ba60Sopenharmony_ci}
63706f6ba60Sopenharmony_ci
63806f6ba60Sopenharmony_ci// 多个插件停止
63906f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, MultPluginStop, TestSize.Level1)
64006f6ba60Sopenharmony_ci{
64106f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
64206f6ba60Sopenharmony_ci        SamplePluginSessionStart,
64306f6ba60Sopenharmony_ci        SamplePluginReportResult,
64406f6ba60Sopenharmony_ci        SamplePluginSessionStop,
64506f6ba60Sopenharmony_ci        0,
64606f6ba60Sopenharmony_ci    };
64706f6ba60Sopenharmony_ci    PluginModuleCallbacks memCallbacks = {
64806f6ba60Sopenharmony_ci        MemDataPluginSessionStart,
64906f6ba60Sopenharmony_ci        MemPluginReportResult,
65006f6ba60Sopenharmony_ci        MemPluginSessionStop,
65106f6ba60Sopenharmony_ci        0,
65206f6ba60Sopenharmony_ci    };
65306f6ba60Sopenharmony_ci    sampleCallbacks_ = &callbacks;
65406f6ba60Sopenharmony_ci    memoryCallbacks_ = &memCallbacks;
65506f6ba60Sopenharmony_ci    uint32_t configLen = MAX_BUFFER_SIZE;
65606f6ba60Sopenharmony_ci
65706f6ba60Sopenharmony_ci    EXPECT_NE(sampleCallbacks_->onPluginSessionStart, nullptr);
65806f6ba60Sopenharmony_ci    std::vector<uint8_t> sampleConfigData(configLen);
65906f6ba60Sopenharmony_ci    SetSampleConfig(sampleConfigData, configLen);
66006f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStart(sampleConfigData.data(), configLen), 0);
66106f6ba60Sopenharmony_ci    EXPECT_NE(samplePlugin, nullptr);
66206f6ba60Sopenharmony_ci
66306f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginSessionStart, nullptr);
66406f6ba60Sopenharmony_ci    configLen = MAX_BUFFER_SIZE;
66506f6ba60Sopenharmony_ci    std::vector<uint8_t> memoryConfigData(configLen);
66606f6ba60Sopenharmony_ci    SetMemoryConfig(memoryConfigData, configLen);
66706f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onPluginSessionStart(memoryConfigData.data(), configLen), 0);
66806f6ba60Sopenharmony_ci    EXPECT_NE(memoryPlugin, nullptr);
66906f6ba60Sopenharmony_ci
67006f6ba60Sopenharmony_ci    EXPECT_EQ(sampleCallbacks_->onPluginSessionStop(), 0);
67106f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onPluginSessionStop(), 0);
67206f6ba60Sopenharmony_ci}
67306f6ba60Sopenharmony_ci
67406f6ba60Sopenharmony_ci// 异常停止
67506f6ba60Sopenharmony_ciHWTEST_F(PluginModuleApiTest, PluginAbnormalStop, TestSize.Level1)
67606f6ba60Sopenharmony_ci{
67706f6ba60Sopenharmony_ci    PluginModuleCallbacks callbacks = {
67806f6ba60Sopenharmony_ci        MemDataPluginSessionStart,
67906f6ba60Sopenharmony_ci        MemPluginReportResult,
68006f6ba60Sopenharmony_ci        MemPluginSessionStop,
68106f6ba60Sopenharmony_ci        0,
68206f6ba60Sopenharmony_ci    };
68306f6ba60Sopenharmony_ci    memoryCallbacks_ = &callbacks;
68406f6ba60Sopenharmony_ci
68506f6ba60Sopenharmony_ci    EXPECT_NE(memoryCallbacks_->onPluginSessionStop, nullptr);
68606f6ba60Sopenharmony_ci    EXPECT_EQ(memoryCallbacks_->onPluginSessionStop(), -1);
68706f6ba60Sopenharmony_ci}
68806f6ba60Sopenharmony_ci} // namespace