Skip to content
Snippets Groups Projects
Commit 10b038ea authored by Kamil Dudka's avatar Kamil Dudka
Browse files

test-common.sh: common vars and fncs for legacy tests

Closes #132
parent 340bd14e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -3,6 +3,7 @@ EXTRA_DIST = \
compress-error \
mailer \
test \
test-common.sh \
$(top_srcdir)/test/test-config.*.in
 
DISTCLEANFILES = \
Loading
Loading
#!/bin/bash
 
ACL_TESTS=1
SELINUX_TESTS=0
SYSLOG_TESTS=0
M="-m ./mailer"
S="-s state"
RLR="$LOGROTATE $M $S"
. ./test-common.sh
 
# -- ACL - BEGIN --------------------------------
# We test if the ACLs tests should be done or not
ACL_TESTS=1
echo 1 > test.x
setfacl -m u:nobody:rwx test.x 2>/dev/null
if [ $? != 0 ]; then
Loading
Loading
@@ -30,6 +26,7 @@ fi
 
# -- SELINUX - BEGIN --------------------------------
# We test if the ACLs tests should be done or not
SELINUX_TESTS=0
if type "selinuxenabled" >/dev/null 2>&1 && selinuxenabled; then
SELINUX_TESTS=1
else
Loading
Loading
@@ -59,159 +56,6 @@ if [ $SELINUX_TESTS = 1 ]; then
fi
# -- SELINUX - END ----------------------------------
 
# -- SYSLOG - BEGIN
logger syslog_test 2>/dev/null
if [ $? = 0 ]; then
journalctl -n 50 2>/dev/null | grep syslog_test 2>/dev/null >/dev/null
if [ $? = 0 ]; then
SYSLOG_TESTS=1
fi
fi
# -- SYSLOG - END
cleanup() {
rm -f test*.log* anothertest*.log* state test-config. scriptout mail-out compress-args compress-env different*.log*
rm -f $(ls | egrep '^test-config.[0-9]+$')
[ -n "$1" ] && echo "Running test $1"
return 0
}
genconfig() {
input=test-config.$1.in
output=test-config.$1
user=$(id -u -n)
group=$(id -g -n)
sed "s,&DIR&,$PWD,g" < $input | sed "s,&USER&,$user,g" | sed "s,&GROUP&,$group,g" > $output
config_crc=$(md5sum $output)
}
createlog() {
num=$1
file=$2
cl_compressed=$3
case $num in
0)
what=zero
;;
1)
what=first
;;
2)
what=second
;;
3)
what=third
;;
4)
what=fourth
;;
5)
what=fifth
;;
6)
what=sixth
;;
7)
what=seventh
;;
8)
what=eight
;;
9)
what=ninth
;;
*)
exit 1
;;
esac
echo $what > $file
[ -n "$cl_compressed" ] && gzip -9 $file
}
createlogs() {
base=$1
numlogs=$2
cls_compressed=$3
rm -f ${base}*
num=0
while [ $num != $numlogs ]; do
if [ $num = 0 ]; then
createlog 0 $base
else
createlog $num ${base}.$num $cls_compressed
fi
num=`expr $num + 1`
done
}
checkmail() {
(echo -s $PWD/$1 user@myhost.org; echo $2) | diff -u - mail-out
if [ $? != 0 ]; then
exit 5
fi
}
checkoutput() {
while read line; do
set $line
file=$1
co_compressed=$2
if [ "$#" -le 2 ]; then
shift $#
else
shift 2
fi
fileother=`echo $line | awk '{print $1}'`
expected=`echo $line | cut -s -d\ -f3-`
if [ $file != $fileother ]; then
echo "unexpected file $file'" >&2
exit 2
fi
if [ ! -f $file ]; then
echo "file $file does not exist"
fi
if [ -n "$co_compressed" ] && [ "$co_compressed" != 0 ]; then
contents=`gunzip -c $file`
else
contents=`cat $file | tr -d '\000'`
fi
if [ "$contents" != "$expected" ]; then
echo "file $file does not contain expected results (compressed $co_compressed, args $*)" >&2
echo contains: \'$contents\'
echo expected: \'$expected\'
exit 2
fi
echo "$config_crc" | md5sum -c - 2>&1 > /dev/null
if [ $? != 0 ]; then
echo "config file $output has been altered: MD5 sum mismatch"
exit 3
fi
done
}
preptest() {
base=$1
confignum=$2
numlogs=$3
pt_compressed=$4
rm -f $base*
rm -f state
genconfig $confignum
createlogs $base $numlogs $pt_compressed
}
# we don't want any stuff left from previous runs
cleanup 1
 
Loading
Loading
@@ -595,6 +439,14 @@ if [ $? != 0 ]; then
cat compress-env++ exit 3
fi
 
SYSLOG_TESTS=0
logger syslog_test 2>/dev/null
if [ $? = 0 ]; then
journalctl -n 50 2>/dev/null | grep syslog_test 2>/dev/null >/dev/null
if [ $? = 0 ]; then
SYSLOG_TESTS=1
fi
fi
if [ $SYSLOG_TESTS = 1 ]; then
journalctl -n 50 2>/dev/null|grep $PWD/test.log.1 2>/dev/null >/dev/null
if [ $? != 0 ]; then
Loading
Loading
# common variables and functions for legacy tests
RLR="$LOGROTATE -m ./mailer -s state"
cleanup() {
rm -f test*.log* anothertest*.log* state test-config. scriptout mail-out compress-args compress-env different*.log*
rm -f $(ls | egrep '^test-config.[0-9]+$')
[ -n "$1" ] && echo "Running test $1"
return 0
}
genconfig() {
input=test-config.$1.in
output=test-config.$1
user=$(id -u -n)
group=$(id -g -n)
sed "s,&DIR&,$PWD,g" < $input | sed "s,&USER&,$user,g" | sed "s,&GROUP&,$group,g" > $output
config_crc=$(md5sum $output)
}
createlog() {
num=$1
file=$2
cl_compressed=$3
case $num in
0)
what=zero
;;
1)
what=first
;;
2)
what=second
;;
3)
what=third
;;
4)
what=fourth
;;
5)
what=fifth
;;
6)
what=sixth
;;
7)
what=seventh
;;
8)
what=eight
;;
9)
what=ninth
;;
*)
exit 1
;;
esac
echo $what > $file
[ -n "$cl_compressed" ] && gzip -9 $file
}
createlogs() {
base=$1
numlogs=$2
cls_compressed=$3
rm -f ${base}*
num=0
while [ $num != $numlogs ]; do
if [ $num = 0 ]; then
createlog 0 $base
else
createlog $num ${base}.$num $cls_compressed
fi
num=`expr $num + 1`
done
}
checkmail() {
(echo -s $PWD/$1 user@myhost.org; echo $2) | diff -u - mail-out
if [ $? != 0 ]; then
exit 5
fi
}
checkoutput() {
while read line; do
set $line
file=$1
co_compressed=$2
if [ "$#" -le 2 ]; then
shift $#
else
shift 2
fi
fileother=`echo $line | awk '{print $1}'`
expected=`echo $line | cut -s -d\ -f3-`
if [ $file != $fileother ]; then
echo "unexpected file $file'" >&2
exit 2
fi
if [ ! -f $file ]; then
echo "file $file does not exist"
fi
if [ -n "$co_compressed" ] && [ "$co_compressed" != 0 ]; then
contents=`gunzip -c $file`
else
contents=`cat $file | tr -d '\000'`
fi
if [ "$contents" != "$expected" ]; then
echo "file $file does not contain expected results (compressed $co_compressed, args $*)" >&2
echo contains: \'$contents\'
echo expected: \'$expected\'
exit 2
fi
echo "$config_crc" | md5sum -c - 2>&1 > /dev/null
if [ $? != 0 ]; then
echo "config file $output has been altered: MD5 sum mismatch"
exit 3
fi
done
}
preptest() {
base=$1
confignum=$2
numlogs=$3
pt_compressed=$4
rm -f $base*
rm -f state
genconfig $confignum
createlogs $base $numlogs $pt_compressed
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment