2017-10-30 19:56:38 +00:00
|
|
|
"""
|
2018-01-04 03:53:35 +00:00
|
|
|
Copyright 2018 Oliver Smith
|
2017-10-30 19:56:38 +00:00
|
|
|
|
|
|
|
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 logging
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# Import from parent directory
|
2017-11-19 14:35:23 +00:00
|
|
|
pmb_src = os.path.realpath(os.path.join(os.path.dirname(__file__) + "/.."))
|
|
|
|
sys.path.append(pmb_src)
|
2017-10-30 19:56:38 +00:00
|
|
|
import pmb.aportgen.device
|
|
|
|
import pmb.config
|
|
|
|
import pmb.config.init
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2017-10-30 19:56:38 +00:00
|
|
|
def fake_ask(args, question="Continue?", choices=["y", "n"], default="n",
|
|
|
|
lowercase_answer=True, validation_regex=None):
|
|
|
|
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"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert pmb.helpers.cli.ask(args) == "first"
|
|
|
|
assert pmb.helpers.cli.ask(args) == "second"
|
|
|
|
|
|
|
|
|
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):
|
2017-10-30 19:56:38 +00:00
|
|
|
functions = [pmb.aportgen.device.ask_for_manufacturer,
|
|
|
|
pmb.aportgen.device.ask_for_name]
|
|
|
|
for func in functions:
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["Simple string answer"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert func(args) == "Simple string answer"
|
|
|
|
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
def test_questions_arch(args, monkeypatch):
|
|
|
|
fake_answers(monkeypatch, ["invalid_arch", "aarch64"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert pmb.aportgen.device.ask_for_architecture(args) == "aarch64"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
bootimg_path = pmb_src + "/test/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",
|
|
|
|
"qcdt": "false"}
|
|
|
|
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
|
|
|
|
args.aports = pmb_src + "/test/testdata/init_questions_device/aports"
|
|
|
|
args.device = "lg-mako"
|
|
|
|
args.nonfree_firmware = True
|
|
|
|
args.nonfree_userland = False
|
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}
|
|
|
|
fake_answers(monkeypatch, ["lg-mako"])
|
|
|
|
assert func(args) == ("lg-mako", True, nonfree)
|
|
|
|
|
|
|
|
# Non-existing device, go back, existing device
|
|
|
|
fake_answers(monkeypatch, ["whoops-typo", "n", "lg-mako"])
|
|
|
|
assert func(args) == ("lg-mako", True, nonfree)
|
|
|
|
|
|
|
|
# New device
|
|
|
|
fake_answers(monkeypatch, ["new-device", "y"])
|
|
|
|
assert func(args) == ("new-device", False, nonfree)
|
|
|
|
|
|
|
|
|
|
|
|
def test_questions_device_nonfree(args, monkeypatch):
|
|
|
|
# Prepare args
|
|
|
|
args.aports = pmb_src + "/test/testdata/init_questions_device/aports"
|
|
|
|
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"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert func(args) == "fastboot"
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["0xffff"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert func(args) == "0xffff"
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["heimdall", "invalid_type", "isorec"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert func(args) == "heimdall-isorec"
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["heimdall", "bootimg"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert func(args) == "heimdall-bootimg"
|
|
|
|
|
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"])
|
2018-01-21 15:09:38 +00:00
|
|
|
assert func(args, "nokia-n900") == "us/rx51_us"
|
2017-10-30 19:56:38 +00:00
|
|
|
assert func(args, "lg-mako") == ""
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
def test_questions_qemu_native_mesa(args, monkeypatch):
|
2018-01-08 15:18:37 +00:00
|
|
|
func = pmb.config.init.ask_for_qemu_native_mesa_driver
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["invalid_driver", "dri-swrast"])
|
2018-01-08 15:18:37 +00:00
|
|
|
assert func(args, "qemu-amd64", "x86_64") == "dri-swrast"
|
|
|
|
assert func(args, "qemu-aarch64", "x86_64") is None
|
Close #453: Support mesa-dri-virtio in Qemu (#861)
The mesa driver, which ends up in the installation image, needs to be known
before the installation is done (in other words: when running the qemu action,
it is to late as the image has already been generated). That's why one can
choose the Qemu mesa driver in `pmbootstrap init` now:
```
Device [qemu-amd64]:
Which mesa driver do you prefer for your Qemu device? Only select something other
than the default if you are having graphical problems (such as glitches).
Mesa driver (dri-swrast/dri-virtio) [dri-virtio]:
```
It is still possible to select `dri-swrast`, because `dri-virtio` may not work
in all cases, and that way we could easily debug it or experiment with other
mesa drivers (e.g. the "vmware" one, which is supported by mesa and Qemu).
Other changes:
* `pmbootstrap qemu` accepts a `--display` variable now, which passes the value
directly to `qemu`'s `display` option. It defaults to `sdl,gl=on` (@PureTryOut
reported that to work best with plasma mobile on his PC). `--display` and
`--spice` (which is still working) are mutually exclusive.
* Removed obsolete telnet port pass-through: We only use the debug telnet port
since osk-sdl has been merged.
* Add show-cursor to the Qemu command line, so it shows a cursor in X11
* Refactored the spice code (`command_spice` only returns the spice command,
because it has all necessary information already) and the spice port can be
specified on the commandline now (previously it was hardcoded in one place and
then always looked up from there).
* Start comments with capital letters.
* Keep the log on the screen a bit shorter (e.g. Qemu command is written to the
"pmbootstrap log" anyway, so there's no need to display it again).
* linux-postmarketos-stable: Adjust kernel configs
x86_64, armhf: enable as modules:
CONFIG_DRM_VIRTIO_GPU, CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_BALLOON
aarch64: all 3 options were already enabled as built-in (no change)
* Set '-vga virtio' for mesa-dri-virtio
2017-11-05 13:48:49 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
def test_questions_ui(args, monkeypatch):
|
|
|
|
fake_answers(monkeypatch, ["invalid_UI", "weston"])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert pmb.config.init.ask_for_ui(args) == "weston"
|
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
def test_questions_work_path(args, monkeypatch, tmpdir):
|
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])
|
2017-10-30 19:56:38 +00:00
|
|
|
assert pmb.config.init.ask_for_work_path(args) == tmpdir
|
2017-12-21 16:42:29 +00:00
|
|
|
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
def test_questions_build_options(args, monkeypatch):
|
2017-12-21 16:42:29 +00:00
|
|
|
func = pmb.config.init.ask_for_build_options
|
|
|
|
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
|
2018-02-24 21:49:10 +00:00
|
|
|
fake_answers(monkeypatch, ["y", "5", "2G", "n"])
|
2017-12-21 16:42:29 +00:00
|
|
|
func(args, cfg)
|
|
|
|
assert cfg == {"pmbootstrap": {"jobs": "5",
|
2018-01-28 23:27:33 +00:00
|
|
|
"ccache_size": "2G"}}
|