Skip to content

Commit e26b49d

Browse files
committed
Add unit tests for USB SD card reader detection
Add comprehensive unit tests for the new USB SD card reader detection functionality in MediacardComboStorage: - test_mediacard_combo_storage_usb_sd_card_reader_insertion: Tests detection of insertion via capacity change messages - test_mediacard_combo_storage_usb_sd_card_reader_removal: Tests detection of removal via capacity change to 0 - test_mediacard_combo_storage_usb_sd_card_reader_partition: Tests extraction of partition names from sda: sda1 patterns - test_mediacard_combo_storage_usb_sd_card_reader_action_update: Tests that action state can be updated from removal to insertion These tests cover the new code paths added to support USB SD card readers that appear as SCSI/USB mass storage devices.
1 parent e840c16 commit e26b49d

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

checkbox-support/checkbox_support/scripts/run_watcher.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,6 @@ def _parse_journal_line(self, line_str):
384384
# This is a removal - always update to reflect current action
385385
self.action = "removal"
386386

387-
# Then extract partition name from patterns like "sda: sda1"
388-
if not self.mounted_partition:
389-
part_re = re.compile(r"sd\w+:.*(?P<part_name>sd\w+)")
390-
match = re.search(part_re, line_str)
391-
if match:
392-
self.mounted_partition = match.group("part_name")
393-
394387
return super()._parse_journal_line(line_str)
395388

396389

checkbox-support/checkbox_support/tests/test_run_watcher.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,54 @@ def test_mediacard_combo_storage_parse_journal_line(self):
420420
mediacard_combo_storage._parse_journal_line(line_str)
421421
self.assertEqual(mediacard_combo_storage.action, None)
422422

423+
def test_mediacard_combo_storage_usb_sd_card_reader_insertion(self):
424+
# Test USB SD card reader insertion detection
425+
line_str = "sda: detected capacity change from 0 to 31116288"
426+
mediacard_combo_storage = MediacardComboStorage("mediacard_combo")
427+
mediacard_combo_storage._parse_journal_line(line_str)
428+
self.assertEqual(mediacard_combo_storage.action, "insertion")
429+
self.assertEqual(
430+
mediacard_combo_storage.device, "SD/MMC via USB reader"
431+
)
432+
433+
def test_mediacard_combo_storage_usb_sd_card_reader_removal(self):
434+
# Test USB SD card reader removal detection
435+
line_str = "sda: detected capacity change from 31116288 to 0"
436+
mediacard_combo_storage = MediacardComboStorage("mediacard_combo")
437+
mediacard_combo_storage._parse_journal_line(line_str)
438+
self.assertEqual(mediacard_combo_storage.action, "removal")
439+
440+
def test_mediacard_combo_storage_usb_sd_card_reader_partition(self):
441+
# Test partition extraction for USB SD card reader
442+
# This tests the USBStorage path which also extracts sda partitions
443+
line_str = " sda: sda1"
444+
mediacard_combo_storage = MediacardComboStorage("mediacard_combo")
445+
mediacard_combo_storage._parse_journal_line(line_str)
446+
self.assertEqual(mediacard_combo_storage.mounted_partition, "sda1")
447+
448+
# Test edge case with different device names
449+
line_str = "sdb: sdb2"
450+
mediacard_combo_storage = MediacardComboStorage("mediacard_combo")
451+
mediacard_combo_storage._parse_journal_line(line_str)
452+
self.assertEqual(mediacard_combo_storage.mounted_partition, "sdb2")
453+
454+
def test_mediacard_combo_storage_usb_sd_card_reader_action_update(self):
455+
# Test that action can be updated (removal then insertion)
456+
mediacard_combo_storage = MediacardComboStorage("mediacard_combo")
457+
458+
# First detect removal
459+
line_str = "sda: detected capacity change from 31116288 to 0"
460+
mediacard_combo_storage._parse_journal_line(line_str)
461+
self.assertEqual(mediacard_combo_storage.action, "removal")
462+
463+
# Then detect insertion - action should update
464+
line_str = "sda: detected capacity change from 0 to 31116288"
465+
mediacard_combo_storage._parse_journal_line(line_str)
466+
self.assertEqual(mediacard_combo_storage.action, "insertion")
467+
self.assertEqual(
468+
mediacard_combo_storage.device, "SD/MMC via USB reader"
469+
)
470+
423471
def test_thunderbolt_storage_init(self):
424472
thunderbolt_storage = ThunderboltStorage("thunderbolt")
425473
self.assertEqual(thunderbolt_storage.storage_type, "thunderbolt")

0 commit comments

Comments
 (0)