From fd68fd29330a3ab49f04a3b8a311dc93135ec2d6 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Tue, 27 Apr 2021 04:47:23 -0700 Subject: [PATCH] tests:Use inttypes --- src/systemcmds/tests/test_adc.cpp | 6 +++--- src/systemcmds/tests/test_bson.cpp | 2 +- src/systemcmds/tests/test_file2.c | 19 ++++++++++--------- src/systemcmds/tests/test_jig_voltages.cpp | 6 +++--- src/systemcmds/tests/test_time.c | 2 +- src/systemcmds/tests/test_versioning.cpp | 6 ++++-- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/systemcmds/tests/test_adc.cpp b/src/systemcmds/tests/test_adc.cpp index 1f6489350f..2609492e1b 100644 --- a/src/systemcmds/tests/test_adc.cpp +++ b/src/systemcmds/tests/test_adc.cpp @@ -52,12 +52,12 @@ int test_adc(int argc, char *argv[]) px4_usleep(50000); // sleep 50ms and wait for adc report if (_adc_sub.update(&adc)) { - PX4_INFO_RAW("DeviceID: %d\n", adc.device_id); - PX4_INFO_RAW("Resolution: %d\n", adc.resolution); + PX4_INFO_RAW("DeviceID: %" PRIu32 "\n", adc.device_id); + PX4_INFO_RAW("Resolution: %" PRIu32 "\n", adc.resolution); PX4_INFO_RAW("Voltage Reference: %f\n", adc.v_ref); for (int i = 0; i < PX4_MAX_ADC_CHANNELS; ++i) { - PX4_INFO_RAW("%d: %d ", adc.channel_id[i], adc.raw_data[i]); + PX4_INFO_RAW("%" PRIu16 ": %" PRIi32 " ", adc.channel_id[i], adc.raw_data[i]); } PX4_INFO_RAW("\n"); diff --git a/src/systemcmds/tests/test_bson.cpp b/src/systemcmds/tests/test_bson.cpp index 6e4e0bc4e4..7be42b176d 100644 --- a/src/systemcmds/tests/test_bson.cpp +++ b/src/systemcmds/tests/test_bson.cpp @@ -124,7 +124,7 @@ decode_callback(bson_decoder_t decoder, void *priv, bson_node_t node) } if (node->i != sample_small_int) { - PX4_ERR("FAIL: decoder: int1 value %" PRIu64 ", expected %d", node->i, sample_small_int); + PX4_ERR("FAIL: decoder: int1 value %" PRIu64 ", expected %" PRIi32 "", node->i, sample_small_int); return 1; } diff --git a/src/systemcmds/tests/test_file2.c b/src/systemcmds/tests/test_file2.c index 941cf06cf2..6f270de701 100644 --- a/src/systemcmds/tests/test_file2.c +++ b/src/systemcmds/tests/test_file2.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -70,8 +71,8 @@ static uint8_t get_value(uint32_t ofs) static int test_corruption(const char *filename, uint32_t write_chunk, uint32_t write_size, uint16_t flags) { - printf("Testing on %s with write_chunk=%u write_size=%u\n", - filename, (unsigned)write_chunk, (unsigned)write_size); + printf("Testing on %s with write_chunk=%" PRIu32 " write_size=%" PRIu32 "\n", + filename, write_chunk, write_size); uint32_t ofs = 0; int fd = open(filename, O_CREAT | O_RDWR | O_TRUNC, PX4_O_MODE_666); @@ -93,7 +94,7 @@ static int test_corruption(const char *filename, uint32_t write_chunk, uint32_t } if (write(fd, buffer, sizeof(buffer)) != (int)sizeof(buffer)) { - printf("write failed at offset %u\n", ofs); + printf("write failed at offset %" PRIu32 "\n", ofs); return 1; } @@ -102,7 +103,7 @@ static int test_corruption(const char *filename, uint32_t write_chunk, uint32_t } if (counter % 100 == 0) { - printf("write ofs=%u\r", ofs); + printf("write ofs=%" PRIu32 "\r", ofs); } counter++; @@ -110,7 +111,7 @@ static int test_corruption(const char *filename, uint32_t write_chunk, uint32_t close(fd); - printf("write ofs=%u\n", ofs); + printf("write ofs=%" PRIu32 "\n", ofs); // read and check fd = open(filename, O_RDONLY); @@ -127,20 +128,20 @@ static int test_corruption(const char *filename, uint32_t write_chunk, uint32_t uint8_t buffer[write_chunk]; if (counter % 100 == 0) { - printf("read ofs=%u\r", ofs); + printf("read ofs=%" PRIu32 "\r", ofs); } counter++; if (read(fd, buffer, sizeof(buffer)) != (int)sizeof(buffer)) { - printf("read failed at offset %u\n", ofs); + printf("read failed at offset %" PRIu32 "\n", ofs); close(fd); return 1; } for (uint16_t j = 0; j < write_chunk; j++) { if (buffer[j] != get_value(ofs)) { - printf("corruption at ofs=%u got %u\n", ofs, buffer[j]); + printf("corruption at ofs=%" PRIu32 " got %" PRIu8 "\n", ofs, buffer[j]); close(fd); return 1; } @@ -153,7 +154,7 @@ static int test_corruption(const char *filename, uint32_t write_chunk, uint32_t } } - printf("read ofs=%u\n", ofs); + printf("read ofs=%" PRIu32 "\n", ofs); close(fd); unlink(filename); printf("All OK\n"); diff --git a/src/systemcmds/tests/test_jig_voltages.cpp b/src/systemcmds/tests/test_jig_voltages.cpp index e4462c9483..37dcae3d56 100644 --- a/src/systemcmds/tests/test_jig_voltages.cpp +++ b/src/systemcmds/tests/test_jig_voltages.cpp @@ -52,14 +52,14 @@ int test_jig_voltages(int argc, char *argv[]) px4_usleep(50000); // sleep 50ms and wait for adc report if (_adc_sub.update(&adc)) { - PX4_INFO_RAW("DeviceID: %d\n", adc.device_id); - PX4_INFO_RAW("Resolution: %d\n", adc.resolution); + PX4_INFO_RAW("DeviceID: %" PRIu32 "\n", adc.device_id); + PX4_INFO_RAW("Resolution: %" PRIu32 "\n", adc.resolution); PX4_INFO_RAW("Voltage Reference: %f\n", adc.v_ref); unsigned channels = 0; for (int i = 0; i < PX4_MAX_ADC_CHANNELS; ++i) { - PX4_INFO_RAW("%d: %d ", adc.channel_id[i], adc.raw_data[i]); + PX4_INFO_RAW("%" PRIu16 ": %" PRIi32 " ", adc.channel_id[i], adc.raw_data[i]); if (adc.channel_id[i] != -1) { ++channels; diff --git a/src/systemcmds/tests/test_time.c b/src/systemcmds/tests/test_time.c index 4d86a42526..5e77619fa8 100644 --- a/src/systemcmds/tests/test_time.c +++ b/src/systemcmds/tests/test_time.c @@ -123,7 +123,7 @@ int test_time(int argc, char *argv[]) } } - printf("Maximum jitter %" PRId64 "us\n", maxdelta); + printf("Maximum jitter %dus\n", maxdelta); return 0; } diff --git a/src/systemcmds/tests/test_versioning.cpp b/src/systemcmds/tests/test_versioning.cpp index bc6ed600bd..53f8b80fc7 100644 --- a/src/systemcmds/tests/test_versioning.cpp +++ b/src/systemcmds/tests/test_versioning.cpp @@ -60,13 +60,15 @@ bool VersioningTest::_test_tag_to_version_number(const char *version_tag, uint32 return true; } else { - PX4_ERR("Wrong vendor version: tag: %s, got: 0x%x, expected: 0x%x", version_tag, vendor_version_result, + PX4_ERR("Wrong vendor version: tag: %s, got: 0x%" PRIx32 ", expected: 0x%" PRIx32 "", version_tag, + vendor_version_result, vendor_version_target); return false; } } else { - PX4_ERR("Wrong flight version: tag: %s, got: 0x%x, expected: 0x%x", version_tag, flight_version_result, + PX4_ERR("Wrong flight version: tag: %s, got: 0x%" PRIx32 ", expected: 0x%" PRIx32 "", version_tag, + flight_version_result, flight_version_target); return false; }