1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ 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 12 /* NOLINTNEXTLINE(bugprone-suspicious-include) */ 13 #include "dsp/bios_table.c" 14 15 /* Satisfy the symbol needs of bios_table.c */ 16 uint32_t crc32(const void* data __attribute__((unused)), 17 size_t size __attribute__((unused))) 18 { 19 return 0; 20 } 21 22 /* This is the non-death version of TEST(Iterator, DeathTest) */ 23 int main(void) 24 { 25 struct pldm_bios_attr_table_entry entries[2] = {0}; 26 struct pldm_bios_table_iter* iter; 27 int result; 28 29 static_assert(2 * sizeof(entries[0]) == sizeof(entries), ""); 30 31 entries[0].attr_type = PLDM_BIOS_PASSWORD; 32 entries[1].attr_type = PLDM_BIOS_STRING_READ_ONLY; 33 34 iter = pldm_bios_table_iter_create(entries, sizeof(entries), 35 PLDM_BIOS_ATTR_TABLE); 36 37 /* 38 * We expect the test configuration to claim the iterator has reached the 39 * end because the there's no entry length descriptor for the 40 * PLDM_BIOS_PASSWORD entry type. By the attr_able_entry_length() 41 * implementation this would normally trigger an assert() to uphold that the 42 * necessary pointers are not NULL. However, we've defined NDEBUG above and 43 * so the assert() is elided. That should force us down the path of the 44 * early-exit, which should in-turn yield a `true` result from 45 * pldm_bios_table_iter_is_end() to prevent further attempts to access 46 * invalid objects. 47 */ 48 result = pldm_bios_table_iter_is_end(iter) ? EXIT_SUCCESS : EXIT_FAILURE; 49 50 pldm_bios_table_iter_free(iter); 51 52 exit(result); 53 54 return 0; 55 } 56