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