libvirt/tests/cputestdata/cpu-parse.sh
Jiri Denemark 3704b9003f tests: Add CPU detection tests
So far we only test CPUID -> CPU def conversion on artificial CPUID data
computed from another CPU def. This patch adds the infrastructure to
test this conversion on real data gathered from a host CPU and two
helper scripts for adding new test data:

- cpu-gather.sh runs cpuid tool and qemu-system-x86_64 to get CPUID data
  from the host CPU; this is what users can be asked to run if they run
  into an issue with host CPU detection in libvirt

- cpu-parse.sh takes the data generated by cpu-gather.sh and creates
  data files for CPU detection tests

The CPUID data queried from QEMU will eventually switch to the format
used by query-host-cpu QMP command once QEMU implements it. Until then
we just spawn QEMU with -cpu host and query the guest CPU in QOM. They
should both provide the same CPUID results, but query-host-cpu does not
require any guest CPU to be created by QEMU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-09 09:47:56 +02:00

58 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Usage:
# ./cpu-gather.sh | ./cpu-parse.sh
data=`cat`
model=`sed -ne '/^model name[ ]*:/ {s/^[^:]*: \(.*\)/\1/p; q}' <<<"$data"`
fname=`sed -e 's/^ *//;
s/ *$//;
s/[ -]\+ \+/ /g;
s/(\([Rr]\|[Tt][Mm]\))//g;
s/.*\(Intel\|AMD\) //;
s/ \(Duo\|Quad\|II X[0-9]\+\) / /;
s/ \(CPU\|Processor\)\>//;
s/ @.*//;
s/ APU .*//;
s/ \(v[0-9]\|SE\)$//;
s/ /-/g' <<<"$model"`
fname="x86-cpuid-$fname"
xml()
{
hex='\(0x[0-9a-f]\+\)'
match="$hex $hex: eax=$hex ebx=$hex ecx=$hex edx=$hex"
subst="<cpuid eax_in='\\1' ecx_in='\\2' eax='\\3' ebx='\\4' ecx='\\5' edx='\\6'\\/>"
echo "<!-- $model -->"
echo "<cpudata arch='x86'>"
sed -ne "s/^ *$match$/ $subst/p"
echo "</cpudata>"
}
json()
{
first=true
sed -ne '/{"QMP".*/d;
/{"return": {}}/d;
/{"timestamp":.*/d;
/^{/p' <<<"$data" | \
while read; do
$first || echo
first=false
json_reformat <<<"$REPLY" | tr -s '\n'
done
}
xml <<<"$data" >$fname.xml
echo $fname.xml
json <<<"$data" >$fname.json
if [[ -s $fname.json ]]; then
echo $fname.json
else
rm $fname.new.json
fi