diff options
author | martijn <martijn@openbsd.org> | 2021-01-13 17:00:20 +0000 |
---|---|---|
committer | martijn <martijn@openbsd.org> | 2021-01-13 17:00:20 +0000 |
commit | f358f99b7dff8e6e380cf2fcc05a5d8acf2609f8 (patch) | |
tree | 1de859399f8ac6aaaae6d742c009a856cdb13b2b /regress | |
parent | kernel, sysctl(8): remove dead variable: tickadj (diff) | |
download | wireguard-openbsd-f358f99b7dff8e6e380cf2fcc05a5d8acf2609f8.tar.xz wireguard-openbsd-f358f99b7dff8e6e380cf2fcc05a5d8acf2609f8.zip |
Make the binary run by linking it against net-snmpd.
Also add an actual first test. More test should probably follow, but we
have to start somewhere.
Diffstat (limited to 'regress')
-rw-r--r-- | regress/lib/libagentx/Makefile | 49 | ||||
-rw-r--r-- | regress/lib/libagentx/main.c | 86 | ||||
-rw-r--r-- | regress/lib/libagentx/walk.err | 1 | ||||
-rw-r--r-- | regress/lib/libagentx/walk.out | 91 |
4 files changed, 173 insertions, 54 deletions
diff --git a/regress/lib/libagentx/Makefile b/regress/lib/libagentx/Makefile index 992fd263962..39c8d466aa9 100644 --- a/regress/lib/libagentx/Makefile +++ b/regress/lib/libagentx/Makefile @@ -1,20 +1,45 @@ -# $OpenBSD: Makefile,v 1.2 2021/01/11 22:58:16 bluhm Exp $ +# $OpenBSD: Makefile,v 1.3 2021/01/13 17:00:20 martijn Exp $ -.if ! exists(/usr/local/lib/libnetsnmpagent.a) +.if ! exists(/usr/local/sbin/snmpd) regress: - @echo Install net-snmp package to run this regress. - @echo SKIPPED + @printf "Install net-snmp package to run this regress.\n" + @printf "SKIPPED\n" .endif -PROG= agentx -SRCS= main.c log.c -CFLAGS= -Wall -NOMAN= yes -LDADD= -lagentx -levent +PROG= agentx +SRCS= main.c log.c +CFLAGS= -Wall +NOMAN= yes +LDADD= -lagentx -levent -REGRESS_TARGETS= run-regress-agentx +REGRESS_SETUP_ONCE= start +REGRESS_TARGETS= run-regress-walk +REGRESS_CLEANUP= stop +CLEANFILES= -run-regress-agentx: ${PROG} - ${SUDO} ./${PROG} +SNMPD_CMD= /usr/local/sbin/snmpd -r -c ${.OBJDIR}/snmpd.conf + +CLEANFILES+= snmpd.conf +snmpd.conf: + @printf "agentaddress udp:127.0.0.1:6161\n" > snmpd.conf + @printf "rwcommunity public\n" >> snmpd.conf + @printf "master agentx\n" >> snmpd.conf + @printf "agentXSocket ${.OBJDIR}/agentx.sock\n" >> snmpd.conf + +CLEANFILES+= ${.OBJDIR}/agentx.sock +start: snmpd.conf + ${SNMPD_CMD} + ${.OBJDIR}/agentx ${.OBJDIR}/agentx.sock + +stop: + pkill -xf "${SNMPD_CMD}" + +CLEANFILES+= walk.run.out walk.run.err +run-regress-walk: agentx + snmp walk 127.0.0.1:6161 openbsd > walk.run.out 2> walk.run.err || true + @cmp -s ${.CURDIR}/walk.err walk.run.err || \ + (printf "XXX ${*} error failed\n" && false) + @cmp -s ${.CURDIR}/walk.out walk.run.out || \ + (printf "XXX ${*} output failed\n" && false) .include <bsd.regress.mk> diff --git a/regress/lib/libagentx/main.c b/regress/lib/libagentx/main.c index 2a60cd305d7..06bb8c60238 100644 --- a/regress/lib/libagentx/main.c +++ b/regress/lib/libagentx/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.4 2021/01/12 21:35:12 rob Exp $ */ +/* $OpenBSD: main.c,v 1.5 2021/01/13 17:00:20 martijn Exp $ */ /* * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org> @@ -23,19 +23,15 @@ #include <arpa/inet.h> #include <event.h> -#include <poll.h> #include <signal.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> #include "log.h" #include <agentx.h> -#ifndef __OpenBSD__ -#include "openbsd-compat.h" -#endif - #define LINKDOWN 1, 3, 6, 1, 6, 3, 1, 1, 5, 3 #define IFINDEX 1, 3, 6, 1, 2, 1, 2, 2, 1, 1 #define IFADMINSTATUS 1, 3, 6, 1, 2, 1, 2, 2, 1, 7 @@ -77,8 +73,6 @@ void regress_intindexstaticanystring(struct agentx_varbind *); void regress_intindexstaticnewint(struct agentx_varbind *); void regress_intindexstaticnewstring(struct agentx_varbind *); -struct event intev, usr1ev, usr2ev, connev; -char *path = AGENTX_MASTER_PATH; struct agentx *sa; struct agentx_session *sas; struct agentx_context *sac; @@ -130,19 +124,36 @@ struct agentx_object *regressobj_intindexstaticnewstring; struct agentx_object *regressobj_scalarerror; +char *path = AGENTX_MASTER_PATH; +int fd = -1; struct event rev; +struct event intev, usr1ev, usr2ev, connev; int main(int argc, char *argv[]) { struct agentx_index *idx[AGENTX_OID_INDEX_MAX_LEN]; + int ch; + int dflag = 0; log_init(2, 1); - if (argc >= 2) - path = argv[1]; + while ((ch = getopt(argc, argv, "d")) != -1) { + switch (ch) { + case 'd': + dflag = 1; + break; + default: + exit(1); + } + } + + argc -= optind; + argv += optind; + + if (argc >= 1) + path = argv[0]; - event_init(); bzero(&rev, sizeof(rev)); agentx_log_fatal = fatalx; @@ -304,50 +315,41 @@ main(int argc, char *argv[]) 0, 0, regress_scalarerror)) == NULL) fatal("agentx_object"); - struct pollfd pfd[1]; + if (!dflag) { + if (daemon(0, 0) == -1) + fatalx("daemon"); + } - pfd[0].fd = rev.ev_fd; - pfd[0].events = POLLIN; + event_init(); - while (poll(pfd,1,200) > 0) - event_loop(EVLOOP_ONCE); + event_set(&rev, fd, EV_READ|EV_PERSIST, regress_read, NULL); + if (event_add(&rev, NULL) == -1) + fatal("event_add"); - regress_shutdown(); + event_dispatch(); return 0; } void regress_fd(struct agentx *sa2, void *cookie, int close) { - event_del(&rev); - if (!close) - regress_tryconnect(-1, 0, sa2); -} - -void -regress_tryconnect(int fd, short event, void *cookie) -{ - struct agentx *sa2 = cookie; - struct timeval timeout = {3, 0}; + static int init = 0; struct sockaddr_un sun; - sun.sun_family = AF_UNIX; - strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); + /* For ease of cleanup we take the single run approach */ + if (init) + regress_shutdown(); + else { + sun.sun_family = AF_UNIX; + strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1 || - connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) { - log_warn("connect"); - close(fd); - evtimer_set(&connev, regress_tryconnect, sa2); - evtimer_add(&connev, &timeout); - return; + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1 || + connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) { + fatal("connect"); + } + agentx_connect(sa2, fd); + init = 1; } - - event_set(&rev, fd, EV_READ|EV_PERSIST, regress_read, NULL); - event_add(&rev, NULL); - - agentx_connect(sa2, fd); - } void diff --git a/regress/lib/libagentx/walk.err b/regress/lib/libagentx/walk.err new file mode 100644 index 00000000000..935e81714d7 --- /dev/null +++ b/regress/lib/libagentx/walk.err @@ -0,0 +1 @@ +snmp: Can't parse oid openBSD.100.20.1.2.1: Generic error diff --git a/regress/lib/libagentx/walk.out b/regress/lib/libagentx/walk.out new file mode 100644 index 00000000000..d8902f38c2b --- /dev/null +++ b/regress/lib/libagentx/walk.out @@ -0,0 +1,91 @@ +openBSD.100.1.0 = INTEGER: 1 +openBSD.100.2.0 = STRING: scalar-string +openBSD.100.4.0 = OID: openBSD +openBSD.100.5.0 = IpAddress: 127.0.0.1 +openBSD.100.6.0 = Counter32: 1 +openBSD.100.7.0 = Gauge32: 1 +openBSD.100.8.0 = Timeticks: (1) 0:00:00.01 +openBSD.100.9.0 = Opaque: 6382179 +openBSD.100.10.0 = Counter64: 1 +openBSD.100.11.1.1.0 = INTEGER: 0 +openBSD.100.11.1.1.1 = INTEGER: 1 +openBSD.100.11.1.1.2 = INTEGER: 2 +openBSD.100.11.1.1.3 = INTEGER: 3 +openBSD.100.11.1.1.4 = INTEGER: 4 +openBSD.100.11.1.1.5 = INTEGER: 5 +openBSD.100.11.1.1.6 = INTEGER: 6 +openBSD.100.11.1.1.7 = INTEGER: 7 +openBSD.100.11.1.1.8 = INTEGER: 8 +openBSD.100.11.1.1.9 = INTEGER: 9 +openBSD.100.11.1.1.10 = INTEGER: 10 +openBSD.100.11.1.1.11 = INTEGER: 11 +openBSD.100.11.1.1.12 = INTEGER: 12 +openBSD.100.11.1.1.13 = INTEGER: 13 +openBSD.100.11.1.1.14 = INTEGER: 14 +openBSD.100.11.1.1.15 = INTEGER: 15 +openBSD.100.12.1.1.0.0 = INTEGER: 0 +openBSD.100.12.1.1.0.1 = INTEGER: 1 +openBSD.100.12.1.1.1.0 = INTEGER: 2 +openBSD.100.12.1.1.1.1 = INTEGER: 3 +openBSD.100.12.1.1.2.0 = INTEGER: 4 +openBSD.100.12.1.1.2.1 = INTEGER: 5 +openBSD.100.12.1.1.3.0 = INTEGER: 6 +openBSD.100.12.1.1.3.1 = INTEGER: 7 +openBSD.100.12.1.1.4.0 = INTEGER: 8 +openBSD.100.12.1.1.4.1 = INTEGER: 9 +openBSD.100.12.1.1.5.0 = INTEGER: 10 +openBSD.100.12.1.1.5.1 = INTEGER: 11 +openBSD.100.12.1.1.6.0 = INTEGER: 12 +openBSD.100.12.1.1.6.1 = INTEGER: 13 +openBSD.100.12.1.1.7.0 = INTEGER: 14 +openBSD.100.12.1.1.7.1 = INTEGER: 15 +openBSD.100.12.1.1.8.0 = INTEGER: 16 +openBSD.100.12.1.1.8.1 = INTEGER: 17 +openBSD.100.13.1.1.1.97 = STRING: a +openBSD.100.13.1.1.1.98 = STRING: b +openBSD.100.13.1.1.1.99 = STRING: c +openBSD.100.14.1.1.97 = STRING: a +openBSD.100.14.1.1.98 = STRING: b +openBSD.100.14.1.1.99 = STRING: c +openBSD.100.15.1.1.1.97.1.98 = STRING: a - b +openBSD.100.15.1.1.1.97.2.97.97 = STRING: a - aa +openBSD.100.15.1.1.1.97.2.98.98 = STRING: a - bb +openBSD.100.15.1.1.1.98.1.98 = STRING: b - b +openBSD.100.15.1.1.1.98.2.97.97 = STRING: b - aa +openBSD.100.15.1.1.1.98.2.98.98 = STRING: b - bb +openBSD.100.15.1.1.1.99.1.98 = STRING: c - b +openBSD.100.15.1.1.1.99.2.97.97 = STRING: c - aa +openBSD.100.15.1.1.1.99.2.98.98 = STRING: c - bb +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.1 = OID: openBSD.100.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.2 = OID: openBSD.100.2 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.4 = OID: openBSD.100.4 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.5 = OID: openBSD.100.5 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.6 = OID: openBSD.100.6 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.7 = OID: openBSD.100.7 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.8 = OID: openBSD.100.8 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.9 = OID: openBSD.100.9 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.10 = OID: openBSD.100.10 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.11.1.1 = OID: openBSD.100.11.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.12.1.1 = OID: openBSD.100.12.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.13.1.1 = OID: openBSD.100.13.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.14.1.1 = OID: openBSD.100.14.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.15.1.1 = OID: openBSD.100.15.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.16.1.1 = OID: openBSD.100.16.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.17.1.1 = OID: openBSD.100.17.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.18.1.1 = OID: openBSD.100.18.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.18.1.2 = OID: openBSD.100.18.1.2 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.19.1.1 = OID: openBSD.100.19.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.19.1.2 = OID: openBSD.100.19.1.2 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.20.1.1 = OID: openBSD.100.20.1.1 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.20.1.2 = OID: openBSD.100.20.1.2 +openBSD.100.16.1.1.1.3.6.1.4.1.30155.100.4294967295 = OID: openBSD.100.4294967295 +openBSD.100.17.1.1.10.0.0.0 = IpAddress: 10.0.0.0 +openBSD.100.17.1.1.127.0.0.1 = IpAddress: 127.0.0.1 +openBSD.100.17.1.1.172.16.0.0 = IpAddress: 172.16.0.0 +openBSD.100.17.1.1.192.168.0.0 = IpAddress: 192.168.0.0 +openBSD.100.18.1.1.5 = INTEGER: 5 +openBSD.100.18.1.2.5 = STRING: 5 +openBSD.100.19.1.1.1 = INTEGER: 1 +openBSD.100.19.1.2.1 = STRING: 1 +openBSD.100.20.1.1.1 = INTEGER: 1 +openBSD.100.20.1.2.1 = STRING: 1 |