• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include <hwext/gtest-ext.h>
17 #include <hwext/gtest-tag.h>
18 
19 #include "rpc/rpc_server.h"
20 #include "print_event_parser.h"
21 
22 using namespace testing::ext;
23 namespace SysTuning {
24 namespace TraceStreamer {
25 class RpcServerTest : public ::testing::Test {
26 public:
SetUp()27     void SetUp()
28     {
29         stream_.InitFilter();
30     }
TearDown()31     void TearDown() {}
32 
33 public:
34     TraceStreamerSelector stream_ = {};
35 };
36 std::string g_result;
res(const std::string result,int32_t finish)37 void res(const std::string result, int32_t finish)
38 {
39     TS_LOGI("%s", result.c_str());
40     g_result = result;
41 }
42 
43 /**
44  * @tc.name: CorrectTraceData
45  * @tc.desc: Upload correct trace file data
46  * @tc.type: FUNC
47  */
48 HWTEST_F(RpcServerTest, CorrectTraceData, TestSize.Level1)
49 {
50     TS_LOGI("test27-1");
51     std::string PARSERDATA("sugov:0-178   (  178) [001] .... 28462.257501: cpu_frequency: state=816000 cpu_id=0 \n");
52     std::string SQLQUERY("select * from measure;");
53 
54     RpcServer rpcServer;
55     auto ret = rpcServer.ParseData((const uint8_t*)PARSERDATA.c_str(), PARSERDATA.length(), res);
56     EXPECT_TRUE(res);
57     EXPECT_TRUE(ret);
58     ret = rpcServer.ParseDataOver((const uint8_t*)PARSERDATA.c_str(), PARSERDATA.length(), res);
59     EXPECT_TRUE(res);
60     EXPECT_TRUE(ret);
61     ret = rpcServer.SqlQuery((const uint8_t*)SQLQUERY.c_str(), SQLQUERY.length(), res);
62     EXPECT_TRUE(res);
63     EXPECT_TRUE(ret);
64 }
65 
66 /**
67  * @tc.name: WrongTraceData
68  * @tc.desc: Upload wrong tracking file data
69  * @tc.type: FUNC
70  */
71 HWTEST_F(RpcServerTest, WrongTraceData, TestSize.Level1)
72 {
73     TS_LOGI("test27-2");
74     std::string PARSERDATA("sugov:0-178   (  178) [001] .... 28462.277458: cpu_frequency: state=600000 cpu_id=2 \n");
75     std::string SQLQUERY("select * from measure_e;");
76 
77     RpcServer rpcServer;
78     auto ret = rpcServer.ParseData((const uint8_t*)PARSERDATA.c_str(), PARSERDATA.length(), res);
79     EXPECT_TRUE(res);
80     EXPECT_TRUE(ret);
81     ret = rpcServer.ParseDataOver((const uint8_t*)PARSERDATA.c_str(), PARSERDATA.length(), res);
82     EXPECT_TRUE(res);
83     EXPECT_TRUE(ret);
84     ret = rpcServer.SqlQuery((const uint8_t*)SQLQUERY.c_str(), SQLQUERY.length(), res);
85     EXPECT_TRUE(g_result == "dberror\r\n");
86     EXPECT_FALSE(ret);
87 }
88 
89 /**
90  * @tc.name: ParserConfig
91  * @tc.desc: Test the ParserConfig method
92  * @tc.type: FUNC
93  */
94 HWTEST_F(RpcServerTest, ParserConfig, TestSize.Level1)
95 {
96     TS_LOGI("test27-3");
97     std::string comm("e.myapplication");
98     uint64_t ts = 89227707307481;
99     uint32_t pid = 16502;
100     std::string event("B|16502|H:Task Allocation: taskId : 1, executeId : 9, priority : 9, executeState : 1");
101     BytraceLine line;
102     std::string json("{\"config\": {\"TaskPool\": 1,\"AnimationAnalysis\": 0,\"AppStartup\": 0}}");
103 
104     RpcServer rpcServer;
105     auto ret = rpcServer.ParserConfig(json);
106     EXPECT_EQ(rpcServer.ts_->traceDataCache_->taskPoolTraceEnabled_, true);
107     PrintEventParser printEvent(rpcServer.ts_->traceDataCache_.get(), rpcServer.ts_->streamFilters_.get());
108     printEvent.ParsePrintEvent(comm, ts, pid, event, line);
109     auto res = rpcServer.ts_->traceDataCache_->GetConstTaskPoolData().prioritys_[0];
110     EXPECT_EQ(res, 9);
111 }
112 } // namespace TraceStreamer
113 } // namespace SysTuning
114