Skip to content

Commit eb19539

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 eb19539

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

checkbox-support/checkbox_support/tests/test_run_watcher.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,47 @@ 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+
line_str = " sda: sda1"
443+
mediacard_combo_storage = MediacardComboStorage("mediacard_combo")
444+
mediacard_combo_storage._parse_journal_line(line_str)
445+
self.assertEqual(mediacard_combo_storage.mounted_partition, "sda1")
446+
447+
def test_mediacard_combo_storage_usb_sd_card_reader_action_update(self):
448+
# Test that action can be updated (removal then insertion)
449+
mediacard_combo_storage = MediacardComboStorage("mediacard_combo")
450+
451+
# First detect removal
452+
line_str = "sda: detected capacity change from 31116288 to 0"
453+
mediacard_combo_storage._parse_journal_line(line_str)
454+
self.assertEqual(mediacard_combo_storage.action, "removal")
455+
456+
# Then detect insertion - action should update
457+
line_str = "sda: detected capacity change from 0 to 31116288"
458+
mediacard_combo_storage._parse_journal_line(line_str)
459+
self.assertEqual(mediacard_combo_storage.action, "insertion")
460+
self.assertEqual(
461+
mediacard_combo_storage.device, "SD/MMC via USB reader"
462+
)
463+
423464
def test_thunderbolt_storage_init(self):
424465
thunderbolt_storage = ThunderboltStorage("thunderbolt")
425466
self.assertEqual(thunderbolt_storage.storage_type, "thunderbolt")

0 commit comments

Comments
 (0)