hil2.dut_cons
1import json 2 3from . import hil_errors 4 5 6# HIL DUT Connection ------------------------------------------------------------------# 7class HilDutCon: 8 """The HIL side of a DUT connection""" 9 10 def __init__(self, device: str, port: str): 11 """ 12 :param device: The name of the HIL device (ex: 'RearTester') 13 :param port: The port name on the HIL device (ex: 'DO7') 14 """ 15 self.device: str = device 16 self.port: str = port 17 18 @classmethod 19 def from_json(cls, hil_dut_con: dict) -> "HilDutCon": 20 """ 21 Create a HilDutCon instance from a JSON dictionary. 22 23 :param hil_dut_con: The JSON dictionary representing the HIL DUT connection 24 :return: A HilDutCon instance 25 """ 26 match hil_dut_con: 27 case {"device": device, "port": port}: 28 return cls(device, port) 29 case _: 30 error_msg = f"Invalid HIL DUT connection configuration: {hil_dut_con}" 31 raise hil_errors.ConfigurationError(error_msg) 32 33 34# Test DUT Connection -----------------------------------------------------------------# 35class DutCon: 36 """The tested side of a DUT connection""" 37 38 def __init__(self, connector: str, pin: int): 39 """ 40 :param connector: The name of the DUT connector (ex: 'J3') 41 :param pin: The pin number on the DUT connector (ex: 9) 42 """ 43 self.connector: str = connector 44 self.pin: int = pin 45 46 @classmethod 47 def from_json(cls, dut_con: dict) -> "DutCon": 48 """ 49 Create a DutCon instance from a JSON dictionary. 50 51 :param dut_con: The JSON dictionary representing the DUT connection 52 :return: A DutCon instance 53 """ 54 match dut_con: 55 case {"connector": connector, "pin": pin}: 56 return cls(connector, pin) 57 case _: 58 error_msg = f"Invalid DUT connection configuration: {dut_con}" 59 raise hil_errors.ConfigurationError(error_msg) 60 61 62# DUT Board Connections ---------------------------------------------------------------# 63class DutBoardCons: 64 def __init__(self, harness_connections: dict[DutCon, HilDutCon]): 65 """ 66 :param harness_connections: A dictionary mapping DUT connections to HIL connections 67 """ 68 self._harness_connections: dict[DutCon, HilDutCon] = harness_connections 69 70 @classmethod 71 def from_json(cls, harness_connections: list[dict]) -> "DutBoardCons": 72 """ 73 Create a DutBoardCons instance from a JSON dictionary. 74 75 :param harness_connections: A list of dictionaries representing the harness connections 76 :return: A DutBoardCons instance 77 """ 78 parsed_connections: dict[DutCon, HilDutCon] = {} 79 80 for con in harness_connections: 81 match con: 82 case {"dut": dut_con, "hil": hil_con}: 83 parsed_connections[DutCon.from_json(dut_con)] = HilDutCon.from_json( 84 hil_con 85 ) 86 case _: 87 error_msg = f"Invalid DUT board connection configuration: {con}" 88 raise hil_errors.ConfigurationError(error_msg) 89 90 return cls(parsed_connections) 91 92 def get_hil_device_connection(self, dut_con: DutCon) -> HilDutCon: 93 """ 94 Get the HIL device connection for a given DUT connection. 95 96 :param dut_con: The DUT connection for which to retrieve the HIL device connection 97 :return: The corresponding HIL device connection 98 """ 99 if dut_con in self._harness_connections: 100 return self._harness_connections[dut_con] 101 else: 102 error_msg = ( 103 "No HIL connection found for DUT connection: " 104 f"({dut_con.connector}, {dut_con.pin})" 105 ) 106 raise hil_errors.ConnectionError(error_msg) 107 108 109# All DUT Connections -----------------------------------------------------------------# 110class DutCons: 111 def __init__(self, dut_connections: dict[str, DutBoardCons]): 112 """ 113 :param dut_connections: A dictionary mapping DUT board names to their connections 114 """ 115 self._dut_connections: dict[str, DutBoardCons] = dut_connections 116 117 @classmethod 118 def from_json(cls, test_config_path: str) -> "DutCons": 119 """ 120 Create a DutCons instance from a JSON configuration file. 121 122 :param test_config_path: The path to the JSON configuration file 123 :return: A DutCons instance 124 """ 125 with open(test_config_path, "r") as test_config_file: 126 test_config = json.load(test_config_file) 127 128 board_cons = {} 129 match test_config: 130 case {"dut_connections": dut_connections}: 131 for board_cons in dut_connections: 132 ... 133 match board_cons: 134 case { 135 "board": board, 136 "harness_connections": harness_connections, 137 }: 138 board_cons[board] = DutBoardCons.from_json( 139 harness_connections 140 ) 141 case _: 142 error_msg = ( 143 "Invalid DUT connections configuration: " 144 f"{board_cons}" 145 ) 146 raise hil_errors.ConfigurationError(error_msg) 147 case _: 148 # Not an error to have no DUT connections 149 pass 150 151 return cls(board_cons) 152 153 def get_hil_device_connection(self, board: str, dut_con: DutCon) -> HilDutCon: 154 """ 155 Get the HIL device connection for a given DUT connection. 156 157 :param board: The name of the DUT board 158 :param dut_con: The DUT connection for which to retrieve the HIL device connection 159 :return: The corresponding HIL device connection 160 """ 161 if board in self._dut_connections: 162 return self._dut_connections[board].get_hil_device_connection(dut_con) 163 else: 164 error_msg = f"No HIL connection found for DUT board: {board}" 165 raise hil_errors.ConnectionError(error_msg)
class
HilDutCon:
8class HilDutCon: 9 """The HIL side of a DUT connection""" 10 11 def __init__(self, device: str, port: str): 12 """ 13 :param device: The name of the HIL device (ex: 'RearTester') 14 :param port: The port name on the HIL device (ex: 'DO7') 15 """ 16 self.device: str = device 17 self.port: str = port 18 19 @classmethod 20 def from_json(cls, hil_dut_con: dict) -> "HilDutCon": 21 """ 22 Create a HilDutCon instance from a JSON dictionary. 23 24 :param hil_dut_con: The JSON dictionary representing the HIL DUT connection 25 :return: A HilDutCon instance 26 """ 27 match hil_dut_con: 28 case {"device": device, "port": port}: 29 return cls(device, port) 30 case _: 31 error_msg = f"Invalid HIL DUT connection configuration: {hil_dut_con}" 32 raise hil_errors.ConfigurationError(error_msg)
The HIL side of a DUT connection
HilDutCon(device: str, port: str)
11 def __init__(self, device: str, port: str): 12 """ 13 :param device: The name of the HIL device (ex: 'RearTester') 14 :param port: The port name on the HIL device (ex: 'DO7') 15 """ 16 self.device: str = device 17 self.port: str = port
Parameters
- device: The name of the HIL device (ex: 'RearTester')
- port: The port name on the HIL device (ex: 'DO7')
19 @classmethod 20 def from_json(cls, hil_dut_con: dict) -> "HilDutCon": 21 """ 22 Create a HilDutCon instance from a JSON dictionary. 23 24 :param hil_dut_con: The JSON dictionary representing the HIL DUT connection 25 :return: A HilDutCon instance 26 """ 27 match hil_dut_con: 28 case {"device": device, "port": port}: 29 return cls(device, port) 30 case _: 31 error_msg = f"Invalid HIL DUT connection configuration: {hil_dut_con}" 32 raise hil_errors.ConfigurationError(error_msg)
Create a HilDutCon instance from a JSON dictionary.
Parameters
- hil_dut_con: The JSON dictionary representing the HIL DUT connection
Returns
A HilDutCon instance
class
DutCon:
36class DutCon: 37 """The tested side of a DUT connection""" 38 39 def __init__(self, connector: str, pin: int): 40 """ 41 :param connector: The name of the DUT connector (ex: 'J3') 42 :param pin: The pin number on the DUT connector (ex: 9) 43 """ 44 self.connector: str = connector 45 self.pin: int = pin 46 47 @classmethod 48 def from_json(cls, dut_con: dict) -> "DutCon": 49 """ 50 Create a DutCon instance from a JSON dictionary. 51 52 :param dut_con: The JSON dictionary representing the DUT connection 53 :return: A DutCon instance 54 """ 55 match dut_con: 56 case {"connector": connector, "pin": pin}: 57 return cls(connector, pin) 58 case _: 59 error_msg = f"Invalid DUT connection configuration: {dut_con}" 60 raise hil_errors.ConfigurationError(error_msg)
The tested side of a DUT connection
DutCon(connector: str, pin: int)
39 def __init__(self, connector: str, pin: int): 40 """ 41 :param connector: The name of the DUT connector (ex: 'J3') 42 :param pin: The pin number on the DUT connector (ex: 9) 43 """ 44 self.connector: str = connector 45 self.pin: int = pin
Parameters
- connector: The name of the DUT connector (ex: 'J3')
- pin: The pin number on the DUT connector (ex: 9)
47 @classmethod 48 def from_json(cls, dut_con: dict) -> "DutCon": 49 """ 50 Create a DutCon instance from a JSON dictionary. 51 52 :param dut_con: The JSON dictionary representing the DUT connection 53 :return: A DutCon instance 54 """ 55 match dut_con: 56 case {"connector": connector, "pin": pin}: 57 return cls(connector, pin) 58 case _: 59 error_msg = f"Invalid DUT connection configuration: {dut_con}" 60 raise hil_errors.ConfigurationError(error_msg)
Create a DutCon instance from a JSON dictionary.
Parameters
- dut_con: The JSON dictionary representing the DUT connection
Returns
A DutCon instance
class
DutBoardCons:
64class DutBoardCons: 65 def __init__(self, harness_connections: dict[DutCon, HilDutCon]): 66 """ 67 :param harness_connections: A dictionary mapping DUT connections to HIL connections 68 """ 69 self._harness_connections: dict[DutCon, HilDutCon] = harness_connections 70 71 @classmethod 72 def from_json(cls, harness_connections: list[dict]) -> "DutBoardCons": 73 """ 74 Create a DutBoardCons instance from a JSON dictionary. 75 76 :param harness_connections: A list of dictionaries representing the harness connections 77 :return: A DutBoardCons instance 78 """ 79 parsed_connections: dict[DutCon, HilDutCon] = {} 80 81 for con in harness_connections: 82 match con: 83 case {"dut": dut_con, "hil": hil_con}: 84 parsed_connections[DutCon.from_json(dut_con)] = HilDutCon.from_json( 85 hil_con 86 ) 87 case _: 88 error_msg = f"Invalid DUT board connection configuration: {con}" 89 raise hil_errors.ConfigurationError(error_msg) 90 91 return cls(parsed_connections) 92 93 def get_hil_device_connection(self, dut_con: DutCon) -> HilDutCon: 94 """ 95 Get the HIL device connection for a given DUT connection. 96 97 :param dut_con: The DUT connection for which to retrieve the HIL device connection 98 :return: The corresponding HIL device connection 99 """ 100 if dut_con in self._harness_connections: 101 return self._harness_connections[dut_con] 102 else: 103 error_msg = ( 104 "No HIL connection found for DUT connection: " 105 f"({dut_con.connector}, {dut_con.pin})" 106 ) 107 raise hil_errors.ConnectionError(error_msg)
65 def __init__(self, harness_connections: dict[DutCon, HilDutCon]): 66 """ 67 :param harness_connections: A dictionary mapping DUT connections to HIL connections 68 """ 69 self._harness_connections: dict[DutCon, HilDutCon] = harness_connections
Parameters
- harness_connections: A dictionary mapping DUT connections to HIL connections
71 @classmethod 72 def from_json(cls, harness_connections: list[dict]) -> "DutBoardCons": 73 """ 74 Create a DutBoardCons instance from a JSON dictionary. 75 76 :param harness_connections: A list of dictionaries representing the harness connections 77 :return: A DutBoardCons instance 78 """ 79 parsed_connections: dict[DutCon, HilDutCon] = {} 80 81 for con in harness_connections: 82 match con: 83 case {"dut": dut_con, "hil": hil_con}: 84 parsed_connections[DutCon.from_json(dut_con)] = HilDutCon.from_json( 85 hil_con 86 ) 87 case _: 88 error_msg = f"Invalid DUT board connection configuration: {con}" 89 raise hil_errors.ConfigurationError(error_msg) 90 91 return cls(parsed_connections)
Create a DutBoardCons instance from a JSON dictionary.
Parameters
- harness_connections: A list of dictionaries representing the harness connections
Returns
A DutBoardCons instance
93 def get_hil_device_connection(self, dut_con: DutCon) -> HilDutCon: 94 """ 95 Get the HIL device connection for a given DUT connection. 96 97 :param dut_con: The DUT connection for which to retrieve the HIL device connection 98 :return: The corresponding HIL device connection 99 """ 100 if dut_con in self._harness_connections: 101 return self._harness_connections[dut_con] 102 else: 103 error_msg = ( 104 "No HIL connection found for DUT connection: " 105 f"({dut_con.connector}, {dut_con.pin})" 106 ) 107 raise hil_errors.ConnectionError(error_msg)
Get the HIL device connection for a given DUT connection.
Parameters
- dut_con: The DUT connection for which to retrieve the HIL device connection
Returns
The corresponding HIL device connection
class
DutCons:
111class DutCons: 112 def __init__(self, dut_connections: dict[str, DutBoardCons]): 113 """ 114 :param dut_connections: A dictionary mapping DUT board names to their connections 115 """ 116 self._dut_connections: dict[str, DutBoardCons] = dut_connections 117 118 @classmethod 119 def from_json(cls, test_config_path: str) -> "DutCons": 120 """ 121 Create a DutCons instance from a JSON configuration file. 122 123 :param test_config_path: The path to the JSON configuration file 124 :return: A DutCons instance 125 """ 126 with open(test_config_path, "r") as test_config_file: 127 test_config = json.load(test_config_file) 128 129 board_cons = {} 130 match test_config: 131 case {"dut_connections": dut_connections}: 132 for board_cons in dut_connections: 133 ... 134 match board_cons: 135 case { 136 "board": board, 137 "harness_connections": harness_connections, 138 }: 139 board_cons[board] = DutBoardCons.from_json( 140 harness_connections 141 ) 142 case _: 143 error_msg = ( 144 "Invalid DUT connections configuration: " 145 f"{board_cons}" 146 ) 147 raise hil_errors.ConfigurationError(error_msg) 148 case _: 149 # Not an error to have no DUT connections 150 pass 151 152 return cls(board_cons) 153 154 def get_hil_device_connection(self, board: str, dut_con: DutCon) -> HilDutCon: 155 """ 156 Get the HIL device connection for a given DUT connection. 157 158 :param board: The name of the DUT board 159 :param dut_con: The DUT connection for which to retrieve the HIL device connection 160 :return: The corresponding HIL device connection 161 """ 162 if board in self._dut_connections: 163 return self._dut_connections[board].get_hil_device_connection(dut_con) 164 else: 165 error_msg = f"No HIL connection found for DUT board: {board}" 166 raise hil_errors.ConnectionError(error_msg)
DutCons(dut_connections: dict[str, DutBoardCons])
112 def __init__(self, dut_connections: dict[str, DutBoardCons]): 113 """ 114 :param dut_connections: A dictionary mapping DUT board names to their connections 115 """ 116 self._dut_connections: dict[str, DutBoardCons] = dut_connections
Parameters
- dut_connections: A dictionary mapping DUT board names to their connections
118 @classmethod 119 def from_json(cls, test_config_path: str) -> "DutCons": 120 """ 121 Create a DutCons instance from a JSON configuration file. 122 123 :param test_config_path: The path to the JSON configuration file 124 :return: A DutCons instance 125 """ 126 with open(test_config_path, "r") as test_config_file: 127 test_config = json.load(test_config_file) 128 129 board_cons = {} 130 match test_config: 131 case {"dut_connections": dut_connections}: 132 for board_cons in dut_connections: 133 ... 134 match board_cons: 135 case { 136 "board": board, 137 "harness_connections": harness_connections, 138 }: 139 board_cons[board] = DutBoardCons.from_json( 140 harness_connections 141 ) 142 case _: 143 error_msg = ( 144 "Invalid DUT connections configuration: " 145 f"{board_cons}" 146 ) 147 raise hil_errors.ConfigurationError(error_msg) 148 case _: 149 # Not an error to have no DUT connections 150 pass 151 152 return cls(board_cons)
Create a DutCons instance from a JSON configuration file.
Parameters
- test_config_path: The path to the JSON configuration file
Returns
A DutCons instance
154 def get_hil_device_connection(self, board: str, dut_con: DutCon) -> HilDutCon: 155 """ 156 Get the HIL device connection for a given DUT connection. 157 158 :param board: The name of the DUT board 159 :param dut_con: The DUT connection for which to retrieve the HIL device connection 160 :return: The corresponding HIL device connection 161 """ 162 if board in self._dut_connections: 163 return self._dut_connections[board].get_hil_device_connection(dut_con) 164 else: 165 error_msg = f"No HIL connection found for DUT board: {board}" 166 raise hil_errors.ConnectionError(error_msg)
Get the HIL device connection for a given DUT connection.
Parameters
- board: The name of the DUT board
- dut_con: The DUT connection for which to retrieve the HIL device connection
Returns
The corresponding HIL device connection