pmbootstrap-meow/test/test_envkernel.py
Oliver Smith e605a0af32
test/pmb_test: prepare for common test code (!1876)
Replace the "Add topdir to import path" boilerplate lines in each test
file with a simple "import pmb_test". Use the "# noqa" comment if
"pmb_test" is not used further in the test file, so flake8 does not
complain about an unused module.

Make the path to the testdata available as pmb_test.const.testdata, and
use pmb.config.pmb_src to access the topdir in all tests.

This is in preparation for new "pmbootstrap status" related tests, which
will have shared test code in test/pmb_test/. Also, this makes the
pmbootstrap codebase more consistent with the bpo codebase, which has a
similar "import bpo_test" mechanism.
2020-02-24 03:01:04 +03:00

142 lines
5.7 KiB
Python

"""
Copyright 2020 Oliver Smith
This file is part of pmbootstrap.
pmbootstrap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pmbootstrap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
import pytest
import pmb_test
import pmb_test.const
import pmb.aportgen
import pmb.aportgen.core
import pmb.build
import pmb.build.envkernel
import pmb.config
import pmb.helpers.logging
@pytest.fixture
def args(tmpdir, request):
import pmb.parse
sys.argv = ["pmbootstrap.py", "init"]
args = pmb.parse.arguments()
args.log = args.work + "/log_testsuite.txt"
pmb.helpers.logging.init(args)
request.addfinalizer(args.logfd.close)
return args
def test_package_kernel_args(args):
args.packages = ["package-one", "package-two"]
with pytest.raises(RuntimeError) as e:
pmb.build.envkernel.package_kernel(args)
assert "--envkernel needs exactly one linux-* package as argument." in \
str(e.value)
def test_find_kbuild_output_dir(args):
# Test parsing an APKBUILD
pkgname = "linux-envkernel-test"
path = pmb_test.const.testdata + "/apkbuild/APKBUILD." + pkgname
function_body = pmb.parse.function_body(path, "package")
kbuild_out = pmb.build.envkernel.find_kbuild_output_dir(args,
function_body)
assert kbuild_out == "build"
# Test full function body
function_body = [
" install -Dm644 \"$srcdir\"/build/arch/arm/boot/dt.img ",
" \"$pkgdir\"/boot/dt.img",
"",
" install -Dm644 \"$srcdir\"/build/arch/arm/boot/zImage-dtb ",
" \"$pkgdir\"/boot/vmlinuz-$_flavor",
"",
" install -D \"$srcdir\"/build/include/config/kernel.release ",
" \"$pkgdir\"/usr/share/kernel/$_flavor/kernel.release",
"",
" cd \"$srcdir\"/build",
" unset LDFLAGS",
"",
" make ARCH=\"$_carch\" CC=\"${CC:-gcc}\" ",
" KBUILD_BUILD_VERSION=\"$((pkgrel + 1))-Alpine\" ",
" INSTALL_MOD_PATH=\"$pkgdir\" modules_install",
]
kbuild_out = pmb.build.envkernel.find_kbuild_output_dir(args,
function_body)
assert kbuild_out == "build"
# Test no kbuild out dir
function_body = [
" install -Dm644 \"$srcdir\"/arch/arm/boot/zImage ",
" \"$pkgdir\"/boot/vmlinuz-$_flavor",
" install -D \"$srcdir\"/include/config/kernel.release ",
" \"$pkgdir\"/usr/share/kernel/$_flavor/kernel.release",
]
kbuild_out = pmb.build.envkernel.find_kbuild_output_dir(args,
function_body)
assert kbuild_out == ""
# Test curly brackets around srcdir
function_body = [
" install -Dm644 \"${srcdir}\"/build/arch/arm/boot/zImage ",
" \"$pkgdir\"/boot/vmlinuz-$_flavor",
" install -D \"${srcdir}\"/build/include/config/kernel.release ",
" \"$pkgdir\"/usr/share/kernel/$_flavor/kernel.release",
]
kbuild_out = pmb.build.envkernel.find_kbuild_output_dir(args,
function_body)
assert kbuild_out == "build"
# Test multiple sub directories
function_body = [
" install -Dm644 \"${srcdir}\"/sub/dir/arch/arm/boot/zImage-dtb ",
" \"$pkgdir\"/boot/vmlinuz-$_flavor",
" install -D \"${srcdir}\"/sub/dir/include/config/kernel.release ",
" \"$pkgdir\"/usr/share/kernel/$_flavor/kernel.release",
]
kbuild_out = pmb.build.envkernel.find_kbuild_output_dir(args,
function_body)
assert kbuild_out == "sub/dir"
# Test no kbuild out dir found
function_body = [
" install -Dm644 \"$srcdir\"/build/not/found/zImage-dtb ",
" \"$pkgdir\"/boot/vmlinuz-$_flavor",
" install -D \"$srcdir\"/not/found/kernel.release ",
" \"$pkgdir\"/usr/share/kernel/$_flavor/kernel.release",
]
with pytest.raises(RuntimeError) as e:
kbuild_out = pmb.build.envkernel.find_kbuild_output_dir(args,
function_body)
assert ("Couldn't find a kbuild out directory. Is your APKBUILD messed up?"
" If not, then consider adjusting the patterns in "
"pmb/build/envkernel.py to work with your APKBUILD, or submit an "
"issue.") in str(e.value)
# Test multiple different kbuild out dirs
function_body = [
" install -Dm644 \"$srcdir\"/build/arch/arm/boot/zImage-dtb ",
" \"$pkgdir\"/boot/vmlinuz-$_flavor",
" install -D \"$srcdir\"/include/config/kernel.release ",
" \"$pkgdir\"/usr/share/kernel/$_flavor/kernel.release",
]
with pytest.raises(RuntimeError) as e:
kbuild_out = pmb.build.envkernel.find_kbuild_output_dir(args,
function_body)
assert ("Multiple kbuild out directories found. Can you modify your "
"APKBUILD so it only has one output path? If you can't resolve it,"
" please open an issue.") in str(e.value)