test: Use PRId64 for portability

POSIX defines PRId64/PRIu64/PRIx64 for printing 64-bit values in a
portable way. Replace a few references to %ld to remove the assumption
about the size of a long. Similarly, use %z with size_t arguments.

Where the value being printed is an unsigned 64-bit value, use PRIu64
instead of %ld.

Add a cast when comparing an enum to an integer value.

Add an explicit uint64_t cast to the definition of BLOCK_CNT to prevent
value truncation.

Signed-off-by: Nick Connolly <nick.connolly@mayadata.io>
Change-Id: I093cffe7e79bc04eba012f4ffaf33062a642d062
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5137
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Nick Connolly 2020-11-17 16:22:36 +00:00 committed by Tomasz Zawadzki
parent 3b461269d2
commit 5c5a44f008
8 changed files with 17 additions and 15 deletions

View File

@ -247,7 +247,7 @@ fuzz_parse_args_into_array(const char *file, void **arr, size_t ele_size, const
rc = cb_fn((void *)arr_idx_pointer, obj_start, values_in_obj);
if (rc == false) {
fprintf(stderr, "failed to parse file after %lu elements.\n", arr_elements_used);
fprintf(stderr, "failed to parse file after %zu elements.\n", arr_elements_used);
goto fail;
}

View File

@ -233,7 +233,7 @@ cleanup(void)
struct fuzz_iscsi_dev_ctx *dev_ctx, *tmp;
TAILQ_FOREACH_SAFE(dev_ctx, &g_dev_list, link, tmp) {
printf("device %p stats: Sent %lu valid opcode PDUs, %lu invalid opcode PDUs.\n",
printf("device %p stats: Sent %" PRIu64 " valid opcode PDUs, %" PRIu64 " invalid opcode PDUs.\n",
dev_ctx, dev_ctx->num_valid_pdus,
dev_ctx->num_sent_pdus - dev_ctx->num_valid_pdus);
free(dev_ctx);

View File

@ -343,7 +343,7 @@ nvme_fuzz_cpl_cb(void *cb_arg, const struct spdk_nvme_cpl *cpl)
qp->completed_cmd_counter++;
if (spdk_unlikely(cpl->status.sc == SPDK_NVME_SC_SUCCESS)) {
fprintf(stderr, "The following %s command (command num %lu) completed successfully\n",
fprintf(stderr, "The following %s command (command num %" PRIu64 ") completed successfully\n",
qp->is_admin ? "Admin" : "I/O", qp->completed_cmd_counter);
qp->successful_completed_cmd_counter++;
json_dump_nvme_cmd(&ctx->cmd);
@ -354,7 +354,7 @@ nvme_fuzz_cpl_cb(void *cb_arg, const struct spdk_nvme_cpl *cpl)
__sync_bool_compare_and_swap(&g_successful_io_opcodes[ctx->cmd.opc], false, true);
}
} else if (g_verbose_mode == true) {
fprintf(stderr, "The following %s command (command num %lu) failed as expected.\n",
fprintf(stderr, "The following %s command (command num %" PRIu64 ") failed as expected.\n",
qp->is_admin ? "Admin" : "I/O", qp->completed_cmd_counter);
json_dump_nvme_cmd(&ctx->cmd);
}
@ -512,10 +512,12 @@ free_namespaces(void)
struct nvme_fuzz_ns *ns, *tmp;
TAILQ_FOREACH_SAFE(ns, &g_ns_list, tailq, tmp) {
printf("NS: %p I/O qp, Total commands completed: %lu, total successful commands: %lu, random_seed: %u\n",
printf("NS: %p I/O qp, Total commands completed: %" PRIu64 ", total successful commands: %" PRIu64
", random_seed: %u\n",
ns->ns,
ns->io_qp.completed_cmd_counter, ns->io_qp.successful_completed_cmd_counter, ns->io_qp.random_seed);
printf("NS: %p admin qp, Total commands completed: %lu, total successful commands: %lu, random_seed: %u\n",
printf("NS: %p admin qp, Total commands completed: %" PRIu64 ", total successful commands: %" PRIu64
", random_seed: %u\n",
ns->ns,
ns->a_qp.completed_cmd_counter, ns->a_qp.successful_completed_cmd_counter, ns->a_qp.random_seed);

View File

@ -504,7 +504,7 @@ bdevperf_complete(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
if (!job->reset && !job->continue_on_failure) {
bdevperf_job_drain(job);
g_run_rc = -1;
printf("task offset: %lu on job bdev=%s fails\n",
printf("task offset: %" PRIu64 " on job bdev=%s fails\n",
task->offset_blocks, job->name);
}
} else if (job->verify || job->reset) {
@ -516,7 +516,7 @@ bdevperf_complete(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
task->md_buf, spdk_bdev_io_get_md_buf(bdev_io),
spdk_bdev_get_md_size(job->bdev),
job->io_size_blocks, md_check)) {
printf("Buffer mismatch! Target: %s Disk Offset: %lu\n", job->name, task->offset_blocks);
printf("Buffer mismatch! Target: %s Disk Offset: %" PRIu64 "\n", job->name, task->offset_blocks);
printf(" First dword expected 0x%x got 0x%x\n", *(int *)task->buf, *(int *)iovs[0].iov_base);
bdevperf_job_drain(job);
g_run_rc = -1;

View File

@ -352,11 +352,11 @@ print_stats(void)
}
printf("========================================================\n");
printf("%16lu IO completed successfully\n", total_completed_io);
printf("%16lu IO completed with error\n", total_completed_err_io);
printf("%16" PRIu64 " IO completed successfully\n", total_completed_io);
printf("%16" PRIu64 " IO completed with error\n", total_completed_err_io);
printf("--------------------------------------------------------\n");
printf("%16lu IO completed total\n", total_completed_io + total_completed_err_io);
printf("%16lu IO submitted\n", total_submitted_io);
printf("%16" PRIu64 " IO completed total\n", total_completed_io + total_completed_err_io);
printf("%16" PRIu64 " IO submitted\n", total_submitted_io);
if (total_submitted_io != (total_completed_io + total_completed_err_io)) {
fprintf(stderr, "Some IO are missing......\n");

View File

@ -882,7 +882,7 @@ verify_raid_bdev(struct rpc_bdev_raid_create *r, bool presence, uint32_t raid_st
CU_ASSERT(pbdev->strip_size_shift == spdk_u32log2(((r->strip_size_kb * 1024) /
g_block_len)));
CU_ASSERT(pbdev->blocklen_shift == spdk_u32log2(g_block_len));
CU_ASSERT(pbdev->state == raid_state);
CU_ASSERT((uint32_t)pbdev->state == raid_state);
CU_ASSERT(pbdev->num_base_bdevs == r->base_bdevs.num_base_bdevs);
CU_ASSERT(pbdev->num_base_bdevs_discovered == r->base_bdevs.num_base_bdevs);
CU_ASSERT(pbdev->level == r->level);

View File

@ -40,7 +40,7 @@
#include "bdev/zone_block/vbdev_zone_block.c"
#include "bdev/zone_block/vbdev_zone_block_rpc.c"
#define BLOCK_CNT (1024ul * 1024ul * 1024ul * 1024ul)
#define BLOCK_CNT ((uint64_t)1024ul * 1024ul * 1024ul * 1024ul)
#define BLOCK_SIZE 4096
/* Globals */

View File

@ -1573,7 +1573,7 @@ check_scsi_task(struct spdk_iscsi_pdu *pdu, enum spdk_scsi_data_dir dir)
task = pdu->task;
CU_ASSERT(task != NULL);
CU_ASSERT(task->pdu == pdu);
CU_ASSERT(task->scsi.dxfer_dir == dir);
CU_ASSERT(task->scsi.dxfer_dir == (uint32_t)dir);
iscsi_task_put(task);
pdu->task = NULL;