~mvo/apt/dep8

« back to all changes in this revision

Viewing changes to test/integration/framework

  • Committer: Michael Vogt
  • Date: 2011-02-08 09:25:47 UTC
  • mfrom: (1561.38.60 apt-sid)
  • Revision ID: michael.vogt@ubuntu.com-20110208092547-3gsosv0ywgr9vh2q
merged from lp:~donkult/apt/sid

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
if [ $MSGLEVEL -le 2 ]; then
40
40
        msgmsg() { true; }
41
41
        msgnmsg() { true; }
 
42
        msgtest() { true; }
 
43
        msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
 
44
        msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
 
45
        msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; }
42
46
fi
43
47
if [ $MSGLEVEL -le 3 ]; then
44
48
        msginfo() { true; }
78
82
dpkg() {
79
83
        $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
80
84
}
 
85
aptitude() {
 
86
        if [ -f ./aptconfig.conf ]; then
 
87
                APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY}  $(which aptitude) $*
 
88
        elif [ -f ../aptconfig.conf ]; then
 
89
                APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $*
 
90
        else
 
91
                LD_LIBRARY_PATH=${BUILDDIRECTORY}  $(which aptitude) $*
 
92
        fi
 
93
}
 
94
 
 
95
addtrap() {
 
96
        CURRENTTRAP="$CURRENTTRAP $1"
 
97
        trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
 
98
}
81
99
 
82
100
setupenvironment() {
83
101
        TMPWORKINGDIRECTORY=$(mktemp -d)
86
104
        BUILDDIRECTORY="${TESTDIR}/../../build/bin"
87
105
        test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
88
106
        local OLDWORKINGDIRECTORY=$(pwd)
89
 
        CURRENTTRAP="cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY"
90
 
        trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
 
107
        addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;"
91
108
        cd $TMPWORKINGDIRECTORY
92
109
        mkdir rootdir aptarchive keys
93
110
        cd rootdir
107
124
        local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
108
125
        if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
109
126
                cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages
110
 
        else
111
 
                touch aptarchive/Packages
 
127
        fi
 
128
        local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/')
 
129
        if [ -f "${TESTDIR}/${SOURCESSFILE}" ]; then
 
130
                cp "${TESTDIR}/${SOURCESSFILE}" aptarchive/Sources
112
131
        fi
113
132
        cp $(find $TESTDIR -name '*.pub' -o -name '*.sec') keys/
114
133
        ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
116
135
        echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
117
136
        echo "Debug::NoLocking \"true\";" >> aptconfig.conf
118
137
        echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
 
138
        echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
119
139
        echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
120
140
        echo "Dir::Bin::methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf
121
141
        echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
123
143
        echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
124
144
        echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
125
145
        echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
 
146
        echo 'quiet::NoUpdate "true";' >> aptconfig.conf
126
147
        export LC_ALL=C
127
148
        msgdone "info"
128
149
}
168
189
Build-Depends: debhelper (>= 7)
169
190
Standards-Version: 3.9.1
170
191
 
171
 
Package: $NAME
172
 
Architecture: $ARCH" > debian/control
 
192
Package: $NAME" > debian/control
 
193
        if [ "$ARCH" = 'all' ]; then
 
194
                echo "Architecture: all" >> debian/control
 
195
        else
 
196
                echo "Architecture: any" >> debian/control
 
197
        fi
173
198
        test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
174
199
        if [ -z "$DESCRIPTION" ]; then
175
200
                echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
199
224
        else
200
225
                DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
201
226
        fi
202
 
        setupsimplenativepackage "$NAME" "$ARCH" "$VERSION" "$RELEASE" "$DEPENDENCIES" "$DESCRIPTION" "$SECTION"
203
 
        buildpackage "incoming/${NAME}-${VERSION}" "$RELEASE" "$DISTSECTION"
204
 
        rm -rf "incoming/${NAME}-${VERSION}"
 
227
        local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}
 
228
 
 
229
        msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… "
 
230
        mkdir -p $BUILDDIR/debian/source
 
231
        echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES
 
232
        echo "#!/bin/sh
 
233
echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME}
 
234
 
 
235
        echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright
 
236
        echo "$NAME ($VERSION) $RELEASE; urgency=low
 
237
 
 
238
  * Initial release
 
239
 
 
240
 -- Joe Sixpack <joe@example.org>  $(date -R)" > ${BUILDDIR}/debian/changelog
 
241
        echo "Source: $NAME
 
242
Section: $SECTION
 
243
Priority: optional
 
244
Maintainer: Joe Sixpack <joe@example.org>
 
245
Standards-Version: 3.9.1
 
246
 
 
247
Package: $NAME" > ${BUILDDIR}/debian/control
 
248
        if [ "$ARCH" = 'all' ]; then
 
249
                echo "Architecture: all" >> ${BUILDDIR}/debian/control
 
250
        else
 
251
                echo "Architecture: any" >> ${BUILDDIR}/debian/control
 
252
        fi
 
253
        test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> ${BUILDDIR}/debian/control
 
254
        if [ -z "$DESCRIPTION" ]; then
 
255
                echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
 
256
 If you find such a package installed on your system,
 
257
 YOU did something horribly wrong! They are autogenerated
 
258
 und used only by testcases for APT and surf no other propose…" >> ${BUILDDIR}/debian/control
 
259
        else
 
260
                echo "Description: $DESCRIPTION" >> ${BUILDIR}/debian/control
 
261
        fi
 
262
        echo '3.0 (native)' > ${BUILDDIR}/debian/source/format
 
263
        local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')"
 
264
 
 
265
        mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
 
266
        cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
 
267
        cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
 
268
        (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$ARCH)
 
269
        (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums)
 
270
 
 
271
        dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. > /dev/null
 
272
        echo "pool/${NAME}_${VERSION}_${ARCH}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist
 
273
        for SRC in $SRCS; do
 
274
                echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist
 
275
        done
 
276
        rm -rf "${BUILDDIR}"
 
277
        msgdone "info"
205
278
}
206
279
 
207
280
buildpackage() {
255
328
        Packages::Compress ". gzip bzip2 lzma";
256
329
        Sources::Compress ". gzip bzip2 lzma";
257
330
        Contents::Compress ". gzip bzip2 lzma";
 
331
        Translation::Compress ". gzip bzip2 lzma";
 
332
        LongDescription "false";
258
333
};
259
334
TreeDefault {
260
335
        Directory "pool/";
308
383
        done
309
384
}
310
385
 
 
386
insertpackage() {
 
387
        local RELEASE="$1"
 
388
        local NAME="$2"
 
389
        local ARCH="$3"
 
390
        local VERSION="$4"
 
391
        local DEPENDENCIES="$5"
 
392
        local ARCHS="$ARCH"
 
393
        if [ "$ARCHS" = "all" ]; then
 
394
                ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
 
395
        fi
 
396
        for BUILDARCH in $ARCHS; do
 
397
                local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}"
 
398
                mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source
 
399
                touch aptarchive/dists/${RELEASE}/main/source/Sources
 
400
                local FILE="${PPATH}/Packages"
 
401
                echo "Package: $NAME
 
402
Priority: optional
 
403
Section: other
 
404
Installed-Size: 42
 
405
Maintainer: Joe Sixpack <joe@example.org>
 
406
Architecture: $ARCH
 
407
Version: $VERSION
 
408
Filename: pool/main/${NAME}/${NAME}_${VERSION}_${ARCH}.deb" >> $FILE
 
409
                test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
 
410
                echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
 
411
 If you find such a package installed on your system,
 
412
 YOU did something horribly wrong! They are autogenerated
 
413
 und used only by testcases for APT and surf no other propose…
 
414
" >> $FILE
 
415
        done
 
416
}
 
417
 
311
418
buildaptarchivefromincoming() {
312
419
        msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…"
313
420
        cd aptarchive
316
423
        [ -e dists ] || buildaptftparchivedirectorystructure
317
424
        msgninfo "\tGenerate Packages, Sources and Contents files… "
318
425
        aptftparchive -qq generate ftparchive.conf
319
 
        msgdone "info"
320
 
        msgninfo "\tGenerate Release files… "
321
 
        for dir in $(find ./dists -mindepth 1 -maxdepth 1 -type d); do
322
 
                aptftparchive -qq release $dir -o APT::FTPArchive::Release::Codename="$(echo "$dir" | cut -d'/' -f 3)" | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
323
 
        done
324
426
        cd - > /dev/null
325
427
        msgdone "info"
 
428
        generatereleasefiles
326
429
}
327
430
 
328
431
buildaptarchivefromfiles() {
329
432
        msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
330
 
        cd aptarchive
331
 
        if [ -f Packages ]; then
332
 
                msgninfo "\tPackages file… "
333
 
                cat Packages | gzip > Packages.gz
334
 
                cat Packages | bzip2 > Packages.bz2
335
 
                cat Packages | lzma > Packages.lzma
336
 
                msgdone "info"
337
 
        fi
338
 
        if [ -f Sources ]; then
339
 
                msgninfo "\tSources file… "
340
 
                cat Sources | gzip > Sources.gz
341
 
                cat Sources | bzip2 > Sources.bz2
342
 
                cat Sources | lzma > Sources.lzma
343
 
                msgdone "info"
344
 
        fi
345
 
        msgninfo "\tRelease file… "
346
 
        aptftparchive -qq release . | sed -e '/0 Release$/ d' > Release # remove the self reference
 
433
        find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
 
434
                msgninfo "\t${line} file… "
 
435
                cat ${line} | gzip > ${line}.gz
 
436
                cat ${line} | bzip2 > ${line}.bz2
 
437
                cat ${line} | lzma > ${line}.lzma
 
438
                msgdone "info"
 
439
        done
 
440
        generatereleasefiles
 
441
}
 
442
 
 
443
generatereleasefiles() {
 
444
        msgninfo "\tGenerate Release files… "
 
445
        local DATE="${1:-now}"
 
446
        if [ -e aptarchive/dists ]; then
 
447
                for dir in $(find ./aptarchive/dists -mindepth 3 -maxdepth 3 -type d -name 'i18n'); do
 
448
                        aptftparchive -qq release $dir -o APT::FTPArchive::Release::Patterns::='Translation-*' > $dir/Index
 
449
                done
 
450
                for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
 
451
                        local CODENAME="$(echo "$dir" | cut -d'/' -f 4)"
 
452
                        aptftparchive -qq release $dir -o APT::FTPArchive::Release::Suite="${CODENAME}" -o APT::FTPArchive::Release::Codename="${CODENAME}" | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
 
453
                        if [ "$CODENAME" = "experimental" -o "$CODENAME" = "experimental2" ]; then
 
454
                                sed -i '/^Date: / a\
 
455
NotAutomatic: yes' $dir/Release
 
456
                        fi
 
457
                done
 
458
        else
 
459
                aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference
 
460
        fi
 
461
        if [ "$DATE" != "now" ]; then
 
462
                for release in $(find ./aptarchive -name 'Release'); do
 
463
                        touch -d "$1" $release
 
464
                done
 
465
        fi
347
466
        msgdone "info"
348
 
        cd ..
349
467
}
350
468
 
351
469
setupdistsaptarchive() {
405
523
        done
406
524
        for RELEASE in $(find aptarchive/ -name Release); do
407
525
                gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
 
526
                gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
408
527
        done
409
528
        msgdone "info"
410
529
}
412
531
changetowebserver() {
413
532
        if which weborf > /dev/null; then
414
533
                weborf -xb aptarchive/ 2>&1 > /dev/null &
415
 
                CURRENTTRAP="kill $(ps | grep weborf | sed -e 's#^[ ]*##' | cut -d' ' -f 1); $CURRENTTRAP"
416
 
                trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
 
534
                addtrap "kill $!;"
417
535
                local APTARCHIVE="file://$(readlink -f ./aptarchive)"
418
536
                for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
419
537
                        sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
447
565
 
448
566
testequal() {
449
567
        local COMPAREFILE=$(mktemp)
 
568
        addtrap "rm $COMPAREFILE;"
450
569
        echo "$1" > $COMPAREFILE
451
570
        shift
452
571
        msgtest "Test for equality of" "$*"
453
572
        $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
454
 
        rm $COMPAREFILE
455
573
}
456
574
 
457
575
testequalor2() {
458
576
        local COMPAREFILE1=$(mktemp)
459
577
        local COMPAREFILE2=$(mktemp)
460
578
        local COMPAREAGAINST=$(mktemp)
 
579
        addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;"
461
580
        echo "$1" > $COMPAREFILE1
462
581
        echo "$2" > $COMPAREFILE2
463
582
        shift 2
468
587
                ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
469
588
                       "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
470
589
                  msgfail )
471
 
        rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
472
590
}
473
591
 
474
592
testshowvirtual() {
485
603
        VIRTUAL="${VIRTUAL}
486
604
N: No packages found"
487
605
        local COMPAREFILE=$(mktemp)
 
606
        addtrap "rm $COMPAREFILE;"
488
607
        local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
489
608
        eval `apt-config shell ARCH APT::Architecture`
490
609
        echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
491
610
        aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
492
 
        rm $COMPAREFILE
493
611
}
494
612
 
495
613
testnopackage() {