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 2024 Oxide Computer Company 14 */ 15 16 #ifndef _SMBIOS_TEST_H 17 #define _SMBIOS_TEST_H 18 19 /* 20 * Test framework for SMBIOS tests 21 */ 22 23 #include <smbios.h> 24 #include <sys/smbios.h> 25 #include <sys/smbios_impl.h> 26 #include <err.h> 27 #include <stdint.h> 28 #include <endian.h> 29 #include <stdlib.h> 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /* 36 * Number of bytes we allocate at a given time for an SMBIOS table. 37 */ 38 #define SMBIOS_TEST_ALLOC_SIZE 1024 39 40 typedef struct smbios_test_table { 41 smbios_entry_point_t stt_type; 42 void *stt_data; 43 size_t stt_buflen; 44 size_t stt_offset; 45 uint_t stt_nents; 46 uint_t stt_version; 47 uint_t stt_nextid; 48 smbios_entry_t stt_entry; 49 } smbios_test_table_t; 50 51 /* 52 * General Interfaces used to construct tables. 53 */ 54 extern smbios_test_table_t *smbios_test_table_init(smbios_entry_point_t, 55 uint_t); 56 extern void smbios_test_table_append_raw(smbios_test_table_t *, const void *, 57 size_t); 58 extern void smbios_test_table_append_string(smbios_test_table_t *, 59 const char *); 60 extern void smbios_test_table_str_fini(smbios_test_table_t *); 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_mktable_35(smbios_test_table_t *); 85 extern boolean_t smbios_test_slot_verify(smbios_hdl_t *); 86 extern boolean_t smbios_test_slot_verify_34_nopeers(smbios_hdl_t *); 87 extern boolean_t smbios_test_slot_verify_34_peers(smbios_hdl_t *); 88 extern boolean_t smbios_test_slot_verify_34_overrun(smbios_hdl_t *); 89 extern boolean_t smbios_test_slot_verify_35(smbios_hdl_t *); 90 91 extern boolean_t smbios_test_badvers_mktable(smbios_test_table_t *); 92 extern boolean_t smbios_test_verify_badids(smbios_hdl_t *); 93 94 extern boolean_t smbios_test_memdevice_mktable_32(smbios_test_table_t *); 95 extern boolean_t smbios_test_memdevice_mktable_33(smbios_test_table_t *); 96 extern boolean_t smbios_test_memdevice_mktable_33ext(smbios_test_table_t *); 97 extern boolean_t smbios_test_memdevice_mktable_37(smbios_test_table_t *); 98 extern boolean_t smbios_test_memdevice_verify_32(smbios_hdl_t *); 99 extern boolean_t smbios_test_memdevice_verify_32_33(smbios_hdl_t *); 100 extern boolean_t smbios_test_memdevice_verify_32_37(smbios_hdl_t *); 101 extern boolean_t smbios_test_memdevice_verify_33(smbios_hdl_t *); 102 extern boolean_t smbios_test_memdevice_verify_33ext(smbios_hdl_t *); 103 extern boolean_t smbios_test_memdevice_verify_37(smbios_hdl_t *); 104 105 extern boolean_t smbios_test_pinfo_mktable_amd64(smbios_test_table_t *); 106 extern boolean_t smbios_test_pinfo_verify_amd64(smbios_hdl_t *); 107 extern boolean_t smbios_test_pinfo_mktable_riscv(smbios_test_table_t *); 108 extern boolean_t smbios_test_pinfo_verify_riscv(smbios_hdl_t *); 109 extern boolean_t smbios_test_pinfo_mktable_invlen1(smbios_test_table_t *); 110 extern boolean_t smbios_test_pinfo_mktable_invlen2(smbios_test_table_t *); 111 extern boolean_t smbios_test_pinfo_mktable_invlen3(smbios_test_table_t *); 112 extern boolean_t smbios_test_pinfo_mktable_invlen4(smbios_test_table_t *); 113 extern boolean_t smbios_test_pinfo_verify_invlen1(smbios_hdl_t *); 114 extern boolean_t smbios_test_pinfo_verify_invlen2(smbios_hdl_t *); 115 extern boolean_t smbios_test_pinfo_verify_invlen3(smbios_hdl_t *); 116 extern boolean_t smbios_test_pinfo_verify_invlen4(smbios_hdl_t *); 117 extern boolean_t smbios_test_pinfo_verify_badtype(smbios_hdl_t *); 118 119 extern boolean_t smbios_test_strprop_mktable_invlen1(smbios_test_table_t *); 120 extern boolean_t smbios_test_strprop_mktable_invlen2(smbios_test_table_t *); 121 extern boolean_t smbios_test_strprop_mktable_badstr(smbios_test_table_t *); 122 extern boolean_t smbios_test_strprop_mktable_basic(smbios_test_table_t *); 123 extern boolean_t smbios_test_strprop_verify_invlen1(smbios_hdl_t *); 124 extern boolean_t smbios_test_strprop_verify_invlen2(smbios_hdl_t *); 125 extern boolean_t smbios_test_strprop_verify_badstr(smbios_hdl_t *); 126 extern boolean_t smbios_test_strprop_verify_badtype(smbios_hdl_t *); 127 extern boolean_t smbios_test_strprop_verify_basic(smbios_hdl_t *); 128 129 extern boolean_t smbios_test_fwinfo_mktable_invlen_base(smbios_test_table_t *); 130 extern boolean_t smbios_test_fwinfo_mktable_invlen_comps(smbios_test_table_t *); 131 extern boolean_t smbios_test_fwinfo_mktable_nocomps(smbios_test_table_t *); 132 extern boolean_t smbios_test_fwinfo_mktable_comps(smbios_test_table_t *); 133 extern boolean_t smbios_test_fwinfo_verify_invlen_base(smbios_hdl_t *); 134 extern boolean_t smbios_test_fwinfo_verify_invlen_comps(smbios_hdl_t *); 135 extern boolean_t smbios_test_fwinfo_verify_badtype(smbios_hdl_t *); 136 extern boolean_t smbios_test_fwinfo_verify_nocomps(smbios_hdl_t *); 137 extern boolean_t smbios_test_fwinfo_verify_comps(smbios_hdl_t *); 138 139 extern boolean_t smbios_test_verify_strings(smbios_hdl_t *); 140 141 extern boolean_t smbios_test_chassis_mktable_invlen_base(smbios_test_table_t *); 142 extern boolean_t smbios_test_chassis_mktable_base(smbios_test_table_t *); 143 extern boolean_t smbios_test_chassis_mktable_part(smbios_test_table_t *); 144 extern boolean_t smbios_test_chassis_mktable_comps(smbios_test_table_t *); 145 extern boolean_t smbios_test_chassis_mktable_sku(smbios_test_table_t *); 146 extern boolean_t smbios_test_chassis_mktable_sku_nocomps(smbios_test_table_t *); 147 extern boolean_t smbios_test_chassis_verify_invlen(smbios_hdl_t *); 148 extern boolean_t smbios_test_chassis_verify_base(smbios_hdl_t *); 149 extern boolean_t smbios_test_chassis_verify_comps(smbios_hdl_t *); 150 extern boolean_t smbios_test_chassis_verify_sku_nocomps(smbios_hdl_t *); 151 extern boolean_t smbios_test_chassis_verify_sku(smbios_hdl_t *); 152 153 extern boolean_t smbios_test_proc_mktable_25(smbios_test_table_t *); 154 extern boolean_t smbios_test_proc_mktable_36(smbios_test_table_t *); 155 extern boolean_t smbios_test_proc_mktable_38(smbios_test_table_t *); 156 extern boolean_t smbios_test_proc_verify_25(smbios_hdl_t *); 157 extern boolean_t smbios_test_proc_verify_36(smbios_hdl_t *); 158 extern boolean_t smbios_test_proc_verify_36_25(smbios_hdl_t *); 159 extern boolean_t smbios_test_proc_verify_38(smbios_hdl_t *); 160 161 extern boolean_t smbios_test_extmem_mktable_invlen_cs(smbios_test_table_t *); 162 extern boolean_t smbios_test_extmem_mktable_nocs(smbios_test_table_t *); 163 extern boolean_t smbios_test_extmem_mktable_cs(smbios_test_table_t *); 164 extern boolean_t smbios_test_extmem_verify_invlen_cs(smbios_hdl_t *); 165 extern boolean_t smbios_test_extmem_verify_nocs(smbios_hdl_t *); 166 extern boolean_t smbios_test_extmem_verify_cs(smbios_hdl_t *); 167 168 extern boolean_t smbios_test_addinfo_mktable_noent(smbios_test_table_t *); 169 extern boolean_t smbios_test_addinfo_mktable_ents(smbios_test_table_t *); 170 extern boolean_t smbios_test_addinfo_mktable_invlen_base(smbios_test_table_t *); 171 extern boolean_t smbios_test_addinfo_mktable_invlen_ent(smbios_test_table_t *); 172 extern boolean_t smbios_test_addinfo_mktable_invlen_multient( 173 smbios_test_table_t *); 174 extern boolean_t smbios_test_addinfo_mktable_invlen_entdata( 175 smbios_test_table_t *); 176 extern boolean_t smbios_test_addinfo_verify_noent(smbios_hdl_t *); 177 extern boolean_t smbios_test_addinfo_verify_ents(smbios_hdl_t *); 178 extern boolean_t smbios_test_addinfo_verify_invlen_base(smbios_hdl_t *); 179 extern boolean_t smbios_test_addinfo_verify_invlen_ent(smbios_hdl_t *); 180 extern boolean_t smbios_test_addinfo_verify_invlen_multient(smbios_hdl_t *); 181 extern boolean_t smbios_test_addinfo_verify_invlen_entdata(smbios_hdl_t *); 182 183 #ifdef __cplusplus 184 } 185 #endif 186 187 #endif /* _SMBIOS_TEST_H */ 188