1#!/bin/bash
2
3#
4# Copyright (C) 2015 Sami Kerola <kerolasa@iki.fi>
5#
6# This file is part of util-linux.
7#
8# This file is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This file is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18
19TS_TOPDIR="${0%/*}/../.."
20TS_DESC="options"
21
22. $TS_TOPDIR/functions.sh
23
24ts_init "$*"
25
26ts_check_test_command "$TS_HELPER_LOGGER"
27
28# Create --file option input files.
29echo {a..c}{1..5}	 > $TS_OUTDIR/input_simple
30echo {a..c}{1..5}	 > $TS_OUTDIR/input_empty_line
31echo ""			>> $TS_OUTDIR/input_empty_line
32echo {5..1}{c..1}	>> $TS_OUTDIR/input_empty_line
33echo "<66>" prio_prefix	 > $TS_OUTDIR/input_prio_prefix
34
35# bash 4 might not be available, use go-around hash
36tests_array=(
37	"simple:test"
38	"log_pid:-i test"
39	"log_pid_long:--id test"
40	"log_pid_define:--id=12345 test"
41	"log_pid_no_arg:-is test"
42	"input_file_simple:-f $TS_OUTDIR/input_simple"
43	"input_file_empty_line:-f $TS_OUTDIR/input_empty_line"
44	"input_file_skip_empty:--file $TS_OUTDIR/input_empty_line -e"
45	"input_file_prio_prefix:--file $TS_OUTDIR/input_prio_prefix --skip-empty --prio-prefix"
46)
47
48export TZ="GMT"
49export LOGGER_TEST_TIMEOFDAY="1234567890.123456"
50export LOGGER_TEST_HOSTNAME="test-hostname"
51export LOGGER_TEST_GETPID="98765"
52
53DEVLOG="$(mktemp "/tmp/ultest-$TS_COMPONENT-$TS_TESTNAME-XXXXXX")" \
54	|| ts_die "mktemp failed"
55SOCKIN="${TS_OUTDIR}/${TS_TESTNAME}_socketin"
56ts_init_socket_to_file $DEVLOG $SOCKIN
57SOCAT_PID="$!"
58
59function logger_fun {
60	$TS_HELPER_LOGGER -u $DEVLOG --stderr --no-act "$@" >> $TS_OUTPUT 2>> $TS_ERRLOG
61	echo "ret: $?" >> "$TS_ERRLOG"  # keep all on stderr
62}
63
64for i in "${tests_array[@]}"; do
65	name="${i%%:*}"
66	options="${i##*:}"
67
68	ts_init_subtest "$name"
69	logger_fun -t "test_tag" $options
70	ts_finalize_subtest
71done
72
73ts_init_subtest "check_socket"
74# Check written socket data of all subtests
75sleep 1
76kill $SOCAT_PID
77wait $SOCAT_PID &>/dev/null
78cat "$SOCKIN" >> $TS_OUTPUT 2>> $TS_ERRLOG
79rm -f "$DEVLOG" "$SOCKIN"
80ts_finalize_subtest
81
82ts_finalize
83