2010-10-07 18:35:17 +04:00
/*
* cputest . c : Test the libvirtd internal CPU APIs
*
2014-09-03 23:39:21 +04:00
* Copyright ( C ) 2010 - 2014 Red Hat , Inc .
2010-10-07 18:35:17 +04:00
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
2012-09-21 02:30:55 +04:00
* License along with this library . If not , see
2012-07-21 14:06:23 +04:00
* < http : //www.gnu.org/licenses/>.
2010-10-07 18:35:17 +04:00
*/
# include <config.h>
# include <unistd.h>
# include <sys/types.h>
# include <fcntl.h>
# include "internal.h"
2012-12-13 22:13:21 +04:00
# include "virxml.h"
2012-12-12 22:06:53 +04:00
# include "viralloc.h"
2012-12-04 16:04:07 +04:00
# include "virbuffer.h"
2010-10-07 18:35:17 +04:00
# include "testutils.h"
# include "cpu_conf.h"
# include "cpu/cpu.h"
2019-02-25 12:05:34 +03:00
# include "cpu/cpu_x86.h"
2010-10-07 18:35:17 +04:00
2019-12-12 20:17:08 +03:00
# if WITH_QEMU
2016-06-01 16:57:00 +03:00
# include "testutilsqemu.h"
# include "qemumonitortestutils.h"
2018-12-13 17:53:50 +03:00
# define LIBVIRT_QEMU_CAPSPRIV_H_ALLOW
2017-02-13 12:33:52 +03:00
# include "qemu / qemu_capspriv.h"
2016-06-01 16:57:00 +03:00
# endif
2010-10-07 18:35:17 +04:00
# define VIR_FROM_THIS VIR_FROM_CPU
enum cpuTestBoolWithError {
FAIL = - 1 ,
NO = 0 ,
YES = 1
} ;
struct data {
2017-02-13 16:18:55 +03:00
virArch arch ;
2010-10-07 18:35:17 +04:00
const char * host ;
const char * name ;
2021-03-11 10:16:13 +03:00
virDomainCapsCPUModels * models ;
2010-10-07 18:35:17 +04:00
const char * modelsName ;
2022-04-21 19:25:15 +03:00
const char * * cpus ;
int ncpus ;
2013-08-02 23:08:19 +04:00
unsigned int flags ;
2010-10-07 18:35:17 +04:00
int result ;
} ;
2019-12-12 20:17:08 +03:00
# if WITH_QEMU
2016-06-01 16:57:00 +03:00
static virQEMUDriver driver ;
# endif
2010-10-07 18:35:17 +04:00
2021-03-11 10:16:13 +03:00
static virCPUDef *
2017-02-13 16:18:55 +03:00
cpuTestLoadXML ( virArch arch , const char * name )
2010-10-07 18:35:17 +04:00
{
2021-08-17 13:21:56 +03:00
g_autofree char * xml = NULL ;
2021-08-11 14:57:18 +03:00
g_autoptr ( xmlDoc ) doc = NULL ;
2021-08-11 14:30:26 +03:00
g_autoptr ( xmlXPathContext ) ctxt = NULL ;
2021-03-11 10:16:13 +03:00
virCPUDef * cpu = NULL ;
2010-10-07 18:35:17 +04:00
2019-10-22 16:26:14 +03:00
xml = g_strdup_printf ( " %s/cputestdata/%s-%s.xml " , abs_srcdir ,
virArchToString ( arch ) , name ) ;
2010-10-07 18:35:17 +04:00
2011-08-19 01:37:14 +04:00
if ( ! ( doc = virXMLParseFileCtxt ( xml , & ctxt ) ) )
2021-08-17 13:17:31 +03:00
return NULL ;
2010-10-07 18:35:17 +04:00
2020-10-07 11:54:55 +03:00
virCPUDefParseXML ( ctxt , NULL , VIR_CPU_TYPE_AUTO , & cpu , false ) ;
2010-10-07 18:35:17 +04:00
return cpu ;
}
2021-03-11 10:16:13 +03:00
static virCPUDef * *
2017-02-13 16:18:55 +03:00
cpuTestLoadMultiXML ( virArch arch ,
2010-10-07 18:35:17 +04:00
const char * name ,
unsigned int * count )
{
2021-08-17 13:21:56 +03:00
g_autofree char * xml = NULL ;
2021-08-11 14:57:18 +03:00
g_autoptr ( xmlDoc ) doc = NULL ;
2021-08-11 14:30:26 +03:00
g_autoptr ( xmlXPathContext ) ctxt = NULL ;
2021-08-17 13:21:56 +03:00
g_autofree xmlNodePtr * nodes = NULL ;
2021-03-11 10:16:13 +03:00
virCPUDef * * cpus = NULL ;
2010-10-07 18:35:17 +04:00
int n ;
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
2010-10-07 18:35:17 +04:00
2019-10-22 16:26:14 +03:00
xml = g_strdup_printf ( " %s/cputestdata/%s-%s.xml " , abs_srcdir ,
virArchToString ( arch ) , name ) ;
2010-10-07 18:35:17 +04:00
2011-08-19 01:37:14 +04:00
if ( ! ( doc = virXMLParseFileCtxt ( xml , & ctxt ) ) )
2021-08-17 13:17:31 +03:00
return NULL ;
2010-10-07 18:35:17 +04:00
n = virXPathNodeSet ( " /cpuTest/cpu " , ctxt , & nodes ) ;
2020-09-23 01:59:59 +03:00
if ( n < = 0 ) {
2015-03-23 19:19:28 +03:00
fprintf ( stderr , " \n No /cpuTest/cpu elements found in %s \n " , xml ) ;
2021-08-17 13:17:31 +03:00
return NULL ;
2015-03-23 19:19:28 +03:00
}
2010-10-07 18:35:17 +04:00
2021-03-11 10:16:13 +03:00
cpus = g_new0 ( virCPUDef * , n ) ;
2020-09-23 01:59:59 +03:00
2010-10-07 18:35:17 +04:00
for ( i = 0 ; i < n ; i + + ) {
ctxt - > node = nodes [ i ] ;
2020-10-07 11:54:55 +03:00
if ( virCPUDefParseXML ( ctxt , NULL , VIR_CPU_TYPE_HOST , & cpus [ i ] ,
false ) < 0 )
2021-08-17 13:17:31 +03:00
goto error ;
2010-10-07 18:35:17 +04:00
}
* count = n ;
return cpus ;
2021-08-17 13:17:31 +03:00
error :
2012-02-06 12:35:47 +04:00
for ( i = 0 ; i < n ; i + + )
virCPUDefFree ( cpus [ i ] ) ;
VIR_FREE ( cpus ) ;
2021-08-17 13:17:31 +03:00
return NULL ;
2010-10-07 18:35:17 +04:00
}
static int
2017-02-13 16:18:55 +03:00
cpuTestCompareXML ( virArch arch ,
2013-10-05 05:40:19 +04:00
virCPUDef * cpu ,
2017-06-30 16:47:23 +03:00
const char * name )
2010-10-07 18:35:17 +04:00
{
2021-08-20 17:05:08 +03:00
g_autofree char * xml = NULL ;
g_autofree char * actual = NULL ;
2010-10-07 18:35:17 +04:00
2019-10-22 16:26:14 +03:00
xml = g_strdup_printf ( " %s/cputestdata/%s-%s.xml " , abs_srcdir ,
virArchToString ( arch ) , name ) ;
2010-10-07 18:35:17 +04:00
2017-06-30 16:47:23 +03:00
if ( ! ( actual = virCPUDefFormat ( cpu , NULL ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
2016-05-26 18:01:53 +03:00
if ( virTestCompareToFile ( actual , xml ) < 0 )
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
2021-08-20 17:12:04 +03:00
return 0 ;
2010-10-07 18:35:17 +04:00
}
static const char *
cpuTestCompResStr ( virCPUCompareResult result )
{
switch ( result ) {
case VIR_CPU_COMPARE_ERROR : return " ERROR " ;
case VIR_CPU_COMPARE_INCOMPATIBLE : return " INCOMPATIBLE " ;
case VIR_CPU_COMPARE_IDENTICAL : return " IDENTICAL " ;
case VIR_CPU_COMPARE_SUPERSET : return " SUPERSET " ;
2012-01-20 22:43:28 +04:00
case VIR_CPU_COMPARE_LAST : break ;
2010-10-07 18:35:17 +04:00
}
return " unknown " ;
}
static const char *
cpuTestBoolWithErrorStr ( enum cpuTestBoolWithError result )
{
switch ( result ) {
case FAIL : return " FAIL " ;
case NO : return " NO " ;
case YES : return " YES " ;
}
return " unknown " ;
}
static int
cpuTestCompare ( const void * arg )
{
const struct data * data = arg ;
2021-08-20 17:00:31 +03:00
g_autoptr ( virCPUDef ) host = NULL ;
g_autoptr ( virCPUDef ) cpu = NULL ;
2010-10-07 18:35:17 +04:00
virCPUCompareResult result ;
if ( ! ( host = cpuTestLoadXML ( data - > arch , data - > host ) ) | |
! ( cpu = cpuTestLoadXML ( data - > arch , data - > name ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
2016-08-09 14:26:53 +03:00
result = virCPUCompare ( host - > arch , host , cpu , false ) ;
2010-10-07 18:35:17 +04:00
if ( data - > result = = VIR_CPU_COMPARE_ERROR )
virResetLastError ( ) ;
if ( data - > result ! = result ) {
2019-05-03 11:45:58 +03:00
VIR_TEST_VERBOSE ( " \n Expected result %s, got %s " ,
2010-10-07 18:35:17 +04:00
cpuTestCompResStr ( data - > result ) ,
cpuTestCompResStr ( result ) ) ;
2015-04-23 20:38:00 +03:00
/* Pad to line up with test name ... in virTestRun */
VIR_TEST_VERBOSE ( " %74s " , " ... " ) ;
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
}
2021-08-20 17:12:04 +03:00
return 0 ;
2010-10-07 18:35:17 +04:00
}
static int
cputest: Don't test cpuGuestData
The API is no longer used anywhere else since it was replaced by a much
saner work flow utilizing new APIs that work on virCPUDefPtr directly:
virCPUCompare, virCPUUpdate, and virCPUTranslate.
Not testing the new work flow caused some bugs to be hidden. This patch
reveals them, but doesn't attempt to fix them. To make sure all test
still pass after this patch, all affected test results are modified to
pretend the tests succeeded. All of the bugs will be fixed in the
following commits and the artificial modifications will be reverted.
The following is the list of bugs in the new CPU model work flow:
- a guest CPU with mode='custom' and missing <vendor/> gets the vendor
copied from host's CPU (the vendor should only be copied to host-model
CPUs):
DO_TEST_UPDATE("x86", "host", "min", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_UPDATE("x86", "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_GUESTCPU("x86", "host-better", "pentium3", NULL, 0)
- when a guest CPU with mode='custom' needs to be translated into
another model because the original model is not supported by a
hypervisor, the result will have its vendor set to the vendor of the
original CPU model as specified in cpu_map.xml even if the original
guest CPU XML didn't contain <vendor/>:
DO_TEST_GUESTCPU("x86", "host", "guest", model486, 0)
DO_TEST_GUESTCPU("x86", "host", "guest", models, 0)
DO_TEST_GUESTCPU("x86", "host-Haswell-noTSX", "Haswell-noTSX",
haswell, 0)
- legacy POWERx_v* model names are not recognized:
DO_TEST_GUESTCPU("ppc64", "host", "guest-legacy", ppc_models, 0)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-10 11:41:17 +03:00
cpuTestGuestCPU ( const void * arg )
2010-10-07 18:35:17 +04:00
{
const struct data * data = arg ;
2015-08-07 18:39:08 +03:00
int ret = - 2 ;
2021-08-20 17:00:31 +03:00
g_autoptr ( virCPUDef ) host = NULL ;
g_autoptr ( virCPUDef ) cpu = NULL ;
2010-10-07 18:35:17 +04:00
virCPUCompareResult cmpResult ;
2020-07-03 02:35:41 +03:00
g_auto ( virBuffer ) buf = VIR_BUFFER_INITIALIZER ;
2021-08-20 17:05:08 +03:00
g_autofree char * result = NULL ;
2010-10-07 18:35:17 +04:00
if ( ! ( host = cpuTestLoadXML ( data - > arch , data - > host ) ) | |
! ( cpu = cpuTestLoadXML ( data - > arch , data - > name ) ) )
goto cleanup ;
2016-11-09 19:09:48 +03:00
if ( virCPUConvertLegacy ( host - > arch , cpu ) < 0 )
goto cleanup ;
cputest: Don't test cpuGuestData
The API is no longer used anywhere else since it was replaced by a much
saner work flow utilizing new APIs that work on virCPUDefPtr directly:
virCPUCompare, virCPUUpdate, and virCPUTranslate.
Not testing the new work flow caused some bugs to be hidden. This patch
reveals them, but doesn't attempt to fix them. To make sure all test
still pass after this patch, all affected test results are modified to
pretend the tests succeeded. All of the bugs will be fixed in the
following commits and the artificial modifications will be reverted.
The following is the list of bugs in the new CPU model work flow:
- a guest CPU with mode='custom' and missing <vendor/> gets the vendor
copied from host's CPU (the vendor should only be copied to host-model
CPUs):
DO_TEST_UPDATE("x86", "host", "min", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_UPDATE("x86", "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_GUESTCPU("x86", "host-better", "pentium3", NULL, 0)
- when a guest CPU with mode='custom' needs to be translated into
another model because the original model is not supported by a
hypervisor, the result will have its vendor set to the vendor of the
original CPU model as specified in cpu_map.xml even if the original
guest CPU XML didn't contain <vendor/>:
DO_TEST_GUESTCPU("x86", "host", "guest", model486, 0)
DO_TEST_GUESTCPU("x86", "host", "guest", models, 0)
DO_TEST_GUESTCPU("x86", "host-Haswell-noTSX", "Haswell-noTSX",
haswell, 0)
- legacy POWERx_v* model names are not recognized:
DO_TEST_GUESTCPU("ppc64", "host", "guest-legacy", ppc_models, 0)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-10 11:41:17 +03:00
cmpResult = virCPUCompare ( host - > arch , host , cpu , false ) ;
2010-10-07 18:35:17 +04:00
if ( cmpResult = = VIR_CPU_COMPARE_ERROR | |
2015-08-07 18:39:08 +03:00
cmpResult = = VIR_CPU_COMPARE_INCOMPATIBLE ) {
ret = - 1 ;
2010-10-07 18:35:17 +04:00
goto cleanup ;
2015-08-07 18:39:08 +03:00
}
2010-10-07 18:35:17 +04:00
cputest: Don't test cpuGuestData
The API is no longer used anywhere else since it was replaced by a much
saner work flow utilizing new APIs that work on virCPUDefPtr directly:
virCPUCompare, virCPUUpdate, and virCPUTranslate.
Not testing the new work flow caused some bugs to be hidden. This patch
reveals them, but doesn't attempt to fix them. To make sure all test
still pass after this patch, all affected test results are modified to
pretend the tests succeeded. All of the bugs will be fixed in the
following commits and the artificial modifications will be reverted.
The following is the list of bugs in the new CPU model work flow:
- a guest CPU with mode='custom' and missing <vendor/> gets the vendor
copied from host's CPU (the vendor should only be copied to host-model
CPUs):
DO_TEST_UPDATE("x86", "host", "min", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_UPDATE("x86", "host", "pentium3", VIR_CPU_COMPARE_IDENTICAL)
DO_TEST_GUESTCPU("x86", "host-better", "pentium3", NULL, 0)
- when a guest CPU with mode='custom' needs to be translated into
another model because the original model is not supported by a
hypervisor, the result will have its vendor set to the vendor of the
original CPU model as specified in cpu_map.xml even if the original
guest CPU XML didn't contain <vendor/>:
DO_TEST_GUESTCPU("x86", "host", "guest", model486, 0)
DO_TEST_GUESTCPU("x86", "host", "guest", models, 0)
DO_TEST_GUESTCPU("x86", "host-Haswell-noTSX", "Haswell-noTSX",
haswell, 0)
- legacy POWERx_v* model names are not recognized:
DO_TEST_GUESTCPU("ppc64", "host", "guest-legacy", ppc_models, 0)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-10 11:41:17 +03:00
if ( virCPUUpdate ( host - > arch , cpu , host ) < 0 | |
2017-09-22 16:51:33 +03:00
virCPUTranslate ( host - > arch , cpu , data - > models ) < 0 ) {
2015-08-07 18:39:08 +03:00
ret = - 1 ;
2010-10-07 18:35:17 +04:00
goto cleanup ;
}
2011-04-30 20:34:49 +04:00
virBufferAsprintf ( & buf , " %s+%s " , data - > host , data - > name ) ;
2017-09-22 16:51:33 +03:00
if ( data - > modelsName )
2011-04-30 20:34:49 +04:00
virBufferAsprintf ( & buf , " ,%s " , data - > modelsName ) ;
2010-10-07 18:35:17 +04:00
virBufferAddLit ( & buf , " -result " ) ;
result = virBufferContentAndReset ( & buf ) ;
2017-06-30 16:47:23 +03:00
if ( cpuTestCompareXML ( data - > arch , cpu , result ) < 0 )
2015-08-07 18:39:08 +03:00
goto cleanup ;
ret = 0 ;
2010-10-07 18:35:17 +04:00
2014-03-25 10:53:44 +04:00
cleanup :
2015-08-07 18:39:08 +03:00
if ( ret = = data - > result ) {
/* We got the result we expected, whether it was
* a success or a failure */
virResetLastError ( ) ;
ret = 0 ;
} else {
2019-05-03 11:45:58 +03:00
VIR_TEST_VERBOSE ( " \n Expected result %d, got %d " ,
2015-08-07 18:39:08 +03:00
data - > result , ret ) ;
/* Pad to line up with test name ... in virTestRun */
VIR_TEST_VERBOSE ( " %74s " , " ... " ) ;
ret = - 1 ;
}
2010-10-07 18:35:17 +04:00
return ret ;
}
static int
cpuTestBaseline ( const void * arg )
{
const struct data * data = arg ;
int ret = - 1 ;
2021-03-11 10:16:13 +03:00
virCPUDef * * cpus = NULL ;
virCPUDef * baseline = NULL ;
2010-10-07 18:35:17 +04:00
unsigned int ncpus = 0 ;
2021-08-20 17:05:08 +03:00
g_autofree char * result = NULL ;
2014-01-28 03:00:44 +04:00
const char * suffix ;
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
2010-10-07 18:35:17 +04:00
if ( ! ( cpus = cpuTestLoadMultiXML ( data - > arch , data - > name , & ncpus ) ) )
goto cleanup ;
2018-05-15 12:57:35 +03:00
baseline = virCPUBaseline ( data - > arch , cpus , ncpus , NULL , NULL ,
2018-05-15 11:50:32 +03:00
! ! ( data - > flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE ) ) ;
2017-03-17 17:57:47 +03:00
if ( baseline & &
( data - > flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES ) & &
virCPUExpandFeatures ( data - > arch , baseline ) < 0 ) {
2022-01-28 20:42:45 +03:00
g_clear_pointer ( & baseline , virCPUDefFree ) ;
2017-03-17 17:57:47 +03:00
}
2010-10-07 18:35:17 +04:00
if ( data - > result < 0 ) {
virResetLastError ( ) ;
2014-09-03 23:39:21 +04:00
if ( ! baseline ) {
2010-10-07 18:35:17 +04:00
ret = 0 ;
2015-04-23 20:38:00 +03:00
} else {
VIR_TEST_VERBOSE ( " \n %-70s... " ,
2018-05-15 11:50:32 +03:00
" virCPUBaseline was expected to fail but it succeeded " ) ;
2010-10-07 18:35:17 +04:00
}
goto cleanup ;
}
if ( ! baseline )
goto cleanup ;
2014-01-28 03:00:44 +04:00
if ( data - > flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES )
suffix = " expanded " ;
2015-02-05 17:28:09 +03:00
else if ( data - > flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE )
suffix = " migratable " ;
2014-01-28 03:00:44 +04:00
else
suffix = " result " ;
2019-10-22 16:26:14 +03:00
result = g_strdup_printf ( " %s-%s " , data - > name , suffix ) ;
2011-04-25 02:25:10 +04:00
2017-06-30 16:47:23 +03:00
if ( cpuTestCompareXML ( data - > arch , baseline , result ) < 0 )
2010-10-07 18:35:17 +04:00
goto cleanup ;
for ( i = 0 ; i < ncpus ; i + + ) {
virCPUCompareResult cmp ;
2016-08-09 14:26:53 +03:00
cmp = virCPUCompare ( cpus [ i ] - > arch , cpus [ i ] , baseline , false ) ;
2010-10-07 18:35:17 +04:00
if ( cmp ! = VIR_CPU_COMPARE_SUPERSET & &
cmp ! = VIR_CPU_COMPARE_IDENTICAL ) {
2019-05-03 11:45:58 +03:00
VIR_TEST_VERBOSE ( " \n baseline CPU is incompatible with CPU %zu " ,
2015-04-23 20:38:00 +03:00
i ) ;
VIR_TEST_VERBOSE ( " %74s " , " ... " ) ;
2010-10-07 18:35:17 +04:00
ret = - 1 ;
goto cleanup ;
}
}
ret = 0 ;
2014-03-25 10:53:44 +04:00
cleanup :
2010-10-07 18:35:17 +04:00
if ( cpus ) {
for ( i = 0 ; i < ncpus ; i + + )
virCPUDefFree ( cpus [ i ] ) ;
2012-02-03 03:16:43 +04:00
VIR_FREE ( cpus ) ;
2010-10-07 18:35:17 +04:00
}
virCPUDefFree ( baseline ) ;
return ret ;
}
static int
cpuTestUpdate ( const void * arg )
{
const struct data * data = arg ;
2021-08-20 17:00:31 +03:00
g_autoptr ( virCPUDef ) host = NULL ;
g_autoptr ( virCPUDef ) migHost = NULL ;
g_autoptr ( virCPUDef ) cpu = NULL ;
2021-08-20 17:05:08 +03:00
g_autofree char * result = NULL ;
2010-10-07 18:35:17 +04:00
if ( ! ( host = cpuTestLoadXML ( data - > arch , data - > host ) ) | |
! ( cpu = cpuTestLoadXML ( data - > arch , data - > name ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
2017-03-29 16:31:17 +03:00
if ( ! ( migHost = virCPUCopyMigratable ( data - > arch , host ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2017-03-29 16:31:17 +03:00
if ( virCPUUpdate ( host - > arch , cpu , migHost ) < 0 )
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
2019-10-22 16:26:14 +03:00
result = g_strdup_printf ( " %s+%s " , data - > host , data - > name ) ;
2011-04-25 02:25:10 +04:00
2021-08-20 17:12:04 +03:00
return cpuTestCompareXML ( data - > arch , cpu , result ) ;
2010-10-07 18:35:17 +04:00
}
static int
cpuTestHasFeature ( const void * arg )
{
const struct data * data = arg ;
2021-08-20 17:00:31 +03:00
g_autoptr ( virCPUDef ) host = NULL ;
2021-08-20 16:57:56 +03:00
g_autoptr ( virCPUData ) hostData = NULL ;
2010-10-07 18:35:17 +04:00
int result ;
if ( ! ( host = cpuTestLoadXML ( data - > arch , data - > host ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
if ( cpuEncode ( host - > arch , host , NULL , & hostData ,
NULL , NULL , NULL , NULL ) < 0 )
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
2016-09-16 15:13:09 +03:00
result = virCPUCheckFeature ( host - > arch , host , data - > name ) ;
if ( data - > result = = result )
result = virCPUDataCheckFeature ( hostData , data - > name ) ;
2010-10-07 18:35:17 +04:00
if ( data - > result = = - 1 )
virResetLastError ( ) ;
if ( data - > result ! = result ) {
2019-05-03 11:45:58 +03:00
VIR_TEST_VERBOSE ( " \n Expected result %s, got %s " ,
2015-04-23 20:38:00 +03:00
cpuTestBoolWithErrorStr ( data - > result ) ,
cpuTestBoolWithErrorStr ( result ) ) ;
/* Pad to line up with test name ... in virTestRun */
VIR_TEST_VERBOSE ( " %74s " , " ... " ) ;
2021-08-20 17:12:04 +03:00
return - 1 ;
2010-10-07 18:35:17 +04:00
}
2021-08-20 17:12:04 +03:00
return 0 ;
2010-10-07 18:35:17 +04:00
}
2017-09-27 12:58:23 +03:00
typedef enum {
2017-11-01 20:35:57 +03:00
/* No JSON data from QEMU. */
2017-09-27 12:58:23 +03:00
JSON_NONE ,
2017-11-01 20:35:57 +03:00
/* Only a reply from query-cpu-model-expansion QMP command. */
2017-09-27 12:58:23 +03:00
JSON_HOST ,
2017-11-01 20:35:57 +03:00
/* Replies from both query-cpu-model-expansion and query-cpu-definitions
* QMP commands .
*/
2017-09-27 12:58:23 +03:00
JSON_MODELS ,
2017-11-01 20:35:57 +03:00
/* Same as JSON_MODELS, but the reply from query-cpu-definitions has to
* be parsed for providing the correct result . This happens when the
* CPU model detected by libvirt has non - empty unavailable - features array
* in query - cpu - definitions reply or when the CPU model detected from CPUID
* differs from the one we get from QEMU and we need to translate them for
* comparison . Such tests require QEMU driver to be enabled .
*/
JSON_MODELS_REQUIRED ,
2017-09-27 12:58:23 +03:00
} cpuTestCPUIDJson ;
2019-12-12 20:17:08 +03:00
# if WITH_QEMU
2021-03-11 10:16:13 +03:00
static virQEMUCaps *
2017-09-27 12:58:23 +03:00
cpuTestMakeQEMUCaps ( const struct data * data )
{
2021-08-19 17:32:35 +03:00
g_autoptr ( virQEMUCaps ) qemuCaps = NULL ;
g_autoptr ( qemuMonitorTest ) testMon = NULL ;
g_autoptr ( qemuMonitorCPUModelInfo ) model = NULL ;
g_autoptr ( virCPUDef ) cpu = NULL ;
2019-09-19 23:24:56 +03:00
bool fail_no_props = true ;
2021-08-19 17:32:35 +03:00
g_autofree char * json = NULL ;
2017-09-27 12:58:23 +03:00
2019-10-22 16:26:14 +03:00
json = g_strdup_printf ( " %s/cputestdata/%s-cpuid-%s.json " , abs_srcdir ,
virArchToString ( data - > arch ) , data - > host ) ;
2017-09-27 12:58:23 +03:00
if ( ! ( testMon = qemuMonitorTestNewFromFile ( json , driver . xmlopt , true ) ) )
2021-08-19 17:32:35 +03:00
return NULL ;
2017-09-27 12:58:23 +03:00
2020-04-23 17:57:31 +03:00
qemuMonitorTestAllowUnusedCommands ( testMon ) ;
2019-11-29 14:00:26 +03:00
cpu = virCPUDefNew ( ) ;
2019-09-19 23:24:54 +03:00
2019-10-20 14:49:46 +03:00
cpu - > model = g_strdup ( " host " ) ;
2019-09-19 23:24:56 +03:00
if ( ARCH_IS_S390 ( data - > arch ) )
fail_no_props = false ;
2017-09-27 12:58:23 +03:00
if ( qemuMonitorGetCPUModelExpansion ( qemuMonitorTestGetMonitor ( testMon ) ,
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC ,
2022-12-19 17:27:08 +03:00
cpu , true , false , fail_no_props , & model ) < 0 )
2021-08-19 17:32:35 +03:00
return NULL ;
2017-09-27 12:58:23 +03:00
if ( ! ( qemuCaps = virQEMUCapsNew ( ) ) )
2021-08-19 17:32:35 +03:00
return NULL ;
2017-09-27 12:58:23 +03:00
virQEMUCapsSet ( qemuCaps , QEMU_CAPS_KVM ) ;
2017-11-01 20:35:57 +03:00
if ( data - > flags = = JSON_MODELS | |
data - > flags = = JSON_MODELS_REQUIRED )
2017-09-27 12:58:23 +03:00
virQEMUCapsSet ( qemuCaps , QEMU_CAPS_QUERY_CPU_DEFINITIONS ) ;
virQEMUCapsSetArch ( qemuCaps , data - > arch ) ;
virQEMUCapsSetCPUModelInfo ( qemuCaps , VIR_DOMAIN_VIRT_KVM , model ) ;
model = NULL ;
2019-10-23 15:08:16 +03:00
if ( virQEMUCapsProbeCPUDefinitionsTest ( qemuCaps ,
qemuMonitorTestGetMonitor ( testMon ) ) < 0 )
2021-08-19 17:32:35 +03:00
return NULL ;
2017-09-27 12:58:23 +03:00
2021-08-19 17:32:35 +03:00
return g_steal_pointer ( & qemuCaps ) ;
2017-09-27 12:58:23 +03:00
}
2017-09-27 10:29:28 +03:00
2017-11-01 20:35:57 +03:00
static int
cpuTestGetCPUModels ( const struct data * data ,
2021-03-11 10:16:13 +03:00
virDomainCapsCPUModels * * models )
2017-09-27 10:29:28 +03:00
{
2021-08-20 16:53:48 +03:00
g_autoptr ( virQEMUCaps ) qemuCaps = NULL ;
2017-09-27 10:29:28 +03:00
2017-11-01 20:35:57 +03:00
* models = NULL ;
if ( data - > flags ! = JSON_MODELS & &
data - > flags ! = JSON_MODELS_REQUIRED )
return 0 ;
2017-09-27 10:29:28 +03:00
if ( ! ( qemuCaps = cpuTestMakeQEMUCaps ( data ) ) )
2017-11-01 20:35:57 +03:00
return - 1 ;
2017-09-27 10:29:28 +03:00
2019-10-09 11:14:59 +03:00
* models = virQEMUCapsGetCPUModels ( qemuCaps , VIR_DOMAIN_VIRT_KVM , NULL , NULL ) ;
2017-09-27 10:29:28 +03:00
2017-11-01 20:35:57 +03:00
return 0 ;
2017-09-27 10:29:28 +03:00
}
2019-12-12 20:17:08 +03:00
# else /* if WITH_QEMU */
2017-09-27 10:29:28 +03:00
2017-11-01 20:35:57 +03:00
static int
cpuTestGetCPUModels ( const struct data * data ,
2021-03-11 10:16:13 +03:00
virDomainCapsCPUModels * * models )
2017-09-27 10:29:28 +03:00
{
2017-11-01 20:35:57 +03:00
* models = NULL ;
if ( data - > flags = = JSON_MODELS_REQUIRED )
return EXIT_AM_SKIP ;
return 0 ;
2017-09-27 10:29:28 +03:00
}
2017-09-27 12:58:23 +03:00
# endif
2016-06-01 16:57:00 +03:00
static int
2016-06-08 17:57:28 +03:00
cpuTestCPUID ( bool guest , const void * arg )
2016-06-01 16:57:00 +03:00
{
const struct data * data = arg ;
2021-08-20 16:57:56 +03:00
g_autoptr ( virCPUData ) hostData = NULL ;
2021-08-20 17:05:08 +03:00
g_autofree char * hostFile = NULL ;
g_autofree char * host = NULL ;
2021-08-20 17:00:31 +03:00
g_autoptr ( virCPUDef ) cpu = NULL ;
2021-08-20 17:05:08 +03:00
g_autofree char * result = NULL ;
2021-08-20 16:53:53 +03:00
g_autoptr ( virDomainCapsCPUModels ) models = NULL ;
2016-06-01 16:57:00 +03:00
2019-10-22 16:26:14 +03:00
hostFile = g_strdup_printf ( " %s/cputestdata/%s-cpuid-%s.xml " , abs_srcdir ,
virArchToString ( data - > arch ) , data - > host ) ;
2016-06-01 16:57:00 +03:00
if ( virTestLoadFile ( hostFile , & host ) < 0 | |
2016-11-04 17:02:26 +03:00
! ( hostData = virCPUDataParse ( host ) ) )
2021-09-04 23:41:46 +03:00
return - 1 ;
2016-06-01 16:57:00 +03:00
2019-11-29 14:00:26 +03:00
cpu = virCPUDefNew ( ) ;
2016-06-01 16:57:00 +03:00
cpu - > arch = hostData - > arch ;
2016-06-08 17:57:28 +03:00
if ( guest ) {
2016-06-01 16:57:00 +03:00
cpu - > type = VIR_CPU_TYPE_GUEST ;
cpu - > match = VIR_CPU_MATCH_EXACT ;
cpu - > fallback = VIR_CPU_FALLBACK_FORBID ;
} else {
cpu - > type = VIR_CPU_TYPE_HOST ;
}
2017-11-01 20:35:57 +03:00
if ( guest ) {
int rc ;
rc = cpuTestGetCPUModels ( data , & models ) ;
2021-09-04 23:41:46 +03:00
if ( rc ! = 0 )
return rc ;
2017-11-01 20:35:57 +03:00
}
2017-09-27 10:29:28 +03:00
if ( cpuDecode ( cpu , hostData , models ) < 0 )
2021-09-04 23:41:46 +03:00
return - 1 ;
2016-06-01 16:57:00 +03:00
2019-10-22 16:26:14 +03:00
result = g_strdup_printf ( " cpuid-%s-%s " , data - > host , guest ? " guest " : " host " ) ;
2016-06-01 16:57:00 +03:00
2021-09-04 23:41:46 +03:00
return cpuTestCompareXML ( data - > arch , cpu , result ) ;
2016-06-01 16:57:00 +03:00
}
2022-04-21 19:25:15 +03:00
static int
cpuTestCPUIDBaseline ( const void * arg )
{
const struct data * data = arg ;
int ret = - 1 ;
virCPUDef * * cpus = NULL ;
virCPUDef * baseline = NULL ;
g_autofree char * result = NULL ;
size_t i ;
cpus = g_new0 ( virCPUDef * , data - > ncpus ) ;
for ( i = 0 ; i < data - > ncpus ; i + + ) {
g_autofree char * name = NULL ;
name = g_strdup_printf ( " cpuid-%s-json " , data - > cpus [ i ] ) ;
if ( ! ( cpus [ i ] = cpuTestLoadXML ( data - > arch , name ) ) )
goto cleanup ;
}
baseline = virCPUBaseline ( data - > arch , cpus , data - > ncpus , NULL , NULL , false ) ;
if ( ! baseline )
goto cleanup ;
result = g_strdup_printf ( " cpuid-baseline-%s " , data - > name ) ;
if ( cpuTestCompareXML ( data - > arch , baseline , result ) < 0 )
goto cleanup ;
for ( i = 0 ; i < data - > ncpus ; i + + ) {
virCPUCompareResult cmp ;
cmp = virCPUCompare ( data - > arch , cpus [ i ] , baseline , false ) ;
if ( cmp ! = VIR_CPU_COMPARE_SUPERSET & &
cmp ! = VIR_CPU_COMPARE_IDENTICAL ) {
VIR_TEST_VERBOSE ( " \n baseline CPU is incompatible with CPU %zu " , i ) ;
VIR_TEST_VERBOSE ( " %74s " , " ... " ) ;
ret = - 1 ;
goto cleanup ;
}
}
ret = 0 ;
cleanup :
if ( cpus ) {
for ( i = 0 ; i < data - > ncpus ; i + + )
virCPUDefFree ( cpus [ i ] ) ;
VIR_FREE ( cpus ) ;
}
virCPUDefFree ( baseline ) ;
return ret ;
}
2016-06-08 17:57:28 +03:00
static int
cpuTestHostCPUID ( const void * arg )
{
return cpuTestCPUID ( false , arg ) ;
}
static int
cpuTestGuestCPUID ( const void * arg )
{
return cpuTestCPUID ( true , arg ) ;
}
2019-02-25 12:05:34 +03:00
static int
cpuTestCompareSignature ( const struct data * data ,
2021-03-11 10:16:13 +03:00
virCPUData * hostData )
2019-02-25 12:05:34 +03:00
{
2019-10-15 16:16:31 +03:00
g_autofree char * result = NULL ;
g_autofree char * sigStr = NULL ;
2019-02-25 12:05:34 +03:00
unsigned long signature ;
unsigned int family ;
unsigned int model ;
unsigned int stepping ;
signature = virCPUx86DataGetSignature ( hostData , & family , & model , & stepping ) ;
2019-10-22 16:26:14 +03:00
result = g_strdup_printf ( " %s/cputestdata/%s-cpuid-%s.sig " , abs_srcdir ,
virArchToString ( data - > arch ) , data - > host ) ;
2019-02-25 12:05:34 +03:00
2019-10-22 16:26:14 +03:00
sigStr = g_strdup_printf ( " %1$06lx \n " " family: %2$3u (0x%2$02x) \n "
" model: %3$3u (0x%3$02x) \n " " stepping: %4$3u (0x%4$02x) \n " ,
signature , family , model , stepping ) ;
2019-02-25 12:05:34 +03:00
return virTestCompareToFile ( sigStr , result ) ;
}
static int
cpuTestCPUIDSignature ( const void * arg )
{
const struct data * data = arg ;
2021-08-20 16:57:56 +03:00
g_autoptr ( virCPUData ) hostData = NULL ;
2021-08-20 17:05:08 +03:00
g_autofree char * hostFile = NULL ;
g_autofree char * host = NULL ;
2019-02-25 12:05:34 +03:00
2019-10-22 16:26:14 +03:00
hostFile = g_strdup_printf ( " %s/cputestdata/%s-cpuid-%s.xml " , abs_srcdir ,
virArchToString ( data - > arch ) , data - > host ) ;
2019-02-25 12:05:34 +03:00
if ( virTestLoadFile ( hostFile , & host ) < 0 | |
! ( hostData = virCPUDataParse ( host ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2019-02-25 12:05:34 +03:00
2021-08-20 17:12:04 +03:00
return cpuTestCompareSignature ( data , hostData ) ;
2019-02-25 12:05:34 +03:00
}
2017-03-16 14:26:30 +03:00
static int
cpuTestUpdateLiveCompare ( virArch arch ,
2021-03-11 10:16:13 +03:00
virCPUDef * actual ,
virCPUDef * expected )
2017-03-16 14:26:30 +03:00
{
size_t i , j ;
int ret = 0 ;
if ( virCPUExpandFeatures ( arch , actual ) < 0 | |
virCPUExpandFeatures ( arch , expected ) < 0 )
return - 1 ;
if ( STRNEQ ( actual - > model , expected - > model ) ) {
2019-05-03 11:45:58 +03:00
VIR_TEST_VERBOSE ( " Actual CPU model '%s', expected '%s' " ,
2017-03-16 14:26:30 +03:00
actual - > model , expected - > model ) ;
return - 1 ;
}
i = j = 0 ;
while ( i < actual - > nfeatures | | j < expected - > nfeatures ) {
2021-03-11 10:16:13 +03:00
virCPUFeatureDef * featAct = NULL ;
virCPUFeatureDef * featExp = NULL ;
2017-03-16 14:26:30 +03:00
int cmp ;
if ( i < actual - > nfeatures )
featAct = actual - > features + i ;
if ( j < expected - > nfeatures )
featExp = expected - > features + j ;
/*
* Act < Exp = > cmp < 0 ( missing entry in Exp )
* Act = Exp = > cmp = 0
* Act > Exp = > cmp > 0 ( missing entry in Act )
*
* NULL > name for any name ! = NULL
*/
if ( featAct & & featExp )
cmp = strcmp ( featAct - > name , featExp - > name ) ;
else
cmp = featExp ? 1 : - 1 ;
if ( cmp < = 0 )
i + + ;
if ( cmp > = 0 )
j + + ;
/* Possible combinations of cmp, featAct->policy, and featExp->policy:
* cmp Act Exp result
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* 0 dis dis ok
* 0 dis req missing
* 0 req dis extra
* 0 req req ok
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* - dis X ok # ignoring extra disabled features
* - req X extra
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* + X dis extra
* + X req missing
*/
if ( ( cmp = = 0 & &
featAct - > policy = = VIR_CPU_FEATURE_DISABLE & &
featExp - > policy = = VIR_CPU_FEATURE_REQUIRE ) | |
( cmp > 0 & &
featExp - > policy = = VIR_CPU_FEATURE_REQUIRE ) ) {
2019-05-03 11:45:58 +03:00
VIR_TEST_VERBOSE ( " Actual CPU lacks feature '%s' " ,
2017-03-16 14:26:30 +03:00
featExp - > name ) ;
ret = - 1 ;
continue ;
}
if ( ( cmp = = 0 & &
featAct - > policy = = VIR_CPU_FEATURE_REQUIRE & &
featExp - > policy = = VIR_CPU_FEATURE_DISABLE ) | |
2022-04-04 21:22:37 +03:00
( cmp < 0 & & featAct & &
2017-03-16 14:26:30 +03:00
featAct - > policy = = VIR_CPU_FEATURE_REQUIRE ) | |
( cmp > 0 & &
featExp - > policy = = VIR_CPU_FEATURE_DISABLE ) ) {
2019-05-03 11:45:58 +03:00
VIR_TEST_VERBOSE ( " Actual CPU has extra feature '%s' " ,
2017-09-27 12:21:36 +03:00
cmp < = 0 ? featAct - > name : featExp - > name ) ;
2017-03-16 14:26:30 +03:00
ret = - 1 ;
}
}
return ret ;
}
static int
cpuTestUpdateLive ( const void * arg )
{
const struct data * data = arg ;
2021-08-20 17:05:08 +03:00
g_autofree char * cpuFile = NULL ;
2021-08-20 17:00:31 +03:00
g_autoptr ( virCPUDef ) cpu = NULL ;
2021-08-20 17:05:08 +03:00
g_autofree char * enabledFile = NULL ;
g_autofree char * enabled = NULL ;
2021-08-20 16:57:56 +03:00
g_autoptr ( virCPUData ) enabledData = NULL ;
2021-08-20 17:05:08 +03:00
g_autofree char * disabledFile = NULL ;
g_autofree char * disabled = NULL ;
2021-08-20 16:57:56 +03:00
g_autoptr ( virCPUData ) disabledData = NULL ;
2021-08-20 17:05:08 +03:00
g_autofree char * expectedFile = NULL ;
2021-08-20 17:00:31 +03:00
g_autoptr ( virCPUDef ) expected = NULL ;
2021-08-20 16:53:53 +03:00
g_autoptr ( virDomainCapsCPUModels ) hvModels = NULL ;
g_autoptr ( virDomainCapsCPUModels ) models = NULL ;
2017-03-16 14:26:30 +03:00
2019-10-22 16:26:14 +03:00
cpuFile = g_strdup_printf ( " cpuid-%s-guest " , data - > host ) ;
if ( ! ( cpu = cpuTestLoadXML ( data - > arch , cpuFile ) ) )
2021-09-04 23:41:46 +03:00
return - 1 ;
2017-03-16 14:26:30 +03:00
2019-10-22 16:26:14 +03:00
enabledFile = g_strdup_printf ( " %s/cputestdata/%s-cpuid-%s-enabled.xml " ,
abs_srcdir , virArchToString ( data - > arch ) , data - > host ) ;
if ( virTestLoadFile ( enabledFile , & enabled ) < 0 | |
2017-03-16 14:26:30 +03:00
! ( enabledData = virCPUDataParse ( enabled ) ) )
2021-09-04 23:41:46 +03:00
return - 1 ;
2017-03-16 14:26:30 +03:00
2019-10-22 16:26:14 +03:00
disabledFile = g_strdup_printf ( " %s/cputestdata/%s-cpuid-%s-disabled.xml " ,
abs_srcdir , virArchToString ( data - > arch ) , data - > host ) ;
if ( virTestLoadFile ( disabledFile , & disabled ) < 0 | |
2017-03-16 14:26:30 +03:00
! ( disabledData = virCPUDataParse ( disabled ) ) )
2021-09-04 23:41:46 +03:00
return - 1 ;
2017-03-16 14:26:30 +03:00
2019-10-22 16:26:14 +03:00
expectedFile = g_strdup_printf ( " cpuid-%s-json " , data - > host ) ;
if ( ! ( expected = cpuTestLoadXML ( data - > arch , expectedFile ) ) )
2021-09-04 23:41:46 +03:00
return - 1 ;
2017-03-16 14:26:30 +03:00
2020-10-09 13:47:17 +03:00
/* In case the host CPU signature does not exactly match any CPU model in
* src / cpu_map , the CPU model we detect from CPUID may differ from the one
2017-09-27 10:29:28 +03:00
* we compute by asking QEMU . Since this test expands both CPU models and
* compares their features , we can try to translate the ' actual ' CPU to
* use the CPU model from ' expected ' .
*/
if ( STRNEQ ( cpu - > model , expected - > model ) ) {
2021-03-11 10:16:13 +03:00
virDomainCapsCPUModel * hvModel ;
2017-09-27 10:29:28 +03:00
char * * blockers = NULL ;
virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN ;
2017-11-01 20:35:57 +03:00
int rc ;
2017-09-27 10:29:28 +03:00
if ( ! ( models = virDomainCapsCPUModelsNew ( 0 ) ) )
2021-09-04 23:41:46 +03:00
return - 1 ;
2017-09-27 10:29:28 +03:00
2017-11-01 20:35:57 +03:00
rc = cpuTestGetCPUModels ( data , & hvModels ) ;
2021-09-04 23:41:46 +03:00
if ( rc ! = 0 )
return rc ;
2017-11-01 20:35:57 +03:00
2017-09-27 10:29:28 +03:00
hvModel = virDomainCapsCPUModelsGet ( hvModels , expected - > model ) ;
if ( hvModel ) {
blockers = hvModel - > blockers ;
usable = hvModel - > usable ;
}
2022-09-29 17:30:19 +03:00
virDomainCapsCPUModelsAdd ( models , expected - > model ,
2022-09-30 12:46:29 +03:00
usable , blockers , false , expected - > vendor ) ;
2017-09-27 10:29:28 +03:00
cpu - > fallback = VIR_CPU_FALLBACK_ALLOW ;
ignore_value ( virCPUTranslate ( data - > arch , cpu , models ) ) ;
cpu - > fallback = VIR_CPU_FALLBACK_FORBID ;
}
if ( virCPUUpdateLive ( data - > arch , cpu , enabledData , disabledData ) < 0 )
2021-09-04 23:41:46 +03:00
return - 1 ;
2017-03-16 14:26:30 +03:00
2021-09-04 23:41:46 +03:00
return cpuTestUpdateLiveCompare ( data - > arch , cpu , expected ) ;
2017-03-16 14:26:30 +03:00
}
2019-12-12 20:17:08 +03:00
# if WITH_QEMU
2016-06-01 16:57:00 +03:00
static int
cpuTestJSONCPUID ( const void * arg )
{
const struct data * data = arg ;
2021-08-20 16:53:48 +03:00
g_autoptr ( virQEMUCaps ) qemuCaps = NULL ;
2021-08-20 17:00:31 +03:00
g_autoptr ( virCPUDef ) cpu = NULL ;
2021-08-20 17:05:08 +03:00
g_autofree char * result = NULL ;
2016-06-01 16:57:00 +03:00
2019-10-22 16:26:14 +03:00
result = g_strdup_printf ( " cpuid-%s-json " , data - > host ) ;
2016-06-01 16:57:00 +03:00
2017-09-27 12:58:23 +03:00
if ( ! ( qemuCaps = cpuTestMakeQEMUCaps ( data ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2017-09-26 22:08:37 +03:00
2019-11-29 14:00:26 +03:00
cpu = virCPUDefNew ( ) ;
2017-02-13 12:33:52 +03:00
cpu - > arch = data - > arch ;
2016-06-01 16:57:00 +03:00
cpu - > type = VIR_CPU_TYPE_GUEST ;
cpu - > match = VIR_CPU_MATCH_EXACT ;
cpu - > fallback = VIR_CPU_FALLBACK_FORBID ;
2017-03-29 14:33:50 +03:00
if ( virQEMUCapsInitCPUModel ( qemuCaps , VIR_DOMAIN_VIRT_KVM , cpu , false ) ! = 0 )
2021-08-20 17:12:04 +03:00
return - 1 ;
2016-06-01 16:57:00 +03:00
2021-08-20 17:12:04 +03:00
return cpuTestCompareXML ( data - > arch , cpu , result ) ;
2016-06-01 16:57:00 +03:00
}
2019-02-25 12:05:34 +03:00
static int
cpuTestJSONSignature ( const void * arg )
{
const struct data * data = arg ;
2021-08-20 16:53:48 +03:00
g_autoptr ( virQEMUCaps ) qemuCaps = NULL ;
2021-08-20 16:57:56 +03:00
g_autoptr ( virCPUData ) hostData = NULL ;
2021-03-11 10:16:13 +03:00
qemuMonitorCPUModelInfo * modelInfo ;
2019-02-25 12:05:34 +03:00
if ( ! ( qemuCaps = cpuTestMakeQEMUCaps ( data ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2019-02-25 12:05:34 +03:00
modelInfo = virQEMUCapsGetCPUModelInfo ( qemuCaps , VIR_DOMAIN_VIRT_KVM ) ;
2019-06-17 14:54:53 +03:00
if ( ! ( hostData = virQEMUCapsGetCPUModelX86Data ( qemuCaps , modelInfo , false ) ) )
2021-08-20 17:12:04 +03:00
return - 1 ;
2019-02-25 12:05:34 +03:00
2021-08-20 17:12:04 +03:00
return cpuTestCompareSignature ( data , hostData ) ;
2019-02-25 12:05:34 +03:00
}
2016-06-01 16:57:00 +03:00
# endif
2017-09-22 16:51:33 +03:00
static const char * model486_list [ ] = { " 486 " , NULL } ;
static const char * nomodel_list [ ] = { " nomodel " , NULL } ;
static const char * models_list [ ] = { " qemu64 " , " core2duo " , " Nehalem " , NULL } ;
static const char * haswell_list [ ] = { " SandyBridge " , " Haswell " , NULL } ;
static const char * ppc_models_list [ ] = { " POWER6 " , " POWER7 " , " POWER8 " , NULL } ;
2021-03-11 10:16:13 +03:00
static virDomainCapsCPUModels *
2017-09-22 16:51:33 +03:00
cpuTestInitModels ( const char * * list )
{
2021-03-11 10:16:13 +03:00
virDomainCapsCPUModels * cpus ;
2017-09-22 16:51:33 +03:00
const char * * model ;
if ( ! ( cpus = virDomainCapsCPUModelsNew ( 0 ) ) )
return NULL ;
for ( model = list ; * model ; model + + ) {
2022-09-29 17:30:19 +03:00
virDomainCapsCPUModelsAdd ( cpus , * model ,
2022-09-30 12:46:29 +03:00
VIR_DOMCAPS_CPU_USABLE_UNKNOWN ,
NULL , false , NULL ) ;
2017-09-22 16:51:33 +03:00
}
return cpus ;
}
2010-10-07 18:35:17 +04:00
static int
2011-04-29 20:21:20 +04:00
mymain ( void )
2010-10-07 18:35:17 +04:00
{
2021-03-11 10:16:13 +03:00
virDomainCapsCPUModels * model486 = NULL ;
virDomainCapsCPUModels * nomodel = NULL ;
virDomainCapsCPUModels * models = NULL ;
virDomainCapsCPUModels * haswell = NULL ;
virDomainCapsCPUModels * ppc_models = NULL ;
2010-10-07 18:35:17 +04:00
int ret = 0 ;
2019-12-12 20:17:08 +03:00
# if WITH_QEMU
2016-06-01 16:57:00 +03:00
if ( qemuTestDriverInit ( & driver ) < 0 )
return EXIT_FAILURE ;
virEventRegisterDefaultImpl ( ) ;
# endif
2017-09-22 16:51:33 +03:00
if ( ! ( model486 = cpuTestInitModels ( model486_list ) ) | |
! ( nomodel = cpuTestInitModels ( nomodel_list ) ) | |
! ( models = cpuTestInitModels ( models_list ) ) | |
! ( haswell = cpuTestInitModels ( haswell_list ) ) | |
! ( ppc_models = cpuTestInitModels ( ppc_models_list ) ) ) {
ret = - 1 ;
goto cleanup ;
}
2022-04-21 19:25:15 +03:00
# define DO_TEST(arch, api, name, host, cpu, cpus, ncpus, \
2017-11-03 15:09:47 +03:00
models , flags , result ) \
do { \
struct data data = { \
arch , host , cpu , models , \
models = = NULL ? NULL : # models , \
2022-04-21 19:25:15 +03:00
cpus , ncpus , flags , result \
2017-11-03 15:09:47 +03:00
} ; \
2021-08-20 17:05:08 +03:00
g_autofree char * testLabel = NULL ; \
2017-11-03 15:09:47 +03:00
\
2019-10-22 16:26:14 +03:00
testLabel = g_strdup_printf ( " %s(%s): %s " , # api , \
virArchToString ( arch ) , name ) ; \
2017-11-03 15:09:47 +03:00
\
2021-08-20 17:29:45 +03:00
virTestRunLog ( & ret , testLabel , api , & data ) ; \
2010-10-07 18:35:17 +04:00
} while ( 0 )
2017-11-03 15:09:47 +03:00
# define DO_TEST_COMPARE(arch, host, cpu, result) \
DO_TEST ( arch , cpuTestCompare , \
host " / " cpu " ( " # result " ) " , \
2022-04-21 19:25:15 +03:00
host , cpu , NULL , 0 , NULL , 0 , result )
2010-10-07 18:35:17 +04:00
2017-11-03 15:09:47 +03:00
# define DO_TEST_UPDATE_ONLY(arch, host, cpu) \
DO_TEST ( arch , cpuTestUpdate , \
cpu " on " host , \
2022-04-21 19:25:15 +03:00
host , cpu , NULL , 0 , NULL , 0 , 0 )
2016-06-23 16:27:07 +03:00
2017-11-03 15:09:47 +03:00
# define DO_TEST_UPDATE(arch, host, cpu, result) \
do { \
DO_TEST_UPDATE_ONLY ( arch , host , cpu ) ; \
DO_TEST_COMPARE ( arch , host , host " + " cpu , result ) ; \
2010-10-07 18:35:17 +04:00
} while ( 0 )
2017-11-03 15:09:47 +03:00
# define DO_TEST_BASELINE(arch, name, flags, result) \
do { \
const char * suffix = " " ; \
2021-08-20 17:05:08 +03:00
g_autofree char * label = NULL ; \
2017-11-03 15:09:47 +03:00
if ( ( flags ) & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES ) \
suffix = " (expanded) " ; \
if ( ( flags ) & VIR_CONNECT_BASELINE_CPU_MIGRATABLE ) \
suffix = " (migratable) " ; \
2019-10-22 16:26:14 +03:00
label = g_strdup_printf ( " %s%s " , name , suffix ) ; \
DO_TEST ( arch , cpuTestBaseline , label , NULL , \
2022-04-21 19:25:15 +03:00
" baseline- " name , NULL , 0 , NULL , flags , result ) ; \
2014-01-28 03:00:44 +04:00
} while ( 0 )
2010-10-07 18:35:17 +04:00
2017-11-03 15:09:47 +03:00
# define DO_TEST_HASFEATURE(arch, host, feature, result) \
DO_TEST ( arch , cpuTestHasFeature , \
host " / " feature " ( " # result " ) " , \
2022-04-21 19:25:15 +03:00
host , feature , NULL , 0 , NULL , 0 , result )
2010-10-07 18:35:17 +04:00
2017-11-03 15:09:47 +03:00
# define DO_TEST_GUESTCPU(arch, host, cpu, models, result) \
DO_TEST ( arch , cpuTestGuestCPU , \
host " / " cpu " ( " # models " ) " , \
2022-04-21 19:25:15 +03:00
host , cpu , NULL , 0 , models , 0 , result )
2010-10-07 18:35:17 +04:00
2019-12-12 20:17:08 +03:00
# if WITH_QEMU
2017-11-03 15:09:47 +03:00
# define DO_TEST_JSON(arch, host, json) \
do { \
if ( json = = JSON_MODELS ) { \
DO_TEST ( arch , cpuTestGuestCPUID , host , host , \
2022-04-21 19:25:15 +03:00
NULL , NULL , 0 , NULL , 0 , 0 ) ; \
2017-11-03 15:09:47 +03:00
} \
if ( json ! = JSON_NONE ) { \
DO_TEST ( arch , cpuTestJSONCPUID , host , host , \
2022-04-21 19:25:15 +03:00
NULL , NULL , 0 , NULL , json , 0 ) ; \
2019-02-25 12:05:34 +03:00
DO_TEST ( arch , cpuTestJSONSignature , host , host , \
2022-04-21 19:25:15 +03:00
NULL , NULL , 0 , NULL , 0 , 0 ) ; \
2017-11-03 15:09:47 +03:00
} \
2016-06-01 16:57:00 +03:00
} while ( 0 )
# else
2017-11-01 20:35:57 +03:00
# define DO_TEST_JSON(arch, host, json)
2016-06-01 16:57:00 +03:00
# endif
2017-11-03 15:09:47 +03:00
# define DO_TEST_CPUID(arch, host, json) \
do { \
DO_TEST ( arch , cpuTestHostCPUID , host , host , \
2022-04-21 19:25:15 +03:00
NULL , NULL , 0 , NULL , 0 , 0 ) ; \
2017-11-03 15:09:47 +03:00
DO_TEST ( arch , cpuTestGuestCPUID , host , host , \
2022-04-21 19:25:15 +03:00
NULL , NULL , 0 , NULL , json , 0 ) ; \
2019-02-25 12:05:34 +03:00
DO_TEST ( arch , cpuTestCPUIDSignature , host , host , \
2022-04-21 19:25:15 +03:00
NULL , NULL , 0 , NULL , 0 , 0 ) ; \
2017-11-03 15:09:47 +03:00
DO_TEST_JSON ( arch , host , json ) ; \
if ( json ! = JSON_NONE ) { \
DO_TEST ( arch , cpuTestUpdateLive , host , host , \
2022-04-21 19:25:15 +03:00
NULL , NULL , 0 , NULL , json , 0 ) ; \
2017-11-03 15:09:47 +03:00
} \
2016-06-01 16:57:00 +03:00
} while ( 0 )
2022-04-21 19:25:15 +03:00
# define DO_TEST_CPUID_BASELINE(arch, label, cpu1, cpu2) \
do { \
const char * cpus [ ] = { cpu1 , cpu2 } ; \
DO_TEST ( arch , cpuTestCPUIDBaseline , \
label " ( " cpu1 " , " cpu2 " ) " , \
NULL , label , cpus , 2 , NULL , 0 , 0 ) ; \
} while ( 0 )
2010-10-07 18:35:17 +04:00
/* host to host comparison */
2017-02-13 16:18:55 +03:00
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " host " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " host-better " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " host-worse " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " host-amd-fake " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " host-incomp-arch " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " host-no-vendor " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host-no-vendor " , " host " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " host " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " host-better " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " host-worse " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " host-incomp-arch " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " host-no-vendor " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host-no-vendor " , " host " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
2015-08-07 18:39:21 +03:00
2010-10-07 18:35:17 +04:00
/* guest to host comparison */
2017-02-13 16:18:55 +03:00
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " bogus-model " , VIR_CPU_COMPARE_ERROR ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " bogus-feature " , VIR_CPU_COMPARE_ERROR ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " min " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " pentium3 " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact-forbid " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact-forbid-extra " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact-disable " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact-disable2 " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact-disable-extra " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact-require " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact-require-extra " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " exact-force " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " strict " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " strict-full " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " strict-disable " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " strict-force-extra " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " guest " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host " , " pentium3-amd " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host-amd " , " pentium3-amd " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host-worse " , " penryn-force " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_X86_64 , " host-SandyBridge " , " exact-force-Haswell " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-strict " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-exact " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-legacy " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-legacy-incompatible " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
2020-10-07 11:54:56 +03:00
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-legacy-bad " , VIR_CPU_COMPARE_ERROR ) ;
2017-02-13 16:18:55 +03:00
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-compat-none " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-compat-valid " , VIR_CPU_COMPARE_IDENTICAL ) ;
2020-10-07 11:54:56 +03:00
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-compat-bad " , VIR_CPU_COMPARE_ERROR ) ;
2017-02-13 16:18:55 +03:00
DO_TEST_COMPARE ( VIR_ARCH_PPC64 , " host " , " guest-compat-incompatible " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
2013-09-03 10:28:25 +04:00
2010-10-07 18:35:17 +04:00
/* guest updates for migration
* automatically compares host CPU with the result */
2017-02-13 16:18:55 +03:00
DO_TEST_UPDATE ( VIR_ARCH_X86_64 , " host " , " min " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_UPDATE ( VIR_ARCH_X86_64 , " host " , " pentium3 " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_UPDATE ( VIR_ARCH_X86_64 , " host " , " guest " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_UPDATE ( VIR_ARCH_X86_64 , " host " , " host-model " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_UPDATE ( VIR_ARCH_X86_64 , " host " , " host-model-nofallback " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_UPDATE ( VIR_ARCH_X86_64 , " host-invtsc " , " host-model " , VIR_CPU_COMPARE_SUPERSET ) ;
DO_TEST_UPDATE_ONLY ( VIR_ARCH_X86_64 , " host " , " host-passthrough " ) ;
DO_TEST_UPDATE_ONLY ( VIR_ARCH_X86_64 , " host " , " host-passthrough-features " ) ;
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest-nofallback " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest-legacy " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest-legacy-incompatible " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
2020-10-07 11:54:56 +03:00
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest-legacy-bad " , VIR_CPU_COMPARE_ERROR ) ;
2017-02-13 16:18:55 +03:00
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest-compat-none " , VIR_CPU_COMPARE_IDENTICAL ) ;
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest-compat-valid " , VIR_CPU_COMPARE_IDENTICAL ) ;
2020-10-07 11:54:56 +03:00
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest-compat-bad " , VIR_CPU_COMPARE_ERROR ) ;
2017-02-13 16:18:55 +03:00
DO_TEST_UPDATE ( VIR_ARCH_PPC64 , " host " , " guest-compat-incompatible " , VIR_CPU_COMPARE_INCOMPATIBLE ) ;
2015-08-14 17:45:18 +03:00
2010-10-07 18:35:17 +04:00
/* computing baseline CPUs */
2017-02-13 16:18:55 +03:00
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " incompatible-vendors " , 0 , - 1 ) ;
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " no-vendor " , 0 , 0 ) ;
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " some-vendors " , 0 , 0 ) ;
2022-05-04 17:28:03 +03:00
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " simple " , 0 , 0 ) ;
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " simple " , VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES , 0 ) ;
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " features " , 0 , 0 ) ;
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " features " , VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES , 0 ) ;
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " Westmere+Nehalem " , 0 , 0 ) ;
DO_TEST_BASELINE ( VIR_ARCH_X86_64 , " Westmere+Nehalem " , VIR_CONNECT_BASELINE_CPU_MIGRATABLE , 0 ) ;
2017-02-13 16:18:55 +03:00
DO_TEST_BASELINE ( VIR_ARCH_PPC64 , " incompatible-vendors " , 0 , - 1 ) ;
DO_TEST_BASELINE ( VIR_ARCH_PPC64 , " no-vendor " , 0 , 0 ) ;
DO_TEST_BASELINE ( VIR_ARCH_PPC64 , " incompatible-models " , 0 , - 1 ) ;
DO_TEST_BASELINE ( VIR_ARCH_PPC64 , " same-model " , 0 , 0 ) ;
DO_TEST_BASELINE ( VIR_ARCH_PPC64 , " legacy " , 0 , - 1 ) ;
2015-08-07 18:39:12 +03:00
2010-10-07 18:35:17 +04:00
/* CPU features */
2017-02-13 16:18:55 +03:00
DO_TEST_HASFEATURE ( VIR_ARCH_X86_64 , " host " , " vmx " , YES ) ;
DO_TEST_HASFEATURE ( VIR_ARCH_X86_64 , " host " , " lm " , YES ) ;
DO_TEST_HASFEATURE ( VIR_ARCH_X86_64 , " host " , " sse4.1 " , YES ) ;
DO_TEST_HASFEATURE ( VIR_ARCH_X86_64 , " host " , " 3dnowext " , NO ) ;
DO_TEST_HASFEATURE ( VIR_ARCH_X86_64 , " host " , " skinit " , NO ) ;
DO_TEST_HASFEATURE ( VIR_ARCH_X86_64 , " host " , " foo " , FAIL ) ;
2010-10-07 18:35:17 +04:00
/* computing guest data and decoding the data into a guest CPU XML */
2017-02-13 16:18:55 +03:00
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " guest " , NULL , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host-better " , " pentium3 " , NULL , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host-worse " , " guest " , NULL , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " strict-force-extra " , NULL , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " penryn-force " , NULL , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " guest " , model486 , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " guest " , models , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " guest " , nomodel , - 1 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " guest-nofallback " , models , - 1 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " host+host-model " , models , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host " , " host+host-model-nofallback " , models , - 1 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host-Haswell-noTSX " , " Haswell " , haswell , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host-Haswell-noTSX " , " Haswell-noTSX " , haswell , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host-Haswell-noTSX " , " Haswell-noTSX-nofallback " , haswell , - 1 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_X86_64 , " host-Haswell-noTSX " , " Haswell-noTSX " , NULL , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_PPC64 , " host " , " guest " , ppc_models , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_PPC64 , " host " , " guest-nofallback " , ppc_models , - 1 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_PPC64 , " host " , " guest-legacy " , ppc_models , 0 ) ;
DO_TEST_GUESTCPU ( VIR_ARCH_PPC64 , " host " , " guest-legacy-incompatible " , ppc_models , - 1 ) ;
2020-10-07 11:54:56 +03:00
DO_TEST_GUESTCPU ( VIR_ARCH_PPC64 , " host " , " guest-legacy-bad " , ppc_models , - 1 ) ;
2017-02-13 16:18:55 +03:00
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " A10-5800K " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Atom-D510 " , JSON_NONE ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Atom-N450 " , JSON_NONE ) ;
2021-01-06 13:05:05 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Atom-P5362 " , JSON_MODELS_REQUIRED ) ;
2018-04-11 11:57:31 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i5-650 " , JSON_MODELS_REQUIRED ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i5-2500 " , JSON_HOST ) ;
2017-09-27 00:07:47 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i5-2540M " , JSON_MODELS ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i5-4670T " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i5-6600 " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-2600 " , JSON_HOST ) ;
2017-11-01 20:35:57 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-2600-xsaveopt " , JSON_MODELS_REQUIRED ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-3520M " , JSON_NONE ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-3740QM " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-3770 " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-4600U " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-4510U " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-5600U " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-5600U-arat " , JSON_HOST ) ;
2018-01-09 02:02:44 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-5600U-ibrs " , JSON_HOST ) ;
2019-02-22 00:14:53 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-7600U " , JSON_MODELS ) ;
2017-10-02 16:51:21 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-7700 " , JSON_MODELS ) ;
2020-03-06 12:50:11 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-8550U " , JSON_MODELS ) ;
2019-03-04 18:45:48 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core-i7-8700 " , JSON_MODELS ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core2-E6850 " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Core2-Q9500 " , JSON_NONE ) ;
2019-12-12 05:58:20 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Hygon-C86-7185-32-core " , JSON_HOST ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " EPYC-7601-32-Core " , JSON_HOST ) ;
2018-01-05 17:58:07 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " EPYC-7601-32-Core-ibpb " , JSON_MODELS_REQUIRED ) ;
2020-10-01 13:22:01 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " EPYC-7502-32-Core " , JSON_MODELS ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " FX-8150 " , JSON_NONE ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Opteron-1352 " , JSON_NONE ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Opteron-2350 " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Opteron-6234 " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Opteron-6282 " , JSON_NONE ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Pentium-P6100 " , JSON_NONE ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Phenom-B95 " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Ryzen-7-1800X-Eight-Core " , JSON_HOST ) ;
2020-10-07 18:35:15 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Ryzen-9-3900X-12-Core " , JSON_MODELS ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-5110 " , JSON_NONE ) ;
2019-04-05 12:19:30 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E3-1225-v5 " , JSON_MODELS ) ;
2017-11-02 16:43:37 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E3-1245-v5 " , JSON_MODELS ) ;
2018-01-05 16:52:45 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E5-2609-v3 " , JSON_MODELS ) ;
2018-01-05 17:03:12 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E5-2623-v4 " , JSON_MODELS ) ;
2017-11-02 16:43:37 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E5-2630-v3 " , JSON_HOST ) ;
2019-02-21 23:51:58 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E5-2630-v4 " , JSON_MODELS ) ;
2019-02-27 11:49:36 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E5-2650 " , JSON_MODELS ) ;
2017-11-02 16:43:37 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E5-2650-v3 " , JSON_HOST ) ;
2017-11-02 22:50:25 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E5-2650-v4 " , JSON_MODELS ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E7-4820 " , JSON_HOST ) ;
2017-11-01 20:35:57 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E7-4830 " , JSON_MODELS_REQUIRED ) ;
2017-11-02 16:43:37 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E7-8890-v3 " , JSON_MODELS ) ;
2019-02-26 23:22:25 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-E7540 " , JSON_MODELS ) ;
2018-01-05 17:43:16 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-Gold-5115 " , JSON_MODELS ) ;
2019-10-17 11:01:29 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-Gold-6130 " , JSON_MODELS ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-Gold-6148 " , JSON_HOST ) ;
2019-03-19 14:33:31 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-Platinum-8268 " , JSON_HOST ) ;
2020-03-18 00:38:21 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-Platinum-9242 " , JSON_MODELS ) ;
2017-09-26 22:01:56 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-W3520 " , JSON_HOST ) ;
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Xeon-X5460 " , JSON_NONE ) ;
2019-10-18 14:50:19 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Ice-Lake-Server " , JSON_MODELS ) ;
2020-05-19 21:18:12 +03:00
DO_TEST_CPUID ( VIR_ARCH_X86_64 , " Cooperlake " , JSON_MODELS ) ;
2016-06-06 15:43:07 +03:00
2022-04-21 19:25:15 +03:00
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Ryzen+Rome " ,
" Ryzen-7-1800X-Eight-Core " , " Ryzen-9-3900X-12-Core " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " EPYC+Rome " ,
" EPYC-7601-32-Core " , " EPYC-7502-32-Core " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Haswell-noTSX-IBRS+Skylake " ,
" Xeon-E5-2609-v3 " , " Xeon-Gold-6148 " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Haswell-noTSX-IBRS+Skylake-IBRS " ,
" Xeon-E5-2609-v3 " , " Xeon-Gold-6130 " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Broadwell-IBRS+Cascadelake " ,
" Xeon-E5-2623-v4 " , " Xeon-Platinum-8268 " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Cascadelake+Skylake-IBRS " ,
" Xeon-Platinum-8268 " , " Xeon-Gold-6130 " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Cascadelake+Skylake " ,
" Xeon-Platinum-9242 " , " Xeon-Gold-6148 " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Cascadelake+Icelake " ,
" Xeon-Platinum-9242 " , " Ice-Lake-Server " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Cooperlake+Icelake " ,
" Cooperlake " , " Ice-Lake-Server " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Cooperlake+Cascadelake " ,
" Cooperlake " , " Xeon-Platinum-9242 " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Skylake-Client+Server " ,
" Core-i5-6600 " , " Xeon-Gold-6148 " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Haswell-noTSX-IBRS+Broadwell " ,
" Xeon-E5-2609-v3 " , " Xeon-E5-2650-v4 " ) ;
DO_TEST_CPUID_BASELINE ( VIR_ARCH_X86_64 , " Haswell+Skylake " ,
" Xeon-E7-8890-v3 " , " Xeon-Gold-5115 " ) ;
2017-09-22 16:51:33 +03:00
cleanup :
2019-12-12 20:17:08 +03:00
# if WITH_QEMU
2016-06-01 16:57:00 +03:00
qemuTestDriverFree ( & driver ) ;
# endif
2017-09-22 16:51:33 +03:00
virObjectUnref ( model486 ) ;
virObjectUnref ( nomodel ) ;
virObjectUnref ( models ) ;
virObjectUnref ( haswell ) ;
virObjectUnref ( ppc_models ) ;
2012-03-22 15:33:35 +04:00
return ret = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
2010-10-07 18:35:17 +04:00
}
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )