2022-01-02 21:38:21 +00:00
|
|
|
# Copyright 2022 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-05-26 20:08:45 +00:00
|
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
|
2020-02-20 19:14:38 +00:00
|
|
|
import pmb_test
|
|
|
|
import pmb_test.const
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.helpers.git
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
import pmb.helpers.logging
|
2017-08-12 14:03:40 +00:00
|
|
|
import pmb.parse.version
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
Debian Jessie/Python 3.4 support for the most part (#6)
* automatically find the chroot binary on Debian, even if it is not
in the user's PATH
* don't use subprocess.run anymore (remove related testcase, that explicitly
checked for subprocess.run usage, and used recursive globbing, another
post 3.4 Python feature, for the checks. A similar case can be added in the
future, but right now it's more important to get Debian 3.4 working and all
PRs are reviewed anyway.)
* pytest fixtures: don't use the newer "yield" feature, as this is only
supported in a newer version of pytest, than provided on Debian Jessie
From manually testing, most stuff works in Debian Jessie. However, the
testsuite does not run through - creating an empty .tar.gz with Python
fails for some reason (this is done in test_apk_static.py).
2017-05-29 18:38:11 +00:00
|
|
|
def args(request):
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.parse
|
|
|
|
sys.argv = ["pmbootstrap.py", "chroot"]
|
|
|
|
args = pmb.parse.arguments()
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
args.log = args.work + "/log_testsuite.txt"
|
|
|
|
pmb.helpers.logging.init(args)
|
2021-09-20 10:00:13 +00:00
|
|
|
request.addfinalizer(pmb.helpers.logging.logfd.close)
|
2017-05-26 20:08:45 +00:00
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def test_version(args):
|
2017-08-12 14:03:40 +00:00
|
|
|
# Fail after the first error or print a grand total of failures
|
|
|
|
keep_going = False
|
|
|
|
|
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
|
|
|
# Iterate over the version tests from apk-tools
|
2020-02-20 19:14:38 +00:00
|
|
|
path = pmb_test.const.testdata + "/version/version.data"
|
2017-05-26 20:08:45 +00:00
|
|
|
mapping = {-1: "<", 0: "=", 1: ">"}
|
2017-08-12 14:03:40 +00:00
|
|
|
count = 0
|
|
|
|
errors = []
|
2017-05-26 20:08:45 +00:00
|
|
|
with open(path) as handle:
|
|
|
|
for line in handle:
|
|
|
|
split = line.split(" ")
|
|
|
|
a = split[0]
|
2017-08-12 14:03:40 +00:00
|
|
|
b = split[2].split("#")[0].rstrip()
|
2017-05-26 20:08:45 +00:00
|
|
|
expected = split[1]
|
2017-08-12 14:03:40 +00:00
|
|
|
print("(#" + str(count) + ") " + line.rstrip())
|
|
|
|
result = pmb.parse.version.compare(a, b)
|
|
|
|
real = mapping[result]
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2017-08-12 14:03:40 +00:00
|
|
|
count += 1
|
|
|
|
if real != expected:
|
|
|
|
if keep_going:
|
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
|
|
|
errors.append(line.rstrip() + " (got: '" + real + "')")
|
2017-08-12 14:03:40 +00:00
|
|
|
else:
|
|
|
|
assert real == expected
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2017-08-12 14:03:40 +00:00
|
|
|
print("---")
|
|
|
|
print("total: " + str(count))
|
|
|
|
print("errors: " + str(len(errors)))
|
|
|
|
print("---")
|
|
|
|
for error in errors:
|
|
|
|
print(error)
|
|
|
|
assert errors == []
|
2019-06-30 14:11:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_version_check_string():
|
|
|
|
func = pmb.parse.version.check_string
|
|
|
|
assert func("3.2.4", ">=0.0.0") is True
|
|
|
|
assert func("3.2.4", ">=3.2.4") is True
|
|
|
|
assert func("3.2.4", "<4.0.0") is True
|
|
|
|
|
|
|
|
assert func("0.0.0", ">=0.0.1") is False
|
|
|
|
assert func("4.0.0", "<4.0.0") is False
|
|
|
|
assert func("4.0.1", "<4.0.0") is False
|
|
|
|
|
|
|
|
assert func("5.2.0_rc3", "<5.2.0") is False
|
|
|
|
assert func("5.2.0_rc3", ">=5.2.0") is True
|