[PATCH] tests/mknod.c: add workaround for ppc bug in travis

Ákos Uzonyi uzonyi.akos at gmail.com
Tue Aug 25 13:36:23 UTC 2020


On Tue, 25 Aug 2020 at 15:00, Dmitry V. Levin <ldv at altlinux.org> wrote:
> On Tue, Aug 25, 2020 at 02:54:13PM +0200, Ákos Uzonyi wrote:
> > On ppc travis builds syscall(mknod) sometimes does not fail with EEXISTS
> > as expected, but returns successfully.
> >
> > A new print_errno function is added, which handles the case when errno
> > is 0.
> >
> > * tests/errno2name.c (print_errno): New function.
> > * tests/defs.h (errno2name.c): New function declaration.
> > * tests/mknod.c (call_mknod): set errno to 0 before syscall.
> > (main): Use print_errno for printing errno.
> > ---
> >  tests/errno2name.c |  9 +++++++++
> >  tests/mknod.c      | 42 ++++++++++++++++++++++++++----------------
> >  tests/tests.h      |  8 ++++++++
> >  3 files changed, 43 insertions(+), 16 deletions(-)
> >
> > diff --git a/tests/errno2name.c b/tests/errno2name.c
> > index 56340d75..103ea08d 100644
> > --- a/tests/errno2name.c
> > +++ b/tests/errno2name.c
> > @@ -8,6 +8,15 @@
> >
> >  #include "tests.h"
> >  #include <errno.h>
> > +#include <stdio.h>
> > +
> > +void
> > +print_errno(void)
> > +{
> > +     if (errno)
> > +             printf(" %s (%m)", errno2name());
> > +     puts("");
> > +}
> >
> >  #define CASE(x) case x: return #x
> >
> > diff --git a/tests/mknod.c b/tests/mknod.c
> > index 44c6f028..03cb8ef2 100644
> > --- a/tests/mknod.c
> > +++ b/tests/mknod.c
> > @@ -10,6 +10,7 @@
> >
> >  #ifdef __NR_mknod
> >
> > +# include <errno.h>
> >  # include <stdio.h>
> >  # include <sys/stat.h>
> >  # include <sys/sysmacros.h>
> > @@ -20,6 +21,7 @@ static const char *sample;
> >  static long
> >  call_mknod(unsigned short mode, unsigned long dev)
> >  {
> > +     errno = 0;
> >       unsigned long lmode = (unsigned long) 0xffffffffffff0000ULL | mode;
> >       return syscall(__NR_mknod, sample, lmode, dev);
> >  }
> > @@ -31,44 +33,52 @@ main(int ac, char **av)
> >       sample = av[0];
> >
> >       long rc = call_mknod(0, dev);
> > -     printf("mknod(\"%s\", 000) = %ld %s (%m)\n",
> > -            sample, rc, errno2name());
> > +     printf("mknod(\"%s\", 000) = %ld",
> > +            sample, rc);
> > +     print_errno();
> >
> >       rc = call_mknod(0xffff, dev);
> > -     printf("mknod(\"%s\", %#03ho) = %ld %s (%m)\n",
> > -            sample, (unsigned short) -1, rc, errno2name());
> > +     printf("mknod(\"%s\", %#03ho) = %ld",
> > +            sample, (unsigned short) -1, rc);
> > +     print_errno();
> >
> >       rc = call_mknod(S_IFREG, 0);
> > -     printf("mknod(\"%s\", S_IFREG|000) = %ld %s (%m)\n",
> > -            sample, rc, errno2name());
> > +     printf("mknod(\"%s\", S_IFREG|000) = %ld",
> > +            sample, rc);
> > +     print_errno();
> >
> >       rc = call_mknod(S_IFDIR | 06, 0);
> > -     printf("mknod(\"%s\", S_IFDIR|006) = %ld %s (%m)\n",
> > -            sample, rc, errno2name());
> > +     printf("mknod(\"%s\", S_IFDIR|006) = %ld",
> > +            sample, rc);
> > +     print_errno();
> >
> >       rc = call_mknod(S_IFLNK | 060, 0);
> > -     printf("mknod(\"%s\", S_IFLNK|060) = %ld %s (%m)\n",
> > -            sample, rc, errno2name());
> > +     printf("mknod(\"%s\", S_IFLNK|060) = %ld",
> > +            sample, rc);
> > +     print_errno();
> >
> >       rc = call_mknod(S_IFIFO | 0600, 0);
> > -     printf("mknod(\"%s\", S_IFIFO|0600) = %ld %s (%m)\n",
> > -            sample, rc, errno2name());
> > +     printf("mknod(\"%s\", S_IFIFO|0600) = %ld",
> > +            sample, rc);
> > +     print_errno();
> >
> >       dev = (unsigned long) 0xdeadbeef00000000ULL | makedev(1, 7);
> >
> >       rc = call_mknod(S_IFCHR | 024, dev);
> > -     printf("mknod(\"%s\", S_IFCHR|024, makedev(0x1, 0x7)) = %ld %s (%m)\n",
> > -            sample, rc, errno2name());
> > +     printf("mknod(\"%s\", S_IFCHR|024, makedev(0x1, 0x7)) = %ld",
> > +            sample, rc);
> > +     print_errno();
> >
> >       const unsigned short mode = (0xffff & ~S_IFMT) | S_IFBLK;
> >       dev = (unsigned long) 0xdeadbeefbadc0dedULL;
> >
> >       rc = call_mknod(mode, dev);
> >       printf("mknod(\"%s\", S_IFBLK|S_ISUID|S_ISGID|S_ISVTX|%#03ho"
> > -            ", makedev(%#x, %#x)) = %ld %s (%m)\n",
> > +            ", makedev(%#x, %#x)) = %ld",
> >              sample, (short) (mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX)),
> >              major((unsigned) dev), minor((unsigned) dev),
> > -            rc, errno2name());
> > +            rc);
> > +     print_errno();
> >
> >       puts("+++ exited with 0 +++");
> >       return 0;
>
> We already have (and use) sprintrc, could it be useful here, too?

Thanks, that's exactly what we need here. I remember seeing sprintc in
the past, but I forgot about it.

I'm sending a v2 with sprintrc...


More information about the Strace-devel mailing list