3535
3636from rspy import log , file
3737regex = None
38- hub_reset = False
3938handle = None
4039test_ran = False
4140device_set = list ()
@@ -121,72 +120,41 @@ def junit_xml_parsing(xml_file):
121120 new_xml = xml_file .split ('.' )[0 ]
122121 tree .write (f'{ logdir } /{ new_xml } _refined.xml' )
123122
124- def build_device_port_mapping (possible_ports ):
123+ def build_device_port_mapping ():
125124 """
126- Build a mapping of devices to YKUSH hub ports by enabling each port and querying connected devices.
125+ Map device-name -> YKUSH hub port from rspy's current enumeration.
126+
127+ rspy resolves each device's hub port from its USB location during query()
128+ (done in find_devices_run_tests), so the mapping is read straight from the
129+ enumerated devices -- no need to power-cycle ports one at a time, and no
130+ direct ykushcmd calls.
127131 """
128132 from rspy import devices
129133 mapping = {}
130-
131- # Turn off all ports first
132- for port in possible_ports :
133- subprocess .run (f'ykushcmd ykush3 -d { port } ' , shell = True )
134- time .sleep (2.5 )
135-
136- for port in possible_ports :
137- log .i (f"Checking YKUSH port { port } ..." )
138-
139- subprocess .run (f'ykushcmd ykush3 -u { port } ' , shell = True )
140- time .sleep (5.0 )
141-
142- devices .query (hub_reset = True )
143-
144- for device in devices ._device_by_sn .values ():
145- key = device .name .upper ()
146- if key not in mapping :
147- mapping [key ] = port
148- log .i (f"Detected device: { device .name } ({ device ._sn } ) on port { port } " )
149-
150- subprocess .run (f'ykushcmd ykush3 -d { port } ' , shell = True )
134+ for device in devices ._device_by_sn .values ():
135+ if device .port is None :
136+ log .w (f"Could not resolve YKUSH port for { device .name } ({ device ._sn } )" )
137+ continue
138+ key = device .name .upper ()
139+ if key not in mapping :
140+ mapping [key ] = device .port
141+ log .i (f"Detected device: { device .name } ({ device ._sn } ) on port { device .port } " )
151142
152143 return mapping
153144
154145
155- def disable_all_ports ():
156- """
157- Disable all ports on the YKUSH hub.
158- """
159- log .i ("Disabling all ports..." )
160- subprocess .run (f'ykushcmd ykush3 -d a' , shell = True )
161- time .sleep (2.5 ) # Wait for the system to unregister devices
162-
163-
164- def enable_port_for_device (device , port ):
146+ def run_tests_for_device (device , port , testname ):
165147 """
166- Enable the port for the specified device.
148+ Enable only the target device's YKUSH port (through rspy's hub) and run its
149+ tests. rspy owns the hub, so there are no direct ykushcmd calls.
167150 """
168- if port :
169- log .i (f"Enabling port { port } for device { device .upper ()} " )
170- subprocess .run (f'ykushcmd ykush3 -u { port } ' , shell = True )
171- time .sleep (5.0 ) # Wait for re-enumeration
172- else :
151+ from rspy import devices
152+ if port is None :
173153 log .e (f"No port mapping found for device { device .upper ()} " )
154+ return
174155
175-
176- def run_tests_for_device (device , testname ):
177- """
178- Run tests for a specific device by enabling its port and executing the test command.
179- """
180-
181- # Define which ports are connected to YKUSH (e.g., 1, 2, 3...)
182- possible_ports = [1 , 2 , 3 ]
183- device_port_mapping = build_device_port_mapping (possible_ports )
184- log .i ("Device to port mapping:" , device_port_mapping )
185-
186- disable_all_ports () # Disable all ports first
187-
188- port = device_port_mapping .get (device .upper ())
189- enable_port_for_device (device , port ) # Enable the port for the target device
156+ if devices .hub :
157+ devices .hub .enable_ports ([port ], disable_other_ports = True , sleep_on_change = 5 )
190158
191159 cmd = command (device .lower (), testname )
192160 run_test (cmd , testname , device , stdout = logdir , append = False )
@@ -203,28 +171,35 @@ def find_devices_run_tests():
203171 try :
204172 os .makedirs (logdir , exist_ok = True )
205173
206- # Update dict '_device_by_sn' from devices module of rspy
174+ # Let rspy own the YKUSH hub: discover it, enumerate the connected
175+ # devices and resolve each device's port. Skip the hub reset on the first
176+ # attempt -- the 'ykushcmd --reset' it runs prints 'cannot claim
177+ # interface' to the console while the board re-enumerates. Only reset as a
178+ # recovery step if the first enumeration comes up empty.
179+ first_attempt = True
207180 while max_retry and not devices ._device_by_sn :
208- subprocess .run ('ykushcmd ykush3 --reset' , shell = True )
209- time .sleep (2.0 )
210- devices .query (hub_reset = hub_reset )
181+ devices .query (hub_reset = not first_attempt )
182+ first_attempt = False
211183 max_retry -= 1
212184
213185 if not devices ._device_by_sn :
214186 assert False , 'No Camera device detected!'
215- else :
216- connected_devices = [device .name for device in devices ._device_by_sn .values ()]
217- log .i ('Connected devices:' , connected_devices )
187+
188+ connected_devices = [device .name for device in devices ._device_by_sn .values ()]
189+ log .i ('Connected devices:' , connected_devices )
190+ device_port_mapping = build_device_port_mapping ()
191+ log .i ('Device to port mapping:' , device_port_mapping )
218192
219193 testname = regex if regex else None
220194
221195 if device_set :
222196 # Loop through user-specified devices and run tests only on them
223197 devices_not_found = []
224198 for device in device_set :
225- if device .upper () in connected_devices :
199+ port = device_port_mapping .get (device .upper ())
200+ if port is not None :
226201 log .i ('Running tests on device:' , device )
227- run_tests_for_device (device , testname )
202+ run_tests_for_device (device , port , testname )
228203 else :
229204 log .e ('Skipping test run on device:' , device , ', -- NOT found' )
230205 devices_not_found .append (device )
@@ -233,7 +208,7 @@ def find_devices_run_tests():
233208 # Loop through all connected devices and run all tests
234209 for device in connected_devices :
235210 log .i ('Running tests on device:' , device )
236- run_tests_for_device (device , testname )
211+ run_tests_for_device (device , device_port_mapping . get ( device . upper ()), testname )
237212 finally :
238213 if devices .hub and devices .hub .is_connected ():
239214 devices .hub .disable_ports ()
0 commit comments