From: Christian Borntraeger Date: Thu, 8 Nov 2012 19:42:00 +0000 (+0000) Subject: Add ptrace getreset testcase from Andreas Arnez X-Git-Tag: svn/VALGRIND_3_9_0~558 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c0b993485e3c00a4134eca95c8fe1ee6707ab6c;p=thirdparty%2Fvalgrind.git Add ptrace getreset testcase from Andreas Arnez arnez AT linux DOT vnet DOT ibm DOT com git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13110 --- diff --git a/memcheck/tests/linux/getregset.c b/memcheck/tests/linux/getregset.c new file mode 100644 index 0000000000..70b5ce2b36 --- /dev/null +++ b/memcheck/tests/linux/getregset.c @@ -0,0 +1,76 @@ +/* -*- mode: C; c-basic-offset: 3; -*- */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static int +err_out(const char *msg) +{ + perror(msg); + return 1; +} + +static int +non_empty(const char *buf, size_t len) +{ + size_t i; + int c; + volatile const char *p = buf; + + for (i = 0; i != len; i++) + c |= p[i]; + return c; +} + +static int +do_child(void) +{ + if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) == -1) + return err_out("ptrace traceme"); + raise(SIGUSR1); + return 0; +} + +int +main(void) +{ + char buf[1024]; + struct iovec iov; + pid_t cpid, pid; + int status; + + cpid = fork(); + if (cpid == -1) + return err_out("fork"); + if (cpid == 0) + return do_child(); + + pid = wait(&status); + if (pid == -1) + return err_out("wait"); + + /* Intentionally provide an uninitialized buffer to ptrace. */ + iov.iov_len = sizeof(buf); + iov.iov_base = buf; + if (ptrace(0x4204, cpid, NT_PRSTATUS, &iov) == -1) + return err_out("ptrace getregset"); + + assert(iov.iov_base == buf); + assert(iov.iov_len > 0 && iov.iov_len < sizeof(buf)); + + /* We're assuming here that NT_PRSTATUS never contains + all-zeros. */ + assert(non_empty(buf, iov.iov_len)); + puts("OK"); + return 0; +} diff --git a/memcheck/tests/linux/getregset.stderr.exp b/memcheck/tests/linux/getregset.stderr.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/memcheck/tests/linux/getregset.stdout.exp b/memcheck/tests/linux/getregset.stdout.exp new file mode 100644 index 0000000000..d86bac9de5 --- /dev/null +++ b/memcheck/tests/linux/getregset.stdout.exp @@ -0,0 +1 @@ +OK diff --git a/memcheck/tests/linux/getregset.vgtest b/memcheck/tests/linux/getregset.vgtest new file mode 100644 index 0000000000..73f52f7944 --- /dev/null +++ b/memcheck/tests/linux/getregset.vgtest @@ -0,0 +1,2 @@ +prog: getregset +vgopts: -q \ No newline at end of file