mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
72 lines
3.0 KiB
Python
72 lines
3.0 KiB
Python
import json
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import unittest
|
|
|
|
|
|
SERVICE = Path(__file__).resolve().parents[2] / (
|
|
"app/src/main/java/com/droiddeck/launcher/session/SessionService.kt")
|
|
|
|
VARIANTS = Path(__file__).resolve().parents[1] / "release/variants.txt"
|
|
PACKAGES = [line.split()[1] for line in VARIANTS.read_text().splitlines()
|
|
if line.strip() and not line.startswith("#")]
|
|
|
|
|
|
def guest_prefix(package):
|
|
source = SERVICE.read_text()
|
|
before_environment = source.split("val guest = ArrayList<String>()", 1)[1].split(
|
|
"addClientEnvironment(guest,", 1)[0]
|
|
environment = source.split("private fun addClientEnvironment(", 1)[1].split(
|
|
'guest.add("HOME=/root")', 1)[0]
|
|
prefix = []
|
|
for line in (before_environment + environment).splitlines():
|
|
line = line.strip()
|
|
if not line.startswith("guest.add("):
|
|
continue
|
|
expression = line[len("guest.add("):-1]
|
|
match = re.fullmatch(r'("[^"\\]*")(?: \+ (.+))?', expression)
|
|
if match is None:
|
|
raise AssertionError("Launch prefix changed; update its regression harness: " + line)
|
|
value = json.loads(match[1])
|
|
if match[2]:
|
|
if match[2] != "com.droiddeck.launcher.runtime.BwrapSpawner.socket(this)":
|
|
raise AssertionError("Unexpected dynamic launch-prefix argument: " + line)
|
|
value += package + ".bwrap"
|
|
prefix.append(value)
|
|
return prefix
|
|
|
|
|
|
def client_environment():
|
|
body = SERVICE.read_text().split("private fun addClientEnvironment(", 1)[1].split("\n private fun ", 1)[0]
|
|
return [line.strip() for line in body.splitlines()]
|
|
|
|
|
|
class SessionGuestCommandTest(unittest.TestCase):
|
|
def test_env_is_the_executable_for_every_package(self):
|
|
for package in PACKAGES:
|
|
with self.subTest(package=package):
|
|
self.assertEqual(["/usr/bin/env", "-i"], guest_prefix(package)[:2])
|
|
|
|
@unittest.skipUnless(Path("/usr/bin/env").is_file(), "needs /usr/bin/env")
|
|
def test_child_receives_its_package_socket_after_environment_is_cleared(self):
|
|
for package in PACKAGES:
|
|
with self.subTest(package=package):
|
|
result = subprocess.run(
|
|
guest_prefix(package), capture_output=True, text=True, check=True,
|
|
timeout=5, env={"DROIDDECK_BWRAP_SOCKET": "wrong.bwrap", "STALE_HOST": "1"})
|
|
self.assertEqual(
|
|
["DROIDDECK_BWRAP_SOCKET=" + package + ".bwrap"],
|
|
result.stdout.splitlines())
|
|
|
|
def test_wine_gets_the_android_zone_without_putting_tz_in_the_windows_environment(self):
|
|
lines = client_environment()
|
|
zone = lines.index("val timeZone = java.util.TimeZone.getDefault().id")
|
|
self.assertEqual(['guest.add("TZ=$timeZone")', 'guest.add("WINE_HOST_TZ=$timeZone")'],
|
|
lines[zone + 1:zone + 3])
|
|
self.assertEqual(1, sum(line.startswith('guest.add("TZ=') for line in lines))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|