2021-01-07 22:30:30 +00:00
|
|
|
# Copyright 2021 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2018-02-24 21:49:10 +00:00
|
|
|
import pytest
|
|
|
|
import sys
|
2021-06-13 10:08:14 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
2018-02-24 21:49:10 +00:00
|
|
|
|
2020-02-20 19:14:38 +00:00
|
|
|
import pmb_test
|
|
|
|
import pmb_test.const
|
2018-02-24 21:49:10 +00:00
|
|
|
import pmb.aportgen.device
|
|
|
|
import pmb.config
|
|
|
|
import pmb.config.init
|
|
|
|
import pmb.helpers.logging
|
|
|
|
import pmb.install._install
|
|
|
|
|
|
|
|
|
|
|
|
@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_get_nonfree_packages(args):
|
2020-02-20 19:14:38 +00:00
|
|
|
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
2018-02-24 21:49:10 +00:00
|
|
|
func = pmb.install._install.get_nonfree_packages
|
|
|
|
|
|
|
|
# Device without any non-free subpackages
|
|
|
|
args.nonfree_firmware = True
|
|
|
|
args.nonfree_userland = True
|
|
|
|
assert func(args, "lg-mako") == []
|
|
|
|
|
|
|
|
# Device with non-free firmware and userland
|
|
|
|
device = "nonfree-firmware-and-userland"
|
|
|
|
assert func(args, device) == ["device-" + device + "-nonfree-firmware",
|
|
|
|
"device-" + device + "-nonfree-userland"]
|
|
|
|
|
|
|
|
# Device with non-free userland
|
|
|
|
device = "nonfree-userland"
|
|
|
|
assert func(args, device) == ["device-" + device + "-nonfree-userland"]
|
|
|
|
|
|
|
|
# Device with non-free userland (but user disabled it init)
|
|
|
|
args.nonfree_userland = False
|
|
|
|
assert func(args, device) == []
|
2020-07-20 06:57:01 +00:00
|
|
|
|
|
|
|
|
2021-01-24 09:00:22 +00:00
|
|
|
def test_get_recommends(args):
|
2020-07-20 06:57:01 +00:00
|
|
|
args.aports = pmb_test.const.testdata + "/pmb_recommends"
|
2021-01-24 09:00:22 +00:00
|
|
|
func = pmb.install.ui.get_recommends
|
2020-07-20 06:57:01 +00:00
|
|
|
|
|
|
|
# UI: none
|
|
|
|
args.install_recommends = True
|
|
|
|
args.ui = "none"
|
|
|
|
assert func(args) == []
|
|
|
|
|
|
|
|
# UI: test, --no-recommends
|
|
|
|
args.install_recommends = False
|
|
|
|
args.ui = "test"
|
|
|
|
assert func(args) == []
|
|
|
|
|
|
|
|
# UI: test, without -extras
|
|
|
|
args.install_recommends = True
|
|
|
|
args.ui = "test"
|
|
|
|
args.ui_extras = False
|
|
|
|
assert func(args) == ["plasma-camera", "plasma-angelfish"]
|
|
|
|
|
|
|
|
# UI: test, with -extras
|
|
|
|
args.install_recommends = True
|
|
|
|
args.ui = "test"
|
|
|
|
args.ui_extras = True
|
|
|
|
assert func(args) == ["plasma-camera", "plasma-angelfish", "buho",
|
|
|
|
"kaidan"]
|
|
|
|
|
|
|
|
# UI: invalid
|
|
|
|
args.install_recommends = True
|
|
|
|
args.ui = "invalid"
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
func(args)
|
|
|
|
assert str(e.value).startswith("Could not find aport for package")
|
2021-01-24 09:03:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_groups(args):
|
|
|
|
args.aports = f"{pmb_test.const.testdata}/pmb_groups"
|
|
|
|
func = pmb.install.ui.get_groups
|
|
|
|
|
|
|
|
# UI: none:
|
|
|
|
args.ui = "none"
|
|
|
|
assert func(args) == []
|
|
|
|
|
|
|
|
# UI: test, without -extras
|
|
|
|
args.ui = "test"
|
|
|
|
args.ui_extras = False
|
|
|
|
assert func(args) == ["feedbackd"]
|
|
|
|
|
|
|
|
# UI: test, with -extras
|
|
|
|
args.ui = "test"
|
|
|
|
args.ui_extras = True
|
|
|
|
assert func(args) == ["feedbackd", "extra"]
|
|
|
|
|
|
|
|
# UI: invalid
|
|
|
|
args.ui = "invalid"
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
func(args)
|
|
|
|
assert str(e.value).startswith("Could not find aport for package")
|
2021-06-13 10:08:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_generate_binary_list(args):
|
|
|
|
suffix = "mysuffix"
|
|
|
|
args.work = "/tmp"
|
|
|
|
func = pmb.install._install.generate_binary_list
|
|
|
|
binary_dir = os.path.join(args.work, f"chroot_{suffix}", "usr/share")
|
|
|
|
os.makedirs(binary_dir, exist_ok=True)
|
|
|
|
step = 1024
|
|
|
|
binaries = [f"{pmb_test.const.testdata}/pmb_install/small.bin",
|
|
|
|
f"{pmb_test.const.testdata}/pmb_install/full.bin",
|
|
|
|
f"{pmb_test.const.testdata}/pmb_install/big.bin",
|
|
|
|
f"{pmb_test.const.testdata}/pmb_install/overrun.bin",
|
|
|
|
f"{pmb_test.const.testdata}/pmb_install/binary2.bin"]
|
|
|
|
for b in binaries:
|
|
|
|
shutil.copy(b, binary_dir)
|
|
|
|
|
|
|
|
# Binary that is small enough to fit the partition of 10 blocks
|
|
|
|
# of 512 bytes each
|
|
|
|
binaries = "small.bin:1,binary2.bin:11"
|
|
|
|
args.deviceinfo = {"sd_embed_firmware": binaries,
|
|
|
|
"boot_part_start": "128"}
|
|
|
|
assert func(args, suffix, step) == [('small.bin', 1), ('binary2.bin', 11)]
|
|
|
|
|
|
|
|
# Binary that is fully filling the partition of 10 blocks of 512 bytes each
|
|
|
|
binaries = "full.bin:1,binary2.bin:11"
|
|
|
|
args.deviceinfo = {"sd_embed_firmware": binaries,
|
|
|
|
"boot_part_start": "128"}
|
|
|
|
assert func(args, suffix, step) == [('full.bin', 1), ('binary2.bin', 11)]
|
|
|
|
|
|
|
|
# Binary that is too big to fit the partition of 10 blocks
|
|
|
|
# of 512 bytes each
|
|
|
|
binaries = "big.bin:1,binary2.bin:2"
|
|
|
|
args.deviceinfo = {"sd_embed_firmware": binaries,
|
|
|
|
"boot_part_start": "128"}
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
func(args, suffix, step)
|
|
|
|
assert str(e.value).startswith("The firmware overlaps with at least one")
|
|
|
|
|
|
|
|
# Binary that overruns the first partition
|
|
|
|
binaries = "overrun.bin:1"
|
|
|
|
args.deviceinfo = {"sd_embed_firmware": binaries,
|
|
|
|
"boot_part_start": "1"}
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
func(args, suffix, step)
|
|
|
|
assert str(e.value).startswith("The firmware is too big to embed in")
|
|
|
|
|
|
|
|
# Binary does not exist
|
|
|
|
binaries = "does-not-exist.bin:1,binary2.bin:11"
|
|
|
|
args.deviceinfo = {"sd_embed_firmware": binaries,
|
|
|
|
"boot_part_start": "128"}
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
func(args, suffix, step)
|
|
|
|
assert str(e.value).startswith("The following firmware binary does not")
|