Skip to content

Commit

Permalink
Enable support of USB3 Gen2x1 devices for detection tests (Bugfix) (#…
Browse files Browse the repository at this point in the history
…1438)

USB3 Gen2x1 devices use a different kernel string when advertising themselves, so this PR takes this into account.
  • Loading branch information
eugene-yujinwu authored Aug 29, 2024
1 parent 6772524 commit b92edc5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion checkbox-support/checkbox_support/scripts/run_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def _validate_insertion(self):
elif self.storage_type == "usb3" and self.device in [
"super_speed_usb",
"super_speed_gen1_usb",
"super_speed_plus_gen2x1_usb",
]:
logger.info("USB3 insertion test passed.")
else:
Expand Down Expand Up @@ -226,6 +227,7 @@ def _parse_journal_line(self, line_str):
"high_speed_usb": "new high-speed USB device",
"super_speed_usb": "new SuperSpeed USB device",
"super_speed_gen1_usb": "new SuperSpeed Gen 1 USB device",
"super_speed_plus_gen2x1_usb": "new SuperSpeed Plus Gen 2x1 USB device",
}

driver_log_dict = {
Expand All @@ -247,7 +249,7 @@ def _parse_journal_line(self, line_str):
).group(1)

# Look for insertion action
if "USB Mass Storage device detected" in line_str:
if "USB Mass Storage device detected" or "uas" in line_str:
self.action = "insertion"

# Look for removal action
Expand Down
21 changes: 21 additions & 0 deletions checkbox-support/checkbox_support/tests/test_run_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ def test_usb3_storage_validate_insertion(self):
USBStorage._validate_insertion(mock_usb_storage)
self.assertEqual(cm.exception.code, None)

def test_usb3_gen2x1_storage_validate_insertion(self):
mock_usb_storage = MagicMock()
mock_usb_storage.storage_type = "usb3"
mock_usb_storage.device = "super_speed_plus_gen2x1_usb"
mock_usb_storage.mounted_partition = "mounted_partition"
mock_usb_storage.action = "insertion"
mock_usb_storage.driver = "xhci_hcd"
with self.assertRaises(SystemExit) as cm:
USBStorage._validate_insertion(mock_usb_storage)
self.assertEqual(cm.exception.code, None)

def test_usb_storage_validate_insertion_wrong_usb_type(self):
mock_usb_storage = MagicMock()
mock_usb_storage.storage_type = "usb2"
Expand Down Expand Up @@ -285,6 +296,12 @@ def test_usb_storage_parse_journal_line(self):
USBStorage._parse_journal_line(mock_usb_storage, line_str)
self.assertEqual(mock_usb_storage.device, "super_speed_gen1_usb")

line_str = "new SuperSpeed Plus Gen 2x1 USB device"
USBStorage._parse_journal_line(mock_usb_storage, line_str)
self.assertEqual(
mock_usb_storage.device, "super_speed_plus_gen2x1_usb"
)

line_str = "new high-speed USB device number 1 using ehci_hcd"
USBStorage._parse_journal_line(mock_usb_storage, line_str)
self.assertEqual(mock_usb_storage.driver, "ehci_hcd")
Expand All @@ -297,6 +314,10 @@ def test_usb_storage_parse_journal_line(self):
USBStorage._parse_journal_line(mock_usb_storage, line_str)
self.assertEqual(mock_usb_storage.action, "insertion")

line_str = "kernel: scsi host0: uas"
USBStorage._parse_journal_line(mock_usb_storage, line_str)
self.assertEqual(mock_usb_storage.action, "insertion")

line_str = "USB disconnect, device"
USBStorage._parse_journal_line(mock_usb_storage, line_str)
self.assertEqual(mock_usb_storage.action, "removal")
Expand Down

0 comments on commit b92edc5

Please sign in to comment.