test/bdevio: refactor two tests
Refactor blockdev_write_read_offset_plus_nbytes_equals_bdev_size() and blockdev_write_read_offset_plus_nbytes_gt_bdev_size() to use blockdev_write_read() similar to how it's done in other tests. Change-Id: Iba853a0df1facd88ce7c206163386f6c8a9c7c1b Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14714 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
65e08d1265
commit
2e73b5c7fb
@ -831,52 +831,37 @@ blockdev_write_read_invalid_size(void)
|
|||||||
static void
|
static void
|
||||||
blockdev_write_read_offset_plus_nbytes_equals_bdev_size(void)
|
blockdev_write_read_offset_plus_nbytes_equals_bdev_size(void)
|
||||||
{
|
{
|
||||||
struct io_target *target;
|
uint32_t data_length;
|
||||||
struct spdk_bdev *bdev;
|
|
||||||
char *tx_buf = NULL;
|
|
||||||
char *rx_buf = NULL;
|
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
uint32_t block_size;
|
int pattern;
|
||||||
int rc;
|
int expected_rc;
|
||||||
|
struct io_target *target = g_current_io_target;
|
||||||
target = g_current_io_target;
|
struct spdk_bdev *bdev = target->bdev;
|
||||||
bdev = target->bdev;
|
uint32_t block_size = spdk_bdev_get_block_size(bdev);
|
||||||
|
|
||||||
block_size = spdk_bdev_get_block_size(bdev);
|
|
||||||
|
|
||||||
|
data_length = block_size;
|
||||||
|
CU_ASSERT_TRUE(data_length < BUFFER_SIZE);
|
||||||
/* The start offset has been set to a marginal value
|
/* The start offset has been set to a marginal value
|
||||||
* such that offset + nbytes == Total size of
|
* such that offset + nbytes == Total size of
|
||||||
* blockdev. */
|
* blockdev. */
|
||||||
offset = ((spdk_bdev_get_num_blocks(bdev) - 1) * block_size);
|
offset = ((spdk_bdev_get_num_blocks(bdev) - 1) * block_size);
|
||||||
|
pattern = 0xA3;
|
||||||
|
/* Params are valid, hence the expected return value
|
||||||
|
* of write and read for all blockdevs is 0. */
|
||||||
|
expected_rc = 0;
|
||||||
|
|
||||||
initialize_buffer(&tx_buf, 0xA3, block_size);
|
blockdev_write_read(data_length, 0, pattern, offset, expected_rc, 0);
|
||||||
initialize_buffer(&rx_buf, 0, block_size);
|
|
||||||
|
|
||||||
blockdev_write(target, tx_buf, offset, block_size, 0);
|
|
||||||
CU_ASSERT_EQUAL(g_completion_success, true);
|
|
||||||
|
|
||||||
blockdev_read(target, rx_buf, offset, block_size, 0);
|
|
||||||
CU_ASSERT_EQUAL(g_completion_success, true);
|
|
||||||
|
|
||||||
rc = blockdev_write_read_data_match(rx_buf, tx_buf, block_size);
|
|
||||||
/* Assert the write by comparing it with values read
|
|
||||||
* from each blockdev */
|
|
||||||
CU_ASSERT_EQUAL(rc, 0);
|
|
||||||
|
|
||||||
spdk_free(tx_buf);
|
|
||||||
spdk_free(rx_buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
blockdev_write_read_offset_plus_nbytes_gt_bdev_size(void)
|
blockdev_write_read_offset_plus_nbytes_gt_bdev_size(void)
|
||||||
{
|
{
|
||||||
struct io_target *target = g_current_io_target;
|
uint32_t data_length;
|
||||||
struct spdk_bdev *bdev = target->bdev;
|
|
||||||
char *tx_buf = NULL;
|
|
||||||
char *rx_buf = NULL;
|
|
||||||
int data_length;
|
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
int pattern;
|
int pattern;
|
||||||
|
int expected_rc;
|
||||||
|
struct io_target *target = g_current_io_target;
|
||||||
|
struct spdk_bdev *bdev = target->bdev;
|
||||||
uint32_t block_size = spdk_bdev_get_block_size(bdev);
|
uint32_t block_size = spdk_bdev_get_block_size(bdev);
|
||||||
|
|
||||||
/* Tests the overflow condition of the blockdevs. */
|
/* Tests the overflow condition of the blockdevs. */
|
||||||
@ -884,25 +869,15 @@ blockdev_write_read_offset_plus_nbytes_gt_bdev_size(void)
|
|||||||
CU_ASSERT_TRUE(data_length < BUFFER_SIZE);
|
CU_ASSERT_TRUE(data_length < BUFFER_SIZE);
|
||||||
pattern = 0xA3;
|
pattern = 0xA3;
|
||||||
|
|
||||||
target = g_current_io_target;
|
|
||||||
bdev = target->bdev;
|
|
||||||
|
|
||||||
/* The start offset has been set to a valid value
|
/* The start offset has been set to a valid value
|
||||||
* but offset + nbytes is greater than the Total size
|
* but offset + nbytes is greater than the Total size
|
||||||
* of the blockdev. The test should fail. */
|
* of the blockdev. The test should fail. */
|
||||||
offset = (spdk_bdev_get_num_blocks(bdev) - 1) * block_size;
|
offset = (spdk_bdev_get_num_blocks(bdev) - 1) * block_size;
|
||||||
|
/* Params are invalid, hence the expected return value
|
||||||
|
* of write and read for all blockdevs is < 0 */
|
||||||
|
expected_rc = -1;
|
||||||
|
|
||||||
initialize_buffer(&tx_buf, pattern, data_length);
|
blockdev_write_read(data_length, 0, pattern, offset, expected_rc, 0);
|
||||||
initialize_buffer(&rx_buf, 0, data_length);
|
|
||||||
|
|
||||||
blockdev_write(target, tx_buf, offset, data_length, 0);
|
|
||||||
CU_ASSERT_EQUAL(g_completion_success, false);
|
|
||||||
|
|
||||||
blockdev_read(target, rx_buf, offset, data_length, 0);
|
|
||||||
CU_ASSERT_EQUAL(g_completion_success, false);
|
|
||||||
|
|
||||||
spdk_free(tx_buf);
|
|
||||||
spdk_free(rx_buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user