xref: /illumos-gate/usr/src/test/util-tests/tests/smbios/smbios_test_errors.c (revision 064d431af1a50617e489660828115f60b99c5c75)
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 /*
17  * Collection of functions to be used with tests that will cause a handle to
18  * fail to open.
19  */
20 
21 #include "smbios_test.h"
22 
23 boolean_t
smbios_test_badvers_mktable(smbios_test_table_t * table)24 smbios_test_badvers_mktable(smbios_test_table_t *table)
25 {
26 	smbios_test_table_append_eot(table);
27 	return (B_TRUE);
28 }
29 
30 typedef int (*smbios_lookup_f)(smbios_hdl_t *, id_t, void *);
31 typedef struct {
32 	smbios_lookup_f sif_func;
33 	const char *sif_name;
34 } smbios_info_func_t;
35 
36 static smbios_info_func_t smbios_lookup_funcs[] = {
37 	{ (smbios_lookup_f)smbios_info_bboard, "bboard" },
38 	{ (smbios_lookup_f)smbios_info_chassis, "chassis" },
39 	{ (smbios_lookup_f)smbios_info_processor, "processor" },
40 	{ (smbios_lookup_f)smbios_info_extprocessor, "extprocessor" },
41 	{ (smbios_lookup_f)smbios_info_cache, "cache" },
42 	{ (smbios_lookup_f)smbios_info_pointdev, "pointdev" },
43 	{ (smbios_lookup_f)smbios_info_battery, "battery" },
44 	{ (smbios_lookup_f)smbios_info_port, "port" },
45 	{ (smbios_lookup_f)smbios_info_extport, "extport" },
46 	{ (smbios_lookup_f)smbios_info_slot, "slot" },
47 	{ (smbios_lookup_f)smbios_info_obdevs_ext, "obdevs_ext" },
48 	{ (smbios_lookup_f)smbios_info_memarray, "memarray" },
49 	{ (smbios_lookup_f)smbios_info_extmemarray, "extmemarray" },
50 	{ (smbios_lookup_f)smbios_info_memarrmap, "memarrmap" },
51 	{ (smbios_lookup_f)smbios_info_memdevice, "memdevice" },
52 	{ (smbios_lookup_f)smbios_info_memdevmap, "memdevmap" },
53 	{ (smbios_lookup_f)smbios_info_vprobe, "vprobe" },
54 	{ (smbios_lookup_f)smbios_info_cooldev, "cooldev" },
55 	{ (smbios_lookup_f)smbios_info_tprobe, "tprobe" },
56 	{ (smbios_lookup_f)smbios_info_iprobe, "iprobe" },
57 	{ (smbios_lookup_f)smbios_info_powersup, "powersup" },
58 	{ (smbios_lookup_f)smbios_info_addinfo_nents, "addinfo" },
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