mirror of
https://github.com/anrieff/libcpuid
synced 2024-11-10 22:59:13 +00:00
Add simple sanity tests of the Python bindings
And include them in the CI together with pylint and formatting checks.
This commit is contained in:
parent
ec938b5d42
commit
9915832b21
4 changed files with 95 additions and 1 deletions
48
.github/workflows/python.yml
vendored
Normal file
48
.github/workflows/python.yml
vendored
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
name: Test Python bindings
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test_python:
|
||||||
|
name: Test Python bindings
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.12'
|
||||||
|
|
||||||
|
- name: Build and install libcpuid
|
||||||
|
run: |
|
||||||
|
sudo apt-get install autoconf libtool automake
|
||||||
|
libtoolize
|
||||||
|
autoreconf --install
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
|
||||||
|
- name: Check code formatting (black)
|
||||||
|
run: |
|
||||||
|
pip install black
|
||||||
|
black --check python
|
||||||
|
|
||||||
|
- name: Install the libcpuid Python package
|
||||||
|
run: pip install ./python
|
||||||
|
|
||||||
|
- name: Perform static analysis (pylint)
|
||||||
|
run: |
|
||||||
|
pip install pylint
|
||||||
|
pylint python/src/libcpuid
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
pip install pytest
|
||||||
|
pytest ./python
|
|
@ -19,7 +19,7 @@ build:
|
||||||
- make
|
- make
|
||||||
- make install
|
- make install
|
||||||
- pip install cffi
|
- pip install cffi
|
||||||
- python ./python/ffi_build_rtd.py ./libcpuid/libcpuid.h ./install
|
- python ./python/src/libcpuid/_ffi_build_rtd.py ./libcpuid/libcpuid.h ./install
|
||||||
|
|
||||||
sphinx:
|
sphinx:
|
||||||
configuration: python/docs/conf.py
|
configuration: python/docs/conf.py
|
||||||
|
|
46
python/tests/sanity_test.py
Normal file
46
python/tests/sanity_test.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
"""Sanity tests for the libcpuid package."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
import libcpuid
|
||||||
|
from libcpuid.info import CPUInfo, SystemInfo
|
||||||
|
from libcpuid.raw import CPURawData, CPURawDataArray
|
||||||
|
|
||||||
|
|
||||||
|
def test_cpu_name_in_vendor_list():
|
||||||
|
"""
|
||||||
|
Checks that the current CPU codename appears
|
||||||
|
in the list of all CPUs of its vendor.
|
||||||
|
"""
|
||||||
|
info = CPUInfo.from_current_cpu()
|
||||||
|
cpulist = libcpuid.get_cpu_list(info.vendor)
|
||||||
|
assert info.cpu_codename in cpulist
|
||||||
|
|
||||||
|
|
||||||
|
def test_serialization():
|
||||||
|
"""
|
||||||
|
Checks that CPU data serialization and
|
||||||
|
deserialization does not raise any errors.
|
||||||
|
"""
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
|
info_file = os.path.join(tmpdirname, "info.txt")
|
||||||
|
raw = CPURawData.from_current_cpu()
|
||||||
|
raw.serialize(info_file)
|
||||||
|
info = CPUInfo.from_raw(raw)
|
||||||
|
info_from_file = CPUInfo.from_raw(CPURawData.from_file(info_file))
|
||||||
|
assert info.features == info_from_file.features
|
||||||
|
|
||||||
|
|
||||||
|
def test_array_serialization():
|
||||||
|
"""
|
||||||
|
Checks that CPU array data serialization and
|
||||||
|
deserialization does not raise any errors.
|
||||||
|
"""
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
|
info_file = os.path.join(tmpdirname, "info.txt")
|
||||||
|
raw_array = CPURawDataArray.from_all_cpus()
|
||||||
|
raw_array.serialize(info_file)
|
||||||
|
info = SystemInfo.from_raw_array(raw_array)
|
||||||
|
info_from_file = SystemInfo.from_raw_array(CPURawDataArray.from_file(info_file))
|
||||||
|
assert len(info) == len(info_from_file)
|
||||||
|
assert info[0].features == info_from_file[0].features
|
Loading…
Reference in a new issue