• 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 
21 using namespace testing::ext;
22 namespace SysTuning {
23 namespace TraceStreamer {
24 class RpcServerTest : public ::testing::Test {
25 public:
SetUp()26     void SetUp()
27     {
28         stream_.InitFilter();
29     }
TearDown()30     void TearDown() {}
31 public:
32     TraceStreamerSelector stream_ = {};
33 };
34 std::string g_result;
res(const std::string result,int finish)35 void res(const std::string result, int finish)
36 {
37     TS_LOGI("%s", result.c_str());
38     g_result = result;
39 }
40 
41 /**
42  * @tc.name: CorrectTraceData
43  * @tc.desc: Upload correct trace file data
44  * @tc.type: FUNC
45  */
46 HWTEST_F(RpcServerTest, CorrectTraceData, TestSize.Level1)
47 {
48     TS_LOGI("test27-1");
49     std::string PARSERDATA("sugov:0-178   (  178) [001] .... 28462.257501: cpu_frequency: state=816000 cpu_id=0 \n");
50     std::string SQLQUERY("select * from measure;");
51 
52     RpcServer rpcServer;
53     auto ret = rpcServer.ParseData((const uint8_t*)PARSERDATA.c_str(), PARSERDATA.length(), res);
54     EXPECT_TRUE(res);
55     EXPECT_TRUE(ret);
56     ret = rpcServer.ParseDataOver((const uint8_t*)PARSERDATA.c_str(), PARSERDATA.length(), res);
57     EXPECT_TRUE(res);
58     EXPECT_TRUE(ret);
59     ret = rpcServer.SqlQuery((const uint8_t*)SQLQUERY.c_str(), SQLQUERY.length(), res);
60     EXPECT_TRUE(res);
61     EXPECT_TRUE(ret);
62 }
63 
64 /**
65  * @tc.name: WrongTraceData
66  * @tc.desc: Upload wrong tracking file data
67  * @tc.type: FUNC
68  */
69 HWTEST_F(RpcServerTest, WrongTraceData, TestSize.Level1)
70 {
71     TS_LOGI("test27-2");
72     std::string PARSERDATA("sugov:0-178   (  178) [001] .... 28462.277458: cpu_frequency: state=600000 cpu_id=2 \n");
73     std::string SQLQUERY("select * from measure_e;");
74 
75     RpcServer rpcServer;
76     auto ret = rpcServer.ParseData((const uint8_t*)PARSERDATA.c_str(), PARSERDATA.length(), res);
77     EXPECT_TRUE(res);
78     EXPECT_TRUE(ret);
79     ret = rpcServer.ParseDataOver((const uint8_t*)PARSERDATA.c_str(), PARSERDATA.length(), res);
80     EXPECT_TRUE(res);
81     EXPECT_TRUE(ret);
82     ret = rpcServer.SqlQuery((const uint8_t*)SQLQUERY.c_str(), SQLQUERY.length(), res);
83     EXPECT_TRUE(g_result == "dberror\r\n");
84     EXPECT_FALSE(ret);
85 }
86 } // namespace TraceStreamer
87 } // namespace SysTuning
88