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 #ifndef OHOS_DBINDER_SERVICE_TEST_HELPER_INCLUDE_H
17 #define OHOS_DBINDER_SERVICE_TEST_HELPER_INCLUDE_H
18 
19 #include <sys/types.h>
20 #include <dirent.h>
21 #include <iostream>
22 #include <string>
23 
24 const std::string DBINDER_TEST_SERVICE_NAME = "dbinder_test";
25 const std::string DBINDER_TEST_SERVICE_NAME_SECOND = "dbinder_send";
26 const std::string SYSTEM_ABILITY_MANAGER_NAME = "SaManager";
27 
28 const int BUF_SIZE = 1024 * 4;
29 const int PATH_LENGTH = 1024 * 4;
30 const static int INVALID_PID = -1;
31 const static int SECOND_TO_MS = 1000;
32 const static int KB_TO_B = 1024;
33 
34 enum {
35     /*
36      * Here's the list of DBinderService Test Case List.
37      * This list should be used for Trans-Mock.
38      */
39     DBINDER_TEST_INIT = -1,
40     DBINDER_TEST_START = 0,
41     DBINDER_TEST_REGISTRY_001,
42     DBINDER_TEST_REGISTRY_002,
43     DBINDER_TEST_REGISTRY_003,
44     DBINDER_TEST_REGISTRY_004,
45     DBINDER_TEST_REMOTE_CALL_001,
46     DBINDER_TEST_REMOTE_CALL_002,
47     DBINDER_TEST_REMOTE_CALL_003,
48     DBINDER_TEST_REMOTE_CALL_004,
49     DBINDER_TEST_REMOTE_CALL_005,
50     DBINDER_TEST_REMOTE_CALL_006,
51     DBINDER_TEST_REMOTE_CALL_007,
52     DBINDER_TEST_REMOTE_CALL_008,
53     DBINDER_TEST_REMOTE_CALL_009,
54     DBINDER_TEST_REMOTE_CALL_010,
55     DBINDER_TEST_REMOTE_CALL_011,
56     DBINDER_TEST_REMOTE_CALL_012,
57     DBINDER_TEST_REMOTE_CALL_013,
58     DBINDER_TEST_REMOTE_CALL_014,
59     DBINDER_TEST_REMOTE_CALL_015,
60     DBINDER_TEST_REMOTE_CALL_016,
61     DBINDER_TEST_DEATH_RECIPIENT_001,
62     DBINDER_TEST_DEATH_RECIPIENT_002,
63     DBINDER_TEST_DEATH_RECIPIENT_003,
64     DBINDER_TEST_DEATH_RECIPIENT_004,
65     DBINDER_TEST_DEATH_RECIPIENT_005,
66     DBINDER_TEST_DEATH_RECIPIENT_006,
67     DBINDER_TEST_DEATH_RECIPIENT_007,
68     DBINDER_TEST_RAW_DATA_001,
69     DBINDER_TEST_RAW_DATA_002,
70     DBINDER_TEST_RAW_DATA_003,
71     DBINDER_TEST_RAW_DATA_004,
72     DBINDER_TEST_RAW_DATA_005,
73     DBINDER_TEST_RAW_DATA_006,
74     DBINDER_TEST_TRACE_001,
75     DBINDER_TEST_TRANS_STUB_001,
76     DBINDER_TEST_FLUSH_COMMAND_001,
77     DBINDER_TEST_END,
78 };
79 
80 static int g_currentTestCase = DBINDER_TEST_INIT;
81 
82 pid_t GetPidByName(std::string taskName);
83 int StartDBinderServiceSARegistry(void);
84 void StopDBinderServiceSARegistry(void);
85 void StartDBinderServiceTestService(void);
86 void StopDBinderServiceTestService(void);
87 int GetChildPids(std::vector<pid_t> &childPids);
88 pid_t StartExecutable(std::string name, std::string args = "");
89 void StopExecutable(pid_t pid);
90 void StopExecutable(std::string name);
91 int SetCurrentTestCase(int caseNum);
92 int GetCurrentTestCase(void);
93 int64_t GetCurrentTime(void);
94 float GetSpeed(int64_t timeInterval, int size, int times);
95 
96 bool MakeIpLoop(void);
97 bool RevertIpLoop(void);
98 
99 #endif // OHOS_DBINDER_SERVICE_TEST_HELPER_INCLUDE_H
100