Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2018, Google Inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <bloblist.h> |
| 8 | #include <log.h> |
| 9 | #include <mapmem.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 11 | #include <test/suites.h> |
| 12 | #include <test/test.h> |
| 13 | #include <test/ut.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Simon Glass | 127ca10 | 2021-08-18 21:40:28 -0600 | [diff] [blame] | 17 | /* Declare a new bloblist test */ |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 18 | #define BLOBLIST_TEST(_name, _flags) \ |
| 19 | UNIT_TEST(_name, _flags, bloblist_test) |
| 20 | |
| 21 | enum { |
Simon Glass | f16ec77 | 2022-01-12 19:26:19 -0700 | [diff] [blame] | 22 | TEST_TAG = BLOBLISTT_U_BOOT_SPL_HANDOFF, |
| 23 | TEST_TAG2 = BLOBLISTT_VBOOT_CTX, |
| 24 | TEST_TAG_MISSING = 0x10000, |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 25 | |
| 26 | TEST_SIZE = 10, |
| 27 | TEST_SIZE2 = 20, |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 28 | TEST_SIZE_LARGE = 0x3e0, |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 29 | |
| 30 | TEST_ADDR = CONFIG_BLOBLIST_ADDR, |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 31 | TEST_BLOBLIST_SIZE = 0x400, |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 32 | |
| 33 | ERASE_BYTE = '\xff', |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 36 | static const char test1_str[] = "the eyes are open"; |
| 37 | static const char test2_str[] = "the mouth moves"; |
| 38 | |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 39 | static struct bloblist_hdr *clear_bloblist(void) |
| 40 | { |
| 41 | struct bloblist_hdr *hdr; |
| 42 | |
Simon Glass | b83994d | 2020-01-27 08:49:52 -0700 | [diff] [blame] | 43 | /* |
| 44 | * Clear out any existing bloblist so we have a clean slate. Zero the |
| 45 | * header so that existing records are removed, but set everything else |
| 46 | * to 0xff for testing purposes. |
| 47 | */ |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 48 | hdr = map_sysmem(CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE); |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 49 | memset(hdr, ERASE_BYTE, TEST_BLOBLIST_SIZE); |
Simon Glass | b83994d | 2020-01-27 08:49:52 -0700 | [diff] [blame] | 50 | memset(hdr, '\0', sizeof(*hdr)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 51 | |
| 52 | return hdr; |
| 53 | } |
| 54 | |
Simon Glass | b83994d | 2020-01-27 08:49:52 -0700 | [diff] [blame] | 55 | static int check_zero(void *data, int size) |
| 56 | { |
| 57 | u8 *ptr; |
| 58 | int i; |
| 59 | |
| 60 | for (ptr = data, i = 0; i < size; i++, ptr++) { |
| 61 | if (*ptr) |
| 62 | return -EINVAL; |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 68 | static int bloblist_test_init(struct unit_test_state *uts) |
| 69 | { |
| 70 | struct bloblist_hdr *hdr; |
| 71 | |
| 72 | hdr = clear_bloblist(); |
| 73 | ut_asserteq(-ENOENT, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
Simon Glass | ff3bd49 | 2022-01-12 19:26:16 -0700 | [diff] [blame] | 74 | ut_asserteq_ptr(NULL, bloblist_check_magic(TEST_ADDR)); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 75 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | ff3bd49 | 2022-01-12 19:26:16 -0700 | [diff] [blame] | 76 | ut_asserteq_ptr(hdr, bloblist_check_magic(TEST_ADDR)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 77 | hdr->version++; |
| 78 | ut_asserteq(-EPROTONOSUPPORT, bloblist_check(TEST_ADDR, |
| 79 | TEST_BLOBLIST_SIZE)); |
| 80 | |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 81 | ut_asserteq(-ENOSPC, bloblist_new(TEST_ADDR, 0xc, 0, 0)); |
| 82 | ut_asserteq(-EFAULT, bloblist_new(1, TEST_BLOBLIST_SIZE, 0, 0)); |
| 83 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 84 | |
| 85 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 86 | ut_assertok(bloblist_finish()); |
| 87 | ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
Simon Glass | ff3bd49 | 2022-01-12 19:26:16 -0700 | [diff] [blame] | 88 | |
| 89 | hdr->magic++; |
| 90 | ut_asserteq_ptr(NULL, bloblist_check_magic(TEST_ADDR)); |
| 91 | hdr->magic--; |
| 92 | |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 93 | hdr->flags++; |
| 94 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 95 | |
| 96 | return 1; |
| 97 | } |
| 98 | BLOBLIST_TEST(bloblist_test_init, 0); |
| 99 | |
| 100 | static int bloblist_test_blob(struct unit_test_state *uts) |
| 101 | { |
| 102 | struct bloblist_hdr *hdr; |
| 103 | struct bloblist_rec *rec, *rec2; |
| 104 | char *data; |
| 105 | |
| 106 | /* At the start there should be no records */ |
| 107 | hdr = clear_bloblist(); |
| 108 | ut_assertnull(bloblist_find(TEST_TAG, TEST_BLOBLIST_SIZE)); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 109 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 110 | ut_asserteq(sizeof(struct bloblist_hdr), bloblist_get_size()); |
| 111 | ut_asserteq(TEST_BLOBLIST_SIZE, bloblist_get_total_size()); |
Simon Glass | e50a24a | 2022-01-12 19:26:23 -0700 | [diff] [blame] | 112 | ut_asserteq(TEST_ADDR, bloblist_get_base()); |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 113 | ut_asserteq(map_to_sysmem(hdr), TEST_ADDR); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 114 | |
| 115 | /* Add a record and check that we can find it */ |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 116 | data = bloblist_add(TEST_TAG, TEST_SIZE, 0); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 117 | rec = (void *)(hdr + 1); |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 118 | ut_asserteq_addr(rec + 1, data); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 119 | data = bloblist_find(TEST_TAG, TEST_SIZE); |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 120 | ut_asserteq_addr(rec + 1, data); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 121 | |
Simon Glass | b83994d | 2020-01-27 08:49:52 -0700 | [diff] [blame] | 122 | /* Check the data is zeroed */ |
| 123 | ut_assertok(check_zero(data, TEST_SIZE)); |
| 124 | |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 125 | /* Check the 'ensure' method */ |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 126 | ut_asserteq_addr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 127 | ut_assertnull(bloblist_ensure(TEST_TAG, TEST_SIZE2)); |
| 128 | rec2 = (struct bloblist_rec *)(data + ALIGN(TEST_SIZE, BLOBLIST_ALIGN)); |
Simon Glass | b83994d | 2020-01-27 08:49:52 -0700 | [diff] [blame] | 129 | ut_assertok(check_zero(data, TEST_SIZE)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 130 | |
| 131 | /* Check for a non-existent record */ |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 132 | ut_asserteq_addr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); |
| 133 | ut_asserteq_addr(rec2 + 1, bloblist_ensure(TEST_TAG2, TEST_SIZE2)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 134 | ut_assertnull(bloblist_find(TEST_TAG_MISSING, 0)); |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | BLOBLIST_TEST(bloblist_test_blob, 0); |
| 139 | |
Simon Glass | 5b04454 | 2020-01-27 08:49:50 -0700 | [diff] [blame] | 140 | /* Check bloblist_ensure_size_ret() */ |
| 141 | static int bloblist_test_blob_ensure(struct unit_test_state *uts) |
| 142 | { |
| 143 | void *data, *data2; |
| 144 | int size; |
| 145 | |
| 146 | /* At the start there should be no records */ |
| 147 | clear_bloblist(); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 148 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 5b04454 | 2020-01-27 08:49:50 -0700 | [diff] [blame] | 149 | |
| 150 | /* Test with an empty bloblist */ |
| 151 | size = TEST_SIZE; |
| 152 | ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); |
| 153 | ut_asserteq(TEST_SIZE, size); |
Simon Glass | b83994d | 2020-01-27 08:49:52 -0700 | [diff] [blame] | 154 | ut_assertok(check_zero(data, TEST_SIZE)); |
Simon Glass | 5b04454 | 2020-01-27 08:49:50 -0700 | [diff] [blame] | 155 | |
| 156 | /* Check that we get the same thing again */ |
| 157 | ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); |
| 158 | ut_asserteq(TEST_SIZE, size); |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 159 | ut_asserteq_addr(data, data2); |
Simon Glass | 5b04454 | 2020-01-27 08:49:50 -0700 | [diff] [blame] | 160 | |
| 161 | /* Check that the size remains the same */ |
| 162 | size = TEST_SIZE2; |
| 163 | ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); |
| 164 | ut_asserteq(TEST_SIZE, size); |
| 165 | |
| 166 | /* Check running out of space */ |
| 167 | size = TEST_SIZE_LARGE; |
| 168 | ut_asserteq(-ENOSPC, bloblist_ensure_size_ret(TEST_TAG2, &size, &data)); |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | BLOBLIST_TEST(bloblist_test_blob_ensure, 0); |
| 173 | |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 174 | static int bloblist_test_bad_blob(struct unit_test_state *uts) |
| 175 | { |
| 176 | struct bloblist_hdr *hdr; |
| 177 | void *data; |
| 178 | |
| 179 | hdr = clear_bloblist(); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 180 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 181 | data = hdr + 1; |
| 182 | data += sizeof(struct bloblist_rec); |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 183 | ut_asserteq_addr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); |
| 184 | ut_asserteq_addr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | BLOBLIST_TEST(bloblist_test_bad_blob, 0); |
| 189 | |
| 190 | static int bloblist_test_checksum(struct unit_test_state *uts) |
| 191 | { |
| 192 | struct bloblist_hdr *hdr; |
| 193 | char *data, *data2; |
| 194 | |
| 195 | hdr = clear_bloblist(); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 196 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 197 | ut_assertok(bloblist_finish()); |
| 198 | ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 199 | |
| 200 | /* |
| 201 | * Now change things amd make sure that the checksum notices. We cannot |
| 202 | * change the size or alloced fields, since that will crash the code. |
| 203 | * It has to rely on these being correct. |
| 204 | */ |
| 205 | hdr->flags--; |
| 206 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 207 | hdr->flags++; |
| 208 | |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 209 | hdr->total_size--; |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 210 | ut_asserteq(-EFBIG, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 211 | hdr->total_size++; |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 212 | |
| 213 | hdr->spare++; |
| 214 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 215 | hdr->spare--; |
| 216 | |
| 217 | hdr->chksum++; |
| 218 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 219 | hdr->chksum--; |
| 220 | |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 221 | hdr->align_log2++; |
| 222 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 223 | hdr->align_log2--; |
| 224 | |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 225 | /* Make sure the checksum changes when we add blobs */ |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 226 | data = bloblist_add(TEST_TAG, TEST_SIZE, 0); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 227 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 228 | |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 229 | data2 = bloblist_add(TEST_TAG2, TEST_SIZE2, 0); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 230 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 231 | ut_assertok(bloblist_finish()); |
| 232 | |
| 233 | /* It should also change if we change the data */ |
| 234 | ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 235 | *data += 1; |
| 236 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 237 | *data -= 1; |
| 238 | |
| 239 | ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 240 | *data2 += 1; |
| 241 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 242 | *data2 -= 1; |
| 243 | |
| 244 | /* |
Simon Glass | 997dac6 | 2023-12-27 13:07:05 -0800 | [diff] [blame] | 245 | * Changing data outside the range of valid data should affect the |
| 246 | * checksum. |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 247 | */ |
| 248 | ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 249 | data[TEST_SIZE]++; |
Simon Glass | 997dac6 | 2023-12-27 13:07:05 -0800 | [diff] [blame] | 250 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 251 | data[TEST_SIZE]--; |
| 252 | ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 253 | |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 254 | data2[TEST_SIZE2]++; |
Simon Glass | 997dac6 | 2023-12-27 13:07:05 -0800 | [diff] [blame] | 255 | ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 256 | data[TEST_SIZE]--; |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 257 | ut_assertok(bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE)); |
| 258 | |
| 259 | return 0; |
| 260 | } |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 261 | BLOBLIST_TEST(bloblist_test_checksum, 0); |
| 262 | |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 263 | /* Test the 'bloblist info' command */ |
| 264 | static int bloblist_test_cmd_info(struct unit_test_state *uts) |
| 265 | { |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 266 | struct bloblist_hdr *hdr; |
| 267 | char *data, *data2; |
| 268 | |
| 269 | hdr = clear_bloblist(); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 270 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 271 | data = bloblist_ensure(TEST_TAG, TEST_SIZE); |
| 272 | data2 = bloblist_ensure(TEST_TAG2, TEST_SIZE2); |
| 273 | |
| 274 | console_record_reset_enable(); |
Simon Glass | ef7e264 | 2020-11-08 21:08:43 -0700 | [diff] [blame] | 275 | ut_silence_console(uts); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 276 | console_record_reset(); |
| 277 | run_command("bloblist info", 0); |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 278 | ut_assert_nextline("base: %lx", (ulong)map_to_sysmem(hdr)); |
| 279 | ut_assert_nextline("total size: 400 1 KiB"); |
| 280 | ut_assert_nextline("used size: 50 80 Bytes"); |
| 281 | ut_assert_nextline("free: 3b0 944 Bytes"); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 282 | ut_assert_console_end(); |
Simon Glass | ef7e264 | 2020-11-08 21:08:43 -0700 | [diff] [blame] | 283 | ut_unsilence_console(uts); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | BLOBLIST_TEST(bloblist_test_cmd_info, 0); |
| 288 | |
| 289 | /* Test the 'bloblist list' command */ |
| 290 | static int bloblist_test_cmd_list(struct unit_test_state *uts) |
| 291 | { |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 292 | struct bloblist_hdr *hdr; |
| 293 | char *data, *data2; |
| 294 | |
| 295 | hdr = clear_bloblist(); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 296 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 297 | data = bloblist_ensure(TEST_TAG, TEST_SIZE); |
| 298 | data2 = bloblist_ensure(TEST_TAG2, TEST_SIZE2); |
| 299 | |
| 300 | console_record_reset_enable(); |
Simon Glass | ef7e264 | 2020-11-08 21:08:43 -0700 | [diff] [blame] | 301 | ut_silence_console(uts); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 302 | console_record_reset(); |
| 303 | run_command("bloblist list", 0); |
Simon Glass | f16ec77 | 2022-01-12 19:26:19 -0700 | [diff] [blame] | 304 | ut_assert_nextline("Address Size Tag Name"); |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 305 | ut_assert_nextline("%08lx %8x fff000 SPL hand-off", |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 306 | (ulong)map_to_sysmem(data), TEST_SIZE); |
Simon Glass | e748e4b | 2023-12-27 13:06:59 -0800 | [diff] [blame] | 307 | ut_assert_nextline("%08lx %8x 202 Chrome OS vboot context", |
Simon Glass | cdd4e30 | 2020-09-19 18:49:27 -0600 | [diff] [blame] | 308 | (ulong)map_to_sysmem(data2), TEST_SIZE2); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 309 | ut_assert_console_end(); |
Simon Glass | ef7e264 | 2020-11-08 21:08:43 -0700 | [diff] [blame] | 310 | ut_unsilence_console(uts); |
Simon Glass | 4aed227 | 2020-09-19 18:49:26 -0600 | [diff] [blame] | 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | BLOBLIST_TEST(bloblist_test_cmd_list, 0); |
| 315 | |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 316 | /* Test alignment of bloblist blobs */ |
| 317 | static int bloblist_test_align(struct unit_test_state *uts) |
| 318 | { |
| 319 | struct bloblist_hdr *hdr; |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 320 | ulong addr; |
| 321 | char *data; |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 322 | int i; |
| 323 | |
| 324 | /* At the start there should be no records */ |
| 325 | hdr = clear_bloblist(); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 326 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 327 | ut_assertnull(bloblist_find(TEST_TAG, TEST_BLOBLIST_SIZE)); |
| 328 | |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 329 | /* Check the default alignment */ |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 330 | for (i = 0; i < 3; i++) { |
| 331 | int size = i * 3; |
| 332 | ulong addr; |
| 333 | char *data; |
| 334 | int j; |
| 335 | |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 336 | data = bloblist_add(i, size, 0); |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 337 | ut_assertnonnull(data); |
| 338 | addr = map_to_sysmem(data); |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 339 | ut_asserteq(0, addr & (BLOBLIST_BLOB_ALIGN - 1)); |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 340 | |
| 341 | /* Only the bytes in the blob data should be zeroed */ |
| 342 | for (j = 0; j < size; j++) |
| 343 | ut_asserteq(0, data[j]); |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 344 | for (; j < BLOBLIST_BLOB_ALIGN; j++) |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 345 | ut_asserteq(ERASE_BYTE, data[j]); |
| 346 | } |
| 347 | |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 348 | /* Check larger alignment */ |
| 349 | for (i = 0; i < 3; i++) { |
Simon Glass | 1a2e02f | 2023-12-27 13:07:00 -0800 | [diff] [blame] | 350 | int align = 5 - i; |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 351 | |
| 352 | data = bloblist_add(3 + i, i * 4, align); |
| 353 | ut_assertnonnull(data); |
| 354 | addr = map_to_sysmem(data); |
| 355 | ut_asserteq(0, addr & (align - 1)); |
| 356 | } |
| 357 | |
| 358 | /* Check alignment with an bloblist starting on a smaller alignment */ |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 359 | hdr = map_sysmem(TEST_ADDR + BLOBLIST_BLOB_ALIGN, TEST_BLOBLIST_SIZE); |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 360 | memset(hdr, ERASE_BYTE, TEST_BLOBLIST_SIZE); |
| 361 | memset(hdr, '\0', sizeof(*hdr)); |
| 362 | ut_assertok(bloblist_new(TEST_ADDR + BLOBLIST_ALIGN, TEST_BLOBLIST_SIZE, |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 363 | 0, 0)); |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 364 | |
Simon Glass | 1a2e02f | 2023-12-27 13:07:00 -0800 | [diff] [blame] | 365 | data = bloblist_add(1, 5, BLOBLIST_ALIGN_LOG2 + 1); |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 366 | ut_assertnonnull(data); |
| 367 | addr = map_to_sysmem(data); |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 368 | ut_asserteq(0, addr & (BLOBLIST_BLOB_ALIGN * 2 - 1)); |
Simon Glass | 4c1497e | 2020-09-19 18:49:29 -0600 | [diff] [blame] | 369 | |
Simon Glass | 751b7c7 | 2020-09-19 18:49:28 -0600 | [diff] [blame] | 370 | return 0; |
| 371 | } |
| 372 | BLOBLIST_TEST(bloblist_test_align, 0); |
| 373 | |
Simon Glass | 9fe0646 | 2021-01-13 20:29:43 -0700 | [diff] [blame] | 374 | /* Test relocation of a bloblist */ |
| 375 | static int bloblist_test_reloc(struct unit_test_state *uts) |
| 376 | { |
| 377 | const uint large_size = TEST_BLOBLIST_SIZE; |
| 378 | const uint small_size = 0x20; |
| 379 | void *old_ptr, *new_ptr; |
| 380 | void *blob1, *blob2; |
| 381 | ulong new_addr; |
| 382 | ulong new_size; |
| 383 | |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 384 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 9fe0646 | 2021-01-13 20:29:43 -0700 | [diff] [blame] | 385 | old_ptr = map_sysmem(TEST_ADDR, TEST_BLOBLIST_SIZE); |
| 386 | |
| 387 | /* Add one blob and then one that won't fit */ |
| 388 | blob1 = bloblist_add(TEST_TAG, small_size, 0); |
| 389 | ut_assertnonnull(blob1); |
| 390 | blob2 = bloblist_add(TEST_TAG2, large_size, 0); |
| 391 | ut_assertnull(blob2); |
| 392 | |
| 393 | /* Relocate the bloblist somewhere else, a bit larger */ |
| 394 | new_addr = TEST_ADDR + TEST_BLOBLIST_SIZE; |
| 395 | new_size = TEST_BLOBLIST_SIZE + 0x100; |
| 396 | new_ptr = map_sysmem(new_addr, TEST_BLOBLIST_SIZE); |
| 397 | bloblist_reloc(new_ptr, new_size, old_ptr, TEST_BLOBLIST_SIZE); |
| 398 | gd->bloblist = new_ptr; |
| 399 | |
| 400 | /* Check the old blob is there and that we can now add the bigger one */ |
| 401 | ut_assertnonnull(bloblist_find(TEST_TAG, small_size)); |
| 402 | ut_assertnull(bloblist_find(TEST_TAG2, small_size)); |
| 403 | blob2 = bloblist_add(TEST_TAG2, large_size, 0); |
| 404 | ut_assertnonnull(blob2); |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | BLOBLIST_TEST(bloblist_test_reloc, 0); |
| 409 | |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 410 | /* Test expansion of a blob */ |
| 411 | static int bloblist_test_grow(struct unit_test_state *uts) |
| 412 | { |
| 413 | const uint small_size = 0x20; |
| 414 | void *blob1, *blob2, *blob1_new; |
| 415 | struct bloblist_hdr *hdr; |
| 416 | void *ptr; |
| 417 | |
| 418 | ptr = map_sysmem(TEST_ADDR, TEST_BLOBLIST_SIZE); |
| 419 | hdr = ptr; |
| 420 | memset(hdr, ERASE_BYTE, TEST_BLOBLIST_SIZE); |
| 421 | |
| 422 | /* Create two blobs */ |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 423 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 424 | blob1 = bloblist_add(TEST_TAG, small_size, 0); |
| 425 | ut_assertnonnull(blob1); |
| 426 | ut_assertok(check_zero(blob1, small_size)); |
| 427 | strcpy(blob1, test1_str); |
| 428 | |
| 429 | blob2 = bloblist_add(TEST_TAG2, small_size, 0); |
| 430 | ut_assertnonnull(blob2); |
| 431 | strcpy(blob2, test2_str); |
| 432 | |
| 433 | ut_asserteq(sizeof(struct bloblist_hdr) + |
| 434 | sizeof(struct bloblist_rec) * 2 + small_size * 2, |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 435 | hdr->used_size); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 436 | |
| 437 | /* Resize the first one */ |
| 438 | ut_assertok(bloblist_resize(TEST_TAG, small_size + 4)); |
| 439 | |
| 440 | /* The first one should not have moved, just got larger */ |
| 441 | blob1_new = bloblist_find(TEST_TAG, small_size + 4); |
| 442 | ut_asserteq_ptr(blob1, blob1_new); |
| 443 | |
| 444 | /* The new space should be zeroed */ |
| 445 | ut_assertok(check_zero(blob1 + small_size, 4)); |
| 446 | |
| 447 | /* The second one should have moved */ |
| 448 | blob2 = bloblist_find(TEST_TAG2, small_size); |
| 449 | ut_assertnonnull(blob2); |
| 450 | ut_asserteq_str(test2_str, blob2); |
| 451 | |
| 452 | /* The header should have more bytes in use */ |
| 453 | hdr = ptr; |
| 454 | ut_asserteq(sizeof(struct bloblist_hdr) + |
| 455 | sizeof(struct bloblist_rec) * 2 + small_size * 2 + |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 456 | BLOBLIST_BLOB_ALIGN, |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 457 | hdr->used_size); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | BLOBLIST_TEST(bloblist_test_grow, 0); |
| 462 | |
| 463 | /* Test shrinking of a blob */ |
| 464 | static int bloblist_test_shrink(struct unit_test_state *uts) |
| 465 | { |
| 466 | const uint small_size = 0x20; |
| 467 | void *blob1, *blob2, *blob1_new; |
| 468 | struct bloblist_hdr *hdr; |
| 469 | int new_size; |
| 470 | void *ptr; |
| 471 | |
| 472 | ptr = map_sysmem(TEST_ADDR, TEST_BLOBLIST_SIZE); |
| 473 | |
| 474 | /* Create two blobs */ |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 475 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 476 | blob1 = bloblist_add(TEST_TAG, small_size, 0); |
| 477 | ut_assertnonnull(blob1); |
| 478 | strcpy(blob1, test1_str); |
| 479 | |
| 480 | blob2 = bloblist_add(TEST_TAG2, small_size, 0); |
| 481 | ut_assertnonnull(blob2); |
| 482 | strcpy(blob2, test2_str); |
| 483 | |
| 484 | hdr = ptr; |
| 485 | ut_asserteq(sizeof(struct bloblist_hdr) + |
| 486 | sizeof(struct bloblist_rec) * 2 + small_size * 2, |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 487 | hdr->used_size); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 488 | |
| 489 | /* Resize the first one */ |
| 490 | new_size = small_size - BLOBLIST_ALIGN - 4; |
| 491 | ut_assertok(bloblist_resize(TEST_TAG, new_size)); |
| 492 | |
| 493 | /* The first one should not have moved, just got smaller */ |
| 494 | blob1_new = bloblist_find(TEST_TAG, new_size); |
| 495 | ut_asserteq_ptr(blob1, blob1_new); |
| 496 | |
| 497 | /* The second one should have moved */ |
| 498 | blob2 = bloblist_find(TEST_TAG2, small_size); |
| 499 | ut_assertnonnull(blob2); |
| 500 | ut_asserteq_str(test2_str, blob2); |
| 501 | |
| 502 | /* The header should have fewer bytes in use */ |
| 503 | hdr = ptr; |
| 504 | ut_asserteq(sizeof(struct bloblist_hdr) + |
| 505 | sizeof(struct bloblist_rec) * 2 + small_size * 2 - |
| 506 | BLOBLIST_ALIGN, |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 507 | hdr->used_size); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | BLOBLIST_TEST(bloblist_test_shrink, 0); |
| 512 | |
| 513 | /* Test failing to adjust a blob size */ |
| 514 | static int bloblist_test_resize_fail(struct unit_test_state *uts) |
| 515 | { |
| 516 | const uint small_size = 0x20; |
| 517 | struct bloblist_hdr *hdr; |
| 518 | void *blob1, *blob2; |
| 519 | int new_size; |
| 520 | void *ptr; |
| 521 | |
| 522 | ptr = map_sysmem(TEST_ADDR, TEST_BLOBLIST_SIZE); |
| 523 | |
| 524 | /* Create two blobs */ |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 525 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 526 | blob1 = bloblist_add(TEST_TAG, small_size, 0); |
| 527 | ut_assertnonnull(blob1); |
| 528 | |
| 529 | blob2 = bloblist_add(TEST_TAG2, small_size, 0); |
| 530 | ut_assertnonnull(blob2); |
| 531 | |
| 532 | hdr = ptr; |
| 533 | ut_asserteq(sizeof(struct bloblist_hdr) + |
| 534 | sizeof(struct bloblist_rec) * 2 + small_size * 2, |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 535 | hdr->used_size); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 536 | |
| 537 | /* Resize the first one, to check the boundary conditions */ |
| 538 | ut_asserteq(-EINVAL, bloblist_resize(TEST_TAG, -1)); |
| 539 | |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 540 | new_size = small_size + (hdr->total_size - hdr->used_size); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 541 | ut_asserteq(-ENOSPC, bloblist_resize(TEST_TAG, new_size + 1)); |
| 542 | ut_assertok(bloblist_resize(TEST_TAG, new_size)); |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | BLOBLIST_TEST(bloblist_test_resize_fail, 0); |
| 547 | |
| 548 | /* Test expanding the last blob in a bloblist */ |
| 549 | static int bloblist_test_resize_last(struct unit_test_state *uts) |
| 550 | { |
| 551 | const uint small_size = 0x20; |
| 552 | struct bloblist_hdr *hdr; |
| 553 | void *blob1, *blob2, *blob2_new; |
| 554 | int alloced_val; |
| 555 | void *ptr; |
| 556 | |
| 557 | ptr = map_sysmem(TEST_ADDR, TEST_BLOBLIST_SIZE); |
| 558 | memset(ptr, ERASE_BYTE, TEST_BLOBLIST_SIZE); |
| 559 | hdr = ptr; |
| 560 | |
| 561 | /* Create two blobs */ |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 562 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 563 | blob1 = bloblist_add(TEST_TAG, small_size, 0); |
| 564 | ut_assertnonnull(blob1); |
| 565 | |
| 566 | blob2 = bloblist_add(TEST_TAG2, small_size, 0); |
| 567 | ut_assertnonnull(blob2); |
| 568 | |
| 569 | /* Check the byte after the last blob */ |
| 570 | alloced_val = sizeof(struct bloblist_hdr) + |
| 571 | sizeof(struct bloblist_rec) * 2 + small_size * 2; |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 572 | ut_asserteq(alloced_val, hdr->used_size); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 573 | ut_asserteq_ptr((void *)hdr + alloced_val, blob2 + small_size); |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 574 | ut_asserteq((u8)ERASE_BYTE, *((u8 *)hdr + hdr->used_size)); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 575 | |
| 576 | /* Resize the second one, checking nothing changes */ |
| 577 | ut_asserteq(0, bloblist_resize(TEST_TAG2, small_size + 4)); |
| 578 | |
| 579 | blob2_new = bloblist_find(TEST_TAG2, small_size + 4); |
| 580 | ut_asserteq_ptr(blob2, blob2_new); |
| 581 | |
| 582 | /* |
| 583 | * the new blob should encompass the byte we checked now, so it should |
| 584 | * be zeroed. This zeroing should affect only the four new bytes added |
| 585 | * to the blob. |
| 586 | */ |
| 587 | ut_asserteq(0, *((u8 *)hdr + alloced_val)); |
| 588 | ut_asserteq((u8)ERASE_BYTE, *((u8 *)hdr + alloced_val + 4)); |
| 589 | |
| 590 | /* Check that the new top of the allocated blobs has not been touched */ |
Simon Glass | b6e8382 | 2023-12-27 13:07:07 -0800 | [diff] [blame] | 591 | alloced_val += BLOBLIST_BLOB_ALIGN; |
Simon Glass | b86b2d9 | 2023-12-27 13:07:08 -0800 | [diff] [blame] | 592 | ut_asserteq(alloced_val, hdr->used_size); |
| 593 | ut_asserteq((u8)ERASE_BYTE, *((u8 *)hdr + hdr->used_size)); |
Simon Glass | 1fe5937 | 2021-07-05 16:32:53 -0600 | [diff] [blame] | 594 | |
| 595 | return 0; |
| 596 | } |
| 597 | BLOBLIST_TEST(bloblist_test_resize_last, 0); |
| 598 | |
Simon Glass | 1f618d5 | 2021-07-05 16:32:55 -0600 | [diff] [blame] | 599 | /* Check a completely full bloblist */ |
| 600 | static int bloblist_test_blob_maxsize(struct unit_test_state *uts) |
| 601 | { |
| 602 | void *ptr; |
| 603 | int size; |
| 604 | |
| 605 | /* At the start there should be no records */ |
| 606 | clear_bloblist(); |
Simon Glass | 7d790a8 | 2023-12-27 13:07:09 -0800 | [diff] [blame] | 607 | ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0)); |
Simon Glass | 1f618d5 | 2021-07-05 16:32:55 -0600 | [diff] [blame] | 608 | |
| 609 | /* Add a blob that takes up all space */ |
| 610 | size = TEST_BLOBLIST_SIZE - sizeof(struct bloblist_hdr) - |
| 611 | sizeof(struct bloblist_rec); |
| 612 | ptr = bloblist_add(TEST_TAG, size, 0); |
| 613 | ut_assertnonnull(ptr); |
| 614 | |
| 615 | ptr = bloblist_add(TEST_TAG, size + 1, 0); |
| 616 | ut_assertnull(ptr); |
| 617 | |
| 618 | return 0; |
| 619 | } |
| 620 | BLOBLIST_TEST(bloblist_test_blob_maxsize, 0); |
| 621 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 622 | int do_ut_bloblist(struct cmd_tbl *cmdtp, int flag, int argc, |
| 623 | char *const argv[]) |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 624 | { |
Simon Glass | a7a9875 | 2021-03-07 17:35:10 -0700 | [diff] [blame] | 625 | struct unit_test *tests = UNIT_TEST_SUITE_START(bloblist_test); |
| 626 | const int n_ents = UNIT_TEST_SUITE_COUNT(bloblist_test); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 627 | |
Philippe Reynes | 4ad4edf | 2019-12-17 19:07:04 +0100 | [diff] [blame] | 628 | return cmd_ut_category("bloblist", "bloblist_test_", |
| 629 | tests, n_ents, argc, argv); |
Simon Glass | 919e7a8 | 2018-11-15 18:43:53 -0700 | [diff] [blame] | 630 | } |