• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "hiperf_client.h"
16 #include "subcommand_record_test.h"
17 #include "perf_pipe_test.h"
18 
19 #include <gtest/gtest.h>
20 #include <hilog/log.h>
21 
22 using namespace testing::ext;
23 using namespace std::chrono;
24 namespace OHOS {
25 namespace Developtools {
26 namespace HiPerf {
27 const std::chrono::milliseconds CONTROL_WAITREPY_TIMEOUT = 2000ms;
28 class PerfPipeTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase()36 void PerfPipeTest::SetUpTestCase() {}
37 
TearDownTestCase()38 void PerfPipeTest::TearDownTestCase() {}
39 
SetUp()40 void PerfPipeTest::SetUp() {}
41 
TearDown()42 void PerfPipeTest::TearDown() {}
43 
44 /**
45  * @tc.name: CreateFifoFile
46  * @tc.desc:
47  * @tc.type: FUNC
48  */
49 HWTEST_F(PerfPipeTest, CreateRecordFifoFile, TestSize.Level0)
50 {
51     PerfPipe perfPipe;
52     std::string controlCmd = "prepare";
53     std::string fifoFileC2S;
54     std::string fifoFileS2C;
55     perfPipe.SetFifoFileName(CommandType::RECORD, controlCmd, fifoFileC2S, fifoFileS2C);
56     EXPECT_EQ(perfPipe.CreateFifoFile(), true);
57     EXPECT_EQ(perfPipe.CreateFifoFile(), false);
58     EXPECT_EQ(remove(fifoFileC2S.c_str()), 0);
59     EXPECT_EQ(remove(fifoFileS2C.c_str()), 0);
60 }
61 
62 /**
63  * @tc.name: SendFifoAndWaitReply
64  * @tc.desc: Test send Fifo and wait reply
65  * @tc.type: FUNC
66  */
67 HWTEST_F(PerfPipeTest, SendFifoAndWaitReply, TestSize.Level1)
68 {
69     PerfPipe perfPipe;
70     std::string controlCmd = "prepare";
71     std::string fifoFileC2S;
72     std::string fifoFileS2C;
73     perfPipe.SetFifoFileName(CommandType::RECORD, controlCmd, fifoFileC2S, fifoFileS2C);
74     EXPECT_EQ(perfPipe.SendFifoAndWaitReply(HiperfClient::ReplyStart, CONTROL_WAITREPY_TIMEOUT), false);
75 }
76 
77 /**
78  * @tc.name: ProcessControlCmd
79  * @tc.desc: Test send Fifo and wait reply
80  * @tc.type: FUNC
81  */
82 HWTEST_F(PerfPipeTest, ProcessControlCmd, TestSize.Level1)
83 {
84     PerfPipe perfPipe;
85     std::string controlCmd = "prepare";
86     std::string fifoFileC2S;
87     std::string fifoFileS2C;
88     perfPipe.SetFifoFileName(CommandType::RECORD, controlCmd, fifoFileC2S, fifoFileS2C);
89     EXPECT_EQ(perfPipe.ProcessControlCmd(), false);
90 }
91 } // namespace HiPerf
92 } // namespace Developtools
93 } // namespace OHOS
94