From ba14452dc253fd59cd9faca4c78d73c77d9568e7 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 21 Sep 2012 20:15:04 -0700 Subject: [PATCH] TEST: Add a test that reads all reported VPD pages and validates qualifier, type and page-code in the returned data --- Makefile.am | 1 + test-tool/0404_inquiry_all_reported_vpd.c | 160 ++++++++++++++++++++++ test-tool/iscsi-test.c | 1 + test-tool/iscsi-test.h | 1 + 4 files changed, 163 insertions(+) create mode 100644 test-tool/0404_inquiry_all_reported_vpd.c diff --git a/Makefile.am b/Makefile.am index ec83693..a50bc91 100644 --- a/Makefile.am +++ b/Makefile.am @@ -132,6 +132,7 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ test-tool/0401_inquiry_alloclen.c \ test-tool/0402_inquiry_evpd.c \ test-tool/0403_inquiry_supported_vpd.c \ + test-tool/0404_inquiry_all_reported_vpd.c \ \ test-tool/1000_cmdsn_invalid.c \ test-tool/1010_datasn_invalid.c \ diff --git a/test-tool/0404_inquiry_all_reported_vpd.c b/test-tool/0404_inquiry_all_reported_vpd.c new file mode 100644 index 0000000..388b539 --- /dev/null +++ b/test-tool/0404_inquiry_all_reported_vpd.c @@ -0,0 +1,160 @@ +/* + Copyright (C) 2012 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include +#include +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0404_inquiry_all_reported_vpd(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + struct scsi_task *task; + struct scsi_inquiry_supported_pages *inq; + int ret, lun, i; + int full_size; + enum scsi_inquiry_pagecode page_code; + + printf("0404_inquiry_all_reported_vpd:\n"); + printf("==========================\n"); + if (show_info) { + printf("Check the INQUIRY SUPPORTED VPD page.\n"); + printf("1, Check we can read the SUPPORTED VPD page.\n"); + printf("2, Verify we can read each reported page and check the qualifier,device-type and page code on the returned data\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; + + + + printf("Read SUPPORTED VPD data ... "); + /* See how big this inquiry data is */ + page_code = SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES; + task = iscsi_inquiry_sync(iscsi, lun, 1, page_code, 255); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send INQUIRY command : %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("INQUIRY command failed : %s\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + ret = -1; + goto finished; + } + full_size = scsi_datain_getfullsize(task); + if (full_size > task->datain.size) { + scsi_free_scsi_task(task); + + /* we need more data for the full list */ + if ((task = iscsi_inquiry_sync(iscsi, lun, 1, page_code, full_size)) == NULL) { + printf("[FAILED]\n"); + printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + } + inq = scsi_datain_unmarshall(task); + if (inq == NULL) { + printf("[FAILED]\n"); + printf("failed to unmarshall inquiry datain blob\n"); + scsi_free_scsi_task(task); + ret = -1; + goto finished; + } + printf("[OK]\n"); + +test2: + printf("Read each page and verify the page size:\n"); + for (i = 0; i < inq->num_pages; i++) { + struct scsi_task *pc_task; + + printf("Verify page 0x%02x can be read ... ", inq->pages[i]); + pc_task = iscsi_inquiry_sync(iscsi, lun, 1, inq->pages[i], 255); + if (pc_task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send INQUIRY command : %s\n", iscsi_get_error(iscsi)); + ret = -1; + continue; + } + if (pc_task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("Failed to read VPD page : %s\n", iscsi_get_error(iscsi)); + scsi_free_scsi_task(pc_task); + ret = -1; + continue; + } + printf("[OK]\n"); + + printf("Verify page 0x%02x qualifier ... ", inq->pages[i]); + if ((pc_task->datain.data[0] & 0xe0) >> 5 != inq->qualifier) { + printf("[FAILED]\n"); + printf("Qualifier differs between VPD pages\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(pc_task); + continue; + } else { + printf("[OK]\n"); + } + + printf("Verify page 0x%02x device type ... ", inq->pages[i]); + if (pc_task->datain.data[0] & 0x1f != inq->device_type) { + printf("[FAILED]\n"); + printf("Device Type differs between VPD pages\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(pc_task); + continue; + } else { + printf("[OK]\n"); + } + + printf("Verify page 0x%02x page code ... ", inq->pages[i]); + if (pc_task->datain.data[1] != inq->pages[i]) { + printf("[FAILED]\n"); + printf("Page code is wrong\n", iscsi_get_error(iscsi)); + ret = -1; + scsi_free_scsi_task(pc_task); + continue; + } else { + printf("[OK]\n"); + } + + scsi_free_scsi_task(pc_task); + } + + +test3: + scsi_free_scsi_task(task); + +finished: + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + return ret; +} diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index 5dd7e87..558fbf9 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -209,6 +209,7 @@ struct scsi_test tests[] = { { "T0401_inquiry_alloclen", T0401_inquiry_alloclen }, { "T0402_inquiry_evpd", T0402_inquiry_evpd }, { "T0403_inquiry_supported_vpd", T0403_inquiry_supported_vpd }, +{ "T0404_inquiry_all_reported_vpd", T0404_inquiry_all_reported_vpd }, /* iSCSI protocol tests */ diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index deecefd..78caa41 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -162,6 +162,7 @@ int T0400_inquiry_basic(const char *initiator, const char *url, int data_loss, i int T0401_inquiry_alloclen(const char *initiator, const char *url, int data_loss, int show_info); int T0402_inquiry_evpd(const char *initiator, const char *url, int data_loss, int show_info); int T0403_inquiry_supported_vpd(const char *initiator, const char *url, int data_loss, int show_info); +int T0404_inquiry_all_reported_vpd(const char *initiator, const char *url, int data_loss, int show_info); int T1000_cmdsn_invalid(const char *initiator, const char *url, int data_loss, int show_info); int T1010_datasn_invalid(const char *initiator, const char *url, int data_loss, int show_info);