mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
tests/cpu-policy: Confirm that CPUID serialisation is sorted
The existing x86_cpuid_copy_to_buffer() does produce sorted results, and we're about to start relying on this. Extend the unit tests. As test_cpuid_serialise_success() is a fairly limited set of synthetic examples right now, introduce test_cpuid_current() to operate on the full policy for the current CPU. Tweak the fail() macro to allow for simplified control flow. Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Reviewed-by: Jan Beulich <jbeulich@suse.com> Release-acked-by: Paul Durrant <paul@xen.org>
This commit is contained in:
1 parent
700738bf6a
commit
c22ced93e1
1 file changed
+48
-1
@@ -16,7 +16,7 @@ static unsigned int nr_failures;
|
||||
#define fail(fmt, ...) \
|
||||
({ \
|
||||
nr_failures++; \
|
||||
printf(fmt, ##__VA_ARGS__); \
|
||||
(void)printf(fmt, ##__VA_ARGS__); \
|
||||
})
|
||||
|
||||
#define memdup(ptr) \
|
||||
@@ -66,6 +66,45 @@ static void test_vendor_identification(void)
|
||||
}
|
||||
}
|
||||
|
||||
static bool leaves_are_sorted(const xen_cpuid_leaf_t *leaves, unsigned int nr)
|
||||
{
|
||||
for ( unsigned int i = 1; i < nr; ++i )
|
||||
{
|
||||
/* leaf index went backwards => not sorted. */
|
||||
if ( leaves[i - 1].leaf > leaves[i].leaf )
|
||||
return false;
|
||||
|
||||
/* leaf index went forwards => ok */
|
||||
if ( leaves[i - 1].leaf < leaves[i].leaf )
|
||||
continue;
|
||||
|
||||
/* leave index the same, subleaf didn't increase => not sorted. */
|
||||
if ( leaves[i - 1].subleaf >= leaves[i].subleaf )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void test_cpuid_current(void)
|
||||
{
|
||||
struct cpuid_policy p;
|
||||
xen_cpuid_leaf_t leaves[CPUID_MAX_SERIALISED_LEAVES];
|
||||
unsigned int nr = ARRAY_SIZE(leaves);
|
||||
int rc;
|
||||
|
||||
printf("Testing CPUID on current CPU\n");
|
||||
|
||||
x86_cpuid_policy_fill_native(&p);
|
||||
|
||||
rc = x86_cpuid_copy_to_buffer(&p, leaves, &nr);
|
||||
if ( rc != 0 )
|
||||
return fail(" Serialise, expected rc 0, got %d\n", rc);
|
||||
|
||||
if ( !leaves_are_sorted(leaves, nr) )
|
||||
return fail(" Leaves not sorted\n");
|
||||
}
|
||||
|
||||
static void test_cpuid_serialise_success(void)
|
||||
{
|
||||
static const struct test {
|
||||
@@ -178,6 +217,13 @@ static void test_cpuid_serialise_success(void)
|
||||
goto test_done;
|
||||
}
|
||||
|
||||
if ( !leaves_are_sorted(leaves, nr) )
|
||||
{
|
||||
fail(" Test %s, leaves not sorted\n",
|
||||
t->name);
|
||||
goto test_done;
|
||||
}
|
||||
|
||||
test_done:
|
||||
free(leaves);
|
||||
}
|
||||
@@ -613,6 +659,7 @@ int main(int argc, char **argv)
|
||||
|
||||
test_vendor_identification();
|
||||
|
||||
test_cpuid_current();
|
||||
test_cpuid_serialise_success();
|
||||
test_cpuid_deserialise_failure();
|
||||
test_cpuid_out_of_range_clearing();
|
||||
|
||||