mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
121 lines
4.8 KiB
Python
121 lines
4.8 KiB
Python
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SCRIPT = ROOT / "tools/venus/build-layer.sh"
|
|
LAYER = ROOT / "tools/venus/layer"
|
|
WORKFLOW = ROOT / ".github/workflows/build.yml"
|
|
SESSION_FILES = ROOT / "app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt"
|
|
|
|
COMPILER = """#!/bin/sh
|
|
printf '%s\\n' "$@" > "$CALLS/cc"
|
|
while [ $# -gt 0 ]; do
|
|
if [ "$1" = -o ]; then printf 'layer' > "$2"; fi
|
|
shift
|
|
done
|
|
"""
|
|
|
|
STRIP = """#!/bin/sh
|
|
printf '%s\\n' "$@" > "$CALLS/strip"
|
|
"""
|
|
|
|
REFUSE = """#!/bin/sh
|
|
echo "$0 must not run" >&2
|
|
exit 1
|
|
"""
|
|
|
|
|
|
def staged_layer_paths():
|
|
text = SESSION_FILES.read_text()
|
|
start = text.index("val maliCompat")
|
|
block = text[start:text.index(".map { it to it }", start)]
|
|
return re.findall(r'"(usr/local/[^"]+)"', block)
|
|
|
|
|
|
def workflow_step(name):
|
|
text = WORKFLOW.read_text()
|
|
start = text.index(" - name: " + name)
|
|
end = text.find("\n - name: ", start + 1)
|
|
return text[start:end if end >= 0 else len(text)]
|
|
|
|
|
|
class VenusLayerBuildTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = Path(tempfile.mkdtemp(prefix="droiddeck-venus-layer-"))
|
|
self.addCleanup(shutil.rmtree, self.tmp)
|
|
self.bin = self.tmp / "bin"
|
|
self.calls = self.tmp / "calls"
|
|
self.bin.mkdir()
|
|
self.calls.mkdir()
|
|
for name, body in (("cc", COMPILER), ("strip", STRIP), ("git", REFUSE), ("curl", REFUSE)):
|
|
path = self.bin / name
|
|
path.write_text(body)
|
|
path.chmod(0o755)
|
|
|
|
def run_script(self, *args):
|
|
environment = dict(os.environ, CC=str(self.bin / "cc"), STRIP=str(self.bin / "strip"),
|
|
CALLS=str(self.calls), PATH=str(self.bin) + os.pathsep + os.environ["PATH"])
|
|
return subprocess.run(["bash", str(SCRIPT), *args], env=environment, capture_output=True, text=True)
|
|
|
|
def test_build_installs_the_layer_where_the_session_stages_it(self):
|
|
deps = self.tmp / "deps"
|
|
out = self.tmp / "linuxfs"
|
|
result = self.run_script("build", str(deps), str(out))
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
library, manifest = staged_layer_paths()
|
|
self.assertTrue((out / library).is_file())
|
|
self.assertEqual((out / manifest).read_bytes(), (LAYER / "VkLayer_droiddeck_mali_compat.json").read_bytes())
|
|
self.assertEqual(json.loads((out / manifest).read_text())["layer"]["library_path"], "/" + library)
|
|
|
|
arguments = (self.calls / "cc").read_text().splitlines()
|
|
sources = sorted(Path(a).name for a in arguments if a.endswith(".c"))
|
|
self.assertEqual(sources, sorted(p.name for p in LAYER.glob("*.c")))
|
|
for include in ("vulkan/include", "spirv/include", "bcdec"):
|
|
self.assertIn("-I" + str(deps / include), arguments)
|
|
self.assertIn(str(out / library), (self.calls / "strip").read_text().splitlines())
|
|
|
|
def test_headers_already_present_are_not_fetched_again(self):
|
|
deps = self.tmp / "deps"
|
|
for name in ("vulkan/include/vulkan/vk_layer.h", "spirv/include/spirv/unified1/spirv.h", "bcdec/bcdec.h"):
|
|
(deps / name).parent.mkdir(parents=True, exist_ok=True)
|
|
(deps / name).write_text("")
|
|
result = self.run_script("headers", str(deps))
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
def test_missing_headers_fail_the_build(self):
|
|
result = self.run_script("headers", str(self.tmp / "deps"))
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("must not run", result.stderr)
|
|
|
|
def test_wrong_arguments_print_usage(self):
|
|
for args in ((), ("build", "deps"), ("headers",), ("pack", "a", "b")):
|
|
result = self.run_script(*args)
|
|
self.assertEqual(result.returncode, 2, args)
|
|
self.assertIn("usage:", result.stderr)
|
|
|
|
def test_the_apk_takes_the_layer_from_the_tree_not_the_pinned_bundle(self):
|
|
library, manifest = staged_layer_paths()
|
|
components = workflow_step("Build the non-Adreno test additions")
|
|
self.assertIn('bash tools/venus/build-layer.sh build build/layer-deps "$D"', components)
|
|
self.assertIn("D=app/src/main/assets/linuxfs", components)
|
|
|
|
fetch = workflow_step("Fetch the Mali (Venus) component")
|
|
self.assertIn("--exclude=assets/linuxfs/" + str(Path(library).parent), fetch)
|
|
self.assertIn("--exclude=assets/linuxfs/" + manifest, fetch)
|
|
self.assertIn("test -f app/src/main/assets/linuxfs/" + library, fetch)
|
|
|
|
self.assertNotIn("/venus/layer", (ROOT / "tools/venus/ci-build.sh").read_text())
|
|
local = (ROOT / "tools/build_local.sh").read_text()
|
|
self.assertIn('bash tools/venus/build-layer.sh build build/layer-deps "$d"', local)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|