xref: /openbmc/libpldm/tests/dsp/bios_table_iter.c (revision 615344fc)
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 #include "compiler.h"
13 
14 /* NOLINTNEXTLINE(bugprone-suspicious-include) */
15 #include "dsp/bios_table.c"
16 
17 /* Satisfy the symbol needs of bios_table.c */
18 uint32_t crc32(const void* data LIBPLDM_CC_UNUSED,
19                size_t size LIBPLDM_CC_UNUSED)
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
41      * end because the there's no entry length descriptor for the
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 }
58