diff options
author | Simon Glass <sjg@chromium.org> | 2025-05-02 08:46:03 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2025-05-30 09:49:31 +0100 |
commit | d58cebbbc7617fbc45e604c883e8501a58d25e62 (patch) | |
tree | 86b85edc452fc6efef46b3a37dfd63d04dec2a3b /test/lib/abuf.c | |
parent | 97b586695cd80821455ae06ee178c6c8cf759ce6 (diff) |
abuf: Add a function to copy a buffer
It is useful to be able to copy an abuf, to allow changes while
preserving the original. Add a function for this.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/lib/abuf.c')
-rw-r--r-- | test/lib/abuf.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/lib/abuf.c b/test/lib/abuf.c index cdc86aad988..96c77ed2379 100644 --- a/test/lib/abuf.c +++ b/test/lib/abuf.c @@ -420,6 +420,29 @@ static int lib_test_abuf_init(struct unit_test_state *uts) } LIB_TEST(lib_test_abuf_init, 0); +/* Test abuf_copy() */ +static int lib_test_abuf_copy(struct unit_test_state *uts) +{ + struct abuf buf, copy; + ulong start; + + start = ut_check_free(); + + abuf_init_set(&buf, test_data, TEST_DATA_LEN); + ut_assert(abuf_copy(&buf, ©)); + ut_asserteq(buf.size, copy.size); + ut_assert(buf.data != copy.data); + ut_assert(copy.alloced); + abuf_uninit(©); + abuf_uninit(&buf); + + /* Check for memory leaks */ + ut_assertok(ut_check_delta(start)); + + return 0; +} +LIB_TEST(lib_test_abuf_copy, 0); + /* Test abuf_init_size() */ static int lib_test_abuf_init_size(struct unit_test_state *uts) { |