summaryrefslogtreecommitdiff
path: root/usr/src/test/util-tests/tests/smbios/smbios_test_strprop.c
blob: 20d0928ebb147c1a7fa253b941786df385a10666 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
 * 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 2021 Oxide Computer Company
 */

/*
 * Tests for SMBIOS type 46 - SMB_TYPE_STRPROP.
 */

#include "smbios_test.h"

static const char *smbios_strprop_path = "/not/really/uefi";
static uint16_t smbios_strprop_hdl = 0xcafe;

boolean_t
smbios_test_strprop_mktable_basic(smbios_test_table_t *table)
{
	smb_strprop_t str;

	str.smbstrp_hdr.smbh_type = SMB_TYPE_STRPROP;
	str.smbstrp_hdr.smbh_len = sizeof (str);
	str.smbstrp_prop_id = htole16(SMB_STRP_UEFI_DEVPATH);
	str.smbstrp_prop_val = 1;
	str.smbstrp_phdl = htole16(smbios_strprop_hdl);

	(void) smbios_test_table_append(table, &str, sizeof (str));
	smbios_test_table_append_string(table, smbios_strprop_path);
	smbios_test_table_str_fini(table);
	smbios_test_table_append_eot(table);

	return (B_TRUE);
}

boolean_t
smbios_test_strprop_mktable_badstr(smbios_test_table_t *table)
{
	smb_strprop_t str;

	str.smbstrp_hdr.smbh_type = SMB_TYPE_STRPROP;
	str.smbstrp_hdr.smbh_len = sizeof (str);
	str.smbstrp_prop_id = htole16(SMB_STRP_UEFI_DEVPATH);
	str.smbstrp_prop_val = 0x23;
	str.smbstrp_phdl = htole16(smbios_strprop_hdl);

	(void) smbios_test_table_append(table, &str, sizeof (str));
	smbios_test_table_append_string(table, smbios_strprop_path);
	smbios_test_table_str_fini(table);
	smbios_test_table_append_eot(table);

	return (B_TRUE);
}

boolean_t
smbios_test_strprop_mktable_invlen1(smbios_test_table_t *table)
{
	smb_header_t hdr;

	hdr.smbh_type = SMB_TYPE_STRPROP;
	hdr.smbh_len = sizeof (hdr);

	(void) smbios_test_table_append(table, &hdr, sizeof (hdr));
	smbios_test_table_append_eot(table);

	return (B_TRUE);
}

boolean_t
smbios_test_strprop_mktable_invlen2(smbios_test_table_t *table)
{
	smb_strprop_t str;
	const uint8_t endstring = 0;

	str.smbstrp_hdr.smbh_type = SMB_TYPE_STRPROP;
	str.smbstrp_hdr.smbh_len = sizeof (str) + 1;
	str.smbstrp_prop_id = htole16(0);
	str.smbstrp_prop_val = 0;
	str.smbstrp_phdl = htole16(0);

	/*
	 * Append the end string again as to get us to our additional byte of
	 * actual table length.
	 */
	(void) smbios_test_table_append(table, &str, sizeof (str));
	(void) smbios_test_table_append_raw(table, &endstring,
	    sizeof (endstring));
	(void) smbios_test_table_append_string(table, smbios_strprop_path);
	(void) smbios_test_table_append_raw(table, &endstring,
	    sizeof (endstring));
	smbios_test_table_append_eot(table);

	return (B_TRUE);
}

static boolean_t
smbios_test_strprop_verify_badtable(smbios_hdl_t *hdl, int smberr)
{
	smbios_struct_t sp;
	smbios_strprop_t prop;

	if (smbios_lookup_type(hdl, SMB_TYPE_STRPROP, &sp) == -1) {
		warnx("failed to lookup SMBIOS strprop: %s",
		    smbios_errmsg(smbios_errno(hdl)));
		return (B_FALSE);
	}

	if (smbios_info_strprop(hdl, sp.smbstr_id, &prop) != -1) {
		warnx("accidentally parsed invalid strprop information as "
		    "valid");
		return (B_FALSE);
	}

	if (smbios_errno(hdl) != smberr) {
		warnx("encountered wrong error for strprop, expected: "
		    "0x%x, found: 0x%x", smberr, smbios_errno(hdl));
		return (B_FALSE);
	}

	return (B_TRUE);
}

boolean_t
smbios_test_strprop_verify_invlen1(smbios_hdl_t *hdl)
{
	return (smbios_test_strprop_verify_badtable(hdl, ESMB_SHORT));
}

boolean_t
smbios_test_strprop_verify_invlen2(smbios_hdl_t *hdl)
{
	return (smbios_test_strprop_verify_badtable(hdl, ESMB_CORRUPT));
}

boolean_t
smbios_test_strprop_verify_badtype(smbios_hdl_t *hdl)
{
	smbios_struct_t sp;
	smbios_strprop_t prop;

	/*
	 * Here we've explicitly created a table with a memory device that we're
	 * going to try and look up as well, not that.
	 */
	if (smbios_lookup_type(hdl, SMB_TYPE_MEMDEVICE, &sp) == -1) {
		warnx("failed to lookup SMBIOS memory device: %s",
		    smbios_errmsg(smbios_errno(hdl)));
		return (B_FALSE);
	}

	if (smbios_info_strprop(hdl, sp.smbstr_id, &prop) != -1) {
		warnx("accidentally parsed invalid strprop information as "
		    "valid");
		return (B_FALSE);
	}

	if (smbios_errno(hdl) != ESMB_TYPE) {
		warnx("encountered wrong error for strprop, expected: "
		    "0x%x, found: 0x%x", ESMB_TYPE, smbios_errno(hdl));
		return (B_FALSE);
	}

	return (B_TRUE);

}

boolean_t
smbios_test_strprop_verify_basic(smbios_hdl_t *hdl)
{
	smbios_struct_t sp;
	smbios_strprop_t prop;
	boolean_t ret = B_TRUE;

	if (smbios_lookup_type(hdl, SMB_TYPE_STRPROP, &sp) == -1) {
		warnx("failed to lookup SMBIOS strprop: %s",
		    smbios_errmsg(smbios_errno(hdl)));
		return (B_FALSE);
	}

	if (smbios_info_strprop(hdl, sp.smbstr_id, &prop) != 0) {
		warnx("failed to get SMBIOS strprop: %s",
		    smbios_errmsg(smbios_errno(hdl)));
		return (B_FALSE);
	}

	if (prop.smbsp_prop_id != SMB_STRP_UEFI_DEVPATH) {
		warnx("property id incorrect, expected 0x%x, found 0x %x",
		    SMB_STRP_UEFI_DEVPATH, prop.smbsp_prop_id);
		ret = B_FALSE;
	}

	if (strcmp(smbios_strprop_id_desc(prop.smbsp_prop_id),
	    "UEFI device path") != 0) {
		warnx("property id string incorrect, found %s",
		    smbios_strprop_id_desc(prop.smbsp_prop_id));
		ret = B_FALSE;
	}

	if (strcmp(prop.smbsp_prop_val, smbios_strprop_path) != 0) {
		warnx("property value incorrect, found %s",
		    prop.smbsp_prop_val);
		ret = B_FALSE;
	}

	return (ret);
}

boolean_t
smbios_test_strprop_verify_badstr(smbios_hdl_t *hdl)
{
	smbios_struct_t sp;
	smbios_strprop_t prop;
	boolean_t ret = B_TRUE;

	if (smbios_lookup_type(hdl, SMB_TYPE_STRPROP, &sp) == -1) {
		warnx("failed to lookup SMBIOS strprop: %s",
		    smbios_errmsg(smbios_errno(hdl)));
		return (B_FALSE);
	}

	if (smbios_info_strprop(hdl, sp.smbstr_id, &prop) != 0) {
		warnx("failed to get SMBIOS strprop: %s",
		    smbios_errmsg(smbios_errno(hdl)));
		return (B_FALSE);
	}

	if (prop.smbsp_prop_id != SMB_STRP_UEFI_DEVPATH) {
		warnx("property id incorrect, expected 0x%x, found 0x %x",
		    SMB_STRP_UEFI_DEVPATH, prop.smbsp_prop_id);
		ret = B_FALSE;
	}

	if (strcmp(smbios_strprop_id_desc(prop.smbsp_prop_id),
	    "UEFI device path") != 0) {
		warnx("property id string incorrect, found %s",
		    smbios_strprop_id_desc(prop.smbsp_prop_id));
		ret = B_FALSE;
	}

	if (strcmp(prop.smbsp_prop_val, "") != 0) {
		warnx("property value incorrect, found %s",
		    prop.smbsp_prop_val);
		ret = B_FALSE;
	}

	return (ret);
}