|
From: <sv...@va...> - 2009-08-26 18:11:31
|
Author: bart
Date: 2009-08-26 19:11:18 +0100 (Wed, 26 Aug 2009)
New Revision: 10871
Log:
Added regression tests that verify the following behavior:
- On Linux, whether Valgrind properly intercepts the system calls that access
/proc/self/cmdline, /proc/<pid>/cmdline, /proc/self/exe and /proc/<pid>/exe.
- On Darwin, whether Valgrind does not modify the behavior of the system calls
that access the aforementioned files.
Added:
trunk/none/tests/procfs-cmdline-exe.c
trunk/none/tests/procfs-linux.stderr.exp
trunk/none/tests/procfs-linux.vgtest
trunk/none/tests/procfs-non-linux.stderr.exp
trunk/none/tests/procfs-non-linux.vgtest
Modified:
trunk/configure.in
trunk/none/tests/
trunk/none/tests/Makefile.am
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2009-08-26 17:27:10 UTC (rev 10870)
+++ trunk/configure.in 2009-08-26 18:11:18 UTC (rev 10871)
@@ -1526,6 +1526,7 @@
pthread_rwlock_timedrdlock \
pthread_rwlock_timedwrlock \
pthread_spin_lock \
+ readlinkat \
semtimedop \
signalfd \
sigwaitinfo \
Property changes on: trunk/none/tests
___________________________________________________________________
Name: svn:ignore
- *.dSYM
*.so
*.stderr.diff*
*.stderr.out
*.stdout.diff*
*.stdout.out
.deps
ansi
args
async-sigs
as_mmap
as_shm
bitfield1
blockfault
bug129866
closeall
coolo_sigaction
coolo_strlen
discard
exec-sigmask
execve
faultstatus
fcntl_setown
fdleak_cmsg
fdleak_creat
fdleak_dup
fdleak_dup2
fdleak_fcntl
fdleak_ipv4
fdleak_open
fdleak_pipe
fdleak_socketpair
floored
fork
fucomip
gxx304
insn_basic
insn_basic.c
insn_cmov
insn_cmov.c
insn_fpu
insn_fpu.c
insn_mmx
insn_mmx.c
insn_mmxext
insn_mmxext.c
insn_sse
insn_sse.c
insn_sse2
insn_sse2.c
Makefile
Makefile.in
manythreads
map_unaligned
map_unmap
mq
mremap
mremap2
munmap_exe
nestedfns
pending
pluto
pth_atfork1
pth_blockedsig
pth_cancel1
pth_cancel2
pth_cvsimple
pth_detached
pth_empty
pth_exit
pth_exit2
pth_mutexspeed
pth_once
pth_rwlock
pth_semaphore1
pth_simple_mutex
pth_simple_threads
pth_specific
pth_stackalign
pth_yield
rcrl
readline1
resolv
res_search
rlimit_nofile
selfrun
sem
semlimit
sha1_test
shortpush
shorts
sigstackgrowth
smc1
stackgrowth
susphello
syscall-restart1
syscall-restart2
syslog
system
thread-exits
threaded-fork
threadederrno
timestamp
tls
vgcore.*
vgprintf
yield
+ *.dSYM
*.so
*.stderr.diff*
*.stderr.out
*.stdout.diff*
*.stdout.out
.deps
ansi
args
async-sigs
as_mmap
as_shm
bitfield1
blockfault
bug129866
closeall
coolo_sigaction
coolo_strlen
discard
exec-sigmask
execve
faultstatus
fcntl_setown
fdleak_cmsg
fdleak_creat
fdleak_dup
fdleak_dup2
fdleak_fcntl
fdleak_ipv4
fdleak_open
fdleak_pipe
fdleak_socketpair
floored
fork
fucomip
gxx304
insn_basic
insn_basic.c
insn_cmov
insn_cmov.c
insn_fpu
insn_fpu.c
insn_mmx
insn_mmx.c
insn_mmxext
insn_mmxext.c
insn_sse
insn_sse.c
insn_sse2
insn_sse2.c
Makefile
Makefile.in
manythreads
map_unaligned
map_unmap
mq
mremap
mremap2
munmap_exe
nestedfns
pending
pluto
procfs-cmdline-exe
pth_atfork1
pth_blockedsig
pth_cancel1
pth_cancel2
pth_cvsimple
pth_detached
pth_empty
pth_exit
pth_exit2
pth_mutexspeed
pth_once
pth_rwlock
pth_semaphore1
pth_simple_mutex
pth_simple_threads
pth_specific
pth_stackalign
pth_yield
rcrl
readline1
resolv
res_search
rlimit_nofile
selfrun
sem
semlimit
sha1_test
shortpush
shorts
sigstackgrowth
smc1
stackgrowth
susphello
syscall-restart1
syscall-restart2
syslog
system
thread-exits
threaded-fork
threadederrno
timestamp
tls
vgcore.*
vgprintf
yield
Modified: trunk/none/tests/Makefile.am
===================================================================
--- trunk/none/tests/Makefile.am 2009-08-26 17:27:10 UTC (rev 10870)
+++ trunk/none/tests/Makefile.am 2009-08-26 18:11:18 UTC (rev 10871)
@@ -88,6 +88,8 @@
munmap_exe.stderr.exp munmap_exe.vgtest \
nestedfns.stderr.exp nestedfns.stdout.exp nestedfns.vgtest \
pending.stdout.exp pending.stderr.exp pending.vgtest \
+ procfs-linux.stderr.exp procfs-linux.vgtest \
+ procfs-non-linux.stderr.exp procfs-non-linux.vgtest \
pth_atfork1.stderr.exp pth_atfork1.stdout.exp pth_atfork1.vgtest \
pth_blockedsig.stderr.exp \
pth_blockedsig.stdout.exp pth_blockedsig.vgtest \
@@ -155,6 +157,7 @@
munmap_exe map_unaligned map_unmap mq \
nestedfns \
pending \
+ procfs-cmdline-exe \
pth_atfork1 pth_blockedsig pth_cancel1 pth_cancel2 pth_cvsimple \
pth_empty pth_exit pth_exit2 pth_mutexspeed pth_once pth_rwlock \
pth_stackalign \
Added: trunk/none/tests/procfs-cmdline-exe.c
===================================================================
--- trunk/none/tests/procfs-cmdline-exe.c (rev 0)
+++ trunk/none/tests/procfs-cmdline-exe.c 2009-08-26 18:11:18 UTC (rev 10871)
@@ -0,0 +1,115 @@
+/*
+ * Read /proc/self/cmdline and /proc/self/exe such that it can be tested
+ * whether Valgrind intercepts the system calls that access these pseudo-files
+ * properly on Linux and whether Valgrind does not modify the behavior of
+ * accessing these files on other operating systems.
+ */
+
+#define _ATFILE_SOURCE
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <unistd.h>
+#include "../../config.h"
+
+static void test_cmdline(const char* const cwd, const char* const label,
+ const char* const path)
+{
+ int fd, n;
+ char ch;
+
+ fprintf(stderr, "%s:\n", label);
+ fd = open(path, 0);
+ if (fd >= 0)
+ {
+ while ((n = read(fd, &ch, 1)) > 0)
+ {
+ if (ch == '\\')
+ fprintf(stderr, "\\\\");
+ else if (ch == 0)
+ fprintf(stderr, "\\0");
+ else if (isprint((unsigned)ch))
+ fprintf(stderr, "%c", ch);
+ else
+ fprintf(stderr, "\\0%o", ch);
+ }
+ fprintf(stderr, "\n");
+ close(fd);
+ }
+ else
+ perror("open()");
+}
+
+static void test_readlink(const char* const cwd, const char* const label,
+ const char* const path)
+{
+ char buf[512];
+ const char* p;
+ int n;
+
+ if ((n = readlink(path, buf, sizeof(buf) - 1)) >= 0)
+ {
+ buf[n] = 0;
+ p = buf;
+ if (strncmp(buf, cwd, strlen(cwd)) == 0)
+ p += strlen(cwd);
+ fprintf(stderr, "Result of readlink(\"%s\"): %s\n", label, p);
+ }
+ else
+ perror("readlink");
+}
+
+static void test_readlinkat(const char* const cwd, const char* const label,
+ const char* const path)
+{
+#if HAVE_READLINKAT
+ char buf[512];
+ const char* p;
+ int n;
+
+ if ((n = readlinkat(AT_FDCWD, path, buf, sizeof(buf) - 1)) >= 0)
+ {
+ buf[n] = 0;
+ p = buf;
+ if (strncmp(buf, cwd, strlen(cwd)) == 0)
+ p += strlen(cwd);
+ fprintf(stderr, "Result of readlinkat(\"%s\"): %s\n", label, p);
+ }
+ else
+ perror("readlinkat");
+#else
+ errno = ENOSYS;
+ perror("readlinkat");
+#endif
+}
+
+int main(int argc, char** argv)
+{
+ char cwd[512];
+ char path[512];
+
+ cwd[0] = 0;
+ if (! getcwd(cwd, sizeof(cwd)))
+ perror("getcwd");
+ strcat(cwd, "/");
+
+ snprintf(path, sizeof(path), "/proc/%d/cmdline", getpid());
+
+ test_cmdline(cwd, "/proc/self/cmdline", "/proc/self/cmdline");
+ test_cmdline(cwd, "/proc/<pid>/cmdline", path);
+
+ snprintf(path, sizeof(path), "/proc/%d/exe", getpid());
+
+ test_readlink(cwd, "/proc/self/exe", "/proc/self/exe");
+ test_readlink(cwd, "/proc/<pid>/exe", path);
+
+ test_readlinkat(cwd, "/proc/self/exe", "/proc/self/exe");
+ test_readlinkat(cwd, "/proc/<pid>/exe", path);
+
+ return 0;
+}
Added: trunk/none/tests/procfs-linux.stderr.exp
===================================================================
--- trunk/none/tests/procfs-linux.stderr.exp (rev 0)
+++ trunk/none/tests/procfs-linux.stderr.exp 2009-08-26 18:11:18 UTC (rev 10871)
@@ -0,0 +1,10 @@
+
+/proc/self/cmdline:
+./procfs-cmdline-exe\0arg1\0arg 2\0arg3\0
+/proc/<pid>/cmdline:
+./procfs-cmdline-exe\0arg1\0arg 2\0arg3\0
+Result of readlink("/proc/self/exe"): procfs-cmdline-exe
+Result of readlink("/proc/<pid>/exe"): procfs-cmdline-exe
+Result of readlinkat("/proc/self/exe"): procfs-cmdline-exe
+Result of readlinkat("/proc/<pid>/exe"): procfs-cmdline-exe
+
Added: trunk/none/tests/procfs-linux.vgtest
===================================================================
--- trunk/none/tests/procfs-linux.vgtest (rev 0)
+++ trunk/none/tests/procfs-linux.vgtest 2009-08-26 18:11:18 UTC (rev 10871)
@@ -0,0 +1,4 @@
+prereq: [ $(uname) = Linux ]
+prog: procfs-cmdline-exe
+args: arg1 "arg 2" arg3
+stderr_filter: filter_stderr
Added: trunk/none/tests/procfs-non-linux.stderr.exp
===================================================================
--- trunk/none/tests/procfs-non-linux.stderr.exp (rev 0)
+++ trunk/none/tests/procfs-non-linux.stderr.exp 2009-08-26 18:11:18 UTC (rev 10871)
@@ -0,0 +1,10 @@
+
+/proc/self/cmdline:
+open(): No such file or directory
+/proc/<pid>/cmdline:
+open(): No such file or directory
+readlink: No such file or directory
+readlink: No such file or directory
+readlinkat: Function not implemented
+readlinkat: Function not implemented
+
Added: trunk/none/tests/procfs-non-linux.vgtest
===================================================================
--- trunk/none/tests/procfs-non-linux.vgtest (rev 0)
+++ trunk/none/tests/procfs-non-linux.vgtest 2009-08-26 18:11:18 UTC (rev 10871)
@@ -0,0 +1,3 @@
+prereq: [ $(uname) != Linux ]
+prog: procfs-cmdline-exe
+stderr_filter: filter_stderr
|