summaryrefslogtreecommitdiff
path: root/tests/sockopt-timestamp.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@strace.io>2021-07-23 08:00:00 +0000
committerDmitry V. Levin <ldv@strace.io>2021-07-23 08:00:00 +0000
commit0211fdc31381fde93f9a561fbcfab5b17efbe850 (patch)
tree6c9d04a765457ad5eee942839e42bf529d0f3fad /tests/sockopt-timestamp.c
parent383e50a3bafbfd1863694a4c1924aa214ced2ae1 (diff)
downloadstrace-0211fdc31381fde93f9a561fbcfab5b17efbe850.tar.gz
tests: change sockopt-timestamp test to use syscall(__NR_recvmsg)
Since the glibc recvmsg wrapper became unsuitable for our needs, invoke __NR_recvmsg syscall directly. * tests/sockopt-timestamp.c: Include "scno.h" and <errno.h>, conditionalize on __NR_recvmsg. (TEST_OLD_SCM_TIMESTAMPS): Remove. (k_recvmsg): New function. (test_sockopt): Use it instead of recvmsg.
Diffstat (limited to 'tests/sockopt-timestamp.c')
-rw-r--r--tests/sockopt-timestamp.c72
1 files changed, 34 insertions, 38 deletions
diff --git a/tests/sockopt-timestamp.c b/tests/sockopt-timestamp.c
index 33e0c1a82..34c4d89a1 100644
--- a/tests/sockopt-timestamp.c
+++ b/tests/sockopt-timestamp.c
@@ -9,44 +9,45 @@
*/
#include "tests.h"
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-
-#if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \
- || defined HAVE_STRUCT___KERNEL_TIMESPEC
-# include <linux/time_types.h>
-#endif
+#include "scno.h"
-#include "kernel_timeval.h"
-#include "kernel_old_timespec.h"
+#ifdef __NR_recvmsg
-#define XLAT_MACROS_ONLY
-# include "xlat/sock_options.h"
-#undef XLAT_MACROS_ONLY
+# include <errno.h>
+# include <stdio.h>
+# include <string.h>
+# include <unistd.h>
+# include <sys/socket.h>
-#undef TEST_OLD_SCM_TIMESTAMPS
+# if defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL \
+ || defined HAVE_STRUCT___KERNEL_TIMESPEC
+# include <linux/time_types.h>
+# endif
-/*
- * Sadly, starting with commit
- * glibc-2.33.9000-707-g13c51549e2077f2f3bf84e8fd0b46d8b0c615912, on every
- * 32-bit architecture where 32-bit time_t support is enabled,
- * glibc mangles old scm timestamps.
- */
-#if GLIBC_PREREQ_GE(2, 33) && defined __TIMESIZE && __TIMESIZE != 64
-# define TEST_OLD_SCM_TIMESTAMPS 0
-#endif
+# include "kernel_timeval.h"
+# include "kernel_old_timespec.h"
-#ifndef TEST_OLD_SCM_TIMESTAMPS
-# define TEST_OLD_SCM_TIMESTAMPS 1
-#endif
+# define XLAT_MACROS_ONLY
+# include "xlat/sock_options.h"
+# undef XLAT_MACROS_ONLY
-#if TEST_OLD_SCM_TIMESTAMPS \
- || defined HAVE_STRUCT___KERNEL_TIMESPEC \
- || defined HAVE_STRUCT___KERNEL_SOCK_TIMEVAL
+static const char *errstr;
+
+static long
+k_recvmsg(const unsigned int fd, const void *const ptr, const unsigned int flags)
+{
+ const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
+ const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
+ const kernel_ulong_t arg1 = fill | fd;
+ const kernel_ulong_t arg2 = (uintptr_t) ptr;
+ const kernel_ulong_t arg3 = fill | flags;
+ const long rc = syscall(__NR_recvmsg, arg1, arg2, arg3, bad, bad, bad);
+ if (rc && errno == ENOSYS)
+ perror_msg_and_skip("recvmsg");
+ errstr = sprintrc(rc);
+ return rc;
+}
-# if TEST_OLD_SCM_TIMESTAMPS
static void
print_timestamp_old(const struct cmsghdr *c)
{
@@ -84,7 +85,6 @@ print_timestampns_old(const struct cmsghdr *c)
printf("{tv_sec=%lld, tv_nsec=%lld}",
(long long) ts.tv_sec, (long long) ts.tv_nsec);
}
-# endif /* TEST_OLD_SCM_TIMESTAMPS */
# ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL
static void
@@ -162,7 +162,7 @@ test_sockopt(int so_val, const char *str, void (*fun)(const struct cmsghdr *))
.msg_controllen = sizeof(control)
};
- if (recvmsg(sv[0], &mh, 0) != (int) size)
+ if (k_recvmsg(sv[0], &mh, 0) != (int) size)
perror_msg_and_fail("recvmsg");
if (close(sv[0]))
perror_msg_and_fail("close recv");
@@ -212,10 +212,8 @@ main(void)
const char *str;
void (*fun)(const struct cmsghdr *);
} tests[] = {
-# if TEST_OLD_SCM_TIMESTAMPS
{ SO_TIMESTAMP_OLD, "SO_TIMESTAMP_OLD", print_timestamp_old },
{ SO_TIMESTAMPNS_OLD, "SO_TIMESTAMPNS_OLD", print_timestampns_old },
-# endif
# ifdef HAVE_STRUCT___KERNEL_SOCK_TIMEVAL
{ SO_TIMESTAMP_NEW, "SO_TIMESTAMP_NEW", print_timestamp_new },
# endif
@@ -237,8 +235,6 @@ main(void)
#else
-SKIP_MAIN_UNDEFINED("TEST_OLD_SCM_TIMESTAMPS"
- " || HAVE_STRUCT___KERNEL_TIMESPEC"
- " || HAVE_STRUCT___KERNEL_SOCK_TIMEVAL")
+SKIP_MAIN_UNDEFINED("__NR_recvmsg")
#endif