sahlberg / libiscsi

iscsi client library and utilities
Other
191 stars 162 forks source link

Enhancements to test_unmap_simple.c #138

Open mykaul opened 10 years ago

mykaul commented 10 years ago
  1. Check via the VPD, what's the max number of unmap block descriptor count that is possible - and use it.
  2. (Negative test) Try to unmap more than the max number of unmap block descriptor count (as specified in the VPD)
  3. (Negative test) Try to unmap more than the range (as specified in the VPD)
mykaul commented 10 years ago

Thought there's a way to attach files here... I'll see what I can do, how I can copy-paste it here without formatting.

mykaul commented 10 years ago
diff --git a/test-tool/test_unmap_simple.c b/test-tool/test_unmap_simple.c
index d080ae5..a546123 100644
--- a/test-tool/test_unmap_simple.c
+++ b/test-tool/test_unmap_simple.c
@@ -39,10 +39,12 @@ init_lun_with_data(unsigned char *buf, uint64_t lba)
 void
 test_unmap_simple(void)
 {
-   int i, ret;
+   int i, ret,max_unmap_bdc, max_unmap;
    struct unmap_list list[257];
    unsigned char *buf = alloca(256 * block_size);
    unsigned char *zbuf = alloca(256 * block_size);
+   struct scsi_inquiry_block_limits *bl;
+   struct scsi_task *bl_task = NULL;
         memset(zbuf, 0, 256 * block_size);

    logging(LOG_VERBOSE, LOG_BLANK_LINE);
@@ -52,6 +54,22 @@ test_unmap_simple(void)
    CHECK_FOR_THIN_PROVISIONING;
    CHECK_FOR_SBC;

+   ret = inquiry(iscsic, tgt_lun,
+           1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS,
+           64, &bl_task);
+   CU_ASSERT_EQUAL(ret, 0);
+   bl = scsi_datain_unmarshall(bl_task);
+
+   if (bl && bl->max_unmap_bdc && bl->max_unmap_bdc <= 256) {
+       max_unmap_bdc = bl->max_unmap_bdc;
+   } else {
+       max_unmap_bdc = 256;
+   }
+   if (bl && bl->max_unmap) {
+       max_unmap = bl->max_unmap;
+   } else {
+       max_unmap = 8192;
+   }

    logging(LOG_VERBOSE, "Test UNMAP of 1-256 blocks at the start of the "
        "LUN as a single descriptor");
@@ -86,14 +104,14 @@ test_unmap_simple(void)
        }
    }

-   logging(LOG_VERBOSE, "Test UNMAP of 1-256 blocks at the start of the "
+   logging(LOG_VERBOSE, "Test UNMAP of 1 to maximum unmap block descriptor count blocks at the start of the "
        "LUN with one descriptor per block");

    logging(LOG_VERBOSE, "Write 'a' to the first 256 LBAs");
    init_lun_with_data(buf, 0);

    CU_ASSERT_EQUAL(ret, 0);
-   for (i = 0; i < 256; i++) {
+   for (i = 0; i < max_unmap_bdc; i++) {
        list[i].lba = i;
        list[i].num = 1;
        ret = unmap(iscsic, tgt_lun, 0, list, i + 1);
@@ -118,4 +136,22 @@ test_unmap_simple(void)
            }
        }
    }
+
+   logging(LOG_VERBOSE, "Test UNMAP of more than maximum unmap block descriptor count blocks");
+
+   i++;
+   list[i].lba = i;
+   list[i].num = 1;
+   ret = unmap(iscsic, tgt_lun, 0, list, i + 1);
+   /* we expect to fail unmapping with more than the maximum unmap block descriptor count blocks */
+   CU_ASSERT_NOT_EQUAL(ret, 0);
+
+   logging(LOG_VERBOSE, "Write more than the Maximum unmap LBA count");
+
+   list[0].lba = 0;
+   list[0].num = (max_unmap + 1);
+   ret = unmap(iscsic, tgt_lun, 0, list, 1);
+   /* We expect to fail unmapping with more than the maximum unmap LBA count" */
+   CU_ASSERT_NOT_EQUAL(ret, 0);
+
 }