Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/utils/msobjdump/msobjdump/utils.py: 100%
34 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-27 14:38 +0800
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-27 14:38 +0800
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3# ----------------------------------------------------------------------------------------------------------
4# Copyright (c) 2025 Huawei Technologies Co., Ltd.
5# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
6# CANN Open Software License Agreement Version 2.0 (the "License").
7# Please refer to the License for details. You may not use this file except in compliance with the License.
8# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
10# See LICENSE in the root of the software repository for the full text of the License.
11# ----------------------------------------------------------------------------------------------------------
13import os
14import re
15import shutil
16import subprocess
19def split_str_with_space(input_str: str) -> list:
20 result = re.split(r'\s+', input_str)
21 return [element for element in result if element != '']
24def get_str_between(input_str: str, sub_str_s: str, sub_str_e: str) -> str:
25 pattern = rf'{sub_str_s}(.*?){sub_str_e}'
26 result = re.search(pattern, input_str)
27 if result:
28 return result.group(1)
29 return ''
32def is_prefix_substring(str_check: str, str_lst: list) -> bool:
33 for lst_str in str_lst:
34 if str_check.lower().startswith(lst_str.lower()):
35 return True
36 return False
39def copy_file_src_exist(src_file: str, dest_file: str) -> None:
40 if not os.path.exists(src_file):
41 return
42 if not os.path.exists(os.path.dirname(dest_file)):
43 os.makedirs(os.path.dirname(dest_file))
44 shutil.copy(src_file, dest_file)
47def get_section_headers_in_file(file_name: str) -> str:
48 return subprocess.run(['readelf', '-SW', file_name], capture_output=True, text=True).stdout
51def get_symbols_in_file(file_name: str) -> str:
52 return subprocess.run(['readelf', '-sW', file_name], capture_output=True, text=True).stdout
55def get_all_section_symbols_in_file(file_name: str) -> str:
56 return subprocess.run(['readelf', '-aW', file_name], capture_output=True, text=True).stdout
59def get_o_file_from_a_file(file_path: str, file_name: str) -> str:
60 return subprocess.run(['ar', 'x', file_path, file_name], capture_output=True)
63def extract_aicore_binary_from_elf(input_file: str, output_file: str):
64 return subprocess.run(
65 ['llvm-objcopy', '-O', 'binary', '--only-section=.aicore_binary', input_file, output_file],
66 capture_output=True,
67 text=True
68 )