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 2021 Oxide Computer Company
15  */
16 
17 /*
18  * Collection of functions to be used with tests that will cause a handle to
19  * fail to open.
20  */
21 
22 #include "smbios_test.h"
23 
24 boolean_t
smbios_test_badvers_mktable(smbios_test_table_t * table)25 smbios_test_badvers_mktable(smbios_test_table_t *table)
26 {
27 	smbios_test_table_append_eot(table);
28 	return (B_TRUE);
29 }
30 
31 typedef int (*smbios_lookup_f)(smbios_hdl_t *, id_t, void *);
32 typedef struct {
33 	smbios_lookup_f sif_func;
34 	const char *sif_name;
35 } smbios_info_func_t;
36 
37 static smbios_info_func_t smbios_lookup_funcs[] = {
38 	{ (smbios_lookup_f)smbios_info_bboard, "bboard" },
39 	{ (smbios_lookup_f)smbios_info_chassis, "chassis" },
40 	{ (smbios_lookup_f)smbios_info_processor, "processor" },
41 	{ (smbios_lookup_f)smbios_info_extprocessor, "extprocessor" },
42 	{ (smbios_lookup_f)smbios_info_cache, "cache" },
43 	{ (smbios_lookup_f)smbios_info_pointdev, "pointdev" },
44 	{ (smbios_lookup_f)smbios_info_battery, "battery" },
45 	{ (smbios_lookup_f)smbios_info_port, "port" },
46 	{ (smbios_lookup_f)smbios_info_extport, "extport" },
47 	{ (smbios_lookup_f)smbios_info_slot, "slot" },
48 	{ (smbios_lookup_f)smbios_info_obdevs_ext, "obdevs_ext" },
49 	{ (smbios_lookup_f)smbios_info_memarray, "memarray" },
50 	{ (smbios_lookup_f)smbios_info_extmemarray, "extmemarray" },
51 	{ (smbios_lookup_f)smbios_info_memarrmap, "memarrmap" },
52 	{ (smbios_lookup_f)smbios_info_memdevice, "memdevice" },
53 	{ (smbios_lookup_f)smbios_info_memdevmap, "memdevmap" },
54 	{ (smbios_lookup_f)smbios_info_vprobe, "vprobe" },
55 	{ (smbios_lookup_f)smbios_info_cooldev, "cooldev" },
56 	{ (smbios_lookup_f)smbios_info_tprobe, "tprobe" },
57 	{ (smbios_lookup_f)smbios_info_iprobe, "iprobe" },
58 	{ (smbios_lookup_f)smbios_info_powersup, "powersup" },
59 	{ (smbios_lookup_f)smbios_info_pciexrc, "pciexrc" },
60 	{ (smbios_lookup_f)smbios_info_processor_info, "processor_info" },
61 	{ (smbios_lookup_f)smbios_info_processor_riscv, "processor_riscv" },
62 	{ (smbios_lookup_f)smbios_info_strprop, "strprop" },
63 	{ (smbios_lookup_f)smbios_info_fwinfo, "fwinfo" }
64 };
65 
66 /*
67  * Go through and verify that if we give an explicit lookup a bad id, it
68  * properly detects that and errors. We simply use SMB_ID_NOTSUP, which should
69  * always trigger the internal lookup to fail. In addition, we always pass NULL
70  * for the actual data pointer to make sure that if we get further, we'll crash
71  * on writing to a NULL pointer.
72  */
73 boolean_t
smbios_test_verify_badids(smbios_hdl_t * hdl)74 smbios_test_verify_badids(smbios_hdl_t *hdl)
75 {
76 	boolean_t ret = B_TRUE;
77 
78 	for (size_t i = 0; i < ARRAY_SIZE(smbios_lookup_funcs); i++) {
79 		if (smbios_lookup_funcs[i].sif_func(hdl, SMB_ID_NOTSUP, NULL) !=
80 		    -1) {
81 			warnx("smbios_info_%s somehow didn't fail?!",
82 			    smbios_lookup_funcs[i].sif_name);
83 			ret = B_FALSE;
84 		}
85 	}
86 
87 	return (ret);
88 }
89