File: test.buffer

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 (107 lines) | stat: -rwxr-xr-x 3,073 bytes parent folder | download | duplicates (4)
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
# vim: set filetype=sh :
#        file: test.buffer
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2020)
#     license: GNU General Public License, version 3
# description: Test if we get unbuffered stdout, stderr, and logfile output.
#              This is important, to see output during a long running step and
#              not only at the end.
#    see also: example.buffer

# The following tests are included:
# (1) check ia_out
# (2) check ia_logout
# (3) check ia_logerr
# (4) check exit,ia_out
# (5) check exit,ia_logout
# (6) check exit,ia_logerr

. ./tstlib

sleep=0.2
shell=""
run_get_buffer=""
while [ $# -ne 0 ]; do
  if [ "$1" = "-s" ]; then
    shell="$2"
    shift 2
  elif [ "$1" = "--sleep" ]; then
    sleep="$2"
    shift 2
  elif [ "$1" = "--get_buffer" ]; then
    run_get_buffer="$1"
    out="$2"
    err="$3"
    log="$4"
    shift 4
  else
    echo "ERROR $0: unknown option <$1>" >&2
    exit 1
  fi
done


# get_buffer
get_buffer()
{
  for j in out err log; do
    eval "${j}_all=0"
    eval "${j}_once=0"
  done

  for i in $(seq 6); do
    sleep $sleep
    for j in out err log; do
      eval "${j}_lines=\"\$(grep -e \"^\(|\|\)[0-9]\" \$${j} 2>/dev/null | tail -n +\$((${j}_all + 1)))\""
      eval "[ \"\$${j}_lines\" ] && ${j}_new=\$(echo \"\$${j}_lines\" | wc -l) || ${j}_new=0"
      eval "[ \$${j}_once -gt \$${j}_new ] || ${j}_once=\$${j}_new"
      eval "${j}_all=\$(( ${j}_all + ${j}_new ))"
    done

    #echo "$i: $out_new $err_new $log_new"
  done
  #echo "out_once out_all err_once err_all log_once log_all:"
  #echo "$out_once $out_all $err_once $err_all $log_once $log_all"

  echo "$out_once $out_all $err_once $err_all $log_once $log_all" | sed -e "s/[123]/1-3/g"
}

if [ "$run_get_buffer" ]; then
  get_buffer
  exit $?
fi

ia_logfile="$(mktemp)"
file_out="$(mktemp)"
file_err="$(mktemp)"

cmd=$(dirname $0)/example.buffer
bug913718_cmd
cmd1="ia_logfile=$ia_logfile $shell $cmd --sleep $sleep"
cmd2=">$file_out 2>$file_err & $0 --sleep $sleep --get_buffer $file_out $file_err $ia_logfile"

# Meaning of the check result strings:
#  5   We expect to see all 5 lines
#  4   We expect to see all 4 lines that are printetd before exit
#  1-3 It is ok to get max 1-3 lines of data at once, but not more, to be sure
#      not all data is sent at once.
#  0   We do not expect any data

rm -f $ia_logfile $file_out $file_err
check "(1) check ia_out" "$@" "$cmd1 ia_out $cmd2" "1-3 5 0 0 0 0"

rm $ia_logfile $file_out $file_err
check "(2) check ia_logout" "$@" "$cmd1 ia_logout $cmd2" "1-3 5 0 0 1-3 5"

rm $ia_logfile $file_out $file_err
check "(3) check ia_logerr" "$@" "$cmd1 ia_logerr $cmd2" "0 0 1-3 5 1-3 5"

rm $ia_logfile $file_out $file_err
check "(4) check exit,ia_out" "$@" "$cmd1 --exit ia_out $cmd2" "1-3 4 0 0 0 0"

rm $ia_logfile $file_out $file_err
check "(5) check exit,ia_logout" "$@" "$cmd1 --exit ia_logout $cmd2" "1-3 4 0 0 1-3 4"

rm $ia_logfile $file_out $file_err
check "(6) check exit,ia_logerr" "$@" "$cmd1 --exit ia_logerr $cmd2" "0 0 1-3 4 1-3 4"

rm $ia_logfile $file_out $file_err