From 96e2f8bcd077ecc7706c0114903ee50b2f2bc4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Tue, 6 May 2025 09:47:34 +0200 Subject: [PATCH] tests: lib: Fix zassert string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix wrong parameter used in zassert macros. Signed-off-by: Krzysztof Chruściński --- tests/kernel/interrupt/src/sw_isr_table.c | 6 +-- tests/lib/c_lib/common/src/main.c | 10 ++--- tests/lib/cobs/src/main.c | 2 +- tests/lib/devicetree/api/src/main.c | 8 ++-- tests/lib/devicetree/devices/src/main.c | 53 ++++++++++------------- tests/lib/heap/src/main.c | 10 ++--- tests/lib/json/src/main.c | 6 +-- tests/lib/lockfree/src/test_mpsc.c | 2 +- tests/lib/mem_alloc/src/main.c | 2 +- tests/lib/mem_blocks/src/main.c | 12 ++--- tests/lib/mpsc_pbuf/src/concurrent.c | 2 +- tests/lib/mpsc_pbuf/src/main.c | 26 +++++------ tests/lib/multi_heap/src/test_mheap_api.c | 6 +-- tests/lib/ringbuffer/src/main.c | 24 +++++----- tests/lib/spsc_pbuf/src/main.c | 6 +-- tests/lib/time/src/main.c | 2 +- tests/misc/iterable_sections/src/main.c | 8 ++-- 17 files changed, 85 insertions(+), 100 deletions(-) diff --git a/tests/kernel/interrupt/src/sw_isr_table.c b/tests/kernel/interrupt/src/sw_isr_table.c index f9ad6cfe847..312820bb40e 100644 --- a/tests/kernel/interrupt/src/sw_isr_table.c +++ b/tests/kernel/interrupt/src/sw_isr_table.c @@ -41,7 +41,7 @@ ZTEST(interrupt_feature, test_sw_isr_irq_parent_table_idx) l2_isr_offset + local_irq + (i * CONFIG_MAX_IRQ_PER_AGGREGATOR); zassert_equal(isr_offset, test_isr_offset, - "%d: expected offset: %d, got: %d", i, + "%zu: expected offset: %d, got: %d", i, isr_offset, test_isr_offset); } } @@ -78,12 +78,12 @@ ZTEST(interrupt_feature, test_sw_isr_irq_parent_table_dev) local_irq < CONFIG_MAX_IRQ_PER_AGGREGATOR; local_irq++) { test_irq = irq_to_level_2(local_irq) | parent_irq[i]; test_dev = z_get_sw_isr_device_from_irq(test_irq); - zassert_equal_ptr(parent_dev[i], test_dev, "%d: expected dev: %p, got: %p", + zassert_equal_ptr(parent_dev[i], test_dev, "%zu: expected dev: %p, got: %p", i, parent_dev[i], test_dev); } test_irq = z_get_sw_isr_irq_from_device(parent_dev[i]); - zassert_equal(parent_irq[i], test_irq, "%d: expected offset: %d, got: %d", i, + zassert_equal(parent_irq[i], test_irq, "%zu: expected offset: %d, got: %d", i, parent_irq[i], test_irq); } } diff --git a/tests/lib/c_lib/common/src/main.c b/tests/lib/c_lib/common/src/main.c index f5379d54584..9cf84e54bbc 100644 --- a/tests/lib/c_lib/common/src/main.c +++ b/tests/lib/c_lib/common/src/main.c @@ -256,7 +256,7 @@ ZTEST(libc_common, test_strncmp) /* test compare the same strings */ buffer[BUFSIZE - 1] = '\0'; zassert_true((strncmp(buffer, buffer, BUFSIZE) == 0), - "strncmp 10 with \0"); + "strncmp 10 with \\0"); } @@ -538,7 +538,7 @@ ZTEST(libc_common, test_memchr) /* verify the character inside the count scope */ zassert_not_null(memchr(str, 'e', strlen(str)), "memchr serach e"); - zassert_not_null(memchr(str, '\0', strlen(str)+1), "memchr serach \0"); + zassert_not_null(memchr(str, '\0', strlen(str)+1), "memchr serach \\0"); /* verify when the count parm is zero */ zassert_is_null(memchr(str, 't', 0), "memchr count 0 error"); @@ -658,7 +658,7 @@ ZTEST(libc_common, test_str_operate) zassert_is_null(strstr(str1, "ayz"), "strstr aabbccd with ayz failed"); zassert_not_null(strstr(str1, str2), "strstr aabbccd with b succeed"); zassert_not_null(strstr(str1, "bb"), "strstr aabbccd with bb succeed"); - zassert_not_null(strstr(str1, ""), "strstr aabbccd with \0 failed"); + zassert_not_null(strstr(str1, ""), "strstr aabbccd with \\0 failed"); } /** @@ -909,7 +909,7 @@ void test_strtoll(void) ret = strtoll(border4, NULL, 10); zassert_equal(ret, LLONG_MAX, "strtoll base = 10 failed"); ret = strtoull(border5, NULL, 16); - zassert_equal(ret, 1, "strtoull base = 16 failed, %s != 0x%x", border5, ret); + zassert_equal(ret, 1, "strtoull base = 16 failed, %s != 0x%llx", border5, ret); ret = strtoull(border6, NULL, 10); zassert_equal(errno, ERANGE, "strtoull base = 10 failed, %s != %lld", border6, ret); ret = strtoull(border7, NULL, 10); @@ -987,7 +987,7 @@ void test_strtoull(void) ret = strtoull(border3, NULL, 10); zassert_equal(ret, ULLONG_MAX, "strtoull base = 10 failed"); ret = strtoull(border4, NULL, 16); - zassert_equal(ret, 1, "strtoull base = 16 failed, %s != 0x%x", border4, ret); + zassert_equal(ret, 1, "strtoull base = 16 failed, %s != 0x%llx", border4, ret); ret = strtoull(border5, NULL, 10); zassert_equal(errno, ERANGE, "strtoull base = 10 failed, %s != %lld", border5, ret); ret = strtoull(border6, NULL, 10); diff --git a/tests/lib/cobs/src/main.c b/tests/lib/cobs/src/main.c index eda89c0454a..e9bcc1c9331 100644 --- a/tests/lib/cobs/src/main.c +++ b/tests/lib/cobs/src/main.c @@ -22,7 +22,7 @@ static void *cobs_test_setup(void) { struct cobs_tests_fixture *fixture = malloc(sizeof(struct cobs_tests_fixture)); - zassume_not_null(fixture, NULL); + zassume_not_null(fixture); fixture->test_data = net_buf_alloc(&test_pool, K_NO_WAIT); fixture->encoded = net_buf_alloc(&test_pool, K_NO_WAIT); diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index 339d6dfd4ef..60a08d298bc 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -544,10 +544,8 @@ ZTEST(devicetree_api, test_bus) zassert_equal(DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(vnd_i2c_device, i2c), 1); zassert_equal(DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(vnd_i2c_device, spi), 0); - zassert_equal(DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(vnd_gpio_expander, i2c), 1, - NULL); - zassert_equal(DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(vnd_gpio_expander, spi), 1, - NULL); + zassert_equal(DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(vnd_gpio_expander, i2c), 1); + zassert_equal(DT_HAS_COMPAT_ON_BUS_STATUS_OKAY(vnd_gpio_expander, spi), 1); } #undef DT_DRV_COMPAT @@ -768,7 +766,7 @@ ZTEST(devicetree_api, test_irq) /* DT_IRQ_HAS_CELL_AT_IDX */ zassert_true(DT_IRQ_HAS_CELL_AT_IDX(TEST_IRQ, 0, irq), ""); zassert_true(DT_IRQ_HAS_CELL_AT_IDX(TEST_IRQ, 0, priority), ""); - zassert_false(DT_IRQ_HAS_CELL_AT_IDX(TEST_IRQ, 0, foo), 0, ""); + zassert_false(DT_IRQ_HAS_CELL_AT_IDX(TEST_IRQ, 0, foo), ""); zassert_true(DT_IRQ_HAS_CELL_AT_IDX(TEST_IRQ, 2, irq), ""); zassert_true(DT_IRQ_HAS_CELL_AT_IDX(TEST_IRQ, 2, priority), ""); zassert_false(DT_IRQ_HAS_CELL_AT_IDX(TEST_IRQ, 2, foo), ""); diff --git a/tests/lib/devicetree/devices/src/main.c b/tests/lib/devicetree/devices/src/main.c index 49a1d08cffe..175a3670d82 100644 --- a/tests/lib/devicetree/devices/src/main.c +++ b/tests/lib/devicetree/devices/src/main.c @@ -71,29 +71,29 @@ ZTEST(devicetree_devices, test_init_get) { /* Check device pointers */ zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO)->dev, - DEVICE_DT_GET(TEST_GPIO), NULL); + DEVICE_DT_GET(TEST_GPIO)); zassert_equal(DEVICE_INIT_DT_GET(TEST_I2C)->dev, - DEVICE_DT_GET(TEST_I2C), NULL); + DEVICE_DT_GET(TEST_I2C)); zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVA)->dev, - DEVICE_DT_GET(TEST_DEVA), NULL); + DEVICE_DT_GET(TEST_DEVA)); zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVB)->dev, - DEVICE_DT_GET(TEST_DEVB), NULL); + DEVICE_DT_GET(TEST_DEVB)); zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIOX)->dev, - DEVICE_DT_GET(TEST_GPIOX), NULL); + DEVICE_DT_GET(TEST_GPIOX)); zassert_equal(DEVICE_INIT_DT_GET(TEST_DEVC)->dev, - DEVICE_DT_GET(TEST_DEVC), NULL); + DEVICE_DT_GET(TEST_DEVC)); zassert_equal(DEVICE_INIT_DT_GET(TEST_PARTITION_OUTER)->dev, - DEVICE_DT_GET(TEST_PARTITION_OUTER), NULL); + DEVICE_DT_GET(TEST_PARTITION_OUTER)); zassert_equal(DEVICE_INIT_DT_GET(TEST_PARTITION0)->dev, - DEVICE_DT_GET(TEST_PARTITION0), NULL); + DEVICE_DT_GET(TEST_PARTITION0)); zassert_equal(DEVICE_INIT_DT_GET(TEST_PARTITION1)->dev, - DEVICE_DT_GET(TEST_PARTITION1), NULL); + DEVICE_DT_GET(TEST_PARTITION1)); zassert_equal(DEVICE_INIT_DT_GET(TEST_GPIO_INJECTED)->dev, - DEVICE_DT_GET(TEST_GPIO_INJECTED), NULL); + DEVICE_DT_GET(TEST_GPIO_INJECTED)); zassert_equal(DEVICE_INIT_GET(manual_dev)->dev, - DEVICE_GET(manual_dev), NULL); + DEVICE_GET(manual_dev)); zassert_equal(DEVICE_INIT_DT_GET(TEST_NOLABEL)->dev, - DEVICE_DT_GET(TEST_NOLABEL), NULL); + DEVICE_DT_GET(TEST_NOLABEL)); /* Check init functions */ zassert_equal(DEVICE_DT_GET(TEST_GPIO)->ops.init, dev_init); @@ -177,24 +177,21 @@ ZTEST(devicetree_devices, test_requires) zassert_equal(dev, DEVICE_DT_GET(TEST_GPIO)); hdls = device_required_handles_get(dev, &nhdls); zassert_equal(nhdls, 0); - zassert_equal(0, device_required_foreach(dev, device_visitor, &ctx), - NULL); + zassert_equal(0, device_required_foreach(dev, device_visitor, &ctx)); /* TEST_GPIO_INJECTED: no req */ dev = device_get_binding(DEVICE_DT_NAME(TEST_GPIO_INJECTED)); zassert_equal(dev, DEVICE_DT_GET(TEST_GPIO_INJECTED)); hdls = device_required_handles_get(dev, &nhdls); zassert_equal(nhdls, 0); - zassert_equal(0, device_required_foreach(dev, device_visitor, &ctx), - NULL); + zassert_equal(0, device_required_foreach(dev, device_visitor, &ctx)); /* TEST_I2C: no req */ dev = device_get_binding(DEVICE_DT_NAME(TEST_I2C)); zassert_equal(dev, DEVICE_DT_GET(TEST_I2C)); hdls = device_required_handles_get(dev, &nhdls); zassert_equal(nhdls, 0); - zassert_equal(0, device_required_foreach(dev, device_visitor, &ctx), - NULL); + zassert_equal(0, device_required_foreach(dev, device_visitor, &ctx)); /* TEST_DEVA: TEST_I2C GPIO */ dev = device_get_binding(DEVICE_DT_NAME(TEST_DEVA)); @@ -208,21 +205,17 @@ ZTEST(devicetree_devices, test_requires) ctx = (struct visitor_context){ .ndevs = 1, }; - zassert_equal(-ENOSPC, device_required_foreach(dev, device_visitor, &ctx), - NULL); + zassert_equal(-ENOSPC, device_required_foreach(dev, device_visitor, &ctx)); /* Visit succeeds if enough space. */ ctx = (struct visitor_context){ .ndevs = 2, }; - zassert_equal(2, device_required_foreach(dev, device_visitor, &ctx), - NULL); + zassert_equal(2, device_required_foreach(dev, device_visitor, &ctx)); zassert_true((ctx.rdevs[0] == device_from_handle(DEV_HDL(TEST_I2C))) - || (ctx.rdevs[1] == device_from_handle(DEV_HDL(TEST_I2C))), - NULL); + || (ctx.rdevs[1] == device_from_handle(DEV_HDL(TEST_I2C)))); zassert_true((ctx.rdevs[0] == device_from_handle(DEV_HDL(TEST_GPIO))) - || (ctx.rdevs[1] == device_from_handle(DEV_HDL(TEST_GPIO))), - NULL); + || (ctx.rdevs[1] == device_from_handle(DEV_HDL(TEST_GPIO)))); /* TEST_GPIOX: TEST_I2C */ dev = device_get_binding(DEVICE_DT_NAME(TEST_GPIOX)); @@ -233,10 +226,8 @@ ZTEST(devicetree_devices, test_requires) ctx = (struct visitor_context){ .ndevs = 3, }; - zassert_equal(1, device_required_foreach(dev, device_visitor, &ctx), - NULL); - zassert_true(ctx.rdevs[0] == device_from_handle(DEV_HDL(TEST_I2C)), - NULL); + zassert_equal(1, device_required_foreach(dev, device_visitor, &ctx)); + zassert_true(ctx.rdevs[0] == device_from_handle(DEV_HDL(TEST_I2C))); /* TEST_DEVB: TEST_I2C TEST_GPIOX */ dev = device_get_binding(DEVICE_DT_NAME(TEST_DEVB)); @@ -281,7 +272,7 @@ ZTEST(devicetree_devices, test_get_or_null) const struct device *dev; dev = DEVICE_DT_GET_OR_NULL(TEST_DEVA); - zassert_not_equal(dev, NULL, NULL); + zassert_not_equal(dev, NULL); dev = DEVICE_DT_GET_OR_NULL(non_existing_node); zassert_is_null(dev); diff --git a/tests/lib/heap/src/main.c b/tests/lib/heap/src/main.c index a87cc91c480..3f82cfd744a 100644 --- a/tests/lib/heap/src/main.c +++ b/tests/lib/heap/src/main.c @@ -130,7 +130,7 @@ void *testalloc(void *arg, size_t bytes) size_t expect = ROUND_UP(bytes + hdr, 8) - hdr; zassert_equal(blksz, expect, - "wrong size block returned bytes = %ld ret = %ld", + "wrong size block returned bytes = %zu ret = %zu", bytes, blksz); } @@ -441,7 +441,7 @@ ZTEST(lib_heap, test_heap_listeners) zassert_equal(listener_heap_id, HEAP_ID_FROM_POINTER(&listener_heap), - "Heap ID mismatched: 0x%lx != %p", listener_heap_id, + "Heap ID mismatched: %p != %p", (void *)listener_heap_id, &listener_heap); zassert_equal(listener_mem, mem, "Heap allocated pointer mismatched: %p != %p", @@ -450,7 +450,7 @@ ZTEST(lib_heap, test_heap_listeners) sys_heap_free(&listener_heap, mem); zassert_equal(listener_heap_id, HEAP_ID_FROM_POINTER(&listener_heap), - "Heap ID mismatched: 0x%lx != %p", listener_heap_id, + "Heap ID mismatched: %p != %p", (void *)listener_heap_id, &listener_heap); zassert_equal(listener_mem, mem, "Heap allocated pointer mismatched: %p != %p", @@ -461,7 +461,7 @@ ZTEST(lib_heap, test_heap_listeners) zassert_equal(listener_heap_id, HEAP_ID_FROM_POINTER(&listener_heap), - "Heap ID mismatched: 0x%lx != %p", listener_heap_id, + "Heap ID mismatched: %p != %p", (void *)listener_heap_id, &listener_heap); zassert_equal(listener_mem, mem, "Heap allocated pointer mismatched: %p != %p", @@ -470,7 +470,7 @@ ZTEST(lib_heap, test_heap_listeners) sys_heap_free(&listener_heap, mem); zassert_equal(listener_heap_id, HEAP_ID_FROM_POINTER(&listener_heap), - "Heap ID mismatched: 0x%lx != %p", listener_heap_id, + "Heap ID mismatched: %p != %p", (void *)listener_heap_id, &listener_heap); zassert_equal(listener_mem, mem, "Heap allocated pointer mismatched: %p != %p", diff --git a/tests/lib/json/src/main.c b/tests/lib/json/src/main.c index db351316b87..8d69b183709 100644 --- a/tests/lib/json/src/main.c +++ b/tests/lib/json/src/main.c @@ -2039,7 +2039,7 @@ ZTEST(lib_json_test, test_large_descriptor) int64_t ret = json_obj_parse(encoded, sizeof(encoded) - 1, large_descr, ARRAY_SIZE(large_descr), &ls); - zassert_false(ret < 0, "json_obj_parse returned error %d", ret); + zassert_false(ret < 0, "json_obj_parse returned error %lld", ret); zassert_false(ret & ((int64_t)1 << 2), "Field int2 erroneously decoded"); zassert_false(ret & ((int64_t)1 << 35), "Field int35 erroneously decoded"); zassert_true(ret & ((int64_t)1 << 1), "Field int1 not decoded"); @@ -2084,7 +2084,7 @@ ZTEST(lib_json_test, test_json_array_alignment) int64_t ret = json_obj_parse(encoded, sizeof(encoded) - 1, outer_descr, ARRAY_SIZE(outer_descr), &o); - zassert_false(ret < 0, "json_obj_parse returned error %d", ret); + zassert_false(ret < 0, "json_obj_parse returned error %lld", ret); zassert_equal(o.num_elements, 2, "Number of elements not decoded correctly"); zassert_equal(o.array[0].int1, 1, "Element 0 int1 not decoded correctly"); @@ -2107,7 +2107,7 @@ ZTEST(lib_json_test, test_json_array_alignment_bool) int64_t ret = json_obj_parse(encoded, sizeof(encoded) - 1, alignment_bool_descr, ARRAY_SIZE(alignment_bool_descr), &o); - zassert_false(ret < 0, "json_obj_parse returned error %d", ret); + zassert_false(ret < 0, "json_obj_parse returned error %lld", ret); zassert_equal(o.num_elements, 2, "Number of elements not decoded correctly"); zassert_equal(o.array[0].bool1, true, "Element 0 bool1 not decoded correctly"); diff --git a/tests/lib/lockfree/src/test_mpsc.c b/tests/lib/lockfree/src/test_mpsc.c index 91381d58d2c..2085d26b32d 100644 --- a/tests/lib/lockfree/src/test_mpsc.c +++ b/tests/lib/lockfree/src/test_mpsc.c @@ -48,7 +48,7 @@ ZTEST(mpsc, test_push_pop) zassert_equal(head, &push_pop_nodes[0], "Queue head should point at push_pop_node"); next = mpsc_ptr_get(push_pop_nodes[0].next); - zassert_is_null(next, NULL, "push_pop_node next should point at null"); + zassert_is_null(next, "push_pop_node next should point at null"); next = mpsc_ptr_get(push_pop_q.stub.next); zassert_equal(next, &push_pop_nodes[0], "Queue stub should point at push_pop_node"); tail = push_pop_q.tail; diff --git a/tests/lib/mem_alloc/src/main.c b/tests/lib/mem_alloc/src/main.c index d9ccd151a93..5f97e00bc4d 100644 --- a/tests/lib/mem_alloc/src/main.c +++ b/tests/lib/mem_alloc/src/main.c @@ -292,7 +292,7 @@ ZTEST(c_lib_dynamic_memalloc, test_reallocarray) cptr = reallocarray(ptr, TOO_BIG, sizeof(int)); zassert_is_null((ptr), "reallocarray failed, errno: %d", errno); - zassert_is_null((cptr), "reallocarray failed, errno: %d"); + zassert_is_null((cptr), "reallocarray failed, errno: %d", errno); free(cptr); ptr = malloc(orig_size); diff --git a/tests/lib/mem_blocks/src/main.c b/tests/lib/mem_blocks/src/main.c index 52232b007ef..6a9ad3dcc58 100644 --- a/tests/lib/mem_blocks/src/main.c +++ b/tests/lib/mem_blocks/src/main.c @@ -151,8 +151,8 @@ static void alloc_free(sys_mem_blocks_t *mem_block, #ifdef CONFIG_SYS_MEM_BLOCKS_LISTENER zassert_equal(listener_heap_id[i], HEAP_ID_FROM_POINTER(mem_block), - "Heap ID mismatched: 0x%lx != %p", - listener_heap_id[i], mem_block); + "Heap ID mismatched: %p != %p", + (void *)listener_heap_id[i], mem_block); zassert_equal(listener_mem[i], blocks[i][0], "Heap allocated pointer mismatched: %p != %p", listener_mem[i], blocks[i][0]); @@ -160,7 +160,7 @@ static void alloc_free(sys_mem_blocks_t *mem_block, BIT(mem_block->info.blk_sz_shift), "Heap allocated sized: %u != %u", listener_size[i], - BIT(mem_block->info.blk_sz_shift)); + (uint32_t)BIT(mem_block->info.blk_sz_shift)); #endif } @@ -188,8 +188,8 @@ static void alloc_free(sys_mem_blocks_t *mem_block, #ifdef CONFIG_SYS_MEM_BLOCKS_LISTENER zassert_equal(listener_heap_id[i], HEAP_ID_FROM_POINTER(mem_block), - "Heap ID mismatched: 0x%lx != %p", - listener_heap_id[i], mem_block); + "Heap ID mismatched: 0x%p != %p", + (void *)listener_heap_id[i], mem_block); zassert_equal(listener_mem[i], blocks[i][0], "Heap allocated pointer mismatched: %p != %p", listener_mem[i], blocks[i][0]); @@ -197,7 +197,7 @@ static void alloc_free(sys_mem_blocks_t *mem_block, BIT(mem_block->info.blk_sz_shift), "Heap allocated sized: %u != %u", listener_size[i], - BIT(mem_block->info.blk_sz_shift)); + (uint32_t)BIT(mem_block->info.blk_sz_shift)); #endif } } diff --git a/tests/lib/mpsc_pbuf/src/concurrent.c b/tests/lib/mpsc_pbuf/src/concurrent.c index 313278d1f61..f677d6e051c 100644 --- a/tests/lib/mpsc_pbuf/src/concurrent.c +++ b/tests/lib/mpsc_pbuf/src/concurrent.c @@ -167,7 +167,7 @@ static bool produce(void *user_data, uint32_t cnt, bool last, int prio) { struct mpsc_pbuf_buffer *buffer = user_data; - zassert_true(prio < 4, NULL); + zassert_true(prio < 4); uint32_t wlen = sys_rand32_get() % (buffer->size / 4) + 1; diff --git a/tests/lib/mpsc_pbuf/src/main.c b/tests/lib/mpsc_pbuf/src/main.c index 923050b1b6d..98ad078a429 100644 --- a/tests/lib/mpsc_pbuf/src/main.c +++ b/tests/lib/mpsc_pbuf/src/main.c @@ -66,7 +66,7 @@ static void drop(const struct mpsc_pbuf_buffer *buffer, const union mpsc_pbuf_ge drop_cnt, packet->hdr.len, exp_dropped_len[drop_cnt]); zassert_equal(packet->hdr.data, exp_dropped_data[drop_cnt], "(%d) Got:%08x, Expected: %08x", - drop_cnt, packet->hdr.data, exp_dropped_data[drop_cnt]); + drop_cnt, packet->hdr.data, (uint32_t)exp_dropped_data[drop_cnt]); for (int i = 0; i < exp_dropped_len[drop_cnt] - 1; i++) { int err = memcmp(packet->data, &exp_dropped_data[drop_cnt], sizeof(uint32_t)); @@ -722,7 +722,7 @@ void overwrite(bool pow2) init(&buffer, 32 - !pow2, true); uint32_t packet_cnt = saturate_buffer_uneven(&buffer, fill_len); - zassert_equal(drop_cnt, exp_drop_cnt, NULL); + zassert_equal(drop_cnt, exp_drop_cnt); exp_dropped_data[0] = 0; exp_dropped_len[0] = fill_len; @@ -898,8 +898,8 @@ static uintptr_t current_rd_idx; static void validate_packet(struct test_data_var *packet) { zassert_equal((uintptr_t)packet->hdr.data, current_rd_idx, - "Got %d, expected: %d", - (uintptr_t)packet->hdr.data, current_rd_idx); + "Got %x, expected: %x", + (uint32_t)packet->hdr.data, (uint32_t)current_rd_idx); current_rd_idx++; } @@ -1083,9 +1083,9 @@ static void check_packet(struct mpsc_pbuf_buffer *buffer, char exp_c) const union mpsc_pbuf_generic *claimed; claimed = mpsc_pbuf_claim(buffer); - zassert_true(claimed, NULL); + zassert_true(claimed); claimed_item.item = *claimed; - zassert_equal(claimed_item.data.data, exp_c, NULL); + zassert_equal(claimed_item.data.data, exp_c); mpsc_pbuf_free(buffer, claimed); } @@ -1129,13 +1129,13 @@ ZTEST(log_buffer, test_put_while_claim) item.data.data = 'e'; mpsc_pbuf_put_word(&buffer, item.item); - zassert_equal(drop_cnt, exp_drop_cnt, NULL); + zassert_equal(drop_cnt, exp_drop_cnt); /* Expect buffer = {e, b, c, d} */ claimed = mpsc_pbuf_claim(&buffer); - zassert_true(claimed, NULL); + zassert_true(claimed); claimed_item.item = *claimed; - zassert_equal(claimed_item.data.data, (uint32_t)'b', NULL); + zassert_equal(claimed_item.data.data, (uint32_t)'b'); /* Expect buffer = {e, B, c, d}. Adding new will drop 'c'. */ exp_dropped_data[exp_drop_cnt] = (int)'c'; @@ -1144,7 +1144,7 @@ ZTEST(log_buffer, test_put_while_claim) item.data.data = 'f'; mpsc_pbuf_put_word(&buffer, item.item); - zassert_equal(drop_cnt, exp_drop_cnt, NULL); + zassert_equal(drop_cnt, exp_drop_cnt); /* Expect buffer = {e, B, f, d}, Adding new will drop 'd'. */ exp_dropped_data[exp_drop_cnt] = (int)'d'; @@ -1152,7 +1152,7 @@ ZTEST(log_buffer, test_put_while_claim) exp_drop_cnt++; item.data.data = 'g'; mpsc_pbuf_put_word(&buffer, item.item); - zassert_equal(drop_cnt, exp_drop_cnt, NULL); + zassert_equal(drop_cnt, exp_drop_cnt); /* Expect buffer = {e, B, f, g} */ mpsc_pbuf_free(&buffer, claimed); @@ -1168,7 +1168,7 @@ ZTEST(log_buffer, test_put_while_claim) /* Expect buffer = {-, -, -, -} */ claimed = mpsc_pbuf_claim(&buffer); - zassert_equal(claimed, NULL, NULL); + zassert_equal(claimed, NULL); } static void check_usage(struct mpsc_pbuf_buffer *buffer, @@ -1180,7 +1180,7 @@ static void check_usage(struct mpsc_pbuf_buffer *buffer, mpsc_pbuf_get_utilization(buffer, &size, &usage); zassert_equal(size / sizeof(int), buffer->size - 1, "%d: got:%d, exp:%d", - line, size / sizeof(int), buffer->size - 1); + line, (uint32_t)(size / sizeof(int)), buffer->size - 1); zassert_equal(usage, now, "%d: got:%d, exp:%d", line, usage, now); err = mpsc_pbuf_get_max_utilization(buffer, &usage); diff --git a/tests/lib/multi_heap/src/test_mheap_api.c b/tests/lib/multi_heap/src/test_mheap_api.c index dff17cea2db..849ea5469a8 100644 --- a/tests/lib/multi_heap/src/test_mheap_api.c +++ b/tests/lib/multi_heap/src/test_mheap_api.c @@ -54,7 +54,7 @@ static void malloc_free_handler(void *p1, void *p2, void *p3) block_fail = k_malloc(BLK_SIZE_MIN); /** TESTPOINT: Return NULL if fail.*/ - zassert_is_null(block_fail, NULL); + zassert_is_null(block_fail); for (int i = 0; i < nb; i++) { /** @@ -69,7 +69,7 @@ static void malloc_free_handler(void *p1, void *p2, void *p3) /** TESTPOINT: Return NULL if fail.*/ block_fail = k_malloc(OVERFLOW_SIZE); - zassert_is_null(block_fail, NULL); + zassert_is_null(block_fail); } static void tIsr_malloc_and_free(void *data) @@ -278,7 +278,7 @@ ZTEST(mheap_api, test_k_aligned_alloc) zassert_not_equal(NULL, r, "aligned alloc of 1 byte failed"); /* r is suitably aligned */ zassert_equal(0, (uintptr_t)r % sizeof(void *), - "%p not %u-byte-aligned", + "%p not %zu-byte-aligned", r, sizeof(void *)); k_free(r); diff --git a/tests/lib/ringbuffer/src/main.c b/tests/lib/ringbuffer/src/main.c index cd68ede1900..bd390660fb7 100644 --- a/tests/lib/ringbuffer/src/main.c +++ b/tests/lib/ringbuffer/src/main.c @@ -233,8 +233,7 @@ ZTEST(ringbuffer_api, test_ringbuffer_declare_pow2) ZTEST(ringbuffer_api, test_ringbuffer_declare_size) { zassert_true(ring_buf_is_empty(&ringbuf_size)); - zassert_equal(ring_buf_item_space_get(&ringbuf_size), RINGBUFFER_SIZE, - NULL); + zassert_equal(ring_buf_item_space_get(&ringbuf_size), RINGBUFFER_SIZE); } /** @@ -501,8 +500,7 @@ ZTEST(ringbuffer_api, test_ringbuffer_raw) zassert_true(in_size == RINGBUFFER_SIZE - 2); zassert_true(in_size == out_size); - zassert_true(memcmp(inbuf, outbuf, RINGBUFFER_SIZE - 2) == 0, - NULL); + zassert_true(memcmp(inbuf, outbuf, RINGBUFFER_SIZE - 2) == 0); } memset(outbuf, 0, sizeof(outbuf)); @@ -634,10 +632,8 @@ ZTEST(ringbuffer_api, test_byte_put_free) granted = ring_buf_get_claim(&ringbuf_raw, &data, RINGBUFFER_SIZE); - zassert_true((granted + granted_1) == - RINGBUFFER_SIZE - 2, NULL); - zassert_true(memcmp(&indata[granted_1], data, granted) - == 0, NULL); + zassert_true((granted + granted_1) == RINGBUFFER_SIZE - 2); + zassert_true(memcmp(&indata[granted_1], data, granted) == 0); } else { zassert_true(false); } @@ -682,7 +678,7 @@ ZTEST(ringbuffer_api, test_size) ring_buf_reset(&ringbuf_raw); ring_buf_put(&ringbuf_raw, buf, sizeof(buf)); size = ring_buf_size_get(&ringbuf_raw); - zassert_equal(sizeof(buf), size, "wrong size: exp: %u: actual: %u", sizeof(buf), size); + zassert_equal(sizeof(buf), size, "wrong size: exp: %zu: actual: %u", sizeof(buf), size); /* Test N - 2 with wrap-around */ ring_buf_put(&ringbuf_raw, buf, sizeof(buf)); @@ -690,7 +686,7 @@ ZTEST(ringbuffer_api, test_size) ring_buf_put(&ringbuf_raw, "x", 1); size = ring_buf_size_get(&ringbuf_raw); - zassert_equal(sizeof(buf) - 2, size, "wrong size: exp: %u: actual: %u", sizeof(buf) - 2, + zassert_equal(sizeof(buf) - 2, size, "wrong size: exp: %zu: actual: %u", sizeof(buf) - 2, size); } @@ -724,9 +720,10 @@ ZTEST(ringbuffer_api, test_peek) memset(buf, '*', sizeof(buf)); /* fill with pattern */ size = ring_buf_peek(&ringbuf_raw, buf, sizeof(buf)); - zassert_equal(sizeof(buf), size, "wrong peek size: exp: %u: actual: %u", sizeof(buf), size); + zassert_equal(sizeof(buf), size, + "wrong peek size: exp: %zu: actual: %u", sizeof(buf), size); size = ring_buf_size_get(&ringbuf_raw); - zassert_equal(sizeof(buf), size, "wrong buffer size: exp: %u: actual: %u", sizeof(buf), + zassert_equal(sizeof(buf), size, "wrong buffer size: exp: %zu: actual: %u", sizeof(buf), size); for (size = 0; size < sizeof(buf); ++size) { @@ -835,8 +832,7 @@ ZTEST(ringbuffer_api, test_ringbuffer_array_perf) } /*Data from the end of the ringbuf can be copied into the array*/ - zassert_true(ring_buf_item_get(&buf_ii, &type, &value, - output, &size) == 0, NULL); + zassert_true(ring_buf_item_get(&buf_ii, &type, &value, output, &size) == 0); /*Verify the ringbuf defined is working*/ for (int i = 0; i < 3; i++) { diff --git a/tests/lib/spsc_pbuf/src/main.c b/tests/lib/spsc_pbuf/src/main.c index 7a0a74d5137..1047cd05684 100644 --- a/tests/lib/spsc_pbuf/src/main.c +++ b/tests/lib/spsc_pbuf/src/main.c @@ -38,7 +38,7 @@ static void test_spsc_pbuf_flags(uint32_t flags) memset(memory_area, 0, sizeof(memory_area)); ib = spsc_pbuf_init(memory_area, sizeof(memory_area), flags); - zassert_equal_ptr(ib, memory_area, NULL); + zassert_equal_ptr(ib, memory_area); zassert_equal(spsc_pbuf_capacity(ib), capacity); /* Try writing invalid value. */ @@ -63,7 +63,7 @@ static void test_spsc_pbuf_flags(uint32_t flags) zassert_equal(rlen, sizeof(message)); ib = spsc_pbuf_init(memory_area, sizeof(memory_area), flags); - zassert_equal_ptr(ib, memory_area, NULL); + zassert_equal_ptr(ib, memory_area); int repeat = capacity / (sizeof(message) + sizeof(uint32_t)); @@ -140,7 +140,7 @@ static void packet_write(struct spsc_pbuf *pb, return; } zassert_equal((uintptr_t)buf % sizeof(uint32_t), 0, "%d: Expected aligned buffer", line); - zassert_true(rv >= outlen, "%d: Unexpected rv (bigger than %d)", line, rv, outlen); + zassert_true(rv >= outlen, "%d: Unexpected rv %d (bigger than %d)", line, rv, outlen); for (uint16_t i = 0; i < outlen; i++) { buf[i] = id + i; diff --git a/tests/lib/time/src/main.c b/tests/lib/time/src/main.c index e815ba11dbb..227ed25131f 100644 --- a/tests/lib/time/src/main.c +++ b/tests/lib/time/src/main.c @@ -29,7 +29,7 @@ ZTEST(libc_time, test_time_passing) time_initial = time(NULL); zassert_equal(time_initial, time_initial_unaligned + 1, "Time (%d) should be one second larger than initially (%d)", - time_initial, time_initial_unaligned); + (int)time_initial, (int)time_initial_unaligned); for (i = 1; i <= 10; i++) { k_sleep(K_SECONDS(1)); diff --git a/tests/misc/iterable_sections/src/main.c b/tests/misc/iterable_sections/src/main.c index 2c615ebfcc7..d6320eedd06 100644 --- a/tests/misc/iterable_sections/src/main.c +++ b/tests/misc/iterable_sections/src/main.c @@ -67,13 +67,13 @@ ZTEST(iterable_sections, test_ram) zassert_equal(out, RAM_EXPECT, "Check value incorrect (got: 0x%08x)", out); zassert_equal(ram1.i & CHECK_BIT, CHECK_BIT, - "ram1.i check bit incorrect (got: 0x%x)", ram1.i); + "ram1.i check bit incorrect (got: 0x%x)", (int)ram1.i); zassert_equal(ram2.i & CHECK_BIT, CHECK_BIT, - "ram2.i check bit incorrect (got: 0x%x)", ram2.i); + "ram2.i check bit incorrect (got: 0x%x)", (int)ram2.i); zassert_equal(ram3.i & CHECK_BIT, CHECK_BIT, - "ram3.i check bit incorrect (got: 0x%x)", ram3.i); + "ram3.i check bit incorrect (got: 0x%x)", (int)ram3.i); zassert_equal(ram4.i & CHECK_BIT, CHECK_BIT, - "ram4.i check bit incorrect (got: 0x%x)", ram4.i); + "ram4.i check bit incorrect (got: 0x%x)", (int)ram4.i); out = 0; STRUCT_SECTION_FOREACH_ALTERNATE(test_ram2, test_ram, t) {