[PATCH] Add tests for option -e

Fei, Jie/费 杰 feij.fnst at cn.fujitsu.com
Fri Jan 8 08:07:52 UTC 2016


Hello!

Thanks for your comments several days ago and according to them
I wrote this patch. This patch adds tests to check how strace -e works
with different parameters, how about it?

On 01/08/2016 03:39 PM, Fei Jie wrote:
> tests: add abbrev-e.test, verbose-e.test, raw-e.test, read-e.test,
> 	write-e.test
>
> Check how strace -e works with different parapeters.
>
> * tests/abbrev-e.c: New file.
> * tests/abbrev-e.test: New test.
> * tests/verbose-e.test: Likewise.
> * tests/raw-e.c: New file.
> * 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, raw-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, raw-e, read-e, write-e.
> ---
>   tests/.gitignore     |  4 ++++
>   tests/Makefile.am    |  9 +++++++++
>   tests/abbrev-e.c     | 11 +++++++++++
>   tests/abbrev-e.test  | 13 +++++++++++++
>   tests/raw-e.c        | 10 ++++++++++
>   tests/raw-e.test     | 13 +++++++++++++
>   tests/read-e.c       | 40 ++++++++++++++++++++++++++++++++++++++++
>   tests/read-e.test    | 26 ++++++++++++++++++++++++++
>   tests/verbose-e.test | 13 +++++++++++++
>   tests/write-e.c      | 39 +++++++++++++++++++++++++++++++++++++++
>   tests/write-e.test   | 26 ++++++++++++++++++++++++++
>   11 files changed, 204 insertions(+)
>   create mode 100644 tests/abbrev-e.c
>   create mode 100755 tests/abbrev-e.test
>   create mode 100644 tests/raw-e.c
>   create mode 100755 tests/raw-e.test
>   create mode 100644 tests/read-e.c
>   create mode 100755 tests/read-e.test
>   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 cfe1e9f..9b821f2 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -6,6 +6,7 @@
>   *.tmp.*
>   *.trs
>   _newselect
> +abbrev-e
>   adjtimex
>   aio
>   bpf
> @@ -63,9 +64,11 @@ personality
>   pipe
>   ppoll
>   pselect6
> +raw-e
>   readdir
>   readlink
>   readlinkat
> +read-e
>   restart_syscall
>   rt_sigqueueinfo
>   sched_xetaffinity
> @@ -107,6 +110,7 @@ utime
>   utimensat
>   vfork-f
>   wait
> +write-e
>   xattr
>   xet_robust_list
>   xetitimer
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 33f76cb..ec5f1a7 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -52,6 +52,7 @@ LDADD = libtests.a
>   
>   check_PROGRAMS = \
>   	_newselect \
> +	abbrev-e \
>   	adjtimex \
>   	aio \
>   	bpf \
> @@ -107,9 +108,11 @@ check_PROGRAMS = \
>   	pipe \
>   	ppoll \
>   	pselect6 \
> +	raw-e \
>   	readdir \
>   	readlink \
>   	readlinkat \
> +	read-e \
>   	restart_syscall \
>   	rt_sigqueueinfo \
>   	sched_xetaffinity \
> @@ -151,6 +154,7 @@ check_PROGRAMS = \
>   	utimensat \
>   	vfork-f \
>   	wait \
> +	write-e \
>   	xattr \
>   	xet_robust_list \
>   	xetitimer \
> @@ -187,6 +191,7 @@ TESTS = \
>   	ksysent.test \
>   	\
>   	_newselect.test \
> +	abbrev-e.test \
>   	adjtimex.test \
>   	aio.test \
>   	bexecve.test \
> @@ -242,9 +247,11 @@ TESTS = \
>   	pipe.test \
>   	ppoll.test \
>   	pselect6.test \
> +	raw-e.test \
>   	readdir.test \
>   	readlink.test \
>   	readlinkat.test \
> +	read-e.test \
>   	rt_sigqueueinfo.test \
>   	sched_xetaffinity.test \
>   	sched_xetattr.test \
> @@ -282,8 +289,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..e33f656
> --- /dev/null
> +++ b/tests/abbrev-e.c
> @@ -0,0 +1,11 @@
> +#include <stdio.h>
> +#include <sys/utsname.h>
> +
> +int main()
> +{
> +	int ret;
> +	struct utsname buf;
> +	ret = uname(&buf);
> +	printf("uname({sysname=\"%s\", nodename=\"%s\", ...}) = %d\n", buf.sysname, buf.nodename, ret);
> +	return 0;
> +}
> diff --git a/tests/abbrev-e.test b/tests/abbrev-e.test
> new file mode 100755
> index 0000000..3e74d47
> --- /dev/null
> +++ b/tests/abbrev-e.test
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +. "${srcdir=.}/init.sh"
> +
> +OUT="${LOG}.out"
> +
> +run_prog
> +run_strace -e abbrev=uname -euname -qq $args >"$OUT"
> +
> +match_diff "$OUT" "$LOG"
> +rm -f "$OUT"
> +
> +exit 0
> diff --git a/tests/raw-e.c b/tests/raw-e.c
> new file mode 100644
> index 0000000..7b2dfcc
> --- /dev/null
> +++ b/tests/raw-e.c
> @@ -0,0 +1,10 @@
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +int main()
> +{
> +	pid_t pid;
> +	pid = getpid();
> +	printf("getpid() = 0x%x\n", pid);
> +	return 0;
> +}
> diff --git a/tests/raw-e.test b/tests/raw-e.test
> new file mode 100755
> index 0000000..d76a0f0
> --- /dev/null
> +++ b/tests/raw-e.test
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +. "${srcdir=.}/init.sh"
> +
> +OUT="${LOG}.out"
> +
> +run_prog
> +run_strace -e raw=getpid -egetpid -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..d8ebe1a
> --- /dev/null
> +++ b/tests/read-e.test
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +
> +. "${srcdir=.}/init.sh"
> +
> +check_rd()
> +{
> +    FUNCLINE=`grep -n "$1" "$LOG" | sed -n '$p' | cut -f1 -d:`
> +    let FUNCLINE=FUNCLINE+1
> +    CONTENT=`sed -n "$FUNCLINE"p "$LOG"`
> +    ERROR=`echo "$CONTENT" | 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
> diff --git a/tests/verbose-e.test b/tests/verbose-e.test
> new file mode 100755
> index 0000000..1c4d361
> --- /dev/null
> +++ b/tests/verbose-e.test
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +. "${srcdir=.}/init.sh"
> +
> +OUT="${LOG}.out"
> +
> +run_prog ./abbrev-e
> +run_strace -e verbose=uname -euname -qq $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..ba07fa9
> --- /dev/null
> +++ b/tests/write-e.test
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +
> +. "${srcdir=.}/init.sh"
> +
> +check_wr()
> +{
> +    FUNCLINE=`grep -n "$1" "$LOG" | sed -n '$p' | cut -f1 -d:`
> +    let FUNCLINE=FUNCLINE+1
> +    CONTENT=`sed -n "$FUNCLINE"p "$LOG"`
> +    ERROR=`echo "$CONTENT" | 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

-- 
Thanks!
Fei Jie







More information about the Strace-devel mailing list