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

31 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 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.ascend950.ascend950_handler import Ascend950Handler 

25 

26class ChipHandler: 

27 

28 def __init__(self): 

29 self.__support_chip_with_handler = { 

30 "910B" : {"regex": rf"910B\d", "handler": Ascend910BHandler()}, 

31 "910_93" : {"regex": "910_93", "handler": Ascend91093Handler()}, 

32 "950" : {"regex": "950", "handler": Ascend950Handler()} 

33 } 

34 

35 def get_support_chip_list(self): 

36 return list(self.__support_chip_with_handler.keys()) 

37 

38 def get_support_chip_regex(self, chip_type): 

39 if chip_type not in self.get_support_chip_list(): 

40 return None 

41 return self.__support_chip_with_handler.get(chip_type).get("regex") 

42 

43 def get_support_chip_regex_list(self): 

44 return [item.get("regex") for item in self.__support_chip_with_handler.values()] 

45 

46 def get_handler(self, chip_type_str): 

47 for support_type, item in self.__support_chip_with_handler.items(): 

48 if support_type in chip_type_str: 

49 return item.get("handler") 

50 return DeviceInfo() 

51 

52g_device_map = {} 

53def get_device(device_id=None): 

54 """get device by chip, default is DeviceInfo""" 

55 if device_id in g_device_map: 

56 return g_device_map[device_id] 

57 

58 if device_id is None: 

59 g_device_map[device_id] = DeviceInfo() 

60 else: 

61 chip_info = DeviceInfo().get_chip_info(device_id) 

62 g_device_map[device_id] = ChipHandler().get_handler(chip_info) 

63 

64 return g_device_map[device_id]