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-10-30 19:56:38 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
import sys
|
|
|
|
|
2020-02-20 19:14:38 +00:00
|
|
|
import pmb_test
|
|
|
|
import pmb_test.const
|
2017-10-30 19:56:38 +00:00
|
|
|
import pmb.aportgen.device
|
|
|
|
import pmb.config
|
|
|
|
import pmb.config.init
|
|
|
|
import pmb.helpers.logging
|
2021-10-22 10:51:21 +00:00
|
|
|
import pmb.parse.deviceinfo
|
2017-10-30 19:56:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def args(tmpdir, request):
|
|
|
|
import pmb.parse
|
2020-04-09 18:48:21 +00:00
|
|
|
cfg = f"{pmb_test.const.testdata}/channels.cfg"
|
|
|
|
sys.argv = ["pmbootstrap.py", "--config-channels", cfg, "init"]
|
2017-10-30 19:56:38 +00:00
|
|
|
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)
|
2017-10-30 19:56:38 +00:00
|
|
|
return args
|
|
|
|
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
def fake_answers(monkeypatch, answers):
|
|
|
|
"""
|
|
|
|
Patch pmb.helpers.cli.ask() function to return defined answers instead of
|
|
|
|
asking the user for an answer.
|
|
|
|
|
|
|
|
:param answers: list of answer strings, e.g. ["y", "n", "invalid-device"].
|
|
|
|
In this example, the first question is answered with "y",
|
|
|
|
the second question with "n" and so on.
|
|
|
|
"""
|
2021-09-20 10:00:13 +00:00
|
|
|
def fake_ask(question="Continue?", choices=["y", "n"], default="n",
|
2020-02-18 15:00:37 +00:00
|
|
|
lowercase_answer=True, validation_regex=None, complete=None):
|
2017-10-30 19:56:38 +00:00
|
|
|
answer = answers.pop(0)
|
2018-02-24 21:49:10 +00:00
|
|
|
logging.info("pmb.helpers.cli.ask() fake answer: " + answer)
|
2017-10-30 19:56:38 +00:00
|
|
|
return answer
|
|
|
|
monkeypatch.setattr(pmb.helpers.cli, "ask", fake_ask)
|
|
|
|
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
def test_fake_answers_selftest(monkeypatch):
|
|
|
|
fake_answers(monkeypatch, ["first", "second"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert pmb.helpers.cli.ask() == "first"
|
|
|
|
assert pmb.helpers.cli.ask() == "second"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
def test_questions_booleans(args, monkeypatch):
|
2017-10-30 19:56:38 +00:00
|
|
|
functions = [pmb.aportgen.device.ask_for_keyboard,
|
|
|
|
pmb.aportgen.device.ask_for_external_storage]
|
|
|
|
for func in functions:
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["y", "n"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert func(args) is True
|
|
|
|
assert func(args) is False
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
def test_questions_strings(args, monkeypatch):
|
2018-08-23 00:44:46 +00:00
|
|
|
functions = [pmb.aportgen.device.ask_for_manufacturer]
|
2017-10-30 19:56:38 +00:00
|
|
|
for func in functions:
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["Simple string answer"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert func() == "Simple string answer"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
|
|
|
|
2018-08-23 00:44:46 +00:00
|
|
|
def test_questions_name(args, monkeypatch):
|
|
|
|
func = pmb.aportgen.device.ask_for_name
|
|
|
|
|
|
|
|
# Manufacturer should get added automatically, but not twice
|
|
|
|
fake_answers(monkeypatch, ["Amazon Thor"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert func("Amazon") == "Amazon Thor"
|
2018-08-23 00:44:46 +00:00
|
|
|
fake_answers(monkeypatch, ["Thor"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert func("Amazon") == "Amazon Thor"
|
2018-08-23 00:44:46 +00:00
|
|
|
|
|
|
|
# Don't add the manufacturer when it starts with "Google"
|
|
|
|
fake_answers(monkeypatch, ["Google Nexus 12345"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert func("Amazon") == "Google Nexus 12345"
|
2018-08-23 00:44:46 +00:00
|
|
|
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
def test_questions_arch(args, monkeypatch):
|
|
|
|
fake_answers(monkeypatch, ["invalid_arch", "aarch64"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert pmb.aportgen.device.ask_for_architecture() == "aarch64"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
def test_questions_bootimg(args, monkeypatch):
|
2017-11-19 14:35:23 +00:00
|
|
|
func = pmb.aportgen.device.ask_for_bootimg
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["invalid_path", ""])
|
2017-11-19 14:35:23 +00:00
|
|
|
assert func(args) is None
|
|
|
|
|
2020-02-20 19:14:38 +00:00
|
|
|
bootimg_path = pmb_test.const.testdata + "/bootimg/normal-boot.img"
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, [bootimg_path])
|
2017-11-19 14:35:23 +00:00
|
|
|
output = {"base": "0x80000000",
|
|
|
|
"kernel_offset": "0x00008000",
|
|
|
|
"ramdisk_offset": "0x04000000",
|
|
|
|
"second_offset": "0x00f00000",
|
|
|
|
"tags_offset": "0x0e000000",
|
|
|
|
"pagesize": "2048",
|
|
|
|
"cmdline": "bootopt=64S3,32S1,32S1",
|
2019-10-25 15:07:08 +00:00
|
|
|
"qcdt": "false",
|
2020-07-05 19:42:54 +00:00
|
|
|
"mtk_mkimage": "false",
|
2019-10-25 15:07:08 +00:00
|
|
|
"dtb_second": "false"}
|
2017-11-19 14:35:23 +00:00
|
|
|
assert func(args) == output
|
|
|
|
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
def test_questions_device(args, monkeypatch):
|
|
|
|
# Prepare 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
|
|
|
args.device = "lg-mako"
|
|
|
|
args.nonfree_firmware = True
|
|
|
|
args.nonfree_userland = False
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
args.kernel = "downstream"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
# Do not generate aports
|
|
|
|
def fake_generate(args, pkgname):
|
|
|
|
return
|
|
|
|
monkeypatch.setattr(pmb.aportgen, "generate", fake_generate)
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
# Existing device (without non-free components so we have defaults there)
|
|
|
|
func = pmb.config.init.ask_for_device
|
|
|
|
nonfree = {"firmware": True, "userland": False}
|
2019-10-13 14:09:32 +00:00
|
|
|
fake_answers(monkeypatch, ["lg", "mako"])
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
kernel = args.kernel
|
|
|
|
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
2018-02-24 21:49:10 +00:00
|
|
|
|
2019-10-13 14:09:32 +00:00
|
|
|
# Non-existing vendor, go back, existing vendor+device
|
|
|
|
fake_answers(monkeypatch, ["whoops", "n", "lg", "mako"])
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
2018-02-24 21:49:10 +00:00
|
|
|
|
2019-10-13 14:09:32 +00:00
|
|
|
# Existing vendor, new device, go back, existing vendor+device
|
|
|
|
fake_answers(monkeypatch, ["lg", "nonexistent", "n", "lg", "mako"])
|
|
|
|
assert func(args) == ("lg-mako", True, kernel, nonfree)
|
|
|
|
|
|
|
|
# New vendor and new device (new port)
|
|
|
|
fake_answers(monkeypatch, ["new", "y", "device", "y"])
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
assert func(args) == ("new-device", False, kernel, nonfree)
|
|
|
|
|
2019-10-13 14:09:32 +00:00
|
|
|
# Existing vendor, new device (new port)
|
|
|
|
fake_answers(monkeypatch, ["lg", "nonexistent", "y"])
|
|
|
|
assert func(args) == ("lg-nonexistent", False, kernel, nonfree)
|
|
|
|
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
|
|
|
|
def test_questions_device_kernel(args, monkeypatch):
|
|
|
|
# Prepare args
|
2020-02-20 19:14:38 +00:00
|
|
|
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363)
* As discussed in IRC/matrix, we're removing `linux-postmarketos-lts`
for now. The kernel isn't used right now, and we save lots of
maintenance effort with not updating it every week or so.
* new config option `"kernel"` with possible values:
`"downstream", "mainline", "stable"` (downstream is always
`linux-$devicename`)
* ask for the kernel during `pmbootstrap init` if the device package
has kernel subpackages and install it in `_install.py`
* postmarketos-mkinitfs: display note instead of exit with error when
the `deviceinfo_dtb` file is missing (because we expect it to be
missing for downstream kernels)
* device-sony-amami:
* add kernel subpackages for downstream, mainline
* set `deviceinfo_dtb`
* device-qemu-amd64: add kernel subpackages for stable, lts, mainline
* test cases and test data for new functions
* test case that checks all aports for right usage of the feature:
* don't mix specifying kernels in depends *and* subpackages
* 1 kernel in depends is maximum
* kernel subpackages must have a valid name
* Test if devices packages reference at least one kernel
* Remove `_build_device_depends_note()` which informs the user that
`--ignore-depends` can be used with device packages to avoid building
the kernel. The idea was to make the transition easier after a change
we did months ago, and now the kernel doesn't always get built before
building the device package so it's not relevant anymore.
* pmb/chroot/other.py:
* Add autoinstall=True to kernel_flavors_installed(). When the flag
is set, the function makes sure that at least one kernel for the
device is installed.
* Remove kernel_flavor_autodetect() function, wherever it was used,
it has been replaced with kernel_flavors_installed()[0].
* pmb.helpers.frontend.py: remove code to install at least one kernel,
kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
|
|
|
args.kernel = "downstream"
|
|
|
|
|
|
|
|
# Kernel hardcoded in depends
|
|
|
|
func = pmb.config.init.ask_for_device_kernel
|
|
|
|
device = "lg-mako"
|
|
|
|
assert func(args, device) == args.kernel
|
|
|
|
|
|
|
|
# Choose "mainline"
|
|
|
|
device = "sony-amami"
|
|
|
|
fake_answers(monkeypatch, ["mainline"])
|
|
|
|
assert func(args, device) == "mainline"
|
|
|
|
|
|
|
|
# Choose "downstream"
|
|
|
|
fake_answers(monkeypatch, ["downstream"])
|
|
|
|
assert func(args, device) == "downstream"
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_questions_device_nonfree(args, monkeypatch):
|
|
|
|
# Prepare 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
|
|
|
args.nonfree_firmware = False
|
|
|
|
args.nonfree_userland = False
|
|
|
|
|
|
|
|
# APKBUILD with firmware and userland (all yes)
|
|
|
|
func = pmb.config.init.ask_for_device_nonfree
|
|
|
|
device = "nonfree-firmware-and-userland"
|
|
|
|
fake_answers(monkeypatch, ["y", "y"])
|
|
|
|
nonfree = {"firmware": True, "userland": True}
|
|
|
|
assert func(args, device) == nonfree
|
|
|
|
|
|
|
|
# APKBUILD with firmware and userland (all no)
|
|
|
|
fake_answers(monkeypatch, ["n", "n"])
|
|
|
|
nonfree = {"firmware": False, "userland": False}
|
|
|
|
assert func(args, device) == nonfree
|
|
|
|
|
|
|
|
# APKBUILD with firmware only
|
|
|
|
func = pmb.config.init.ask_for_device_nonfree
|
|
|
|
device = "nonfree-firmware"
|
|
|
|
fake_answers(monkeypatch, ["y"])
|
|
|
|
nonfree = {"firmware": True, "userland": False}
|
|
|
|
assert func(args, device) == nonfree
|
|
|
|
|
|
|
|
# APKBUILD with userland only
|
|
|
|
func = pmb.config.init.ask_for_device_nonfree
|
|
|
|
device = "nonfree-userland"
|
|
|
|
fake_answers(monkeypatch, ["y"])
|
|
|
|
nonfree = {"firmware": False, "userland": True}
|
|
|
|
assert func(args, device) == nonfree
|
|
|
|
|
|
|
|
|
|
|
|
def test_questions_flash_methods(args, monkeypatch):
|
2017-10-30 19:56:38 +00:00
|
|
|
func = pmb.aportgen.device.ask_for_flash_method
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["invalid_flash_method", "fastboot"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert func() == "fastboot"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["0xffff"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert func() == "0xffff"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["heimdall", "invalid_type", "isorec"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert func() == "heimdall-isorec"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["heimdall", "bootimg"])
|
2021-09-20 10:00:13 +00:00
|
|
|
assert func() == "heimdall-bootimg"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
def test_questions_keymaps(args, monkeypatch):
|
2017-10-30 19:56:38 +00:00
|
|
|
func = pmb.config.init.ask_for_keymaps
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["invalid_keymap", "us/rx51_us"])
|
2021-10-22 10:51:21 +00:00
|
|
|
assert func(args, pmb.parse.deviceinfo(args, "nokia-n900")) == "us/rx51_us"
|
|
|
|
assert func(args, pmb.parse.deviceinfo(args, "lg-mako")) == ""
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
def test_questions_ui(args, monkeypatch):
|
2020-04-11 18:22:06 +00:00
|
|
|
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
2020-05-14 10:20:11 +00:00
|
|
|
device = "lg-mako"
|
2021-10-22 10:51:21 +00:00
|
|
|
info = pmb.parse.deviceinfo(args, device)
|
2020-04-11 18:22:06 +00:00
|
|
|
|
2020-04-11 18:23:33 +00:00
|
|
|
fake_answers(monkeypatch, ["none"])
|
2021-10-22 10:51:21 +00:00
|
|
|
assert pmb.config.init.ask_for_ui(args, info) == "none"
|
2020-04-11 18:23:33 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["invalid_UI", "weston"])
|
2021-10-22 10:51:21 +00:00
|
|
|
assert pmb.config.init.ask_for_ui(args, info) == "weston"
|
2017-10-30 19:56:38 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
2020-04-11 18:28:17 +00:00
|
|
|
def test_questions_ui_extras(args, monkeypatch):
|
|
|
|
args.aports = pmb_test.const.testdata + "/init_questions_device/aports"
|
|
|
|
assert not pmb.config.init.ask_for_ui_extras(args, "none")
|
|
|
|
|
|
|
|
fake_answers(monkeypatch, ["n"])
|
|
|
|
assert not pmb.config.init.ask_for_ui_extras(args, "weston")
|
|
|
|
|
|
|
|
fake_answers(monkeypatch, ["y"])
|
|
|
|
assert pmb.config.init.ask_for_ui_extras(args, "weston")
|
|
|
|
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
def test_questions_work_path(args, monkeypatch, tmpdir):
|
2018-09-05 05:57:38 +00:00
|
|
|
# Existing paths (triggering various errors)
|
|
|
|
func = pmb.config.init.ask_for_work_path
|
2017-10-30 19:56:38 +00:00
|
|
|
tmpdir = str(tmpdir)
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["/dev/null", os.path.dirname(__file__),
|
|
|
|
pmb.config.pmb_src, tmpdir])
|
2018-09-05 05:57:38 +00:00
|
|
|
assert func(args) == (tmpdir, True)
|
|
|
|
|
|
|
|
# Non-existing path
|
|
|
|
work = tmpdir + "/non_existing_subfolder"
|
|
|
|
fake_answers(monkeypatch, [work])
|
|
|
|
assert func(args) == (work, False)
|
2017-12-21 16:42:29 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
2020-06-02 07:52:54 +00:00
|
|
|
def test_questions_additional_options(args, monkeypatch):
|
|
|
|
func = pmb.config.init.ask_for_additional_options
|
2017-12-21 16:42:29 +00:00
|
|
|
cfg = {"pmbootstrap": {}}
|
|
|
|
|
|
|
|
# Skip changing anything
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["n"])
|
2017-12-21 16:42:29 +00:00
|
|
|
func(args, cfg)
|
|
|
|
assert cfg == {"pmbootstrap": {}}
|
|
|
|
|
|
|
|
# Answer everything
|
2021-03-17 17:09:59 +00:00
|
|
|
fake_answers(monkeypatch, ["y", "128", "64", "5", "2G", "n", "y", "1",
|
|
|
|
"n"])
|
2017-12-21 16:42:29 +00:00
|
|
|
func(args, cfg)
|
2021-03-17 17:09:59 +00:00
|
|
|
mirror = pmb.config.defaults["mirrors_postmarketos"]
|
2020-11-15 16:19:25 +00:00
|
|
|
assert cfg == {"pmbootstrap": {"extra_space": "128",
|
|
|
|
"boot_size": "64",
|
2020-04-28 07:04:31 +00:00
|
|
|
"jobs": "5",
|
2020-11-30 13:08:29 +00:00
|
|
|
"ccache_size": "2G",
|
2021-03-17 17:09:59 +00:00
|
|
|
"sudo_timer": "False",
|
|
|
|
"mirrors_postmarketos": mirror}}
|
2018-03-17 18:41:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_questions_hostname(args, monkeypatch):
|
|
|
|
func = pmb.config.init.ask_for_hostname
|
|
|
|
device = "test-device"
|
|
|
|
|
|
|
|
# Valid hostname
|
|
|
|
fake_answers(monkeypatch, ["valid"])
|
|
|
|
assert func(args, device) == "valid"
|
|
|
|
|
|
|
|
# Hostname too long ("aaaaa...")
|
|
|
|
fake_answers(monkeypatch, ["a" * 64, "a" * 63])
|
|
|
|
assert func(args, device) == "a" * 63
|
|
|
|
|
|
|
|
# Fail the regex
|
|
|
|
fake_answers(monkeypatch, ["$invalid", "valid"])
|
|
|
|
assert func(args, device) == "valid"
|
|
|
|
|
|
|
|
# Begins or ends with minus
|
|
|
|
fake_answers(monkeypatch, ["-invalid", "invalid-", "valid"])
|
|
|
|
assert func(args, device) == "valid"
|
|
|
|
|
|
|
|
# Device name: empty string
|
|
|
|
fake_answers(monkeypatch, [device])
|
|
|
|
assert func(args, device) == ""
|
2020-04-09 18:48:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_questions_channel(args, monkeypatch):
|
2021-03-02 18:47:58 +00:00
|
|
|
fake_answers(monkeypatch, ["invalid-channel", "v20.05"])
|
|
|
|
assert pmb.config.init.ask_for_channel(args) == "v20.05"
|