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:
parent
b1c86d4586
commit
ed94ab7449
|
@ -7,11 +7,12 @@ addons:
|
||||||
- debian-sid
|
- debian-sid
|
||||||
packages:
|
packages:
|
||||||
- shellcheck
|
- shellcheck
|
||||||
install: "pip install flake8"
|
install: "pip install flake8 pytest-cov"
|
||||||
script:
|
script:
|
||||||
- test/static_code_analysis.sh
|
- test/static_code_analysis.sh
|
||||||
- yes "" | ./pmbootstrap.py init
|
- yes "" | ./pmbootstrap.py init
|
||||||
- ./pmbootstrap.py kconfig_check
|
- ./pmbootstrap.py kconfig_check
|
||||||
|
- test/testcases_fast.sh
|
||||||
- test/check_checksums.py
|
- test/check_checksums.py
|
||||||
notifications:
|
notifications:
|
||||||
- email: false
|
- email: false
|
||||||
|
|
|
@ -26,11 +26,14 @@ import pmb.helpers.run
|
||||||
def folder_size(args, path):
|
def folder_size(args, path):
|
||||||
"""
|
"""
|
||||||
Run `du` to calculate the size of a folder (this is less code and
|
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
|
:returns: folder size in bytes
|
||||||
"""
|
"""
|
||||||
output = pmb.helpers.run.root(args, ["du", "--summarize",
|
output = pmb.helpers.run.root(args, ["du", "--summarize",
|
||||||
|
"--apparent-size",
|
||||||
"--block-size=1",
|
"--block-size=1",
|
||||||
path], return_stdout=True)
|
path], return_stdout=True)
|
||||||
ret = int(output.split("\t")[0])
|
ret = int(output.split("\t")[0])
|
||||||
|
|
|
@ -23,6 +23,7 @@ DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
cd "$DIR"/..
|
cd "$DIR"/..
|
||||||
sh_files="
|
sh_files="
|
||||||
./test/static_code_analysis.sh
|
./test/static_code_analysis.sh
|
||||||
|
./test/testcases_fast.sh
|
||||||
./aports/main/postmarketos-base/firmwareload.sh
|
./aports/main/postmarketos-base/firmwareload.sh
|
||||||
./aports/main/postmarketos-mkinitfs/init.sh.in
|
./aports/main/postmarketos-mkinitfs/init.sh.in
|
||||||
./aports/main/postmarketos-mkinitfs/init_functions.sh
|
./aports/main/postmarketos-mkinitfs/init_functions.sh
|
||||||
|
|
|
@ -60,7 +60,7 @@ def test_apk_challenge_contents_diff(args):
|
||||||
|
|
||||||
# Second file
|
# Second file
|
||||||
apk_b = temp_path_outside + "/b.apk"
|
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],
|
pmb.chroot.user(args, ["tar", "-czf", "b.apk", name],
|
||||||
working_dir=temp_path)
|
working_dir=temp_path)
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,19 @@ def args(request):
|
||||||
|
|
||||||
|
|
||||||
def test_get_folder_size(args, tmpdir):
|
def test_get_folder_size(args, tmpdir):
|
||||||
# Write five 2 KB files to tmpdir
|
# Write five 200 KB files to tmpdir
|
||||||
tmpdir = str(tmpdir)
|
tmpdir = str(tmpdir)
|
||||||
files = 5
|
files = 5
|
||||||
for i in range(files):
|
for i in range(files):
|
||||||
pmb.helpers.run.user(args, ["dd", "if=/dev/zero", "of=" +
|
pmb.helpers.run.user(args, ["dd", "if=/dev/zero", "of=" +
|
||||||
tmpdir + "/" + str(i), "bs=1K",
|
tmpdir + "/" + str(i), "bs=1K",
|
||||||
"count=2", "conv=notrunc"])
|
"count=200", "conv=notrunc"])
|
||||||
|
|
||||||
# Check if the size is correct
|
# Check if the size is correct. Unfortunately, the `du` call
|
||||||
assert pmb.helpers.other.folder_size(args, tmpdir) == 20480
|
# 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)
|
||||||
|
|
|
@ -21,7 +21,6 @@ import sys
|
||||||
import pytest
|
import pytest
|
||||||
import types
|
import types
|
||||||
import time
|
import time
|
||||||
import logging
|
|
||||||
|
|
||||||
# Import from parent directory
|
# Import from parent directory
|
||||||
pmb_src = os.path.realpath(os.path.join(os.path.dirname(__file__) + "/.."))
|
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"
|
url = "https://nl.alpinelinux.org/alpine/edge/testing"
|
||||||
hash = "865a153c"
|
hash = "865a153c"
|
||||||
assert pmb.helpers.repo.hash(url, 8) == hash
|
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)
|
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue