mirror of
https://github.com/HorlogeSkynet/archey4
synced 2025-05-02 04:00:15 +02:00
[GPU] Parses lspci
to avoid classing 3D NAND devices as GPUs.
Closes #149.
This commit is contained in:
parent
0a970c010f
commit
d5fc44d2d9
archey
@ -2,6 +2,7 @@
|
||||
|
||||
import platform
|
||||
import re
|
||||
from shlex import split
|
||||
from subprocess import DEVNULL, CalledProcessError, check_output
|
||||
from typing import List
|
||||
|
||||
@ -31,7 +32,7 @@ class GPU(Entry):
|
||||
def _parse_lspci_output() -> List[str]:
|
||||
"""Based on `lspci` output, return a list of video controllers names"""
|
||||
try:
|
||||
lspci_output = check_output("lspci", universal_newlines=True).splitlines()
|
||||
lspci_output = check_output(["lspci", "-m"], universal_newlines=True).splitlines()
|
||||
except (FileNotFoundError, CalledProcessError):
|
||||
return []
|
||||
|
||||
@ -40,10 +41,11 @@ class GPU(Entry):
|
||||
# We'll be looking for specific video controllers (in the below keys order).
|
||||
for video_key in ("3D", "VGA", "Display"):
|
||||
for pci_device in lspci_output:
|
||||
# If a controller type match...
|
||||
if video_key in pci_device:
|
||||
pci_class, pci_vendor, pci_device = split(pci_device)[1:4]
|
||||
# If a controller type matches the class...
|
||||
if video_key in pci_class:
|
||||
# ... adds its name to the final list.
|
||||
gpus_list.append(pci_device.partition(": ")[2])
|
||||
gpus_list.append(f"{pci_vendor} {pci_device}")
|
||||
|
||||
return gpus_list
|
||||
|
||||
|
@ -17,18 +17,25 @@ class TestGPUEntry(unittest.TestCase, CustomAssertions):
|
||||
side_effect=[
|
||||
FileNotFoundError(),
|
||||
"""\
|
||||
XX:YY.H IDE interface: IIIIIIIIIIIIIIII
|
||||
XX:YY.H SMBus: BBBBBBBBBBBBBBBB
|
||||
XX:YY.H VGA compatible controller: GPU-MODEL-NAME
|
||||
XX:YY.H Audio device: DDDDDDDDDDDDDDDD
|
||||
XX:YY.H "IDE interface" "Manufacturer" "IIIIIIIIIIIIIIII"
|
||||
XX:YY.H "SMBus" "Manufacturer" "BBBBBBBBBBBBBBBB"
|
||||
XX:YY.H "VGA compatible controller" "GPU-Manufacturer" "GPU-MODEL-NAME"
|
||||
XX:YY.H "Audio device" "Manufacturer" "DDDDDDDDDDDDDDDD"
|
||||
""",
|
||||
"""\
|
||||
XX:YY.H IDE interface: IIIIIIIIIIIIIIII
|
||||
XX:YY.H SMBus: BBBBBBBBBBBBBBBB
|
||||
XX:YY.H VGA compatible controller: GPU-MODEL-NAME
|
||||
XX:YY.H Display controller: ANOTHER-MATCHING-VIDEO-CONTROLLER
|
||||
XX:YY.H Audio device: DDDDDDDDDDDDDDDD
|
||||
XX:YY.H 3D controller: 3D GPU-MODEL-NAME TAKES ADVANTAGE
|
||||
XX:YY.H "IDE interface" "Manufacturer" "IIIIIIIIIIIIIIII"
|
||||
XX:YY.H "SMBus" "Manufacturer" "BBBBBBBBBBBBBBBB"
|
||||
XX:YY.H "VGA compatible controller" "GPU-Manufacturer" "GPU-MODEL-NAME"
|
||||
XX:YY.H "Display controller" "Another-GPU-Manufacturer" "ANOTHER-MATCHING-VIDEO-CONTROLLER"
|
||||
XX:YY.H "Audio device" "Manufacturer" "DDDDDDDDDDDDDDDD"
|
||||
XX:YY.H "3D controller" "3D-Manufacturer" "3D GPU-MODEL-NAME TAKES ADVANTAGE"
|
||||
""",
|
||||
"""\
|
||||
XX:YY.H "IDE interface" "Manufacturer" "IIIIIIIIIIIIIIII"
|
||||
XX:YY.H "SMBus" "Manufacturer" "BBBBBBBBBBBBBBBB"
|
||||
XX:YY.H "VGA compatible controller" "GPU-Manufacturer" "GPU-MODEL-NAME"
|
||||
XX:YY.H "Audio device" "Manufacturer" "DDDDDDDDDDDDDDDD"
|
||||
XX:YY.H "Non-Volatile memory controller" "Sandisk Corp" "SanDisk Ultra 3D / WD Blue SN570 NVMe SSD"
|
||||
""",
|
||||
],
|
||||
)
|
||||
@ -36,15 +43,17 @@ XX:YY.H 3D controller: 3D GPU-MODEL-NAME TAKES ADVANTAGE
|
||||
"""Check `_parse_lspci_output` behavior"""
|
||||
# pylint: disable=protected-access
|
||||
self.assertListEmpty(GPU._parse_lspci_output())
|
||||
self.assertListEqual(GPU._parse_lspci_output(), ["GPU-MODEL-NAME"])
|
||||
self.assertListEqual(GPU._parse_lspci_output(), ["GPU-Manufacturer GPU-MODEL-NAME"])
|
||||
self.assertListEqual(
|
||||
GPU._parse_lspci_output(),
|
||||
[
|
||||
"3D GPU-MODEL-NAME TAKES ADVANTAGE",
|
||||
"GPU-MODEL-NAME",
|
||||
"ANOTHER-MATCHING-VIDEO-CONTROLLER",
|
||||
"3D-Manufacturer 3D GPU-MODEL-NAME TAKES ADVANTAGE",
|
||||
"GPU-Manufacturer GPU-MODEL-NAME",
|
||||
"Another-GPU-Manufacturer ANOTHER-MATCHING-VIDEO-CONTROLLER",
|
||||
],
|
||||
)
|
||||
# Ensure 3D nand flash is ignored; see issue #149
|
||||
self.assertListEqual(GPU._parse_lspci_output(), ["GPU-Manufacturer GPU-MODEL-NAME"])
|
||||
# pylint: enable=protected-access
|
||||
|
||||
@patch(
|
||||
|
Loading…
x
Reference in New Issue
Block a user