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 2026 Oxide Computer Company
14 */
15
16 /*
17 * Basic tests for SMBIOS System Boot Information, Type 32.
18 */
19
20 #include "smbios_test.h"
21
22 static const char *boot_data = "three rings for elven kings";
23
24 boolean_t
smbios_test_boot_mktable_short_base(smbios_test_table_t * table)25 smbios_test_boot_mktable_short_base(smbios_test_table_t *table)
26 {
27 smb_header_t hdr;
28
29 hdr.smbh_type = SMB_TYPE_BOOT;
30 hdr.smbh_len = sizeof (hdr);
31
32 (void) smbios_test_table_append(table, &hdr, sizeof (hdr));
33 smbios_test_table_append_eot(table);
34 return (B_TRUE);
35 }
36
37 boolean_t
smbios_test_boot_mktable_short_data(smbios_test_table_t * table)38 smbios_test_boot_mktable_short_data(smbios_test_table_t *table)
39 {
40 smb_boot_t boot;
41
42 (void) memset(&boot, 0, sizeof (smb_boot_t));
43 boot.smbbo_hdr.smbh_type = SMB_TYPE_BOOT;
44 boot.smbbo_hdr.smbh_len = sizeof (smb_boot_t) - 1;
45
46 (void) smbios_test_table_append(table, &boot, sizeof (boot) - 1);
47 smbios_test_table_append_eot(table);
48 return (B_TRUE);
49 }
50
51 boolean_t
smbios_test_boot_mktable(smbios_test_table_t * table)52 smbios_test_boot_mktable(smbios_test_table_t *table)
53 {
54 smb_boot_t boot;
55 size_t dlen = strlen(boot_data);
56
57 (void) memset(&boot, 0, sizeof (smb_boot_t));
58 boot.smbbo_hdr.smbh_type = SMB_TYPE_BOOT;
59 boot.smbbo_hdr.smbh_len = sizeof (smb_boot_t) + dlen - 1;
60 boot.smbbo_status[0] = boot_data[0];
61
62 (void) smbios_test_table_append(table, &boot, sizeof (boot));
63 smbios_test_table_append_raw(table, &boot_data[1], dlen - 1);
64 smbios_test_table_append_eot(table);
65 return (B_TRUE);
66 }
67
68 boolean_t
smbios_test_boot_mktable_nodata(smbios_test_table_t * table)69 smbios_test_boot_mktable_nodata(smbios_test_table_t *table)
70 {
71 smb_boot_t boot;
72
73 (void) memset(&boot, 0, sizeof (smb_boot_t));
74 boot.smbbo_hdr.smbh_type = SMB_TYPE_BOOT;
75 boot.smbbo_hdr.smbh_len = sizeof (smb_boot_t);
76 boot.smbbo_status[0] = 0x42;
77
78 (void) smbios_test_table_append(table, &boot, sizeof (boot));
79 smbios_test_table_append_eot(table);
80 return (B_TRUE);
81 }
82
83 boolean_t
smbios_test_boot_verify_short(smbios_hdl_t * hdl)84 smbios_test_boot_verify_short(smbios_hdl_t *hdl)
85 {
86 smbios_boot_t boot;
87
88 if (smbios_info_boot(hdl, &boot) != -1) {
89 warnx("accidentally parsed invalid boot data as valid");
90 return (B_FALSE);
91 }
92
93 if (smbios_errno(hdl) != ESMB_SHORT) {
94 warnx("encountered wrong error for boot, expected: "
95 "0x%x, found: 0x%x", ESMB_SHORT, smbios_errno(hdl));
96 return (B_FALSE);
97 }
98
99 return (B_TRUE);
100 }
101
102 boolean_t
smbios_test_boot_verify(smbios_hdl_t * hdl)103 smbios_test_boot_verify(smbios_hdl_t *hdl)
104 {
105 smbios_boot_t boot;
106 boolean_t ret = B_TRUE;
107
108 if (smbios_info_boot(hdl, &boot) == -1) {
109 warnx("failed to get boot data: %s",
110 smbios_errmsg(smbios_errno(hdl)));
111 return (B_FALSE);
112 }
113
114 if (boot.smbt_status != boot_data[0]) {
115 warnx("found wrong boot status: expected 0x%x, found 0x%x",
116 boot_data[0], boot.smbt_status);
117 ret = B_FALSE;
118 }
119
120 size_t len = strlen(boot_data);
121 if (boot.smbt_size != len - 1) {
122 warnx("found wrong data length: expected %zu, found %zu",
123 len - 1, boot.smbt_size);
124 ret = B_FALSE;
125 } else if (bcmp(boot.smbt_data, &boot_data[1], boot.smbt_size) != 0) {
126 warnx("boot data mismatch encountered");
127 ret = B_FALSE;
128 }
129
130 return (ret);
131 }
132
133 boolean_t
smbios_test_boot_verify_nodata(smbios_hdl_t * hdl)134 smbios_test_boot_verify_nodata(smbios_hdl_t *hdl)
135 {
136 smbios_boot_t boot;
137 boolean_t ret = B_TRUE;
138
139 boot.smbt_data = (void *)(uintptr_t)0x7777;
140 boot.smbt_size = 0x7777;
141
142 if (smbios_info_boot(hdl, &boot) == -1) {
143 warnx("failed to get boot data: %s",
144 smbios_errmsg(smbios_errno(hdl)));
145 return (B_FALSE);
146 }
147
148 if (boot.smbt_status != 0x42) {
149 warnx("found wrong boot status: expected 0x42, found 0x%x",
150 boot.smbt_status);
151 ret = B_FALSE;
152 }
153
154 if (boot.smbt_size != 0) {
155 warnx("found non-zero data size: 0x%zx", boot.smbt_size);
156 ret = B_FALSE;
157 }
158
159 if (boot.smbt_data != NULL) {
160 warnx("found non-NULL data pointer: 0x%p", boot.smbt_data);
161 ret = B_FALSE;
162 }
163
164 return (ret);
165 }
166