test: Extend API test with three more phases

- with/without openlog()
- setlogmask()
- syslogp() API

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-03 19:51:39 +01:00
parent f07d00f910
commit dca48d8b7d
5 changed files with 73 additions and 8 deletions

View File

@ -7,14 +7,13 @@
** DONE Add syslogp() and vsyslogp() to libsyslog ** DONE Add syslogp() and vsyslogp() to libsyslog
** DONE Add support for =/etc/syslog.d/*.conf= to syslogd ** DONE Add support for =/etc/syslog.d/*.conf= to syslogd
** DONE Test support of =/etc/syslog.d/*.conf= to syslogd ** DONE Test support of =/etc/syslog.d/*.conf= to syslogd
** Test SIGHUP of syslogd ** DONE Test SIGHUP of syslogd
** DONE Custom facilities! ** DONE Custom facilities!
** DONE Fix option parsing in syslog.conf, e.g. ;RFC5424 and log rotation ** DONE Fix option parsing in syslog.conf, e.g. ;RFC5424 and log rotation
** Test with/without openlog() ** DONE Test with/without openlog()
** Test custom facilities ** DONE Test custom facilities
** Test setlogmask() ** DONE Test setlogmask()
** Test levels? ** DONE Test v1 API, syslogp()
** Test v1 API, syslogp()
** DONE Add RFC5424 parsing of incoming msgs to syslogd ** DONE Add RFC5424 parsing of incoming msgs to syslogd
** DONE Local `stdout | stdin` unit testing ** DONE Local `stdout | stdin` unit testing
** DONE Rewrite man pages do mandoc format ** DONE Rewrite man pages do mandoc format

View File

@ -1,14 +1,48 @@
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "syslog.h" #include "syslog.h"
int main(void) int main(int argc, char *argv[])
{ {
char *ident = NULL;
char *msg = getenv("MSG"); char *msg = getenv("MSG");
char c;
int severity = LOG_NOTICE;
int facility = LOG_CONSOLE;
int v1 = 0;
if (!msg) if (!msg)
return 1; return 1;
syslog(LOG_ERR, msg); while ((c = getopt(argc, argv, "i:lp")) != EOF) {
switch (c) {
case 'i':
ident = optarg;
break;
case 'l':
setlogmask(LOG_UPTO(severity));
severity = LOG_INFO;
break;
case 'p':
v1 = 1;
facility = LOG_FTP;
break;
}
}
if (ident)
openlog(ident, LOG_NOWAIT, facility);
if (v1)
syslogp(severity, "MSGID", NULL, msg);
else
syslog(severity, msg);
if (ident)
closelog();
return 0; return 0;
} }

View File

@ -3,5 +3,32 @@ set -e
. ./test.rc . ./test.rc
export MSG="no-openlog-apitest" export MSG="no-openlog-apitest"
echo "= Phase 1 - simple syslog(), no openlog() ==============="
./api ./api
grep "api ${MSG}" ${LOG} grep "api ${MSG}" ${LOG}
echo "= Phase 2 - syslog() with openlog() & custom facility ==="
cat <<EOF >${CONFD}/bar.conf
console.* -${LOGCONS}
EOF
kill -HUP `cat ${PID}`
sleep 2
./api -i foo
grep "foo ${MSG}" ${LOGCONS}
echo "= Phase 3 - Verify setlogmask() filters out LOG_INFO ===="
./api -i xyzzy -l
grep "xyzzy ${MSG}" ${LOGCONS} || true
echo "= Phase 4 - Verify RFC5424 API with syslogp() ==========="
cat <<EOF >${CONFD}/v1.conf
ftp.* -${LOGV1} ;RFC5424
EOF
kill -HUP `cat ${PID}`
sleep 2
./api -i troglobit -p
grep "troglobit - MSGID - ${MSG}" ${LOGV1}

View File

@ -7,7 +7,10 @@ if [ -e ${PID} ]; then
fi fi
rm -f ${LOG} rm -f ${LOG}
rm -f ${LOGV1}
rm -f ${LOGCONS}
rm -f ${PID} rm -f ${PID}
rm -f ${CAP} rm -f ${CAP}
rm -f ${SOCK} rm -f ${SOCK}
rm -f ${CONF} rm -f ${CONF}
rm -rf ${CONFD}

View File

@ -1,5 +1,7 @@
NM=syslog-test NM=syslog-test
LOG=/tmp/${NM}.log LOG=/tmp/${NM}.log
LOGV1=/tmp/${NM}-v1.log
LOGCONS=/tmp/${NM}-cons.log
PID=/tmp/${NM}.pid PID=/tmp/${NM}.pid
CAP=/tmp/${NM}.pcapng CAP=/tmp/${NM}.pcapng
CONF=/tmp/${NM}.conf CONF=/tmp/${NM}.conf