pmbootstrap-meow/test/check_checksums.py
Oliver Smith 5e85d72ca0
Testsuite: Run UIs in Qemu and check running processes and more (#982)
* Testsuite: Run UIs in Qemu and check running processes (and other changes)

* When `pmbootstrap qemu` gets killed, it now takes down the Qemu process with it
* `test/check_checksums.py` got a new optional `--build` parameter, which makes
  it build all changed packages instead of just checking the checksums
* We run this before running the testsuite now, so all changed packages get
  built before running tests (otherwise tests would hang without any output
  while a changed package is building)
* New testcase, that zaps all chroots, installs a specific UI (xfce4 and
  plasma-mobile currently, easy to extend), runs it via Qemu and checks the
  running processes via SSH.
* Version checking testcase: rewritten to include Alpine's testsuite file in
  our source tree, so we don't need to clone their git repo anymore. Now it
  is enabled for Travis.
* All this gives us a nice 10% code coverage boost
* Increased the `hello-world` pkgrel to verify that the Travis job is working.

* Various fixes
* Build device-packages for the device arch and don't raise an
  exception, but print a note if --ignore-depends is not specified
  and therefore the kernel gets installed, too.
* Don't use --force when building in Travis (because abuild doesn't
  check the checksums then. Bug report on the way.)
* Don't run the building process in the background, but wait for its
  completion
* Exit with 1 when showing usage in check_checksums.py
2018-02-02 00:16:29 +00:00

104 lines
3.4 KiB
Python
Executable file

#!/usr/bin/env python3
import os
import subprocess
import sys
def get_changed_files():
try:
raw = subprocess.check_output(['git', 'diff', '--name-only', os.environ['TRAVIS_COMMIT_RANGE']])
except (KeyError, subprocess.CalledProcessError) as e:
if 'TRAVIS_PULL_REQUEST' in os.environ and os.environ['TRAVIS_PULL_REQUEST'] == "true":
branch = os.environ['TRAVIS_PULL_REQUEST_BRANCH']
raw = subprocess.check_output(['git', 'diff', '--name-only', 'master...{}'.format(branch)])
else:
raw = subprocess.check_output(['git', 'diff', '--name-only', 'HEAD~1'])
return raw.decode().splitlines()
def get_changed_packages():
files = get_changed_files()
packages = set()
for file in files:
if not file.startswith("aports/"):
continue
name = file.split("/")[2]
package_path = "/".join(file.split("/")[0:3])
apkbuild_path = os.path.join(package_path, "APKBUILD")
if not os.path.exists(apkbuild_path):
print("No APKBUILD found at {}".format(package_path))
continue
packages.add(name)
return packages
def check_output_always(command):
try:
return subprocess.check_output(command)
except subprocess.CalledProcessError as e:
return e.output
def check_checksums(package):
command = ['./pmbootstrap.py', 'checksum', package]
try:
subprocess.check_output(command)
except subprocess.CalledProcessError as e:
print("Something gone wrong in pmbootstrap. Log:")
logfile = os.path.expanduser("~/.local/var/pmbootstrap/log.txt")
with open(logfile) as log:
print(log.read())
print("Test script failed on checksumming package '{}'".format(package))
exit(1)
result = check_output_always(['git', 'status', '--porcelain', '--untracked-files=no']).decode()
if result == "":
print("** The checksums are correct")
else:
print(result)
result = check_output_always(['git', 'diff']).decode()
print(result)
print("** The checksums are not correct")
exit(1)
def check_build(packages):
command = (["./pmbootstrap.py", "--details-to-stdout", "build",
"--strict"] + list(packages))
try:
process = subprocess.Popen(command)
process.communicate()
except subprocess.CalledProcessError as e:
print("** Building failed")
exit(1)
if __name__ == "__main__":
# Allow to specify "--build" to build instead of only verifying checksums
build = False
if len(sys.argv) > 1:
if sys.argv[1] == "--build":
build = True
else:
print("usage: {} [--build]".format(sys.argv[0]))
exit(1)
if 'TRAVIS_COMMIT_RANGE' in os.environ:
print('Checking commit range: {}'.format(os.environ['TRAVIS_COMMIT_RANGE']))
if 'TRAVIS_PULL_REQUEST_BRANCH' in os.environ:
print('Checking PR branch: {}'.format(os.environ['TRAVIS_PULL_REQUEST_BRANCH']))
packages = get_changed_packages()
if len(packages) == 0:
print("No aports packages changed in this commit")
exit(0)
if build:
print("Building in strict mode: " + ", ".join(packages))
check_build(packages)
else:
for package in packages:
print("Checking {} for correct checksums".format(package))
check_checksums(package)