File: run_tests

package info (click to toggle)
shellia 5.10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792 kB
  • sloc: sh: 7,840; makefile: 34
file content (156 lines) | stat: -rwxr-xr-x 3,830 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
# vim: set filetype=sh :
#        file: run_tests
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2020)
#     license: GNU General Public License, version 3
# description: run shellia internal tests

usage()
{
  cat <<END >&2
Usage: run_tests [-v] [-t <testfile>]
  -v        be verbose
  -t <file> Instead of using all testfiles use only <file>
            Example:
            ./run_tests -t tests/test.hello_world -t tests/test.sshfd
END
  exit 1
}

TESTFILES=""
VERBOSE=""
while [ $# -gt 0 ]; do
  if [ "$1" = "-v" ]; then
    VERBOSE="$1"
    shift
  elif [ "$1" = "-t" ]; then
    TESTFILES="$TESTFILES $2"
    shift 2
  else
    echo "ERROR run_tests: unknown option <$1>" >&2
    usage
  fi
done

# show_indented_short_error
short_err()
{
  echo "/ shortened difference between expectation and result:"
  diff exp res | head -10 | sed "s/^/   /"

  # rotate old dbgerr files
  for n in $(seq 9 -1 1); do
    [ -f dbgerr/$i ] && mv dbgerr/$i dbgerr/$((n+1))
  done
  # save current dbgerr files
  for i in res exp r4s res.cmd res.org; do
    mkdir -p dbgerr/1
    cp $i dbgerr/1
  done
}

check_shellia_tmpfiles()
{
  local tmpn

  if [ "$1" = "--rm" ]; then
    rm -f timelist /tmp/shellia.??????????
  fi

  tmpn="$(ls /tmp/shellia.?????????? 2>/dev/null | wc -l)"
  if [ $tmpn -ne 0 ]; then
    echo "ERROR found $tmpn /tmp/shellia.* files" >&2
    exit 1
  fi
}

# test_with_sh <testfile> <sh>
test_with_sh()
{
  local out errmsg
  out="$("./$1" -s "$2" 2>&1)"
  if [ "$(echo "$out" | grep -e "^ERROR" | grep -v -e "^ERROR: ia premature exit")" ]; then
    errmsg="ERROR$(echo "$out"| sed -E -n -e "s/^ERROR\s+(\([0-9]+\)).*/ \1/p")"
    [ "$VERBOSE" ] && echo "$out" || echo "$errmsg \"./$1\" -s \"$2\" $(short_err)"
    err=$((err +1))
  elif [ "$(echo "$out" | grep -e "^WARN")" ]; then
    [ "$VERBOSE" ] && echo "$out" || echo "WARN \"./$1\" -s \"$2\" $(echo "$out" | sed -n "s/^WARN .* => /=> /p" | sort -u)"
  else
    [ "$VERBOSE" ] && echo "$out" || echo "OK \"./$1\" -s \"$2\""
  fi
}

if ./sshd2222 should-work; then
  ./sshd2222 start || exit $?
fi

rm -f timelist

[ "$TESTFILES" ] || TESTFILES="$(/bin/ls tests/test.*)"

err=0
check_shellia_tmpfiles --rm
for testfile in $TESTFILES; do
  testdir="$(dirname $testfile)"
  testfile="$(basename $testfile)"
  if [ "$testfile" = "test.prefix" ]; then
    # dash can not list functions, but bash can
    for sh in bash; do
      test_with_sh "$testdir/$testfile" "$sh"
      check_shellia_tmpfiles
    done
  elif [ "$testfile" = "test.ia_mktemp" -o "$testfile" = "test.ia_mktemp2" ]; then
    # posh Bug#910275
    for sh in mksh bash dash "busybox sh"; do
      test_with_sh "$testdir/$testfile" "$sh"
      check_shellia_tmpfiles
    done
  elif [ "$testfile" = "test.multiply" ]; then
    for sh in bash dash "busybox sh" mksh; do
      test_with_sh "$testdir/$testfile" "$sh"
      check_shellia_tmpfiles
    done
    # posh Bug#910275
    for sh in posh; do
      test_with_sh "$testdir/$testfile" "$sh"
      check_shellia_tmpfiles --rm
    done
  else
    #for sh in bash dash "busybox sh" mksh posh yash zsh sash; do
    for sh in bash dash "busybox sh" mksh posh; do
      test_with_sh "$testdir/$testfile" "$sh"
      check_shellia_tmpfiles
    done
  fi
done
check_shellia_tmpfiles

s="$(
( echo "( "
  cat timelist | sed "s/^real=\([0-9]\+\):.*/\1+/"
  echo "0 ) * 3600"

  echo "+"

  echo "( "
  cat timelist | sed "s/^real=[0-9]\+:\([0-9]\+\)\..*/\1+/"
  echo "0 ) * 60"

  echo "+"

  cat timelist | sed "s/^real=[0-9]\+:[0-9]\+\.\([0-9]\+\).*/\1+/"
  echo 0
) | xargs | bc)"
#echo "s=$s"
h=$((s/3600))
s=$((s-h*3600))
m=$((s/60))
s=$((s-m*60))
date "+%Y/%m/%d-%H:%M $h:$m.$s err=$err times=$(cat timelist | wc -l)" >> timelist.all

if ./sshd2222 should-work; then
  ./sshd2222 stop
fi

echo "$err Errors"
exit $err