diff --git a/test/scripts/performance_test/performance_build.py b/test/scripts/performance_test/performance_build.py index 3b804face0a1761b81285bcc568def9c721fa601..7547c36d3907a479257e7f3933c5aad7a74ea722 100644 --- a/test/scripts/performance_test/performance_build.py +++ b/test/scripts/performance_test/performance_build.py @@ -15,7 +15,6 @@ # limitations under the License. -import json5 import os import subprocess import sys @@ -23,6 +22,8 @@ import time import traceback import zipfile +import json5 + import performance_config @@ -36,7 +37,6 @@ class PerformanceBuild(): self.all_size_dic = {} self.mail_helper = None self.mail_msg = '' - self.developing_test_data_path = '' self.mail_helper = mail_obj self.config = config_input self.prj_name = '' @@ -56,7 +56,6 @@ class PerformanceBuild(): dic[key].append(value) def init(self): - self.developing_test_data_path = os.path.join(os.path.dirname(__file__), self.config.developing_test_data_path) if self.config.ide == performance_config.IdeType.DevEco: os.environ['path'] = self.config.node_js_path + ";" + os.environ['path'] os.chdir(self.config.project_path) @@ -67,7 +66,7 @@ class PerformanceBuild(): self.config.release_package_path = os.path.join(self.config.project_path, self.config.release_package_path) self.config.incremental_code_path = os.path.join(self.config.project_path, self.config.incremental_code_path) self.config.json5_path = os.path.join(self.config.project_path, self.config.json5_path) - if self.developing_test_data_path: + if self.config.developing_test_data_path: self.config.build_times = 3 else: subprocess.Popen((self.config.cmd_prefix + " --stop-daemon").split(" "), @@ -80,7 +79,7 @@ class PerformanceBuild(): content = modified_file.read() add_str_end_pos = content.find(end_pos) if add_str_end_pos == -1: - print('Can not find code : {end_pos} in {code_path}, please check config') + print(f'Can not find code : {end_pos} in {code_path}, please check config') return add_str_start_pos = content.find(start_pos) if add_str_start_pos == -1: @@ -118,14 +117,14 @@ class PerformanceBuild(): self.revert_incremental_code() def clean_project(self): - if not self.developing_test_data_path: + if not self.config.developing_test_data_path: print(self.config.cmd_prefix + " clean") subprocess.Popen((self.config.cmd_prefix + " clean").split(" "), stderr=sys.stderr, stdout=sys.stdout).communicate(timeout=self.timeout) def get_bytecode_size(self, is_debug): - if self.developing_test_data_path: + if self.config.developing_test_data_path: # test data for size PerformanceBuild.append_into_dic("ets/mudules.abc rawSize", 44444, self.all_size_dic) PerformanceBuild.append_into_dic("ets/mudules.abc Compress_size", 33333, self.all_size_dic) @@ -143,37 +142,40 @@ class PerformanceBuild(): PerformanceBuild.append_into_dic(name_str2, info.compress_size, self.all_size_dic) def collect_build_data(self, is_debug, report_path): + event_obj = None with open(report_path, 'r+', encoding='UTF-8') as report: event_obj = json5.load(report)['events'] - found_error = False - for node in event_obj: - if node['head']['type'] == "log" and node['additional']['logType'] == 'error': - self.error_log_str = self.error_log_str + node['head']['name'] - found_error = True - if found_error: - continue - - build_time = 0 - task_name = node['head']['name'] - if node['head']['type'] == "mark": - if node['additional']['markType'] == 'history': - build_time = (node['body']['endTime'] - node['body']['startTime']) / 1000000000 - task_name = "total build cost" - else: - continue - elif node['head']['type'] == "continual": - build_time = node['additional']['totalTime'] / 1000000000 + if not event_obj: + raise Exception('Open report json failed') + found_error = False + for node in event_obj: + if node['head']['type'] == "log" and node['additional']['logType'] == 'error': + self.error_log_str = self.error_log_str + node['head']['name'] + found_error = True + if found_error: + continue + + build_time = 0 + task_name = node['head']['name'] + if node['head']['type'] == "mark": + if node['additional']['markType'] == 'history': + build_time = (node['body']['endTime'] - node['body']['startTime']) / 1000000000 + task_name = "total build cost" else: continue - PerformanceBuild.append_into_dic(task_name, build_time, self.all_time_dic) - if found_error: - raise Exception('Build Failed') + elif node['head']['type'] == "continual": + build_time = node['additional']['totalTime'] / 1000000000 + else: + continue + PerformanceBuild.append_into_dic(task_name, build_time, self.all_time_dic) + if found_error: + raise Exception('Build Failed') self.get_bytecode_size(is_debug) def start_build(self, is_debug): - if self.developing_test_data_path: + if self.config.developing_test_data_path: # test data - self.collect_build_data(is_debug, os.path.join(os.path.dirname(__file__), self.developing_test_data_path)) + self.collect_build_data(is_debug, os.path.join(os.path.dirname(__file__), self.config.developing_test_data_path)) return True reports_before = [] report_dir = '.hvigor/report' @@ -190,7 +192,7 @@ class PerformanceBuild(): def get_millisecond(self, time_string): - if self.config.ide != performance_config.IdeType.DevEco and not self.developing_test_data_path: + if self.config.ide != performance_config.IdeType.DevEco and not self.config.developing_test_data_path: return int(time_string) else: cost_time = 0 @@ -305,7 +307,7 @@ class PerformanceBuild(): full_size = dic[key][0] self.mail_helper.add_pic_data(self.config.name, is_debug, [full_size]) - def write_mail_files(self, dic, is_Time_dic): + def write_mail_files(self, dic): if not hasattr(self.config, 'show_time_detail_filter'): return '' msg = '' @@ -318,8 +320,8 @@ class PerformanceBuild(): show_dic = [] for k in self.config.show_time_detail_filter: - if k in dic: - show_dic.append(k) + if k in dic: + show_dic.append(k) for key in show_dic: content_row = PerformanceBuild.add_th(key) for v in dic[key]: @@ -360,7 +362,7 @@ class PerformanceBuild(): self.write_logs_from_dic(path_prefix, self.config.log_filename[2], self.all_time_dic, False) # write avg build time, html msg and picture data self.write_logs_from_dic(path_prefix, self.config.log_filename[3], self.time_avg_dic, True) - temp_mail_msg += self.write_mail_files(self.time_avg_dic, True) + temp_mail_msg += self.write_mail_files(self.time_avg_dic) self.add_time_pic_data(self.time_avg_dic, is_debug) # write all size of abc log self.write_logs_from_dic(path_prefix, self.config.log_filename[0], self.all_size_dic, False) diff --git a/test/scripts/performance_test/performance_config.py b/test/scripts/performance_test/performance_config.py index 3d34b34b4ae82e864b4d9dc0f34ac63447aaa546..2360d7c74b47abae83a12cec00a4adf92343c824 100644 --- a/test/scripts/performance_test/performance_config.py +++ b/test/scripts/performance_test/performance_config.py @@ -23,8 +23,6 @@ class IdeType(): class Config(): - log_direct = "buildTestData" - log_direct_data_format = "%Y-%m-%d-%H-%M-%S" send_mail = True run_list = ["HelloWorld"] @@ -43,12 +41,12 @@ class Config(): self.incremental_code_str = "let index = 5 + 6\n" self.incremental_code_start_pos = "let index = 5 + 6\n" self.incremental_code_end_pos = 'this.num = num' - self.cmd_debug_suffix = r' --mode module -p product=default module=entry@default -p buildMode=debug assembleHap ' + \ - '--info --verbose-analyze --parallel --incremental --daemon' - self.cmd_release_suffix = r' --mode module -p product=default module=entry@default -p buildMode=release assembleHap ' + \ - '--info --verbose-analyze --parallel --incremental --daemon' + self.cmd_debug_suffix = r' --mode module -p product=default module=entry@default -p' + \ + ' buildMode=debug assembleHap --info --verbose-analyze --parallel --incremental --daemon' + self.cmd_release_suffix = r' --mode module -p product=default module=entry@default -p' + \ + ' buildMode=release assembleHap --info --verbose-analyze --parallel --incremental --daemon' self.debug_package_path = r'entry/build/default/outputs/default/entry-default-signed.hap' - self.release_package_path = r'entry/build/default/outputs/default/app/entry-default.hap' + self.release_package_path = r'entry/build/default/outputs/default/entry-default-unsigned.hap' self.incremental_code_path = r'entry/src/main/ets/pages/Index.ets' self.json5_path = r'build-profile.json5' @@ -97,7 +95,7 @@ class Config(): # The following params is not neccessary to be modified debug_package_path=r'entry/build/default/outputs/default/entry-default-unsigned.hap', - release_package_path=r'entry/build/default/outputs/default/app/entry-default.hap', + release_package_path=r'entry/build/default/outputs/default/entry-default-unsigned.hap', incremental_code_path=r'entry/src/main/ets/pages/Index.ets', incremental_code_end_pos='build() {', incremental_code_str="a: number=5 + 6\n", @@ -105,7 +103,7 @@ class Config(): # This app will show the time costs in html # you can setting this as a global setting to show all applications. - show_time_detail_filter = ["createProgram", "arkTSLinter", "tsProgramEmit", + show_time_detail_filter=["createProgram", "arkTSLinter", "tsProgramEmit", "generate content and source map information", "write obfuscated source code", "write source map (async)", "generate merged abc by es2abc (async)", "total build cost" ] diff --git a/test/scripts/performance_test/performance_entry.py b/test/scripts/performance_test/performance_entry.py index a364696f58334a4ec12b64a91f4cf2a21d27f570..9e33c189e9ab05c19f3733ec62e95e0ad615d68f 100644 --- a/test/scripts/performance_test/performance_entry.py +++ b/test/scripts/performance_test/performance_entry.py @@ -36,6 +36,7 @@ class MailHelper(): self.mail_msg = '' self.logs_file = {} self.failed_prjs = '' + self.data_count_in_line_graph = 10 MailHelper.remove_files() @staticmethod @@ -177,8 +178,9 @@ class MailHelper(): if len(dic) > 0: df_inserted = pd.DataFrame(dic, index=self.time_index) df = df._append(df_inserted) - if len(df) > 10: - df = df[1:len(df)] + df_length = len(df) + if df_length > self.data_count_in_line_graph: + df = df[(df_length - self.data_count_in_line_graph) : df_length] df.to_csv(csv_filename) y_lable = 'build time (s)' if log_type < performance_config.LogType.SIZE else 'size (Byte)' self.draw_pic(df, pic_name, title_name, y_lable) diff --git a/test/scripts/performance_test/test_error_report.json b/test/scripts/performance_test/test_error_report.json index 2d1f0b2220bfd48f7fcfa3f74f3aa8342239bc64..e52205e51a6febe9a8012eb786bc3a6b0e2fbb2b 100644 --- a/test/scripts/performance_test/test_error_report.json +++ b/test/scripts/performance_test/test_error_report.json @@ -88,7 +88,7 @@ ,{ "head": { "id": "22", - "name": "build failed2\r\naabb", + "name": "This is error log\r\nThis is the same log in another line", "type": "log" }, diff --git a/test/scripts/sdk_test/config.yaml b/test/scripts/sdk_test/config.yaml index ffd306bf0439f30ca75ddd1af3c3ebf2345de3e2..b3d9870b2c108dd1588c8ff0e0b0319ef1a04e59 100644 --- a/test/scripts/sdk_test/config.yaml +++ b/test/scripts/sdk_test/config.yaml @@ -32,6 +32,7 @@ log_file: ./sdk_test_log.txt # -error: indicates this hap need to test whether compile error is correctly generated as well # -exceed_length_error: indicates this hap need to test whether compile error is correctly generated when path exceed the limit # -ohosTest: indicates this hap needed to compile ohosTest as well +# -hap_module: specify one module to build in the test. # -build_path: path to build path, in form of list # -cache_path: path to cache path, in form of list # -output_hap_path: path of output hap(debug mode), in form of list @@ -44,6 +45,7 @@ haps: name: Calendar path: D:\haps\calendar type: [stage] + hap_module: entry build_path: cache_path: output_hap_path: @@ -55,6 +57,7 @@ haps: name: WidgetDemo path: D:\haps\WidgetDemo type: [stage, widget] + hap_module: entry build_path: cache_path: output_hap_path: @@ -66,6 +69,7 @@ haps: name: IdeStageDemoEmptyAbility path: D:\sdk-test\DemoApplication_EmptyAbility type: [stage, ohosTest, exceed_length_error, error] + hap_module: entry build_path: [entry, build, default] cache_path: [cache, default, default@CompileArkTS, esmodule] output_hap_path: [outputs, default, entry-default-unsigned.hap] @@ -76,6 +80,7 @@ haps: name: IdeFaDemoEmptyAbility path: D:\sdk-test\DemoApplication_EmptyAbility_fa type: [fa, ohosTest, exceed_length_error, error] + hap_module: entry build_path: [entry, build, default] cache_path: [cache, default, default@LegacyCompileArkTS, jsbundle] output_hap_path: [outputs, default, entry-default-unsigned.hap] @@ -86,6 +91,7 @@ haps: name: IdeCompatible8DemoEmptyAbility path: D:\sdk-test\DemoApplication_EmptyAbility_compatible8 type: [compatible8, ohosTest, exceed_length_error, error] + hap_module: entry build_path: [entry, build, default] cache_path: [cache, default, default@LegacyCompileArkTS, jsbundle] output_hap_path: [outputs, default, entry-default-unsigned.hap] @@ -96,6 +102,7 @@ haps: name: IdeJsDemoEmptyAbility path: D:\sdk-test\DemoApplication_EmptyAbility_js type: [js, ohosTest, exceed_length_error, error] + hap_module: entry build_path: [entry, build, default] cache_path: [cache, default, default@LegacyCompileJS, jsbundle] output_hap_path: [outputs, default, entry-default-unsigned.hap] diff --git a/test/scripts/sdk_test/execution.py b/test/scripts/sdk_test/execution.py index bcdeb614e66b7eb8a41eb7addb8d2cecb95764bc..4f898b99bb0c5df67bff617b8b6f47d2e79c3e22 100644 --- a/test/scripts/sdk_test/execution.py +++ b/test/scripts/sdk_test/execution.py @@ -102,7 +102,7 @@ class IncrementalTest: @staticmethod def validate_compile_incremental_file(task, inc_task, is_debug, modified_files): - cache_extension = '' + cache_extention = '' if 'stage' in task.type: cache_extention = '.protoBin' elif 'fa' in task.type or 'compatible8' in task.type: @@ -150,6 +150,7 @@ class IncrementalTest: task.type, file_relative_path, modified_cache_files) logging.debug(f"is file in list: {is_file_in_list}") if not is_file_in_list: + logging.debug(f"Unexpected file modified: {file_relative_path}") inc_info.result = options.TaskResult.failed inc_info.error_message = f'Incremental compile found unexpected file timestamp changed. \ Changed file: {file_relative_path}' @@ -291,7 +292,10 @@ class IncrementalTest: profile_data = json5.load(file) new_module_name = "new_entry" logging.debug(f"profile_data is: {profile_data}") - profile_data['modules'][0]['name'] = new_module_name + for module in profile_data['modules']: + if module['name'] == task.hap_module: + module['name'] = new_module_name + break with open(profile_file, 'w') as file: json5.dump(profile_data, file) @@ -309,7 +313,8 @@ class IncrementalTest: json5.dump(config_data, file) try: - [stdout, stderr] = compile_project(task, is_debug) + cmd = get_hvigor_compile_cmd(task, is_debug, new_module_name) + [stdout, stderr] = compile_project(task, is_debug, cmd) IncrementalTest.validate_module_name_change( task, inc_task, is_debug, stdout, stderr, new_module_name) except Exception as e: @@ -394,12 +399,12 @@ class OtherTest: logging.info(f"==========> Running {test_name} for task: {task.name}") clean_compile(task) - cmd = get_hvigor_compile_cmd(task.path, is_debug) + cmd = get_hvigor_compile_cmd(task, is_debug) logging.debug(f'cmd: {cmd}') logging.debug(f"cmd execution path {task.path}") process = subprocess.Popen(cmd, shell=False, cwd=task.path, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.STDOUT) for line in iter(process.stdout.readline, b''): if b'CompileArkTS' in line: @@ -412,8 +417,6 @@ class OtherTest: logging.debug("first compile: stdcout: %s", stdout.decode('utf-8', errors="ignore")) - logging.warning("first compile: stdcerr: %s", - stderr.decode('utf-8', errors="ignore")) logging.debug("another compile") [stdout, stderr] = compile_project(task, is_debug) @@ -475,7 +478,7 @@ class OtherTest: profile_file_backup = profile_file + ".bak" shutil.copyfile(profile_file, profile_file_backup) - with open(profile_file, 'r') as file: + with open(profile_file, 'r', encoding='utf-8') as file: profile_data = json5.load(file) long_str = 'default1234567890123456789012345678901234567890123456789012345678901234567890123456789' + \ @@ -483,10 +486,11 @@ class OtherTest: logging.debug("long_str: %s", long_str) profile_data['targets'][0]['name'] = long_str - with open(profile_file, 'w') as file: + with open(profile_file, 'w', encoding='utf-8') as file: json5.dump(profile_data, file) - [stdout, stderr] = compile_project(task, is_debug) + cmd = get_hvigor_compile_cmd(task, is_debug, task.hap_module, long_str) + [stdout, stderr] = compile_project(task, is_debug, cmd) # Only the Windows platform has a length limit if utils.is_windows(): expected_error_message = 'The length of path exceeds the maximum length: 259' @@ -803,18 +807,19 @@ def get_hvigor_path(project_path): return hvigor -def get_hvigor_compile_cmd(project_path, is_debug): - cmd = [get_hvigor_path(project_path)] - if is_debug: - cmd.append('assembleHap') - else: - cmd.append('assembleApp') +def get_hvigor_compile_cmd(task, is_debug, module_name='', module_target='default'): + cmd = [get_hvigor_path(task.path)] + build_mode = 'debug' if is_debug else 'release' + module = module_name if module_name else task.hap_module + cmd.extend(['--mode', 'module', '-p', 'product=default', '-p', f'module={module}@{module_target}', '-p', + f'buildMode={build_mode}', 'assembleHap', + '--info', '--verbose-analyze', '--parallel', '--incremental', '--daemon']) return cmd def compile_project(task, is_debug, cmd=''): if not cmd: - cmd = get_hvigor_compile_cmd(task.path, is_debug) + cmd = get_hvigor_compile_cmd(task, is_debug) logging.debug(f'cmd: {cmd}') logging.debug(f"cmd execution path {task.path}") diff --git a/test/scripts/sdk_test/options.py b/test/scripts/sdk_test/options.py index 0f5e58b17399b65a2446ea83e70d46186452d295..fb50139b6ed0ce45b85fb73d66c3e61154558f0d 100644 --- a/test/scripts/sdk_test/options.py +++ b/test/scripts/sdk_test/options.py @@ -157,6 +157,7 @@ def create_test_tasks(): task.name = hap['name'] task.path = hap['path'] task.type = hap['type'] + task.hap_module = hap['hap_module'] task.build_path = hap['build_path'] task.cache_path = hap['cache_path'] task.output_hap_path = hap['output_hap_path']