[PATCH 2/5] bloblist: Compare addresses rather than pointers in tests
Simon Glass
sjg at chromium.org
Sun Sep 20 02:49:27 CEST 2020
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 at chromium.org>
---
include/test/ut.h | 13 +++++++++++++
test/bloblist.c | 17 +++++++++--------
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/include/test/ut.h b/include/test/ut.h
index 3295cd4e548..3f2ee7514b8 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -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); \
diff --git a/test/bloblist.c b/test/bloblist.c
index cbdc9db4ecf..271fe9f5d7f 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -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;
}
--
2.28.0.681.g6f77f65b4e-goog
More information about the U-Boot
mailing list