Skip to content

Commit 4f622b8

Browse files
authored
Add bios mode to submission json (new) (#2423)
* Add boot mode in BIOS metadata In `raw_devices_dmi_json` Checkbox job, the boot mode is deduced from the INXI output. This commit guesses the boot mode based on the existence of the `/sys/firmware/efi` directory. This is used in C3 to provide more information about what boot mode has been used to test a device. * Update unit tests
1 parent 486d37c commit 4f622b8

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

checkbox-ng/checkbox_ng/support/device_info.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def get_bios_info() -> dict:
4545
4646
This function extracts the content from these files and returns a dict,
4747
using the filename as a key, defaulting to `None` if it cannot find data.
48+
49+
In addition, it provides the boot mode by checking the existence of the
50+
/sys/firmware/efi directory.
4851
"""
4952
bios_data = {
5053
"date": None,
@@ -65,6 +68,11 @@ def get_bios_info() -> dict:
6568
"Failed to read bios {}. Error: {}".format(key, e),
6669
file=sys.stderr,
6770
)
71+
if Path("/sys/firmware/efi").is_dir():
72+
boot_mode = "UEFI"
73+
else:
74+
boot_mode = "BIOS"
75+
bios_data["boot_mode"] = boot_mode
6876
return bios_data
6977

7078

checkbox-ng/checkbox_ng/support/tests/test_device_info.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def test_get_debian_packages(self, mock_co):
3030
self.assertEqual(pkg[0]["version"], "23.01+dfsg-11")
3131
self.assertEqual(pkg[0]["architecture"], "amd64")
3232

33-
def test_get_bios_info_success(self):
33+
@patch("checkbox_ng.support.device_info.Path.is_dir", return_value=True)
34+
def test_get_bios_info_success(self, mock_path_is_dir):
3435
"""Test successful retrieval of multiple BIOS files."""
3536

3637
file_contents = [
@@ -48,9 +49,11 @@ def test_get_bios_info_success(self):
4849

4950
self.assertEqual(result["vendor"], "Dell Inc.")
5051
self.assertEqual(result["version"], "1.5.0")
51-
self.assertEqual(len(result), 4)
52+
self.assertEqual(result["boot_mode"], "UEFI")
53+
self.assertEqual(len(result), 5)
5254

53-
def test_get_bios_info_empty(self):
55+
@patch("checkbox_ng.support.device_info.Path.is_dir", return_value=False)
56+
def test_get_bios_info_empty(self, mock_path_is_dir):
5457
"""Test behavior when no bios_* files are found."""
5558
with patch(
5659
"checkbox_ng.support.device_info.Path.read_text",
@@ -60,10 +63,17 @@ def test_get_bios_info_empty(self):
6063

6164
self.assertEqual(
6265
result,
63-
{"date": None, "release": None, "vendor": None, "version": None},
66+
{
67+
"date": None,
68+
"release": None,
69+
"vendor": None,
70+
"version": None,
71+
"boot_mode": "BIOS",
72+
},
6473
)
6574

66-
def test_get_bios_info_permission_denied(self):
75+
@patch("checkbox_ng.support.device_info.Path.is_dir", return_value=True)
76+
def test_get_bios_info_permission_denied(self, mock_path_is_dir):
6777
"""Test behavior when a file exists but cannot be read."""
6878
with patch(
6979
"checkbox_ng.support.device_info.Path.read_text",
@@ -73,7 +83,13 @@ def test_get_bios_info_permission_denied(self):
7383

7484
self.assertEqual(
7585
result,
76-
{"date": None, "release": None, "vendor": None, "version": None},
86+
{
87+
"date": None,
88+
"release": None,
89+
"vendor": None,
90+
"version": None,
91+
"boot_mode": "UEFI",
92+
},
7793
)
7894

7995
@patch("checkbox_ng.support.device_info.get_debian_packages")

0 commit comments

Comments
 (0)