blob: 82e945bd4dfd380c697e8588f9f9367cb5a729b5 (
plain)
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
|
# Default DTF library copyied/used both by testsuite and testsuite generator.
# Copyright (C) 2015 Red Hat, Inc.
# Written by Pavel Raiskup.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Methods prefixed by '__dtf_' are internal, for example __dtf_is_testdir.
# Other methods prefixed by 'dtf_' are API. This file must never be used as
# template for 'dg' because it is used both on maintainer machine and on tested
# machine.
: ${SHELL=/bin/sh}
__dtf_is_testdir ()
{
test -d "$1" || return 1
case "$1" in
DTF_OUTPUT|DTF_RESULT|library)
return 1
;;
esac
_d_sub_path=`readlink -f "$1"`
_d_out_path=`readlink -f "$outputdir"`
test "$_d_sub_path" != "$_d_out_path"
}
__dtf_internal_fail ()
{
__dtf_control_msg "internal fail: $*"
__dtf_rc=1
}
__dtf_run_testcase ()
{
resultdir="$outputdir/$testname"
test "$testname" = ROOT && resultdir="$outputdir"
stdout="$resultdir/stdout"
stderr="$resultdir/stderr"
mkdir -p "$resultdir" && cd "$resultdir"
set dummy \
__DTF_TOP_TEST=false \
outputdir="$outputdir" \
"$@"
shift
__save_rc=1
if $__DTF_TOP_TEST; then
eval "$@" 4>&2 3>&1 \
2>> "$stderr" \
1>> "$stdout"
__save_rc=$?
else
for _d_i in stdout stderr
do
_d_fifo=$resultdir/fifo-$_d_i
eval "_d_fifo_$_d_i=\$_d_fifo"
test -e "$_d_fifo" && continue
mkfifo "$_d_fifo" && continue
__dtf_internal_fail "can't create $_d_fifo fifo"
return 1
done
tee -a "$stdout" < "$_d_fifo_stdout" >&1 &
tee -a "$stderr" < "$_d_fifo_stderr" >&2 &
eval "$@" 2> $_d_fifo_stderr >$_d_fifo_stdout
__save_rc=$?
rm "$_d_fifo_stdout" "$_d_fifo_stderr" || {
__dtf_internal_fail "can't remove fifos"
return 1
}
fi
case $__save_rc in
0|77)
return 0
;;
*)
__dtf_rc=1
return 1
;;
esac
}
__dtf_control_msg ()
{
echo >&4 "$*"
}
__dtf_nl_control_msg ()
{
__dtf_control_msg "
** $* **
"
}
__dtf_top_control_msg ()
{
$__DTF_TOP_TEST && return
__dtf_nl_control_msg "$*"
}
__dtf_toplevel_result_msg ()
{
$__DTF_TOP_TEST || return
case $1 in
0)
__dtf_nl_control_msg "Success."
;;
*)
__dtf_nl_control_msg "Fail."
;;
esac
}
|