test-tool/test_async_read.c: Allocate large arrays dynamically

This patch avoids that Valgrind complains about the memset() call
that was used to initialize the array that it triggers an invalid
write.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
This commit is contained in:
Bart Van Assche
2017-01-23 10:46:14 -08:00
parent 38e6ab7582
commit 9df32565a6
+13 -8
View File
@@ -60,27 +60,29 @@ test_async_read(void)
{ {
int i, ret; int i, ret;
struct tests_async_read_state state = { 0, 0, 0 }; struct tests_async_read_state state = { 0, 0, 0 };
int blocksize = 512; const int blocksize = 512;
int blocks_per_io = 8; const int blocks_per_io = 8;
int num_ios = 1000; const int num_ios = 1000;
/* IOs in flight concurrently, so need a buffer large enough for all */ /* IOs in flight concurrently, so need a buffer large enough for all */
unsigned char buf[blocksize * blocks_per_io * num_ios]; unsigned char *buf = calloc(blocksize * blocks_per_io, num_ios);
CU_ASSERT_NOT_EQUAL(buf, NULL);
if (!buf)
goto out;
CHECK_FOR_DATALOSS; CHECK_FOR_DATALOSS;
CHECK_FOR_SBC; CHECK_FOR_SBC;
if (sd->iscsi_ctx == NULL) { if (sd->iscsi_ctx == NULL) {
CU_PASS("[SKIPPED] Non-iSCSI"); CU_PASS("[SKIPPED] Non-iSCSI");
return; goto out;
} }
if (maximum_transfer_length if (maximum_transfer_length
&& (maximum_transfer_length < (blocks_per_io * num_ios))) { && (maximum_transfer_length < (blocks_per_io * num_ios))) {
CU_PASS("[SKIPPED] device too small for async_read test"); CU_PASS("[SKIPPED] device too small for async_read test");
return; goto out;
} }
memset(buf, 0, blocksize * blocks_per_io * num_ios);
for (i = 0; i < num_ios; i++) { for (i = 0; i < num_ios; i++) {
uint32_t lba = i * blocks_per_io; uint32_t lba = i * blocks_per_io;
struct scsi_task *atask; struct scsi_task *atask;
@@ -116,4 +118,7 @@ test_async_read(void)
ret = iscsi_service(sd->iscsi_ctx, pfd.revents); ret = iscsi_service(sd->iscsi_ctx, pfd.revents);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
} }
out:
free(buf);
} }