|
| 1 | +From: Kshitiz Godara <kgodara@microsoft.com> |
| 2 | +Date: Sun, 21 Jun 2026 00:00:00 +0000 |
| 3 | +Subject: [PATCH] test: gate live local-disk probes behind LSM_TEST_LOCAL_DISK_HW |
| 4 | + |
| 5 | +test_local_disk_link_type and test_local_disk_link_speed_get issue real |
| 6 | +SCSI MODE SENSE / lsm_local_disk_list() probes against /dev/sd*. In a |
| 7 | +build chroot those devices are not real backing hardware, so MODE SENSE |
| 8 | +returns a zero-length data page and the library legitimately reports |
| 9 | +LSM_ERR_LIB_BUG (or another "unexpected" return code), failing the |
| 10 | +tests. |
| 11 | + |
| 12 | +Gate only the hardware-touching portions of both tests behind an opt-in |
| 13 | +LSM_TEST_LOCAL_DISK_HW environment variable (off by default). The |
| 14 | +negative-path assertions (invalid argument, non-existent disk) still |
| 15 | +run unconditionally, preserving coverage of the public API contract. |
| 16 | + |
| 17 | +Test-only change; nothing in the shipped libstoragemgmt binary is |
| 18 | +affected. |
| 19 | +--- |
| 20 | +diff --git a/test/tester.c b/test/tester.c |
| 21 | +index aba56a0..aa06839 100644 |
| 22 | +--- a/test/tester.c |
| 23 | ++++ b/test/tester.c |
| 24 | +@@ -3735,18 +3735,22 @@ START_TEST(test_local_disk_link_type) { |
| 25 | + lsm_disk_link_type link_type = LSM_DISK_LINK_TYPE_UNKNOWN; |
| 26 | + lsm_error *lsm_err = NULL; |
| 27 | + |
| 28 | +- rc = lsm_local_disk_link_type_get("/dev/sda", &link_type, &lsm_err); |
| 29 | +- if (lsm_err != NULL) |
| 30 | +- ck_assert_msg(rc != LSM_ERR_LIB_BUG, |
| 31 | +- "lsm_local_disk_link_type_get() got LSM_ERR_LIB_BUG: %s", |
| 32 | +- lsm_error_message_get(lsm_err)); |
| 33 | +- else |
| 34 | +- ck_assert_msg(rc != LSM_ERR_LIB_BUG, |
| 35 | +- "lsm_local_disk_link_type_get() got LSM_ERR_LIB_BUG with " |
| 36 | +- "NULL lsm_err"); |
| 37 | +- |
| 38 | +- if (rc != LSM_ERR_OK) |
| 39 | +- lsm_error_free(lsm_err); |
| 40 | ++ /* /dev/sda probe issues a real SCSI MODE SENSE ioctl; only works on |
| 41 | ++ * real hardware. Opt in via LSM_TEST_LOCAL_DISK_HW=1 on bare metal. */ |
| 42 | ++ if (getenv("LSM_TEST_LOCAL_DISK_HW") != NULL) { |
| 43 | ++ rc = lsm_local_disk_link_type_get("/dev/sda", &link_type, &lsm_err); |
| 44 | ++ if (lsm_err != NULL) |
| 45 | ++ ck_assert_msg(rc != LSM_ERR_LIB_BUG, |
| 46 | ++ "lsm_local_disk_link_type_get() got LSM_ERR_LIB_BUG: %s", |
| 47 | ++ lsm_error_message_get(lsm_err)); |
| 48 | ++ else |
| 49 | ++ ck_assert_msg(rc != LSM_ERR_LIB_BUG, |
| 50 | ++ "lsm_local_disk_link_type_get() got LSM_ERR_LIB_BUG with " |
| 51 | ++ "NULL lsm_err"); |
| 52 | ++ |
| 53 | ++ if (rc != LSM_ERR_OK) |
| 54 | ++ lsm_error_free(lsm_err); |
| 55 | ++ } |
| 56 | + |
| 57 | + /* Test non-exist disk */ |
| 58 | + rc = lsm_local_disk_link_type_get(NOT_EXIST_SD_PATH, &link_type, &lsm_err); |
| 59 | +@@ -4163,23 +4167,30 @@ START_TEST(test_local_disk_link_speed_get) { |
| 60 | + const char *disk_path = NULL; |
| 61 | + uint32_t link_speed = LSM_DISK_LINK_SPEED_UNKNOWN; |
| 62 | + |
| 63 | +- rc = lsm_local_disk_list(&disk_paths, &lsm_err); |
| 64 | +- if (lsm_err) |
| 65 | +- lsm_error_free(lsm_err); |
| 66 | +- ck_assert_msg(rc == LSM_ERR_OK, "lsm_local_disk_list() failed as %d", rc); |
| 67 | +- /* Only try maximum 4 disks */ |
| 68 | +- for (; i < lsm_string_list_size(disk_paths) && i < 4; ++i) { |
| 69 | +- disk_path = lsm_string_list_elem_get(disk_paths, i); |
| 70 | +- ck_assert_msg(disk_path != NULL, "Got NULL disk path"); |
| 71 | +- rc = lsm_local_disk_link_speed_get(disk_path, &link_speed, &lsm_err); |
| 72 | +- ck_assert_msg(rc == LSM_ERR_OK || rc == LSM_ERR_NO_SUPPORT || |
| 73 | +- rc == LSM_ERR_PERMISSION_DENIED, |
| 74 | +- "lsm_local_disk_led_status_get(): " |
| 75 | +- "Got unexpected return: %d", |
| 76 | +- rc); |
| 77 | ++ /* Iterating local disks and probing link speed needs real SCSI hardware |
| 78 | ++ * backing /dev/sd*; in a build chroot the probe returns LSM_ERR_LIB_BUG. |
| 79 | ++ * Opt in via LSM_TEST_LOCAL_DISK_HW=1 on bare metal. */ |
| 80 | ++ if (getenv("LSM_TEST_LOCAL_DISK_HW") != NULL) { |
| 81 | ++ rc = lsm_local_disk_list(&disk_paths, &lsm_err); |
| 82 | + if (lsm_err) |
| 83 | + lsm_error_free(lsm_err); |
| 84 | +- lsm_err = NULL; |
| 85 | ++ ck_assert_msg(rc == LSM_ERR_OK, |
| 86 | ++ "lsm_local_disk_list() failed as %d", rc); |
| 87 | ++ /* Only try maximum 4 disks */ |
| 88 | ++ for (; i < lsm_string_list_size(disk_paths) && i < 4; ++i) { |
| 89 | ++ disk_path = lsm_string_list_elem_get(disk_paths, i); |
| 90 | ++ ck_assert_msg(disk_path != NULL, "Got NULL disk path"); |
| 91 | ++ rc = lsm_local_disk_link_speed_get(disk_path, &link_speed, |
| 92 | ++ &lsm_err); |
| 93 | ++ ck_assert_msg(rc == LSM_ERR_OK || rc == LSM_ERR_NO_SUPPORT || |
| 94 | ++ rc == LSM_ERR_PERMISSION_DENIED, |
| 95 | ++ "lsm_local_disk_link_speed_get(): " |
| 96 | ++ "Got unexpected return: %d", |
| 97 | ++ rc); |
| 98 | ++ if (lsm_err) |
| 99 | ++ lsm_error_free(lsm_err); |
| 100 | ++ lsm_err = NULL; |
| 101 | ++ } |
| 102 | + } |
| 103 | + |
| 104 | + /* Test invalid argument */ |
| 105 | +@@ -4221,7 +4232,8 @@ START_TEST(test_local_disk_link_speed_get) { |
| 106 | + "LSM_DISK_LINK_SPEED_UNKNOWN, but got %" PRIu32 "", |
| 107 | + link_speed); |
| 108 | + lsm_error_free(lsm_err); |
| 109 | +- lsm_string_list_free(disk_paths); |
| 110 | ++ if (disk_paths != NULL) |
| 111 | ++ lsm_string_list_free(disk_paths); |
| 112 | + } |
| 113 | + END_TEST |
| 114 | + |
0 commit comments