1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 */
HWTEST_F(WasmFuncTest, CorrectTraceData, TestSize.Level1)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 =
56 TraceStreamerSqlQuery((const uint8_t *)sqlQuery.c_str(), sqlQuery.length(), (uint8_t *)out, MAX_TESET_BUF_SIZE);
57 TS_LOGI("sql value:%s", out);
58 EXPECT_NE(-1, ret);
59 ret = TraceStreamerReset();
60 EXPECT_EQ(0, ret);
61 }
62
63 /**
64 * @tc.name: WrongTraceData
65 * @tc.desc: Upload wrong tracking file data
66 * @tc.type: FUNC
67 */
HWTEST_F(WasmFuncTest, WrongTraceData, TestSize.Level1)68 HWTEST_F(WasmFuncTest, WrongTraceData, TestSize.Level1)
69 {
70 TS_LOGI("test32-2");
71 std::string parseData("sugov:0-178 ( 178) [001] .... 28462.277458: cpu_frequency: state=600000 cpu_id=2 \n");
72 std::string sqlQuery("select * from measure_a;");
73
74 char out[MAX_TESET_BUF_SIZE] = {0};
75
76 int32_t ret = TraceStreamerParseData((const uint8_t *)parseData.c_str(), parseData.length());
77 EXPECT_EQ(0, ret);
78 ret = TraceStreamerParseDataOver();
79 EXPECT_EQ(0, ret);
80 ret =
81 TraceStreamerSqlQuery((const uint8_t *)sqlQuery.c_str(), sqlQuery.length(), (uint8_t *)out, MAX_TESET_BUF_SIZE);
82 TS_LOGI("sql value:%s", out);
83 EXPECT_EQ(-1, ret);
84 ret = TraceStreamerReset();
85 EXPECT_EQ(0, ret);
86 }
87 } // namespace TraceStreamer
88 } // namespace SysTuning