mirror of
https://github.com/systemd/systemd.git
synced 2025-03-10 16:58:28 +03:00
test: Add test-chid-match
This commit is contained in:
parent
7c4e351861
commit
640f8c3eb8
8
.github/workflows/linter.yml
vendored
8
.github/workflows/linter.yml
vendored
@ -37,7 +37,7 @@ jobs:
|
||||
VALIDATE_GITHUB_ACTIONS: true
|
||||
|
||||
- name: Check that tabs are not used in Python code
|
||||
run: sh -c '! git grep -P "\\t" -- src/ukify/ukify.py test/integration-test-wrapper.py'
|
||||
run: sh -c '! git grep -P "\\t" -- src/boot/generate-hwids-section.py src/ukify/ukify.py test/integration-test-wrapper.py'
|
||||
|
||||
- name: Install ruff and mypy
|
||||
run: |
|
||||
@ -47,14 +47,14 @@ jobs:
|
||||
- name: Run mypy
|
||||
run: |
|
||||
python3 -m mypy --version
|
||||
python3 -m mypy src/test/generate-sym-test.py src/ukify/ukify.py test/integration-test-wrapper.py
|
||||
python3 -m mypy src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-test-wrapper.py
|
||||
|
||||
- name: Run ruff check
|
||||
run: |
|
||||
ruff --version
|
||||
ruff check src/test/generate-sym-test.py src/ukify/ukify.py test/integration-test-wrapper.py
|
||||
ruff check src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-test-wrapper.py
|
||||
|
||||
- name: Run ruff format
|
||||
run: |
|
||||
ruff --version
|
||||
ruff format --check src/test/generate-sym-test.py src/ukify/ukify.py test/integration-test-wrapper.py
|
||||
ruff format --check src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-test-wrapper.py
|
||||
|
39
src/boot/generate-hwids-section.py
Normal file
39
src/boot/generate-hwids-section.py
Normal file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# We import ukify.py, which is a template file. But only __version__ is
|
||||
# substituted, which we don't care about here. Having the .py suffix makes it
|
||||
# easier to import the file.
|
||||
sys.path.append(os.path.dirname(__file__) + '/../ukify')
|
||||
import ukify
|
||||
|
||||
BYTES_PER_LINE = 16
|
||||
|
||||
hwids = ukify.parse_hwid_dir(Path(sys.argv[1]))
|
||||
|
||||
print(
|
||||
"""/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
const uint8_t hwids_section_data[] = {
|
||||
""",
|
||||
end='',
|
||||
)
|
||||
|
||||
for i, b in enumerate(hwids):
|
||||
print(f'0x{b:02X}, ', end='')
|
||||
if i % BYTES_PER_LINE == BYTES_PER_LINE - 1:
|
||||
print('\n ', end='')
|
||||
elif i == len(hwids) - 1:
|
||||
print('')
|
||||
|
||||
print(
|
||||
"""};
|
||||
const size_t hwids_section_len =""",
|
||||
f'{len(hwids)};',
|
||||
)
|
8
src/boot/hwids/device1.json
Normal file
8
src/boot/hwids/device1.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "Device 1",
|
||||
"compatible": "test,device-1",
|
||||
"hwids": [
|
||||
"2bdcafa9-727c-5e8b-b13b-236f1391c25a",
|
||||
"c87886da-8026-5149-8c95-6d2504c1b7f9"
|
||||
]
|
||||
}
|
8
src/boot/hwids/device2.json
Normal file
8
src/boot/hwids/device2.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "Device 2",
|
||||
"compatible": "test,device-2",
|
||||
"hwids": [
|
||||
"6ff16153-a32f-548a-9cd7-3574a5d0caa4",
|
||||
"0afb4762-c5bb-5fba-887b-d56ce73ee793"
|
||||
]
|
||||
}
|
8
src/boot/hwids/device3.json
Normal file
8
src/boot/hwids/device3.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "Device 3",
|
||||
"compatible": "test,device-3",
|
||||
"hwids": [
|
||||
"06b74502-e5d8-5ecd-a67a-e77654cf3b17",
|
||||
"a8d84e4e-23d9-5629-86da-a49d859b5cde"
|
||||
]
|
||||
}
|
@ -26,6 +26,16 @@ efitest_base = {
|
||||
efi_test_template = test_template + efitest_base
|
||||
efi_fuzz_template = fuzz_template + efitest_base
|
||||
|
||||
generate_hwids_section_py = find_program('generate-hwids-section.py')
|
||||
|
||||
test_hwids_section_c = custom_target(
|
||||
'test-hwids-section.c',
|
||||
input : ['hwids/device1.json', 'hwids/device2.json', 'hwids/device2.json'],
|
||||
output : 'test-hwids-section.c',
|
||||
command : [generate_hwids_section_py, meson.current_source_dir()/'hwids'],
|
||||
capture : true,
|
||||
build_by_default : want_tests != 'false')
|
||||
|
||||
executables += [
|
||||
efi_test_template + {
|
||||
'sources' : files('test-bcd.c'),
|
||||
@ -36,6 +46,11 @@ executables += [
|
||||
'sources' : files('test-efi-string.c'),
|
||||
'conditions' : ['ENABLE_BOOTLOADER'],
|
||||
},
|
||||
efi_test_template + {
|
||||
'sources' : files('test-chid-match.c') +
|
||||
test_hwids_section_c,
|
||||
'conditions' : ['ENABLE_BOOTLOADER'],
|
||||
},
|
||||
efi_fuzz_template + {
|
||||
'sources' : files('fuzz-bcd.c'),
|
||||
},
|
||||
|
77
src/boot/test-chid-match.c
Normal file
77
src/boot/test-chid-match.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "chid.h"
|
||||
#include "smbios.h"
|
||||
#include "tests.h"
|
||||
|
||||
extern uint8_t hwids_section_data[];
|
||||
extern size_t hwids_section_len;
|
||||
|
||||
static const RawSmbiosInfo smbios_info[] = {
|
||||
{
|
||||
.manufacturer = "First Vendor",
|
||||
.product_name = "Device 1",
|
||||
.product_sku = "KD01",
|
||||
.family = "Laptop X",
|
||||
.baseboard_product = "FODM1",
|
||||
.baseboard_manufacturer = "First ODM",
|
||||
},
|
||||
{
|
||||
.manufacturer = "Second Vendor",
|
||||
.product_name = "Device 2",
|
||||
.product_sku = "KD02",
|
||||
.family = "Laptop 2",
|
||||
.baseboard_product = "SODM2",
|
||||
.baseboard_manufacturer = "Second ODM",
|
||||
},
|
||||
{
|
||||
.manufacturer = "First Vendor",
|
||||
.product_name = "Device 3",
|
||||
.product_sku = "KD03",
|
||||
.family = "Tablet Y",
|
||||
.baseboard_product = "FODM2",
|
||||
.baseboard_manufacturer = "First ODM",
|
||||
},
|
||||
};
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
const char *compatible;
|
||||
} results[] = {
|
||||
{ "Device 1", "test,device-1" },
|
||||
{ "Device 2", "test,device-2" },
|
||||
{ "Device 3", "test,device-3" },
|
||||
};
|
||||
|
||||
static RawSmbiosInfo current_info = {};
|
||||
|
||||
/* This is a dummy implementation for testing purposes */
|
||||
void smbios_raw_info_get_cached(RawSmbiosInfo *ret_info) {
|
||||
assert(ret_info);
|
||||
*ret_info = current_info;
|
||||
}
|
||||
|
||||
TEST(chid_match) {
|
||||
for (size_t i = 0; i < ELEMENTSOF(smbios_info); i++) {
|
||||
current_info = smbios_info[i];
|
||||
const Device *dev = NULL;
|
||||
/* Match and check */
|
||||
ASSERT_EQ(chid_match(hwids_section_data, hwids_section_len, &dev), EFI_SUCCESS);
|
||||
ASSERT_NOT_NULL(dev);
|
||||
ASSERT_STREQ(device_get_name(hwids_section_data, dev), results[i].name);
|
||||
ASSERT_STREQ(device_get_compatible(hwids_section_data, dev), results[i].compatible);
|
||||
}
|
||||
}
|
||||
|
||||
static int intro(void) {
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
return EXIT_SUCCESS;
|
||||
#else
|
||||
return log_tests_skipped("cannot run CHID calculation on big-endian machine");
|
||||
#endif
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro);
|
Loading…
x
Reference in New Issue
Block a user