On Fri, Jan 08, 2016 at 04:07:52PM +0800, Fei, Jie/费 杰 wrote:
> 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?
[...]
> > 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"

What are you testing here?  Since the default behavior is abbrev=all,
I suppose you meant something different from what you've written here.

> > +
> > +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"

getpid is not portable: alpha has no getpid syscall.

> > +
> > +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"`

"let" keyword is not a portable /bin/sh syntax,
and the whole shell script does not use regular shell programming
patterns, e.g. there is no need to save sed's output to a variable
just to grep it afterwards.

> > +    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"

What are you testing here?  Since the default behavior is verbose=all,
I suppose you meant something different from what you've written here.

> > +
> > +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"`

"let" keyword is not a portable /bin/sh syntax,
and the whole shell script does not use regular shell programming
patterns, e.g. there is no need to save sed's output to a variable
just to grep it afterwards.


-- 
ldv

Attachment: pgpHhlbHJeIWt.pgp
Description: PGP signature

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to