• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 TEST_WUKONG_RANDOM_TEST_H
17 #define TEST_WUKONG_RANDOM_TEST_H
18 
19 #include <string>
20 
21 #include "input_factory.h"
22 #include "test_flow.h"
23 
24 namespace OHOS {
25 namespace WuKong {
26 class RandomTestFlow : public TestFlow {
27 public:
28     RandomTestFlow(WuKongShellCommand &shellcommand);
29     virtual ~RandomTestFlow();
30 
31     /**
32      * @brief to confirm the input of event percent is valid or not
33      * and distribute the event count randomly according to possibility.
34      * @return Return ERR_OK on success, others on failure.
35      */
36     virtual ErrCode EnvInit() override;
37 
38     /**
39      * @brief run the test according to shellCommand, output seed value, exec
40      * count and interval value.
41      * @return Return ERR_OK on success, others on failure.
42      */
43     virtual ErrCode RunStep() override;
44 
45 private:
46     virtual const struct option* GetOptionArguments(std::string &shortOpts) override;
47     ErrCode HandleUnknownOption(const char optopt) override;
48     ErrCode HandleNormalOption(const int option) override;
49 
50     /**
51      * @brief check if the '-c' and 'T' is exist at the same time
52      * @param option command letter.
53      * @return Return ERR_OK on success, others on failure.
54      */
55     ErrCode CheckArgument(const int option);
56 
57     /**
58      * @brief init event list percent.
59      * @return return ERR_OK on success, others on failure.
60      */
61     ErrCode InitEventPercent();
62     /**
63      * @brief shuffle the elements in event list
64      */
65     void RandomShuffle();
66 
67     /**
68      * @brief registered timer to monitor test time
69      */
70     void RegisterTimer();
71 
72     /**
73      * @brief the callback function of the timer
74      */
75     void TestTimeout();
76 
77     /**
78      * @brief set number of input type
79      * @param option the param of test
80      */
81     ErrCode SetInputPercent(const int option);
82 
83     ErrCode InputScene(std::shared_ptr<InputAction> inputaction, bool inputFlag);
84 
85     bool SetBlockPage();
86 
87     int countArgs_ = 10;
88 
89     // the interval time of test
90     int intervalArgs_ = 1500;
91 
92     // the seed value of test
93     int seedArgs_ = -1;
94 
95     // the total count of test
96     int totalCount_ = 10;
97 
98     // the total time of test
99     float totalTime_ = 10.0;
100 
101     std::shared_ptr<Utils::Timer> timer_ = nullptr;
102     uint32_t timerId_ = 0;
103     std::vector<int> inputPercent_;
104     std::vector<int> eventList_;
105 };
106 }  // namespace WuKong
107 }  // namespace OHOS
108 #endif  // TEST_WUKONG_RANDOM_TEST_H
109