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 */ 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 uint16_t smbios_test_table_append(smbios_test_table_t *, const void *, 61 size_t); 62 extern void smbios_test_table_append_eot(smbios_test_table_t *); 63 64 typedef boolean_t (*smbios_test_mktable_f)(smbios_test_table_t *); 65 typedef boolean_t (*smbios_test_verify_f)(smbios_hdl_t *); 66 67 typedef struct smbios_test { 68 int st_entry; 69 int st_tvers; 70 int st_libvers; 71 smbios_test_mktable_f st_mktable; 72 boolean_t st_canopen; 73 smbios_test_verify_f st_verify; 74 const char *st_desc; 75 } smbios_test_t; 76 77 /* 78 * Test functions 79 */ 80 extern boolean_t smbios_test_slot_mktable(smbios_test_table_t *); 81 extern boolean_t smbios_test_slot_verify(smbios_hdl_t *); 82 extern boolean_t smbios_test_badvers_mktable(smbios_test_table_t *); 83 84 extern boolean_t smbios_test_memdevice_mktable_32(smbios_test_table_t *); 85 extern boolean_t smbios_test_memdevice_mktable_33(smbios_test_table_t *); 86 extern boolean_t smbios_test_memdevice_mktable_33ext(smbios_test_table_t *); 87 extern boolean_t smbios_test_memdevice_verify_32(smbios_hdl_t *); 88 extern boolean_t smbios_test_memdevice_verify_32_33(smbios_hdl_t *); 89 extern boolean_t smbios_test_memdevice_verify_33(smbios_hdl_t *); 90 extern boolean_t smbios_test_memdevice_verify_33ext(smbios_hdl_t *); 91 92 extern boolean_t smbios_test_pinfo_mktable_amd64(smbios_test_table_t *); 93 extern boolean_t smbios_test_pinfo_verify_amd64(smbios_hdl_t *); 94 extern boolean_t smbios_test_pinfo_mktable_riscv(smbios_test_table_t *); 95 extern boolean_t smbios_test_pinfo_verify_riscv(smbios_hdl_t *); 96 extern boolean_t smbios_test_pinfo_mktable_invlen1(smbios_test_table_t *); 97 extern boolean_t smbios_test_pinfo_mktable_invlen2(smbios_test_table_t *); 98 extern boolean_t smbios_test_pinfo_mktable_invlen3(smbios_test_table_t *); 99 extern boolean_t smbios_test_pinfo_mktable_invlen4(smbios_test_table_t *); 100 extern boolean_t smbios_test_pinfo_verify_invlen1(smbios_hdl_t *); 101 extern boolean_t smbios_test_pinfo_verify_invlen2(smbios_hdl_t *); 102 extern boolean_t smbios_test_pinfo_verify_invlen3(smbios_hdl_t *); 103 extern boolean_t smbios_test_pinfo_verify_invlen4(smbios_hdl_t *); 104 extern boolean_t smbios_test_pinfo_verify_badtype(smbios_hdl_t *); 105 106 #ifdef __cplusplus 107 } 108 #endif 109 110 #endif /* _SMBIOS_TEST_H */ 111