]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add ptrace getreset testcase from Andreas Arnez
authorChristian Borntraeger <borntraeger@de.ibm.com>
Thu, 8 Nov 2012 19:42:00 +0000 (19:42 +0000)
committerChristian Borntraeger <borntraeger@de.ibm.com>
Thu, 8 Nov 2012 19:42:00 +0000 (19:42 +0000)
arnez AT  linux DOT vnet DOT ibm DOT com

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13110

memcheck/tests/linux/getregset.c [new file with mode: 0644]
memcheck/tests/linux/getregset.stderr.exp [new file with mode: 0644]
memcheck/tests/linux/getregset.stdout.exp [new file with mode: 0644]
memcheck/tests/linux/getregset.vgtest [new file with mode: 0644]

diff --git a/memcheck/tests/linux/getregset.c b/memcheck/tests/linux/getregset.c
new file mode 100644 (file)
index 0000000..70b5ce2
--- /dev/null
@@ -0,0 +1,76 @@
+/* -*- mode: C; c-basic-offset: 3; -*- */
+
+#include <assert.h>
+#include <elf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/ptrace.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/user.h>
+#include <sys/wait.h>
+
+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 (file)
index 0000000..e69de29
diff --git a/memcheck/tests/linux/getregset.stdout.exp b/memcheck/tests/linux/getregset.stdout.exp
new file mode 100644 (file)
index 0000000..d86bac9
--- /dev/null
@@ -0,0 +1 @@
+OK
diff --git a/memcheck/tests/linux/getregset.vgtest b/memcheck/tests/linux/getregset.vgtest
new file mode 100644 (file)
index 0000000..73f52f7
--- /dev/null
@@ -0,0 +1,2 @@
+prog: getregset
+vgopts: -q
\ No newline at end of file