|
From: <sv...@va...> - 2005-11-02 16:15:58
|
Author: tom
Date: 2005-11-02 16:15:55 +0000 (Wed, 02 Nov 2005)
New Revision: 4992
Log:
Split faultstatus into the platform independent tests and those
which are x86 specific. The first three x86 specific ones should
work on amd64 as well so I have added those as amd64 tests.
Note that the x86/amd64 tests will still fail as VEX doesn't
always trigger the right sort of signal for faulting instructions
at the moment.
Added:
trunk/none/tests/amd64/faultstatus.c
trunk/none/tests/amd64/faultstatus.stderr.exp
trunk/none/tests/amd64/faultstatus.vgtest
trunk/none/tests/x86/faultstatus.c
trunk/none/tests/x86/faultstatus.stderr.exp
trunk/none/tests/x86/faultstatus.vgtest
Modified:
trunk/none/tests/amd64/Makefile.am
trunk/none/tests/faultstatus.c
trunk/none/tests/faultstatus.stderr.exp
trunk/none/tests/x86/Makefile.am
Modified: trunk/none/tests/amd64/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/amd64/Makefile.am 2005-11-02 15:47:43 UTC (rev 4991)
+++ trunk/none/tests/amd64/Makefile.am 2005-11-02 16:15:55 UTC (rev 4992)
@@ -5,6 +5,7 @@
INSN_TESTS=3Dinsn_mmx insn_sse insn_sse2 insn_fpu
=20
EXTRA_DIST =3D $(noinst_SCRIPTS) \
+ faultstatus.vgtest faultstatus.stderr.exp \
$(addsuffix .stderr.exp,$(INSN_TESTS)) \
$(addsuffix .stdout.exp,$(INSN_TESTS)) \
$(addsuffix .vgtest,$(INSN_TESTS)) \
@@ -13,7 +14,7 @@
smc1.stderr.exp smc1.stdout.exp smc1.vgtest
=20
check_PROGRAMS =3D \
- $(INSN_TESTS) looper jrcxz smc1
+ faultstatus $(INSN_TESTS) looper jrcxz smc1
=20
AM_CFLAGS =3D $(WERROR) -Winline -Wall -Wshadow -g -I$(top_srcdir)/inc=
lude
AM_CXXFLAGS =3D $(AM_CFLAGS)
Added: trunk/none/tests/amd64/faultstatus.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/amd64/faultstatus.c 2005-11-02 15:47:43 UTC (rev 499=
1)
+++ trunk/none/tests/amd64/faultstatus.c 2005-11-02 16:15:55 UTC (rev 499=
2)
@@ -0,0 +1,143 @@
+/*=20
+ Check that a fault signal handler gets the expected info
+ */
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <setjmp.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+struct test {
+ void (*test)(void);
+ int sig;
+ int code;
+ volatile void *addr;
+};
+
+static const struct test *cur_test;
+
+static int zero();
+
+static jmp_buf escape;
+
+#define BADADDR ((int *)0x1234)
+
+#define FILESIZE (16*1024)
+#define MAPSIZE (2*FILESIZE)
+
+static char volatile *volatile mapping;
+
+static int testsig(int sig, int want)
+{
+ if (sig !=3D want) {
+ fprintf(stderr, " FAIL: expected signal %d, not %d\n", want, sig);
+ return 0;
+ }=20
+ return 1;
+}
+
+static int testcode(int code, int want)
+{
+ if (code !=3D want) {
+ fprintf(stderr, " FAIL: expected si_code=3D=3D%d, not %d\n", want, co=
de);
+ return 0;
+ }
+ return 1;
+}
+
+static int testaddr(void *addr, volatile void *want)
+{
+ if (addr !=3D want) {
+ fprintf(stderr, " FAIL: expected si_addr=3D=3D%p, not %p\n", want, ad=
dr);
+ return 0;
+ }
+ return 1;
+
+}
+
+static void handler(int sig, siginfo_t *si, void *uc)
+{
+ int ok =3D 1;
+
+ ok =3D ok && testsig(sig, cur_test->sig);
+ ok =3D ok && testcode(si->si_code, cur_test->code);
+ if (cur_test->addr)
+ ok =3D ok && testaddr(si->si_addr, cur_test->addr);
+
+ if (ok)
+ fprintf(stderr, " PASS\n");
+
+ siglongjmp(escape, ok + 1);
+}
+
+
+extern char test1_ill;
+static void test1()
+{
+ asm volatile("test1_ill: ud2");
+}
+
+static void test2()
+{
+ asm volatile ("int3");
+}
+
+static void test3()
+{
+ asm volatile ("int $0x10");
+}
+
+int main()
+{
+ int fd, i;
+ static const int sigs[] =3D { SIGSEGV, SIGILL, SIGBUS, SIGFPE, SIGTRAP =
};
+ struct sigaction sa;
+
+ sa.sa_sigaction =3D handler;
+ sa.sa_flags =3D SA_SIGINFO;
+ sigfillset(&sa.sa_mask);
+=09
+ for(i =3D 0; i < sizeof(sigs)/sizeof(*sigs); i++)
+ sigaction(sigs[i], &sa, NULL);
+
+ fd =3D open("faultstatus.tmp", O_CREAT|O_TRUNC|O_EXCL, 0600);
+ if (fd =3D=3D -1) {
+ perror("tmpfile");
+ exit(1);
+ }
+ unlink("faultstatus.tmp");
+ ftruncate(fd, FILESIZE);
+
+ mapping =3D mmap(0, MAPSIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+ close(fd);
+
+ {
+ const struct test tests[] =3D {
+#define T(n, sig, code, addr) { test##n, sig, code, addr }
+ T(1, SIGILL, ILL_ILLOPN, &test1_ill),
+
+ T(2, SIGTRAP, 128, 0), /* TRAP_BRKPT? */
+ T(3, SIGSEGV, 128, 0),
+#undef T
+ };
+
+ for(i =3D 0; i < sizeof(tests)/sizeof(*tests); i++) {
+ cur_test =3D &tests[i];
+ =09
+ if (sigsetjmp(escape, 1) =3D=3D 0) {
+ fprintf(stderr, "Test %d: ", i+1);
+ tests[i].test();
+ fprintf(stderr, " FAIL: no fault, or handler returned\n");
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int zero()
+{
+ return 0;
+}
Added: trunk/none/tests/amd64/faultstatus.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/amd64/faultstatus.stderr.exp 2005-11-02 15:47:43 UTC=
(rev 4991)
+++ trunk/none/tests/amd64/faultstatus.stderr.exp 2005-11-02 16:15:55 UTC=
(rev 4992)
@@ -0,0 +1,5 @@
+
+Test 1: PASS
+Test 2: PASS
+Test 3: PASS
+
Added: trunk/none/tests/amd64/faultstatus.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/amd64/faultstatus.vgtest 2005-11-02 15:47:43 UTC (re=
v 4991)
+++ trunk/none/tests/amd64/faultstatus.vgtest 2005-11-02 16:15:55 UTC (re=
v 4992)
@@ -0,0 +1 @@
+prog: faultstatus
Modified: trunk/none/tests/faultstatus.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/faultstatus.c 2005-11-02 15:47:43 UTC (rev 4991)
+++ trunk/none/tests/faultstatus.c 2005-11-02 16:15:55 UTC (rev 4992)
@@ -95,39 +95,6 @@
(void)v;
}
=20
-#ifdef __i386__
-extern char test5_ill;
-static void test5()
-{
- asm volatile("test5_ill: ud2");
-}
-
-static void test6()
-{
- asm volatile ("int3");
-}
-
-static void test7()
-{
- asm volatile ("int $0x10");
-}
-
-static void test8()
-{
- volatile int a;
- asm volatile ("add $1, %0;"/* set OF */
- "into"
- : "=3Da" (a) : "0" (0x7fffffff) : "cc");
-}
-
-static void test9()
-{
- static int limit[2] =3D { 0, 10 };
-
- asm volatile ("bound %0, %1" : : "r" (11), "m" (limit[0]));
-}
-#endif /* __i386__ */
-
int main()
{
int fd, i;
@@ -159,18 +126,6 @@
T(2, SIGSEGV, SEGV_ACCERR, mapping),
T(3, SIGBUS, BUS_ADRERR, &mapping[FILESIZE+10]),
T(4, SIGFPE, FPE_INTDIV, 0),
-#ifdef __i386__
- T(5, SIGILL, ILL_ILLOPN, &test5_ill),
-
- T(6, SIGTRAP, 128, 0), /* TRAP_BRKPT? */
- T(7, SIGSEGV, 128, 0),
- T(8, SIGSEGV, 128, 0),
-
- /* This is an expected failure - Valgrind
- doesn't implement the BOUND instruction,
- and so issues a SIGILL instead. */
- T(9, SIGSEGV, 128, 0),
-#endif /* __i386__ */
#undef T
};
=20
Modified: trunk/none/tests/faultstatus.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/faultstatus.stderr.exp 2005-11-02 15:47:43 UTC (rev =
4991)
+++ trunk/none/tests/faultstatus.stderr.exp 2005-11-02 16:15:55 UTC (rev =
4992)
@@ -3,11 +3,4 @@
Test 2: PASS
Test 3: PASS
Test 4: PASS
-Test 5: PASS
-Test 6: PASS
-Test 7: PASS
-Test 8: PASS
-Test 9: disInstr: unhandled instruction bytes: 0x........ 0x........ 0x.=
....... 0x........
- at 0x........: test9 (faultstatus.c:127)
- FAIL: expected signal 11, not 4
=20
Modified: trunk/none/tests/x86/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/x86/Makefile.am 2005-11-02 15:47:43 UTC (rev 4991)
+++ trunk/none/tests/x86/Makefile.am 2005-11-02 16:15:55 UTC (rev 4992)
@@ -9,6 +9,7 @@
bt_literal.stderr.exp bt_literal.stdout.exp bt_literal.vgtest \
cpuid.stderr.exp cpuid.stdout.exp cpuid.vgtest \
cmpxchg8b.stderr.exp cmpxchg8b.stdout.exp cmpxchg8b.vgtest \
+ faultstatus.vgtest faultstatus.stderr.exp \
fpu_lazy_eflags.stderr.exp fpu_lazy_eflags.stdout.exp \
fpu_lazy_eflags.vgtest \
fxtract.stdout.exp fxtract.stderr.exp fxtract.vgtest \
@@ -28,8 +29,8 @@
yield.stderr.exp yield.stdout.exp yield.vgtest
=20
check_PROGRAMS =3D \
- badseg bt_everything bt_literal cmpxchg8b cpuid fpu_lazy_eflags \
- fxtract \
+ badseg bt_everything bt_literal cmpxchg8b cpuid \
+ faultstatus fpu_lazy_eflags fxtract \
getseg incdec_alt $(INSN_TESTS) \
lahf looper int pushpopseg sbbmisc \
seg_override sigcontext smc1 yield
Added: trunk/none/tests/x86/faultstatus.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/x86/faultstatus.c 2005-11-02 15:47:43 UTC (rev 4991)
+++ trunk/none/tests/x86/faultstatus.c 2005-11-02 16:15:55 UTC (rev 4992)
@@ -0,0 +1,164 @@
+/*=20
+ Check that a fault signal handler gets the expected info
+ */
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <setjmp.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+struct test {
+ void (*test)(void);
+ int sig;
+ int code;
+ volatile void *addr;
+};
+
+static const struct test *cur_test;
+
+static int zero();
+
+static jmp_buf escape;
+
+#define BADADDR ((int *)0x1234)
+
+#define FILESIZE (16*1024)
+#define MAPSIZE (2*FILESIZE)
+
+static char volatile *volatile mapping;
+
+static int testsig(int sig, int want)
+{
+ if (sig !=3D want) {
+ fprintf(stderr, " FAIL: expected signal %d, not %d\n", want, sig);
+ return 0;
+ }=20
+ return 1;
+}
+
+static int testcode(int code, int want)
+{
+ if (code !=3D want) {
+ fprintf(stderr, " FAIL: expected si_code=3D=3D%d, not %d\n", want, co=
de);
+ return 0;
+ }
+ return 1;
+}
+
+static int testaddr(void *addr, volatile void *want)
+{
+ if (addr !=3D want) {
+ fprintf(stderr, " FAIL: expected si_addr=3D=3D%p, not %p\n", want, ad=
dr);
+ return 0;
+ }
+ return 1;
+
+}
+
+static void handler(int sig, siginfo_t *si, void *uc)
+{
+ int ok =3D 1;
+
+ ok =3D ok && testsig(sig, cur_test->sig);
+ ok =3D ok && testcode(si->si_code, cur_test->code);
+ if (cur_test->addr)
+ ok =3D ok && testaddr(si->si_addr, cur_test->addr);
+
+ if (ok)
+ fprintf(stderr, " PASS\n");
+
+ siglongjmp(escape, ok + 1);
+}
+
+
+extern char test1_ill;
+static void test1()
+{
+ asm volatile("test1_ill: ud2");
+}
+
+static void test2()
+{
+ asm volatile ("int3");
+}
+
+static void test3()
+{
+ asm volatile ("int $0x10");
+}
+
+static void test4()
+{
+ volatile int a;
+ asm volatile ("add $1, %0;"/* set OF */
+ "into"
+ : "=3Da" (a) : "0" (0x7fffffff) : "cc");
+}
+
+static void test5()
+{
+ static int limit[2] =3D { 0, 10 };
+
+ asm volatile ("bound %0, %1" : : "r" (11), "m" (limit[0]));
+}
+
+int main()
+{
+ int fd, i;
+ static const int sigs[] =3D { SIGSEGV, SIGILL, SIGBUS, SIGFPE, SIGTRAP =
};
+ struct sigaction sa;
+
+ sa.sa_sigaction =3D handler;
+ sa.sa_flags =3D SA_SIGINFO;
+ sigfillset(&sa.sa_mask);
+=09
+ for(i =3D 0; i < sizeof(sigs)/sizeof(*sigs); i++)
+ sigaction(sigs[i], &sa, NULL);
+
+ fd =3D open("faultstatus.tmp", O_CREAT|O_TRUNC|O_EXCL, 0600);
+ if (fd =3D=3D -1) {
+ perror("tmpfile");
+ exit(1);
+ }
+ unlink("faultstatus.tmp");
+ ftruncate(fd, FILESIZE);
+
+ mapping =3D mmap(0, MAPSIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+ close(fd);
+
+ {
+ const struct test tests[] =3D {
+#define T(n, sig, code, addr) { test##n, sig, code, addr }
+ T(1, SIGILL, ILL_ILLOPN, &test1_ill),
+
+ T(2, SIGTRAP, 128, 0), /* TRAP_BRKPT? */
+ T(3, SIGSEGV, 128, 0),
+ T(4, SIGSEGV, 128, 0),
+
+ /* This is an expected failure - Valgrind
+ doesn't implement the BOUND instruction,
+ and so issues a SIGILL instead. */
+ T(5, SIGSEGV, 128, 0),
+#undef T
+ };
+
+ for(i =3D 0; i < sizeof(tests)/sizeof(*tests); i++) {
+ cur_test =3D &tests[i];
+ =09
+ if (sigsetjmp(escape, 1) =3D=3D 0) {
+ fprintf(stderr, "Test %d: ", i+1);
+ tests[i].test();
+ fprintf(stderr, " FAIL: no fault, or handler returned\n");
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int zero()
+{
+ return 0;
+}
Added: trunk/none/tests/x86/faultstatus.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/x86/faultstatus.stderr.exp 2005-11-02 15:47:43 UTC (=
rev 4991)
+++ trunk/none/tests/x86/faultstatus.stderr.exp 2005-11-02 16:15:55 UTC (=
rev 4992)
@@ -0,0 +1,9 @@
+
+Test 1: PASS
+Test 2: PASS
+Test 3: PASS
+Test 4: PASS
+Test 5: disInstr: unhandled instruction bytes: 0x........ 0x........ 0x.=
....... 0x........
+ at 0x........: test9 (faultstatus.c:127)
+ FAIL: expected signal 11, not 4
+
Added: trunk/none/tests/x86/faultstatus.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/none/tests/x86/faultstatus.vgtest 2005-11-02 15:47:43 UTC (rev =
4991)
+++ trunk/none/tests/x86/faultstatus.vgtest 2005-11-02 16:15:55 UTC (rev =
4992)
@@ -0,0 +1 @@
+prog: faultstatus
|