Example #1
0
void
test_prefetch10_flags(void)
{ 
	int ret;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test PREFETCH10 flags");

	logging(LOG_VERBOSE, "Test PREFETCH10 with IMMED==1");
	ret = prefetch10(sd, 0, 1, 1, 0,
			 EXPECT_STATUS_GOOD);
	if (ret == -2) {
		logging(LOG_NORMAL, "[SKIPPED] PREFETCH10 is not implemented.");
		CU_PASS("PREFETCH10 is not implemented.");
		return;
	}	
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Test PREFETCH10 with GROUP==3");
	ret = prefetch10(sd, 0, 1, 0, 3,
			 EXPECT_STATUS_GOOD);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Test PREFETCH10 with IMMED=1 and GROUP==3");
	ret = prefetch10(sd, 0, 1, 1, 3,
			 EXPECT_STATUS_GOOD);
	CU_ASSERT_EQUAL(ret, 0);
}
void
test_prefetch10_beyond_eol(void)
{ 
	int i, ret;

	if (num_blocks >= 0x80000000) {
		CU_PASS("LUN is too big for read-beyond-eol tests with PREFETCH10. Skipping test.\n");
		return;
	}

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test PREFETCH10 1-256 blocks one block beyond the end");
	for (i = 1; i <= 256; i++) {
		ret = prefetch10(sd, num_blocks + 1 - i, i, 0, 0,
				 EXPECT_LBA_OOB);
		if (ret == -2) {
			logging(LOG_NORMAL, "[SKIPPED] PREFETCH10 is not implemented.");
			CU_PASS("PREFETCH10 is not implemented.");
			return;
		}	
		CU_ASSERT_EQUAL(ret, 0);
	}


	logging(LOG_VERBOSE, "Test PREFETCH10 1-256 blocks at LBA==2^31");
	for (i = 1; i <= 256; i++) {
		ret = prefetch10(sd, 0x80000000, i, 0, 0,
				 EXPECT_LBA_OOB);
		CU_ASSERT_EQUAL(ret, 0);
	}


	logging(LOG_VERBOSE, "Test PREFETCH10 1-256 blocks at LBA==-1");
	for (i = 1; i <= 256; i++) {
		ret = prefetch10(sd, -1, i, 0, 0,
				 EXPECT_LBA_OOB);
		CU_ASSERT_EQUAL(ret, 0);
	}


	logging(LOG_VERBOSE, "Test PREFETCH10 2-256 blocks all but one block beyond the end");
	for (i = 2; i <= 256; i++) {
		ret = prefetch10(sd, num_blocks - 1, i, 0, 0,
				 EXPECT_LBA_OOB);
		CU_ASSERT_EQUAL(ret, 0);
	}
}
void
test_prefetch10_0blocks(void)
{
	int ret;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test PREFETCH10 0-blocks at LBA==0");
	ret = prefetch10(iscsic, tgt_lun, 0,
			 0, 0, 0);
	if (ret == -2) {
		logging(LOG_NORMAL, "[SKIPPED] PREFETCH10 is not implemented.");
		CU_PASS("PREFETCH10 is not implemented.");
		return;
	}	
	CU_ASSERT_EQUAL(ret, 0);

	if (num_blocks > 0x80000000) {
		CU_PASS("[SKIPPED] LUN is too big");
		return;
	}

	logging(LOG_VERBOSE, "Test PREFETCH10 0-blocks one block past end-of-LUN");
	ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1,
				       0, 0, 0);
	CU_ASSERT_EQUAL(ret, 0);


	logging(LOG_VERBOSE, "Test PREFETCH10 0-blocks at LBA==2^31");
	ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, 0x80000000,
				       0, 0, 0);
	CU_ASSERT_EQUAL(ret, 0);


	logging(LOG_VERBOSE, "Test PREFETCH10 0-blocks at LBA==-1");
	ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, -1,
				       0, 0, 0);
	CU_ASSERT_EQUAL(ret, 0);
}
int T0243_prefetch10_0blocks(const char *initiator, const char *url)
{ 
	struct iscsi_context *iscsi;
	int ret, lun;

	printf("0243_prefetch10_0blocks:\n");
	printf("===================\n");
	if (show_info) {
		printf("Test that PREFETCH10 works correctly when transfer length is 0 blocks.\n");
		printf("Transfer Length == 0 means to PREFETCH until the end of the LUN.\n");
		printf("1, Prefetch at LBA:0 should work.\n");
		printf("2, Prefetch at one block beyond end-of-lun should fail. (only on LUNs with less than 2^31 blocks)\n");
		printf("3, Prefetch at LBA:2^31 should fail (only on LUNs with less than 2^31 blocks).\n");
		printf("4, Prefetch at LBA:-1 should fail (only on LUNs with less than 2^31 blocks).\n");
		printf("\n");
		return 0;
	}

	iscsi = iscsi_context_login(initiator, url, &lun);
	if (iscsi == NULL) {
		printf("Failed to login to target\n");
		return -1;
	}


	ret = 0;


	/* prefetch 0blocks at the start of the LUN */
	printf("PREFETCH10 0blocks at LBA==0.\n");
	ret = prefetch10(iscsi, lun, 0, 0, 0, 0);
	if (ret != 0) {
		goto finished;
	}


	/* Prefetch 0 blocks beyond end of the LUN */
	printf("PREFETCH10 0blocks at one block beyond <end-of-LUN>.\n");
	if (num_blocks > 0x80000000) {
	        printf("[SKIPPED]\n");
		printf("LUN is too big, skipping test\n");
		goto finished;
	}
	ret = prefetch10_lbaoutofrange(iscsi, lun, num_blocks + 1, 0, 0, 0);
	if (ret != 0) {
		goto finished;
	}


	/* Prefetch 0blocks at LBA:2^31 */
	printf("PREFETCH10 0blocks at LBA:2^31.\n");
	ret = prefetch10_lbaoutofrange(iscsi, lun, 0x80000000, 0, 0, 0);
	if (ret != 0) {
		goto finished;
	}


	/* Prefetch 0blocks at LBA:-1 */
	printf("PREFETCH10 0blocks at LBA:-1.\n");
	ret = prefetch10_lbaoutofrange(iscsi, lun, 0xffffffff, 0, 0, 0);
	if (ret != 0) {
		goto finished;
	}


finished:
	iscsi_logout_sync(iscsi);
	iscsi_destroy_context(iscsi);
	return ret;
}