[PATCH v2] tests/fcntl-common.c: extend coverage for other fcntl flags

Zhibin Li 08826794brmt at gmail.com
Tue Jul 10 13:14:27 UTC 2018


I almost forget it. Thanks for reminding.

On Tue, Jul 10, 2018 at 7:51 PM Dmitry V. Levin <ldv at altlinux.org> wrote:

> On Wed, Jul 04, 2018 at 12:04:22AM +0300, Dmitry V. Levin wrote:
> > On Fri, Jun 15, 2018 at 05:00:05PM +0800, Zhibin Li wrote:
> > [...]
> > > --- a/tests/fcntl-common.c
> > > +++ b/tests/fcntl-common.c
> > > @@ -31,7 +31,9 @@
> > >  #include <stdlib.h>
> > >  #include <string.h>
> > >  #include <unistd.h>
> > > +#include <assert.h>
> > >  #include "flock.h"
> > > +#include "signal2name.c"
> >
> > No need to include "signal2name.c", it's available via libtests,
> > you can just use signal2name().
> >
> > >
> > >  #define FILE_LEN 4096
> > >
> > > @@ -238,6 +240,135 @@ test_f_owner_ex(void)
> > >  }
> > >  #endif /* TEST_F_OWNER_EX */
> > >
> > > +struct fcntl_cmd_check {
> > > +   int fd;
> > > +   int cmd;
> > > +   const char *cmd_str;
> > > +   long arg;
> > > +   const char *arg_str;
> > > +   void (*print_flags)(long rc);
> > > +};
> > > +
> > > +static void
> > > +print_retval_flags(const struct fcntl_cmd_check *check, long rc)
> > > +{
> > > +   if (check->print_flags) {
> > > +           check->print_flags(rc);
> > > +   } else {
> > > +           printf("%s", errstr);
> > > +   }
> > > +   printf("\n");
> > > +}
> > > +
> > > +static void
> > > +test_other_set_cmd(const struct fcntl_cmd_check *check)
> > > +{
> > > +   invoke_test_syscall(check->fd, check->cmd, (void *) check->arg);
> >
> > This explicit cast to (void *) is redundant.
> >
> > > +   printf("%s(%d, %s, %s) = %s\n",
> > > +          TEST_SYSCALL_STR, check->fd,
> > > +          check->cmd_str, check->arg_str, errstr);
> > > +
> > > +   /* bad file fd */
> > > +   invoke_test_syscall(-1, check->cmd, (void *) check->arg);
> >
> > Likewise.
> >
> > > +   printf("%s(-1, %s, %s) = %s\n",
> > > +          TEST_SYSCALL_STR, check->cmd_str,
> > > +          check->arg_str, errstr);
> > > +}
> > > +
> > > +static void
> > > +test_other_get_cmd(const struct fcntl_cmd_check *check)
> > > +{
> > > +   long rc = invoke_test_syscall(check->fd, check->cmd, NULL);
> > > +   printf("%s(%d, %s) = ",
> > > +          TEST_SYSCALL_STR, check->fd, check->cmd_str);
> > > +   print_retval_flags(check, rc);
> > > +
> > > +   /* bad file fd */
> > > +   invoke_test_syscall(-1, check->cmd, NULL);
> > > +   printf("%s(-1, %s) = %s\n",
> > > +          TEST_SYSCALL_STR, check->cmd_str, errstr);
> > > +}
> > > +
> > > +static void
> > > +print_flags_getfd(long rc)
> > > +{
> > > +   assert(rc >= 0);
> > > +   const char *text;
> > > +   text = rc & 1 ? " (flags FD_CLOEXEC)" : "";
> > > +   printf("%#lx%s", rc, text);
> >
> > This "text" variable looks redundant here.
> >
> > > +}
> > > +
> > > +static void
> > > +print_flags_getsig(long rc)
> > > +{
> > > +   assert(rc >= 0);
> > > +   const char *text;
> > > +
> > > +   if (!rc) {
> > > +           text = "";
> >
> > This assignment is redundant.
> >
> > > +           printf("%ld", rc);
> > > +   } else {
> > > +           text = signal2name((int) rc);
> > > +           printf("%ld (%s)", rc, text);
> >
> > This "text" variable looks redundant here.
>
> Is there any process with this?
>
>
> --
> ldv
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180710/7f430939/attachment.html>


More information about the Strace-devel mailing list