Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/src/asys/common/const.py: 98%

164 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-08-21 15:37 +0800

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3# ---------------------------------------------------------------------------- 

4# Copyright (c) 2025 Huawei Technologies Co., Ltd. 

5# 

6# Licensed under the Apache License, Version 2.0 (the "License"); 

7# you may not use this file except in compliance with the License. 

8# You may obtain a copy of the License at 

9# 

10# http://www.apache.org/licenses/LICENSE-2.0 

11# 

12# Unless required by applicable law or agreed to in writing, software 

13# distributed under the License is distributed on an "AS IS" BASIS, 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

15# See the License for the specific language governing permissions and 

16# limitations under the License. 

17# ---------------------------------------------------------------------------- 

18 

19import enum 

20from pathlib import Path 

21 

22PROCESSES_NUMBER = 4 

23DEVICE_ID_MIN = 0 

24DEVICE_ID_MAX = 63 

25MAX_CHAR_LINE = 100 

26 

27MEMORY_FREQUENCY = 1 

28HBM_FREQUENCY = 6 

29CONTROL_CPU_FREQUENCY = 2 

30AI_CORE_FREQUENCY = 7 

31 

32MEM_BANDWIDTH_USE = 5 

33HBM_BANDWIDTH_USE = 10 

34AI_CORE_USE = 2 

35AI_CPU_USE = 3 

36CONTROL_CPU_USE = 4 

37 

38NOT_SUPPORT = '-' 

39UNKNOWN = 'Unknown' 

40NONE = 'none' 

41 

42CANN_LOG_NAME = 'log' 

43ATRACE_LOG_NAME = 'atrace' 

44 

45REG_OFF = 0 

46REG_THREAD = 1 

47REG_STACK = 2 

48 

49HBM_MIN_TIMEOUT = 0 # detection side 

50CPU_MIN_TIMEOUT = 1 # detection 1s 

51DETECT_MAX_TIMEOUT = 604800 # one week 

52DETECT_DEFAULT_TIMEOUT = 600 

53 

54CHECK_BIN_MAX_TIMEOUT = 60 

55CHECK_BIN_DEFAULT_TIMEOUT = 10 

56 

57CPU_DETECT_ERROR_CODE_MIN = 500000 

58CPU_DETECT_ERROR_CODE_MAX = 599999 

59 

60ADDR_LEN_HEX = 18 # 0x 0000 0000 0000 0000 

61ADDR_BIT_LEN = 16 # 0000 0000 0000 0000 

62 

63GDB_LAYER_MAX = 32 

64 

65MAX_PERIOD = 2592000 # 30*24*3600 

66LP_MODE_NO = 0 

67LP_MODE_AIC = 1 

68LP_MODE_LP = 2 

69 

70# sigrtmin 

71SIGRTMIN = 34 

72STACKTRACE = 'stacktrace' 

73 

74DSMI_UB_PORT_NUM = 36 

75DL_PORT_RX_VL_NUM = 16 

76STATS_ITEM_NUM = 50 

77UBQOS_MAX_SL_NUM = 16 

78 

79UB_ENTIRE_STATUS_MAP = { 

80 0: "DSMI_UB_ALL_PORT_NO_LINK (All ports have no link)", 

81 1: "DSMI_UB_ALL_PORT_LINK (All ports have link)", 

82 2: "DSMI_UB_PARTIAL_PORT_LINK (Partial ports have link)", 

83 3: "DSMI_UB_NO_NEED_LINK (No link required)" 

84} 

85 

86UB_PORT_STATUS_MAP = { 

87 0: "DSMI_UB_PORT_STATUS_INITIAL (Initial status)", 

88 1: "DSMI_UB_PORT_STATUS_FULL_LANE (Full lane normal)", 

89 2: "DSMI_UB_PORT_STATUS_PARTIAL_LANE (Partial lane normal)", 

90 3: "DSMI_UB_PORT_STATUS_NONE_LANE (No lane normal)" 

91} 

92 

93BALANCE_ALGORITHM_MAP = { 

94 1: "Hash by lower 2 bits of address (only check address low 2 bits)", 

95 2: "Hash by multiple bits of address (check multiple address bits)", 

96 0: "Reserved/Unspecified algorithm", 

97} 

98 

99GET_DEVICES_INFO_TIMEOUT = 10 

100 

101ALL_NOT_SUPPORTED_CHIP_TYPE = 'NULL' 

102ALL_SUPPORTED_CHIP_TYPE = 'ALL' 

103 

104CONFIG_TABLE_FILE = Path(__file__).parent.parent / 'conf' / 'config_table.csv' 

105 

106 

107class ScreenResult(enum.Enum): 

108 PASS = 'Pass' 

109 FAIL = 'Fail' 

110 WARN = 'Warn' 

111 

112 

113class CannPkg: 

114 firmware = 'firmware' 

115 driver = 'driver' 

116 runtime = 'runtime' 

117 ge_compiler = 'ge-compiler' 

118 bisheng_compiler = 'bisheng-compiler' 

119 toolkit = 'oam_tools' 

120 dvpp = 'dvpp' 

121 aoe = 'aoe' 

122 hccl = 'hccl' 

123 ncs = 'ncs' 

124 opbase = 'opbase' 

125 ops_cv = 'ops_cv' 

126 ops_legacy = 'ops_legacy' 

127 ops_math = 'ops_math' 

128 ops_nn = 'ops_nn' 

129 ops_transformer = 'ops_transformer' 

130 

131 @classmethod 

132 def get_all_pkg_list(cls): 

133 return [cls.firmware, cls.driver, cls.runtime, cls.ge_compiler, cls.bisheng_compiler, 

134 cls.toolkit, cls.dvpp, cls.aoe, cls.hccl, cls.ncs, cls.opbase, cls.ops_cv, 

135 cls.ops_legacy, cls.ops_math, cls.ops_nn, cls.ops_transformer] 

136 

137 

138class Singleton(type): 

139 """ Singleton class """ 

140 _instances = {} 

141 

142 def __call__(cls, *args, **kwargs): 

143 if cls not in Singleton._instances: 

144 Singleton._instances[cls] = super().__call__(*args, **kwargs) 

145 return Singleton._instances[cls] 

146 

147 def clear(cls): 

148 try: 

149 del Singleton._instances[cls] 

150 except KeyError: 

151 pass 

152 

153 

154class RetCode(enum.Enum): 

155 SUCCESS = 0 

156 FAILED = 1 

157 ARG_PATH_INVALID = 2 

158 ARG_EMPTY_STRING = 3 

159 ARG_SAPCE_STRING = 4 

160 ARG_ILLEGAL_STRING = 5 

161 ARG_NO_EXIST_DIR = 6 

162 ARG_NO_EXECUTABLE = 7 

163 ARG_NO_WRITABLE_PERMISSION = 8 

164 ARG_CREATE_DIR_FAILED = 9 

165 READ_FILE_FAILED = 10 

166 PERMISSION_FAILED = 11 

167 

168 

169class ConfigOptionName(enum.Enum): 

170 CHIP_NAME = 'chip_name' 

171 POWER = 'power' 

172 TEMPERATURE = 'temperature' 

173 HEALTH = 'health' 

174 ACPU_CNT = 'acpu_cnt' 

175 ACPU_USAGE = 'acpu_usage' 

176 CCPU_USAGE = 'ccpu_usage' 

177 CCPU_CNT = 'ccpu_cnt' 

178 CCPU_FREQUENCY = 'ccpu_frequency' 

179 CCPU_VOLTAGE = 'ccpu_voltage' 

180 AIC_CNT = 'aic_cnt' 

181 AIC_USAGE = 'aic_usage' 

182 AIC_FREQUENCY = 'aic_frequency' 

183 AIC_VOLTAGE = 'aic_voltage' 

184 BUS_VOLTAGE = 'bus_voltage' 

185 CPU_FREQUENCY = 'cpu_frequency' 

186 RING_FREQUENCY = 'ring_frequency' 

187 MATA_FREQUENCY = 'mata_frequency' 

188 L2BUFFER_FREQUENCY = 'l2buffer_frequency' 

189 DDR_TOTAL = 'ddr_total' 

190 DDR_USED = 'ddr_used' 

191 DDR_BANDWIDTH = 'ddr_bandwidth' 

192 DDR_FREQUENCY = 'ddr_frequency' 

193 HBM_TOTAL = 'hbm_total' 

194 HBM_USED = 'hbm_used' 

195 HBM_BANDWIDTH_USE = 'hbm_bandwidth_usage' 

196 HBM_FREQUENCY = 'hbm_frequency' 

197 HBM_VOLTAGE = 'hbm_voltage' 

198 

199 

200class ConfigOperateType(enum.Enum): 

201 GET = 'get' 

202 SET = 'set' 

203 RESTORE = 'restore' 

204 

205 

206class Constants: 

207 @property 

208 def help_cmd(self): 

209 return 'help' 

210 

211 @property 

212 def collect_cmd(self): 

213 return 'collect' 

214 

215 @property 

216 def launch_cmd(self): 

217 return 'launch' 

218 

219 @property 

220 def info_cmd(self): 

221 return 'info' 

222 

223 @property 

224 def diagnose_cmd(self): 

225 return 'diagnose' 

226 

227 @property 

228 def health_cmd(self): 

229 return 'health' 

230 

231 @property 

232 def analyze_cmd(self): 

233 return 'analyze' 

234 

235 @property 

236 def config_cmd(self): 

237 return 'config' 

238 

239 @property 

240 def profiling_cmd(self): 

241 return 'profiling' 

242 

243 @property 

244 def cmd_set(self): 

245 return [self.help_cmd, self.collect_cmd, self.launch_cmd, self.info_cmd, self.diagnose_cmd, self.health_cmd, 

246 self.analyze_cmd, self.config_cmd, self.profiling_cmd] 

247 

248 

249consts = Constants()