Run fast testcases in Travis CI, remove obsolete testcase (#760)

* Removed obsolete apkindex_files cache testcase (the corresponding
function has been removed in #345 already).
* Fix test_challenge_apk: It failed on Travis, because we're accessing
/etc/abuild.conf, which only exists after initializing the build environment.
It's a random dummy file anyway, so I've replaced it with another file.
* Fix test_folder_size: accept a tolerance in the result
This commit is contained in:
Oliver Smith 2017-10-23 19:44:08 +00:00 committed by GitHub
parent b1c86d4586
commit ed94ab7449
7 changed files with 45 additions and 27 deletions

View File

@ -7,11 +7,12 @@ addons:
- debian-sid
packages:
- shellcheck
install: "pip install flake8"
install: "pip install flake8 pytest-cov"
script:
- test/static_code_analysis.sh
- yes "" | ./pmbootstrap.py init
- ./pmbootstrap.py kconfig_check
- test/testcases_fast.sh
- test/check_checksums.py
notifications:
- email: false

View File

@ -26,11 +26,14 @@ import pmb.helpers.run
def folder_size(args, path):
"""
Run `du` to calculate the size of a folder (this is less code and
faster than doing the same task in pure Python).
faster than doing the same task in pure Python). This result is only
approximatelly right, but good enough for pmbootstrap's use case:
<https://github.com/postmarketOS/pmbootstrap/pull/760>
:returns: folder size in bytes
"""
output = pmb.helpers.run.root(args, ["du", "--summarize",
"--apparent-size",
"--block-size=1",
path], return_stdout=True)
ret = int(output.split("\t")[0])

View File

@ -23,6 +23,7 @@ DIR="$(cd "$(dirname "$0")" && pwd -P)"
cd "$DIR"/..
sh_files="
./test/static_code_analysis.sh
./test/testcases_fast.sh
./aports/main/postmarketos-base/firmwareload.sh
./aports/main/postmarketos-mkinitfs/init.sh.in
./aports/main/postmarketos-mkinitfs/init_functions.sh

View File

@ -60,7 +60,7 @@ def test_apk_challenge_contents_diff(args):
# Second file
apk_b = temp_path_outside + "/b.apk"
pmb.chroot.user(args, ["cp", "/etc/abuild.conf", temp_path + "/" + name])
pmb.chroot.user(args, ["cp", "/etc/motd", temp_path + "/" + name])
pmb.chroot.user(args, ["tar", "-czf", "b.apk", name],
working_dir=temp_path)

View File

@ -39,13 +39,19 @@ def args(request):
def test_get_folder_size(args, tmpdir):
# Write five 2 KB files to tmpdir
# Write five 200 KB files to tmpdir
tmpdir = str(tmpdir)
files = 5
for i in range(files):
pmb.helpers.run.user(args, ["dd", "if=/dev/zero", "of=" +
tmpdir + "/" + str(i), "bs=1K",
"count=2", "conv=notrunc"])
"count=200", "conv=notrunc"])
# Check if the size is correct
assert pmb.helpers.other.folder_size(args, tmpdir) == 20480
# Check if the size is correct. Unfortunately, the `du` call
# in pmb.helpers.other.folder_size is not very accurate, so we
# allow 10kb of tolerance (good enough for our use case):
# <https://github.com/postmarketOS/pmbootstrap/pull/760>
tolerance = 10240
size = 204800 * files
result = pmb.helpers.other.folder_size(args, tmpdir)
assert (result < size + tolerance and result > size - tolerance)

View File

@ -21,7 +21,6 @@ import sys
import pytest
import types
import time
import logging
# Import from parent directory
pmb_src = os.path.realpath(os.path.join(os.path.dirname(__file__) + "/.."))
@ -108,22 +107,3 @@ def test_hash():
url = "https://nl.alpinelinux.org/alpine/edge/testing"
hash = "865a153c"
assert pmb.helpers.repo.hash(url, 8) == hash
def test_apkindex_files(args):
# Make sure, that we have a user's APKINDEX.tar.gz
pmb.build.package(args, "hello-world", args.arch_native)
# Reset the cache
del args.cache["apkindex_files"][args.arch_native]
# Fake the upstream folder to be the same as the normal packages folder
args.mirror_postmarketos = args.work + "/packages"
files = pmb.helpers.repo.apkindex_files(args)
for file in files:
assert os.path.exists(file)
logging.info(file)
# Test cache
assert files == pmb.helpers.repo.apkindex_files(args)

27
test/testcases_fast.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh -e
# Disable slow testcases
# aport_in_sync_with_git: clones Alpine's aports repo
# aportgen: clones Alpine's aports repo
# build: builds cross-compilers for aarch64 and armhf
# version: clones Alpine's apk repo
disabled="
aport_in_sync_with_git
aportgen
build
version
"
# Filter out disabled testcases
enabled=""
cd "$(dirname "$0")/.."
for file in test/test_*.py; do
for test in $disabled; do
[ "test/test_${test}.py" = "$file" ] && continue 2
done
enabled="$enabled $file"
done
# Run enabled testcases with coverage enabled
# shellcheck disable=SC2086
pytest --cov=pmb $enabled