TESTS: Add tests for STARTSTOPUNIT
This commit is contained in:
@@ -231,6 +231,9 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
|
||||
test-tool/test_readcapacity16_simple.c \
|
||||
test-tool/test_readcapacity16_alloclen.c \
|
||||
test-tool/test_readonly_sbc.c \
|
||||
test-tool/test_startstopunit_simple.c \
|
||||
test-tool/test_startstopunit_pwrcnd.c \
|
||||
test-tool/test_startstopunit_noloej.c \
|
||||
test-tool/test_testunitready_simple.c \
|
||||
test-tool/test_unmap_simple.c \
|
||||
test-tool/test_unmap_0blocks.c \
|
||||
|
||||
@@ -1022,6 +1022,31 @@ verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send STARTSTOPUNIT (Expecting SUCCESS) IMMED:%d PCM:%d PC:%d NO_FLUSH:%d LOEJ:%d START:%d", immed, pcm, pc, no_flush, loej, start);
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, immed, pcm, pc, no_flush,
|
||||
loej, start);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL,
|
||||
"[FAILED] Failed to send STARTSTOPUNIT command: %s",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL,
|
||||
"[FAILED] STARTSTOPUNIT command: failed with sense. %s",
|
||||
iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] STARTSTOPUNIT returned SUCCESS.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
testunitready(struct iscsi_context *iscsi, int lun)
|
||||
{
|
||||
@@ -1043,7 +1068,7 @@ testunitready(struct iscsi_context *iscsi, int lun)
|
||||
return -1;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] TestUnitReady returned SUCCESS.");
|
||||
logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned SUCCESS.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1078,12 +1103,11 @@ testunitready_nomedium(struct iscsi_context *iscsi, int lun)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
printf("Send TESTUNITREADY (expecting NOT_READY/MEDIUM_NOT_PRESENT) ... ");
|
||||
logging(LOG_VERBOSE, "Send TESTUNITREADY (expecting NOT_READY/MEDIUM_NOT_PRESENT)");
|
||||
task = iscsi_testunitready_sync(iscsi, lun);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send TESTUNITREADY command: %s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY "
|
||||
"command: %s", iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
@@ -1091,13 +1115,14 @@ testunitready_nomedium(struct iscsi_context *iscsi, int lun)
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("TESTUNITREADY Should have failed with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
logging(LOG_NORMAL, "[FAILED] TESTUNITREADY Should have failed "
|
||||
"with NOT_READY/MEDIUM_NOT_PRESENT* Buut failed "
|
||||
"with %s", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned MEDIUM_NOT_PRESENT.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1106,21 +1131,19 @@ testunitready_conflict(struct iscsi_context *iscsi, int lun)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
printf("Send TESTUNITREADY (expecting RESERVATION_CONFLICT) ... ");
|
||||
logging(LOG_VERBOSE, "Send TESTUNITREADY (expecting RESERVATION_CONFLICT)");
|
||||
task = iscsi_testunitready_sync(iscsi, lun);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send TESTUNITREADY command: %s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY "
|
||||
"command: %s", iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Expected RESERVATION CONFLICT\n");
|
||||
logging(LOG_NORMAL, "[FAILED] Expected RESERVATION CONFLICT");
|
||||
return -1;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned RESERVATION_CONFLICT.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -221,6 +221,7 @@ int read16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
int read16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data);
|
||||
int readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi);
|
||||
int readcapacity16(struct iscsi_context *iscsi, int lun, int alloc_len);
|
||||
int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start);
|
||||
int testunitready_clear_ua(struct iscsi_context *iscsi, int lun);
|
||||
int testunitready(struct iscsi_context *iscsi, int lun);
|
||||
int testunitready_nomedium(struct iscsi_context *iscsi, int lun);
|
||||
|
||||
@@ -193,6 +193,13 @@ static CU_TestInfo tests_testunitready[] = {
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_startstopunit[] = {
|
||||
{ (char *)"testStartStopUnitSimple", test_startstopunit_simple },
|
||||
{ (char *)"testStartStopUnitPwrCnd", test_startstopunit_pwrcnd },
|
||||
{ (char *)"testStartStopUnitNoLoej", test_startstopunit_noloej },
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_unmap[] = {
|
||||
{ (char *)"testUnmapSimple", test_unmap_simple },
|
||||
{ (char *)"testUnmapZeroBlocks", test_unmap_0blocks },
|
||||
@@ -339,6 +346,8 @@ static CU_SuiteInfo suites[] = {
|
||||
tests_readcapacity16 },
|
||||
{ (char *)"TestReadOnly", test_setup, test_teardown,
|
||||
tests_readonly },
|
||||
{ (char *)"TestStartStopUnit", test_setup, test_teardown,
|
||||
tests_startstopunit },
|
||||
{ (char *)"TestTestUnitReady", test_setup, test_teardown,
|
||||
tests_testunitready },
|
||||
{ (char *)"TestUnmap", test_setup, test_teardown,
|
||||
|
||||
@@ -110,6 +110,10 @@ void test_readcapacity16_alloclen(void);
|
||||
|
||||
void test_readonly_sbc(void);
|
||||
|
||||
void test_startstopunit_simple(void);
|
||||
void test_startstopunit_pwrcnd(void);
|
||||
void test_startstopunit_noloej(void);
|
||||
|
||||
void test_testunitready_simple(void);
|
||||
|
||||
void test_unmap_simple(void);
|
||||
|
||||
116
test-tool/test_startstopunit_noloej.c
Normal file
116
test-tool/test_startstopunit_noloej.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
void
|
||||
test_startstopunit_noloej(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||
logging(LOG_VERBOSE, "Test STARTSTOPUNIT LOEJ==0");
|
||||
if (!removable) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] LUN is not removalbe. "
|
||||
"Skipping test.");
|
||||
return;
|
||||
}
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==0 START==0");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
0, 0, 0, 0, 0, 0);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==0 START==1");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
0, 0, 0, 0, 0, 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==0 START==0");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
1, 0, 0, 0, 0, 0);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==0 START==1");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
1, 0, 0, 0, 0, 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==1 START==0");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
0, 0, 0, 1, 0, 0);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==1 START==1");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
0, 0, 0, 1, 0, 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==1 START==0");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
1, 0, 0, 1, 0, 0);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==1 START==1");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
1, 0, 0, 1, 0, 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "In case the target did eject the medium, load it again.");
|
||||
startstopunit(iscsic, tgt_lun, 1, 0, 0, 0, 1, 1);
|
||||
}
|
||||
54
test-tool/test_startstopunit_pwrcnd.c
Normal file
54
test-tool/test_startstopunit_pwrcnd.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
void
|
||||
test_startstopunit_pwrcnd(void)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||
logging(LOG_VERBOSE, "Test STARTSTOPUNIT PowerCondition");
|
||||
if (!removable) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] LUN is not removalbe. "
|
||||
"Skipping test.");
|
||||
return;
|
||||
}
|
||||
|
||||
logging(LOG_VERBOSE, "Test that media is not ejected when PC!=0");
|
||||
for (i = 1; i < 16; i++) {
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
1, 0, i, 0, 1, 0);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is not ejected.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
|
||||
logging(LOG_VERBOSE, "In case the target did eject the medium, load it again.");
|
||||
startstopunit(iscsic, tgt_lun, 1, 0, 0, 0, 1, 1);
|
||||
}
|
||||
88
test-tool/test_startstopunit_simple.c
Normal file
88
test-tool/test_startstopunit_simple.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
void
|
||||
test_startstopunit_simple(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||
logging(LOG_VERBOSE, "Test basic STARTSTOPUNIT");
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test we can eject removable the media with IMMED==1");
|
||||
if (removable) {
|
||||
logging(LOG_VERBOSE, "Media is not removable. STARTSTOPUNIT should fail");
|
||||
} else {
|
||||
logging(LOG_VERBOSE, "Media is removable. STARTSTOPUNIT should work");
|
||||
}
|
||||
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
1, 0, 0, 0, 1, 0);
|
||||
if (!removable) {
|
||||
CU_ASSERT_NOT_EQUAL(ret, 0);
|
||||
return;
|
||||
}
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is ejected.");
|
||||
ret = testunitready_nomedium(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test we can load the removable the media with IMMED==1");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
1, 0, 0, 0, 1, 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Verify we can read from the media.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test we can eject removable the media with IMMED==1");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
0, 0, 0, 0, 1, 0);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test TESTNUITREADY that medium is ejected.");
|
||||
ret = testunitready_nomedium(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
|
||||
logging(LOG_VERBOSE, "Test we can load the removable the media with IMMED==1");
|
||||
ret = startstopunit(iscsic, tgt_lun,
|
||||
0, 0, 0, 0, 1, 1);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "Verify we can read from the media.");
|
||||
ret = testunitready(iscsic, tgt_lun);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user