• 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 "wasm_func.cpp"
21 
22 using namespace testing::ext;
23 namespace SysTuning {
24 namespace TraceStreamer {
25 class WasmFuncTest : 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 constexpr int32_t MAX_TESET_BUF_SIZE = 1024;
37 
38 /**
39  * @tc.name: CorrectTraceData
40  * @tc.desc: Upload correct trace file data
41  * @tc.type: FUNC
42  */
43 HWTEST_F(WasmFuncTest, CorrectTraceData, TestSize.Level1)
44 {
45     TS_LOGI("test32-1");
46     std::string parseData("sugov:0-178   (  178) [001] .... 28462.257501: cpu_frequency: state=816000 cpu_id=0 \n");
47     std::string sqlQuery("select * from measure;");
48 
49     char out[MAX_TESET_BUF_SIZE] = {0};
50 
51     int32_t ret = TraceStreamerParseData((const uint8_t*)parseData.c_str(), parseData.length());
52     EXPECT_EQ(0, ret);
53     ret = TraceStreamerParseDataOver();
54     EXPECT_EQ(0, ret);
55     ret = TraceStreamerSqlQuery((const uint8_t*)sqlQuery.c_str(), sqlQuery.length(), (uint8_t*)out, MAX_TESET_BUF_SIZE);
56     TS_LOGI("sql value:%s", out);
57     EXPECT_NE(-1, ret);
58     ret = TraceStreamerReset();
59     EXPECT_EQ(0, ret);
60 }
61 
62 /**
63  * @tc.name: WrongTraceData
64  * @tc.desc: Upload wrong tracking file data
65  * @tc.type: FUNC
66  */
67 HWTEST_F(WasmFuncTest, WrongTraceData, TestSize.Level1)
68 {
69     TS_LOGI("test32-2");
70     std::string parseData("sugov:0-178   (  178) [001] .... 28462.277458: cpu_frequency: state=600000 cpu_id=2 \n");
71     std::string sqlQuery("select * from measure_a;");
72 
73     char out[MAX_TESET_BUF_SIZE] = {0};
74 
75     int32_t ret = TraceStreamerParseData((const uint8_t*)parseData.c_str(), parseData.length());
76     EXPECT_EQ(0, ret);
77     ret = TraceStreamerParseDataOver();
78     EXPECT_EQ(0, ret);
79     ret = TraceStreamerSqlQuery((const uint8_t*)sqlQuery.c_str(), sqlQuery.length(), (uint8_t*)out, MAX_TESET_BUF_SIZE);
80     TS_LOGI("sql value:%s", out);
81     EXPECT_EQ(-1, ret);
82     ret = TraceStreamerReset();
83     EXPECT_EQ(0, ret);
84 }
85 } // namespace TraceStreamer
86 } // namespace SysTuning