From 5c0b1b9913159c181d3df3ff144272c3aa629932 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Fri, 18 Sep 2015 18:00:51 +0200 Subject: [PATCH] test/pr: simple PR Out CLEAR test Check that a Persistent Reserve Out CLEAR request: - clears an existing reservation - clears existing registration keys - bumps the PRgeneration number Signed-off-by: David Disseldorp --- test-tool/Makefile.am | 1 + test-tool/iscsi-test-cu.c | 8 +++ test-tool/iscsi-test-cu.h | 1 + test-tool/test_prout_clear_simple.c | 87 +++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 test-tool/test_prout_clear_simple.c diff --git a/test-tool/Makefile.am b/test-tool/Makefile.am index 8c702cd..8b2e2e0 100644 --- a/test-tool/Makefile.am +++ b/test-tool/Makefile.am @@ -73,6 +73,7 @@ iscsi_test_cu_SOURCES = iscsi-test-cu.c \ test_prout_reserve_simple.c \ test_prout_reserve_access.c \ test_prout_reserve_ownership.c \ + test_prout_clear_simple.c \ test_read6_simple.c \ test_read6_beyond_eol.c \ test_read10_simple.c \ diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index c155390..4d950a7 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -192,6 +192,12 @@ static CU_TestInfo tests_prout_reserve[] = { CU_TEST_INFO_NULL }; +static CU_TestInfo tests_prout_clear[] = { + { (char *)"Simple", + test_prout_clear_simple }, + CU_TEST_INFO_NULL +}; + static CU_TestInfo tests_prin_serviceaction_range[] = { { (char *)"Range", test_prin_serviceaction_range }, CU_TEST_INFO_NULL @@ -478,6 +484,7 @@ static libiscsi_suite_info scsi_suites[] = { { "PrinServiceactionRange", NON_PGR_FUNCS, tests_prin_serviceaction_range }, { "ProutRegister", NON_PGR_FUNCS, tests_prout_register }, { "ProutReserve", NON_PGR_FUNCS, tests_prout_reserve }, + { "ProutClear", NON_PGR_FUNCS, tests_prout_clear }, { "Read6", NON_PGR_FUNCS, tests_read6 }, { "Read10", NON_PGR_FUNCS, tests_read10 }, { "Read12", NON_PGR_FUNCS, tests_read12 }, @@ -563,6 +570,7 @@ static libiscsi_suite_info all_suites[] = { tests_prin_serviceaction_range }, { "ProutRegister", NON_PGR_FUNCS, tests_prout_register }, { "ProutReserve", NON_PGR_FUNCS, tests_prout_reserve }, + { "ProutClear", NON_PGR_FUNCS, tests_prout_clear }, { "Read6", NON_PGR_FUNCS, tests_read6 }, { "Read10", NON_PGR_FUNCS, tests_read10 }, { "Read12", NON_PGR_FUNCS, tests_read12 }, diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 9dda8b5..fa9a0c0 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -129,6 +129,7 @@ void test_prout_reserve_ownership_earo(void); void test_prout_reserve_ownership_wero(void); void test_prout_reserve_ownership_eaar(void); void test_prout_reserve_ownership_wear(void); +void test_prout_clear_simple(void); void test_read6_simple(void); void test_read6_beyond_eol(void); diff --git a/test-tool/test_prout_clear_simple.c b/test-tool/test_prout_clear_simple.c new file mode 100644 index 0000000..25858f2 --- /dev/null +++ b/test-tool/test_prout_clear_simple.c @@ -0,0 +1,87 @@ +/* + Copyright (C) 2015 David Disseldorp + + 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_clear_simple(void) +{ + int ret = 0; + uint32_t old_gen; + const unsigned long long key = rand_key(); + struct scsi_task *tsk; + struct scsi_persistent_reserve_in_read_keys *rk; + + CHECK_FOR_DATALOSS; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test Persistent Reserve OUT CLEAR works."); + + /* register our reservation key with the target */ + ret = prout_register_and_ignore(sd, key); + if (ret == -2) { + logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE OUT is not implemented."); + CU_PASS("PERSISTENT RESERVE OUT is not implemented."); + return; + } + CU_ASSERT_EQUAL(ret, 0); + + ret = prin_read_keys(sd, &tsk, &rk); + CU_ASSERT_EQUAL(ret, 0); + + CU_ASSERT_NOT_EQUAL(rk->num_keys, 0); + /* retain PR generation number to check for increments */ + old_gen = rk->prgeneration; + + scsi_free_scsi_task(tsk); + rk = NULL; /* freed with tsk */ + + /* reserve the target */ + ret = prout_reserve(sd, key, + SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS); + CU_ASSERT_EQUAL(ret, 0); + + /* verify target reservation */ + ret = prin_verify_reserved_as(sd, key, + SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS); + CU_ASSERT_EQUAL(ret, 0); + + /* clear reservation and registration */ + ret = prout_clear(sd, key); + CU_ASSERT_EQUAL(ret, 0); + + ret = prin_verify_not_reserved(sd); + CU_ASSERT_EQUAL(ret, 0); + + ret = prin_read_keys(sd, &tsk, &rk); + CU_ASSERT_EQUAL(ret, 0); + + CU_ASSERT_EQUAL(rk->num_keys, 0); + /* generation incremented once for CLEAR (not for RESERVE) */ + CU_ASSERT_EQUAL(rk->prgeneration, old_gen + 1); + + scsi_free_scsi_task(tsk); + rk = NULL; /* freed with tsk */ +}