1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# 4# Copyright (c) 2023 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import os 18 19 20class IdeType(): 21 AS = 1 22 DevEco = 2 23 24 25class Config(): 26 log_direct = "buildTestData" 27 log_direct_data_format = "%Y-%m-%d-%H-%M-%S" 28 send_mail = True 29 run_list = ["FTB", "FDY", "FWX"] 30 31 def __init__(self): 32 # Default config settings for all projects, if it's not what you need, config them in application_configs 33 self.cmd_prefix = r"hvigorw.bat" 34 35 self.output_split = "_" 36 self.ide_filename = ["AS", "DevEco"] 37 self.debug_or_release = ["Debug", "Release"] 38 self.build_type_of_log = ["full_then_incremental", "add_code_and_ui"] 39 self.log_filename = ["size_all.csv", "size_avg.csv", 40 "time_all.csv", "time_avg.csv"] 41 self.error_filename = 'error.log' 42 self.ide = IdeType.DevEco 43 self.incremental_code_str = "let index = 5 + 6\n" 44 self.incremental_code_start_pos = "let index = 5 + 6\n" 45 self.incremental_code_end_pos = 'this.num = num' 46 self.cmd_debug_suffix = r' --mode module -p product=default assembleHap --no-daemon' 47 self.cmd_release_suffix = r' --mode project -p product=default assembleApp --no-daemon' 48 self.debug_package_path = r'entry/build/default/outputs/default/entry-default-signed.hap' 49 self.release_package_path = r'entry/build/default/outputs/default/app/entry-default.hap' 50 self.incremental_code_path = r'entry/src/main/ets/pages/Index.ets' 51 self.json5_path = r'entry/build-profile.json5' 52 53 # build serveral times then calculate the average value 54 self.build_times = 3 55 # Do not build the project,use the test data if you need to debug the scripts 56 self.developing_test_mode = False 57 # set your node_js path, it should be the same to the setting in your IDE 58 self.node_js_path = r"%s/nodejs" % os.environ['USERPROFILE'] 59 # Must set according environment 60 self.jbr_path = r'xxx/DevEco Studio/jbr' 61 62 # If Default config is not what you need, you can set here! 63 application_configs = dict( 64 [ 65 ( 66 "FTB", dict 67 ( 68 project_path=r"D:/FTB", 69 ) 70 ), 71 ( 72 "FDY", dict 73 ( 74 project_path=r"D:/FDY", 75 ) 76 ), 77 ( 78 "FWX", dict 79 ( 80 project_path=r"D:/FWX", 81 ) 82 ), 83 ( 84 "HelloWorld", dict 85 ( 86 # The following params must be set according you environment 87 project_path=r"D:/HelloWorld", 88 89 # The following params is not neccessary to be modified 90 debug_package_path=r'entry/build/default/outputs/default/entry-default-unsigned.hap', 91 release_package_path=r'entry/build/default/outputs/default/app/entry-default.hap', 92 incremental_code_path=r'entry/src/main/ets/pages/Index.ets', 93 incremental_code_end_pos='build() {', 94 incremental_code_str="a: number=5 + 6\n", 95 incremental_code_start_pos="a: number=5 + 6\n", 96 ) 97 ) 98 ] 99 ) 100 101 102def get_config(index): 103 config = Config() 104 res = config.application_configs.get(index) 105 if not res: 106 print("No key in config, please check: " + index) 107 return res 108 for k in res: 109 setattr(config, k, res[k]) 110 return config 111 112 113def get_html_prefix(): 114 return '<html><body><table width="100%" border=1 cellspacing=0 cellpadding=0 align="center">' + \ 115 '<tr><th bgcolor="SlateBlue"><font size="5">Daily Performance Test</font></th></tr></table>' + \ 116 '<font size="5" color=red>{}' + \ 117 '<img src="cid:performance10"><img src="cid:performance11">' + \ 118 '<img src="cid:performance00"><img src="cid:performance01">' + \ 119 '<img src="cid:performance02"><img src="cid:performance12">' 120 121 122 123def get_html_suffix(): 124 return '</body></html>' 125 126 127class BuildMode(): 128 DEBUG = 0 129 RELEASE = 1 130 131 132class LogType(): 133 FULL = 0 134 INCREMENTAL = 1 135 SIZE = 2 136 137 138class MailPicConfig(): 139 mail_data_path = os.path.join( 140 os.path.dirname(os.path.abspath(__file__)), 141 'mail_data', 142 ) 143 144 html_file_path = os.path.join( 145 mail_data_path, 146 "email_msg.html" 147 ) 148 149 attach_path = os.path.join( 150 mail_data_path, 151 "performance_logs.zip" 152 ) 153 154 # Count of days which will be add into the email picture 155 mail_pic_table_name = { 156 BuildMode.DEBUG: { 157 LogType.FULL: os.path.join(mail_data_path, 'debug_full_time.csv'), 158 LogType.INCREMENTAL: os.path.join(mail_data_path, 'debug_incremental_time.csv'), 159 LogType.SIZE: os.path.join(mail_data_path, 'debug_size.csv') 160 }, 161 BuildMode.RELEASE:{ 162 LogType.FULL: os.path.join(mail_data_path, 'release_full_time.csv'), 163 LogType.INCREMENTAL: os.path.join(mail_data_path, 'release_incremental_time.csv'), 164 LogType.SIZE: os.path.join(mail_data_path, 'release_size.csv') 165 } 166 } 167 168 mail_pic_name = { 169 BuildMode.DEBUG: { 170 LogType.FULL:os.path.join(mail_data_path, 'debug_full_time.jpg'), 171 LogType.INCREMENTAL: os.path.join(mail_data_path, 'debug_incremental_time.jpg'), 172 LogType.SIZE: os.path.join(mail_data_path, 'debug_size.jpg') 173 }, 174 BuildMode.RELEASE:{ 175 LogType.FULL: os.path.join(mail_data_path, 'release_full_time.jpg'), 176 LogType.INCREMENTAL: os.path.join(mail_data_path, 'release_incremental_time.jpg'), 177 LogType.SIZE: os.path.join(mail_data_path, 'release_size.jpg') 178 } 179 } 180 181 mail_pic_table_lable = { 182 BuildMode.DEBUG: { 183 LogType.FULL: 'Debug Full Build', 184 LogType.INCREMENTAL: 'Debug Incremental Build', 185 LogType.SIZE: 'Debug Full Build size' 186 }, 187 BuildMode.RELEASE:{ 188 LogType.FULL: 'Release Full Build', 189 LogType.INCREMENTAL: 'Release Incremental Time', 190 LogType.SIZE: 'Release Full Build size' 191 } 192 }