mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
test: cover native-only launches
This commit is contained in:
1 parent
57ce8e8534
commit
14afdbb880
4 files changed
+35
-56
No files matched your search
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.runtime
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@@ -13,11 +14,13 @@ class NativeGuestTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRuntimeStillToBeInstalledRunsTheNextSessionNatively() {
|
||||
val empty = Files.createTempDirectory("native-root").toFile()
|
||||
assertTrue(NativeGuest.willRun(empty, installed = false))
|
||||
assertEquals(false, NativeGuest.willRun(empty, installed = true))
|
||||
assertTrue(NativeGuest.willRun(rootWithLoader(), installed = true))
|
||||
fun anInstalledRuntimeNeedsBothTheLoaderAndTheHook() {
|
||||
val root = rootWithLoader()
|
||||
assertFalse(NativeGuest.available(root))
|
||||
NativeGuest.hook(root).writeText("")
|
||||
assertTrue(NativeGuest.available(root))
|
||||
File(root, "usr/lib/ld-linux-aarch64.so.1").delete()
|
||||
assertFalse(NativeGuest.available(root))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -236,9 +236,8 @@ class AntiCheatRoutingTest(unittest.TestCase):
|
||||
launcher = COMPAT["LAUNCHER_SH"]
|
||||
self.assertLess(launcher.index('dd_anticheat "$@"'), launcher.index('dd_components "$depot"'))
|
||||
wrapper = COMPAT["extra_wrapper_sh"]("proton")
|
||||
self.assertLess(wrapper.index("dd_x86_64_proton() {"), wrapper.index("dd_fallback="))
|
||||
self.assertLess(wrapper.index("dd_x86_64_proton() {"), wrapper.index('if dd_x86_64_proton "$here"'))
|
||||
self.assertLess(wrapper.index('droiddeck-fex proton "$here/proton"'), wrapper.index('dd_components "$here"'))
|
||||
self.assertIn('! dd_x86_64_proton "$d"', wrapper)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -10,7 +10,6 @@ from pathlib import Path
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
SESSION = BIN / "droiddeck-session"
|
||||
EXEC = BIN / "droiddeck-appimage-exec"
|
||||
URUNTIME = "/usr/local/lib/droiddeck/uruntime"
|
||||
FEX = "/usr/local/bin/droiddeck-fex"
|
||||
REPORT = "#!/bin/sh\nprintf '%%s\\n' \"TARGET=${TARGET_APPIMAGE:-} EXTRACT=${APPIMAGE_EXTRACT_AND_RUN:-}\" %s \"$@\"\n"
|
||||
|
||||
@@ -26,7 +25,7 @@ class AppImageExecTest(unittest.TestCase):
|
||||
self.addCleanup(shutil.rmtree, self.dir, True)
|
||||
self.image = self.dir / "rpcs3.AppImage"
|
||||
self.machine(183)
|
||||
self.uruntime = self.tool("uruntime", "uruntime")
|
||||
self.cache = self.dir / "cache"
|
||||
self.fex = self.tool("droiddeck-fex", "fex")
|
||||
|
||||
def machine(self, number):
|
||||
@@ -40,17 +39,14 @@ class AppImageExecTest(unittest.TestCase):
|
||||
|
||||
def launch(self, **extra):
|
||||
script = self.dir / "exec"
|
||||
script.write_text(EXEC.read_text().replace(URUNTIME, str(self.uruntime)).replace(FEX, str(self.fex)))
|
||||
script.write_text(EXEC.read_text().replace(FEX, str(self.fex)))
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("TARGET_APPIMAGE", "APPIMAGE_EXTRACT_AND_RUN", "DDNATV_ROOT")}
|
||||
env["XDG_CACHE_HOME"] = str(self.cache)
|
||||
env.update(extra)
|
||||
return subprocess.run(["bash", str(script), str(self.image), "--no-gui"], env=env,
|
||||
capture_output=True, text=True, timeout=30).stdout.splitlines()
|
||||
|
||||
def native(self, **extra):
|
||||
return self.launch(DDNATV_ROOT=str(self.dir / "rootfs"), XDG_CACHE_HOME=str(self.cache), **extra)
|
||||
|
||||
def unpacker(self, works=True, apprun=None):
|
||||
self.cache = self.dir / "cache"
|
||||
self.unpacks = self.dir / "unpacks"
|
||||
apprun = apprun or "#!/bin/sh\nprintf '%s\\n' \"APPIMAGE=$APPIMAGE APPDIR=$APPDIR TARGET=${TARGET_APPIMAGE:-}\" apprun \"$@\"\n"
|
||||
self.fex.write_text(
|
||||
@@ -60,49 +56,36 @@ class AppImageExecTest(unittest.TestCase):
|
||||
def unpacked_dirs(self):
|
||||
return [d for d in self.cache.glob("droiddeck-appimage/*") if d.is_dir()]
|
||||
|
||||
def test_an_arm64_image_runs_through_the_shipped_runtime(self):
|
||||
self.assertEqual(["TARGET=%s EXTRACT=1" % self.image, "uruntime", "--no-gui"], self.launch())
|
||||
|
||||
def test_without_the_shipped_runtime_the_image_runs_itself(self):
|
||||
self.uruntime.unlink()
|
||||
self.image.write_text(REPORT % "own")
|
||||
self.assertEqual(["TARGET= EXTRACT=1", "own", "--no-gui"], self.launch())
|
||||
|
||||
def test_an_x86_image_still_starts_under_fex(self):
|
||||
self.machine(62)
|
||||
self.assertEqual(["TARGET= EXTRACT=1", "fex", "run", "--mode", "on", "--", str(self.image), "--no-gui"], self.launch())
|
||||
|
||||
def test_an_x86_image_without_fex_uses_the_shipped_runtime(self):
|
||||
self.machine(62)
|
||||
self.fex.unlink()
|
||||
self.assertEqual(["TARGET=%s EXTRACT=1" % self.image, "uruntime", "--no-gui"], self.launch())
|
||||
|
||||
def test_an_arm64_image_is_unpacked_once_and_runs_from_its_apprun(self):
|
||||
self.unpacker()
|
||||
expected = ["== appimage: unpacking %s" % self.image]
|
||||
ran = ["APPIMAGE=%s APPDIR=%s/squashfs-root TARGET=" % (self.image, "%s"), "apprun", "--no-gui"]
|
||||
first = self.native()
|
||||
first = self.launch()
|
||||
self.assertEqual(expected, first[:1])
|
||||
[unpacked] = self.unpacked_dirs()
|
||||
ran[0] = ran[0] % unpacked
|
||||
self.assertEqual(ran, first[1:])
|
||||
self.assertEqual(ran, self.native())
|
||||
self.assertEqual(ran, self.launch())
|
||||
self.assertEqual([str(self.image)], self.unpacks.read_text().splitlines())
|
||||
|
||||
def test_a_changed_image_is_unpacked_again(self):
|
||||
self.unpacker()
|
||||
self.native()
|
||||
self.launch()
|
||||
os.utime(self.image, (1, 1))
|
||||
self.assertEqual("apprun", self.native()[2])
|
||||
self.assertEqual("apprun", self.launch()[2])
|
||||
self.assertEqual(2, len(self.unpacks.read_text().splitlines()))
|
||||
self.assertEqual(1, len(self.unpacked_dirs()))
|
||||
|
||||
def test_a_same_size_change_within_one_second_is_unpacked_again(self):
|
||||
self.unpacker()
|
||||
os.utime(self.image, ns=(1_000_000_100_000_000, 1_000_000_100_000_000))
|
||||
self.native()
|
||||
self.launch()
|
||||
os.utime(self.image, ns=(1_000_000_900_000_000, 1_000_000_900_000_000))
|
||||
self.assertEqual("apprun", self.native()[2])
|
||||
self.assertEqual("apprun", self.launch()[2])
|
||||
self.assertEqual(2, len(self.unpacks.read_text().splitlines()))
|
||||
self.assertEqual(1, len(self.unpacked_dirs()))
|
||||
|
||||
@@ -114,32 +97,32 @@ class AppImageExecTest(unittest.TestCase):
|
||||
|
||||
def test_a_running_copy_survives_an_update_until_it_exits(self):
|
||||
self.unpacker()
|
||||
self.native()
|
||||
self.launch()
|
||||
[old] = self.unpacked_dirs()
|
||||
running = self.hold(old)
|
||||
os.utime(self.image, (1, 1))
|
||||
self.assertEqual("apprun", self.native()[2])
|
||||
self.assertEqual("apprun", self.launch()[2])
|
||||
self.assertTrue((old / "squashfs-root/AppRun").exists())
|
||||
[new] = [d for d in self.unpacked_dirs() if d != old]
|
||||
running.close()
|
||||
self.assertEqual("apprun", self.native()[1])
|
||||
self.assertEqual("apprun", self.launch()[1])
|
||||
self.assertEqual([new], self.unpacked_dirs())
|
||||
|
||||
def test_a_running_copy_of_a_removed_image_is_kept(self):
|
||||
self.unpacker()
|
||||
self.native()
|
||||
self.launch()
|
||||
[old] = self.unpacked_dirs()
|
||||
self.hold(old)
|
||||
self.image.unlink()
|
||||
self.image = self.dir / "dolphin.AppImage"
|
||||
self.machine(183)
|
||||
self.native()
|
||||
self.launch()
|
||||
self.assertTrue((old / "squashfs-root/AppRun").exists())
|
||||
self.assertEqual(2, len(self.unpacked_dirs()))
|
||||
|
||||
def test_the_running_application_holds_its_copy(self):
|
||||
self.unpacker(apprun="#!/bin/sh\nflock -n -x \"$APPDIR/../source\" true && echo free || echo held\n")
|
||||
self.assertEqual(["held"], self.native()[1:])
|
||||
self.assertEqual(["held"], self.launch()[1:])
|
||||
|
||||
def test_nothing_runs_when_the_cache_cannot_be_locked(self):
|
||||
self.unpacker()
|
||||
@@ -147,17 +130,17 @@ class AppImageExecTest(unittest.TestCase):
|
||||
tools.mkdir()
|
||||
(tools / "flock").write_text("#!/bin/sh\nexit 1\n")
|
||||
(tools / "flock").chmod(0o755)
|
||||
self.assertEqual([], self.native(PATH="%s:%s" % (tools, os.environ["PATH"])))
|
||||
self.assertEqual([], self.launch(PATH="%s:%s" % (tools, os.environ["PATH"])))
|
||||
self.assertFalse(self.unpacks.exists())
|
||||
|
||||
def test_the_unpacked_copy_of_a_removed_image_is_dropped(self):
|
||||
self.unpacker()
|
||||
self.native()
|
||||
self.launch()
|
||||
[old] = self.unpacked_dirs()
|
||||
self.image.unlink()
|
||||
self.image = self.dir / "dolphin.AppImage"
|
||||
self.machine(183)
|
||||
self.native()
|
||||
self.launch()
|
||||
self.assertFalse(old.exists())
|
||||
self.assertEqual(1, len(self.unpacked_dirs()))
|
||||
|
||||
@@ -170,23 +153,18 @@ class AppImageExecTest(unittest.TestCase):
|
||||
link = self.cache / "droiddeck-appimage" / "linked"
|
||||
link.parent.mkdir(parents=True)
|
||||
link.symlink_to(outside, target_is_directory=True)
|
||||
self.assertEqual("apprun", self.native()[2])
|
||||
self.assertEqual("apprun", self.launch()[2])
|
||||
self.assertTrue(link.is_symlink())
|
||||
self.assertEqual("data", (outside / "keep").read_text())
|
||||
|
||||
def test_an_image_that_cannot_be_unpacked_runs_nothing(self):
|
||||
self.unpacker(works=False)
|
||||
out = self.native()
|
||||
out = self.launch()
|
||||
self.assertNotIn("uruntime", out)
|
||||
self.assertNotIn("apprun", out)
|
||||
self.assertEqual([], self.unpacked_dirs())
|
||||
self.assertEqual([], list(self.cache.glob("droiddeck-appimage/.unpack.*")))
|
||||
|
||||
def test_an_x86_image_still_starts_under_fex(self):
|
||||
self.machine(62)
|
||||
self.cache = self.dir / "cache"
|
||||
self.assertEqual(["TARGET= EXTRACT=1", "fex", "run", "--mode", "on", "--", str(self.image), "--no-gui"], self.native())
|
||||
|
||||
def test_the_session_starts_images_through_the_shared_launcher(self):
|
||||
script = ("set -u\n"
|
||||
"run_program() { printf '%%s\\n' \"$@\"; exit 0; }\n"
|
||||
|
||||
@@ -40,8 +40,8 @@ artifact; distribute corresponding sources with published binaries.
|
||||
|
||||
`droiddeck-credential-fallback.patch` names the reason when the backend cannot reach the
|
||||
app's credential socket (`NEXUS_CREDENTIAL_ERROR_V1 socket-refused`, `-denied`, ...) and then
|
||||
uses a keyed loopback port the app also listens on; some devices refuse the abstract socket
|
||||
from inside PRoot. The key is passed in the backend's environment only.
|
||||
uses a keyed loopback port the app also listens on. The key is passed in the backend's
|
||||
environment only.
|
||||
|
||||
`droiddeck-licensing-device-ticket.patch` sends a delegation-compact device ticket to content
|
||||
licensing in the licensing wire form (`t=` or a bare compact JWE), as user tickets already are;
|
||||
@@ -65,11 +65,10 @@ write using its existing Keystore cipher, verifies backend read-backs, and
|
||||
rejects writes when Keystore is unavailable. No token values enter process
|
||||
arguments, external storage, application logs or a plaintext credential file.
|
||||
Account-generation invalidation prevents a signed-out child's later writes from
|
||||
restoring credentials. Each backend gets its own socket. The host checks the peer UID, the PRoot tracer
|
||||
owned by its live child, and an executable mapping of the backend file with a matching inode and
|
||||
SHA-256 against the APK asset. PRoot's loader can occupy `/proc/<pid>/exe`, so
|
||||
authentication checks the mapped backend image instead. A socket name alone grants no credential operations, including to another
|
||||
copy of Xodus started by the guest.
|
||||
restoring credentials. Each backend gets its own socket. The host checks the peer UID, ancestry under its live backend process, and an executable
|
||||
mapping of the backend file with a matching inode and SHA-256 against the APK asset.
|
||||
A socket name alone grants no credential operations, including to another copy of Xodus
|
||||
started by the guest.
|
||||
|
||||
Licensed launch-view preparation runs in an Android-owned Xodus child, which
|
||||
never starts Wine or a game. Steam and DroidDeck launch paths can request
|
||||
|
||||
Reference in new issue
Block a user