Add a basic sanity test of the Python bindings

This commit is contained in:
Pavol Žáčik 2024-11-14 16:41:29 +01:00
commit 4fcd36a91e
No known key found for this signature in database
GPG key ID: 5B5640AB63D575DE
3 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,16 @@
import json
import sys
from libcpuid.info import CPUInfo
out_filename = sys.argv[1]
cpu_info = CPUInfo.from_current_cpu()
to_output = {
"vendor_str": cpu_info.vendor_str,
"ext_family": cpu_info.ext_family,
"ext_model": cpu_info.ext_model,
"stepping": cpu_info.stepping
}
with open(out_filename, "w") as out_file:
json.dump(to_output, out_file)

View file

@ -0,0 +1,21 @@
summary: Python bindings sanity test
contact: Pavol Žáčik <pzacik@redhat.com>
component:
- libcpuid
require:
- python3-libcpuid
- jq
test: ./test.sh
framework: beakerlib
duration: 5m
enabled: true
tag:
- Tier1
tier: '1'
adjust:
- enabled: false
when: distro < rhel-10
continue: false
- enabled: false
when: distro < centos-stream-10
continue: false

39
Sanity/binding-test/test.sh Executable file
View file

@ -0,0 +1,39 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
. /usr/share/beakerlib/beakerlib.sh || exit 1
rlJournalStart
rlPhaseStartSetup
rlAssertRpm "python3-libcpuid"
script=$(pwd)/libcpuid_info.py
rlRun "tmp=$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd $tmp"
script_outfile=libcpuid_info.json
lscpu_outfile=lscpu.out
rlPhaseEnd
rlPhaseStartTest
rlRun "python3 $script $script_outfile"
rlRun "lscpu > $lscpu_outfile"
rlRun "libcpuid_vendor=$(cat $script_outfile | jq -r .vendor_str)"
rlRun "libcpuid_family=$(cat $script_outfile | jq .ext_family)"
rlRun "libcpuid_model=$(cat $script_outfile | jq .ext_model)"
rlRun "libcpuid_stepping=$(cat $script_outfile | jq .stepping)"
rlRun "lscpu_vendor=$(sed -n 's/^Vendor ID:\s*//p' $lscpu_outfile)"
rlRun "lscpu_family=$(sed -n 's/^CPU family:\s*//p' $lscpu_outfile)"
rlRun "lscpu_model=$(sed -n 's/^Model:\s*//p' $lscpu_outfile)"
rlRun "lscpu_stepping=$(sed -n 's/^Stepping:\s*//p' $lscpu_outfile)"
rlAssertEquals "Check equality of CPU vendor" "$libcpuid_vendor" "$lscpu_vendor"
rlAssertEquals "Check equality of CPU family" "$libcpuid_family" "$lscpu_family"
rlAssertEquals "Check equality of CPU model" "$libcpuid_model" "$lscpu_model"
rlAssertEquals "Check equality of CPU stepping" "$libcpuid_stepping" "$lscpu_stepping"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd