summaryrefslogtreecommitdiffstats
path: root/docs/runtests.sh
blob: a7a7aaaabd2cbf0326aa9f3004715637f64c4210 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/sh
# vim:tw=0:ts=4:sw=4

# this is a test script to run everything through its paces before you do a
# release. The basic idea is:

# 1) make distcheck to ensure that all autoconf stuff is setup properly
# 2) run some basic tests to test different mock options.
# 3) rebuild mock srpm using this version of mock under all distributed configs

# This test will only run on a machine with full access to internet.
# might work with http_proxy= env var, but I havent tested that.
# 
# This test script expects to be run on an x86_64 machine. It will *not* run
# properly on an i386 machine.
#

set -e
set -x

header() {
    set +x
    echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
    echo $1
    echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
    echo ""
    set -x
}

#MOCK_EXTRA_ARGS=--trace

CURDIR=$(pwd)
MOCKSRPM=${CURDIR}/mock-*.src.rpm
DIR=$(cd $(dirname $0); pwd)
TOP_SRCTREE=$DIR/../
cd $TOP_SRCTREE

#
# most tests below will use this mock command line
# 
testConfig=fedora-13-x86_64
uniqueext="$$-$RANDOM"
outdir=${CURDIR}/mock-unit-test
MOCKCMD="sudo ./py/mock.py --resultdir=$outdir --uniqueext=$uniqueext -r $testConfig $MOCK_EXTRA_ARGS"
CHROOT=/var/lib/mock/${testConfig}-$uniqueext/root

trap '$MOCKCMD --clean' INT HUP QUIT EXIT TERM

# clear out root cache so we get at least run without root cache present
#sudo rm -rf /var/lib/mock/cache/${testConfig}/root_cache

#
# pre-populate yum cache for the rest of the commands below
#
header "pre-populating the cache"
time $MOCKCMD --init
time $MOCKCMD --installdeps $MOCKSRPM
if [ ! -e $CHROOT/usr/include/python* ]; then
    echo "installdeps test FAILED. could not find /usr/include/python*"
    exit 1
fi

#
# Test that chroot return code is properly passed up
#
header "testing that chroot return code is passed back correctly"
set +e
time $MOCKCMD --offline --chroot -- bash -c "exit 5"
res=$?
if [ $res -ne 5 ]; then
    echo "'mock --chroot' return code not properly passed back: $res"
    exit 1
fi
set -e

#
# test mock shell (interactive) and return code passing
#
header "testing interactive shell and return code"
set +e
echo exit 5 | time $MOCKCMD --offline --shell
res=$?
if [ $res -ne 5 ]; then
    echo "'mock --chroot' return code not properly passed back: $res"
    exit 1
fi
set -e

#
# Test that chroot with one arg is getting passed though a shell (via os.system())
#
header "testing that args are passed correctly to a shell"
time $MOCKCMD --offline --chroot 'touch /tmp/{foo,bar,baz}'
if [ ! -f $CHROOT/tmp/foo ] || [ ! -f $CHROOT/tmp/bar ] || [ ! -f $CHROOT/tmp/baz ]; then
    echo "'mock --chroot' with one argument is not being passed to os.system()"
    exit 1
fi

#
# Test that chroot with more than one arg is not getting passed through a shell
#
header "Test that chroot with more than one arg is not getting passed through a shell"
time $MOCKCMD --offline --chroot touch '/tmp/{quux,wibble}'
if [ ! -f $CHROOT/tmp/\{quux,wibble\} ] || [ -f $CHROOT/tmp/quux ] || [ -f $CHROOT/tmp/wibble ]; then
    echo "'mock --chroot' with more than one argument is being passed to os.system()"
    exit 1
fi

#
# Test offline build as well as tmpfs
#
header "Test offline build as well as tmpfs"
time $MOCKCMD --offline --enable-plugin=tmpfs --rebuild $MOCKSRPM
if [ ! -e $outdir/mock-*.noarch.rpm ]; then
    echo "rebuild test FAILED. could not find $outdir/mock-*.noarch.rpm"
    exit 1
fi

#
# Test orphanskill feature (std)
#
header "Test orphanskill feature (std)"
if pgrep daemontest; then
    echo "Exiting because there is already a daemontest running."
    exit 1
fi
time $MOCKCMD --offline --init
time $MOCKCMD --offline --copyin docs/daemontest.c /tmp
time $MOCKCMD --offline --chroot -- gcc -Wall -o /tmp/daemontest /tmp/daemontest.c
time $MOCKCMD --offline --chroot -- /tmp/daemontest
if pgrep daemontest; then
    echo "Daemontest FAILED. found a daemontest process running after exit." 
    exit 1
fi

#
# Test orphanskill feature (explicit)
#
header "Test orphanskill feature (explicit)"
time $MOCKCMD --offline --init
time $MOCKCMD --offline --copyin docs/daemontest.c /tmp
time $MOCKCMD --offline --chroot -- gcc -Wall -o /tmp/daemontest /tmp/daemontest.c
echo -e "#!/bin/sh\n/tmp/daemontest\nsleep 60\n" >> $CHROOT/tmp/try
# the following should launch about three processes in the chroot: bash, sleep, daemontest
$MOCKCMD --offline --chroot -- bash /tmp/try &
mockpid=$!
sleep 1
# now we 'prematurely' kill mock. This should leave the three orphans above
sudo kill -9 $mockpid
if ! pgrep daemontest; then
    echo "Daemontest failed. daemontest should be running now but is not."
    exit 1
fi
$MOCKCMD --offline --orphanskill 
if pgrep daemontest; then
    echo "Daemontest FAILED. found a daemontest process running after exit." 
    exit 1
fi


#
# test init/clean
#
header "test init/clean"
time $MOCKCMD --offline --clean
if [ -e $CHROOT ]; then
    echo "clean test FAILED. still found $CHROOT dir."
    exit 1
fi

time $MOCKCMD --offline --init
time $MOCKCMD --offline --install ccache
if [ ! -e $CHROOT/usr/bin/ccache ]; then
    echo "init/clean test FAILED. ccache not found."
    exit 1
fi

#
# test old-style cmdline options
#
header "test old-style cmdline options"
time $MOCKCMD --offline clean
time $MOCKCMD --offline init
time $MOCKCMD --offline install ccache
if [ ! -e $CHROOT/usr/bin/ccache ]; then
    echo "init/clean test FAILED. ccache not found."
    exit 1
fi

#
# clean up from first round of tests
#
header "clean up from first round of tests"
time $MOCKCMD --offline --clean

#
# Test build all configs we ship.
#
for i in $(ls etc/mock | grep .cfg | grep -v default | egrep -v 'ppc|s390|sparc'); do
    MOCKCMD="sudo ./py/mock.py --resultdir=$outdir --uniqueext=$uniqueext -r $(basename $i .cfg) $MOCK_EXTRA_ARGS"
    if [ "${i#epel-4-x86_64.cfg}" != "" ]; then
	header "testing config $(basename $i .cfg)"
	time $MOCKCMD --enable-plugin=tmpfs --rebuild $MOCKSRPM 
    fi
    time $MOCKCMD                       --rebuild $MOCKSRPM 
done