"Fossies" - the Fresh Open Source Software Archive

Member "logrotate-3.18.1/test/test-common.sh" (16 Apr 2021, 3683 Bytes) of package /linux/privat/logrotate-3.18.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test-common.sh": 3.18.0_vs_3.18.1.

    1 # common variables and functions for legacy tests
    2 LOGROTATE="$(readlink -f $LOGROTATE)"
    3 RLR="$LOGROTATE -v -m ./mailer -s state"
    4 
    5 if du --apparent-size $LOGROTATE > /dev/null 2>&1; then
    6   DU_APPARENT_SIZE='du --apparent-size'
    7 elif du -A $LOGROTATE > /dev/null 2>&1; then
    8   DU_APPARENT_SIZE='du -A'
    9 else
   10   echo "no du option for apparent size found:"
   11   du --apparent-size $LOGROTATE
   12   du -A $LOGROTATE
   13   exit 1
   14 fi
   15 
   16 if command -v md5sum > /dev/null 2>&1; then
   17   MD5SUM=md5sum
   18 elif command -v md5 > /dev/null 2>&1; then
   19   MD5SUM=md5
   20 else
   21   echo "no md5sum/md5 command found"
   22   exit 1
   23 fi
   24 
   25 if stat -c %f $LOGROTATE > /dev/null 2>&1; then
   26   STAT_MODE_FORMAT='stat -c %f'
   27 elif stat -f %Xp $LOGROTATE > /dev/null 2>&1; then
   28   STAT_MODE_FORMAT='stat -f %Xp'
   29 else
   30   echo "no stat format option found:"
   31   stat -c %f $LOGROTATE
   32   stat -f %Xp $LOGROTATE
   33   exit 1
   34 fi
   35 
   36 TESTDIR="$(basename "$0" .sh)"
   37 mkdir -p "$TESTDIR"
   38 cd "$TESTDIR" || exit $?
   39 
   40 TESTNUM="$(printf "%s\n" "$TESTDIR" | sed -e 's/^test-0*//')"
   41 
   42 import() {
   43   [ -e "$1" ] && return
   44   [ -e "../$1" ] || return
   45   ln -s "../$1"
   46 }
   47 
   48 import "compress"
   49 import "compress-error"
   50 import "mailer"
   51 import "test-common-acl.sh"
   52 import "test-common-selinux.sh"
   53 import "test-config.$TESTNUM.in"
   54 
   55 cleanup() {
   56     rm -f test*.log* anothertest*.log* state test-config. scriptout mail-out compress-args compress-env different*.log* test-config.*[0-9]
   57 
   58     [ -n "$1" ] && echo "Running test $1"
   59     return 0
   60 }
   61 
   62 genconfig() {
   63     input=test-config.$1.in
   64     output=test-config.$1
   65     user=$(id -u -n)
   66     group=$(id -g -n)
   67     rootgroup=$(id -g -n root)
   68     sed "s,&DIR&,$PWD,g" < $input | sed "s,&USER&,$user,g" | sed "s,&GROUP&,$group,g" | sed "s,&ROOTGROUP&,$rootgroup,g" > $output
   69     chmod go-w $output
   70     config_crc=$(${MD5SUM} $output)
   71 }
   72 
   73 createlog() {
   74     num=$1
   75     file=$2
   76     cl_compressed=$3
   77 
   78     case $num in
   79     0)
   80         what=zero
   81         ;;
   82     1)
   83         what=first
   84         ;;
   85     2)
   86         what=second
   87         ;;
   88     3)
   89         what=third
   90         ;;
   91     4)
   92         what=fourth
   93         ;;
   94     5)
   95         what=fifth
   96         ;;
   97     6)
   98         what=sixth
   99         ;;
  100     7)
  101         what=seventh
  102         ;;
  103     8)
  104         what=eight
  105         ;;
  106     9)
  107         what=ninth
  108         ;;
  109     *)
  110         exit 1
  111         ;;
  112     esac
  113 
  114     echo $what > $file
  115     [ -n "$cl_compressed" ] && gzip -9 $file
  116 }
  117 
  118 createlogs() {
  119     base=$1
  120     numlogs=$2
  121     cls_compressed=$3
  122 
  123     rm -f ${base}*
  124 
  125     createlog 0 $base
  126     num=1
  127     while [ $num -le $numlogs ]; do
  128     createlog $num ${base}.$num $cls_compressed
  129     num=`expr $num + 1`
  130     done
  131 }
  132 
  133 checkmail() {
  134     (echo -s $PWD/$1 user@invalid.; echo $2) | diff -u - mail-out
  135     if [ $? != 0 ]; then
  136         exit 5
  137     fi
  138 }
  139 
  140 checkoutput() {
  141     while read line; do
  142     set $line
  143     file=$1
  144     co_compressed=$2
  145     if [ "$#" -le 2 ]; then
  146         shift $#
  147     else
  148         shift 2
  149     fi
  150 
  151     fileother=`echo $line | awk '{print $1}'`
  152     expected=`echo $line | cut -s -d\  -f3-`
  153 
  154     if [ $file != $fileother ]; then
  155         echo "unexpected file $file'" >&2
  156         exit 2
  157     fi
  158 
  159     if [ ! -f $file ]; then
  160         echo "file $file does not exist"
  161     fi
  162 
  163     if [ -n "$co_compressed" ] && [ "$co_compressed" != 0 ]; then
  164         contents=`gunzip -c $file`
  165     else
  166         contents=`cat $file | tr -d '\000'`
  167     fi
  168     if [ "$contents" != "$expected" ]; then
  169         echo "file $file does not contain expected results (compressed $co_compressed, args $*)" >&2
  170         echo contains: \'$contents\'
  171         echo expected: \'$expected\'
  172         exit 2
  173     fi
  174     echo "$config_crc" | ${MD5SUM} -c - >/dev/null
  175     if [ $? != 0 ]; then
  176         echo "config file $output has been altered: MD5 sum mismatch"
  177         exit 3
  178     fi
  179     done
  180 }
  181 
  182 preptest() {
  183     base=$1
  184     confignum=$2
  185     numlogs=$3
  186     pt_compressed=$4
  187 
  188     rm -f $base*
  189     rm -f state
  190 
  191     genconfig $confignum
  192     createlogs $base $numlogs $pt_compressed
  193 }