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: utils for test suite
193af6ab5fSopenharmony_ci"""
203af6ab5fSopenharmony_ci
213af6ab5fSopenharmony_ciimport gzip
223af6ab5fSopenharmony_ciimport logging
233af6ab5fSopenharmony_ciimport os
243af6ab5fSopenharmony_ciimport re
253af6ab5fSopenharmony_ciimport shutil
263af6ab5fSopenharmony_ciimport subprocess
273af6ab5fSopenharmony_ciimport sys
283af6ab5fSopenharmony_ciimport time
293af6ab5fSopenharmony_ciimport zipfile
303af6ab5fSopenharmony_ci
313af6ab5fSopenharmony_cifrom PIL import Image
323af6ab5fSopenharmony_ci
333af6ab5fSopenharmony_ciimport options
343af6ab5fSopenharmony_ci
353af6ab5fSopenharmony_ci
363af6ab5fSopenharmony_cidef get_log_level(arg_log_level):
373af6ab5fSopenharmony_ci    log_level_dict = {
383af6ab5fSopenharmony_ci        'debug': logging.DEBUG,
393af6ab5fSopenharmony_ci        'info': logging.INFO,
403af6ab5fSopenharmony_ci        'warn': logging.WARN,
413af6ab5fSopenharmony_ci        'error': logging.ERROR
423af6ab5fSopenharmony_ci    }
433af6ab5fSopenharmony_ci    if arg_log_level not in log_level_dict.keys():
443af6ab5fSopenharmony_ci        return logging.ERROR  # use error as default log level
453af6ab5fSopenharmony_ci    else:
463af6ab5fSopenharmony_ci        return log_level_dict[arg_log_level]
473af6ab5fSopenharmony_ci
483af6ab5fSopenharmony_ci
493af6ab5fSopenharmony_cidef init_logger(log_level, log_file):
503af6ab5fSopenharmony_ci    logging.basicConfig(filename=log_file,
513af6ab5fSopenharmony_ci                        level=get_log_level(log_level),
523af6ab5fSopenharmony_ci                        encoding=get_encoding(),
533af6ab5fSopenharmony_ci                        format='[%(asctime)s %(filename)s:%(lineno)d]: [%(levelname)s] %(message)s')
543af6ab5fSopenharmony_ci    logging.info("Test command:")
553af6ab5fSopenharmony_ci    logging.info(" ".join(sys.argv))
563af6ab5fSopenharmony_ci
573af6ab5fSopenharmony_ci
583af6ab5fSopenharmony_cidef get_encoding():
593af6ab5fSopenharmony_ci    if is_windows():
603af6ab5fSopenharmony_ci        return 'utf-8'
613af6ab5fSopenharmony_ci    else:
623af6ab5fSopenharmony_ci        return sys.getfilesystemencoding()
633af6ab5fSopenharmony_ci
643af6ab5fSopenharmony_ci
653af6ab5fSopenharmony_cidef check_zip_file(file_path):
663af6ab5fSopenharmony_ci    try:
673af6ab5fSopenharmony_ci        if zipfile.is_zipfile(file_path):
683af6ab5fSopenharmony_ci            with zipfile.ZipFile(file_path, 'r'):
693af6ab5fSopenharmony_ci                return True
703af6ab5fSopenharmony_ci        else:
713af6ab5fSopenharmony_ci            return False
723af6ab5fSopenharmony_ci    except Exception as e:
733af6ab5fSopenharmony_ci        print(e)
743af6ab5fSopenharmony_ci        return False
753af6ab5fSopenharmony_ci
763af6ab5fSopenharmony_ci
773af6ab5fSopenharmony_cidef check_gzip_file(file_path):
783af6ab5fSopenharmony_ci    try:
793af6ab5fSopenharmony_ci        with gzip.open(file_path, 'rb') as gzfile:
803af6ab5fSopenharmony_ci            gzfile.read(1)
813af6ab5fSopenharmony_ci    except Exception as e:
823af6ab5fSopenharmony_ci        print(e)
833af6ab5fSopenharmony_ci        return False
843af6ab5fSopenharmony_ci    return True
853af6ab5fSopenharmony_ci
863af6ab5fSopenharmony_ci
873af6ab5fSopenharmony_cidef is_windows():
883af6ab5fSopenharmony_ci    return sys.platform == 'win32' or sys.platform == 'cygwin'
893af6ab5fSopenharmony_ci
903af6ab5fSopenharmony_ci
913af6ab5fSopenharmony_cidef is_mac():
923af6ab5fSopenharmony_ci    return sys.platform == 'darwin'
933af6ab5fSopenharmony_ci
943af6ab5fSopenharmony_ci
953af6ab5fSopenharmony_cidef is_linux():
963af6ab5fSopenharmony_ci    return sys.platform == 'linux'
973af6ab5fSopenharmony_ci
983af6ab5fSopenharmony_ci
993af6ab5fSopenharmony_cidef get_time_string():
1003af6ab5fSopenharmony_ci    return time.strftime('%Y%m%d-%H%M%S')
1013af6ab5fSopenharmony_ci
1023af6ab5fSopenharmony_ci
1033af6ab5fSopenharmony_cidef is_esmodule(hap_type):
1043af6ab5fSopenharmony_ci    # if hap_type is stage, it's esmodule.
1053af6ab5fSopenharmony_ci    # if hap_type is js, fa, compatible 8, it's js_bundle
1063af6ab5fSopenharmony_ci    return 'stage' in hap_type
1073af6ab5fSopenharmony_ci
1083af6ab5fSopenharmony_ci
1093af6ab5fSopenharmony_cidef is_file_timestamps_same(file_a, file_b):
1103af6ab5fSopenharmony_ci    file_a_mtime = os.stat(file_a).st_mtime
1113af6ab5fSopenharmony_ci    file_b_mtime = os.stat(file_b).st_mtime
1123af6ab5fSopenharmony_ci    return file_a_mtime == file_b_mtime
1133af6ab5fSopenharmony_ci
1143af6ab5fSopenharmony_ci
1153af6ab5fSopenharmony_cidef is_file_name_same(file_a, file_b):
1163af6ab5fSopenharmony_ci    file_a_name = os.path.basename(file_a)
1173af6ab5fSopenharmony_ci    file_b_name = os.path.basename(file_b)
1183af6ab5fSopenharmony_ci    return file_a_name == file_b_name
1193af6ab5fSopenharmony_ci
1203af6ab5fSopenharmony_ci
1213af6ab5fSopenharmony_cidef add_executable_permission(file_path):
1223af6ab5fSopenharmony_ci    current_mode = os.stat(file_path).st_mode
1233af6ab5fSopenharmony_ci    new_mode = current_mode | 0o111
1243af6ab5fSopenharmony_ci    os.chmod(file_path, new_mode)
1253af6ab5fSopenharmony_ci
1263af6ab5fSopenharmony_ci
1273af6ab5fSopenharmony_cidef replace_file_content(file_path, old_content, new_content):
1283af6ab5fSopenharmony_ci    with open(file_path, 'r+', encoding='utf-8') as file:
1293af6ab5fSopenharmony_ci        content = file.read()
1303af6ab5fSopenharmony_ci        content = content.replace(old_content, new_content)
1313af6ab5fSopenharmony_ci        file.seek(0)
1323af6ab5fSopenharmony_ci        file.write(content)
1333af6ab5fSopenharmony_ci        file.truncate()
1343af6ab5fSopenharmony_ci
1353af6ab5fSopenharmony_ci
1363af6ab5fSopenharmony_cidef run_cmd(cmd):
1373af6ab5fSopenharmony_ci    logging.debug(f'cmd: {cmd}')
1383af6ab5fSopenharmony_ci    result = subprocess.run(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
1393af6ab5fSopenharmony_ci    logging.debug(f'cmd stdout: {result.stdout}')
1403af6ab5fSopenharmony_ci    logging.error(f'cmd stderr: {result.stderr}')
1413af6ab5fSopenharmony_ci    return result
1423af6ab5fSopenharmony_ci
1433af6ab5fSopenharmony_ci
1443af6ab5fSopenharmony_cidef move_picture(task, image_name):
1453af6ab5fSopenharmony_ci    pic_save_dic = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'pictures')
1463af6ab5fSopenharmony_ci    if not os.path.exists(pic_save_dic):
1473af6ab5fSopenharmony_ci        os.mkdir(pic_save_dic)
1483af6ab5fSopenharmony_ci
1493af6ab5fSopenharmony_ci    pic_save_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'pictures/{task.name}')
1503af6ab5fSopenharmony_ci    if not os.path.exists(pic_save_path):
1513af6ab5fSopenharmony_ci        os.mkdir(pic_save_path)
1523af6ab5fSopenharmony_ci
1533af6ab5fSopenharmony_ci    pic_file_path = os.path.join(pic_save_path, f'{image_name}.jpeg')
1543af6ab5fSopenharmony_ci    if os.path.exists(pic_file_path):
1553af6ab5fSopenharmony_ci        os.remove(pic_file_path)
1563af6ab5fSopenharmony_ci
1573af6ab5fSopenharmony_ci    shutil.move(f'{image_name}.jpeg', pic_save_path)
1583af6ab5fSopenharmony_ci
1593af6ab5fSopenharmony_ci
1603af6ab5fSopenharmony_cidef get_running_screenshot(task, image_name, is_debug, module=''):
1613af6ab5fSopenharmony_ci    logging.debug(f'Getting runtime screenshot of {task.name}')
1623af6ab5fSopenharmony_ci    run_cmd(['hdc', 'shell', 'power-shell', 'wakeup;power-shell', 'setmode 602'])
1633af6ab5fSopenharmony_ci    run_cmd(['hdc', 'shell', 'uinput', '-T', '-m', '420', '1000', '420',
1643af6ab5fSopenharmony_ci             '400;uinput', '-T', '-m', '420', '400', '420', '1000'])
1653af6ab5fSopenharmony_ci
1663af6ab5fSopenharmony_ci    module_path = get_module_path(task, module)
1673af6ab5fSopenharmony_ci    output_path_signed = get_output_path(task, module, options.OutputType.signed)
1683af6ab5fSopenharmony_ci    build_path = os.path.join(task.path, *module_path, *task.build_path)
1693af6ab5fSopenharmony_ci    out_path = os.path.join(build_path, *output_path_signed)
1703af6ab5fSopenharmony_ci
1713af6ab5fSopenharmony_ci    result = run_cmd(['hdc', 'install', f'{out_path}'])
1723af6ab5fSopenharmony_ci    # After importing Hsp, Hap needs to install the Hsp package first before installing the Hap package.
1733af6ab5fSopenharmony_ci    not_hsp_error_message = 'Failed to install the HAP or HSP because the dependent module does not exist'
1743af6ab5fSopenharmony_ci    if not_hsp_error_message in result.stdout:
1753af6ab5fSopenharmony_ci        hsp_output_path = task.backup_info.hsp_signed_output_debug if is_debug \
1763af6ab5fSopenharmony_ci            else task.backup_info.hsp_signed_output_release
1773af6ab5fSopenharmony_ci        run_cmd(['hdc', 'install', f'{hsp_output_path}'])
1783af6ab5fSopenharmony_ci        time.sleep(3)
1793af6ab5fSopenharmony_ci    not_out_hsp_error_message = 'outHsp does not exist'
1803af6ab5fSopenharmony_ci    if not_out_hsp_error_message in result.stdout:
1813af6ab5fSopenharmony_ci        external_hsp_output_path = task.backup_info.external_hsp_signed_output_debug if is_debug \
1823af6ab5fSopenharmony_ci            else task.backup_info.external_hsp_signed_output_release
1833af6ab5fSopenharmony_ci        run_cmd(['hdc', 'install', f'{external_hsp_output_path}'])
1843af6ab5fSopenharmony_ci        time.sleep(3)
1853af6ab5fSopenharmony_ci
1863af6ab5fSopenharmony_ci    if not_hsp_error_message in result.stdout or not_out_hsp_error_message in result.stdout:
1873af6ab5fSopenharmony_ci        run_cmd(['hdc', 'install', f'{out_path}'])
1883af6ab5fSopenharmony_ci
1893af6ab5fSopenharmony_ci    run_cmd(['hdc', 'shell', 'aa', 'start', '-a', f'{task.ability_name}', '-b', f'{task.bundle_name}'])
1903af6ab5fSopenharmony_ci    time.sleep(3)
1913af6ab5fSopenharmony_ci
1923af6ab5fSopenharmony_ci    screen_path = f'/data/local/tmp/{image_name}.jpeg'
1933af6ab5fSopenharmony_ci    run_cmd(['hdc', 'shell', 'snapshot_display', '-f', f'{screen_path}'])
1943af6ab5fSopenharmony_ci    time.sleep(3)
1953af6ab5fSopenharmony_ci
1963af6ab5fSopenharmony_ci    run_cmd(['hdc', 'file', 'recv', f'{screen_path}', f'{image_name}.jpeg'])
1973af6ab5fSopenharmony_ci    run_cmd(['hdc', 'shell', 'aa', 'force-stop', f'{task.bundle_name}'])
1983af6ab5fSopenharmony_ci    run_cmd(['hdc', 'shell', 'bm', 'uninstall', '-n', f'{task.bundle_name}'])
1993af6ab5fSopenharmony_ci
2003af6ab5fSopenharmony_ci    move_picture(task, image_name)
2013af6ab5fSopenharmony_ci
2023af6ab5fSopenharmony_ci
2033af6ab5fSopenharmony_cidef compare_screenshot(runtime_picture_path, picture_reference_path, threshold=0.95):
2043af6ab5fSopenharmony_ci    try:
2053af6ab5fSopenharmony_ci        runtime_picture = Image.open(runtime_picture_path).convert('RGB')
2063af6ab5fSopenharmony_ci        picture_reference_path = Image.open(picture_reference_path).convert('RGB')
2073af6ab5fSopenharmony_ci    except Exception:
2083af6ab5fSopenharmony_ci        logging.error(f'open image {runtime_picture_path} failed')
2093af6ab5fSopenharmony_ci        return False
2103af6ab5fSopenharmony_ci    runtime_picture.thumbnail((256, 256))
2113af6ab5fSopenharmony_ci    picture_reference_path.thumbnail((256, 256))
2123af6ab5fSopenharmony_ci
2133af6ab5fSopenharmony_ci    runtime_pixel = runtime_picture.load()
2143af6ab5fSopenharmony_ci    reference_pixel = picture_reference_path.load()
2153af6ab5fSopenharmony_ci    width, height = runtime_picture.size
2163af6ab5fSopenharmony_ci
2173af6ab5fSopenharmony_ci    similar_pixels = 0
2183af6ab5fSopenharmony_ci    total_pixels = width * height
2193af6ab5fSopenharmony_ci
2203af6ab5fSopenharmony_ci    for x in range(width):
2213af6ab5fSopenharmony_ci        for y in range(height):
2223af6ab5fSopenharmony_ci            if runtime_pixel[x, y] == reference_pixel[x, y]:
2233af6ab5fSopenharmony_ci                similar_pixels += 1
2243af6ab5fSopenharmony_ci
2253af6ab5fSopenharmony_ci    similarity = similar_pixels / total_pixels
2263af6ab5fSopenharmony_ci
2273af6ab5fSopenharmony_ci    if similarity >= threshold:
2283af6ab5fSopenharmony_ci        return True
2293af6ab5fSopenharmony_ci    else:
2303af6ab5fSopenharmony_ci        return False
2313af6ab5fSopenharmony_ci
2323af6ab5fSopenharmony_ci
2333af6ab5fSopenharmony_cidef verify_runtime(task, picture_name):
2343af6ab5fSopenharmony_ci    pic_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
2353af6ab5fSopenharmony_ci                            f'pictures/{task.name}/{picture_name}.jpeg')
2363af6ab5fSopenharmony_ci    pic_path_reference = os.path.join(os.path.dirname(os.path.abspath(__file__)),
2373af6ab5fSopenharmony_ci                                      f'pictures_reference/{task.name}/{picture_name}.jpeg')
2383af6ab5fSopenharmony_ci    passed = compare_screenshot(pic_path, pic_path_reference, threshold=0.95)
2393af6ab5fSopenharmony_ci    if not passed:
2403af6ab5fSopenharmony_ci        logging.error(f'{task.name} get error when running')
2413af6ab5fSopenharmony_ci        return False
2423af6ab5fSopenharmony_ci    return True
2433af6ab5fSopenharmony_ci
2443af6ab5fSopenharmony_ci
2453af6ab5fSopenharmony_cidef add_content_to_file(file_path, head_content, tail_content):
2463af6ab5fSopenharmony_ci    if not head_content and not tail_content:
2473af6ab5fSopenharmony_ci        logging.error('Both head_content and tail_content are missing,please check!')
2483af6ab5fSopenharmony_ci        return
2493af6ab5fSopenharmony_ci
2503af6ab5fSopenharmony_ci    with open(file_path, 'r+', encoding='utf-8') as file:
2513af6ab5fSopenharmony_ci        old_content = file.read()
2523af6ab5fSopenharmony_ci        file.seek(0)
2533af6ab5fSopenharmony_ci        if head_content:
2543af6ab5fSopenharmony_ci            file.write(head_content)
2553af6ab5fSopenharmony_ci        file.write(old_content)
2563af6ab5fSopenharmony_ci        if tail_content:
2573af6ab5fSopenharmony_ci            file.write(tail_content)
2583af6ab5fSopenharmony_ci        file.truncate()
2593af6ab5fSopenharmony_ci
2603af6ab5fSopenharmony_ci
2613af6ab5fSopenharmony_cidef remove_content_from_file(file_path, head_content, tail_content):
2623af6ab5fSopenharmony_ci    if not head_content and not tail_content:
2633af6ab5fSopenharmony_ci        logging.error('Both head_content and tail_content are missing,please check!')
2643af6ab5fSopenharmony_ci        return
2653af6ab5fSopenharmony_ci
2663af6ab5fSopenharmony_ci    with open(file_path, 'r+', encoding='utf-8') as file:
2673af6ab5fSopenharmony_ci        old_content = file.read()
2683af6ab5fSopenharmony_ci        if head_content and old_content.startswith(head_content):
2693af6ab5fSopenharmony_ci            old_content = old_content[len(head_content):]
2703af6ab5fSopenharmony_ci        elif head_content:
2713af6ab5fSopenharmony_ci            logging.debug(f'Cannot find the head content to remove in {file_path}')
2723af6ab5fSopenharmony_ci
2733af6ab5fSopenharmony_ci        if tail_content and old_content.endswith(tail_content):
2743af6ab5fSopenharmony_ci            old_content = old_content[:-len(tail_content)]
2753af6ab5fSopenharmony_ci        elif tail_content:
2763af6ab5fSopenharmony_ci            logging.debug(f'Cannot find the tail content to remove in {file_path}')
2773af6ab5fSopenharmony_ci
2783af6ab5fSopenharmony_ci        file.seek(0)
2793af6ab5fSopenharmony_ci        file.write(old_content)
2803af6ab5fSopenharmony_ci        file.truncate()
2813af6ab5fSopenharmony_ci
2823af6ab5fSopenharmony_ci
2833af6ab5fSopenharmony_cidef extract_library_names(import_statement):
2843af6ab5fSopenharmony_ci    pattern = r"import\s+{[^}]+}\s+from\s+'([^']+)';"
2853af6ab5fSopenharmony_ci    matches = re.findall(pattern, import_statement)
2863af6ab5fSopenharmony_ci
2873af6ab5fSopenharmony_ci    return matches[0]
2883af6ab5fSopenharmony_ci
2893af6ab5fSopenharmony_ci
2903af6ab5fSopenharmony_cidef get_module_name(task, module=''):
2913af6ab5fSopenharmony_ci    module_mapping = {
2923af6ab5fSopenharmony_ci        'Hap': task.hap_module,
2933af6ab5fSopenharmony_ci        'Har': task.har_module,
2943af6ab5fSopenharmony_ci        'BytecodeHar': task.har_module,
2953af6ab5fSopenharmony_ci        'Hsp': task.hsp_module,
2963af6ab5fSopenharmony_ci        'Cpp': task.cpp_module
2973af6ab5fSopenharmony_ci    }
2983af6ab5fSopenharmony_ci
2993af6ab5fSopenharmony_ci    return module_mapping.get(module, module_mapping['Hap'])
3003af6ab5fSopenharmony_ci
3013af6ab5fSopenharmony_ci
3023af6ab5fSopenharmony_cidef get_module_path(task, module=''):
3033af6ab5fSopenharmony_ci    module_mapping = {
3043af6ab5fSopenharmony_ci        'Hap': task.hap_module_path,
3053af6ab5fSopenharmony_ci        'Har': task.har_module_path,
3063af6ab5fSopenharmony_ci        'BytecodeHar': task.har_module_path,
3073af6ab5fSopenharmony_ci        'Hsp': task.hsp_module_path,
3083af6ab5fSopenharmony_ci        'Cpp': task.cpp_module_path
3093af6ab5fSopenharmony_ci    }
3103af6ab5fSopenharmony_ci
3113af6ab5fSopenharmony_ci    return module_mapping.get(module, module_mapping['Hap'])
3123af6ab5fSopenharmony_ci
3133af6ab5fSopenharmony_ci
3143af6ab5fSopenharmony_cidef get_output_path_unsigned(task, module=''):
3153af6ab5fSopenharmony_ci    output_path_mapping = {
3163af6ab5fSopenharmony_ci        "Hap": task.hap_output_path,
3173af6ab5fSopenharmony_ci        "Hsp": task.hsp_output_path,
3183af6ab5fSopenharmony_ci        "Cpp": task.cpp_output_path
3193af6ab5fSopenharmony_ci    }
3203af6ab5fSopenharmony_ci    return output_path_mapping.get(module, output_path_mapping['Hap'])
3213af6ab5fSopenharmony_ci
3223af6ab5fSopenharmony_ci
3233af6ab5fSopenharmony_cidef get_output_path_signed(task, module=''):
3243af6ab5fSopenharmony_ci    output_path_mapping = {
3253af6ab5fSopenharmony_ci        "Hap": task.hap_output_path_signed,
3263af6ab5fSopenharmony_ci        "Hsp": task.hsp_output_path_signed,
3273af6ab5fSopenharmony_ci        "Cpp": task.cpp_output_path_signed
3283af6ab5fSopenharmony_ci    }
3293af6ab5fSopenharmony_ci    return output_path_mapping.get(module, output_path_mapping['Hap'])
3303af6ab5fSopenharmony_ci
3313af6ab5fSopenharmony_ci
3323af6ab5fSopenharmony_cidef get_output_path_har(task, module=''):
3333af6ab5fSopenharmony_ci    output_path_mapping = {
3343af6ab5fSopenharmony_ci        "Har": task.har_output_path_har,
3353af6ab5fSopenharmony_ci        "BytecodeHar": task.har_output_path_har,
3363af6ab5fSopenharmony_ci        "Hsp": task.hsp_output_path_har
3373af6ab5fSopenharmony_ci    }
3383af6ab5fSopenharmony_ci    return output_path_mapping.get(module, output_path_mapping['Har'])
3393af6ab5fSopenharmony_ci
3403af6ab5fSopenharmony_ci
3413af6ab5fSopenharmony_cidef get_output_path(task, module, output_type):
3423af6ab5fSopenharmony_ci    if output_type == options.OutputType.unsigned:
3433af6ab5fSopenharmony_ci        return get_output_path_unsigned(task, module)
3443af6ab5fSopenharmony_ci    elif output_type == options.OutputType.signed:
3453af6ab5fSopenharmony_ci        return get_output_path_signed(task, module)
3463af6ab5fSopenharmony_ci    else:
3473af6ab5fSopenharmony_ci        return get_output_path_har(task, module)
3483af6ab5fSopenharmony_ci
3493af6ab5fSopenharmony_ci
3503af6ab5fSopenharmony_cidef get_cache_extension(task_type):
3513af6ab5fSopenharmony_ci    cache_extension = ''
3523af6ab5fSopenharmony_ci    if 'stage' in task_type:
3533af6ab5fSopenharmony_ci        cache_extension = '.protoBin'
3543af6ab5fSopenharmony_ci    elif 'fa' in task_type or 'compatible8' in task_type:
3553af6ab5fSopenharmony_ci        cache_extension = '.temp.abc'
3563af6ab5fSopenharmony_ci    elif 'js' in task_type:
3573af6ab5fSopenharmony_ci        cache_extension = '.abc'
3583af6ab5fSopenharmony_ci
3593af6ab5fSopenharmony_ci    return cache_extension
3603af6ab5fSopenharmony_ci
3613af6ab5fSopenharmony_ci
3623af6ab5fSopenharmony_cidef file_contains_specified_fields(file_path, fields):
3633af6ab5fSopenharmony_ci    if not os.path.exists(file_path):
3643af6ab5fSopenharmony_ci        logging.error(f"File {file_path} doesn't exist")
3653af6ab5fSopenharmony_ci        return False
3663af6ab5fSopenharmony_ci    with open(file_path, 'r', encoding='utf-8') as file:
3673af6ab5fSopenharmony_ci        line = file.readline()
3683af6ab5fSopenharmony_ci        while line:
3693af6ab5fSopenharmony_ci            if fields in line:
3703af6ab5fSopenharmony_ci                return True
3713af6ab5fSopenharmony_ci            line = file.readline()
3723af6ab5fSopenharmony_ci    return False
373