summaryrefslogtreecommitdiffstats
path: root/fuel/include/build.sh.debug
blob: b6594cb16bedb155c6e8d0b31240229f2150e2a4 (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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# stefan.k.berg@ericsson.com
# jonas.bjurel@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

############################################################################
# BEGIN of build script integration test
#
integration-test () {

test_clean () {
    make -C ${BUILD_BASE} clean
    test_cache_clean
    test_output_clean
}

test_cache_clean () {
    rm -rf ${TEST_BUILD_CACHE_URI_DIR}
}

test_output_clean () {
    rm -rf ${TEST_BUILD_RESULT_DIR}
}

test_prepare () {
    test_clean
    test_cache_clean
    test_output_clean
    mkdir -p ${TEST_BUILD_CACHE_URI_DIR}
}

test_cache_check () {
    if [ ! -f ${BUILD_BASE}/fuel-6.0.1.iso ] || \
       [ ! -f ${BUILD_BASE}/.versions ] || \
       [ ! -f ${BUILD_BASE}/opendaylight/.odl-build-history ]; \
       [ ! -f ${BUILD_BASE}/opendaylight/.odl-build.log ]; then
	echo "Cache not present in the build system"
	echo "TEST FAILED"
	exit $rc
    fi

    if [ ! -f ${TEST_BUILD_CACHE_URI_DIR}/${REMOTE_CACHE_ARCH_NAME}.tgz ]; then
	echo "Cache archive not present"
	echo "TEST FAILED"
	exit $rc
    fi

    if tar -tf ${TEST_BUILD_CACHE_URI_DIR}/${REMOTE_CACHE_ARCH_NAME}.tgz ${CACHE_DIR}/.mark > /dev/null 2>&1; then
	echo "Cache archive is invalidated"
	echo "TEST FAILED"
	exit $rc
    fi
}

test_output_check () {
    if [ ! -f  ${TEST_BUILD_RESULT_DIR}/*.iso ] || \
       [ ! -f  ${TEST_BUILD_RESULT_DIR}/*.txt ] || \
       [ ! -f  ${TEST_BUILD_RESULT_DIR}/.versions ]; then
	echo "Build output not produced by the build system"
	echo "TEST FAILED"
	exit $rc
    fi
}

test_invalidate_cache () {
    tar -C ${TEST_BUILD_CACHE_URI_DIR} -xf ${TEST_BUILD_CACHE_URI_DIR}/${REMOTE_CACHE_ARCH_NAME}.tgz
    echo "cache.mk 123" > ${TEST_BUILD_CACHE_URI_DIR}/cache/.versions
    echo "config.mk 123" >> ${TEST_BUILD_CACHE_URI_DIR}/cache/.versions
    echo "fuel 123" >> ${TEST_BUILD_CACHE_URI_DIR}/cache/.versions
    echo "odl 123" >> ${TEST_BUILD_CACHE_URI_DIR}/cache/.versions

    echo "This file marks the invalid cache" > ${TEST_BUILD_CACHE_URI_DIR}/cache/.mark
    rm -f ${TEST_BUILD_CACHE_URI_DIR}/${REMOTE_CACHE_ARCH_NAME}.tgz
    tar --dereference -C ${TEST_BUILD_CACHE_URI_DIR} -caf ${TEST_BUILD_CACHE_URI_DIR}/${REMOTE_CACHE_ARCH_NAME}.tgz ${CACHE_DIR}
}

##### Always succeed integration test ####
build_tc1 () {
    echo "TEST - $0 - ALWAYS SUCCEED"
    set +e
    $0 -f s tmp/output
    rc=$?
    set -e
    if [ $rc -ne 0 ]; then
	echo "TEST FAILED"
	rc=151
	exit $rc
    fi
}

##### Always fail integration test (TC2) ####
build_tc2 () {
    echo "TEST - $0 - ALWAYS FAIL"
    set +e
    $0 -f f tmp/output
    rc=$?
    set -e
    if [ $rc -eq 0 ]; then
	echo "TEST FAILED"
	rc=152
	exit $rc
    fi
}

##### Fake build and populate dummy cache - integration test (TC3) ####
build_tc3 () {
    echo "TEST - $0 - FAKE BUILD AND POPULATE DUMMY CACHE"
    rm -rf tmp
    mkdir -p ${TEST_BUILD_CACHE_URI_DIR}
    set +e
    $0 -c ${TEST_BUILD_CACHE_URI} -f PD ${TEST_BUILD_RESULT_DIR}
    rc=$?
    set -e
    if [ $rc -ne 0 ]; then
	echo "Build failed"
	echo "TEST FAILED"
	rc=152
	exit $rc
    fi

    rc=153
    test_output_check

    rc=154
    test_cache_check
}

##### Fake build usng dummy cache integration test (TC4) ####
build_tc4 () {
    echo "TEST - $0 - FAKE BUILD USING DUMMY CACHE"
    set +e
    $0 -c ${TEST_BUILD_CACHE_URI} -f D ${TEST_BUILD_RESULT_DIR}
    rc=$?
    set -e
    if [ $rc -ne 0 ]; then
	echo "Build failed"
	echo "TEST FAILED"
	rc=155
	exit $rc
    fi

    rc=156
    test_output_check

    rc=157
    test_cache_check
}

#### Fake build and repopulate cache because cache non existant (TC5) ####
build_tc5 () {
    echo "TEST - $0 - FAKE BUILD AND REPOPULATE CACHE BECAUSE NON EXISTANT"
    rm -rf ${TEST_BUILD_CACHE_URI_DIR}/*
    set +e
    $0 -c ${TEST_BUILD_CACHE_URI} -f D ${TEST_BUILD_RESULT_DIR}
    rc=$?
    set -e
    if [ $rc -ne 0 ]; then
	echo "Build failed"
	echo "TEST FAILED"
	rc=158
	exit $rc
    fi

    rc=159
    test_output_check

    rc=160
    test_cache_check
}

#### Fake build and repopulate cache because cache is ivalidated (TC6) ####
build_tc6 () {
    echo "TEST - $0 - FAKE BUILD AND REPOPULATE DUE TO CACHE INVALIDATION"
    test_invalidate_cache
    set +e
    $0 -c ${TEST_BUILD_CACHE_URI} -f D ${TEST_BUILD_RESULT_DIR}
    rc=$?
    set -e
    if [ $rc -ne 0 ]; then
	echo "Build failed"
	echo "TEST FAILED"
	rc=161
	exit $rc
    fi

    rc=162
    test_output_check

    rc=163
    test_cache_check
}

#### Real build and populate cache (TC7) ####
build_tc7 () {
    echo "TEST - $0 - FULL BUILD AND POPULATE CACHE"
    test_prepare
    BUILD_START=$(date +%s)
    set +e
    $0 -c ${TEST_BUILD_CACHE_URI} -f Pi ${TEST_BUILD_RESULT_DIR}
    rc=$?
    set -e
    if [ $rc -ne 0 ]; then
	echo "Build failed"
	echo "TEST FAILED"
	rc=164
	exit $rc
    fi

    BUILD_TIME=$(($(date +%s)-${BUILD_START}))
    rc=165
    test_output_check
    rc=166
    test_cache_check
}

#### Real build using cache from TC7 (TC8) ####
build_tc8 () {
    echo "TEST - $0 - INCREMENTAL BUILD AND USING CACHE"
    BUILD_START=$(date +%s)
    set +e
    $0 -c ${TEST_BUILD_CACHE_URI} -f i ${TEST_BUILD_RESULT_DIR}
    rc=$?
    set -e
    if [ $rc -ne 0 ]; then
	echo "Build failed"
	echo "TEST FAILED"
	rc=167
	exit $rc
    fi
    BUILD_TIME=$(($(date +%s)-${BUILD_START}))
    test_output_check
    rc=168
    test_cache_check
    rc=169
}

TEST_BUILD_ARTIFACT_DIR=${BUILD_BASE}/test
TEST_BUILD_CACHE_URI_DIR=${TEST_BUILD_ARTIFACT_DIR}
TEST_BUILD_CACHE_URI=file://${TEST_BUILD_CACHE_URI_DIR}
TEST_BUILD_RESULT_DIR=${BUILD_BASE}/tmp/output

TEST_START=$(date +%s)
# Run test case 1: Always succeed integration test
echo ==========================================================================
echo ========================= RUNNING TEST CASE 1 ============================
echo ==========================================================================
test_prepare
build_tc1

# Run test case 2: Always fail integration test
echo ==========================================================================
echo ========================= RUNNING TEST CASE 2 ============================
echo ==========================================================================
test_prepare
build_tc2

# Run test case 3: Fake build and populate a build cach
echo ==========================================================================
echo ========================= RUNNING TEST CASE 3 ============================
echo ==========================================================================
test_prepare
build_tc3

# Run test case 4: Fake build using the build cache produced in TC 3
echo ==========================================================================
echo ========================= RUNNING TEST CASE 4 ============================
echo ==========================================================================
build_tc4

# Run test case 5: Fake build and repopulate the build cache as there is no existing one
echo ==========================================================================
echo ========================= RUNNING TEST CASE 5 ============================
echo ==========================================================================
test_prepare
build_tc5

# Run test case 6: Fake build and repopulate the build cache as there the current one is invalidated/outdated
echo ==========================================================================
echo ========================= RUNNING TEST CASE 6 ============================
echo ==========================================================================
test_invalidate_cache
build_tc4

# Run test case 7: Build from upstream repos and populate the build cache
if [ ${FULL_INTEGRATION_TEST} -eq 1 ]; then
echo ==========================================================================
echo ========================= RUNNING TEST CASE 7 ============================
echo ==========================================================================
    test_prepare
    build_tc7
    POPULATE_CACHE_TIME=${BUILD_TIME}
fi

# Run test case 8: Build from cache produced in TC7
if [ ${FULL_INTEGRATION_TEST} -eq 1 ]; then
echo ==========================================================================
echo ========================= RUNNING TEST CASE 8 ============================
echo ==========================================================================
    build_tc8
    PARTIAL_BUILD_TIME=${BUILD_TIME}
fi

# Run test case 9: Build and repopulate the cache as the current one is invalidated/not up to date
if [ ${FULL_INTEGRATION_TEST} -eq 1 ]; then
echo ==========================================================================
echo ========================= RUNNING TEST CASE 9 ============================
echo ==========================================================================
    echo "TEST - $0 - REPOPULATING CACHE DUE TO CACHE INVALIDATION"
    test_invalidate_cache
    build_tc8
fi

TEST_TIME=$(($(date +%s)-${TEST_START}))

rm -rf tmp
echo "All tests passed!, test duration was ${TEST_TIME} seconds"
if [ ${FULL_INTEGRATION_TEST} -eq 1 ]; then
    echo "Full build took ${POPULATE_CACHE_TIME} second"
    echo "Incremental build took ${PARTIAL_BUILD_TIME} seconds"
fi
rc=0
exit $rc
}
#
# END of build script integration test
############################################################################

############################################################################
# BEGIN of debug_make - a fake make initiated with -D for debugging
#
debug_make () {
    make -C ${BUILD_BASE} clean
    echo "This is a fake debug fuel .iso image" > ${BUILD_BASE}/fuel-6.0.1.iso

    echo "This is a fake debug versions file" > ${BUILD_BASE}/.versions
    echo "cache.mk" $(md5sum ${BUILD_BASE}/cache.mk | cut -f1 -d " ") >> ${BUILD_BASE}/.versions
    echo "config.mk" $(md5sum ${BUILD_BASE}/config.mk | cut -f1 -d " ") >> ${BUILD_BASE}/.versions
    echo "fuel" $(git ls-remote $(make -C ${BUILD_BASE} get-fuel-repo | grep https) | awk '{print $(NF-1)}') >> ${BUILD_BASE}/.versions
    echo "odl" $(git ls-remote $(make -C ${BUILD_BASE} get-odl-repo | grep https) | awk '{print $(NF-1)}') >> ${BUILD_BASE}/.versions

    rm -rf ${BUILD_BASE}/release
    mkdir ${BUILD_BASE}/release
    echo "This is a fake debug OPNFV .iso image"  > ${BUILD_BASE}/release/fake-debug.iso
    echo "This is a fake debug OPNFV .iso.txt message"  > ${BUILD_BASE}/release/fake-debug.iso.txt
    echo "This a fake debug odl build history" > ${BUILD_BASE}/opendaylight/.odl-build-history
    echo "This a fake debug odl build log" > ${BUILD_BASE}/opendaylight/.odl-build.log
}
#
# END of debug_make
############################################################################