Merge remote-tracking branch 'droiddeck/main' into feat/malibridge

# Conflicts:
#	README.md
#	app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java
#	app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt
#	app/src/main/res/values-ar/strings.xml
#	app/src/main/res/values-b+es+419/strings.xml
#	app/src/main/res/values-bg/strings.xml
#	app/src/main/res/values-cs/strings.xml
#	app/src/main/res/values-da/strings.xml
#	app/src/main/res/values-de/strings.xml
#	app/src/main/res/values-el/strings.xml
#	app/src/main/res/values-es/strings.xml
#	app/src/main/res/values-fi/strings.xml
#	app/src/main/res/values-fr/strings.xml
#	app/src/main/res/values-hi/strings.xml
#	app/src/main/res/values-hu/strings.xml
#	app/src/main/res/values-in/strings.xml
#	app/src/main/res/values-it/strings.xml
#	app/src/main/res/values-ja/strings.xml
#	app/src/main/res/values-ko/strings.xml
#	app/src/main/res/values-ms/strings.xml
#	app/src/main/res/values-nb/strings.xml
#	app/src/main/res/values-nl/strings.xml
#	app/src/main/res/values-pl/strings.xml
#	app/src/main/res/values-pt-rPT/strings.xml
#	app/src/main/res/values-pt/strings.xml
#	app/src/main/res/values-ro/strings.xml
#	app/src/main/res/values-ru/strings.xml
#	app/src/main/res/values-sv/strings.xml
#	app/src/main/res/values-th/strings.xml
#	app/src/main/res/values-tr/strings.xml
#	app/src/main/res/values-uk/strings.xml
#	app/src/main/res/values-vi/strings.xml
#	app/src/main/res/values-zh-rCN/strings.xml
#	app/src/main/res/values-zh-rHK/strings.xml
#	app/src/main/res/values-zh-rTW/strings.xml
#	app/src/main/res/values/strings.xml
#	tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env
This commit is contained in:
maxjivi05 committed 2026-10-30 11:58:55 -04:00
commit 0a5955d6fa
731 files changed
+54131 -2491

No files matched your search

@@ -0,0 +1,110 @@
package com.droiddeck.launcher.session
import android.content.Context
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.github.luben.zstd.ZstdOutputStream
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class ComponentsRepublishTest {
private val fex = "FEXCore-2610-d2rfix28-linux.wcp"
private val scope = "2596113170"
private val dll = "files/lib/wine/aarch64-windows/libwow64fex.dll"
private lateinit var context: Context
@Before fun setUp() {
context = RuntimeEnvironment.getApplication()
File(context.filesDir, "components").deleteRecursively()
LinuxRuntime.rootDir(context).deleteRecursively()
}
@Test fun aGameFexChoiceReachesAProtonInstalledAfterIt() {
proton("DroidDeck-Proton 11-11.7", "DroidDeck-Proton-11-11.7")
packageFile()
ComponentsManager.setGameComponent(context, scope, "fex", fex)
assertEquals(setOf("DroidDeck-Proton 11-11.7"), scopedTools())
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
assertEquals(setOf("DroidDeck-Proton 11-11.7"), scopedTools())
assertTrue(ComponentsManager.republish(context))
assertEquals(setOf("DroidDeck-Proton 11-11.7", "DroidDeck-Proton 11-11.8"), scopedTools())
val row = rows().single { it[0] == scope && it[1] == "DroidDeck-Proton 11-11.8" && it[4] == dll }
assertEquals("DroidDeck-Proton-11-11.8", row[2])
assertEquals("d2rfix28 wow64", File(LinuxRuntime.rootDir(context), row[6].removePrefix("/")).readText())
assertEquals(fex, ComponentsManager.gameComponents(context, scope)["fex"])
}
@Test fun nothingIsRewrittenWhileTheToolsAreUnchanged() {
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
packageFile()
ComponentsManager.setGameComponent(context, scope, "fex", fex)
val published = launchState().readText()
val modified = launchState().lastModified()
assertFalse(ComponentsManager.republish(context))
assertEquals(published, launchState().readText())
assertEquals(modified, launchState().lastModified())
}
@Test fun anUnreadableStateLeavesThePublishedSelectionsAlone() {
proton("DroidDeck-Proton 11-11.7", "DroidDeck-Proton-11-11.7")
packageFile()
ComponentsManager.setGameComponent(context, scope, "fex", fex)
val published = launchState().readText()
val state = File(context.filesDir, "components/state.json").apply { writeText("{\"active\": ") }
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
assertFalse(ComponentsManager.republish(context))
assertEquals(published, launchState().readText())
assertEquals("{\"active\": ", state.readText())
}
@Test fun withNoSelectionsNothingIsPublished() {
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
assertFalse(ComponentsManager.republish(context))
assertFalse(launchState().exists())
}
private fun scopedTools() = rows().filter { it[0] == scope }.map { it[1] }.toSet()
private fun rows() = launchState().readLines().filter { it.isNotEmpty() }.map { it.split('\t') }
private fun launchState() = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-components/desired.tsv")
private fun proton(name: String, version: String) {
val dir = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/steamapps/common/$name")
File(dir, "files/lib/wine").mkdirs()
File(dir, "proton").writeText("#!/bin/sh\n")
File(dir, "version").writeText("1 $version\n")
File(dir, dll).apply { parentFile!!.mkdirs(); writeText("bundled FEX $version") }
}
private fun packageFile() {
val out = File(context.filesDir, "components/packages/$fex").apply { parentFile!!.mkdirs() }
val profile = JSONObject().put("type", "FEXCore-Linux").put("versionName", "2610-d2rfix28").toString().toByteArray()
val body = "d2rfix28 wow64".toByteArray()
TarArchiveOutputStream(ZstdOutputStream(out.outputStream())).use { tar ->
tar.putArchiveEntry(TarArchiveEntry("profile.json").apply { size = profile.size.toLong() })
tar.write(profile)
tar.closeArchiveEntry()
tar.putArchiveEntry(TarArchiveEntry(dll).apply { size = body.size.toLong() })
tar.write(body)
tar.closeArchiveEntry()
}
}
}
@@ -4,6 +4,7 @@ import android.content.Context
import com.droiddeck.launcher.core.GameEnvironment
import com.droiddeck.launcher.runtime.LinuxRuntime
import org.json.JSONObject
import org.junit.After
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
@@ -12,6 +13,8 @@ import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
@@ -21,10 +24,137 @@ class GameEnvironmentStoreTest {
@Before fun setUp() {
context = RuntimeEnvironment.getApplication()
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
.remove("logs")
.remove("gameDebugLogsEnabled")
.commit()
guest = File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-environment.json")
File(context.filesDir, "game-environment.json").delete()
}
@After fun tearDown() {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
.remove("logs")
.remove("gameDebugLogsEnabled")
.commit()
}
@Test fun gameDebugLogsAreOffByDefault() {
assertFalse(SessionPrefs.gameDebugLogsEnabled(context))
GameEnvironmentStore.save(context, GameEnvironment.Config())
assertFalse(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
@Test fun gameDebugLogsRequireSessionLogsAndPreserveCustomDiagnostics() {
val config = GameEnvironment.Config(shared = mapOf("PROTON_LOG" to "0", "WINEDEBUG" to "+warn"))
GameEnvironmentStore.save(context, config)
SessionPrefs.setGameDebugLogsEnabled(context, true)
var published = JSONObject(guest.readText())
assertTrue(published.getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertEquals("0", published.getJSONObject("shared").getString("PROTON_LOG"))
assertEquals("+warn", published.getJSONObject("shared").getString("WINEDEBUG"))
assertEquals(config, GameEnvironmentStore.read(context))
SessionPrefs.setLogsEnabled(context, false)
published = JSONObject(guest.readText())
assertFalse(published.getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
SessionPrefs.setLogsEnabled(context, true)
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
@Test fun failedGameDebugOptOutLeavesTheEnabledPreferenceVisible() {
assertTrue(SessionPrefs.setGameDebugLogsEnabled(context, true))
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
val guestDirectory = guest.parentFile!!
guestDirectory.deleteRecursively()
guestDirectory.parentFile!!.mkdirs()
guestDirectory.writeText("blocks the guest configuration directory\n")
try {
assertFalse(SessionPrefs.setGameDebugLogsEnabled(context, false))
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
} finally {
guestDirectory.delete()
guestDirectory.mkdirs()
GameEnvironmentStore.publish(context)
}
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
@Test fun unchangedEffectiveDiagnosticsDoNotRequireGuestPublication() {
assertFalse(SessionPrefs.gameDebugLogsEnabled(context))
val guestDirectory = guest.parentFile!!
guestDirectory.deleteRecursively()
guestDirectory.parentFile!!.mkdirs()
guestDirectory.writeText("blocks the guest configuration directory\n")
try {
assertTrue(SessionPrefs.setLogsEnabled(context, false))
assertFalse(SessionPrefs.logsEnabled(context))
} finally {
guestDirectory.delete()
guestDirectory.mkdirs()
SessionPrefs.setLogsEnabled(context, true)
GameEnvironmentStore.publish(context)
}
}
@Test fun logPreferenceUpdatesUseThePublisherLock() {
GameEnvironmentStore.publish(context)
val entered = CountDownLatch(1)
val finished = CountDownLatch(1)
lateinit var thread: Thread
synchronized(GameEnvironmentStore) {
thread = Thread {
entered.countDown()
SessionPrefs.setGameDebugLogsEnabled(context, true)
finished.countDown()
}
thread.start()
assertTrue(entered.await(5, TimeUnit.SECONDS))
assertFalse(finished.await(100, TimeUnit.MILLISECONDS))
assertFalse(SessionPrefs.gameDebugLogsEnabled(context))
assertFalse(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
assertTrue(finished.await(5, TimeUnit.SECONDS))
thread.join()
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
}
@Test fun gameDebugLogsWaitForARetainedSessionFolder() {
assertNull(SessionPaths.current())
assertTrue(SessionPaths.currentSessionLogsRetained(context))
GameEnvironmentStore.publish(context)
SessionPrefs.setLogsEnabled(context, false)
val cacheSession = SessionPaths.beginOrCurrent(context, "game-debug-logs")
try {
assertFalse(SessionPaths.currentSessionLogsRetained(context))
SessionPrefs.setLogsEnabled(context, true)
SessionPrefs.setGameDebugLogsEnabled(context, true)
assertTrue(SessionPrefs.gameDebugLogsEnabled(context))
assertFalse(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertEquals(cacheSession, SessionPaths.take())
SessionPaths.release(context, cacheSession)
val retainedSession = SessionPaths.beginOrCurrent(context, "game-debug-logs")
assertTrue(SessionPaths.currentSessionLogsRetained(context))
GameEnvironmentStore.publish(context)
assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertEquals(retainedSession, SessionPaths.current())
} finally {
SessionPaths.take()?.let { ended ->
SessionPaths.release(context, ended)
ended.deleteRecursively()
}
}
}
@Test fun savedSettingsAndPublishedSettingsPreserveUnsetsAndLiteralValues() {
val config = GameEnvironment.Config(
shared = mapOf("LITERAL" to "a=b 'quoted' $(echo test)", "EMPTY" to ""),
@@ -0,0 +1,39 @@
package com.droiddeck.launcher.session
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import org.junit.After
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class HudDefaultTest {
private lateinit var context: Context
@Before fun setUp() {
context = ApplicationProvider.getApplicationContext()
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
}
@After fun tearDown() {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun aNewInstallStartsWithTheHudOff() {
assertFalse(SessionPrefs.hudEnabled(context))
}
@Test fun aHudTheUserTurnedOnStaysOn() {
SessionPrefs.setHudEnabled(context, true)
assertTrue(SessionPrefs.hudEnabled(context))
}
@Test fun aHudTheUserTurnedOffStaysOff() {
SessionPrefs.setHudEnabled(context, false)
assertFalse(SessionPrefs.hudEnabled(context))
}
}
@@ -0,0 +1,23 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Test
class OutputPacingTest {
@Test fun phoneOutputIsUnpaced() {
assertEquals(SessionPrefs.FPS_UNPACED, SessionPrefs.compositorFpsLimit(0))
}
@Test fun sessionLimitPacesThePhone() {
assertEquals(45, SessionPrefs.compositorFpsLimit(0, 45))
}
@Test fun sessionLimitNeverExceedsTheGlassesRate() {
assertEquals(60, SessionPrefs.compositorFpsLimit(60, 90))
assertEquals(30, SessionPrefs.compositorFpsLimit(60, 30))
}
@Test fun mirroringKeepsTheGlassesRate() {
assertEquals(60, SessionPrefs.compositorFpsLimit(60))
}
}
@@ -1,18 +0,0 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Test
class PerfHudGraphTest {
@Test fun theGraphShowsOnlyFramesFromThisHudRun() {
val samples = floatArrayOf(9f, 9f, 9f, 9f, 9f, 16.7f, 33.4f, 16.6f)
assertArrayEquals(floatArrayOf(16.7f, 33.4f, 16.6f), PerfHud.recent(samples, 105, 102), 0f)
assertEquals(0, PerfHud.recent(samples, 103, 102).size)
}
@Test fun anEarlySessionShowsWhatWasShownSoFar() {
val samples = floatArrayOf(16.6f, 16.7f, 120f, 0f, 0f, 0f)
assertArrayEquals(floatArrayOf(16.6f, 16.7f, 50f), PerfHud.recent(samples, 3, 0), 0f)
}
}
@@ -1,36 +0,0 @@
package com.droiddeck.launcher.session
import android.content.Context
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class PerformanceModeTest {
private val app get() = RuntimeEnvironment.getApplication()
private val session get() = app.getSharedPreferences("session", Context.MODE_PRIVATE)
@Before fun clear() { session.edit().clear().commit() }
@Test fun offByDefaultAndPerMode() {
assertFalse(SessionPrefs.performanceMode(app, SessionService.MODE_STEAM))
SessionPrefs.setPerformanceMode(app, SessionService.MODE_STEAM, true)
assertTrue(SessionPrefs.performanceMode(app, SessionService.MODE_STEAM))
assertFalse(SessionPrefs.performanceMode(app, SessionService.MODE_DESKTOP))
}
@Test fun offKeepsDisplayAndMirrorPacing() {
assertEquals(0, SessionPrefs.compositorFpsLimit(0, false))
assertEquals(60, SessionPrefs.compositorFpsLimit(60, false))
}
@Test fun onIsUnpacedUnlessMirroring() {
assertEquals(SessionPrefs.FPS_UNPACED, SessionPrefs.compositorFpsLimit(0, true))
assertEquals(60, SessionPrefs.compositorFpsLimit(60, true))
}
}
@@ -115,6 +115,22 @@ class RumbleComponentTest {
assertFalse(pad.vibrating)
}
@Test fun quietingStopsAHeldEffectAndDropsEffectsUntilLifted() {
val pad = FakeMotors()
rumble.controllerMotors = { pad }
activeController(PAD_ID)
effect(strong = 40000, weak = 20000, ms = RumbleComponent.HOLD_MS)
rumble.quiet(true)
assertFalse(pad.vibrating)
idle(RumbleComponent.KEEPALIVE_MS * 4 + 100)
assertEquals("the keepalive restarted the motors while quiet", 1, pad.played.size)
effect(strong = 40000, weak = 20000)
assertFalse("an effect played while quiet", pad.vibrating)
rumble.quiet(false)
effect(strong = 40000, weak = 20000)
assertTrue(pad.vibrating)
}
@Test fun aHeldEffectFollowsTheGamesNewStrength() {
val pad = FakeMotors()
rumble.controllerMotors = { pad }
@@ -18,8 +18,9 @@ class SessionBackgroundPrefsTest {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun nativeIsOptInAndDoesNotChangeDesktopOrExistingPolicies() {
assertEquals(SessionPrefs.SUSPEND_MANUAL, SessionPrefs.suspendPolicy(context, "steam"))
@Test fun nativeIsTheSteamDefaultWithoutChangingOtherModesOrSavedPolicies() {
assertEquals(SessionPrefs.SUSPEND_NATIVE, SessionPrefs.suspendPolicy(context, "steam"))
assertEquals(SessionPrefs.SUSPEND_MANUAL, SessionPrefs.suspendPolicy(context, SessionService.MODE_RUN))
for (policy in listOf(SessionPrefs.SUSPEND_AUTO, SessionPrefs.SUSPEND_MANUAL, SessionPrefs.SUSPEND_NEVER,
SessionPrefs.SUSPEND_NATIVE)) {
SessionPrefs.setSuspendPolicy(context, "steam", policy)
@@ -28,6 +29,14 @@ class SessionBackgroundPrefsTest {
}
}
@Test fun automaticPipDefaultsOnAndHonorsSavedChoices() {
assertEquals(true, SessionPrefs.pipAutoEnter(context))
SessionPrefs.setPipAutoEnter(context, false)
assertEquals(false, SessionPrefs.pipAutoEnter(context))
SessionPrefs.setPipAutoEnter(context, true)
assertEquals(true, SessionPrefs.pipAutoEnter(context))
}
@Test fun directGamesUseAutoWithoutOverwritingSteamsNativeChoice() {
SessionPrefs.setSuspendPolicy(context, SessionService.MODE_STEAM, SessionPrefs.SUSPEND_NATIVE)
assertEquals(SessionPrefs.SUSPEND_AUTO, SessionPrefs.suspendPolicy(context, SessionService.MODE_RUN))
@@ -0,0 +1,121 @@
package com.droiddeck.launcher.session
import android.app.Application
import com.droiddeck.launcher.R
import com.droiddeck.launcher.SessionActivity
import com.droiddeck.launcher.gpu.GpuInfo
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.Implementation
import org.robolectric.annotation.Implements
import org.robolectric.util.ReflectionHelpers
import java.io.File
@RunWith(RobolectricTestRunner::class)
@Config(
sdk = [33], application = Application::class, qualifiers = "en-rUS",
instrumentedPackages = ["com.droiddeck.launcher.gpu.GpuInfo"],
shadows = [SessionEndHintTest.DetectedGpu::class],
)
class SessionEndHintTest {
@get:Rule val temporary = TemporaryFolder()
private lateinit var activity: SessionActivity
private var previousArchitecture: String? = null
@Before
fun setUp() {
previousArchitecture = SessionState.steamClientArch
DetectedGpu.family = GpuInfo.Family.NOT_ADRENO
activity = Robolectric.buildActivity(SessionActivity::class.java).get()
SessionState.steamClientArch = "arm64"
}
@After
fun tearDown() {
SessionState.steamClientArch = previousArchitecture
DetectedGpu.family = GpuInfo.Family.NOT_ADRENO
}
@Test
fun sigillOnArm64IncludesTheExperimentalX64Fallback() {
SessionState.steamClientArch = "arm64"
assertEquals(
activity.getString(R.string.session_end_steam_sigill) + "\n" + activity.getString(R.string.session_end_steam_try_x64),
hintText(sigillLog()),
)
}
@Test
fun sigillOnX86_64DoesNotSuggestSwitchingToItself() {
SessionState.steamClientArch = "x86_64"
assertEquals(activity.getString(R.string.session_end_steam_sigill), hintText(sigillLog()))
}
@Test
fun sigillWithUnknownArchitectureDoesNotAssumeArm64() {
SessionState.steamClientArch = null
assertEquals(activity.getString(R.string.session_end_steam_sigill), hintText(sigillLog()))
}
@Test
fun vulkanFailureOnAdrenoSelectsTheDriverHint() {
for (family in listOf(GpuInfo.Family.A6XX, GpuInfo.Family.ADRENO_UNKNOWN)) {
DetectedGpu.family = family
assertEquals(family.name, activity.getString(R.string.session_end_vulkan_device), hintText(vulkanLog()))
}
}
@Test
fun vulkanFailureOnNonAdrenoExplainsTheMissingLinuxDriver() {
DetectedGpu.family = GpuInfo.Family.NOT_ADRENO
assertEquals(activity.getString(R.string.session_end_gpu_unsupported), hintText(vulkanLog()))
}
@Test
fun missingEmptyAndUnrelatedLogsHaveNoHint() {
assertNull(hint(null))
assertNull(hint(File(temporary.root, "missing.log")))
assertNull(hint(log("")))
assertNull(hint(log("game: Illegal instruction\n== steam exited rc=132")))
}
private fun sigillLog() = log("== STEP 12:00:00 starting the Steam client\n== steam exited rc=132\n")
private fun vulkanLog() = log("[gamescope] [Error] vulkan: failed to find physical device\n")
private fun log(text: String): File = temporary.newFile().apply { writeText(text) }
private fun hint(log: File?): Any? = SessionActivity::class.java
.getDeclaredMethod("sessionEndHint", File::class.java).apply { isAccessible = true }.invoke(activity, log)
private fun hintText(log: File): String {
val result = hint(log)
assertNotNull(result)
return ReflectionHelpers.getField(result, "text")
}
@Implements(value = GpuInfo.Companion::class, isInAndroidSdk = false)
class DetectedGpu {
@Implementation
fun detect(): GpuInfo = GpuInfo("test GPU", if (family == GpuInfo.Family.A6XX) 610 else 0, family, "", false)
companion object {
var family = GpuInfo.Family.NOT_ADRENO
}
}
}
@@ -0,0 +1,54 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class SessionLaunchFailureTest {
private fun find(vararg lines: String) = SessionLaunchFailure.find(lines.asSequence())
@Test fun installedSteamThatExitsWithSigillHasACpuFailureHint() {
assertEquals(SessionLaunchFailure.STEAM_ILLEGAL_INSTRUCTION, find(
"== STEP 06:35:36.987 Steam client ready",
"== STEP 06:35:41.058 starting the Steam client",
"/usr/local/bin/droiddeck-session: line 309: 1192 Illegal instruction steam",
"== steam exited rc=132",
"(EE) failed to read Wayland events: Broken pipe",
))
}
@Test fun gamescopeWithoutAPhysicalDeviceHasAGraphicsFailureHint() {
assertEquals(SessionLaunchFailure.VULKAN_DEVICE_MISSING, find(
"[gamescope] [\u001b[0;31mError\u001b[0m] \u001b[0;37mvulkan:\u001b[0m failed to find physical device",
"SDL_Vulkan_CreateSurface failed: VK_KHR_wayland_surface extension is not enabled in the Vulkan instance.Failed to create backend.",
))
}
@Test fun unrelatedIllegalInstructionsAndExitCodesAreNotBlamedOnSteam() {
assertNull(find("game: Illegal instruction", "== steam exited rc=132"))
assertNull(find("== STEP 12:00:00 starting the Steam client", "== steam exited rc=139"))
assertNull(find("== STEP 12:00:00 starting the Steam client", "== steam exited rc=1320"))
assertNull(find("== STEP 12:00:00 starting the Steam client", "== steam exited rc=0"))
}
@Test fun onlyTheLatestClientAttemptCounts() {
assertNull(find(
"== STEP 12:00:00 starting the Steam client", "== steam exited rc=132",
"== STEP 12:01:00 starting the Steam client", "== steam exited rc=0",
))
}
@Test fun aLaterSuccessfulDeviceSelectionClearsTheGraphicsFailure() {
assertNull(find(
"[gamescope] [Error] vulkan: failed to find physical device",
"[gamescope] [Info] vulkan: selecting physical device 'Turnip Adreno (TM) 610': queue family 0",
))
}
@Test fun aNewSessionDoesNotReuseAnOldFailure() {
assertNull(find(
"== STEP 12:00:00 starting the Steam client", "== steam exited rc=132",
"== droiddeck-session Fri Oct 23 12:01:00 mode=steam",
))
}
}
@@ -1,8 +1,10 @@
package com.droiddeck.launcher.session
import com.droiddeck.launcher.core.LogRedactor
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
@@ -12,6 +14,9 @@ import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.zip.ZipFile
@RunWith(RobolectricTestRunner::class)
@@ -147,6 +152,41 @@ class SessionLogShareTest {
assertTrue(zip(folder).values.none { it.contains(leaked) })
}
@Test fun aDirectoryListingFailureLeavesTheTreeUnrecordedButDoesNotStopSiblingScrubbing() {
val folder = tmp.newFolder("2026-10-06-06-listing")
val unavailable = File(folder, "unavailable").apply { mkdirs() }
val unavailableLog = File(unavailable, "session.log").apply { writeText("$secret\n") }
val availableLog = File(folder, "available/session.log").apply {
parentFile!!.mkdirs()
writeText("$secret\n")
}
assertFalse(SessionArtifacts.scrubAndMark(folder, listFiles = {
if (it == unavailable) null else it.listFiles()
}))
assertTrue(unavailableLog.readText().contains(leaked))
assertFalse(availableLog.readText().contains(leaked))
assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists())
assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists())
}
@Test fun aFailedScrubStillRecordsTheCollectionEventWithoutCompletingTheFolder() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val folder = tmp.newFolder("2026-10-06-06-collect")
File(folder, "wayland.log").writeText("test compositor log\n")
File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).apply {
mkdirs()
resolve("blocker").writeText("force marker write failure\n")
}
SessionArtifacts.collect(context, folder, "test")
assertTrue(File(folder, "events.jsonl").readText().contains("session.artifacts_collected"))
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists())
}
@Test fun steamLogsPastTheSizeLimitStayOut() {
val folder = tmp.newFolder("2026-10-06-07-steam")
File(folder, "session.log").writeText("ok\n")
@@ -160,4 +200,322 @@ class SessionLogShareTest {
assertTrue("steam/console_log.txt" in names)
assertFalse("steam/cef_log.previous.txt" in names)
}
@Test fun streamingComparisonPreservesUnchangedFileAndReplacesChangedFile() {
val folder = tmp.newFolder("2026-10-06-08-steam")
val unchanged = File(folder, "unchanged.log")
unchanged.bufferedWriter().use { out -> repeat(5000) { out.write("safe diagnostic $it\n") } }
val originalModified = 1_600_000_000_000L
assertTrue(unchanged.setLastModified(originalModified))
val changed = File(folder, "changed.log")
changed.bufferedWriter().use { out ->
repeat(5000) { out.write("safe diagnostic $it\n") }
out.write("$secret\n")
}
assertTrue(SessionArtifacts.scrubAndMark(folder))
assertEquals(originalModified, unchanged.lastModified())
assertFalse(changed.readText().contains(leaked))
assertTrue(changed.readText().contains("sessionid=<redacted:token>"))
}
@Test fun historicalScrubDefersWithoutLeavingMarkersAndResumes() {
val folder = tmp.newFolder("2026-10-06-09-steam")
val log = File(folder, "session.log").apply { writeText("$secret\n") }
val rulesMarker = File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").apply { writeText("stale\n") }
val treeMarker = File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).apply { writeText("rules ${LogRedactor.RULES_VERSION}\n") }
SessionState.running = true
try {
assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true))
} finally {
SessionState.running = false
}
assertFalse(rulesMarker.exists())
assertFalse(treeMarker.exists())
assertTrue(log.readText().contains(leaked))
assertTrue(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true))
assertFalse(log.readText().contains(leaked))
assertTrue(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").isFile)
}
@Test fun historicalScrubCancellationDuringStreamingPreservesTheOriginal() {
val folder = tmp.newFolder("2026-10-06-10-steam")
val original = "first safe line\n" + "x".repeat(20_000) + " $secret\n"
val log = File(folder, "session.log").apply { writeText(original) }
var checks = 0
assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true) { ++checks >= 4 })
assertEquals(original, log.readText())
assertFalse(File(folder, ".session.log.scrub").exists())
assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists())
}
@Test fun historicalScrubCancellationBeforeComparisonPreservesTheOriginal() {
val folder = tmp.newFolder("2026-10-06-11-steam")
val original = "safe diagnostic\n"
val log = File(folder, "session.log").apply { writeText(original) }
val temporary = File(folder, ".session.log.scrub")
assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true) { temporary.length() > 0 })
assertEquals(original, log.readText())
assertFalse(temporary.exists())
assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists())
}
@Test fun historicalScrubDoesNotReplaceALogThatChangedBeforeCommit() {
val folder = tmp.newFolder("2026-10-06-12-steam")
val original = "sessionid=$leaked\n"
val appended = "writer finished after collection started\n"
val log = File(folder, "session.log").apply { writeText(original) }
assertFalse(SessionArtifacts.scrubAndMark(folder, beforeReplace = { it.appendText(appended) }))
assertEquals(original + appended, log.readText())
assertFalse(File(folder, ".session.log.scrub").exists())
assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists())
assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists())
}
@Test fun comparisonCancellationWinsOverAnImmediateLengthMismatch() {
val left = tmp.newFile("left.log").apply { writeText("short\n") }
val right = tmp.newFile("right.log").apply { writeText("a different length\n") }
assertNull(SessionArtifacts.sameContents(left, right) { true })
}
@Test fun recoveryRetryKeepsItsSteamLogsWhenALaterSessionLeftNoFolder() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "2026-10-08-01-steam").apply { mkdirs() }
val saved = File(folder, "steam/console_log.txt").apply {
parentFile!!.mkdirs()
writeText("session A\n")
}
File(folder, "ended-without-teardown.txt").writeText("recovery attempted before session B\n")
val runtime = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.local/share/Steam/logs/console_log.txt").apply {
parentFile!!.mkdirs()
writeText("session B\n")
}
SessionArtifacts.finishAbandoned(context)
assertEquals("session A\n", saved.readText())
assertEquals("session B\n", runtime.readText())
assertTrue(File(folder, "ended-without-teardown.txt").readText().contains("runtime capture did not finish"))
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
}
@Test fun abandonedRecoveryDoesNotCopyLogsFromANewerCompletedSession() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val logs = com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context)
val folder = File(logs, "2026-10-08-02-steam").apply { mkdirs() }
val saved = File(folder, "steam/console_log.txt").apply {
parentFile!!.mkdirs()
writeText("session A\n")
}
File(logs, "2026-10-08-03-steam").apply { mkdirs() }
.resolve(SessionArtifacts.COMPLETE_MARKER).writeText("finished session B\n")
File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.local/share/Steam/logs/console_log.txt").apply {
parentFile!!.mkdirs()
writeText("session B\n")
}
SessionArtifacts.finishAbandoned(context)
assertEquals("session A\n", saved.readText())
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
}
@Test fun startupRecoveryRunsBeforeVacMarkerArmWhileOrdinaryCleanupDefers() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context)
val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "2999-12-31-99-startup-recovery")
val marker = File(root, "root/.droiddeck-vac-diagnostics")
val launches = File(root, "root/.droiddeck-vac-launches")
val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/startup-recovery-vac.log")
val sessionLog = File(folder, "session.log")
val crashLog = File(folder, "crash.log")
val previousRunning = SessionState.running
val previousPhase = SessionState.phase
try {
folder.deleteRecursively()
folder.mkdirs()
SessionArtifacts.recordClient(folder, "arm64")
sessionLog.writeText("$secret\n")
marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") }
launches.writeText("startup VAC evidence\n")
runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("startup VAC evidence\n") }
SessionState.running = true
SessionState.phase = SessionPhase.STARTING_GUEST
SessionArtifacts.finishAbandoned(context)
assertFalse(File(folder, "ended-without-teardown.txt").exists())
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertEquals("startup VAC evidence\n", File(folder, "steam/startup-recovery-vac.log").readText())
assertTrue(File(folder, "vac.txt").readText().contains("startup VAC evidence"))
assertTrue(File(folder, ".recovery-runtime-captured").isFile)
assertTrue(crashLog.isFile && crashLog.length() > 0L)
assertTrue(sessionLog.readText().contains(leaked))
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
SessionState.running = false
SessionArtifacts.finishAbandoned(context)
assertFalse(sessionLog.readText().contains(leaked))
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
} finally {
SessionState.running = previousRunning
SessionState.phase = previousPhase
folder.deleteRecursively()
runtimeSteamLog.delete()
marker.delete()
launches.delete()
}
}
@Test fun startupRecoveryExcludesCurrentFolderAndCapturesDeferredRuntime() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context)
val logs = com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context)
val day = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date())
val olderFolder = File(logs, "$day-8999-older-recovery")
val folder = File(logs, "$day-9000-deferred-recovery")
val marker = File(root, "root/.droiddeck-vac-diagnostics")
val launches = File(root, "root/.droiddeck-vac-launches")
val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/deferred-recovery-vac.log")
val previousRunning = SessionState.running
val previousPhase = SessionState.phase
val previousLogsEnabled = SessionPrefs.logsEnabled(context)
var currentFolder: File? = null
try {
olderFolder.deleteRecursively()
olderFolder.mkdirs()
folder.deleteRecursively()
folder.mkdirs()
SessionArtifacts.recordClient(folder, "arm64")
File(folder, "ended-without-teardown.txt").writeText("recovery began before session start\n")
marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") }
launches.writeText("deferred VAC evidence\n")
runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("deferred VAC evidence\n") }
SessionState.running = true
SessionState.phase = SessionPhase.STARTING_GUEST
SessionPrefs.setLogsEnabled(context, true)
currentFolder = SessionPaths.beginOrCurrent(context, "current-session")
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertEquals("deferred VAC evidence\n", File(folder, "steam/deferred-recovery-vac.log").readText())
assertTrue(File(folder, "vac.txt").readText().contains("deferred VAC evidence"))
assertTrue(File(folder, ".recovery-runtime-captured").isFile)
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
assertFalse(File(olderFolder, "ended-without-teardown.txt").exists())
assertFalse(File(olderFolder, SessionArtifacts.COMPLETE_MARKER).exists())
assertFalse(File(currentFolder, "ended-without-teardown.txt").exists())
assertFalse(File(currentFolder, SessionArtifacts.COMPLETE_MARKER).exists())
SessionState.running = false
SessionArtifacts.finishAbandoned(context)
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
assertTrue(File(olderFolder, SessionArtifacts.COMPLETE_MARKER).isFile)
assertFalse(File(currentFolder, SessionArtifacts.COMPLETE_MARKER).exists())
} finally {
SessionState.running = previousRunning
SessionState.phase = previousPhase
SessionPaths.take()?.let { SessionPaths.release(context, it) }
currentFolder?.deleteRecursively()
SessionPrefs.setLogsEnabled(context, previousLogsEnabled)
olderFolder.deleteRecursively()
folder.deleteRecursively()
runtimeSteamLog.delete()
marker.delete()
launches.delete()
}
}
@Test fun failedPreGuestRuntimeCaptureWritesNeitherCaptureNorCompleteMarker() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context)
val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "9999-12-31-01-vac-failure")
val marker = File(root, "root/.droiddeck-vac-diagnostics")
val launches = File(root, "root/.droiddeck-vac-launches")
val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/expired-recovery.log")
val crashLog = File(folder, "crash.log")
val previousRunning = SessionState.running
try {
folder.deleteRecursively()
folder.mkdirs()
SessionArtifacts.recordClient(folder, "arm64")
File(folder, "ended-without-teardown.txt").writeText("recovery began before session start\n")
val firstCrashSnapshot = "first crash snapshot\n".toByteArray()
crashLog.writeBytes(firstCrashSnapshot)
File(folder, "vac.txt").mkdirs()
marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") }
launches.writeText("VAC evidence that cannot be reported\n")
runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("session A\n") }
SessionState.running = true
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertFalse(File(folder, ".recovery-runtime-captured").exists())
assertTrue(File(folder, ".recovery-runtime-expired").isFile)
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
assertArrayEquals(firstCrashSnapshot, crashLog.readBytes())
File(folder, "vac.txt").deleteRecursively()
runtimeSteamLog.writeText("session B\n")
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertEquals("session A\n", File(folder, "steam/expired-recovery.log").readText())
assertArrayEquals(firstCrashSnapshot, crashLog.readBytes())
assertTrue(File(folder, "ended-without-teardown.txt").readText().contains("runtime capture did not finish"))
assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists())
SessionState.running = false
SessionArtifacts.finishAbandoned(context)
assertArrayEquals(firstCrashSnapshot, crashLog.readBytes())
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
} finally {
SessionState.running = previousRunning
folder.deleteRecursively()
runtimeSteamLog.delete()
marker.delete()
launches.delete()
}
}
@Test fun emptyCrashSnapshotIsPreservedAcrossRecovery() {
val context: android.content.Context = RuntimeEnvironment.getApplication()
val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "9999-12-31-02-empty-crash")
val crashLog = File(folder, "crash.log")
val previousRunning = SessionState.running
try {
folder.deleteRecursively()
folder.mkdirs()
crashLog.writeBytes(ByteArray(0))
SessionState.running = true
SessionArtifacts.finishAbandoned(context, beforeGuestStart = true)
assertTrue(crashLog.isFile)
assertEquals(0L, crashLog.length())
SessionState.running = false
SessionArtifacts.finishAbandoned(context)
assertTrue(crashLog.isFile)
assertEquals(0L, crashLog.length())
assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile)
} finally {
SessionState.running = previousRunning
folder.deleteRecursively()
}
}
}
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.session
import com.droiddeck.launcher.runtime.LinuxRuntime
import java.io.File
import java.nio.charset.StandardCharsets
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@@ -20,6 +21,49 @@ import org.robolectric.annotation.Config
class SessionLogShareZipTest {
private val app get() = RuntimeEnvironment.getApplication()
@Test fun aLargeSteamLogIsRedactedInTheSharedArchive() {
val session = File(LinuxRuntime.logDir(app), "2026-10-08-02-steam").apply { mkdirs() }
val raw = File(session, "steam-42.log")
val earlySecret = "early-sessionid-abcdef123456"
val trailingSecret = "late-refresh-token-abcdef123456"
try {
// One long line exercises the streaming limit; the final ordinary line must still be redacted.
raw.bufferedWriter().use { out ->
out.write("sessionid=$earlySecret")
val chunk = "x".repeat(8192)
repeat(8192) { out.write(chunk) }
out.write("\nrefresh_token=$trailingSecret\n")
}
assertTrue(raw.length() > 64L * 1024 * 1024)
val zip = SessionLogShare.zipFolder(app, session)!!
ZipFile(zip).use { archive ->
val entry = archive.getEntry("${session.name}/steam-42.log")!!
archive.getInputStream(entry).use { input ->
// Only inspect the bounded scrubbed prefix: the pre-fix raw archive is over 64 MiB.
val expected = "${com.droiddeck.launcher.core.LogRedactor.OVERSIZED_LINE}\n"
val prefix = ByteArray(expected.toByteArray(StandardCharsets.UTF_8).size)
var offset = 0
while (offset < prefix.size) {
val count = input.read(prefix, offset, prefix.size - offset)
assertTrue("zip entry ended before its scrubbed prefix", count > 0)
offset += count
}
assertEquals(expected, String(prefix, StandardCharsets.UTF_8))
input.bufferedReader().use { reader ->
val trailing = requireNotNull(reader.readLine())
assertFalse("trailing secret survived", trailing.contains(trailingSecret))
assertEquals("refresh_token=<redacted:token>", trailing)
assertEquals(null, reader.readLine())
}
}
}
} finally {
SessionLogShare.clear(app)
session.deleteRecursively()
}
}
@Test fun everyTextFileInTheZipIsScrubbedAndTheStoresAndToolsLogsComeAlong() {
val logs = LinuxRuntime.logDir(app)
val session = File(logs, "2026-10-08-01-steam").apply { mkdirs() }
@@ -2,10 +2,13 @@ package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import java.io.IOException
import java.io.Writer
class SessionSteamLogsTest {
@get:Rule val tmp = TemporaryFolder()
@@ -59,4 +62,37 @@ class SessionSteamLogsTest {
assertEquals(listOf("web.txt"), names(copied))
assertFalse(File(out, "web.txt").readText().contains("abcdef123456"))
}
@Test fun aCopyFailurePreservesThePreviousSnapshotAndRemovesPartialStaging() {
val logs = tmp.newFolder("logs")
val session = tmp.newFolder("session")
val out = tmp.newFolder("out")
File(logs, "console_log.txt").writeText("new complete line\n")
val snapshot = File(out, "console_log.txt").apply { writeText("previous valid snapshot\n") }
lateinit var staging: File
val copied = SessionArtifacts.copySessionLogs(logs, session, out) { target ->
staging = target
val delegate = target.bufferedWriter()
object : Writer() {
private var failed = false
override fun write(buffer: CharArray, offset: Int, length: Int) {
if (!failed) {
delegate.write(buffer, offset, minOf(length, 4))
delegate.flush()
failed = true
}
throw IOException("injected writer failure")
}
override fun flush() = delegate.flush()
override fun close() = delegate.close()
}
}
assertTrue(copied.isEmpty())
assertEquals("previous valid snapshot\n", snapshot.readText())
assertFalse(staging.exists())
}
}
@@ -27,17 +27,21 @@ class SettingsResetTest {
@Test fun settingsGoBackToTheirDefaults() {
SessionPrefs.setTheme(app, "ocean")
SessionPrefs.setBackDoubleTapMs(app, 100)
SessionPrefs.setUnfoldedControlsWithController(app, true)
SessionPrefs.setNoXalia(app, false)
session.edit().putInt("fpsLimit.steam", 30).commit()
SessionPrefs.setHdr(app, SessionService.MODE_DESKTOP, true)
SessionPrefs.setResolutionChoice(app, SessionService.MODE_STEAM, "1280x800")
SessionPrefs.setGuestHostname(app, "MyDeck")
assertTrue(SessionPrefs.setGameDebugLogsEnabled(app, true))
SessionPrefs.setHudShowFps(app, false)
SessionPrefs.setHudShowBattery(app, false)
SessionPrefs.setHudShowGraph(app, false)
SessionPrefs.setHudColor(app, "amber")
SessionPrefs.setHudOpacity(app, 40)
SessionPrefs.setFusionHudConfig(app, "hudSize=mega,showFPSGraph=0")
SessionPrefs.setFusionHudPosition(app, 120f, 40f)
ControllerPrefs.setOpacity(app, 40)
AppUiPrefs.setScale(app, 150)
FrameGen.set(app, FrameGen.Mode(FrameGen.ENGINE_DDFG, 3))
@@ -46,25 +50,46 @@ class SettingsResetTest {
assertTrue(SettingsReset.resetAll(app, gameProfiles = false))
assertEquals("graphite", SessionPrefs.theme(app))
assertEquals(500, SessionPrefs.backDoubleTapMs(app))
assertFalse(SessionPrefs.unfoldedControlsWithController(app))
assertTrue(SessionPrefs.noXalia(app))
assertFalse(session.contains("fpsLimit.steam"))
assertFalse(SessionPrefs.hdr(app, SessionService.MODE_DESKTOP))
assertFalse(SessionPrefs.resolutionChosen(app, SessionService.MODE_STEAM))
assertEquals(SessionPrefs.DEFAULT_GUEST_HOSTNAME, SessionPrefs.guestHostname(app))
assertFalse(SessionPrefs.gameDebugLogsEnabled(app))
val guest = java.io.File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app),
"root/.config/droiddeck/game-environment.json")
assertFalse(org.json.JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS))
assertTrue(SessionPrefs.hudShowFps(app))
assertTrue(SessionPrefs.hudShowBattery(app))
assertTrue(SessionPrefs.hudShowGraph(app))
assertEquals(SessionPrefs.HUD_COLOR_MINT, SessionPrefs.hudColor(app))
assertEquals(SessionPrefs.HUD_OPACITY_DEFAULT, SessionPrefs.hudOpacity(app))
assertEquals("32.4°C", PerfHud.batteryCelsius(324))
assertNull(PerfHud.batteryCelsius(0))
assertNull(SessionPrefs.fusionHudConfig(app))
assertNull(SessionPrefs.fusionHudPosition(app))
assertEquals(100, ControllerPrefs.read(app).opacity)
assertEquals(AppUiPrefs.DEFAULT_SCALE, AppUiPrefs.scale(app))
assertEquals(FrameGen.Mode.OFF.engine, FrameGen.engine(app))
assertFalse(prefs("steam_touch").contains("gyro"))
}
@Test fun aFailedDebugOptOutDoesNotHideTheEnabledPreference() {
assertTrue(SessionPrefs.setGameDebugLogsEnabled(app, true))
val directory = java.io.File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app),
"root/.config/droiddeck")
directory.deleteRecursively()
directory.writeText("blocks configuration publication")
try {
assertFalse(SettingsReset.resetAll(app, gameProfiles = false))
assertTrue(SessionPrefs.gameDebugLogsEnabled(app))
} finally {
directory.delete()
directory.mkdirs()
GameEnvironmentStore.publish(app)
}
}
@Test fun libraryAndRecordsAreKept() {
val folder = "/storage/emulated/0/Games/Foo"
SessionPrefs.setAddedGameName(app, folder, "Foo")
@@ -0,0 +1,46 @@
package com.droiddeck.launcher.session
import android.app.Application
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import java.io.File
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33], manifest = Config.NONE, application = Application::class)
class SteamImportPromptTest {
@get:Rule val temp = TemporaryFolder()
private fun ask(root: File, text: String) = File(root, "root/.cache/droiddeck").apply { mkdirs() }.resolve("steam-import.json").writeText(text)
@Test fun aRequestFromTheGuestIsRead() {
val root = temp.newFolder()
ask(root, """{"token":"7","games":["Absolum","","Hades"]}""")
assertEquals(SteamImportPrompt.Ask("7", listOf("Absolum", "Hades")), SteamImportPrompt.read(root))
}
@Test fun noRequestOrABrokenOneIsIgnored() {
val root = temp.newFolder()
assertNull(SteamImportPrompt.read(root))
ask(root, "{")
assertNull(SteamImportPrompt.read(root))
ask(root, """{"games":["Hades"]}""")
assertNull(SteamImportPrompt.read(root))
}
@Test fun theAnswerCarriesTheTokenAndTheChoice() {
val root = temp.newFolder()
for ((now, choice) in listOf(true to "now", false to "later")) {
SteamImportPrompt.answer(root, "9", now)
val json = JSONObject(File(root, "root/.cache/droiddeck/steam-import.answer").readText())
assertEquals("9", json.getString("token"))
assertEquals(choice, json.getString("choice"))
}
}
}
@@ -0,0 +1,97 @@
package com.droiddeck.launcher.session
import java.io.File
import java.nio.file.Files
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
class UsbLinkTest {
private lateinit var sys: File
@Before fun setUp() { sys = Files.createTempDirectory("usblink").toFile() }
@After fun tearDown() {
Files.walk(sys.toPath()).use { paths -> paths.sorted(Comparator.reverseOrder()).forEach { Files.deleteIfExists(it) } }
}
private val mounts = """
/dev/block/dm-5 /data ext4 rw 0 0
/dev/fuse /storage/8C5A-1F23 fuse rw 0 0
/dev/block/vold/public:8,97 /mnt/media_rw/8C5A-1F23 fuseblk rw 0 0
""".trimIndent()
private fun drive(deviceSpeed: String, otherHub: String) {
val controller = File(sys, "devices/platform/xhci")
val hub = File(controller, "usb1").apply { mkdirs(); File(this, "speed").writeText("480\n"); File(this, "idVendor").writeText("1d6b\n") }
File(controller, "usb2").apply { mkdirs(); File(this, "speed").writeText("$otherHub\n"); File(this, "idVendor").writeText("1d6b\n") }
val device = File(hub, "1-1").apply { mkdirs() }
File(device, "speed").writeText("$deviceSpeed\n")
File(device, "idVendor").writeText("04e8\n")
File(device, "busnum").writeText("1\n")
File(device, "devnum").writeText("7\n")
File(device, "manufacturer").writeText("Samsung\n")
File(device, "product").writeText("PSSD T7\n")
val part = File(device, "1-1:1.0/host1/target1:0:0/1:0:0:0/block/sdg/sdg1").apply { mkdirs() }
File(sys, "dev/block").mkdirs()
Files.createSymbolicLink(File(sys, "dev/block/8:97").toPath(), part.toPath())
File(sys, "bus/usb/devices").mkdirs()
Files.createSymbolicLink(File(sys, "bus/usb/devices/usb1").toPath(), hub.toPath())
}
@Test fun findsTheUsbSpeedOfADriveBehindItsMount() {
drive("480", "10000")
val link = UsbLink.forPath("/storage/8C5A-1F23/Games", mounts, sys)!!
assertEquals("8:97", link.device)
assertEquals(480.0, link.mbps, 0.0)
assertEquals("Samsung PSSD T7", link.name)
assertEquals(10000.0, link.portMbps!!, 0.0)
assertEquals("1-7", link.plug)
assertEquals("3/1-7/8:97@480.0", UsbLink.dismissKey(3, link))
assertFalse(UsbLink.SlowDrive("k", link.name, link.mbps, link.portMbps).portLimited)
}
@Test fun aPortWithoutSuperSpeedIsReportedAsTheLimit() {
drive("480", "480")
val link = UsbLink.forPath("/storage/8C5A-1F23", mounts, sys)!!
assertTrue(UsbLink.SlowDrive("k", link.name, link.mbps, link.portMbps).portLimited)
}
@Test fun anUnknownPortSpeedIsNotReportedAsTheLimit() {
drive("480", "10000")
Files.delete(File(sys, "bus/usb/devices/usb1").toPath())
val link = UsbLink.forPath("/storage/8C5A-1F23", mounts, sys)!!
assertNull(link.portMbps)
assertFalse(UsbLink.SlowDrive("k", link.name, link.mbps, link.portMbps).portLimited)
}
@Test fun internalStorageAndUnknownMountsHaveNoLink() {
drive("480", "10000")
assertNull(UsbLink.forPath("/storage/emulated/0/Games", mounts, sys))
assertNull(UsbLink.forPath("/storage/ABCD-0000", mounts, sys))
}
@Test fun mountsPickTheLongestMatchingMountPoint() {
assertEquals("8:97", UsbLink.mountDevice("/mnt/media_rw/8C5A-1F23/Games/PC", mounts))
assertNull(UsbLink.mountDevice("/mnt/media_rw/8C5A-1F230", mounts))
assertEquals("name:sda1", UsbLink.mountDevice("/mnt/usb/a", "/dev/block/sda1 /mnt/usb vfat rw 0 0"))
}
@Test fun rawMountPathsAreTreatedAsTheirStorageVolume() {
assertEquals("/storage/8C5A-1F23/Games", UsbLink.storagePath("/mnt/media_rw/8C5A-1F23/Games"))
assertEquals("/storage/emulated/0/Games", UsbLink.storagePath("/storage/emulated/0/Games"))
assertTrue(UsbLink.external(UsbLink.storagePath("/mnt/media_rw/8C5A-1F23/Games")))
}
@Test fun generationsFollowTheLinkSpeed() {
assertEquals("USB 1.1", UsbLink.generation(12.0))
assertEquals("USB 2.0", UsbLink.generation(480.0))
assertEquals("USB 3.2 Gen 1", UsbLink.generation(5000.0))
assertEquals("USB 3.2 Gen 2", UsbLink.generation(10000.0))
assertEquals(42, UsbLink.megabytesPerSecond(480.0))
}
}