qemu-patch-raspberry4/tests/tcg/aarch64/pauth-1.c
Richard Henderson e2d30df907 tests/tcg/aarch64: Add newline in pauth-1 printf
Make the output just a bit prettier when running by hand.

Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20200229012811.24129-13-richard.henderson@linaro.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2020-03-05 16:09:19 +00:00

36 lines
729 B
C

#include <assert.h>
#include <sys/prctl.h>
#include <stdio.h>
#ifndef PR_PAC_RESET_KEYS
#define PR_PAC_RESET_KEYS 54
#define PR_PAC_APDAKEY (1 << 2)
#endif
#define TESTS 1000
int main()
{
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));
if (p1 != p0) {
count++;
}
if (p1 != p2) {
count++;
}
}
perc = (float) count / (float) (TESTS * 2);
printf("Ptr Check: %0.2f%%\n", perc * 100.0);
assert(perc > 0.95);
return 0;
}