svn commit: r309631 - head/tools/regression/sockets/unix_cmsg
Maxim Sobolev
sobomax at FreeBSD.org
Tue Dec 6 18:22:26 UTC 2016
Author: sobomax
Date: Tue Dec 6 18:22:25 2016
New Revision: 309631
URL: https://svnweb.freebsd.org/changeset/base/309631
Log:
Auto-generate 2 test cases that differ only in structure and SCM_XXX constant
used. We can do it programmatically, but that would make code convoluted
and more complex. I have two more of those types coming for the CLOCK_REALTIME
and CLOCK_MONOTONIC. This seems like an elegant and scallable approach.
Added:
head/tools/regression/sockets/unix_cmsg/t_xxxtime.c.in
- copied, changed from r309630, head/tools/regression/sockets/unix_cmsg/t_timeval.c
head/tools/regression/sockets/unix_cmsg/t_xxxtime.h.in
- copied, changed from r309590, head/tools/regression/sockets/unix_cmsg/t_timeval.h
Deleted:
head/tools/regression/sockets/unix_cmsg/t_bintime.c
head/tools/regression/sockets/unix_cmsg/t_bintime.h
head/tools/regression/sockets/unix_cmsg/t_timeval.c
head/tools/regression/sockets/unix_cmsg/t_timeval.h
Modified:
head/tools/regression/sockets/unix_cmsg/Makefile
Modified: head/tools/regression/sockets/unix_cmsg/Makefile
==============================================================================
--- head/tools/regression/sockets/unix_cmsg/Makefile Tue Dec 6 17:13:17 2016 (r309630)
+++ head/tools/regression/sockets/unix_cmsg/Makefile Tue Dec 6 18:22:25 2016 (r309631)
@@ -1,11 +1,31 @@
# $FreeBSD$
PROG= unix_cmsg
-SRCS= unix_cmsg.c t_bintime.h t_bintime.c uc_common.h uc_common.c \
- t_generic.h t_generic.c t_peercred.h t_peercred.c t_timeval.h \
- t_timeval.c t_cmsgcred.h t_cmsgcred.c t_sockcred.h t_sockcred.c \
+SRCS= ${AUTOSRCS} unix_cmsg.c uc_common.h uc_common.c \
+ t_generic.h t_generic.c t_peercred.h t_peercred.c \
+ t_cmsgcred.h t_cmsgcred.c t_sockcred.h t_sockcred.c \
t_cmsgcred_sockcred.h t_cmsgcred_sockcred.c t_cmsg_len.h t_cmsg_len.c
+CLEANFILES+= ${AUTOSRCS}
MAN=
WARNS?= 3
+REXP_bintime= 's|%%TTYPE%%|bintime|g ; s|%%DTYPE%%|bintime|g ; \
+ s|%%SCM_TTYPE%%|SCM_BINTIME|g ; \
+ s|%%MAJ_MEMB%%|sec|g ; s|%%MIN_MEMB%%|frac|g'
+REXP_timeval= 's|%%TTYPE%%|timeval|g ; s|%%DTYPE%%|timeval|g ; \
+ s|%%SCM_TTYPE%%|SCM_TIMESTAMP|g ; \
+ s|%%MAJ_MEMB%%|tv_sec|g ; s|%%MIN_MEMB%%|tv_usec|g'
+
+.for ttype in bintime timeval
+AUTOSRCS+= t_${ttype}.h t_${ttype}.c
+
+t_${ttype}.o: t_${ttype}.c t_${ttype}.h
+
+t_${ttype}.c: t_xxxtime.c.in
+ sed ${REXP_${ttype}} < ${.ALLSRC} > ${.TARGET}
+
+t_${ttype}.h: t_xxxtime.h.in
+ sed ${REXP_${ttype}} < ${.ALLSRC} > ${.TARGET}
+.endfor
+
.include <bsd.prog.mk>
Copied and modified: head/tools/regression/sockets/unix_cmsg/t_xxxtime.c.in (from r309630, head/tools/regression/sockets/unix_cmsg/t_timeval.c)
==============================================================================
--- head/tools/regression/sockets/unix_cmsg/t_timeval.c Tue Dec 6 17:13:17 2016 (r309630, copy source)
+++ head/tools/regression/sockets/unix_cmsg/t_xxxtime.c.in Tue Dec 6 18:22:25 2016 (r309631)
@@ -27,6 +27,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -35,28 +36,29 @@ __FBSDID("$FreeBSD$");
#include <stdbool.h>
#include <stdlib.h>
-#include "uc_common.h"
+#include "t_%%TTYPE%%.h"
#include "t_generic.h"
-#include "t_timeval.h"
+#include "uc_common.h"
+#if defined(%%SCM_TTYPE%%)
static int
-check_scm_timestamp(struct cmsghdr *cmsghdr)
+check_scm_%%TTYPE%%(struct cmsghdr *cmsghdr)
{
- const struct timeval *tv;
+ const struct %%DTYPE%% *bt;
- if (uc_check_cmsghdr(cmsghdr, SCM_TIMESTAMP, sizeof(struct timeval)) < 0)
+ if (uc_check_cmsghdr(cmsghdr, %%SCM_TTYPE%%, sizeof(struct %%DTYPE%%)) < 0)
return (-1);
- tv = (struct timeval *)CMSG_DATA(cmsghdr);
+ bt = (struct %%DTYPE%% *)CMSG_DATA(cmsghdr);
- uc_dbgmsg("timeval.tv_sec %"PRIdMAX", timeval.tv_usec %"PRIdMAX,
- (intmax_t)tv->tv_sec, (intmax_t)tv->tv_usec);
+ uc_dbgmsg("%%DTYPE%%.%%MAJ_MEMB%% %"PRIdMAX", %%DTYPE%%.%%MIN_MEMB%% %"PRIuMAX,
+ (intmax_t)bt->%%MAJ_MEMB%%, (uintmax_t)bt->%%MIN_MEMB%%);
return (0);
}
static int
-t_timeval_client(int fd)
+t_%%TTYPE%%_client(int fd)
{
struct msghdr msghdr;
struct iovec iov[1];
@@ -69,14 +71,14 @@ t_timeval_client(int fd)
rv = -2;
- cmsg_size = CMSG_SPACE(sizeof(struct timeval));
+ cmsg_size = CMSG_SPACE(sizeof(struct %%DTYPE%%));
cmsg_data = malloc(cmsg_size);
if (cmsg_data == NULL) {
uc_logmsg("malloc");
goto done;
}
uc_msghdr_init_client(&msghdr, iov, cmsg_data, cmsg_size,
- SCM_TIMESTAMP, sizeof(struct timeval));
+ %%SCM_TTYPE%%, sizeof(struct %%DTYPE%%));
if (uc_socket_connect(fd) < 0)
goto done;
@@ -91,7 +93,7 @@ done:
}
static int
-t_timeval_server(int fd1)
+t_%%TTYPE%%_server(int fd1)
{
struct msghdr msghdr;
struct iovec iov[1];
@@ -107,7 +109,7 @@ t_timeval_server(int fd1)
fd2 = -1;
rv = -2;
- cmsg_size = CMSG_SPACE(sizeof(struct timeval));
+ cmsg_size = CMSG_SPACE(sizeof(struct %%DTYPE%%));
cmsg_data = malloc(cmsg_size);
if (cmsg_data == NULL) {
uc_logmsg("malloc");
@@ -135,7 +137,7 @@ t_timeval_server(int fd1)
break;
cmsghdr = CMSG_FIRSTHDR(&msghdr);
- if (check_scm_timestamp(cmsghdr) < 0)
+ if (check_scm_%%TTYPE%%(cmsghdr) < 0)
break;
}
if (i > uc_cfg.ipc_msg.msg_num)
@@ -149,7 +151,8 @@ done:
}
int
-t_timeval(void)
+t_%%TTYPE%%(void)
{
- return (t_generic(t_timeval_client, t_timeval_server));
+ return (t_generic(t_%%TTYPE%%_client, t_%%TTYPE%%_server));
}
+#endif /* %%SCM_TTYPE%% */
Copied and modified: head/tools/regression/sockets/unix_cmsg/t_xxxtime.h.in (from r309590, head/tools/regression/sockets/unix_cmsg/t_timeval.h)
==============================================================================
--- head/tools/regression/sockets/unix_cmsg/t_timeval.h Tue Dec 6 01:35:27 2016 (r309590, copy source)
+++ head/tools/regression/sockets/unix_cmsg/t_xxxtime.h.in Tue Dec 6 18:22:25 2016 (r309631)
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2005 Andrey Simonenko
+ * Copyright (c) 2016 Maksym Sobolyev <sobomax at FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,4 +27,6 @@
* $FreeBSD$
*/
-int t_timeval(void);
+#if defined(%%SCM_TTYPE%%)
+int t_%%TTYPE%%(void);
+#endif
More information about the svn-src-all
mailing list