13af6ab5fSopenharmony_ci#!/usr/bin/env python3
23af6ab5fSopenharmony_ci# coding: utf-8
33af6ab5fSopenharmony_ci
43af6ab5fSopenharmony_ci"""
53af6ab5fSopenharmony_ciCopyright (c) 2023 Huawei Device Co., Ltd.
63af6ab5fSopenharmony_ciLicensed under the Apache License, Version 2.0 (the "License");
73af6ab5fSopenharmony_ciyou may not use this file except in compliance with the License.
83af6ab5fSopenharmony_ciYou may obtain a copy of the License at
93af6ab5fSopenharmony_ci
103af6ab5fSopenharmony_ci    http://www.apache.org/licenses/LICENSE-2.0
113af6ab5fSopenharmony_ci
123af6ab5fSopenharmony_ciUnless required by applicable law or agreed to in writing, software
133af6ab5fSopenharmony_cidistributed under the License is distributed on an "AS IS" BASIS,
143af6ab5fSopenharmony_ciWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
153af6ab5fSopenharmony_ciSee the License for the specific language governing permissions and
163af6ab5fSopenharmony_cilimitations under the License.
173af6ab5fSopenharmony_ci
183af6ab5fSopenharmony_ciDescription: output test results
193af6ab5fSopenharmony_ci"""
203af6ab5fSopenharmony_ci
213af6ab5fSopenharmony_ciimport copy
223af6ab5fSopenharmony_ciimport logging
233af6ab5fSopenharmony_ciimport os
243af6ab5fSopenharmony_ciimport time
253af6ab5fSopenharmony_ci
263af6ab5fSopenharmony_ciimport pandas
273af6ab5fSopenharmony_ci
283af6ab5fSopenharmony_ciimport options
293af6ab5fSopenharmony_ci
303af6ab5fSopenharmony_cifull_compile_tests = ["full_compile",
313af6ab5fSopenharmony_ci                      "import_ordinary_ohpm_package",
323af6ab5fSopenharmony_ci                      "import_special_ohpm_package",
333af6ab5fSopenharmony_ci                      "import_static_library",
343af6ab5fSopenharmony_ci                      "import_share_library",
353af6ab5fSopenharmony_ci                      "import_so_file",
363af6ab5fSopenharmony_ci                      "has_syntax_error_in_js",
373af6ab5fSopenharmony_ci                      "use_normalize_ohmurl",
383af6ab5fSopenharmony_ci                      "module_name_is_inconsistent",
393af6ab5fSopenharmony_ci                      ]
403af6ab5fSopenharmony_ci
413af6ab5fSopenharmony_ciincremental_compile_tests = ["no_change",
423af6ab5fSopenharmony_ci                             "add_oneline",
433af6ab5fSopenharmony_ci                             "add_file",
443af6ab5fSopenharmony_ci                             "add_nonexistent_file",
453af6ab5fSopenharmony_ci                             "delete_file",
463af6ab5fSopenharmony_ci                             "modify_error_then_fix",
473af6ab5fSopenharmony_ci                             "add_error_page_then_fix",
483af6ab5fSopenharmony_ci                             "add_error_non_page_then_fix",
493af6ab5fSopenharmony_ci                             "build_entry_then_har",
503af6ab5fSopenharmony_ci                             "build_har_then_entry",
513af6ab5fSopenharmony_ci                             "build_entry_then_hsp",
523af6ab5fSopenharmony_ci                             "build_hsp_then_entry",
533af6ab5fSopenharmony_ci                             "build_hsp_then_ohos",
543af6ab5fSopenharmony_ci                             "build_entry_then_ohos",
553af6ab5fSopenharmony_ci                             "build_entry_then_preview_build",
563af6ab5fSopenharmony_ci                             "reverse_hap_mode",
573af6ab5fSopenharmony_ci                             "change_module_name",
583af6ab5fSopenharmony_ci                             "modify_sdk_version",
593af6ab5fSopenharmony_ci                             ]
603af6ab5fSopenharmony_ci
613af6ab5fSopenharmony_cibytecode_har_compile_tests = ["build_bytecode_har",
623af6ab5fSopenharmony_ci                               "build_har_then_bytecode_har",
633af6ab5fSopenharmony_ci                               "import_bytecode_static_library",
643af6ab5fSopenharmony_ci                               ]
653af6ab5fSopenharmony_ci
663af6ab5fSopenharmony_ciexternal_compile_tests = ["import_external_share_library",
673af6ab5fSopenharmony_ci                          "import_external_static_library",
683af6ab5fSopenharmony_ci                          "full_compile_external_static_library",
693af6ab5fSopenharmony_ci                          "full_compile_external_share_library"
703af6ab5fSopenharmony_ci                          ]
713af6ab5fSopenharmony_ci
723af6ab5fSopenharmony_cipreview_compile_tests = ["preview_compile",
733af6ab5fSopenharmony_ci                         "build_entry_then_preview",
743af6ab5fSopenharmony_ci                         "build_modify_file_name",
753af6ab5fSopenharmony_ci                         "build_generate_sourcemap",
763af6ab5fSopenharmony_ci                         "tigger_incremental_build",
773af6ab5fSopenharmony_ci                         "has_arkui_error",
783af6ab5fSopenharmony_ci                         "sdk_path_has_special_char",
793af6ab5fSopenharmony_ci                         "modify_hello_world_then_fix"
803af6ab5fSopenharmony_ci                         ]
813af6ab5fSopenharmony_ci
823af6ab5fSopenharmony_ciother_tests = ["binary_consistency",
833af6ab5fSopenharmony_ci               "break_continue_compile",
843af6ab5fSopenharmony_ci               "compile_with_error",
853af6ab5fSopenharmony_ci               "compile_with_exceed_length",
863af6ab5fSopenharmony_ci               "ohos_test"
873af6ab5fSopenharmony_ci               ]
883af6ab5fSopenharmony_ci
893af6ab5fSopenharmony_ci
903af6ab5fSopenharmony_ciclass TestResult:
913af6ab5fSopenharmony_ci    def __init__(self):
923af6ab5fSopenharmony_ci        self.passed = []
933af6ab5fSopenharmony_ci        self.failed = []
943af6ab5fSopenharmony_ci        self.time = 0.0
953af6ab5fSopenharmony_ci
963af6ab5fSopenharmony_ci
973af6ab5fSopenharmony_cidef print_result(test_result, test_tasks):
983af6ab5fSopenharmony_ci    logging.info("========================================")
993af6ab5fSopenharmony_ci    logging.info("Test finished. The result is as following:")
1003af6ab5fSopenharmony_ci    logging.info("=====> Summary")
1013af6ab5fSopenharmony_ci    logging.info("Total test number: %s, took time: %.3f s",
1023af6ab5fSopenharmony_ci                 len(test_tasks), test_result.time)
1033af6ab5fSopenharmony_ci    logging.info("Passed test number: %s", len(test_result.passed))
1043af6ab5fSopenharmony_ci    logging.info("Failed test number: %s", len(test_result.failed))
1053af6ab5fSopenharmony_ci
1063af6ab5fSopenharmony_ci    logging.info("=====> Detail Information")
1073af6ab5fSopenharmony_ci    logging.info("-----")
1083af6ab5fSopenharmony_ci    idx = 1
1093af6ab5fSopenharmony_ci    for task in test_tasks:
1103af6ab5fSopenharmony_ci        logging.info("task index: %d", idx)
1113af6ab5fSopenharmony_ci        idx = idx + 1
1123af6ab5fSopenharmony_ci        logging.info("task name: %s", task.name)
1133af6ab5fSopenharmony_ci        logging.info("task type: %s", task.type)
1143af6ab5fSopenharmony_ci        # print full compile result
1153af6ab5fSopenharmony_ci        logging.info("--full compilation result:")
1163af6ab5fSopenharmony_ci        for full_task in task.full_compilation_info.values():
1173af6ab5fSopenharmony_ci            logging.info("full test: %s", full_task.name)
1183af6ab5fSopenharmony_ci            logging.info("debug: %s, abc_size(byte) %s, time(s) %s, error message: %s",
1193af6ab5fSopenharmony_ci                         full_task.debug_info.result,
1203af6ab5fSopenharmony_ci                         full_task.debug_info.abc_size,
1213af6ab5fSopenharmony_ci                         full_task.debug_info.time,
1223af6ab5fSopenharmony_ci                         full_task.debug_info.error_message)
1233af6ab5fSopenharmony_ci            logging.info("release: %s, abc_size(byte) %s, time(s) %s, error message: %s",
1243af6ab5fSopenharmony_ci                         full_task.release_info.result,
1253af6ab5fSopenharmony_ci                         full_task.release_info.abc_size,
1263af6ab5fSopenharmony_ci                         full_task.release_info.time,
1273af6ab5fSopenharmony_ci                         full_task.debug_info.error_message)
1283af6ab5fSopenharmony_ci
1293af6ab5fSopenharmony_ci        # print incremental compile result
1303af6ab5fSopenharmony_ci        logging.info("--incremental compilation result:")
1313af6ab5fSopenharmony_ci        for inc_task in task.incre_compilation_info.values():
1323af6ab5fSopenharmony_ci            logging.info("incre test: %s", inc_task.name)
1333af6ab5fSopenharmony_ci            logging.info("debug: %s, abc_size(byte) %s, time(s) %s, error message: %s",
1343af6ab5fSopenharmony_ci                         inc_task.debug_info.result,
1353af6ab5fSopenharmony_ci                         inc_task.debug_info.abc_size,
1363af6ab5fSopenharmony_ci                         inc_task.debug_info.time,
1373af6ab5fSopenharmony_ci                         inc_task.debug_info.error_message)
1383af6ab5fSopenharmony_ci            logging.info("release: %s, abc_size(byte) %s, time(s) %s, error message: %s",
1393af6ab5fSopenharmony_ci                         inc_task.release_info.result,
1403af6ab5fSopenharmony_ci                         inc_task.release_info.abc_size,
1413af6ab5fSopenharmony_ci                         inc_task.release_info.time,
1423af6ab5fSopenharmony_ci                         inc_task.release_info.error_message)
1433af6ab5fSopenharmony_ci
1443af6ab5fSopenharmony_ci        # print bytecode har compile result
1453af6ab5fSopenharmony_ci        logging.info("--bytecode har compilation result:")
1463af6ab5fSopenharmony_ci        for byte_task in task.bytecode_har_compilation_info.values():
1473af6ab5fSopenharmony_ci            logging.info("bytecode har test: %s", byte_task.name)
1483af6ab5fSopenharmony_ci            logging.info("debug: %s, abc_size(byte) %s, time(s) %s, error message: %s",
1493af6ab5fSopenharmony_ci                         byte_task.debug_info.result,
1503af6ab5fSopenharmony_ci                         byte_task.debug_info.abc_size,
1513af6ab5fSopenharmony_ci                         byte_task.debug_info.time,
1523af6ab5fSopenharmony_ci                         byte_task.debug_info.error_message)
1533af6ab5fSopenharmony_ci            logging.info("release: %s, abc_size(byte) %s, time(s) %s, error message: %s",
1543af6ab5fSopenharmony_ci                         byte_task.release_info.result,
1553af6ab5fSopenharmony_ci                         byte_task.release_info.abc_size,
1563af6ab5fSopenharmony_ci                         byte_task.release_info.time,
1573af6ab5fSopenharmony_ci                         byte_task.release_info.error_message)
1583af6ab5fSopenharmony_ci
1593af6ab5fSopenharmony_ci        # print external compile result
1603af6ab5fSopenharmony_ci        logging.info("--external compilation result:")
1613af6ab5fSopenharmony_ci        for external_task in task.external_compilation_info.values():
1623af6ab5fSopenharmony_ci            logging.info("external test: %s", external_task.name)
1633af6ab5fSopenharmony_ci            logging.info("debug: %s, abc_size(byte) %s, time(s) %s, error message: %s",
1643af6ab5fSopenharmony_ci                         external_task.debug_info.result,
1653af6ab5fSopenharmony_ci                         external_task.debug_info.abc_size,
1663af6ab5fSopenharmony_ci                         external_task.debug_info.time,
1673af6ab5fSopenharmony_ci                         external_task.debug_info.error_message)
1683af6ab5fSopenharmony_ci            logging.info("release: %s, abc_size(byte) %s, time(s) %s, error message: %s",
1693af6ab5fSopenharmony_ci                         external_task.release_info.result,
1703af6ab5fSopenharmony_ci                         external_task.release_info.abc_size,
1713af6ab5fSopenharmony_ci                         external_task.release_info.time,
1723af6ab5fSopenharmony_ci                         external_task.release_info.error_message)
1733af6ab5fSopenharmony_ci
1743af6ab5fSopenharmony_ci        # print preview compile result
1753af6ab5fSopenharmony_ci        for name, task_info in task.preview_compilation_info.items():
1763af6ab5fSopenharmony_ci            logging.info("--test name: %s", name)
1773af6ab5fSopenharmony_ci            logging.info("result: %s, error message: %s",
1783af6ab5fSopenharmony_ci                         task_info.result,
1793af6ab5fSopenharmony_ci                         task_info.error_message)
1803af6ab5fSopenharmony_ci
1813af6ab5fSopenharmony_ci        # print other tests result
1823af6ab5fSopenharmony_ci        for name, task_info in task.other_tests.items():
1833af6ab5fSopenharmony_ci            logging.info("--test name: %s", name)
1843af6ab5fSopenharmony_ci            logging.info("result: %s, error message: %s",
1853af6ab5fSopenharmony_ci                         task_info.result,
1863af6ab5fSopenharmony_ci                         task_info.error_message)
1873af6ab5fSopenharmony_ci
1883af6ab5fSopenharmony_ci        logging.info("-----")
1893af6ab5fSopenharmony_ci        logging.info("========================================")
1903af6ab5fSopenharmony_ci
1913af6ab5fSopenharmony_ci
1923af6ab5fSopenharmony_cidef is_compilation_passed(task_info, compile_mode):
1933af6ab5fSopenharmony_ci    if options.arguments.compile_mode not in ['all', compile_mode]:
1943af6ab5fSopenharmony_ci        return True
1953af6ab5fSopenharmony_ci
1963af6ab5fSopenharmony_ci    if len(task_info) == 0:
1973af6ab5fSopenharmony_ci        return False
1983af6ab5fSopenharmony_ci
1993af6ab5fSopenharmony_ci    passed_debug = True
2003af6ab5fSopenharmony_ci    passed_release = True
2013af6ab5fSopenharmony_ci    for task_name, inc_task in task_info.items():
2023af6ab5fSopenharmony_ci        if options.arguments.hap_mode in ['all', 'release']:
2033af6ab5fSopenharmony_ci            if inc_task.release_info.result == options.TaskResult.undefined:
2043af6ab5fSopenharmony_ci                continue
2053af6ab5fSopenharmony_ci            passed_release = passed_release and inc_task.release_info.result == options.TaskResult.passed
2063af6ab5fSopenharmony_ci        if options.arguments.hap_mode == ['all', 'debug']:
2073af6ab5fSopenharmony_ci            if inc_task.debug_info.result == options.TaskResult.undefined:
2083af6ab5fSopenharmony_ci                continue
2093af6ab5fSopenharmony_ci            passed_debug = passed_debug and inc_task.debug_info.result == options.TaskResult.passed
2103af6ab5fSopenharmony_ci
2113af6ab5fSopenharmony_ci    return passed_debug and passed_release
2123af6ab5fSopenharmony_ci
2133af6ab5fSopenharmony_ci
2143af6ab5fSopenharmony_cidef is_task_passed(task):
2153af6ab5fSopenharmony_ci    passed = is_compilation_passed(task.full_compilation_info, 'full') and \
2163af6ab5fSopenharmony_ci             is_compilation_passed(task.incre_compilation_info, 'incremental') and \
2173af6ab5fSopenharmony_ci             is_compilation_passed(task.bytecode_har_compilation_info, 'bytecode_har') and \
2183af6ab5fSopenharmony_ci             is_compilation_passed(task.external_compilation_info, 'external')
2193af6ab5fSopenharmony_ci
2203af6ab5fSopenharmony_ci    for test in task.preview_compilation_info.values():
2213af6ab5fSopenharmony_ci        passed = passed and (test.result == options.TaskResult.passed)
2223af6ab5fSopenharmony_ci
2233af6ab5fSopenharmony_ci    for test in task.other_tests.values():
2243af6ab5fSopenharmony_ci        passed = passed and (test.result == options.TaskResult.passed)
2253af6ab5fSopenharmony_ci
2263af6ab5fSopenharmony_ci    return passed
2273af6ab5fSopenharmony_ci
2283af6ab5fSopenharmony_ci
2293af6ab5fSopenharmony_cidef collect_result(test_result, test_tasks, start_time):
2303af6ab5fSopenharmony_ci    for task in test_tasks:
2313af6ab5fSopenharmony_ci        if not is_task_passed(task):
2323af6ab5fSopenharmony_ci            test_result.failed.append(task)
2333af6ab5fSopenharmony_ci        else:
2343af6ab5fSopenharmony_ci            test_result.passed.append(task)
2353af6ab5fSopenharmony_ci
2363af6ab5fSopenharmony_ci    end_time = time.time()
2373af6ab5fSopenharmony_ci    test_result.time = round(end_time - start_time, 3)
2383af6ab5fSopenharmony_ci
2393af6ab5fSopenharmony_ci
2403af6ab5fSopenharmony_cidef get_result_symbol(result_type):
2413af6ab5fSopenharmony_ci    if result_type == options.TaskResult.passed:
2423af6ab5fSopenharmony_ci        return '√'
2433af6ab5fSopenharmony_ci    elif result_type == options.TaskResult.failed:
2443af6ab5fSopenharmony_ci        return '×'
2453af6ab5fSopenharmony_ci    else:
2463af6ab5fSopenharmony_ci        return '-'
2473af6ab5fSopenharmony_ci
2483af6ab5fSopenharmony_ci
2493af6ab5fSopenharmony_cidef generate_summary_data(test_result, test_tasks):
2503af6ab5fSopenharmony_ci    # collect summary data
2513af6ab5fSopenharmony_ci    passed_task_name_list = []
2523af6ab5fSopenharmony_ci    for task in test_result.passed:
2533af6ab5fSopenharmony_ci        passed_task_name_list.append(task.name)
2543af6ab5fSopenharmony_ci    failed_task_name_list = []
2553af6ab5fSopenharmony_ci    for task in test_result.failed:
2563af6ab5fSopenharmony_ci        failed_task_name_list.append(task.name)
2573af6ab5fSopenharmony_ci
2583af6ab5fSopenharmony_ci    summary_data = {
2593af6ab5fSopenharmony_ci        'Total Test Number': len(test_tasks),
2603af6ab5fSopenharmony_ci        'Passed Test Number': len(test_result.passed),
2613af6ab5fSopenharmony_ci        'Failed Test Number': len(test_result.failed),
2623af6ab5fSopenharmony_ci        'Passed Tests': ','.join(passed_task_name_list),
2633af6ab5fSopenharmony_ci        'Failed Tests': ','.join(failed_task_name_list),
2643af6ab5fSopenharmony_ci        'Test Took Time(s)': test_result.time
2653af6ab5fSopenharmony_ci    }
2663af6ab5fSopenharmony_ci
2673af6ab5fSopenharmony_ci    return summary_data
2683af6ab5fSopenharmony_ci
2693af6ab5fSopenharmony_ci
2703af6ab5fSopenharmony_cidef generate_detail_data(test_tasks):
2713af6ab5fSopenharmony_ci    time_size_data = []
2723af6ab5fSopenharmony_ci    result_data = []
2733af6ab5fSopenharmony_ci
2743af6ab5fSopenharmony_ci    idx = 0
2753af6ab5fSopenharmony_ci    for task in test_tasks:
2763af6ab5fSopenharmony_ci        idx += 1
2773af6ab5fSopenharmony_ci        task_time_size_data = {
2783af6ab5fSopenharmony_ci            'Task Index': idx,
2793af6ab5fSopenharmony_ci            'Task Name': task.name
2803af6ab5fSopenharmony_ci        }
2813af6ab5fSopenharmony_ci        task_result_data = copy.deepcopy(task_time_size_data)
2823af6ab5fSopenharmony_ci        task_result_data['Task Type'] = ','.join(task.type)
2833af6ab5fSopenharmony_ci
2843af6ab5fSopenharmony_ci        full_compilation_debug, full_compilation_release = get_full_build_test_result(task, task_result_data,
2853af6ab5fSopenharmony_ci                                                                                      task_time_size_data)
2863af6ab5fSopenharmony_ci
2873af6ab5fSopenharmony_ci        get_incremental_build_test_result(task, task_result_data, task_time_size_data)
2883af6ab5fSopenharmony_ci
2893af6ab5fSopenharmony_ci        get_bytecode_har_build_test_result(task, task_result_data, task_time_size_data)
2903af6ab5fSopenharmony_ci
2913af6ab5fSopenharmony_ci        get_external_build_test_result(task, task_result_data, task_time_size_data)
2923af6ab5fSopenharmony_ci
2933af6ab5fSopenharmony_ci        get_preview_build_test_result(task, task_result_data)
2943af6ab5fSopenharmony_ci
2953af6ab5fSopenharmony_ci        get_other_test_result(task, task_result_data)
2963af6ab5fSopenharmony_ci
2973af6ab5fSopenharmony_ci        task_time_size_data['[Abc Size(byte)]\n[Debug]'] = full_compilation_debug.abc_size
2983af6ab5fSopenharmony_ci        task_time_size_data['[Abc Size(byte)]\n[Release]'] = full_compilation_release.abc_size
2993af6ab5fSopenharmony_ci        time_size_data.append(task_time_size_data)
3003af6ab5fSopenharmony_ci        result_data.append(task_result_data)
3013af6ab5fSopenharmony_ci
3023af6ab5fSopenharmony_ci    detail_data = {
3033af6ab5fSopenharmony_ci        'result_data': result_data,
3043af6ab5fSopenharmony_ci        'time_size_data': time_size_data
3053af6ab5fSopenharmony_ci    }
3063af6ab5fSopenharmony_ci    return detail_data
3073af6ab5fSopenharmony_ci
3083af6ab5fSopenharmony_ci
3093af6ab5fSopenharmony_cidef get_test_tesult(test, task_result_data, compilation_info):
3103af6ab5fSopenharmony_ci    debug_result = options.TaskResult.undefined
3113af6ab5fSopenharmony_ci    debug_runtime_result = options.TaskResult.undefined
3123af6ab5fSopenharmony_ci    release_result = options.TaskResult.undefined
3133af6ab5fSopenharmony_ci    release_runtime_result = options.TaskResult.undefined
3143af6ab5fSopenharmony_ci    if test in compilation_info.keys():
3153af6ab5fSopenharmony_ci        task_info = compilation_info[test]
3163af6ab5fSopenharmony_ci        debug_result = task_info.debug_info.result
3173af6ab5fSopenharmony_ci        debug_runtime_result = task_info.debug_info.runtime_result
3183af6ab5fSopenharmony_ci        release_result = task_info.release_info.result
3193af6ab5fSopenharmony_ci        release_runtime_result = task_info.release_info.runtime_result
3203af6ab5fSopenharmony_ci    task_result_data[f'[Debug]\n{test}'] = get_result_symbol(
3213af6ab5fSopenharmony_ci        debug_result)
3223af6ab5fSopenharmony_ci    task_result_data[f'[Debug-runtime]\n{test}'] = get_result_symbol(
3233af6ab5fSopenharmony_ci        debug_runtime_result)
3243af6ab5fSopenharmony_ci    task_result_data[f'[Release]\n{test}'] = get_result_symbol(
3253af6ab5fSopenharmony_ci        release_result)
3263af6ab5fSopenharmony_ci    task_result_data[f'[Release-runtime]\n{test}'] = get_result_symbol(
3273af6ab5fSopenharmony_ci        release_runtime_result)
3283af6ab5fSopenharmony_ci
3293af6ab5fSopenharmony_ci
3303af6ab5fSopenharmony_cidef get_full_build_test_result(task, task_result_data, task_time_size_data):
3313af6ab5fSopenharmony_ci    for test in full_compile_tests:
3323af6ab5fSopenharmony_ci        get_test_tesult(test, task_result_data, task.full_compilation_info)
3333af6ab5fSopenharmony_ci
3343af6ab5fSopenharmony_ci        if test == 'full_compile':
3353af6ab5fSopenharmony_ci            debug_test_time = 0
3363af6ab5fSopenharmony_ci            release_test_time = 0
3373af6ab5fSopenharmony_ci            if test in task.full_compilation_info.keys():
3383af6ab5fSopenharmony_ci                full_task_info = task.full_compilation_info[test]
3393af6ab5fSopenharmony_ci                debug_test_time = full_task_info.debug_info.time
3403af6ab5fSopenharmony_ci                release_test_time = full_task_info.release_info.time
3413af6ab5fSopenharmony_ci
3423af6ab5fSopenharmony_ci            task_time_size_data[
3433af6ab5fSopenharmony_ci                '[Full Compilation]\n[Debug]\n[Compilation Time(s)]'] = debug_test_time
3443af6ab5fSopenharmony_ci            task_time_size_data[
3453af6ab5fSopenharmony_ci                '[Full Compilation]\n[Release]\n[Compilation Time(s)]'] = release_test_time
3463af6ab5fSopenharmony_ci
3473af6ab5fSopenharmony_ci    return (task.full_compilation_info['full_compile'].debug_info,
3483af6ab5fSopenharmony_ci            task.full_compilation_info['full_compile'].release_info)
3493af6ab5fSopenharmony_ci
3503af6ab5fSopenharmony_ci
3513af6ab5fSopenharmony_cidef get_incremental_build_test_result(task, task_result_data, task_time_size_data):
3523af6ab5fSopenharmony_ci    for test in incremental_compile_tests:
3533af6ab5fSopenharmony_ci        get_test_tesult(test, task_result_data, task.incre_compilation_info)
3543af6ab5fSopenharmony_ci
3553af6ab5fSopenharmony_ci        if test == 'add_oneline':
3563af6ab5fSopenharmony_ci            debug_test_time = 0
3573af6ab5fSopenharmony_ci            release_test_time = 0
3583af6ab5fSopenharmony_ci            if test in task.incre_compilation_info.keys():
3593af6ab5fSopenharmony_ci                inc_task_info = task.incre_compilation_info[test]
3603af6ab5fSopenharmony_ci                debug_test_time = inc_task_info.debug_info.time
3613af6ab5fSopenharmony_ci                release_test_time = inc_task_info.release_info.time
3623af6ab5fSopenharmony_ci
3633af6ab5fSopenharmony_ci            task_time_size_data[
3643af6ab5fSopenharmony_ci                '[Incremental Compilation]\n[Debug]\n[Compilation Time(s)]'] = debug_test_time
3653af6ab5fSopenharmony_ci            task_time_size_data[
3663af6ab5fSopenharmony_ci                '[Incremental Compilation]\n[Release]\n[Compilation Time(s)]'] = release_test_time
3673af6ab5fSopenharmony_ci
3683af6ab5fSopenharmony_ci
3693af6ab5fSopenharmony_cidef get_bytecode_har_build_test_result(task, task_result_data, task_time_size_data):
3703af6ab5fSopenharmony_ci    for test in bytecode_har_compile_tests:
3713af6ab5fSopenharmony_ci        get_test_tesult(test, task_result_data, task.bytecode_har_compilation_info)
3723af6ab5fSopenharmony_ci
3733af6ab5fSopenharmony_ci        if test == 'build_bytecode_har':
3743af6ab5fSopenharmony_ci            debug_test_time = 0
3753af6ab5fSopenharmony_ci            release_test_time = 0
3763af6ab5fSopenharmony_ci            if test in task.bytecode_har_compilation_info.keys():
3773af6ab5fSopenharmony_ci                inc_task_info = task.bytecode_har_compilation_info[test]
3783af6ab5fSopenharmony_ci                debug_test_time = inc_task_info.debug_info.time
3793af6ab5fSopenharmony_ci                release_test_time = inc_task_info.release_info.time
3803af6ab5fSopenharmony_ci
3813af6ab5fSopenharmony_ci            task_time_size_data[
3823af6ab5fSopenharmony_ci                '[Bytecode Har Compilation]\n[Debug]\n[Compilation Time(s)]'] = debug_test_time
3833af6ab5fSopenharmony_ci            task_time_size_data[
3843af6ab5fSopenharmony_ci                '[Bytecode Har Compilation]\n[Release]\n[Compilation Time(s)]'] = release_test_time
3853af6ab5fSopenharmony_ci
3863af6ab5fSopenharmony_ci
3873af6ab5fSopenharmony_cidef get_external_build_test_result(task, task_result_data, task_time_size_data):
3883af6ab5fSopenharmony_ci    for test in external_compile_tests:
3893af6ab5fSopenharmony_ci        get_test_tesult(test, task_result_data, task.external_compilation_info)
3903af6ab5fSopenharmony_ci
3913af6ab5fSopenharmony_ci        if test == 'import_external_share_library':
3923af6ab5fSopenharmony_ci            debug_test_time = 0
3933af6ab5fSopenharmony_ci            release_test_time = 0
3943af6ab5fSopenharmony_ci            if test in task.external_compilation_info.keys():
3953af6ab5fSopenharmony_ci                inc_task_info = task.external_compilation_info[test]
3963af6ab5fSopenharmony_ci                debug_test_time = inc_task_info.debug_info.time
3973af6ab5fSopenharmony_ci                release_test_time = inc_task_info.release_info.time
3983af6ab5fSopenharmony_ci
3993af6ab5fSopenharmony_ci            task_time_size_data[
4003af6ab5fSopenharmony_ci                '[External Compilation]\n[Debug]\n[Compilation Time(s)]'] = debug_test_time
4013af6ab5fSopenharmony_ci            task_time_size_data[
4023af6ab5fSopenharmony_ci                '[External Compilation]\n[Release]\n[Compilation Time(s)]'] = release_test_time
4033af6ab5fSopenharmony_ci
4043af6ab5fSopenharmony_ci
4053af6ab5fSopenharmony_cidef get_preview_build_test_result(task, task_result_data):
4063af6ab5fSopenharmony_ci    for test in preview_compile_tests:
4073af6ab5fSopenharmony_ci        result = options.TaskResult.undefined
4083af6ab5fSopenharmony_ci        runtime_result = options.TaskResult.undefined
4093af6ab5fSopenharmony_ci        if test in task.preview_compilation_info.keys():
4103af6ab5fSopenharmony_ci            task_info = task.preview_compilation_info[test]
4113af6ab5fSopenharmony_ci            result = task_info.result
4123af6ab5fSopenharmony_ci            runtime_result = task_info.runtime_result
4133af6ab5fSopenharmony_ci
4143af6ab5fSopenharmony_ci        task_result_data[f'{test}'] = get_result_symbol(result)
4153af6ab5fSopenharmony_ci        task_result_data[f'{test}-runtime'] = get_result_symbol(runtime_result)
4163af6ab5fSopenharmony_ci
4173af6ab5fSopenharmony_ci
4183af6ab5fSopenharmony_cidef get_other_test_result(task, task_result_data):
4193af6ab5fSopenharmony_ci    for test in other_tests:
4203af6ab5fSopenharmony_ci        result = options.TaskResult.undefined
4213af6ab5fSopenharmony_ci        runtime_result = options.TaskResult.undefined
4223af6ab5fSopenharmony_ci        if test in task.other_tests.keys():
4233af6ab5fSopenharmony_ci            task_info = task.other_tests[test]
4243af6ab5fSopenharmony_ci            result = task_info.result
4253af6ab5fSopenharmony_ci            runtime_result = task_info.runtime_result
4263af6ab5fSopenharmony_ci        task_result_data[f'{test}'] = get_result_symbol(result)
4273af6ab5fSopenharmony_ci        task_result_data[f'{test}-runtime'] = get_result_symbol(runtime_result)
4283af6ab5fSopenharmony_ci
4293af6ab5fSopenharmony_ci
4303af6ab5fSopenharmony_cidef rotate_data(df):
4313af6ab5fSopenharmony_ci    num_rows, num_cols = df.shape
4323af6ab5fSopenharmony_ci    rotated_df = pandas.DataFrame(columns=range(num_rows), index=range(num_cols))
4333af6ab5fSopenharmony_ci    for i in range(num_rows):
4343af6ab5fSopenharmony_ci        for j in range(num_cols):
4353af6ab5fSopenharmony_ci            rotated_df.iloc[j, i] = df.iloc[i, j]
4363af6ab5fSopenharmony_ci    return rotated_df
4373af6ab5fSopenharmony_ci
4383af6ab5fSopenharmony_ci
4393af6ab5fSopenharmony_cidef get_merge_data(rotated_df):
4403af6ab5fSopenharmony_ci    data = rotated_df.iloc[3:, :].values.tolist()
4413af6ab5fSopenharmony_ci    merged_data = []
4423af6ab5fSopenharmony_ci    for i in range(0, len(data) - 1, 2):
4433af6ab5fSopenharmony_ci        row = [value for sublist in zip(data[i], data[i + 1]) for value in sublist]
4443af6ab5fSopenharmony_ci        merged_data.append(row)
4453af6ab5fSopenharmony_ci    return merged_data
4463af6ab5fSopenharmony_ci
4473af6ab5fSopenharmony_ci
4483af6ab5fSopenharmony_cidef generate_content_section(section_title, tests, start_index, merged_data):
4493af6ab5fSopenharmony_ci    section_content = f'<tr><th rowspan={len(tests) * 2}>{section_title}</th>'
4503af6ab5fSopenharmony_ci    for index, item in enumerate(tests):
4513af6ab5fSopenharmony_ci        debug_result = ''.join([f'<th>{column}</th>' for column in merged_data[start_index]])
4523af6ab5fSopenharmony_ci        section_content = ''.join(
4533af6ab5fSopenharmony_ci            [section_content, f'<th rowspan="2">{item}</th><th>[Debug]</th>', debug_result, '</tr>'])
4543af6ab5fSopenharmony_ci        release_result = ''.join([f'<th>{column}</th>' for column in merged_data[start_index + 1]])
4553af6ab5fSopenharmony_ci        section_content = ''.join([section_content, '<tr><th>[Release]</th>', release_result, '</tr>'])
4563af6ab5fSopenharmony_ci        start_index += 2
4573af6ab5fSopenharmony_ci    return section_content, start_index
4583af6ab5fSopenharmony_ci
4593af6ab5fSopenharmony_ci
4603af6ab5fSopenharmony_cidef get_result_table_content(result_df_rotate):
4613af6ab5fSopenharmony_ci    start_index = 0
4623af6ab5fSopenharmony_ci    merged_data = get_merge_data(result_df_rotate)
4633af6ab5fSopenharmony_ci    # Full Compilation section
4643af6ab5fSopenharmony_ci    full_compile_section, start_index = generate_content_section("Full Compilation", full_compile_tests, start_index,
4653af6ab5fSopenharmony_ci                                                                 merged_data)
4663af6ab5fSopenharmony_ci    content = full_compile_section
4673af6ab5fSopenharmony_ci
4683af6ab5fSopenharmony_ci    # Incremental Compilation section
4693af6ab5fSopenharmony_ci    incremental_compile_section, start_index = generate_content_section("Incremental Compilation",
4703af6ab5fSopenharmony_ci                                                                        incremental_compile_tests, start_index,
4713af6ab5fSopenharmony_ci                                                                        merged_data)
4723af6ab5fSopenharmony_ci    content += incremental_compile_section
4733af6ab5fSopenharmony_ci
4743af6ab5fSopenharmony_ci    # Bytecode Har Compilation section
4753af6ab5fSopenharmony_ci    bytecode_har_compile_section, start_index = generate_content_section("Bytecode Har Compilation",
4763af6ab5fSopenharmony_ci                                                                          bytecode_har_compile_tests, start_index,
4773af6ab5fSopenharmony_ci                                                                          merged_data)
4783af6ab5fSopenharmony_ci    content += bytecode_har_compile_section
4793af6ab5fSopenharmony_ci
4803af6ab5fSopenharmony_ci    # External Compilation section
4813af6ab5fSopenharmony_ci    external_compile_section, start_index = generate_content_section("External Compilation",
4823af6ab5fSopenharmony_ci                                                                     external_compile_tests, start_index,
4833af6ab5fSopenharmony_ci                                                                     merged_data)
4843af6ab5fSopenharmony_ci    content += external_compile_section
4853af6ab5fSopenharmony_ci
4863af6ab5fSopenharmony_ci    content += f'<tr><th colspan=2 rowspan={len(preview_compile_tests)}>Preview Compilation</th>'
4873af6ab5fSopenharmony_ci    for index, item in enumerate(preview_compile_tests):
4883af6ab5fSopenharmony_ci        preview_result = ''.join([f'<th>{column}</th>' for column in merged_data[start_index]])
4893af6ab5fSopenharmony_ci        content = ''.join([content, f'<th>{item}</th>', preview_result, '</tr>'])
4903af6ab5fSopenharmony_ci        start_index = start_index + 1
4913af6ab5fSopenharmony_ci
4923af6ab5fSopenharmony_ci    # Other Test section
4933af6ab5fSopenharmony_ci    content += f'<tr><th colspan=2 rowspan={len(other_tests)}>Other Tests</th>'
4943af6ab5fSopenharmony_ci    for index, item in enumerate(other_tests):
4953af6ab5fSopenharmony_ci        other_result = ''.join([f'<th>{column}</th>' for column in merged_data[start_index]])
4963af6ab5fSopenharmony_ci        content = ''.join([content, f'<th>{item}</th>', other_result, '</tr>'])
4973af6ab5fSopenharmony_ci        start_index = start_index + 1
4983af6ab5fSopenharmony_ci
4993af6ab5fSopenharmony_ci    return content
5003af6ab5fSopenharmony_ci
5013af6ab5fSopenharmony_ci
5023af6ab5fSopenharmony_cidef generate_data_html(summary_data, detail_data):
5033af6ab5fSopenharmony_ci    # summary table
5043af6ab5fSopenharmony_ci    key_value_pairs = [
5053af6ab5fSopenharmony_ci        f'<tr><td>{key}</td><td>{value}</td></tr>' for key, value in summary_data.items()]
5063af6ab5fSopenharmony_ci    summary_table_content = ''.join(key_value_pairs)
5073af6ab5fSopenharmony_ci    summary_table = f'<table id=sdk>{summary_table_content}</table>'
5083af6ab5fSopenharmony_ci
5093af6ab5fSopenharmony_ci    # time and size table
5103af6ab5fSopenharmony_ci    time_size_data = detail_data.get('time_size_data')
5113af6ab5fSopenharmony_ci    time_size_df = pandas.DataFrame(time_size_data)
5123af6ab5fSopenharmony_ci
5133af6ab5fSopenharmony_ci    time_size_table_header = '<tr>' + \
5143af6ab5fSopenharmony_ci        ''.join(
5153af6ab5fSopenharmony_ci            [f'<th rowspan="2">{column}</th>' for column in time_size_df.columns[:2]])
5163af6ab5fSopenharmony_ci    time_size_table_header += '<th colspan="2">Full Compilation Time(s)</th>' + \
5173af6ab5fSopenharmony_ci                              f'<th colspan="2">Incremental Compilation Time(s)</th>' + \
5183af6ab5fSopenharmony_ci                              f'<th colspan="2">Bytecode Har Compilation Time(s)</th>' + \
5193af6ab5fSopenharmony_ci                              f'<th colspan="2">External Compilation Time(s)</th>' + \
5203af6ab5fSopenharmony_ci                              f'<th colspan="2">Abc Size(byte)</th></tr>'
5213af6ab5fSopenharmony_ci    time_size_table_sub_header = '<tr>' + \
5223af6ab5fSopenharmony_ci        f'<th>[Debug]</th><th>[Release]</th>' * 5 + '</tr>'
5233af6ab5fSopenharmony_ci
5243af6ab5fSopenharmony_ci    time_size_table_content = ''.join([
5253af6ab5fSopenharmony_ci        '<tr>' + ''.join([f'<td>{value}</td>' for _,
5263af6ab5fSopenharmony_ci                         value in row.items()]) + '</tr>'
5273af6ab5fSopenharmony_ci        for _, row in time_size_df.iterrows()
5283af6ab5fSopenharmony_ci    ])
5293af6ab5fSopenharmony_ci    time_size_table = f'<table id=sdk> \
5303af6ab5fSopenharmony_ci        {time_size_table_header}{time_size_table_sub_header}{time_size_table_content}</table>'
5313af6ab5fSopenharmony_ci
5323af6ab5fSopenharmony_ci    # result table
5333af6ab5fSopenharmony_ci    result_data = detail_data.get('result_data')
5343af6ab5fSopenharmony_ci    result_df = pandas.DataFrame(result_data)
5353af6ab5fSopenharmony_ci    result_df_rotate = rotate_data(result_df)
5363af6ab5fSopenharmony_ci
5373af6ab5fSopenharmony_ci    result_table_header = '<tr><th colspan="3">Task Index</th>' + \
5383af6ab5fSopenharmony_ci            ''.join(
5393af6ab5fSopenharmony_ci            [f'<th colspan="2">{column}</th>' for column in result_df.iloc[:, 0].tolist()]) + '</tr>'
5403af6ab5fSopenharmony_ci    result_table_header += '<tr><th colspan="3">Task Name</th>' + \
5413af6ab5fSopenharmony_ci           ''.join(
5423af6ab5fSopenharmony_ci               [f'<th colspan="2">{column}</th>' for column in result_df.iloc[:, 1].tolist()]) + '</tr>'
5433af6ab5fSopenharmony_ci    result_table_header += '<tr><th colspan="3">Task Type</th>' + \
5443af6ab5fSopenharmony_ci                           ''.join(
5453af6ab5fSopenharmony_ci                               [f'<th colspan="2">{column}</th>' for column in result_df.iloc[:, 2].tolist()]) + '</tr>'
5463af6ab5fSopenharmony_ci    result_table_sub_header = f"<tr><th colspan=3>Build && Run </th>{'<th>[build]</th><th>[runtime]</th>' * result_df.shape[0]}</tr>"
5473af6ab5fSopenharmony_ci    result_table_content = get_result_table_content(result_df_rotate)
5483af6ab5fSopenharmony_ci
5493af6ab5fSopenharmony_ci    result_table = f'<table id=sdk> \
5503af6ab5fSopenharmony_ci        {result_table_header}{result_table_sub_header}{result_table_content}</table>'
5513af6ab5fSopenharmony_ci
5523af6ab5fSopenharmony_ci    return summary_table, time_size_table, result_table
5533af6ab5fSopenharmony_ci
5543af6ab5fSopenharmony_ci
5553af6ab5fSopenharmony_cidef get_html_style():
5563af6ab5fSopenharmony_ci    html_style = '''
5573af6ab5fSopenharmony_ci         #sdk body {
5583af6ab5fSopenharmony_ci            font-family: Arial, sans-serif;
5593af6ab5fSopenharmony_ci            margin: 20px;
5603af6ab5fSopenharmony_ci        }
5613af6ab5fSopenharmony_ci        #sdk h2 {
5623af6ab5fSopenharmony_ci            color: #333;
5633af6ab5fSopenharmony_ci        }
5643af6ab5fSopenharmony_ci        #sdk {
5653af6ab5fSopenharmony_ci            border-collapse: collapse;
5663af6ab5fSopenharmony_ci            width: 100%;
5673af6ab5fSopenharmony_ci            margin-bottom: 20px;
5683af6ab5fSopenharmony_ci        }
5693af6ab5fSopenharmony_ci        #sdk th, #sdk td {
5703af6ab5fSopenharmony_ci            padding: 8px;
5713af6ab5fSopenharmony_ci            border: 1px solid #ddd;
5723af6ab5fSopenharmony_ci        }
5733af6ab5fSopenharmony_ci        #sdk th {
5743af6ab5fSopenharmony_ci            background-color: #f2f2f2;
5753af6ab5fSopenharmony_ci            font-weight: bold;
5763af6ab5fSopenharmony_ci        }
5773af6ab5fSopenharmony_ci        #sdk tr:nth-child(odd) {
5783af6ab5fSopenharmony_ci            background-color: #f9f9f9;
5793af6ab5fSopenharmony_ci        }
5803af6ab5fSopenharmony_ci    '''
5813af6ab5fSopenharmony_ci    return html_style
5823af6ab5fSopenharmony_ci
5833af6ab5fSopenharmony_ci
5843af6ab5fSopenharmony_cidef generate_report_html(summary_data, detail_data):
5853af6ab5fSopenharmony_ci    [summary_table, time_size_table, result_table] = generate_data_html(
5863af6ab5fSopenharmony_ci        summary_data, detail_data)
5873af6ab5fSopenharmony_ci    html_style = get_html_style()
5883af6ab5fSopenharmony_ci
5893af6ab5fSopenharmony_ci    html_content = f'''
5903af6ab5fSopenharmony_ci    <html>
5913af6ab5fSopenharmony_ci    <head>
5923af6ab5fSopenharmony_ci    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5933af6ab5fSopenharmony_ci    <style>
5943af6ab5fSopenharmony_ci    {html_style}
5953af6ab5fSopenharmony_ci    </style>
5963af6ab5fSopenharmony_ci    </head>
5973af6ab5fSopenharmony_ci    <body>
5983af6ab5fSopenharmony_ci    <h2>SDK Test Results</h2>
5993af6ab5fSopenharmony_ci    <h3>Summary</h3>
6003af6ab5fSopenharmony_ci    {summary_table}
6013af6ab5fSopenharmony_ci    <h3>Detail Information</h3>
6023af6ab5fSopenharmony_ci    <h4>Test Result</h4>
6033af6ab5fSopenharmony_ci    {result_table}
6043af6ab5fSopenharmony_ci    <h4>Compilation Time And Abc Size</h4>
6053af6ab5fSopenharmony_ci    {time_size_table}
6063af6ab5fSopenharmony_ci    <p>
6073af6ab5fSopenharmony_ci    Notes:<br>
6083af6ab5fSopenharmony_ci    1. Incremental compilation time refers to add-one line incremental compile.<br>
6093af6ab5fSopenharmony_ci    2. For details compile output or error message during compile, please refer to attachment of log file.<br>
6103af6ab5fSopenharmony_ci    3. For sdk commit tags, please refer to attachment of manifest file(to be added).
6113af6ab5fSopenharmony_ci    </p>
6123af6ab5fSopenharmony_ci    </body>
6133af6ab5fSopenharmony_ci    </html>
6143af6ab5fSopenharmony_ci    '''
6153af6ab5fSopenharmony_ci
6163af6ab5fSopenharmony_ci    daily_report_file = options.configs.get('output_html_file')
6173af6ab5fSopenharmony_ci    with open(daily_report_file, 'w', encoding='utf-8') as report:
6183af6ab5fSopenharmony_ci        report.write(html_content)
6193af6ab5fSopenharmony_ci
6203af6ab5fSopenharmony_ci
6213af6ab5fSopenharmony_cidef generate_log_file():
6223af6ab5fSopenharmony_ci    logger = logging.getLogger()
6233af6ab5fSopenharmony_ci    if not hasattr(logger.handlers[0], 'baseFilename'):
6243af6ab5fSopenharmony_ci        return
6253af6ab5fSopenharmony_ci    log_file = logger.handlers[0].baseFilename
6263af6ab5fSopenharmony_ci    logger.handlers[0].close()
6273af6ab5fSopenharmony_ci    output_log_file = options.configs.get('log_file')
6283af6ab5fSopenharmony_ci    os.rename(log_file, output_log_file)
6293af6ab5fSopenharmony_ci
6303af6ab5fSopenharmony_ci
6313af6ab5fSopenharmony_cidef generate_result_reports(test_result, test_tasks):
6323af6ab5fSopenharmony_ci    summary_data = generate_summary_data(test_result, test_tasks)
6333af6ab5fSopenharmony_ci    detail_data = generate_detail_data(test_tasks)
6343af6ab5fSopenharmony_ci    generate_report_html(summary_data, detail_data)
6353af6ab5fSopenharmony_ci    generate_log_file()
6363af6ab5fSopenharmony_ci
6373af6ab5fSopenharmony_ci
6383af6ab5fSopenharmony_cidef process_test_result(test_tasks, start_time):
6393af6ab5fSopenharmony_ci    test_result = TestResult()
6403af6ab5fSopenharmony_ci
6413af6ab5fSopenharmony_ci    collect_result(test_result, test_tasks, start_time)
6423af6ab5fSopenharmony_ci    print_result(test_result, test_tasks)
6433af6ab5fSopenharmony_ci    generate_result_reports(test_result, test_tasks)
6443af6ab5fSopenharmony_ci
645