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
|
|
|
|
""" Test pmb.helper.pkgrel_bump """
|
2018-01-14 01:26:42 +00:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import pytest
|
2019-11-10 10:20:00 +00:00
|
|
|
import shutil
|
2018-01-14 01:26:42 +00:00
|
|
|
import sys
|
|
|
|
|
2020-02-20 19:14:38 +00:00
|
|
|
import pmb_test # noqa
|
2018-01-14 01:26:42 +00:00
|
|
|
import pmb.helpers.pkgrel_bump
|
|
|
|
import pmb.helpers.logging
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def args(request):
|
|
|
|
import pmb.parse
|
|
|
|
sys.argv = ["pmbootstrap.py", "chroot"]
|
|
|
|
args = pmb.parse.arguments()
|
|
|
|
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)
|
2018-01-14 01:26:42 +00:00
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def pmbootstrap(args, tmpdir, parameters, zero_exit=True):
|
|
|
|
"""
|
2021-05-19 19:43:36 +00:00
|
|
|
Helper function for running pmbootstrap inside the fake work folder
|
|
|
|
(created by setup() below) with the binary repo disabled and with the
|
|
|
|
testdata configured as aports.
|
2018-01-14 01:26:42 +00:00
|
|
|
|
|
|
|
:param parameters: what to pass to pmbootstrap, e.g. ["build", "testlib"]
|
|
|
|
:param zero_exit: expect pmbootstrap to exit with 0 (no error)
|
|
|
|
"""
|
|
|
|
# Run pmbootstrap
|
|
|
|
aports = tmpdir + "/_aports"
|
|
|
|
config = tmpdir + "/_pmbootstrap.cfg"
|
|
|
|
|
2019-11-10 10:20:00 +00:00
|
|
|
# Copy .git dir to fake pmaports
|
|
|
|
dot_git = tmpdir + "/_aports/.git"
|
|
|
|
if not os.path.exists(dot_git):
|
|
|
|
shutil.copytree(args.aports + "/.git", dot_git)
|
|
|
|
|
2018-01-14 01:26:42 +00:00
|
|
|
try:
|
|
|
|
pmb.helpers.run.user(args, ["./pmbootstrap.py", "--work=" + tmpdir,
|
|
|
|
"--mirror-pmOS=", "--aports=" + aports,
|
|
|
|
"--config=" + config] + parameters,
|
2020-02-20 19:14:38 +00:00
|
|
|
working_dir=pmb.config.pmb_src)
|
2018-01-14 01:26:42 +00:00
|
|
|
|
|
|
|
# Verify that it exits as desired
|
|
|
|
except Exception as exc:
|
|
|
|
if zero_exit:
|
|
|
|
raise RuntimeError("pmbootstrap failed") from exc
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
if not zero_exit:
|
|
|
|
raise RuntimeError("Expected pmbootstrap to fail, but it did not!")
|
|
|
|
|
|
|
|
|
|
|
|
def setup_work(args, tmpdir):
|
|
|
|
"""
|
|
|
|
Create fake work folder in tmpdir with everything symlinked except for the
|
|
|
|
built packages. The aports testdata gets copied to the tempfolder as
|
|
|
|
well, so it can be modified during testing.
|
|
|
|
"""
|
|
|
|
# Clean the chroots, and initialize the build chroot in the native chroot.
|
2021-05-19 19:43:36 +00:00
|
|
|
# We do this before creating the fake work folder, because then all
|
|
|
|
# packages are still present.
|
2020-02-20 19:14:38 +00:00
|
|
|
os.chdir(pmb.config.pmb_src)
|
2018-01-14 01:26:42 +00:00
|
|
|
pmb.helpers.run.user(args, ["./pmbootstrap.py", "-y", "zap"])
|
|
|
|
pmb.helpers.run.user(args, ["./pmbootstrap.py", "build_init"])
|
|
|
|
pmb.helpers.run.user(args, ["./pmbootstrap.py", "shutdown"])
|
|
|
|
|
|
|
|
# Link everything from work (except for "packages") to the tmpdir
|
|
|
|
for path in glob.glob(args.work + "/*"):
|
|
|
|
if os.path.basename(path) != "packages":
|
|
|
|
pmb.helpers.run.user(args, ["ln", "-s", path, tmpdir + "/"])
|
|
|
|
|
|
|
|
# Copy testdata and selected device aport
|
2020-02-26 11:13:26 +00:00
|
|
|
for folder in ["device/testing", "main"]:
|
2018-01-14 01:26:42 +00:00
|
|
|
pmb.helpers.run.user(args, ["mkdir", "-p", args.aports, tmpdir +
|
|
|
|
"/_aports/" + folder])
|
2020-04-11 16:40:11 +00:00
|
|
|
path_original = pmb.helpers.pmaports.find(args, f"device-{args.device}")
|
|
|
|
pmb.helpers.run.user(args, ["cp", "-r", path_original,
|
|
|
|
f"{tmpdir}/_aports/device/testing"])
|
2018-04-15 21:34:40 +00:00
|
|
|
for pkgname in ["testlib", "testapp", "testsubpkg"]:
|
2018-01-14 01:26:42 +00:00
|
|
|
pmb.helpers.run.user(args, ["cp", "-r",
|
2021-05-19 19:43:36 +00:00
|
|
|
"test/testdata/pkgrel_bump/aports/"
|
|
|
|
f"{pkgname}",
|
|
|
|
f"{tmpdir}/_aports/main/{pkgname}"])
|
2018-01-14 01:26:42 +00:00
|
|
|
|
2018-09-05 05:57:38 +00:00
|
|
|
# Copy pmaports.cfg
|
|
|
|
pmb.helpers.run.user(args, ["cp", args.aports + "/pmaports.cfg", tmpdir +
|
|
|
|
"/_aports"])
|
|
|
|
|
2018-01-14 01:26:42 +00:00
|
|
|
# Empty packages folder
|
2020-04-10 13:21:23 +00:00
|
|
|
channel = pmb.config.pmaports.read_config(args)["channel"]
|
|
|
|
packages_path = f"{tmpdir}/packages/{channel}"
|
|
|
|
pmb.helpers.run.user(args, ["mkdir", "-p", packages_path])
|
|
|
|
pmb.helpers.run.user(args, ["chmod", "777", packages_path])
|
2018-01-14 01:26:42 +00:00
|
|
|
|
pmb: fix test suite not running through twice
The test suite needed a `pmbootstrap shutdown` after running through,
before it could successfully run again.
Explanation:
This was caused by `test/test_pkgrel_bump.py`, which creates a
temporary work folder with every subfolder ("chroot_native",
"cache_apk_x86_64", ...) linked to the original work folder except for
the "packages" folder. At the end of the test case,
`pmbootstrap shutdown` gets executed and is expected to umount
everything as usual. But it does not umount anything because of the
symlinks, so `work/chroot_native/mnt/pmbootstrap-packages` points to
the fake packages folder of that test case, even after it is finished.
As a result, any test case that tries to access the packages folder in
the native chroot, will fail until `pmbootstrap shutdown` gets called.
Detailed Changes:
* Umount all folders inside the work folder, even if these are symlinks
* Remove obsolete reference to "disable timestamp based rebuilds" in a
comment in `test/test_pkgrel_bump.py`
* Run `pmbootstrap work_migrate` and `pmbootstrap shutdown` at the
beginning of `test/testcases_fast.sh`, in case the pkgrel_bump test
case was aborted before it could properly shutdown and to make it
more robust in general (user may have changed the mountpoints, work
folder may need to be migrated)
2018-07-14 00:38:33 +00:00
|
|
|
# Copy over the pmbootstrap config
|
2018-01-14 01:26:42 +00:00
|
|
|
pmb.helpers.run.user(args, ["cp", args.config, tmpdir +
|
|
|
|
"/_pmbootstrap.cfg"])
|
|
|
|
|
|
|
|
|
2021-11-09 11:54:07 +00:00
|
|
|
def verify_pkgrels(tmpdir, pkgrel_testlib, pkgrel_testapp,
|
2018-04-15 21:34:40 +00:00
|
|
|
pkgrel_testsubpkg):
|
2018-01-14 01:26:42 +00:00
|
|
|
"""
|
2018-04-15 21:34:40 +00:00
|
|
|
Verify the pkgrels of the three test APKBUILDs ("testlib", "testapp",
|
|
|
|
"testsubpkg").
|
2018-01-14 01:26:42 +00:00
|
|
|
"""
|
2021-10-30 12:20:57 +00:00
|
|
|
pmb.helpers.other.cache["apkbuild"] = {}
|
2018-04-15 21:34:40 +00:00
|
|
|
mapping = {"testlib": pkgrel_testlib,
|
|
|
|
"testapp": pkgrel_testapp,
|
|
|
|
"testsubpkg": pkgrel_testsubpkg}
|
2018-01-14 01:26:42 +00:00
|
|
|
for pkgname, pkgrel in mapping.items():
|
|
|
|
# APKBUILD path
|
|
|
|
path = tmpdir + "/_aports/main/" + pkgname + "/APKBUILD"
|
|
|
|
|
|
|
|
# Parse and verify
|
2021-11-09 11:52:10 +00:00
|
|
|
apkbuild = pmb.parse.apkbuild(path)
|
2018-01-14 01:26:42 +00:00
|
|
|
assert pkgrel == int(apkbuild["pkgrel"])
|
|
|
|
|
|
|
|
|
|
|
|
def test_pkgrel_bump_high_level(args, tmpdir):
|
|
|
|
# Tempdir setup
|
|
|
|
tmpdir = str(tmpdir)
|
|
|
|
setup_work(args, tmpdir)
|
|
|
|
|
|
|
|
# Let pkgrel_bump exit normally
|
2018-04-15 21:34:40 +00:00
|
|
|
pmbootstrap(args, tmpdir, ["build", "testlib", "testapp", "testsubpkg"])
|
2018-01-14 01:26:42 +00:00
|
|
|
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "--auto"])
|
2021-11-09 11:54:07 +00:00
|
|
|
verify_pkgrels(tmpdir, 0, 0, 0)
|
2018-01-14 01:26:42 +00:00
|
|
|
|
|
|
|
# Increase soname (testlib soname changes with the pkgrel)
|
|
|
|
pmbootstrap(args, tmpdir, ["pkgrel_bump", "testlib"])
|
2021-11-09 11:54:07 +00:00
|
|
|
verify_pkgrels(tmpdir, 1, 0, 0)
|
2018-01-14 01:26:42 +00:00
|
|
|
pmbootstrap(args, tmpdir, ["build", "testlib"])
|
|
|
|
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "--auto"])
|
2021-11-09 11:54:07 +00:00
|
|
|
verify_pkgrels(tmpdir, 1, 0, 0)
|
2018-01-14 01:26:42 +00:00
|
|
|
|
|
|
|
# Delete package with previous soname (--auto-dry exits with >0 now)
|
2020-04-10 13:21:23 +00:00
|
|
|
channel = pmb.config.pmaports.read_config(args)["channel"]
|
2021-10-16 16:33:27 +00:00
|
|
|
arch = pmb.config.arch_native
|
2020-04-10 13:21:23 +00:00
|
|
|
apk_path = f"{tmpdir}/packages/{channel}/{arch}/testlib-1.0-r0.apk"
|
|
|
|
pmb.helpers.run.root(args, ["rm", apk_path])
|
2018-01-14 01:26:42 +00:00
|
|
|
pmbootstrap(args, tmpdir, ["index"])
|
|
|
|
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "--auto"], False)
|
2021-11-09 11:54:07 +00:00
|
|
|
verify_pkgrels(tmpdir, 1, 0, 0)
|
2018-01-14 01:26:42 +00:00
|
|
|
|
2018-04-15 21:34:40 +00:00
|
|
|
# Bump pkgrel and build testapp/testsubpkg
|
2018-01-14 01:26:42 +00:00
|
|
|
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--auto"])
|
2021-11-09 11:54:07 +00:00
|
|
|
verify_pkgrels(tmpdir, 1, 1, 1)
|
2018-04-15 21:34:40 +00:00
|
|
|
pmbootstrap(args, tmpdir, ["build", "testapp", "testsubpkg"])
|
2018-01-14 01:26:42 +00:00
|
|
|
|
|
|
|
# After rebuilding, pkgrel_bump --auto-dry exits with 0
|
|
|
|
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "--auto"])
|
2021-11-09 11:54:07 +00:00
|
|
|
verify_pkgrels(tmpdir, 1, 1, 1)
|
2018-01-14 01:26:42 +00:00
|
|
|
|
|
|
|
# Test running with specific package names
|
|
|
|
pmbootstrap(args, tmpdir, ["pkgrel_bump", "invalid_package_name"], False)
|
|
|
|
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "testlib"], False)
|
2021-11-09 11:54:07 +00:00
|
|
|
verify_pkgrels(tmpdir, 1, 1, 1)
|
2018-01-14 01:26:42 +00:00
|
|
|
|
|
|
|
# Clean up
|
|
|
|
pmbootstrap(args, tmpdir, ["shutdown"])
|
|
|
|
pmb.helpers.run.root(args, ["rm", "-rf", tmpdir])
|