Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Improve http tests-- parallel jobs & better portability
John Hood committed 4 years ago
commit 631baa9980a2c2d911f1406ae0a135ee59f0b987
parent 1aacbc7
2 files changed +82 -19
modified .cirrus.yml
@@ -1,5 +1,5 @@
freebsd_task:
-
        install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y kyua pkgconf mini_httpd
+
        install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y kyua pkgconf python3 bzip2
        script:
                - ./configure $EXTRA_ARGS
                - make -j4 || make V=1
@@ -24,7 +24,7 @@ debian_task:
                image: debian:latest
        install_script:
                - DEBIAN_FRONTEND=noninteractive apt-get update
-
                - DEBIAN_FRONTEND=noninteractive apt-get install -y libsqlite3-dev libbsd-dev libarchive-tools libarchive-dev libssl-dev liblzma-dev liblua5.2-dev nettle-dev liblzo2-dev libattr1-dev libacl1-dev wget build-essential zlib1g-dev libbz2-dev m4 libexpat1-dev liblz4-dev libxml2-dev libzstd-dev kyua atf-sh libatf-dev
+
                - DEBIAN_FRONTEND=noninteractive apt-get install -y libsqlite3-dev libbsd-dev libarchive-tools libarchive-dev libssl-dev liblzma-dev liblua5.2-dev nettle-dev liblzo2-dev libattr1-dev libacl1-dev wget build-essential zlib1g-dev libbz2-dev m4 libexpat1-dev liblz4-dev libxml2-dev libzstd-dev kyua atf-sh libatf-dev python3 bzip2
        env:
                # False-positive leak detection in recent glibc:
                # Direct leak of 12 byte(s) in 2 object(s) allocated from:
@@ -65,7 +65,7 @@ fedora_task:
                                 bzip2-devel libarchive-devel openssl-devel xz-devel m4 lz4-devel expat-devel
                                 libxml2-devel libacl-devel libzstd-devel
                                 libasan-static libubsan-static libasan-static libubsan-static
-
                                 bsdtar diffutils openssl which xz
+
                                 bsdtar diffutils openssl which xz python3 bzip2
        script:
                - ./configure --with-libarchive.pc --with-asan --with-ubsan
                - make -j4 || make V=1
modified tests/frontend/http.sh
@@ -2,35 +2,63 @@

. $(atf_get_srcdir)/test_environment.sh

+
CLEANUP="simple_fetch simple_repo simple_audit"
+

tests_init \
+
	simple_fetch \
	simple_repo \
-
	simple_fetch
+
	simple_audit
+


-
cleanup() {
-
	pkill -15 -F ${TMPDIR}/http.pid
+
httpd_startup() {
+
	pidfile=${TMPDIR}/http.pid
+
	statusfile=${TMPDIR}/http.status
+
	: > ${pidfile}
+
	: > ${statusfile}
+

+
	DIR=$1
+
	python3 -u -m http.server -d "${DIR}" --bind 127.0.0.1 0 > ${statusfile} &
+
	jobs -p %1 > ${pidfile}
+
	# a crude way to wait for its startup, I can't think of anything better
+
	while kill -s 0 %1 && ! [ -s ${statusfile} ]; do
+
	    sleep .1
+
	done
+
        url=$(sed -n 's#.*(\(http://.*\)/).*#\1#p' ${statusfile})
+
	atf_check test -n "${url}"
+
}
+

+
httpd_cleanup() {
+
	pid=$(cat ${TMPDIR}/http.pid)
+
	if [ -z "${pid}" ]; then
+
	    return 1
+
	fi
+
	if kill -s 0 ${pid}; then
+
	    kill -s INT ${pid}
+
	    for i in 0 1 2 3 4 5 6 7 8 9; do
+
		if ! kill -s 0 ${pid}; then
+
		    break
+
		fi
+
	    done
+
	fi
}

simple_repo_body()
{
-
	pidfile=${TMPDIR}/http.pid
-
	touch ${pidfile}
-

-
	atf_require mini_httpd "Requires mini_httpd to run this test"
+
	atf_require python3 "Requires python3 to run this test"
	atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
	atf_check pkg create -M test.ucl
	mkdir repo
	mv test-1.txz test-1.pkg repo/
	atf_check -o ignore pkg repo repo

-
	trap cleanup EXIT
-
	atf_check -o empty -e empty mini_httpd -h 127.0.0.1 -p 64242 -d ${TMPDIR}/repo -dd ${TMPDIR}/repo -i ${pidfile}
+
	httpd_startup ${TMPDIR}/repo

	cat > pkg.conf << EOF
PKG_DBDIR=${TMPDIR}
PKG_CACHEDIR=${TMPDIR}/cache
REPOS_DIR=[]
repositories: {
-
	local: { url: http://localhost:64242 }
+
	local: { url: ${url} }
}
EOF
	atf_check -o ignore \
@@ -39,12 +67,44 @@ EOF
		pkg -C ./pkg.conf install -y test
}

+
simple_repo_cleanup()
+
{
+
    httpd_cleanup
+
}
+

simple_fetch_body()
{
-
	pidfile=${TMPDIR}/http.pid
-
	touch ${pidfile}
+
	atf_require python3 "Requires python3 to run this test"
+
	atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
+
	atf_check pkg create -M test.ucl
+
	mkdir repo
+
	mv test-1.txz test-1.pkg repo/
+
	atf_check -o ignore pkg repo repo

-
	atf_require mini_httpd "Requires mini_httpd to run this test"
+
	httpd_startup ${TMPDIR}/repo
+

+
	cat > pkg.conf << EOF
+
PKG_DBDIR=${TMPDIR}
+
PKG_CACHEDIR=${TMPDIR}/cache
+
REPOS_DIR=[]
+
repositories: {
+
	local: { url: ${url} }
+
}
+
EOF
+
	atf_check -o ignore \
+
		pkg -C ./pkg.conf update
+
	atf_check -o match:"test-1" \
+
		pkg -C ./pkg.conf fetch -y test
+
}
+

+
simple_fetch_cleanup()
+
{
+
    httpd_cleanup
+
}
+

+
simple_audit_body()
+
{
+
	atf_require python3 "Requires python3 to run this test"

	mkdir rootdir
	cat > ${TMPDIR}/rootdir/meh <<EOF
@@ -54,14 +114,17 @@ simple_fetch_body()
EOF
	bzip2 ${TMPDIR}/rootdir/meh

-
	trap cleanup EXIT
-
	atf_check -o empty -e empty mini_httpd -h 127.0.0.1 -p 64242 -d ${TMPDIR}/rootdir -dd ${TMPDIR}/rootdir -i ${pidfile}
+
	httpd_startup ${TMPDIR}/rootdir

	cat > pkg.conf << EOF
PKG_DBDIR=${TMPDIR}
-
VULNXML_SITE = "http://localhost:64242/meh.bz2"
+
VULNXML_SITE = "${url}/meh.bz2"
EOF

	atf_check -o ignore pkg -C ./pkg.conf audit -F

}
+
simple_audit_cleanup()
+
{
+
    httpd_cleanup
+
}