head     1.1;
branch   1.1.1;
access   ;
symbols  LTP_20031204:1.1.1.1 LINUX_TEST_PROJECT:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2003.12.31.09.00.06;  author mtm;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2003.12.31.09.00.06;  author mtm;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@#! /bin/sh

#  Copyright (c) International Business Machines  Corp., 2002
#
#  This program is free software;  you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#  the GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program;  if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# 12/05/02  Port to bash -Robbie Williamson <robbiew@@us.ibm.com>
# 02/05/03  Modified - Manoj Iyer <manjo@@mail.utexas.edu> use USCTEST macros
#           fixed bugs.

##################################################################
# case 8: Test all the facilities at a particular level.         #
#                                                                #
#         Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL #
#         LOG_DAEMON, LOG_AUTH, LOG_LPR.                         #
#         Don't know how to send kernel messages from syslog()   #
#                                                                #
#         o Create seperate entries in config file for each      #
#            facility.                                           #
#         o Send the message and grep for the entry in log file. #
##################################################################
DEBIAN=0
#number of seconds to wait for another syslog test to complete
wait_count=60

cleanup()
{
if [ $status_flag -eq 0 ]
then
	tst_resm TPASS "all facilities work"
else
	tst_resm TPASS "some facilities failed to work"
fi

#Restore syslog.conf
mv /etc/syslog.conf.ltpbak /etc/syslog.conf


#Restart syslog
tst_resm TINFO "Restart syslog"
/etc/init.d/syslog restart 2>&1 1>/dev/null 
sleep 2
if [ $DEBIAN -eq 1 ];then
 rm -f /etc/init.d/syslog
fi

exit $status_flag
}

syslog_case8()
{
	#set the trap to handle signals.
	trap '
		tst_resm TBROK "Testing is terminating due to a signal"
		status_flag=1
		cleanup
	' 1 2 3 6 11 15

	echo
	tst_resm  TINFO "syslog: Testing all the facilities"

	# check if syslogd command exits.
	if [ -z $(which syslogd) ]
	then
		tst_resm TBROK "syslogd no such command"
		status_flag=1
		cleanup
	fi

	#Create symlink to /etc/init.d/sysklogd for Debian
        find /etc/init.d/ |grep sysklogd 2>&1 1>/dev/null 
	RC=$?
        if [ $RC -eq 0 ]
        then
                ln -s /etc/init.d/sysklogd /etc/init.d/syslog
                DEBIAN=1
        fi

	# check if /etc/init/syslog script exists
	find /etc/init.d/ |grep syslog 2>&1 1>/dev/null 
	RC=$?
	if [ $RC -ne 0 ]
	then
		tst_resm TBROK "/etc/init.d/syslog no such script"
		status_flag=1
		cleanup
	fi

	facility_no=1
	facility="user mail daemon auth lpr"
	for current in $facility
	do
		tst_resm TINFO "Doing facility: $current..."

		# Create the configuration file specific to this facility
		# Level is fixed at info.
		echo "$current.info    /var/log/messages" > /etc/syslog.conf
		echo "$current.info    /var/log/maillog" >> /etc/syslog.conf

		#Restart syslog
		tst_resm TINFO "Restart syslog"

		/etc/init.d/syslog restart 2>&1 1>/dev/null 
		sleep 2

		# Grepping pattern is as follows:
		# syslogtst: $current info test.
		# check if /var/log/maillog script exists
		for logf in messages maillog
		do
			find /var/log/ |grep $logf 2>&1 1>/dev/null 
			RC=$?
			if [ $RC -ne 0 ]
			then
				tst_resm TBROK "/var/log/$logf no such log file"
				status_flag=1
				cleanup
			fi
		done
		oldvalue=`grep -c "syslogtst: $current info test." /var/log/messages`
		old_mail_check=`grep -c "syslogtst: $current info test." /var/log/maillog`

		# syslogtst has to be called with one more additional facility argument(1-6)
		syslogtst 8 $facility_no 2>/dev/null
		if [ $? -ne 0 ]; then
				status_flag=1
				return
		fi
		sleep 2
		# check if /var/log/maillog script exists
		for logf in messages maillog
		do
			find /var/log/ |grep $logf 2>&1 1>/dev/null 
			RC=$?
			if [ $RC -ne 0 ]
			then
				tst_resm TBROK "/var/log/$logf no such log file"
				status_flag=1
				cleanup
			fi
		done
		new_mail_check=`grep -c "syslogtst: $current info test." /var/log/maillog`
		newvalue=`grep -c "syslogtst: $current info test." /var/log/messages`

		diff=$(( $newvalue - $oldvalue ))
		mail_check=$(( $new_mail_check - $old_mail_check ))
		if [ $current = "mail" ]; then
				if [ $mail_check -ne 1 ]; then
						status_flag=1
						tst_resm TINFO  " Facility $current failed"
				elif [ $mail_check -eq 1 ]; then
						tst_resm TINFO  " Facility $current passed"
				fi
		elif [ $diff -ne 1 ]; then
						status_flag=1
						tst_resm TINFO  " Facility $current failed"
				else
						tst_resm TINFO  " Facility $current passed"
		fi
		# Increment the facility_no for next...
		facility_no=$(($facility_no+1))
	done
}

export TST_TOTAL=1
export TST_COUNT=1
export TCID=$(basename $0)

RC=0
status_flag=0

tst_resm TINFO " Test all the facilities at a particular level."
tst_resm TINFO " Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL"
tst_resm TINFO " LOG_DAEMON, LOG_AUTH, LOG_LPR."
tst_resm TINFO " Don't know how to send kernel messages from syslog()"
tst_resm TINFO " o Create seperate entries in config file for each facility."
tst_resm TINFO " o Send the message and grep for the entry in log file."

#Back up /etc/syslog.conf
if ! [ -a /etc/syslog.conf ]
then
        tst_resm TBROK "/etc/syslog.conf not found!"
else
    while [ -a /etc/syslog.conf.ltpbak ]  #Pause if another LTP syslog test is running
    do
        if [ $(( wait_count-- )) -gt 0 ]
        then
          sleep 1
        else
          tst_resm TBROK "Another syslog test appears to be stuck, could not run"
          status_flag=1
          exit $status_flag
        fi

    done
    cp /etc/syslog.conf /etc/syslog.conf.ltpbak
fi

syslog_case8
cleanup
@


1.1.1.1
log
@Initial import of the Linux Test Project (http://ltp.sourceforge.net).

This import is minus the Posix test suite, which will be imported separately,
and the HPI suite, which doesn't concern us.
@
text
@@
