From 9b436eee2f4d51a2571c93e2960b0a99caf457a6 Mon Sep 17 00:00:00 2001 From: Lee Duncan Date: Sat, 16 Feb 2013 13:56:21 -0800 Subject: [PATCH] ported 3 more group reservation tests to CUnit Ported 3 more group reservation tests to new the CUnit format. --- Makefile.am | 3 + test-tool/iscsi-support.c | 43 ++++++++++++ test-tool/iscsi-support.h | 3 +- test-tool/iscsi-test-cu.c | 23 ++++++- test-tool/iscsi-test-cu.h | 3 + test-tool/test_prin_serviceaction_range.c | 54 +++++++++++++++ test-tool/test_prout_register_simple.c | 58 ++++++++++++++++ test-tool/test_prout_reserve_simple.c | 81 +++++++++++++++++++++++ 8 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 test-tool/test_prin_serviceaction_range.c create mode 100644 test-tool/test_prout_register_simple.c create mode 100644 test-tool/test_prout_reserve_simple.c diff --git a/Makefile.am b/Makefile.am index ed67040..76d9497 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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_flags.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_beyond_eol.c \ test-tool/test_read6_0blocks.c \ diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index b349caa..634c4b9 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -187,6 +187,49 @@ iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *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 prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp, struct scsi_persistent_reserve_in_read_keys **rkp) diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index e543c31..3b69f14 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -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, struct scsi_persistent_reserve_in_read_keys **rkp); - int prout_register_and_ignore(struct iscsi_context *iscsi, int lun, unsigned long long key); int prout_register_key(struct iscsi_context *iscsi, int lun, diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 649b3ea..d45f7ce 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -225,6 +225,21 @@ static CU_TestInfo tests_prin_read_keys[] = { 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[] = { { (char *)"TestGetLBAStatus", test_setup, test_teardown, tests_get_lba_status }, @@ -266,6 +281,12 @@ static CU_SuiteInfo suites[] = { tests_writesame16 }, { (char *)"TestPrinReadKeys", test_setup, test_teardown, 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 }; @@ -312,7 +333,7 @@ print_usage(void) fprintf(stderr, " -v|--verbose Test Mode: Verbose [DEFAULT]\n"); 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, "Where iSCSI URL format is: %s\n", ISCSI_URL_SYNTAX); diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index a6cc7bd..8acd32d 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -141,5 +141,8 @@ void test_writesame16_unmap_unaligned(void); void test_writesame16_unmap_until_end(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_ */ diff --git a/test-tool/test_prin_serviceaction_range.c b/test-tool/test_prin_serviceaction_range.c new file mode 100644 index 0000000..7e3420b --- /dev/null +++ b/test-tool/test_prin_serviceaction_range.c @@ -0,0 +1,54 @@ +/* + Copyright (C) 2013 by Lee Duncan + + 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-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); + } +} diff --git a/test-tool/test_prout_register_simple.c b/test-tool/test_prout_register_simple.c new file mode 100644 index 0000000..4cdd6eb --- /dev/null +++ b/test-tool/test_prout_register_simple.c @@ -0,0 +1,58 @@ +/* + Copyright (C) 2013 by Lee Duncan + + 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-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); +} diff --git a/test-tool/test_prout_reserve_simple.c b/test-tool/test_prout_reserve_simple.c new file mode 100644 index 0000000..9266711 --- /dev/null +++ b/test-tool/test_prout_reserve_simple.c @@ -0,0 +1,81 @@ +/* + Copyright (C) 2013 by Lee Duncan + + 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-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); + +}