[PATCH v2] Add tests for option -e
Fei Jie
feij.fnst at cn.fujitsu.com
Tue Jan 26 05:50:54 UTC 2016
tests: add abbrev-e.test, verbose-e.test, raw-e.test, read-e.test,
write-e.test
* tests/abbrev-e.c: New file.
* tests/abbrev-e.test: New test.
* tests/verbose-e.c: New file.
* tests/verbose-e.test: New test.
* tests/raw-e.test: New test.
* tests/read-e.c: New file.
* tests/read-e.test: New test.
* tests/write-e.c: New file.
* tests/write-e.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add abbrev-e, verbose-e,
read-e, write-e.
(TESTS): Add abbrev-e.test, verbose-e.test, raw-e.tese, read-e.test,
write-e.test.
* tests/.gitignore: Add abbrev-e, verbose-e, read-e, write-e.
---
tests/.gitignore | 4 ++++
tests/Makefile.am | 9 +++++++++
tests/abbrev-e.c | 29 +++++++++++++++++++++++++++++
tests/abbrev-e.test | 15 +++++++++++++++
tests/raw-e.test | 15 +++++++++++++++
tests/read-e.c | 40 ++++++++++++++++++++++++++++++++++++++++
tests/read-e.test | 28 ++++++++++++++++++++++++++++
tests/verbose-e.c | 12 ++++++++++++
tests/verbose-e.test | 15 +++++++++++++++
tests/write-e.c | 39 +++++++++++++++++++++++++++++++++++++++
tests/write-e.test | 28 ++++++++++++++++++++++++++++
11 files changed, 234 insertions(+)
create mode 100644 tests/abbrev-e.c
create mode 100755 tests/abbrev-e.test
create mode 100755 tests/raw-e.test
create mode 100644 tests/read-e.c
create mode 100755 tests/read-e.test
create mode 100644 tests/verbose-e.c
create mode 100755 tests/verbose-e.test
create mode 100644 tests/write-e.c
create mode 100755 tests/write-e.test
diff --git a/tests/.gitignore b/tests/.gitignore
index 207a9b2..9ccbf35 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -6,6 +6,7 @@
*.tmp.*
*.trs
_newselect
+abbrev-e
adjtimex
aio
attach-p-cmd-cmd
@@ -70,6 +71,7 @@ readdir
readlink
readlinkat
readv
+read-e
recvmsg
restart_syscall
rt_sigqueueinfo
@@ -111,8 +113,10 @@ unix-pair-send-recv
userfaultfd
utime
utimensat
+verbose-e
vfork-f
wait
+write-e
xattr
xet_robust_list
xetitimer
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f634583..3eaf354 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -54,6 +54,7 @@ LDADD = libtests.a
check_PROGRAMS = \
_newselect \
+ abbrev-e \
adjtimex \
aio \
attach-p-cmd-cmd \
@@ -116,6 +117,7 @@ check_PROGRAMS = \
readlink \
readlinkat \
readv \
+ read-e \
recvmsg \
restart_syscall \
rt_sigqueueinfo \
@@ -157,8 +159,10 @@ check_PROGRAMS = \
userfaultfd \
utime \
utimensat \
+ verbose-e \
vfork-f \
wait \
+ write-e \
xattr \
xet_robust_list \
xetitimer \
@@ -195,6 +199,7 @@ TESTS = \
ksysent.test \
\
_newselect.test \
+ abbrev-e.test \
adjtimex.test \
aio.test \
bexecve.test \
@@ -251,10 +256,12 @@ TESTS = \
pipe.test \
ppoll.test \
pselect6.test \
+ raw-e.test \
readdir.test \
readlink.test \
readlinkat.test \
readv.test \
+ read-e.test \
recvmsg.test \
rt_sigqueueinfo.test \
sched_xetaffinity.test \
@@ -293,8 +300,10 @@ TESTS = \
userfaultfd.test \
utime.test \
utimensat.test \
+ verbose-e.test \
vfork-f.test \
wait.test \
+ write-e.test \
xattr.test \
xet_robust_list.test \
xetitimer.test \
diff --git a/tests/abbrev-e.c b/tests/abbrev-e.c
new file mode 100644
index 0000000..f172f8e
--- /dev/null
+++ b/tests/abbrev-e.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <sys/utsname.h>
+
+int main()
+{
+ int ret;
+ struct utsname buf;
+ ret = uname(&buf);
+ printf("uname({sysname=\"%s\", nodename=\"%s\", release=\"%s\""
+ ", version=\"%s\", machine=\"%s\""
+#if _UTSNAME_DOMAIN_LENGTH - 0
+ ", domainname=\"%s\""
+#endif
+ "}) = %d\n",
+ buf.sysname,
+ buf.nodename,
+ buf.release,
+ buf.version,
+ buf.machine,
+#if _UTSNAME_DOMAIN_LENGTH - 0
+# ifdef __USE__GNU
+ buf.domainname,
+# else
+ buf.__domainname,
+# endif
+#endif
+ ret);
+ return 0;
+}
diff --git a/tests/abbrev-e.test b/tests/abbrev-e.test
new file mode 100755
index 0000000..4772a97
--- /dev/null
+++ b/tests/abbrev-e.test
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Check option -e abbrev.
+
+. "${srcdir=.}/init.sh"
+
+OUT="${LOG}.out"
+
+run_prog
+run_strace -e abbrev=none -euname -qq $args >"$OUT"
+
+match_diff "$OUT" "$LOG"
+rm -f "$OUT"
+
+exit 0
diff --git a/tests/raw-e.test b/tests/raw-e.test
new file mode 100755
index 0000000..5f4f94e
--- /dev/null
+++ b/tests/raw-e.test
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Check option -e raw.
+
+. "${srcdir=.}/init.sh"
+
+OUT="${LOG}.out"
+
+run_prog ./verbose-e
+run_strace -e raw=uname -euname -a9 -qq $args >"$OUT"
+
+match_diff "$LOG" "$OUT"
+rm -f "$OUT"
+
+exit 0
diff --git a/tests/read-e.c b/tests/read-e.c
new file mode 100644
index 0000000..723cb60
--- /dev/null
+++ b/tests/read-e.c
@@ -0,0 +1,40 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void do_readfd(int fd)
+{
+ int oldfd;
+ oldfd = open("/dev/zero", O_RDONLY);
+ if (-1 == oldfd)
+ {
+ return;
+ }
+ int newfd;
+ if (oldfd == fd)
+ {
+ newfd = fd;
+ }
+ else
+ {
+ newfd = dup2(oldfd, fd);
+ close(oldfd);
+ if (-1 == newfd)
+ {
+ return;
+ }
+ }
+ char c;
+ read(newfd, &c, 1);
+ close(newfd);
+}
+
+int main()
+{
+ long fd = 4;
+ do_readfd(fd);
+ fd = 5;
+ do_readfd(fd);
+ return 0;
+}
diff --git a/tests/read-e.test b/tests/read-e.test
new file mode 100755
index 0000000..e4c0d27
--- /dev/null
+++ b/tests/read-e.test
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# Check option -e read.
+
+. "${srcdir=.}/init.sh"
+
+check_rd()
+{
+ FUNCLINE=$((`grep -n "$1" "$LOG" | sed -n '$p' | cut -f1 -d:` + 1))
+ ERROR=`sed -n "$FUNCLINE"p "$LOG" | grep " | 00000"`
+ if [ "$2" -eq 1 ];then
+ if [ "$ERROR" = "" ];then
+ fail_ "read not exist"
+ fi
+ else
+ if [ "$ERROR" != "" ];then
+ fail_ "read exist"
+ fi
+ fi
+}
+
+run_prog
+run_strace -e read=4 -eread -qq $args
+
+check_rd "read(4, \"\\\\0\", 1) \+= 1" 1
+check_rd "read(5, \"\\\\0\", 1) \+= 1" 0
+
+exit 0
diff --git a/tests/verbose-e.c b/tests/verbose-e.c
new file mode 100644
index 0000000..580831e
--- /dev/null
+++ b/tests/verbose-e.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <sys/utsname.h>
+#include <stdint.h>
+
+int main()
+{
+ int ret;
+ struct utsname buf;
+ ret = uname(&buf);
+ printf("uname(%p) = %d\n", &buf, ret);
+ return 0;
+}
diff --git a/tests/verbose-e.test b/tests/verbose-e.test
new file mode 100755
index 0000000..9d04351
--- /dev/null
+++ b/tests/verbose-e.test
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Check option -e verbose.
+
+. "${srcdir=.}/init.sh"
+
+OUT="${LOG}.out"
+
+run_prog
+run_strace -e verbose=none -euname -qq -a9 $args >"$OUT"
+
+match_diff "$OUT" "$LOG"
+rm -f "$OUT"
+
+exit 0
diff --git a/tests/write-e.c b/tests/write-e.c
new file mode 100644
index 0000000..a495c7a
--- /dev/null
+++ b/tests/write-e.c
@@ -0,0 +1,39 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void do_writefd(int fd)
+{
+ int oldfd;
+ oldfd = open("/dev/null", O_WRONLY);
+ if (-1 == oldfd)
+ {
+ return;
+ }
+ int newfd;
+ if (oldfd == fd)
+ {
+ newfd = fd;
+ }
+ else
+ {
+ newfd = dup2(oldfd, fd);
+ close(oldfd);
+ if (-1 == newfd)
+ {
+ return;
+ }
+ }
+ write(newfd, "", 1);
+ close(newfd);
+}
+
+int main()
+{
+ long fd = 4;
+ do_writefd(fd);
+ fd = 5;
+ do_writefd(fd);
+ return 0;
+}
diff --git a/tests/write-e.test b/tests/write-e.test
new file mode 100755
index 0000000..a480324
--- /dev/null
+++ b/tests/write-e.test
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+# Check option -e write.
+
+. "${srcdir=.}/init.sh"
+
+check_wr()
+{
+ FUNCLINE=$((`grep -n "$1" "$LOG" | sed -n '$p' | cut -f1 -d:` + 1))
+ ERROR=`sed -n "$FUNCLINE"p "$LOG" | grep " | 00000"`
+ if [ "$2" -eq 1 ];then
+ if [ "$ERROR" = "" ];then
+ fail_ "write not exist"
+ fi
+ else
+ if [ "$ERROR" != "" ];then
+ fail_ "write exist"
+ fi
+ fi
+}
+
+run_prog
+run_strace -e write=4 -ewrite -qq $args
+
+check_wr "write(4, \"\\\\0\", 1) \+= 1" 1
+check_wr "write(5, \"\\\\0\", 1) \+= 1" 0
+
+exit 0
--
1.8.3.1
More information about the Strace-devel
mailing list