diff options
Diffstat (limited to 'usr/src/test/util-tests/tests/smbios/smbios.c')
| -rw-r--r-- | usr/src/test/util-tests/tests/smbios/smbios.c | 376 |
1 files changed, 178 insertions, 198 deletions
diff --git a/usr/src/test/util-tests/tests/smbios/smbios.c b/usr/src/test/util-tests/tests/smbios/smbios.c index 96b887c3cc..364cb9344f 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios.c +++ b/usr/src/test/util-tests/tests/smbios/smbios.c @@ -19,33 +19,8 @@ * This should be evolved into a much fuller test suite. */ -#include <smbios.h> #include <umem.h> -#include <stdint.h> -#include <endian.h> -#include <stdio.h> -#include <err.h> - -#include <sys/smbios.h> -#include <sys/smbios_impl.h> - -static const char *smbios_test_name = "The One Slot"; - -/* - * Number of bytes we allocate at a given time for an SMBIOS table. - */ -#define SMBIOS_TEST_ALLOC_SIZE 1024 - -typedef struct smbios_test_table { - smbios_entry_point_t stt_type; - void *stt_data; - size_t stt_buflen; - size_t stt_offset; - uint_t stt_nents; - uint_t stt_version; - uint_t stt_nextid; - smbios_entry_t stt_entry; -} smbios_test_table_t; +#include "smbios_test.h" const char * _umem_debug_init(void) @@ -59,7 +34,7 @@ _umem_logging_init(void) return ("fail,contents"); } -static smbios_test_table_t * +smbios_test_table_t * smbios_test_table_init(smbios_entry_point_t type, uint_t version) { smbios_test_table_t *table; @@ -122,21 +97,21 @@ smbios_test_table_append_common(smbios_test_table_t *table, const void *buf, return (start); } -static void +void smbios_test_table_append_raw(smbios_test_table_t *table, const void *buf, size_t len) { (void) smbios_test_table_append_common(table, buf, len); } -static void +void smbios_test_table_append_string(smbios_test_table_t *table, const char *str) { size_t len = strlen(str) + 1; (void) smbios_test_table_append_common(table, str, len); } -static uint16_t +uint16_t smbios_test_table_append(smbios_test_table_t *table, const void *buf, size_t len) { @@ -153,6 +128,25 @@ smbios_test_table_append(smbios_test_table_t *table, const void *buf, return (id); } +void +smbios_test_table_append_eot(smbios_test_table_t *table) +{ + smb_header_t eot; + uint8_t endstring = 0; + + bzero(&eot, sizeof (eot)); + eot.smbh_type = SMB_TYPE_EOT; + eot.smbh_len = 4; + (void) smbios_test_table_append(table, &eot, sizeof (eot)); + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + +} + static uint8_t smbios_test_table_checksum(const uint8_t *buf, size_t len) { @@ -217,195 +211,181 @@ smbios_test_table_fini(smbios_test_table_t *table) umem_free(table, sizeof (smbios_test_table_t)); } -static void -smbios_test_mktable(smbios_test_table_t *table) +static const smbios_test_t smbios_tests[] = { + { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_32, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_slot_mktable, + .st_canopen = B_TRUE, + .st_verify = smbios_test_slot_verify, + .st_desc = "slot tests" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION, + .st_libvers = 0xffff, + .st_mktable = smbios_test_badvers_mktable, + .st_desc = "bad library version" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_32, + .st_libvers = SMB_VERSION_32, + .st_mktable = smbios_test_memdevice_mktable_32, + .st_canopen = B_TRUE, + .st_verify = smbios_test_memdevice_verify_32, + .st_desc = "memory device 3.2 / 3.2" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_32, + .st_libvers = SMB_VERSION_33, + .st_mktable = smbios_test_memdevice_mktable_32, + .st_canopen = B_TRUE, + .st_verify = smbios_test_memdevice_verify_32_33, + .st_desc = "memory device 3.2 / 3.3" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_33, + .st_libvers = SMB_VERSION_33, + .st_mktable = smbios_test_memdevice_mktable_33, + .st_canopen = B_TRUE, + .st_verify = smbios_test_memdevice_verify_33, + .st_desc = "memory device 3.3" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_33, + .st_libvers = SMB_VERSION_33, + .st_mktable = smbios_test_memdevice_mktable_33ext, + .st_canopen = B_TRUE, + .st_verify = smbios_test_memdevice_verify_33ext, + .st_desc = "memory device 3.3" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_pinfo_mktable_amd64, + .st_canopen = B_TRUE, + .st_verify = smbios_test_pinfo_verify_amd64, + .st_desc = "processor additional information - amd64" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_pinfo_mktable_riscv, + .st_canopen = B_TRUE, + .st_verify = smbios_test_pinfo_verify_riscv, + .st_desc = "processor additional information - riscv" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_pinfo_mktable_invlen1, + .st_canopen = B_TRUE, + .st_verify = smbios_test_pinfo_verify_invlen1, + .st_desc = "processor additional information - bad table length 1" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_pinfo_mktable_invlen2, + .st_canopen = B_TRUE, + .st_verify = smbios_test_pinfo_verify_invlen2, + .st_desc = "processor additional information - bad table length 2" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_pinfo_mktable_invlen3, + .st_canopen = B_TRUE, + .st_verify = smbios_test_pinfo_verify_invlen3, + .st_desc = "processor additional information - bad table length 3" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_pinfo_mktable_invlen4, + .st_canopen = B_TRUE, + .st_verify = smbios_test_pinfo_verify_invlen4, + .st_desc = "processor additional information - bad table length 4" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_memdevice_mktable_32, + .st_canopen = B_TRUE, + .st_verify = smbios_test_pinfo_verify_badtype, + .st_desc = "processor additional information - bad type" + }, + +}; + +static boolean_t +smbios_test_run_one(const smbios_test_t *test) { - smb_slot_t slot; - smb_slot_peer_t peers[2]; - smb_header_t eot; - uint8_t endstring = 0; - - slot.smbsl_hdr.smbh_type = SMB_TYPE_SLOT; - slot.smbsl_hdr.smbh_len = sizeof (smb_slot_t) + sizeof (peers); - - slot.smbsl_name = 1; - slot.smbsl_type = SMB_SLT_PCIE3G16; - slot.smbsl_width = SMB_SLW_16X; - slot.smbsl_length = SMB_SLL_SHORT; - slot.smbsl_id = htole16(1); - slot.smbsl_ch1 = SMB_SLCH1_33V; - slot.smbsl_ch2 = SMB_SLCH2_PME; - slot.smbsl_sg = htole16(1); - slot.smbsl_bus = 0x42; - slot.smbsl_df = 0x23; - slot.smbsl_dbw = SMB_SLW_16X; - slot.smbsl_npeers = 2; - peers[0].smbspb_group_no = htole16(1); - peers[0].smbspb_bus = 0x42; - peers[0].smbspb_df = 0x42; - peers[0].smbspb_width = SMB_SLW_8X; - - peers[1].smbspb_group_no = htole16(1); - peers[1].smbspb_bus = 0x23; - peers[1].smbspb_df = 0x31; - peers[1].smbspb_width = SMB_SLW_8X; - - (void) smbios_test_table_append(table, &slot, sizeof (slot)); - (void) smbios_test_table_append_raw(table, peers, sizeof (peers)); - (void) smbios_test_table_append_string(table, smbios_test_name); - (void) smbios_test_table_append_raw(table, &endstring, - sizeof (endstring)); - - bzero(&eot, sizeof (eot)); - eot.smbh_type = SMB_TYPE_EOT; - eot.smbh_len = 4; - (void) smbios_test_table_append(table, &eot, sizeof (eot)); - (void) smbios_test_table_append_raw(table, &endstring, - sizeof (endstring)); - (void) smbios_test_table_append_raw(table, &endstring, - sizeof (endstring)); -} - -static void -smbios_test_verify_table(smbios_hdl_t *hdl) -{ - smbios_struct_t sp; - smbios_slot_t slot; - uint_t npeers; - smbios_slot_peer_t *peers; - uint_t errs = 0; - - if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) { - errx(EXIT_FAILURE, "failed to lookup SMBIOS slot: %s", - smbios_errmsg(smbios_errno(hdl))); - } - - if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) { - errx(EXIT_FAILURE, "failed to get SMBIOS slot info: %s", - smbios_errmsg(smbios_errno(hdl))); - } - - /* - * Verify everything we'd expect about the slot. - */ - if (strcmp(slot.smbl_name, smbios_test_name) != 0) { - warnx("slot name mismatch, expected %s, found %s", - smbios_test_name, slot.smbl_name); - errs++; - } - - if (slot.smbl_type != SMB_SLT_PCIE3G16) { - warnx("incorrect slot type, found %u", slot.smbl_type); - errs++; - } - - if (slot.smbl_width != SMB_SLW_16X) { - warnx("incorrect slot width, found %u", slot.smbl_width); - errs++; - } - - if (slot.smbl_length != SMB_SLL_SHORT) { - warnx("incorrect slot length, found %u", slot.smbl_length); - errs++; - } - - if (slot.smbl_dbw != SMB_SLW_16X) { - warnx("incorrect slot data bus width, found %u", slot.smbl_dbw); - errs++; - } - - if (slot.smbl_npeers != 2) { - warnx("incorrect number of slot peers, found %u", - slot.smbl_npeers); - errs++; - } - - if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) { - errx(EXIT_FAILURE, "failed to get SMBIOS peer info: %s", - smbios_errmsg(smbios_errno(hdl))); - } - - if (npeers != 2) { - errx(EXIT_FAILURE, "got wrong number of slot peers: %u\n", - npeers); - } - - if (peers[0].smblp_group != 1) { - warnx("incorrect group for peer 0: %u", peers[0].smblp_group); - errs++; - } - - if (peers[0].smblp_data_width != SMB_SLW_8X) { - warnx("incorrect data width for peer 0: %u", - peers[0].smblp_data_width); - errs++; - } + smbios_test_table_t *table = NULL; + smbios_hdl_t *hdl = NULL; + void *buf; + size_t len; + smbios_entry_t *entry; + int err = 0; + boolean_t ret = B_FALSE; - if (peers[0].smblp_device != (0x42 >> 3)) { - warnx("incorrect PCI device for peer 0: %u", - peers[0].smblp_device); - errs++; + table = smbios_test_table_init(test->st_entry, test->st_tvers); + if (!test->st_mktable(table)) { + goto out; } - if (peers[0].smblp_function != (0x42 & 0x7)) { - warnx("incorrect PCI function for peer 0: %u", - peers[0].smblp_function); - errs++; + smbios_test_table_snapshot(table, &entry, &buf, &len); + hdl = smbios_bufopen(entry, buf, len, test->st_libvers, SMB_FL_DEBUG, + &err); + if (test->st_canopen) { + if (hdl == NULL) { + warnx("failed to create table for test %s: %s", + test->st_desc, smbios_errmsg(err)); + goto out; + } + } else { + if (hdl != NULL) { + warnx("accidentally created table for test %s, " + "expected failure", test->st_desc); + } else { + ret = B_TRUE; + } + goto out; } - if (peers[1].smblp_group != 1) { - warnx("incorrect group for peer 1: %u", peers[1].smblp_group); - errs++; + if (test->st_verify(hdl)) { + ret = B_TRUE; } - if (peers[1].smblp_device != (0x31 >> 3)) { - warnx("incorrect PCI device for peer 1: %u", - peers[1].smblp_device); - errs++; +out: + if (hdl != NULL) { + smbios_close(hdl); } - if (peers[1].smblp_function != (0x31 & 0x7)) { - warnx("incorrect PCI function for peer 1: %u", - peers[1].smblp_function); - errs++; + if (table != NULL) { + smbios_test_table_fini(table); } - if (peers[1].smblp_data_width != SMB_SLW_8X) { - warnx("incorrect data width for peer 1: %u", - peers[1].smblp_data_width); - errs++; + if (ret) { + (void) printf("TEST PASSED: %s\n", test->st_desc); + } else { + (void) printf("TEST FAILED: %s\n", test->st_desc); } - smbios_info_slot_peers_free(hdl, npeers, peers); - - if (errs > 0) { - errx(EXIT_FAILURE, "encountered fatal errors"); - } + return (ret); } int main(void) { - void *buf; - size_t len; - smbios_test_table_t *table; - smbios_entry_t *entry; - smbios_hdl_t *hdl; int err = 0; + size_t i; - table = smbios_test_table_init(SMBIOS_ENTRY_POINT_30, SMB_VERSION_32); - smbios_test_mktable(table); - smbios_test_table_snapshot(table, &entry, &buf, &len); - - hdl = smbios_bufopen(entry, buf, len, SMB_VERSION_32, SMB_FL_DEBUG, - &err); - if (hdl == NULL) { - errx(EXIT_FAILURE, "failed to create fake smbios table: %s", - smbios_errmsg(err)); + for (i = 0; i < ARRAY_SIZE(smbios_tests); i++) { + if (!smbios_test_run_one(&smbios_tests[i])) { + err = 1; + } } - smbios_test_verify_table(hdl); - smbios_close(hdl); - smbios_test_table_fini(table); - return (0); + return (err); } |
