xref: /test/ostest/wukong/report/include/report.h (revision a69a01cd)
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_REPORT_H
17#define TEST_WUKONG_REPORT_H
18
19#include <map>
20#include <memory>
21#include <string>
22#include <vector>
23#include <mutex>
24
25#include "data_set.h"
26#include "input_msg_object.h"
27#include "singleton.h"
28#include "sysevent_listener.h"
29#include "wukong_define.h"
30
31namespace OHOS {
32namespace WuKong {
33namespace {
34struct componmentRecord {
35    std::map<std::string, uint32_t> componmentTypeCount;
36    std::map<uint32_t, std::vector<std::string>> pageIdComponments;
37};
38}  // namespace
39class Report final : public DelayedSingleton<Report> {
40    DECLARE_DELAYED_SINGLETON(Report)
41    friend class SysEventListener;
42
43public:
44    void Finish();
45    void SetSeed(std::string seed);
46    /*
47     * @brief  Synchronous inputted information
48     * @return void
49     */
50    void SyncInputInfo(std::shared_ptr<InputedMsgObject> inputedMsgObject);
51    /*
52     * @brief  deal data under different mode
53     * @return void
54     */
55    void SplitInputMode(std::shared_ptr<InputedMsgObject> &inputedMsgObject, std::map<std::string, std::string> &data);
56    /*
57     * @brief  group data, record them to temp container
58     * @return void
59     */
60    void GroupFocusDataAndRecord(std::shared_ptr<InputedMsgObject> &inputedMsgObject, std::map<std::string,
61        std::string> &data);
62
63    /*
64     * @brief Write the content of the test process segmented to the storage csvfile
65     * @return void
66     */
67    void SegmentedWriteCSV();
68
69    /*
70     * @brief Write the content of the test process segmented to the storage jsonfile
71     * @return void
72     */
73    void SegmentedWriteJson();
74
75    /*
76     * @brief recor screen path to report
77     * @return void
78     */
79    void RecordScreenPath(const std::string &screenPath);
80
81    /*
82     * @brief Write the content of the focus input segmented to the storage file
83     * @return void
84     */
85    void SegmentedWriteForFocusInput();
86
87    /*
88    * @brief get report exception dir
89    * @return void
90    */
91    std::string GetReportExceptionDir();
92
93    /*
94     * @brief find Exception Type by crash file name
95     * @param exceptionFilename
96     * @return void
97     */
98    void ExceptionRecord(const std::string &exceptionFilename);
99
100    void SetIsFocusTest(bool isFocus)
101    {
102        is_focus_ = isFocus;
103    }
104private:
105    /*
106     * @brief dependent environment init, include create file,dir, setting start time
107     * @return void
108     */
109    void EnvInit();
110
111    /*
112     * @brief dataSet init, include  event input, componment input, ability, exception
113     * @return void
114     */
115    void DataSetInit();
116
117    /*
118     * @brief When a crash occurs check /data/log/hilog/ dir is exist new hilog file then copy
119     * @return void
120     */
121    void HilogFileRecord();
122
123    /*
124     * @brief componment information arrange
125     * @param bundle bundle name
126     * @param inputCompMsgPtr input componment msg ptr
127     * @param data out data
128     * @return void
129     */
130    void ComponmentInfoArrange(const std::string &bundle, std::shared_ptr<ComponmentInputMsg> inputCompMsgPtr,
131                               std::map<std::string, std::string> &data);
132    // csv filename
133    std::string reportCsvFileName_ = "";
134    std::string reportJsonFileName_ = "";
135    std::string reportFocusInputFileName_ = "";
136    std::string reportExceptionDir_ = "";
137    std::string currentTestDir_ = "";
138    std::string startRunTime_ = "";
139    std::string crashDir_ = "/data/log/faultlog/faultlogger/";
140    std::vector<std::string> hilogFiles_;
141    std::string seed_ = "";
142    int taskCount_ = 0;
143    bool isFirstAppSwitch_ = false;
144    time_t startTime_ = time(0);
145    std::mutex crashMtx_;
146    std::string hilogDirs_ = "/data/log/hilog/";
147    // multimodal input data set
148    std::shared_ptr<DataSet> eventDataSet_ = std::make_shared<DataSet>();
149    // componment input data set
150    std::shared_ptr<DataSet> componmentDataSet_ = std::make_shared<DataSet>();
151    // ability data set
152    std::shared_ptr<DataSet> abilityDataSet_ = std::make_shared<DataSet>();
153    // exception data set
154    std::shared_ptr<DataSet> exceptionDataSet_ = std::make_shared<DataSet>();
155    // app set
156    std::vector<std::string> bundles_;
157    std::map<std::string, componmentRecord> bundleComponmentRecord_;
158
159    // screen store path vector
160    std::vector<std::string> screenPaths_;
161    // focus_input output container
162    std::vector<std::string> focus_input_vec_;
163    // identify cur test is focus test
164    bool is_focus_ = false;
165};
166}  // namespace WuKong
167}  // namespace OHOS
168
169#endif
170