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:
parent
f07d00f910
commit
dca48d8b7d
11
TODO.org
11
TODO.org
@ -7,14 +7,13 @@
|
||||
** DONE Add syslogp() and vsyslogp() to libsyslog
|
||||
** DONE Add support for =/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 Fix option parsing in syslog.conf, e.g. ;RFC5424 and log rotation
|
||||
** Test with/without openlog()
|
||||
** Test custom facilities
|
||||
** Test setlogmask()
|
||||
** Test levels?
|
||||
** Test v1 API, syslogp()
|
||||
** DONE Test with/without openlog()
|
||||
** DONE Test custom facilities
|
||||
** DONE Test setlogmask()
|
||||
** DONE Test v1 API, syslogp()
|
||||
** DONE Add RFC5424 parsing of incoming msgs to syslogd
|
||||
** DONE Local `stdout | stdin` unit testing
|
||||
** DONE Rewrite man pages do mandoc format
|
||||
|
38
test/api.c
38
test/api.c
@ -1,14 +1,48 @@
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "syslog.h"
|
||||
|
||||
int main(void)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *ident = NULL;
|
||||
char *msg = getenv("MSG");
|
||||
char c;
|
||||
int severity = LOG_NOTICE;
|
||||
int facility = LOG_CONSOLE;
|
||||
int v1 = 0;
|
||||
|
||||
if (!msg)
|
||||
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;
|
||||
}
|
||||
|
27
test/api.sh
27
test/api.sh
@ -3,5 +3,32 @@ set -e
|
||||
. ./test.rc
|
||||
|
||||
export MSG="no-openlog-apitest"
|
||||
|
||||
echo "= Phase 1 - simple syslog(), no openlog() ==============="
|
||||
./api
|
||||
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}
|
||||
|
||||
|
@ -7,7 +7,10 @@ if [ -e ${PID} ]; then
|
||||
fi
|
||||
|
||||
rm -f ${LOG}
|
||||
rm -f ${LOGV1}
|
||||
rm -f ${LOGCONS}
|
||||
rm -f ${PID}
|
||||
rm -f ${CAP}
|
||||
rm -f ${SOCK}
|
||||
rm -f ${CONF}
|
||||
rm -rf ${CONFD}
|
||||
|
@ -1,5 +1,7 @@
|
||||
NM=syslog-test
|
||||
LOG=/tmp/${NM}.log
|
||||
LOGV1=/tmp/${NM}-v1.log
|
||||
LOGCONS=/tmp/${NM}-cons.log
|
||||
PID=/tmp/${NM}.pid
|
||||
CAP=/tmp/${NM}.pcapng
|
||||
CONF=/tmp/${NM}.conf
|
||||
|
Loading…
Reference in New Issue
Block a user