1 #include "qemu/osdep.h"
2 #include "qemu-common.h"
3 #include "qapi/qmp/qlist.h"
4 #include "qapi/qmp/qdict.h"
5 #include "qapi/qmp/qint.h"
8 static char *get_cpu0_qom_path(void)
15 resp
= qmp("{'execute': 'query-cpus', 'arguments': {}}");
16 g_assert(qdict_haskey(resp
, "return"));
17 ret
= qdict_get_qlist(resp
, "return");
19 cpu0
= qobject_to_qdict(qlist_peek(ret
));
20 path
= g_strdup(qdict_get_str(cpu0
, "qom_path"));
25 static QObject
*qom_get(const char *path
, const char *prop
)
27 QDict
*resp
= qmp("{ 'execute': 'qom-get',"
28 " 'arguments': { 'path': %s,"
29 " 'property': %s } }",
31 QObject
*ret
= qdict_get(resp
, "return");
37 typedef struct CpuidTestArgs
{
40 int64_t expected_value
;
43 static void test_cpuid_prop(const void *data
)
45 const CpuidTestArgs
*args
= data
;
49 qtest_start(args
->cmdline
);
50 path
= get_cpu0_qom_path();
51 value
= qobject_to_qint(qom_get(path
, args
->property
));
52 g_assert_cmpint(qint_get_int(value
), ==, args
->expected_value
);
59 static void add_cpuid_test(const char *name
, const char *cmdline
,
60 const char *property
, int64_t expected_value
)
62 CpuidTestArgs
*args
= g_new0(CpuidTestArgs
, 1);
63 args
->cmdline
= cmdline
;
64 args
->property
= property
;
65 args
->expected_value
= expected_value
;
66 qtest_add_data_func(name
, args
, test_cpuid_prop
);
69 int main(int argc
, char **argv
)
71 g_test_init(&argc
, &argv
, NULL
);
73 /* Original level values for CPU models: */
74 add_cpuid_test("x86/cpuid/phenom/level",
75 "-cpu phenom", "level", 5);
76 add_cpuid_test("x86/cpuid/Conroe/level",
77 "-cpu Conroe", "level", 10);
78 add_cpuid_test("x86/cpuid/SandyBridge/level",
79 "-cpu SandyBridge", "level", 0xd);
80 add_cpuid_test("x86/cpuid/486/xlevel",
81 "-cpu 486", "xlevel", 0);
82 add_cpuid_test("x86/cpuid/core2duo/xlevel",
83 "-cpu core2duo", "xlevel", 0x80000008);
84 add_cpuid_test("x86/cpuid/phenom/xlevel",
85 "-cpu phenom", "xlevel", 0x8000001A);
86 add_cpuid_test("x86/cpuid/athlon/xlevel",
87 "-cpu athlon", "xlevel", 0x80000008);
89 /* If level is not large enough, it should increase automatically: */
91 add_cpuid_test("x86/cpuid/auto-level/phenom/arat",
92 "-cpu 486,+arat", "level", 6);
93 /* CPUID[EAX=7,ECX=0].EBX: */
94 add_cpuid_test("x86/cpuid/auto-level/phenom/fsgsbase",
95 "-cpu phenom,+fsgsbase", "level", 7);
96 /* CPUID[EAX=7,ECX=0].ECX: */
97 add_cpuid_test("x86/cpuid/auto-level/phenom/avx512vbmi",
98 "-cpu phenom,+avx512vbmi", "level", 7);
99 /* CPUID[EAX=0xd,ECX=1].EAX: */
100 add_cpuid_test("x86/cpuid/auto-level/phenom/xsaveopt",
101 "-cpu phenom,+xsaveopt", "level", 0xd);
102 /* CPUID[8000_0001].EDX: */
103 add_cpuid_test("x86/cpuid/auto-xlevel/486/3dnow",
104 "-cpu 486,+3dnow", "xlevel", 0x80000001);
105 /* CPUID[8000_0001].ECX: */
106 add_cpuid_test("x86/cpuid/auto-xlevel/486/sse4a",
107 "-cpu 486,+sse4a", "xlevel", 0x80000001);
108 /* CPUID[8000_0007].EDX: */
109 add_cpuid_test("x86/cpuid/auto-xlevel/486/invtsc",
110 "-cpu 486,+invtsc", "xlevel", 0x80000007);
111 /* CPUID[8000_000A].EDX: */
112 add_cpuid_test("x86/cpuid/auto-xlevel/486/npt",
113 "-cpu 486,+npt", "xlevel", 0x8000000A);
114 /* CPUID[C000_0001].EDX: */
115 add_cpuid_test("x86/cpuid/auto-xlevel2/phenom/xstore",
116 "-cpu phenom,+xstore", "xlevel2", 0xC0000001);
117 /* SVM needs CPUID[0x8000000A] */
118 add_cpuid_test("x86/cpuid/auto-xlevel/athlon/svm",
119 "-cpu athlon,+svm", "xlevel", 0x8000000A);
122 /* If level is already large enough, it shouldn't change: */
123 add_cpuid_test("x86/cpuid/auto-level/SandyBridge/multiple",
124 "-cpu SandyBridge,+arat,+fsgsbase,+avx512vbmi",
126 /* If level is explicitly set, it shouldn't change: */
127 add_cpuid_test("x86/cpuid/auto-level/486/fixed/0xF",
128 "-cpu 486,level=0xF,+arat,+fsgsbase,+avx512vbmi,+xsaveopt",
130 add_cpuid_test("x86/cpuid/auto-level/486/fixed/2",
131 "-cpu 486,level=2,+arat,+fsgsbase,+avx512vbmi,+xsaveopt",
133 add_cpuid_test("x86/cpuid/auto-level/486/fixed/0",
134 "-cpu 486,level=0,+arat,+fsgsbase,+avx512vbmi,+xsaveopt",
137 /* if xlevel is already large enough, it shouldn't change: */
138 add_cpuid_test("x86/cpuid/auto-xlevel/phenom/3dnow",
139 "-cpu phenom,+3dnow,+sse4a,+invtsc,+npt,+svm",
140 "xlevel", 0x8000001A);
141 /* If xlevel is explicitly set, it shouldn't change: */
142 add_cpuid_test("x86/cpuid/auto-xlevel/486/fixed/80000002",
143 "-cpu 486,xlevel=0x80000002,+3dnow,+sse4a,+invtsc,+npt,+svm",
144 "xlevel", 0x80000002);
145 add_cpuid_test("x86/cpuid/auto-xlevel/486/fixed/8000001A",
146 "-cpu 486,xlevel=0x8000001A,+3dnow,+sse4a,+invtsc,+npt,+svm",
147 "xlevel", 0x8000001A);
148 add_cpuid_test("x86/cpuid/auto-xlevel/phenom/fixed/0",
149 "-cpu 486,xlevel=0,+3dnow,+sse4a,+invtsc,+npt,+svm",
152 /* if xlevel2 is already large enough, it shouldn't change: */
153 add_cpuid_test("x86/cpuid/auto-xlevel2/486/fixed",
154 "-cpu 486,xlevel2=0xC0000002,+xstore",
155 "xlevel2", 0xC0000002);
157 /* Check compatibility of old machine-types that didn't
158 * auto-increase level/xlevel/xlevel2: */
160 add_cpuid_test("x86/cpuid/auto-level/pc-2.7",
161 "-machine pc-i440fx-2.7 -cpu 486,+arat,+avx512vbmi,+xsaveopt",
163 add_cpuid_test("x86/cpuid/auto-xlevel/pc-2.7",
164 "-machine pc-i440fx-2.7 -cpu 486,+3dnow,+sse4a,+invtsc,+npt,+svm",
166 add_cpuid_test("x86/cpuid/auto-xlevel2/pc-2.7",
167 "-machine pc-i440fx-2.7 -cpu 486,+xstore",