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