Patrick Williams | 691668f | 2023-11-01 08:19:10 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Andrew Jeffery | 73d9176 | 2023-06-28 12:19:19 +0930 | [diff] [blame] | 2 | /* Force elision of assert() */ |
| 3 | #ifndef NDEBUG |
| 4 | #define NDEBUG |
| 5 | #endif |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | #include <stdlib.h> |
| 11 | |
Andrew Jeffery | 860a43d | 2024-08-23 01:21:58 +0000 | [diff] [blame] | 12 | #include "compiler.h" |
| 13 | |
Andrew Jeffery | 73d9176 | 2023-06-28 12:19:19 +0930 | [diff] [blame] | 14 | /* NOLINTNEXTLINE(bugprone-suspicious-include) */ |
Andrew Jeffery | 48761c6 | 2024-06-03 15:48:26 +0930 | [diff] [blame] | 15 | #include "dsp/bios_table.c" |
Andrew Jeffery | 73d9176 | 2023-06-28 12:19:19 +0930 | [diff] [blame] | 16 | |
| 17 | /* Satisfy the symbol needs of bios_table.c */ |
Andrew Jeffery | 860a43d | 2024-08-23 01:21:58 +0000 | [diff] [blame] | 18 | uint32_t crc32(const void* data LIBPLDM_CC_UNUSED, |
| 19 | size_t size LIBPLDM_CC_UNUSED) |
Andrew Jeffery | 73d9176 | 2023-06-28 12:19:19 +0930 | [diff] [blame] | 20 | { |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | /* This is the non-death version of TEST(Iterator, DeathTest) */ |
| 25 | int main(void) |
| 26 | { |
| 27 | struct pldm_bios_attr_table_entry entries[2] = {0}; |
| 28 | struct pldm_bios_table_iter* iter; |
| 29 | int result; |
| 30 | |
| 31 | static_assert(2 * sizeof(entries[0]) == sizeof(entries), ""); |
| 32 | |
| 33 | entries[0].attr_type = PLDM_BIOS_PASSWORD; |
| 34 | entries[1].attr_type = PLDM_BIOS_STRING_READ_ONLY; |
| 35 | |
| 36 | iter = pldm_bios_table_iter_create(entries, sizeof(entries), |
| 37 | PLDM_BIOS_ATTR_TABLE); |
| 38 | |
| 39 | /* |
| 40 | * We expect the test configuration to claim the iterator has reached the |
Manojkiran Eda | 9e3a5d4 | 2024-06-17 16:06:42 +0530 | [diff] [blame] | 41 | * end because the there's no entry length descriptor for the |
Andrew Jeffery | 73d9176 | 2023-06-28 12:19:19 +0930 | [diff] [blame] | 42 | * PLDM_BIOS_PASSWORD entry type. By the attr_able_entry_length() |
| 43 | * implementation this would normally trigger an assert() to uphold that the |
| 44 | * necessary pointers are not NULL. However, we've defined NDEBUG above and |
| 45 | * so the assert() is elided. That should force us down the path of the |
| 46 | * early-exit, which should in-turn yield a `true` result from |
| 47 | * pldm_bios_table_iter_is_end() to prevent further attempts to access |
| 48 | * invalid objects. |
| 49 | */ |
| 50 | result = pldm_bios_table_iter_is_end(iter) ? EXIT_SUCCESS : EXIT_FAILURE; |
| 51 | |
| 52 | pldm_bios_table_iter_free(iter); |
| 53 | |
| 54 | exit(result); |
| 55 | |
| 56 | return 0; |
| 57 | } |