ported 3 more group reservation tests to CUnit
Ported 3 more group reservation tests to new the CUnit format.
This commit is contained in:
committed by
Ronnie Sahlberg
parent
99ef5c6495
commit
9b436eee2f
@@ -187,6 +187,9 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
|
|||||||
test-tool/test_prefetch16_0blocks.c \
|
test-tool/test_prefetch16_0blocks.c \
|
||||||
test-tool/test_prefetch16_flags.c \
|
test-tool/test_prefetch16_flags.c \
|
||||||
test-tool/test_prin_read_keys_simple.c \
|
test-tool/test_prin_read_keys_simple.c \
|
||||||
|
test-tool/test_prin_serviceaction_range.c \
|
||||||
|
test-tool/test_prout_register_simple.c \
|
||||||
|
test-tool/test_prout_reserve_simple.c \
|
||||||
test-tool/test_read6_simple.c \
|
test-tool/test_read6_simple.c \
|
||||||
test-tool/test_read6_beyond_eol.c \
|
test-tool/test_read6_beyond_eol.c \
|
||||||
test-tool/test_read6_0blocks.c \
|
test-tool/test_read6_0blocks.c \
|
||||||
|
|||||||
@@ -187,6 +187,49 @@ iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
|||||||
return real_iscsi_queue_pdu(iscsi, pdu);
|
return real_iscsi_queue_pdu(iscsi, pdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
prin_task(struct iscsi_context *iscsi, int lun, int service_action,
|
||||||
|
int success_expected)
|
||||||
|
{
|
||||||
|
const int buf_sz = 16384;
|
||||||
|
struct scsi_task *task;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
|
||||||
|
logging(LOG_VERBOSE, "Send PRIN/SA=0x%02x, expect %s", service_action,
|
||||||
|
success_expected ? "success" : "failure");
|
||||||
|
|
||||||
|
task = iscsi_persistent_reserve_in_sync(iscsi, lun,
|
||||||
|
service_action, buf_sz);
|
||||||
|
if (task == NULL) {
|
||||||
|
logging(LOG_NORMAL,
|
||||||
|
"[FAILED] Failed to send PRIN command: %s",
|
||||||
|
iscsi_get_error(iscsi));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success_expected) {
|
||||||
|
if (task->status != SCSI_STATUS_GOOD) {
|
||||||
|
logging(LOG_NORMAL,
|
||||||
|
"[FAILED] PRIN/SA=0x%x failed: %s",
|
||||||
|
service_action, iscsi_get_error(iscsi));
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (task->status == SCSI_STATUS_GOOD) {
|
||||||
|
logging(LOG_NORMAL,
|
||||||
|
"[FAILED] PRIN/SA=0x%x succeeded with invalid serviceaction",
|
||||||
|
service_action);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scsi_free_scsi_task(task);
|
||||||
|
task = NULL;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp,
|
prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp,
|
||||||
struct scsi_persistent_reserve_in_read_keys **rkp)
|
struct scsi_persistent_reserve_in_read_keys **rkp)
|
||||||
|
|||||||
@@ -165,9 +165,10 @@ static inline int pr_type_is_all_registrants(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int prin_task(struct iscsi_context *iscsi, int lun, int service_action,
|
||||||
|
int success_expected);
|
||||||
int prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp,
|
int prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp,
|
||||||
struct scsi_persistent_reserve_in_read_keys **rkp);
|
struct scsi_persistent_reserve_in_read_keys **rkp);
|
||||||
|
|
||||||
int prout_register_and_ignore(struct iscsi_context *iscsi, int lun,
|
int prout_register_and_ignore(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long key);
|
unsigned long long key);
|
||||||
int prout_register_key(struct iscsi_context *iscsi, int lun,
|
int prout_register_key(struct iscsi_context *iscsi, int lun,
|
||||||
|
|||||||
@@ -225,6 +225,21 @@ static CU_TestInfo tests_prin_read_keys[] = {
|
|||||||
CU_TEST_INFO_NULL
|
CU_TEST_INFO_NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static CU_TestInfo tests_prout_register[] = {
|
||||||
|
{ (char *)"testProutRegisterSimple", test_prout_register_simple },
|
||||||
|
CU_TEST_INFO_NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static CU_TestInfo tests_prout_reserve[] = {
|
||||||
|
{ (char *)"testProutReserveSimple", test_prout_reserve_simple },
|
||||||
|
CU_TEST_INFO_NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static CU_TestInfo tests_prin_serviceaction_range[] = {
|
||||||
|
{ (char *)"testPrinServiceactionRange", test_prin_serviceaction_range },
|
||||||
|
CU_TEST_INFO_NULL
|
||||||
|
};
|
||||||
|
|
||||||
static CU_SuiteInfo suites[] = {
|
static CU_SuiteInfo suites[] = {
|
||||||
{ (char *)"TestGetLBAStatus", test_setup, test_teardown,
|
{ (char *)"TestGetLBAStatus", test_setup, test_teardown,
|
||||||
tests_get_lba_status },
|
tests_get_lba_status },
|
||||||
@@ -266,6 +281,12 @@ static CU_SuiteInfo suites[] = {
|
|||||||
tests_writesame16 },
|
tests_writesame16 },
|
||||||
{ (char *)"TestPrinReadKeys", test_setup, test_teardown,
|
{ (char *)"TestPrinReadKeys", test_setup, test_teardown,
|
||||||
tests_prin_read_keys },
|
tests_prin_read_keys },
|
||||||
|
{ (char *)"TestPrinServiceactionRange", test_setup, test_teardown,
|
||||||
|
tests_prin_serviceaction_range },
|
||||||
|
{ (char *)"TestProutRegister", test_setup, test_teardown,
|
||||||
|
tests_prout_register },
|
||||||
|
{ (char *)"TestProutReserve", test_setup, test_teardown,
|
||||||
|
tests_prout_reserve },
|
||||||
CU_SUITE_INFO_NULL
|
CU_SUITE_INFO_NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -312,7 +333,7 @@ print_usage(void)
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" -v|--verbose Test Mode: Verbose [DEFAULT]\n");
|
" -v|--verbose Test Mode: Verbose [DEFAULT]\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"-V|--Verbose-scsi Enable verbose SCSI logging [default SILENT]\n");
|
" -V|--Verbose-scsi Enable verbose SCSI logging [default SILENT]\n");
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Where <iscsi-url> iSCSI URL format is: %s\n", ISCSI_URL_SYNTAX);
|
"Where <iscsi-url> iSCSI URL format is: %s\n", ISCSI_URL_SYNTAX);
|
||||||
|
|||||||
@@ -141,5 +141,8 @@ void test_writesame16_unmap_unaligned(void);
|
|||||||
void test_writesame16_unmap_until_end(void);
|
void test_writesame16_unmap_until_end(void);
|
||||||
|
|
||||||
void test_prin_read_keys_simple(void);
|
void test_prin_read_keys_simple(void);
|
||||||
|
void test_prin_serviceaction_range(void);
|
||||||
|
void test_prout_register_simple(void);
|
||||||
|
void test_prout_reserve_simple(void);
|
||||||
|
|
||||||
#endif /* _ISCSI_TEST_CU_H_ */
|
#endif /* _ISCSI_TEST_CU_H_ */
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2013 by Lee Duncan <lee@gonzoleeman.net>
|
||||||
|
|
||||||
|
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 <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <CUnit/CUnit.h>
|
||||||
|
|
||||||
|
#include "iscsi.h"
|
||||||
|
#include "scsi-lowlevel.h"
|
||||||
|
#include "iscsi-support.h"
|
||||||
|
#include "iscsi-test-cu.h"
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
test_prin_serviceaction_range(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
|
||||||
|
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||||
|
logging(LOG_VERBOSE, "Test Persistent Reserve IN Serviceaction range.");
|
||||||
|
|
||||||
|
/* verify PRIN/READ_KEYS works -- XXX redundant -- remove this? */
|
||||||
|
ret = prin_read_keys(iscsic, tgt_lun, &task, NULL);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
/* verify that PRIN/SA={0,1,2,3} works ... */
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
ret = prin_task(iscsic, tgt_lun, i, 1);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* verify that PRIN/SA={4..0x20} fails ... */
|
||||||
|
for (i = 4; i < 0x20; i++) {
|
||||||
|
ret = prin_task(iscsic, tgt_lun, i, 0);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2013 by Lee Duncan <lee@gonzoleeman.net>
|
||||||
|
|
||||||
|
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 <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <CUnit/CUnit.h>
|
||||||
|
|
||||||
|
#include "iscsi.h"
|
||||||
|
#include "scsi-lowlevel.h"
|
||||||
|
#include "iscsi-support.h"
|
||||||
|
#include "iscsi-test-cu.h"
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
test_prout_register_simple(void)
|
||||||
|
{
|
||||||
|
const unsigned long long key = rand_key();
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
|
||||||
|
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||||
|
logging(LOG_VERBOSE, "Test Persistent Reserve IN REGISTER works.");
|
||||||
|
|
||||||
|
/* register our reservation key with the target */
|
||||||
|
ret = prout_register_and_ignore(iscsic, tgt_lun, key);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
/* verify we can read the registration */
|
||||||
|
ret = prin_verify_key_presence(iscsic, tgt_lun, key, 1);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
/* try to reregister, which should fail */
|
||||||
|
ret = prout_reregister_key_fails(iscsic, tgt_lun, key+1);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
/* release from the target */
|
||||||
|
ret = prout_register_key(iscsic, tgt_lun, 0, key);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
/* Verify the registration is gone */
|
||||||
|
ret = prin_verify_key_presence(iscsic, tgt_lun, key, 0);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2013 by Lee Duncan <lee@gonzoleeman.net>
|
||||||
|
|
||||||
|
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 <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <CUnit/CUnit.h>
|
||||||
|
|
||||||
|
#include "iscsi.h"
|
||||||
|
#include "scsi-lowlevel.h"
|
||||||
|
#include "iscsi-support.h"
|
||||||
|
#include "iscsi-test-cu.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* list of persistent reservation types to test, in order
|
||||||
|
*/
|
||||||
|
static enum scsi_persistent_out_type pr_types_to_test[] = {
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE,
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS,
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_REGISTRANTS_ONLY,
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_REGISTRANTS_ONLY,
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_ALL_REGISTRANTS,
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_ALL_REGISTRANTS,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
test_prout_reserve_simple(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int i;
|
||||||
|
const unsigned long long key = rand_key();
|
||||||
|
|
||||||
|
|
||||||
|
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||||
|
logging(LOG_VERBOSE, "Test Persistent Reserve IN RESERVE works.");
|
||||||
|
|
||||||
|
/* register our reservation key with the target */
|
||||||
|
ret = prout_register_and_ignore(iscsic, tgt_lun, key);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
/* test each reservatoin type */
|
||||||
|
for (i = 0; pr_types_to_test[i] != 0; i++) {
|
||||||
|
enum scsi_persistent_out_type pr_type = pr_types_to_test[i];
|
||||||
|
|
||||||
|
/* reserve the target */
|
||||||
|
ret = prout_reserve(iscsic, tgt_lun, key, pr_type);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
/* verify target reservation */
|
||||||
|
ret = prin_verify_reserved_as(iscsic, tgt_lun,
|
||||||
|
pr_type_is_all_registrants(pr_type) ? 0 : key,
|
||||||
|
pr_type);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
/* release our reservation */
|
||||||
|
ret = prout_release(iscsic, tgt_lun, key, pr_type);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* remove our key from the target */
|
||||||
|
ret = prout_register_key(iscsic, tgt_lun, 0, key);
|
||||||
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user