Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/src/asys/common/chip_handler.py: 88%
32 statements
« prev ^ index » next coverage.py v7.15.3, created at 2026-08-11 18:39 +0800
« prev ^ index » next coverage.py v7.15.3, created at 2026-08-11 18:39 +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# ----------------------------------------------------------------------------
19import os
20from common.log import log_error
21from common.device import DeviceInfo
22from common.ascend910B.ascend910B_handler import Ascend910BHandler
23from common.ascend910_93.ascend91093_handler import Ascend91093Handler
24from common.ascend910_96.ascend91096_handler import Ascend91096Handler
25from common.ascend950.ascend950_handler import Ascend950Handler
27class ChipHandler:
29 def __init__(self):
30 self.__support_chip_with_handler = {
31 "910B" : {"regex": rf"910B\d", "handler": Ascend910BHandler()},
32 "910_93" : {"regex": "910_93", "handler": Ascend91093Handler()},
33 "910_96" : {"regex": "910_96", "handler": Ascend91096Handler()},
34 "950" : {"regex": "950", "handler": Ascend950Handler()}
35 }
37 def get_support_chip_list(self):
38 return list(self.__support_chip_with_handler.keys())
40 def get_support_chip_regex(self, chip_type):
41 if chip_type not in self.get_support_chip_list():
42 return None
43 return self.__support_chip_with_handler.get(chip_type).get("regex")
45 def get_support_chip_regex_list(self):
46 return [item.get("regex") for item in self.__support_chip_with_handler.values()]
48 def get_handler(self, chip_type_str):
49 for support_type, item in self.__support_chip_with_handler.items():
50 if support_type in chip_type_str:
51 return item.get("handler")
52 return DeviceInfo()
54g_device_map = {}
55def get_device(device_id=None):
56 """get device by chip, default is DeviceInfo"""
57 if device_id in g_device_map:
58 return g_device_map[device_id]
60 if device_id is None:
61 g_device_map[device_id] = DeviceInfo()
62 else:
63 chip_info = DeviceInfo().get_chip_info(device_id)
64 g_device_map[device_id] = ChipHandler().get_handler(chip_info)
66 return g_device_map[device_id]