Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/ztest/unit/objpool/test_objpool_ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,44 @@ ZTEST(objpool_suite, test_objpool)
zassert_ok(objpool_free(&head, blocks[k]), "free failed");
}

struct test_objpool_data {
char cnt;
uint8_t reserved[DATA_SIZE - sizeof(char)];
} __packed;

static unsigned int test_objpool_check;

static bool test_objpool_cb(void *data, void *arg)
{
struct test_objpool_data *odata = data;

zassert_equal(test_objpool_check++, odata->cnt, "Counter mismatch");
zassert_equal((unsigned int)arg, 2, "Wrong argument");

return odata->cnt == (unsigned int)arg;
Comment on lines +85 to +92
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test passes an integer as a pointer ((void *)2) and later casts the callback arg back with (unsigned int)arg. This is non-portable and can trigger pointer/integer size warnings (and truncation) on 64-bit builds, potentially failing with -Werror. Use the project’s pointer/int conversion helpers (e.g. UINT_TO_POINTER() when passing and POINTER_TO_UINT()/uintptr_t when reading) or pass a real pointer to a typed value, and update the comparisons accordingly.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyakh can you use the macros ?

}

ZTEST(objpool_suite, test_objpool_iterate)
{
struct objpool_head head = {.list = LIST_INIT(head.list)};
unsigned int i;

for (i = 0; i < 4; i++) {
struct test_objpool_data *odata = objpool_alloc(&head, sizeof(*odata), 0);

zassert_not_null(odata, "allocation failed loop %u", i);

odata->cnt = i;
}

int ret = objpool_iterate(&head, test_objpool_cb, (void *)2);

zassert_equal(test_objpool_check, 3);

zassert_ok(ret);

/* Reset for a possible rerun */
test_objpool_check = 0;
}

ZTEST_SUITE(objpool_suite, NULL, NULL, NULL, NULL, NULL);
Loading