aboutsummaryrefslogtreecommitdiff
path: root/tools/regression/sockets/udp_pingpong/udp_pingpong.c
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2018-07-30 15:46:40 +0000
committerAlan Somers <asomers@FreeBSD.org>2018-07-30 15:46:40 +0000
commit6040822c4e20fb46638ecaaad543fc56f6ec2b0f (patch)
tree133352663bf8c98c65abf581f6a4a8769325ca09 /tools/regression/sockets/udp_pingpong/udp_pingpong.c
parent19fe43f796f3d962b3bf023a4484a82d7b2a5711 (diff)
downloadsrc-6040822c4e20fb46638ecaaad543fc56f6ec2b0f.tar.gz
src-6040822c4e20fb46638ecaaad543fc56f6ec2b0f.zip
Make timespecadd(3) and friends public
The timespecadd(3) family of macros were imported from NetBSD back in r35029. However, they were initially guarded by #ifdef _KERNEL. In the meantime, we have grown at least 28 syscalls that use timespecs in some way, leading many programs both inside and outside of the base system to redefine those macros. It's better just to make the definitions public. Our kernel currently defines two-argument versions of timespecadd and timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, define three-argument versions. Solaris also defines a three-argument version, but only in its kernel. This revision changes our definition to match the common three-argument version. Bump _FreeBSD_version due to the breaking KPI change. Discussed with: cem, jilles, ian, bde Differential Revision: https://reviews.freebsd.org/D14725
Notes
Notes: svn path=/head/; revision=336914
Diffstat (limited to 'tools/regression/sockets/udp_pingpong/udp_pingpong.c')
-rw-r--r--tools/regression/sockets/udp_pingpong/udp_pingpong.c41
1 files changed, 8 insertions, 33 deletions
diff --git a/tools/regression/sockets/udp_pingpong/udp_pingpong.c b/tools/regression/sockets/udp_pingpong/udp_pingpong.c
index 25750b0c3c0d..fc585d275db4 100644
--- a/tools/regression/sockets/udp_pingpong/udp_pingpong.c
+++ b/tools/regression/sockets/udp_pingpong/udp_pingpong.c
@@ -106,31 +106,6 @@ struct rtt {
#define NSEC_MAX 1000000000L
#define NSEC_IN_USEC 1000L
-#define timespecsub2(r, v, u) \
- do { \
- SEC(r) = SEC(v) - SEC(u); \
- NSEC(r) = NSEC(v) - NSEC(u); \
- if (NSEC(r) < 0 && (SEC(r) > 0 || NSEC(r) <= -NSEC_MAX)) { \
- SEC(r)--; \
- NSEC(r) += NSEC_MAX; \
- } \
- } while (0);
-
-#define timespecadd2(r, v, u) \
- do { \
- SEC(r) = SEC(v) + SEC(u); \
- NSEC(r) = NSEC(v) + NSEC(u); \
- if (NSEC(r) >= NSEC_MAX) { \
- SEC(r)++; \
- NSEC(r) -= NSEC_MAX; \
- } \
- } while (0);
-
-#define timespeccmp(t, c, u) \
- ((SEC(t) == SEC(u)) ? \
- (NSEC(t) c NSEC(u)) : \
- (SEC(t) c SEC(u)))
-
#define timeval2timespec(tv, ts) \
do { \
SEC(ts) = (tv)->tv_sec; \
@@ -536,10 +511,10 @@ static void
calc_rtt(struct test_pkt *tpp, struct rtt *rttp)
{
- timespecsub2(&rttp->a2b, &tpp->tss[1].recvd, &tpp->tss[0].sent);
- timespecsub2(&rttp->b2a, &tpp->tss[0].recvd, &tpp->tss[1].sent);
- timespecadd2(&rttp->a2b_b2a, &rttp->a2b, &rttp->b2a);
- timespecsub2(&rttp->e2e, &tpp->tss[0].recvd, &tpp->tss[0].sent);
+ timespecsub(&tpp->tss[1].recvd, &tpp->tss[0].sent, &rttp->a2b);
+ timespecsub(&tpp->tss[0].recvd, &tpp->tss[1].sent, &rttp->b2a);
+ timespecadd(&rttp->a2b, &rttp->b2a, &rttp->a2b_b2a);
+ timespecsub(&tpp->tss[0].recvd, &tpp->tss[0].sent, &rttp->e2e);
}
static void
@@ -604,13 +579,13 @@ test_run(int ts_type, int use_ipv6, int use_recvmsg, const char *name)
continue;
}
calc_rtt(&test_ctx.test_pkts[i], &rtt);
- if (!timespeccmp(&rtt.e2e, >, &rtt.a2b_b2a))
+ if (!timespeccmp(&rtt.e2e, &rtt.a2b_b2a, >))
errx(1, "end-to-end trip time is too small");
- if (!timespeccmp(&rtt.e2e, <, &max_ts))
+ if (!timespeccmp(&rtt.e2e, &max_ts, <))
errx(1, "end-to-end trip time is too large");
- if (!timespeccmp(&rtt.a2b, >, &zero_ts))
+ if (!timespeccmp(&rtt.a2b, &zero_ts, >))
errx(1, "A2B trip time is not positive");
- if (!timespeccmp(&rtt.b2a, >, &zero_ts))
+ if (!timespeccmp(&rtt.b2a, &zero_ts, >))
errx(1, "B2A trip time is not positive");
}
teardown_udp(&test_ctx);