blob: 72600548a04c3a63855fedfc2307c4ee86c0b6c3 [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
Andrew Jeffery860a43d2024-08-23 01:21:58 +000012#include "compiler.h"
13
Andrew Jeffery73d91762023-06-28 12:19:19 +093014/* NOLINTNEXTLINE(bugprone-suspicious-include) */
Andrew Jeffery48761c62024-06-03 15:48:26 +093015#include "dsp/bios_table.c"
Andrew Jeffery73d91762023-06-28 12:19:19 +093016
17/* Satisfy the symbol needs of bios_table.c */
Andrew Jeffery860a43d2024-08-23 01:21:58 +000018uint32_t crc32(const void* data LIBPLDM_CC_UNUSED,
19 size_t size LIBPLDM_CC_UNUSED)
Andrew Jeffery73d91762023-06-28 12:19:19 +093020{
21 return 0;
22}
23
24/* This is the non-death version of TEST(Iterator, DeathTest) */
25int 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 Eda9e3a5d42024-06-17 16:06:42 +053041 * end because the there's no entry length descriptor for the
Andrew Jeffery73d91762023-06-28 12:19:19 +093042 * 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}