blob: 5e187b4faa512e721ecaa2de7b7df3cb9c6d8aa2 [file] [log] [blame]
Patrick Williams691668f2023-11-01 08:19:10 -05001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
Andrew Jeffery73d91762023-06-28 12:19:19 +09302/* 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) */
Andrew Jeffery48761c62024-06-03 15:48:26 +093013#include "dsp/bios_table.c"
Andrew Jeffery73d91762023-06-28 12:19:19 +093014
15/* Satisfy the symbol needs of bios_table.c */
16uint32_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) */
23int 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 beause 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}