xref: /illumos-gate/usr/src/test/util-tests/tests/smbios/smbios_test.h (revision a92282e44f968185a6bba094d1e5fece2da819cf)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2019 Robert Mustacchi
14  * Copyright 2020 Oxide Computer Company
15  */
16 
17 #ifndef _SMBIOS_TEST_H
18 #define	_SMBIOS_TEST_H
19 
20 /*
21  * Test framework for SMBIOS tests
22  */
23 
24 #include <smbios.h>
25 #include <sys/smbios.h>
26 #include <sys/smbios_impl.h>
27 #include <err.h>
28 #include <stdint.h>
29 #include <endian.h>
30 #include <stdlib.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Number of bytes we allocate at a given time for an SMBIOS table.
38  */
39 #define	SMBIOS_TEST_ALLOC_SIZE	1024
40 
41 typedef struct smbios_test_table {
42 	smbios_entry_point_t	stt_type;
43 	void			*stt_data;
44 	size_t			stt_buflen;
45 	size_t			stt_offset;
46 	uint_t			stt_nents;
47 	uint_t			stt_version;
48 	uint_t			stt_nextid;
49 	smbios_entry_t		stt_entry;
50 } smbios_test_table_t;
51 
52 /*
53  * General Interfaces used to construct tables.
54  */
55 extern smbios_test_table_t *smbios_test_table_init(smbios_entry_point_t,
56     uint_t);
57 extern void smbios_test_table_append_raw(smbios_test_table_t *, const void *,
58     size_t);
59 extern void smbios_test_table_append_string(smbios_test_table_t *,
60     const char *);
61 extern uint16_t smbios_test_table_append(smbios_test_table_t *, const void *,
62     size_t);
63 extern void smbios_test_table_append_eot(smbios_test_table_t *);
64 
65 typedef boolean_t (*smbios_test_mktable_f)(smbios_test_table_t *);
66 typedef boolean_t (*smbios_test_verify_f)(smbios_hdl_t *);
67 
68 typedef struct smbios_test {
69 	int			st_entry;
70 	int			st_tvers;
71 	int			st_libvers;
72 	smbios_test_mktable_f	st_mktable;
73 	boolean_t		st_canopen;
74 	smbios_test_verify_f	st_verify;
75 	const char		*st_desc;
76 } smbios_test_t;
77 
78 /*
79  * Test functions
80  */
81 extern boolean_t smbios_test_slot_mktable(smbios_test_table_t *);
82 extern boolean_t smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *);
83 extern boolean_t smbios_test_slot_mktable_34_peers(smbios_test_table_t *);
84 extern boolean_t smbios_test_slot_verify(smbios_hdl_t *);
85 extern boolean_t smbios_test_slot_verify_34_nopeers(smbios_hdl_t *);
86 extern boolean_t smbios_test_slot_verify_34_peers(smbios_hdl_t *);
87 extern boolean_t smbios_test_badvers_mktable(smbios_test_table_t *);
88 
89 extern boolean_t smbios_test_memdevice_mktable_32(smbios_test_table_t *);
90 extern boolean_t smbios_test_memdevice_mktable_33(smbios_test_table_t *);
91 extern boolean_t smbios_test_memdevice_mktable_33ext(smbios_test_table_t *);
92 extern boolean_t smbios_test_memdevice_verify_32(smbios_hdl_t *);
93 extern boolean_t smbios_test_memdevice_verify_32_33(smbios_hdl_t *);
94 extern boolean_t smbios_test_memdevice_verify_33(smbios_hdl_t *);
95 extern boolean_t smbios_test_memdevice_verify_33ext(smbios_hdl_t *);
96 
97 extern boolean_t smbios_test_pinfo_mktable_amd64(smbios_test_table_t *);
98 extern boolean_t smbios_test_pinfo_verify_amd64(smbios_hdl_t *);
99 extern boolean_t smbios_test_pinfo_mktable_riscv(smbios_test_table_t *);
100 extern boolean_t smbios_test_pinfo_verify_riscv(smbios_hdl_t *);
101 extern boolean_t smbios_test_pinfo_mktable_invlen1(smbios_test_table_t *);
102 extern boolean_t smbios_test_pinfo_mktable_invlen2(smbios_test_table_t *);
103 extern boolean_t smbios_test_pinfo_mktable_invlen3(smbios_test_table_t *);
104 extern boolean_t smbios_test_pinfo_mktable_invlen4(smbios_test_table_t *);
105 extern boolean_t smbios_test_pinfo_verify_invlen1(smbios_hdl_t *);
106 extern boolean_t smbios_test_pinfo_verify_invlen2(smbios_hdl_t *);
107 extern boolean_t smbios_test_pinfo_verify_invlen3(smbios_hdl_t *);
108 extern boolean_t smbios_test_pinfo_verify_invlen4(smbios_hdl_t *);
109 extern boolean_t smbios_test_pinfo_verify_badtype(smbios_hdl_t *);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* _SMBIOS_TEST_H */
116