summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2025-05-01 07:37:01 -0600
committerSimon Glass <sjg@chromium.org>2025-05-30 09:49:31 +0100
commit97b586695cd80821455ae06ee178c6c8cf759ce6 (patch)
tree51e652168f67b87cfc9fd044079d83a2b574ba7f /test
parenta619c4410956f446510749b6dc3989849616b7a0 (diff)
abuf: Add a helper for initing and allocating a buffer
This construct appears in various places. Reduce code size by adding a function for it. It inits the abuf, then allocates it to the requested size. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/lib/abuf.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/lib/abuf.c b/test/lib/abuf.c
index b38690fe1a9..cdc86aad988 100644
--- a/test/lib/abuf.c
+++ b/test/lib/abuf.c
@@ -419,3 +419,24 @@ static int lib_test_abuf_init(struct unit_test_state *uts)
return 0;
}
LIB_TEST(lib_test_abuf_init, 0);
+
+/* Test abuf_init_size() */
+static int lib_test_abuf_init_size(struct unit_test_state *uts)
+{
+ struct abuf buf;
+ ulong start;
+
+ start = ut_check_free();
+
+ ut_assert(abuf_init_size(&buf, TEST_DATA_LEN));
+ ut_assertnonnull(buf.data);
+ ut_asserteq(TEST_DATA_LEN, buf.size);
+ ut_asserteq(true, buf.alloced);
+ abuf_uninit(&buf);
+
+ /* Check for memory leaks */
+ ut_assertok(ut_check_delta(start));
+
+ return 0;
+}
+LIB_TEST(lib_test_abuf_init_size, 0);