bloblist: Compare addresses rather than pointers in tests

When running these tests on sandbox any failures result in very large or
long pointer values which are a pain to work with. Map them to an address
so it is easier to diagnose failures.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2020-09-19 18:49:27 -06:00
parent 4aed227623
commit cdd4e30dfc
2 changed files with 27 additions and 13 deletions

View File

@ -224,6 +224,19 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
} \
}
/* Assert that two addresses (converted from pointers) are equal */
#define ut_asserteq_addr(expr1, expr2) { \
ulong _val1 = map_to_sysmem(expr1); \
ulong _val2 = map_to_sysmem(expr2); \
\
if (_val1 != _val2) { \
ut_failf(uts, __FILE__, __LINE__, __func__, \
#expr1 " = " #expr2, \
"Expected %lx, got %lx", _val1, _val2); \
return CMD_RET_FAILURE; \
} \
}
/* Assert that a pointer is NULL */
#define ut_assertnull(expr) { \
const void *_val = (expr); \

View File

@ -95,26 +95,27 @@ static int bloblist_test_blob(struct unit_test_state *uts)
hdr = clear_bloblist();
ut_assertnull(bloblist_find(TEST_TAG, TEST_BLOBLIST_SIZE));
ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0));
ut_asserteq(map_to_sysmem(hdr), TEST_ADDR);
/* Add a record and check that we can find it */
data = bloblist_add(TEST_TAG, TEST_SIZE);
rec = (void *)(hdr + 1);
ut_asserteq_ptr(rec + 1, data);
ut_asserteq_addr(rec + 1, data);
data = bloblist_find(TEST_TAG, TEST_SIZE);
ut_asserteq_ptr(rec + 1, data);
ut_asserteq_addr(rec + 1, data);
/* Check the data is zeroed */
ut_assertok(check_zero(data, TEST_SIZE));
/* Check the 'ensure' method */
ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
ut_asserteq_addr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
ut_assertnull(bloblist_ensure(TEST_TAG, TEST_SIZE2));
rec2 = (struct bloblist_rec *)(data + ALIGN(TEST_SIZE, BLOBLIST_ALIGN));
ut_assertok(check_zero(data, TEST_SIZE));
/* Check for a non-existent record */
ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
ut_asserteq_ptr(rec2 + 1, bloblist_ensure(TEST_TAG2, TEST_SIZE2));
ut_asserteq_addr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
ut_asserteq_addr(rec2 + 1, bloblist_ensure(TEST_TAG2, TEST_SIZE2));
ut_assertnull(bloblist_find(TEST_TAG_MISSING, 0));
return 0;
@ -140,7 +141,7 @@ static int bloblist_test_blob_ensure(struct unit_test_state *uts)
/* Check that we get the same thing again */
ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2));
ut_asserteq(TEST_SIZE, size);
ut_asserteq_ptr(data, data2);
ut_asserteq_addr(data, data2);
/* Check that the size remains the same */
size = TEST_SIZE2;
@ -164,8 +165,8 @@ static int bloblist_test_bad_blob(struct unit_test_state *uts)
ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0));
data = hdr + 1;
data += sizeof(struct bloblist_rec);
ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
ut_asserteq_addr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
ut_asserteq_addr(data, bloblist_ensure(TEST_TAG, TEST_SIZE));
return 0;
}
@ -251,7 +252,7 @@ static int bloblist_test_cmd_info(struct unit_test_state *uts)
gd->flags |= GD_FLG_SILENT;
console_record_reset();
run_command("bloblist info", 0);
ut_assert_nextline("base: %x", map_to_sysmem(hdr));
ut_assert_nextline("base: %lx", (ulong)map_to_sysmem(hdr));
ut_assert_nextline("size: 100 256 Bytes");
ut_assert_nextline("alloced: 70 112 Bytes");
ut_assert_nextline("free: 90 144 Bytes");
@ -280,10 +281,10 @@ static int bloblist_test_cmd_list(struct unit_test_state *uts)
console_record_reset();
run_command("bloblist list", 0);
ut_assert_nextline("Address Size Tag Name");
ut_assert_nextline("%08x %8x 1 EC host event", map_to_sysmem(data),
TEST_SIZE);
ut_assert_nextline("%08x %8x 2 SPL hand-off", map_to_sysmem(data2),
TEST_SIZE2);
ut_assert_nextline("%08lx %8x 1 EC host event",
(ulong)map_to_sysmem(data), TEST_SIZE);
ut_assert_nextline("%08lx %8x 2 SPL hand-off",
(ulong)map_to_sysmem(data2), TEST_SIZE2);
ut_assert_console_end();
gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);