From: Roger Pau Monne Date: Tue, 13 Apr 2021 12:51:44 +0000 (+0200) Subject: tests/cpu-policy: add sorted MSR test X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~587 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b8e53a81ba538849b98b0d417436f8be653fa1ff;p=xen.git tests/cpu-policy: add sorted MSR test Further changes will rely on MSR entries being sorted, so add a test to assert it. Signed-off-by: Roger Pau Monné Acked-by: Andrew Cooper --- diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c index cb578ca6e5..75973298df 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -89,6 +89,16 @@ static bool leaves_are_sorted(const xen_cpuid_leaf_t *leaves, unsigned int nr) return true; } +static bool msrs_are_sorted(const xen_msr_entry_t *entries, unsigned int nr) +{ + for ( unsigned int i = 1; i < nr; ++i ) + /* MSR index went backwards => not sorted. */ + if ( entries[i - 1].idx > entries[i].idx ) + return false; + + return true; +} + static void test_cpuid_current(void) { struct cpuid_policy p; @@ -273,6 +283,13 @@ static void test_msr_serialise_success(void) goto test_done; } + if ( !msrs_are_sorted(msrs, nr) ) + { + fail(" Test %s, MSR entries not sorted\n", + t->name); + goto test_done; + } + test_done: free(msrs); }