• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 AotMode():
26    NoAOT = 0
27    Type = 1
28
29
30class Config():
31    log_direct = "buildTestData"
32    log_direct_data_format = "%Y-%m-%d-%H-%M-%S"
33    send_mail = True
34    run_list = ["FTB", "FDY", "FWX"]
35
36    def __init__(self):
37        # Default config settings for all projects, if it's not what you need, config them in application_configs
38        self.cmd_prefix = r"hvigorw.bat"
39
40        self.output_split = "_"
41        self.ide_filename = ["AS", "DevEco"]
42        self.debug_or_release = ["Debug", "Release"]
43        self.build_type_of_log = ["full_then_incremental", "add_code_and_ui"]
44        self.log_filename = ["size_all.csv", "size_avg.csv",
45                             "time_all.csv", "time_avg.csv"]
46        self.error_filename = 'error.log'
47        self.aot_mode = ["noaot", "aottype"]
48        self.ide = IdeType.DevEco
49        self.incremental_code_str = "let index = 5 + 6\n"
50        self.incremental_code_start_pos = "let index = 5 + 6\n"
51        self.incremental_code_end_pos = 'this.num = num'
52        self.cmd_debug_suffix = r' --mode module -p product=default assembleHap --no-daemon'
53        self.cmd_release_suffix = r' --mode project -p product=default assembleApp --no-daemon'
54        self.debug_package_path = r'entry/build/default/outputs/default/entry-default-signed.hap'
55        self.release_package_path = r'entry/build/default/outputs/default/app/entry-default.hap'
56        self.incremental_code_path = r'entry/src/main/ets/pages/Index.ets'
57        self.json5_path = r'entry/build-profile.json5'
58
59        # build serveral times then calculate the average value
60        self.build_times = 3
61        # Do not build the project,use the test data if you need to debug the scripts
62        self.developing_test_mode = False
63        # set your node_js path, it should be the same to the setting in your IDE
64        self.node_js_path = r"%s/nodejs" % os.environ['USERPROFILE']
65        # Must set according environment
66        self.jbr_path = r'xxx/DevEco Studio/jbr'
67
68    # If Default config is not what you need, you can set here!
69    application_configs = dict(
70        [
71            (
72                "FTB", dict
73                    (
74                        project_path=r"D:/FTB",
75                    )
76            ),
77            (
78                "FDY", dict
79                    (
80                        project_path=r"D:/FDY",
81                    )
82            ),
83            (
84                "FWX", dict
85                    (
86                        project_path=r"D:/FWX",
87                    )
88            ),
89            (
90                "HelloWorld", dict
91                    (
92                        # The following params must be set according you environment
93                        project_path=r"D:/HelloWorld",
94
95                        # The following params is not neccessary to be modified
96                        debug_package_path=r'entry/build/default/outputs/default/entry-default-unsigned.hap',
97                        release_package_path=r'entry/build/default/outputs/default/app/entry-default.hap',
98                        incremental_code_path=r'entry/src/main/ets/pages/Index.ets',
99                        incremental_code_end_pos='build() {',
100                        incremental_code_str="a: number=5 + 6\n",
101                        incremental_code_start_pos="a: number=5 + 6\n",
102                    )
103            )
104        ]
105    )
106
107
108def get_config(index):
109    config = Config()
110    res = config.application_configs.get(index)
111    if not res:
112        print("No key in config, please check: " + index)
113        return res
114    for k in res:
115        setattr(config, k, res[k])
116    return config
117
118
119def get_html_prefix():
120    return '<html><body><table width="100%" border=1 cellspacing=0 cellpadding=0 align="center">' + \
121           '<tr><th bgcolor="SlateBlue"><font size="5">Daily Performance Test</font></th></tr></table>' + \
122           '<font size="5" color=red>{}' + \
123           '<img src="cid:performance10"><img src="cid:performance11">' + \
124           '<img src="cid:performance00"><img src="cid:performance01">' + \
125           '<img src="cid:performance02"><img src="cid:performance12">'
126
127
128
129def get_html_suffix():
130    return '</body></html>'
131
132
133class BuildMode():
134    DEBUG = 0
135    RELEASE = 1
136
137
138class LogType():
139    FULL = 0
140    INCREMENTAL = 1
141    SIZE = 2
142
143
144class MailPicConfig():
145    mail_data_path = os.path.join(
146        os.path.dirname(os.path.abspath(__file__)),
147        'mail_data',
148    )
149
150    html_file_path = os.path.join(
151        mail_data_path,
152        "email_msg.html"
153    )
154
155    attach_path = os.path.join(
156        mail_data_path,
157        "performance_logs.zip"
158    )
159
160    # Count of days which will be add into the email picture
161    mail_pic_table_name = {
162        BuildMode.DEBUG: {
163            LogType.FULL: os.path.join(mail_data_path, 'debug_full_time.csv'),
164            LogType.INCREMENTAL: os.path.join(mail_data_path, 'debug_incremental_time.csv'),
165            LogType.SIZE: os.path.join(mail_data_path, 'debug_size.csv')
166        },
167        BuildMode.RELEASE:{
168            LogType.FULL: os.path.join(mail_data_path, 'release_full_time.csv'),
169            LogType.INCREMENTAL: os.path.join(mail_data_path, 'release_incremental_time.csv'),
170            LogType.SIZE: os.path.join(mail_data_path, 'release_size.csv')
171        }
172    }
173
174    mail_pic_name = {
175        BuildMode.DEBUG: {
176            LogType.FULL:os.path.join(mail_data_path, 'debug_full_time.jpg'),
177            LogType.INCREMENTAL: os.path.join(mail_data_path, 'debug_incremental_time.jpg'),
178            LogType.SIZE: os.path.join(mail_data_path, 'debug_size.jpg')
179        },
180        BuildMode.RELEASE:{
181            LogType.FULL: os.path.join(mail_data_path, 'release_full_time.jpg'),
182            LogType.INCREMENTAL: os.path.join(mail_data_path, 'release_incremental_time.jpg'),
183            LogType.SIZE: os.path.join(mail_data_path, 'release_size.jpg')
184        }
185    }
186
187    mail_pic_table_lable = {
188        BuildMode.DEBUG: {
189            LogType.FULL: 'Debug Full Build',
190            LogType.INCREMENTAL: 'Debug Incremental Build',
191            LogType.SIZE: 'Debug Full Build size'
192        },
193        BuildMode.RELEASE:{
194            LogType.FULL: 'Release Full Build',
195            LogType.INCREMENTAL: 'Release Incremental Time',
196            LogType.SIZE: 'Release Full Build size'
197        }
198    }