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 31 namespace OHOS { 32 namespace WuKong { 33 namespace { 34 struct componmentRecord { 35 std::map<std::string, uint32_t> componmentTypeCount; 36 std::map<uint32_t, std::vector<std::string>> pageIdComponments; 37 }; 38 } // namespace 39 class Report final : public DelayedSingleton<Report> { 40 DECLARE_DELAYED_SINGLETON(Report) 41 friend class SysEventListener; 42 43 public: 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 Write the content of the test process segmented to the storage csvfile 53 * @return void 54 */ 55 void SegmentedWriteCSV(); 56 57 /* 58 * @brief Write the content of the test process segmented to the storage jsonfile 59 * @return void 60 */ 61 void SegmentedWriteJson(); 62 63 /* 64 * @brief recor screen path to report 65 * @return void 66 */ 67 void RecordScreenPath(const std::string &screenPath); 68 69 /* 70 * @brief get report exception dir 71 * @return void 72 */ 73 std::string GetReportExceptionDir(); 74 75 /* 76 * @brief find Exception Type by crash file name 77 * @param exceptionFilename 78 * @return void 79 */ 80 void ExceptionRecord(const std::string &exceptionFilename); 81 private: 82 /* 83 * @brief dependent environment init, include create file,dir, setting start time 84 * @return void 85 */ 86 void EnvInit(); 87 88 /* 89 * @brief dataSet init, include event input, componment input, ability, exception 90 * @return void 91 */ 92 void DataSetInit(); 93 94 /* 95 * @brief When a crash occurs check /data/log/hilog/ dir is exist new hilog file then copy 96 * @return void 97 */ 98 void HilogFileRecord(); 99 100 /* 101 * @brief componment information arrange 102 * @param bundle bundle name 103 * @param inputCompMsgPtr input componment msg ptr 104 * @param data out data 105 * @return void 106 */ 107 void ComponmentInfoArrange(const std::string &bundle, std::shared_ptr<ComponmentInputMsg> inputCompMsgPtr, 108 std::map<std::string, std::string> &data); 109 // csv filename 110 std::string reportCsvFileName_ = ""; 111 std::string reportJsonFileName_ = ""; 112 std::string reportExceptionDir_ = ""; 113 std::string currentTestDir_ = ""; 114 std::string startRunTime_ = ""; 115 std::string crashDir_ = "/data/log/faultlog/faultlogger/"; 116 std::vector<std::string> hilogFiles_; 117 std::string seed_ = ""; 118 int taskCount_ = 0; 119 bool isFirstAppSwitch_ = false; 120 time_t startTime_ = time(0); 121 std::mutex crashMtx_; 122 std::string hilogDirs_ = "/data/log/hilog/"; 123 // multimodal input data set 124 std::shared_ptr<DataSet> eventDataSet_ = std::make_shared<DataSet>(); 125 // componment input data set 126 std::shared_ptr<DataSet> componmentDataSet_ = std::make_shared<DataSet>(); 127 // ability data set 128 std::shared_ptr<DataSet> abilityDataSet_ = std::make_shared<DataSet>(); 129 // exception data set 130 std::shared_ptr<DataSet> exceptionDataSet_ = std::make_shared<DataSet>(); 131 // app set 132 std::vector<std::string> bundles_; 133 std::map<std::string, componmentRecord> bundleComponmentRecord_; 134 135 // screen store path vector 136 std::vector<std::string> screenPaths_; 137 }; 138 } // namespace WuKong 139 } // namespace OHOS 140 141 #endif 142