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 2022 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 void smbios_test_table_str_fini(smbios_test_table_t *); 62 extern uint16_t smbios_test_table_append(smbios_test_table_t *, const void *, 63 size_t); 64 extern void smbios_test_table_append_eot(smbios_test_table_t *); 65 66 typedef boolean_t (*smbios_test_mktable_f)(smbios_test_table_t *); 67 typedef boolean_t (*smbios_test_verify_f)(smbios_hdl_t *); 68 69 typedef struct smbios_test { 70 int st_entry; 71 int st_tvers; 72 int st_libvers; 73 smbios_test_mktable_f st_mktable; 74 boolean_t st_canopen; 75 smbios_test_verify_f st_verify; 76 const char *st_desc; 77 } smbios_test_t; 78 79 /* 80 * Test functions 81 */ 82 extern boolean_t smbios_test_slot_mktable(smbios_test_table_t *); 83 extern boolean_t smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *); 84 extern boolean_t smbios_test_slot_mktable_34_peers(smbios_test_table_t *); 85 extern boolean_t smbios_test_slot_mktable_35(smbios_test_table_t *); 86 extern boolean_t smbios_test_slot_verify(smbios_hdl_t *); 87 extern boolean_t smbios_test_slot_verify_34_nopeers(smbios_hdl_t *); 88 extern boolean_t smbios_test_slot_verify_34_peers(smbios_hdl_t *); 89 extern boolean_t smbios_test_slot_verify_34_overrun(smbios_hdl_t *); 90 extern boolean_t smbios_test_slot_verify_35(smbios_hdl_t *); 91 92 extern boolean_t smbios_test_badvers_mktable(smbios_test_table_t *); 93 extern boolean_t smbios_test_verify_badids(smbios_hdl_t *); 94 95 extern boolean_t smbios_test_memdevice_mktable_32(smbios_test_table_t *); 96 extern boolean_t smbios_test_memdevice_mktable_33(smbios_test_table_t *); 97 extern boolean_t smbios_test_memdevice_mktable_33ext(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_33(smbios_hdl_t *); 101 extern boolean_t smbios_test_memdevice_verify_33ext(smbios_hdl_t *); 102 103 extern boolean_t smbios_test_pinfo_mktable_amd64(smbios_test_table_t *); 104 extern boolean_t smbios_test_pinfo_verify_amd64(smbios_hdl_t *); 105 extern boolean_t smbios_test_pinfo_mktable_riscv(smbios_test_table_t *); 106 extern boolean_t smbios_test_pinfo_verify_riscv(smbios_hdl_t *); 107 extern boolean_t smbios_test_pinfo_mktable_invlen1(smbios_test_table_t *); 108 extern boolean_t smbios_test_pinfo_mktable_invlen2(smbios_test_table_t *); 109 extern boolean_t smbios_test_pinfo_mktable_invlen3(smbios_test_table_t *); 110 extern boolean_t smbios_test_pinfo_mktable_invlen4(smbios_test_table_t *); 111 extern boolean_t smbios_test_pinfo_verify_invlen1(smbios_hdl_t *); 112 extern boolean_t smbios_test_pinfo_verify_invlen2(smbios_hdl_t *); 113 extern boolean_t smbios_test_pinfo_verify_invlen3(smbios_hdl_t *); 114 extern boolean_t smbios_test_pinfo_verify_invlen4(smbios_hdl_t *); 115 extern boolean_t smbios_test_pinfo_verify_badtype(smbios_hdl_t *); 116 117 extern boolean_t smbios_test_strprop_mktable_invlen1(smbios_test_table_t *); 118 extern boolean_t smbios_test_strprop_mktable_invlen2(smbios_test_table_t *); 119 extern boolean_t smbios_test_strprop_mktable_badstr(smbios_test_table_t *); 120 extern boolean_t smbios_test_strprop_mktable_basic(smbios_test_table_t *); 121 extern boolean_t smbios_test_strprop_verify_invlen1(smbios_hdl_t *); 122 extern boolean_t smbios_test_strprop_verify_invlen2(smbios_hdl_t *); 123 extern boolean_t smbios_test_strprop_verify_badstr(smbios_hdl_t *); 124 extern boolean_t smbios_test_strprop_verify_badtype(smbios_hdl_t *); 125 extern boolean_t smbios_test_strprop_verify_basic(smbios_hdl_t *); 126 127 extern boolean_t smbios_test_fwinfo_mktable_invlen_base(smbios_test_table_t *); 128 extern boolean_t smbios_test_fwinfo_mktable_invlen_comps(smbios_test_table_t *); 129 extern boolean_t smbios_test_fwinfo_mktable_nocomps(smbios_test_table_t *); 130 extern boolean_t smbios_test_fwinfo_mktable_comps(smbios_test_table_t *); 131 extern boolean_t smbios_test_fwinfo_verify_invlen_base(smbios_hdl_t *); 132 extern boolean_t smbios_test_fwinfo_verify_invlen_comps(smbios_hdl_t *); 133 extern boolean_t smbios_test_fwinfo_verify_badtype(smbios_hdl_t *); 134 extern boolean_t smbios_test_fwinfo_verify_nocomps(smbios_hdl_t *); 135 extern boolean_t smbios_test_fwinfo_verify_comps(smbios_hdl_t *); 136 137 extern boolean_t smbios_test_verify_strings(smbios_hdl_t *); 138 139 extern boolean_t smbios_test_chassis_mktable_invlen_base(smbios_test_table_t *); 140 extern boolean_t smbios_test_chassis_mktable_base(smbios_test_table_t *); 141 extern boolean_t smbios_test_chassis_mktable_comps(smbios_test_table_t *); 142 extern boolean_t smbios_test_chassis_mktable_sku(smbios_test_table_t *); 143 extern boolean_t smbios_test_chassis_mktable_sku_nocomps(smbios_test_table_t *); 144 extern boolean_t smbios_test_chassis_verify_invlen(smbios_hdl_t *); 145 extern boolean_t smbios_test_chassis_verify_base(smbios_hdl_t *); 146 extern boolean_t smbios_test_chassis_verify_comps(smbios_hdl_t *); 147 extern boolean_t smbios_test_chassis_verify_sku_nocomps(smbios_hdl_t *); 148 extern boolean_t smbios_test_chassis_verify_sku(smbios_hdl_t *); 149 150 151 extern boolean_t smbios_test_proc_mktable_25(smbios_test_table_t *); 152 extern boolean_t smbios_test_proc_mktable_36(smbios_test_table_t *); 153 extern boolean_t smbios_test_proc_verify_25(smbios_hdl_t *); 154 extern boolean_t smbios_test_proc_verify_36(smbios_hdl_t *); 155 extern boolean_t smbios_test_proc_verify_36_25(smbios_hdl_t *); 156 157 #ifdef __cplusplus 158 } 159 #endif 160 161 #endif /* _SMBIOS_TEST_H */ 162