Tests: add getlbastatus helper

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
Ronnie Sahlberg
2016-02-21 11:53:29 -08:00
parent 23a9278e23
commit 05fb882e19
5 changed files with 50 additions and 83 deletions
+14
View File
@@ -209,6 +209,20 @@ do { \
CU_ASSERT_EQUAL(_r, 0); \ CU_ASSERT_EQUAL(_r, 0); \
} while (0); } while (0);
#define GETLBASTATUS(...) \
do { \
int _r; \
_r = get_lba_status(__VA_ARGS__); \
if (_r == -2) { \
logging(LOG_NORMAL, "[SKIPPED] GETLBASTATUS " \
"is not implemented."); \
CU_PASS("[SKIPPED] Target does not support " \
"GETLBASTATUS. Skipping test"); \
return; \
} \
CU_ASSERT_EQUAL(_r, 0); \
} while (0);
#define ORWRITE(...) \ #define ORWRITE(...) \
do { \ do { \
int _r; \ int _r; \
+9 -20
View File
@@ -29,28 +29,17 @@
void void
test_get_lba_status_beyond_eol(void) test_get_lba_status_beyond_eol(void)
{ {
int ret;
logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS one block beyond the end of the LUN"); logging(LOG_VERBOSE, "Test GETLBASTATUS one block beyond the end of the LUN");
ret = get_lba_status(sd, NULL, num_blocks + 1, 24, GETLBASTATUS(sd, NULL, num_blocks + 1, 24,
EXPECT_LBA_OOB); EXPECT_LBA_OOB);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test");
return;
}
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS at LBA 2^63"); logging(LOG_VERBOSE, "Test GETLBASTATUS at LBA 2^63");
GETLBASTATUS(sd, NULL, 0x8000000000000000ULL, 24,
EXPECT_LBA_OOB);
ret = get_lba_status(sd, NULL, 0x8000000000000000ULL, 24, logging(LOG_VERBOSE, "Test GETLBASTATUS at LBA -1");
EXPECT_LBA_OOB); GETLBASTATUS(sd, NULL, 0xffffffffffffffffULL, 24,
CU_ASSERT_EQUAL(ret, 0); EXPECT_LBA_OOB);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS at LBA -1");
ret = get_lba_status(sd, NULL, 0xffffffffffffffffULL, 24,
EXPECT_LBA_OOB);
CU_ASSERT_EQUAL(ret, 0);
} }
+7 -20
View File
@@ -29,31 +29,18 @@
void void
test_get_lba_status_simple(void) test_get_lba_status_simple(void)
{ {
int i, ret; int i;
logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS of 1-256 blocks at the start of the LUN"); logging(LOG_VERBOSE, "Test GETLBASTATUS of 1-256 blocks at the start of the LUN");
for (i = 1; i <= 256; i++) { for (i = 1; i <= 256; i++) {
ret = get_lba_status(sd, NULL, i, 24, GETLBASTATUS(sd, NULL, i, 24,
EXPECT_STATUS_GOOD); EXPECT_STATUS_GOOD);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test");
return;
}
if (ret != 0) {
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
return;
}
} }
logging(LOG_VERBOSE, "Test GETLBASTATUS of 1-256 blocks at the end of the LUN");
logging(LOG_VERBOSE, "Test GET_LBA_STATUS of 1-256 blocks at the end of the LUN");
for (i = 1; i <= 256; i++) { for (i = 1; i <= 256; i++) {
ret = get_lba_status(sd, NULL, num_blocks - i, 24, GETLBASTATUS(sd, NULL, num_blocks - i, 24,
EXPECT_STATUS_GOOD); EXPECT_STATUS_GOOD);
if (ret != 0) {
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
return;
}
} }
} }
+18 -40
View File
@@ -43,7 +43,7 @@ test_get_lba_status_unmap_single(void)
memset(scratch, 'A', (256 + lbppb + 1) * block_size); memset(scratch, 'A', (256 + lbppb + 1) * block_size);
logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS for a single unmapped block " logging(LOG_VERBOSE, "Test GETLBASTATUS for a single unmapped block "
"at offset 0-255"); "at offset 0-255");
logging(LOG_VERBOSE, "We have %d logical blocks per physical block", logging(LOG_VERBOSE, "We have %d logical blocks per physical block",
lbppb); lbppb);
@@ -66,38 +66,27 @@ test_get_lba_status_unmap_single(void)
logging(LOG_VERBOSE, "Read the status of the block at LBA:%" logging(LOG_VERBOSE, "Read the status of the block at LBA:%"
PRIu64, i); PRIu64, i);
ret = get_lba_status(sd, NULL, i, 24, GETLBASTATUS(sd, NULL, i, 24,
EXPECT_STATUS_GOOD); EXPECT_STATUS_GOOD);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test");
return;
}
if (ret != 0) {
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
return;
}
logging(LOG_VERBOSE, "Read the status of the block at LBA:%" logging(LOG_VERBOSE, "Read the status of the block at LBA:%"
PRIu64, i + lbppb); PRIu64, i + lbppb);
ret = get_lba_status(sd, &t, i + lbppb, 24, GETLBASTATUS(sd, &t, i + lbppb, 24,
EXPECT_STATUS_GOOD); EXPECT_STATUS_GOOD);
if (ret != 0) {
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
return;
}
if (t == NULL) { if (t == NULL) {
CU_FAIL("[FAILED] GET_LBA_STATUS task is NULL"); CU_FAIL("[FAILED] GETLBASTATUS task is NULL");
return; return;
} }
lbas = scsi_datain_unmarshall(t); lbas = scsi_datain_unmarshall(t);
if (lbas == NULL) { if (lbas == NULL) {
CU_FAIL("[FAILED] GET_LBA_STATUS command: failed " CU_FAIL("[FAILED] GETLBASTATUS command: failed "
"to unmarshall data."); "to unmarshall data.");
scsi_free_scsi_task(t); scsi_free_scsi_task(t);
return; return;
} }
lbasd = &lbas->descriptors[0]; lbasd = &lbas->descriptors[0];
if (lbasd->lba != i + lbppb) { if (lbasd->lba != i + lbppb) {
CU_FAIL("[FAILED] GET_LBA_STATUS command: " CU_FAIL("[FAILED] GETLBASTATUS command: "
"lba offset in first descriptor does not " "lba offset in first descriptor does not "
"match request."); "match request.");
scsi_free_scsi_task(t); scsi_free_scsi_task(t);
@@ -111,7 +100,7 @@ test_get_lba_status_unmap_single(void)
} }
logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test GET_LBA_STATUS for a single range of 1-255 " logging(LOG_VERBOSE, "Test GETLBASTATUS for a single range of 1-255 "
"blocks at offset 0"); "blocks at offset 0");
for (i = lbppb; i + lbppb <= 256; i += lbppb) { for (i = lbppb; i + lbppb <= 256; i += lbppb) {
logging(LOG_VERBOSE, "Write the first %i blocks with a known " logging(LOG_VERBOSE, "Write the first %i blocks with a known "
@@ -129,37 +118,26 @@ test_get_lba_status_unmap_single(void)
logging(LOG_VERBOSE, "Read the status of the block at LBA:0"); logging(LOG_VERBOSE, "Read the status of the block at LBA:0");
ret = get_lba_status(sd, NULL, 0, 24, GETLBASTATUS(sd, NULL, 0, 24,
EXPECT_STATUS_GOOD); EXPECT_STATUS_GOOD);
if (ret == -2) {
CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test");
return;
}
if (ret != 0) {
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
return;
}
logging(LOG_VERBOSE, "Read the status of the block at LBA:%" PRIu64, i + 1); logging(LOG_VERBOSE, "Read the status of the block at LBA:%" PRIu64, i + 1);
ret = get_lba_status(sd, &t, i + 1, 24, GETLBASTATUS(sd, &t, i + 1, 24,
EXPECT_STATUS_GOOD); EXPECT_STATUS_GOOD);
if (ret != 0) {
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
return;
}
if (t == NULL) { if (t == NULL) {
CU_FAIL("[FAILED] GET_LBA_STATUS task is NULL"); CU_FAIL("[FAILED] GETLBASTATUS task is NULL");
return; return;
} }
lbas = scsi_datain_unmarshall(t); lbas = scsi_datain_unmarshall(t);
if (lbas == NULL) { if (lbas == NULL) {
CU_FAIL("[FAILED] GET_LBA_STATUS command: failed " CU_FAIL("[FAILED] GETLBASTATUS command: failed "
"to unmarshall data."); "to unmarshall data.");
scsi_free_scsi_task(t); scsi_free_scsi_task(t);
return; return;
} }
lbasd = &lbas->descriptors[0]; lbasd = &lbas->descriptors[0];
if (lbasd->lba != i + lbppb) { if (lbasd->lba != i + lbppb) {
CU_FAIL("[FAILED] GET_LBA_STATUS command: " CU_FAIL("[FAILED] GETLBASTATUS command: "
"lba offset in first descriptor does not " "lba offset in first descriptor does not "
"match request."); "match request.");
scsi_free_scsi_task(t); scsi_free_scsi_task(t);
+2 -3
View File
@@ -109,8 +109,8 @@ check_unmap(void)
uint64_t lba; uint64_t lba;
logging(LOG_VERBOSE, "Read LBA mapping from the target"); logging(LOG_VERBOSE, "Read LBA mapping from the target");
get_lba_status(sd, &task_ret, 0, 256, GETLBASTATUS(sd, &task_ret, 0, 256,
EXPECT_STATUS_GOOD); EXPECT_STATUS_GOOD);
if (task_ret == NULL) { if (task_ret == NULL) {
logging(LOG_VERBOSE, "[FAILED] Failed to read LBA mapping " logging(LOG_VERBOSE, "[FAILED] Failed to read LBA mapping "
"from the target."); "from the target.");
@@ -128,7 +128,6 @@ check_unmap(void)
return; return;
} }
logging(LOG_VERBOSE, "Unmarshall LBA mapping datain buffer"); logging(LOG_VERBOSE, "Unmarshall LBA mapping datain buffer");
lbas = scsi_datain_unmarshall(task_ret); lbas = scsi_datain_unmarshall(task_ret);
if (lbas == NULL) { if (lbas == NULL) {