summaryrefslogtreecommitdiffstats
path: root/tests/tcg/aarch64
diff options
context:
space:
mode:
authorAlex Bennée2019-03-12 16:42:21 +0100
committerAlex Bennée2019-03-12 18:05:21 +0100
commitb6407281513ddca03c2dbce0b1e48eb7afd14cb1 (patch)
tree0057694ff109408c0c005caa843e7c251df56401 /tests/tcg/aarch64
parenttests/tcg/i386: add memory test to exercise softmmu (diff)
downloadqemu-b6407281513ddca03c2dbce0b1e48eb7afd14cb1.tar.gz
qemu-b6407281513ddca03c2dbce0b1e48eb7afd14cb1.tar.xz
qemu-b6407281513ddca03c2dbce0b1e48eb7afd14cb1.zip
tests/tcg/arm: account for pauth randomness
Pointer authentication isn't guaranteed to always detect a clash between different keys. Take this into account in the test by running several times and checking the percentage hit rate of the test. Cc: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Diffstat (limited to 'tests/tcg/aarch64')
-rw-r--r--tests/tcg/aarch64/pauth-1.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/tcg/aarch64/pauth-1.c b/tests/tcg/aarch64/pauth-1.c
index ae6dc05c2b..a3c1443cd0 100644
--- a/tests/tcg/aarch64/pauth-1.c
+++ b/tests/tcg/aarch64/pauth-1.c
@@ -1,5 +1,6 @@
#include <assert.h>
#include <sys/prctl.h>
+#include <stdio.h>
asm(".arch armv8.4-a");
@@ -8,16 +9,29 @@ asm(".arch armv8.4-a");
#define PR_PAC_APDAKEY (1 << 2)
#endif
+#define TESTS 1000
+
int main()
{
- int x;
+ int x, i, count = 0;
void *p0 = &x, *p1, *p2;
+ float perc;
+
+ for (i = 0; i < TESTS; i++) {
+ asm volatile("pacdza %0" : "=r"(p1) : "0"(p0));
+ prctl(PR_PAC_RESET_KEYS, PR_PAC_APDAKEY, 0, 0, 0);
+ asm volatile("pacdza %0" : "=r"(p2) : "0"(p0));
- asm volatile("pacdza %0" : "=r"(p1) : "0"(p0));
- prctl(PR_PAC_RESET_KEYS, PR_PAC_APDAKEY, 0, 0, 0);
- asm volatile("pacdza %0" : "=r"(p2) : "0"(p0));
+ if (p1 != p0) {
+ count++;
+ }
+ if (p1 != p2) {
+ count++;
+ }
+ }
- assert(p1 != p0);
- assert(p1 != p2);
+ perc = (float) count / (float) (TESTS * 2);
+ printf("Ptr Check: %0.2f%%", perc * 100.0);
+ assert(perc > 0.95);
return 0;
}