• 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 #include <exception>
16 #include <iostream>
17 #include <string>
18 #include <thread>
19 #include <gtest/gtest.h>
20 #include <unistd.h>
21 #include <cstring>
22 #include <cstdint>
23 #include <cstdio>
24 #include <functional>
25 #include "sp_utils.h"
26 #include "sp_log.h"
27 #include "sp_task.h"
28 #include "parameters.h"
29 #include "GPU.h"
30 using namespace testing::ext;
31 using namespace std;
32 
33 namespace OHOS {
34 namespace SmartPerf {
35 class SPdaemonTaskTest : public testing::Test {
36 public:
SetUpTestCase()37     static void SetUpTestCase() {}
TearDownTestCase()38     static void TearDownTestCase() {}
SetUp()39     void SetUp() {}
TearDown()40     void TearDown() {}
41 };
42 
43 /**
44  * @tc.name: CheckTcpParamTestCase
45  * @tc.desc: Test CheckTcpParam
46  * @tc.type: FUNC
47  */
48 HWTEST_F(SPdaemonTaskTest, CheckTcpParamTestCase001, TestSize.Level1)
49 {
50     std::string str = "-SESSIONID 12345678 -INTERVAL 1000 -PKG ohos.samples.ecg -c -g -t -p -f -r -o";
51     std::string errorInfo = "";
52     SPTask &spTask = SPTask::GetInstance();
53     bool flag = spTask.CheckTcpParam(str, errorInfo);
54     EXPECT_TRUE(flag);
55 }
56 
57 HWTEST_F(SPdaemonTaskTest, CheckTcpParamTestCase002, TestSize.Level1)
58 {
59     std::string str = "";
60     std::string errorInfo = "";
61     SPTask &spTask = SPTask::GetInstance();
62     bool flag = spTask.CheckTcpParam(str, errorInfo);
63     EXPECT_FALSE(flag);
64 }
65 
66 HWTEST_F(SPdaemonTaskTest, CheckTcpParamTestCase003, TestSize.Level1)
67 {
68     std::string str = "";
69     std::string errorInfo = "";
70     SPTask &spTask = SPTask::GetInstance();
71     bool flag = spTask.CheckTcpParam(str, errorInfo);
72     EXPECT_FALSE(flag);
73 }
74 
75 /**
76  * @tc.name: SPTask::DetectionAndGrab
77  * @tc.desc: Test DetectionAndGrab
78  * @tc.type: FUNC
79  */
80 HWTEST_F(SPdaemonTaskTest, DetectionAndGrabTestCase001, TestSize.Level1)
81 {
82     bool ret = false;
83     std::map<std::string, std::string> templateMap;
84     std::string recvStr = "-SESSIONID 12345678 -INTERVAL 1000 -PKG ohos.samples.ecg -c -g -t -p -f -r -o";
85     SPTask::GetInstance().InitTask(recvStr);
86     templateMap = SPTask::GetInstance().DetectionAndGrab();
87 
88     if (templateMap.empty()) {
89         ret = true;
90     }
91 
92     EXPECT_TRUE(ret);
93 }
94 
95 /**
96  * @tc.name: GpuRkTestCase
97  * @tc.desc: Gpu rkflag is true
98  * @tc.type: FUNC
99  */
100 HWTEST_F(SPdaemonTaskTest, GpuRkTestCase, TestSize.Level1)
101 {
102     std::string str = "";
103     std::string errorInfo = "";
104     GPU &gpu = GPU::GetInstance();
105     gpu.SetRkFlag();
106     std::map<std::string, std::string> result = gpu.ItemData();
107     EXPECT_NE(result.size(), 0);
108 }
109 }
110 }