summaryrefslogtreecommitdiff
path: root/usr/src/test/util-tests/tests/smbios/smbios_test_errors.c
blob: 5211eebc743ab7a15c1ba77145279d00ab87a820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2019 Robert Mustacchi
 * Copyright 2021 Oxide Computer Company
 */

/*
 * Collection of functions to be used with tests that will cause a handle to
 * fail to open.
 */

#include "smbios_test.h"

boolean_t
smbios_test_badvers_mktable(smbios_test_table_t *table)
{
	smbios_test_table_append_eot(table);
	return (B_TRUE);
}

typedef int (*smbios_lookup_f)(smbios_hdl_t *, id_t, void *);
typedef struct {
	smbios_lookup_f sif_func;
	const char *sif_name;
} smbios_info_func_t;

static smbios_info_func_t smbios_lookup_funcs[] = {
	{ (smbios_lookup_f)smbios_info_bboard, "bboard" },
	{ (smbios_lookup_f)smbios_info_chassis, "chassis" },
	{ (smbios_lookup_f)smbios_info_processor, "processor" },
	{ (smbios_lookup_f)smbios_info_extprocessor, "extprocessor" },
	{ (smbios_lookup_f)smbios_info_cache, "cache" },
	{ (smbios_lookup_f)smbios_info_pointdev, "pointdev" },
	{ (smbios_lookup_f)smbios_info_battery, "battery" },
	{ (smbios_lookup_f)smbios_info_port, "port" },
	{ (smbios_lookup_f)smbios_info_extport, "extport" },
	{ (smbios_lookup_f)smbios_info_slot, "slot" },
	{ (smbios_lookup_f)smbios_info_obdevs_ext, "obdevs_ext" },
	{ (smbios_lookup_f)smbios_info_memarray, "memarray" },
	{ (smbios_lookup_f)smbios_info_extmemarray, "extmemarray" },
	{ (smbios_lookup_f)smbios_info_memarrmap, "memarrmap" },
	{ (smbios_lookup_f)smbios_info_memdevice, "memdevice" },
	{ (smbios_lookup_f)smbios_info_extmemdevice, "extmemdevice" },
	{ (smbios_lookup_f)smbios_info_memdevmap, "memdevmap" },
	{ (smbios_lookup_f)smbios_info_vprobe, "vprobe" },
	{ (smbios_lookup_f)smbios_info_cooldev, "cooldev" },
	{ (smbios_lookup_f)smbios_info_tprobe, "tprobe" },
	{ (smbios_lookup_f)smbios_info_iprobe, "iprobe" },
	{ (smbios_lookup_f)smbios_info_powersup, "powersup" },
	{ (smbios_lookup_f)smbios_info_pciexrc, "pciexrc" },
	{ (smbios_lookup_f)smbios_info_processor_info, "processor_info" },
	{ (smbios_lookup_f)smbios_info_processor_riscv, "processor_riscv" },
	{ (smbios_lookup_f)smbios_info_strprop, "strprop" },
	{ (smbios_lookup_f)smbios_info_fwinfo, "fwinfo" }
};

/*
 * Go through and verify that if we give an explicit lookup a bad id, it
 * properly detects that and errors. We simply use SMB_ID_NOTSUP, which should
 * always trigger the internal lookup to fail. In addition, we always pass NULL
 * for the actual data pointer to make sure that if we get further, we'll crash
 * on writing to a NULL pointer.
 */
boolean_t
smbios_test_verify_badids(smbios_hdl_t *hdl)
{
	boolean_t ret = B_TRUE;

	for (size_t i = 0; i < ARRAY_SIZE(smbios_lookup_funcs); i++) {
		if (smbios_lookup_funcs[i].sif_func(hdl, SMB_ID_NOTSUP, NULL) !=
		    -1) {
			warnx("smbios_info_%s somehow didn't fail?!",
			    smbios_lookup_funcs[i].sif_name);
			ret = B_FALSE;
		}
	}

	return (ret);
}