| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "chid.h" |
| 4 |
#include "edid.h" |
| 5 |
#include "efi-string.h" |
| 6 |
#include "smbios.h" |
| 7 |
#include "tests.h" |
| 8 |
|
| 9 |
extern uint8_t hwids_section_data[]; |
| 10 |
extern size_t hwids_section_len; |
| 11 |
|
| 12 |
static struct { |
| 13 |
const RawSmbiosInfo smbios_info; |
| 14 |
const char16_t *panel_id; |
| 15 |
uint32_t device_type; |
| 16 |
} info[] = { |
| 17 |
{ |
| 18 |
.smbios_info = { |
| 19 |
.manufacturer = "First Vendor", |
| 20 |
.product_name = "Device 1", |
| 21 |
.product_sku = "KD01", |
| 22 |
.family = "Laptop X", |
| 23 |
.baseboard_product = "FODM1", |
| 24 |
.baseboard_manufacturer = "First ODM", |
| 25 |
}, |
| 26 |
.panel_id = u"TST42", |
| 27 |
.device_type = DEVICE_TYPE_DEVICETREE, |
| 28 |
}, |
| 29 |
{ |
| 30 |
.smbios_info = { |
| 31 |
.manufacturer = "Second Vendor", |
| 32 |
.product_name = "Device 2", |
| 33 |
.product_sku = "KD02", |
| 34 |
.family = "Laptop 2", |
| 35 |
.baseboard_product = "SODM2", |
| 36 |
.baseboard_manufacturer = "Second ODM", |
| 37 |
}, |
| 38 |
.device_type = DEVICE_TYPE_DEVICETREE, |
| 39 |
}, |
| 40 |
{ |
| 41 |
.smbios_info = { |
| 42 |
.manufacturer = "First Vendor", |
| 43 |
.product_name = "Device 3", |
| 44 |
.product_sku = "KD03", |
| 45 |
.family = "Tablet Y", |
| 46 |
.baseboard_product = "FODM2", |
| 47 |
.baseboard_manufacturer = "First ODM", |
| 48 |
}, |
| 49 |
.device_type = DEVICE_TYPE_DEVICETREE, |
| 50 |
}, |
| 51 |
{ |
| 52 |
.smbios_info = { |
| 53 |
.manufacturer = "VMware, Inc.", |
| 54 |
.product_name = "VMware20,1", |
| 55 |
.product_sku = "0000000000000001", |
| 56 |
.family = "VMware", |
| 57 |
.baseboard_product = "VBSA", |
| 58 |
.baseboard_manufacturer = "VMware, Inc.", |
| 59 |
}, |
| 60 |
.device_type = DEVICE_TYPE_UEFI_FW, |
| 61 |
}, |
| 62 |
}; |
| 63 |
|
| 64 |
static struct { |
| 65 |
const char *name; |
| 66 |
const char *compatible; |
| 67 |
const char *fwid; |
| 68 |
} results[] = { |
| 69 |
{ "Device 1", "test,device-1", NULL }, |
| 70 |
{ "Device 2", "test,device-2", NULL }, |
| 71 |
{ "Device 3", "test,device-3", NULL }, |
| 72 |
{ "Device 4", NULL, "test,vmware" }, |
| 73 |
}; |
| 74 |
|
| 75 |
static RawSmbiosInfo current_info = {}; |
| 76 |
|
| 77 |
/* This is a dummy implementation for testing purposes */ |
| 78 |
void smbios_raw_info_get_cached(RawSmbiosInfo *ret_info) { |
| 79 |
assert(ret_info); |
| 80 |
*ret_info = current_info; |
| 81 |
} |
| 82 |
|
| 83 |
static const char16_t *current_panel = NULL; |
| 84 |
EFI_STATUS edid_get_discovered_panel_id(char16_t **ret_panel) { |
| 85 |
assert(ret_panel); |
| 86 |
|
| 87 |
if (!current_panel) |
| 88 |
return EFI_UNSUPPORTED; |
| 89 |
|
| 90 |
*ret_panel = xstrdup16(current_panel); |
| 91 |
return EFI_SUCCESS; |
| 92 |
} |
| 93 |
|
| 94 |
TEST(chid_match) { |
| 95 |
for (size_t i = 0; i < ELEMENTSOF(info); i++) { |
| 96 |
current_info = info[i].smbios_info; |
| 97 |
current_panel = info[i].panel_id; |
| 98 |
const Device *dev = NULL; |
| 99 |
/* Match and check */ |
| 100 |
ASSERT_EQ(chid_match(hwids_section_data, hwids_section_len, info[i].device_type, &dev), EFI_SUCCESS); |
| 101 |
ASSERT_NOT_NULL(dev); |
| 102 |
ASSERT_EQ(DEVICE_TYPE_FROM_DESCRIPTOR(dev->descriptor), info[i].device_type); |
| 103 |
ASSERT_STREQ(device_get_name(hwids_section_data, dev), results[i].name); |
| 104 |
ASSERT_STREQ(device_get_compatible(hwids_section_data, dev), results[i].compatible); |
| 105 |
ASSERT_STREQ(device_get_fwid(hwids_section_data, dev), results[i].fwid); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
static int intro(void) { |
| 110 |
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 111 |
return EXIT_SUCCESS; |
| 112 |
#else |
| 113 |
return log_tests_skipped("cannot run CHID calculation on big-endian machine"); |
| 114 |
#endif |
| 115 |
} |
| 116 |
|
| 117 |
DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro); |