[PATCH v3] tests: Add test for the futex syscall
* tests/futex.c: New file. * tests/futex.test: Likewise. * tests/Makefile.am (check_PROGRAMS): Add futex. (DECODER_TESTS): Add futex.test. --- Changes since v2: * Commands not available on the old kernels (2.6.18 onwards) are wrapped in CHECK_FUTEX_ENOSYS which prevents failure in case errno is ENOSYS and is not expected one. * Checks for PI mutexes do no rely on PID 2 being kthreadd (which is not true when process namespaces are employed, for example). * Printing return code is done via retstr() which utilizes errno2name for errno printing. * All headers except asm/unistd.h moved under ifdef __NR_futex. * inclusion removed since it is proven broken in some distros * Added definitions for FUTEX_PRIVATE_FLAG, FUTEX_CLOCK_REALTIME, FUTEX_CMD_MASK * Skip on EPERM since it is sometimes returned for otherwise perfectly valid commands (WAKE_OP on AArch64) * Minor formatting fixes. tests/Makefile.am |2 + tests/futex.c | 692 + tests/futex.test |8 + 3 files changed, 702 insertions(+) create mode 100644 tests/futex.c create mode 100755 tests/futex.test diff --git a/tests/Makefile.am b/tests/Makefile.am index 0c28f06..93ed37f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -125,6 +125,7 @@ check_PROGRAMS = \ fsync \ ftruncate \ ftruncate64 \ + futex \ futimesat \ get_mempolicy \ getcwd \ @@ -457,6 +458,7 @@ DECODER_TESTS = \ ftruncate.test \ ftruncate64.test \ futimesat.test \ + futex.test \ get_mempolicy.test \ getcwd.test \ getdents.test \ diff --git a/tests/futex.c b/tests/futex.c new file mode 100644 index 000..dd6955e --- /dev/null +++ b/tests/futex.c @@ -0,0 +1,692 @@ +#include "tests.h" + +#include + +#ifdef __NR_futex + +# include +# include +# include +# include +# include +# include + +# include + +# ifndef FUTEX_PRIVATE_FLAG +# define FUTEX_PRIVATE_FLAG 128 +# endif +# ifndef FUTEX_CLOCK_REALTIME +# define FUTEX_CLOCK_REALTIME 256 +# endif +# ifndef FUTEX_CMD_MASK +# define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) +# endif + +# include "xlat.h" +# include "xlat/futexops.h" +# include "xlat/futexwakeops.h" +# include "xlat/futexwakecmps.h" + +static struct timespec *tmout; + +void futex_error(int *uaddr, int op, unsigned long val, unsigned long timeout, + int *uaddr2, unsigned long val3, int rc) +{ + perror_msg_and_fail("futex(%p, %#x, %#x, %#lx, %p, %#x) = %d", + uaddr, op, (unsigned)val, timeout, uaddr, (unsigned)val3, rc); +} + +# define CHECK_FUTEX_GENERIC(uaddr, op, val, timeout, uaddr2, val3, check, \ + enosys) \ + do { \ + rc = syscall(__NR_futex, (uaddr), (op), (val), (timeout), \ + (uaddr2), (val3)); \ + /* It is here due to EPERM on WAKE_OP on AArch64 */ \ + if ((rc == -1) && (errno == EPERM)) \ + break; \ + if (enosys && (rc == -1) && (errno == ENOSYS)) \ + break; \ + if (!(check)) \ + futex_error((uaddr), (op), (val), \ + (unsigned long)(timeout), (int *)(uaddr2), \ + (val3), rc); \ + } while (0) + +# define CHECK_FUTEX_ENOSYS(uaddr, op, val, timeout, uaddr2, val3, check) \ + CHECK_FUTEX_GENERIC(uaddr, op, val, timeout, uaddr2, val3, check, 1) + +# define CHECK_FUTEX(uaddr, op, val, timeout, uaddr2, val3, check) \ + CHECK_FUTEX_GENERIC(uaddr, op, val, timeout, uaddr2, val3, check, 0) + +enum argmask { + ARG3 = 1 << 0, + ARG4 = 1 << 1, + ARG5 = 1 << 2, + ARG6 = 1 << 3, +}; + +void invalid_op(int *val, int op, uint32_t argmask, ...) +{ + static const unsigned long args[] = { + (unsigned long)0xface1e55deadbee1ULL, + (unsigned long)0xface1e56deadbee2ULL, + (unsigned long)0xface1e57deadbee3ULL, + (unsigned long)0xface1e58deadbee4ULL, + }; + /* Since timeout value is copied before full op check, we should provide +* some valid timeout address or NULL */ + int cmd = op & FUTEX_CMD_MASK; + bool valid_timeout = (cmd == FUTEX_WAIT) || (cmd == FUTEX_LOCK_PI) || + (cmd == FUTEX_WAIT_BITSET) || (cmd == FUTEX_WAIT_REQUEUE_PI); + bool timeout_is_val2 = (cmd == FUTEX_REQUEUE) || + (cmd == FUTEX_CMP_REQUEUE) || (cmd == FUTEX_WAKE_OP) || + (cmd == FUTEX_CMP_REQUEUE_PI); + const char *fmt; + int saved_errno; + int rc; + int i; + va_list ap; + + + CHECK_FUTEX(val, op, args[0], valid_timeout ? 0 : args[1], args[2], + args[3], (rc == -1) && (errno == ENOSYS)); + saved_errno = errno; + printf("futex(%p, %#x /* FUTEX_??? */", val, op); + + va_start(ap, argmask); + +
Re: [PATCH 2/2] Use the correct m32/mx32 st_mtime_nsec check in tests/xstatx.c
On 30 Aug 2016, at 16:59, Dmitry V. Levin wrote: > On Tue, Aug 30, 2016 at 12:50:34AM +0100, James Clarke wrote: >> * tests/Makefile.am: Define MPERS_IS_m(x)32 for mpers builds. >> * tests/xstatx.c: Use the correct m32/mx32 and stat/stat64 macros when >> checking if st_mtime_nsec exists. >> --- >> >> Hi, >> This fixes tests-m32 failures for the *stat.c (32-bit native) test cases, as >> sparc64's stat does not have nsec, but sparc's does, so xstatx.c wasn't >> printing the nsec (but strace itself was correctly printing it). It doesn't >> look quite right given there's a whole load of other nsec stuff above it, but >> it's sufficient on sparc64. I don't expect it to be committed as-is, but >> hopefully it's helpful. >> >> Regards, >> James > > I've made a slightly different change based on your patch. Thanks! Tested and verified it works, thanks! >> tests/Makefile.am | 3 +++ >> tests/xstatx.c| 24 >> 2 files changed, 27 insertions(+) >> >> diff --git a/tests/Makefile.am b/tests/Makefile.am >> index 0c28f06..26d5a3a 100644 >> --- a/tests/Makefile.am >> +++ b/tests/Makefile.am >> @@ -38,6 +38,9 @@ AM_CPPFLAGS = $(ARCH_MFLAGS) \ >>-I$(top_srcdir)/$(OS) \ >>-I$(top_builddir) \ >>-I$(top_srcdir) >> +ifneq ($(MPERS_NAME),) >> +AM_CPPFLAGS += -DMPERS_IS_$(MPERS_NAME) >> +endif > > GNU Automake doesn't like this, so I've moved it to ARCH_MFLAGS. Ah. I tested this by patching Makefile.in instead and didn’t even consider that Automake wouldn’t like it. James -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
Re: [PATCH 2/2] Use the correct m32/mx32 st_mtime_nsec check in tests/xstatx.c
On Tue, Aug 30, 2016 at 12:50:34AM +0100, James Clarke wrote: > * tests/Makefile.am: Define MPERS_IS_m(x)32 for mpers builds. > * tests/xstatx.c: Use the correct m32/mx32 and stat/stat64 macros when > checking if st_mtime_nsec exists. > --- > > Hi, > This fixes tests-m32 failures for the *stat.c (32-bit native) test cases, as > sparc64's stat does not have nsec, but sparc's does, so xstatx.c wasn't > printing the nsec (but strace itself was correctly printing it). It doesn't > look quite right given there's a whole load of other nsec stuff above it, but > it's sufficient on sparc64. I don't expect it to be committed as-is, but > hopefully it's helpful. > > Regards, > Hames I've made a slightly different change based on your patch. Thanks! > tests/Makefile.am | 3 +++ > tests/xstatx.c| 24 > 2 files changed, 27 insertions(+) > > diff --git a/tests/Makefile.am b/tests/Makefile.am > index 0c28f06..26d5a3a 100644 > --- a/tests/Makefile.am > +++ b/tests/Makefile.am > @@ -38,6 +38,9 @@ AM_CPPFLAGS = $(ARCH_MFLAGS) \ > -I$(top_srcdir)/$(OS) \ > -I$(top_builddir) \ > -I$(top_srcdir) > +ifneq ($(MPERS_NAME),) > +AM_CPPFLAGS += -DMPERS_IS_$(MPERS_NAME) > +endif GNU Automake doesn't like this, so I've moved it to ARCH_MFLAGS. > AM_LDFLAGS = $(ARCH_MFLAGS) > > libtests_a_SOURCES = \ > diff --git a/tests/xstatx.c b/tests/xstatx.c > index 359ee1d..8dbe89f 100644 > --- a/tests/xstatx.c > +++ b/tests/xstatx.c > @@ -108,6 +108,30 @@ typedef off_t libc_off_t; > # endif /* HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC */ > # endif > > +# if defined MPERS_IS_m32 > +# undef HAVE_STRUCT_STAT_ST_MTIME_NSEC > +# if STRUCT_STAT_IS_STAT64 > +# ifdef HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC > +#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1 > +# endif /* HAVE_M32_STRUCT_STAT64_ST_MTIME_NSEC */ > +# else > +# ifdef HAVE_M32_STRUCT_STAT_ST_MTIME_NSEC > +#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1 > +# endif /* HAVE_M32_STRUCT_STAT_ST_MTIME_NSEC */ > +# endif /* STRUCT_STAT_IS_STAT64 */ > +# elif defined MPERS_IS_mx32 > +# undef HAVE_STRUCT_STAT_ST_MTIME_NSEC > +# if STRUCT_STAT_IS_STAT64 > +# ifdef HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC > +#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1 > +# endif /* HAVE_MX32_STRUCT_STAT64_ST_MTIME_NSEC */ > +# else > +# ifdef HAVE_MX32_STRUCT_STAT_ST_MTIME_NSEC > +#define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1 > +# endif /* HAVE_MX32_STRUCT_STAT_ST_MTIME_NSEC */ > +# endif /* STRUCT_STAT_IS_STAT64 */ > +# endif This (or something like this) had to be placed inside USE_ASM_STAT section. -- ldv pgpcvUroKSlDm.pgp Description: PGP signature -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
Re: [PATCH] futex: Remove inclusion which is not used
On Tue, Aug 30, 2016 at 04:24:37PM +0300, Eugene Syromyatnikov wrote: > configure script doesn't perform check for linux/futex.h presence, so > HAVE_LINUX_FUTEX_H is always undefined and inclusion of system header is > never performed. Moreover, this header had an incorrect definition of > FUTEX_WAIT_BITSET_PRIVATE/FUTEX_WAKE_BITSET_PRIVATE in the past: from > commit v2.6.24-6320-gcd68998 (where these definitions had been initially > introduced) up to v2.6.31-7082-gf8d1e54 (where they have be finally > fixed) these macros has been incorrectly defined via > FUTEX_WAIT_BITS/FUTEX_WAKE_BITS (not FUTEX_WAIT_BITSET/FUTEX_WAKE_BITSET) > and these incorrect definitions made their way in some distributions still > in use. > > * futex.c: Remove conditional inclusion: HAVE_LINUX_FUTEX_H > is never defined and this is dead code, effectively. > --- > futex.c |4 > 1 file changed, 4 deletions(-) > > diff --git a/futex.c b/futex.c > index 9410b2a..d1b5a42 100644 > --- a/futex.c > +++ b/futex.c > @@ -30,10 +30,6 @@ > > #include "defs.h" > > -#ifdef HAVE_LINUX_FUTEX_H > -# include > -#endif > - > #ifndef FUTEX_PRIVATE_FLAG > # define FUTEX_PRIVATE_FLAG 128 > #endif LGTM -- ldv pgpxv3073G1WO.pgp Description: PGP signature -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
[PATCH] futex: Remove inclusion which is not used
configure script doesn't perform check for linux/futex.h presence, so HAVE_LINUX_FUTEX_H is always undefined and inclusion of system header is never performed. Moreover, this header had an incorrect definition of FUTEX_WAIT_BITSET_PRIVATE/FUTEX_WAKE_BITSET_PRIVATE in the past: from commit v2.6.24-6320-gcd68998 (where these definitions had been initially introduced) up to v2.6.31-7082-gf8d1e54 (where they have be finally fixed) these macros has been incorrectly defined via FUTEX_WAIT_BITS/FUTEX_WAKE_BITS (not FUTEX_WAIT_BITSET/FUTEX_WAKE_BITSET) and these incorrect definitions made their way in some distributions still in use. * futex.c: Remove conditional inclusion: HAVE_LINUX_FUTEX_H is never defined and this is dead code, effectively. --- futex.c |4 1 file changed, 4 deletions(-) diff --git a/futex.c b/futex.c index 9410b2a..d1b5a42 100644 --- a/futex.c +++ b/futex.c @@ -30,10 +30,6 @@ #include "defs.h" -#ifdef HAVE_LINUX_FUTEX_H -# include -#endif - #ifndef FUTEX_PRIVATE_FLAG # define FUTEX_PRIVATE_FLAG 128 #endif -- 1.7.10.4 -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel
Re: [PATCH 1/2] Use PTRACE_SUNDETACH everywhere on SPARC and SPARC64
On Tue, Aug 30, 2016 at 12:50:33AM +0100, James Clarke wrote: > SPARC has a different PTRACE_DETACH value correctly defined in sys/ptrace.h, > but linux/ptrace.h clobbers it with the standard one. PTRACE_SUNDETACH is > also defined to the correct value by sys/ptrace.h, so use that instead. > > * pthread.h [SPARC || SPARC64]: Define PTRACE_DETACH as PTRACE_SUNDETACH. > * strace.c (detach) [SPARC]: Remove PTRACE_DETACH definition and use the > one from pthread.h. Applied, thanks. -- ldv pgpY2iK4HAV1U.pgp Description: PGP signature -- ___ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel