Tests: add getlbastatus helper
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
@@ -209,6 +209,20 @@ do { \
|
||||
CU_ASSERT_EQUAL(_r, 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(...) \
|
||||
do { \
|
||||
int _r; \
|
||||
|
||||
@@ -29,28 +29,17 @@
|
||||
void
|
||||
test_get_lba_status_beyond_eol(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
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,
|
||||
EXPECT_LBA_OOB);
|
||||
if (ret == -2) {
|
||||
CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test");
|
||||
return;
|
||||
}
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
GETLBASTATUS(sd, NULL, num_blocks + 1, 24,
|
||||
EXPECT_LBA_OOB);
|
||||
|
||||
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,
|
||||
EXPECT_LBA_OOB);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
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);
|
||||
logging(LOG_VERBOSE, "Test GETLBASTATUS at LBA -1");
|
||||
GETLBASTATUS(sd, NULL, 0xffffffffffffffffULL, 24,
|
||||
EXPECT_LBA_OOB);
|
||||
}
|
||||
|
||||
@@ -29,31 +29,18 @@
|
||||
void
|
||||
test_get_lba_status_simple(void)
|
||||
{
|
||||
int i, ret;
|
||||
int i;
|
||||
|
||||
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++) {
|
||||
ret = get_lba_status(sd, NULL, i, 24,
|
||||
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;
|
||||
}
|
||||
GETLBASTATUS(sd, NULL, i, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
}
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test GET_LBA_STATUS of 1-256 blocks at the end of the LUN");
|
||||
logging(LOG_VERBOSE, "Test GETLBASTATUS of 1-256 blocks at the end of the LUN");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = get_lba_status(sd, NULL, num_blocks - i, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
if (ret != 0) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
|
||||
return;
|
||||
}
|
||||
GETLBASTATUS(sd, NULL, num_blocks - i, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ test_get_lba_status_unmap_single(void)
|
||||
memset(scratch, 'A', (256 + lbppb + 1) * block_size);
|
||||
|
||||
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");
|
||||
logging(LOG_VERBOSE, "We have %d logical blocks per physical block",
|
||||
lbppb);
|
||||
@@ -66,38 +66,27 @@ test_get_lba_status_unmap_single(void)
|
||||
|
||||
logging(LOG_VERBOSE, "Read the status of the block at LBA:%"
|
||||
PRIu64, i);
|
||||
ret = get_lba_status(sd, NULL, i, 24,
|
||||
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;
|
||||
}
|
||||
GETLBASTATUS(sd, NULL, i, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
|
||||
logging(LOG_VERBOSE, "Read the status of the block at LBA:%"
|
||||
PRIu64, i + lbppb);
|
||||
ret = get_lba_status(sd, &t, i + lbppb, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
if (ret != 0) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
|
||||
return;
|
||||
}
|
||||
GETLBASTATUS(sd, &t, i + lbppb, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
if (t == NULL) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS task is NULL");
|
||||
CU_FAIL("[FAILED] GETLBASTATUS task is NULL");
|
||||
return;
|
||||
}
|
||||
lbas = scsi_datain_unmarshall(t);
|
||||
if (lbas == NULL) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS command: failed "
|
||||
CU_FAIL("[FAILED] GETLBASTATUS command: failed "
|
||||
"to unmarshall data.");
|
||||
scsi_free_scsi_task(t);
|
||||
return;
|
||||
}
|
||||
lbasd = &lbas->descriptors[0];
|
||||
if (lbasd->lba != i + lbppb) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS command: "
|
||||
CU_FAIL("[FAILED] GETLBASTATUS command: "
|
||||
"lba offset in first descriptor does not "
|
||||
"match request.");
|
||||
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, "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");
|
||||
for (i = lbppb; i + lbppb <= 256; i += lbppb) {
|
||||
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");
|
||||
|
||||
ret = get_lba_status(sd, NULL, 0, 24,
|
||||
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;
|
||||
}
|
||||
GETLBASTATUS(sd, NULL, 0, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
|
||||
logging(LOG_VERBOSE, "Read the status of the block at LBA:%" PRIu64, i + 1);
|
||||
ret = get_lba_status(sd, &t, i + 1, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
if (ret != 0) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS command failed");
|
||||
return;
|
||||
}
|
||||
GETLBASTATUS(sd, &t, i + 1, 24,
|
||||
EXPECT_STATUS_GOOD);
|
||||
if (t == NULL) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS task is NULL");
|
||||
CU_FAIL("[FAILED] GETLBASTATUS task is NULL");
|
||||
return;
|
||||
}
|
||||
lbas = scsi_datain_unmarshall(t);
|
||||
if (lbas == NULL) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS command: failed "
|
||||
CU_FAIL("[FAILED] GETLBASTATUS command: failed "
|
||||
"to unmarshall data.");
|
||||
scsi_free_scsi_task(t);
|
||||
return;
|
||||
}
|
||||
lbasd = &lbas->descriptors[0];
|
||||
if (lbasd->lba != i + lbppb) {
|
||||
CU_FAIL("[FAILED] GET_LBA_STATUS command: "
|
||||
CU_FAIL("[FAILED] GETLBASTATUS command: "
|
||||
"lba offset in first descriptor does not "
|
||||
"match request.");
|
||||
scsi_free_scsi_task(t);
|
||||
|
||||
@@ -109,8 +109,8 @@ check_unmap(void)
|
||||
uint64_t lba;
|
||||
|
||||
logging(LOG_VERBOSE, "Read LBA mapping from the target");
|
||||
get_lba_status(sd, &task_ret, 0, 256,
|
||||
EXPECT_STATUS_GOOD);
|
||||
GETLBASTATUS(sd, &task_ret, 0, 256,
|
||||
EXPECT_STATUS_GOOD);
|
||||
if (task_ret == NULL) {
|
||||
logging(LOG_VERBOSE, "[FAILED] Failed to read LBA mapping "
|
||||
"from the target.");
|
||||
@@ -128,7 +128,6 @@ check_unmap(void)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Unmarshall LBA mapping datain buffer");
|
||||
lbas = scsi_datain_unmarshall(task_ret);
|
||||
if (lbas == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user