Merge upstream main and close diagnostic publication races

This commit is contained in:
wallentx committed 2026-10-25 18:15:44 -05:00
commit f4adbeb602
473 files changed
+36063 -3507

No files matched your search

@@ -49,11 +49,25 @@ class BatteryComponentTest {
assertEquals("-2000000", File(supplies, "BAT1/current_now").readText().trim())
}
private fun start(supplies: File, vpower: File, currentUa: Long) {
@Test fun chargingAtFullLevelIsReportedFullSoSteamStopsSaying99() {
val supplies = tmp.newFolder("power_supply")
val vpower = tmp.newFolder("vpower")
start(supplies, vpower, 2_000_000L, BatteryManager.BATTERY_STATUS_CHARGING, 100)
assertEquals("Full", File(supplies, "BAT1/status").readText().trim())
assertEquals("Full", File(vpower, "battery_status").readText().trim())
battery?.stop()
start(supplies, vpower, 2_000_000L, BatteryManager.BATTERY_STATUS_CHARGING, 99)
assertEquals("Charging", File(supplies, "BAT1/status").readText().trim())
}
private fun start(
supplies: File, vpower: File, currentUa: Long,
status: Int = BatteryManager.BATTERY_STATUS_DISCHARGING, level: Int = 50,
) {
val context = RuntimeEnvironment.getApplication()
context.sendStickyBroadcast(Intent(Intent.ACTION_BATTERY_CHANGED).apply {
putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_DISCHARGING)
putExtra(BatteryManager.EXTRA_LEVEL, 50)
putExtra(BatteryManager.EXTRA_STATUS, status)
putExtra(BatteryManager.EXTRA_LEVEL, level)
putExtra(BatteryManager.EXTRA_SCALE, 100)
putExtra(BatteryManager.EXTRA_VOLTAGE, 4000)
})
@@ -178,17 +178,39 @@ class BootMovieLibraryTest {
assertNull(SessionFiles.startupMoviePath(BootMovieLibrary.steamConfig(app)))
}
@Test fun onlyTheThreeStartupMoviesOfSteamAreListed() {
listOf("deck_startup", "oled_startup", "startup_machine", "controller_generic_thumbstick_move").forEach {
@Test fun onlyTheStartupMoviesOfSteamAreListed() {
listOf("deck_startup", "oled_startup", "startup_machine", "steam_os_startup", "controller_generic_thumbstick_move").forEach {
File(BootMovieLibrary.steamRoot(app), "steamui/movies/$it.webm").also { f -> f.parentFile!!.mkdirs(); f.writeText("movie") }
}
val ids = BootMovieLibrary.list(app).map { it.id }.filter { it.startsWith("steam:") }
assertEquals(
listOf("steam:/movies/deck_startup.webm", "steam:/movies/oled_startup.webm", "steam:/movies/startup_machine.webm"),
listOf(
"steam:/movies/deck_startup.webm", "steam:/movies/oled_startup.webm", "steam:/movies/startup_machine.webm",
"steam:/movies/steam_os_startup.webm",
),
ids.sorted(),
)
}
@Test fun steamsDefaultPickIsTakenOverAsItsOwnStartupMovie() {
val native = File(BootMovieLibrary.steamRoot(app), "steamui/movies/steam_os_startup.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
movie("a.webm")
steamPicksAt(SessionFiles.BOOT_MOVIE_PATH)
BootMovie.select(app, "file:a.webm")
steamPicksAt("")
assertTrue(BootMovie.syncFromSteam(app))
assertEquals("steam:/movies/steam_os_startup.webm", BootMovie.choice(app))
assertEquals(native, BootMovie.currentFile(app))
assertFalse(BootMovie.syncFromSteam(app))
}
@Test fun anEmptySteamPickThatWasNeverSeenChangesNothing() {
File(BootMovieLibrary.steamRoot(app), "steamui/movies/steam_os_startup.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
steamPicksAt("")
assertFalse(BootMovie.syncFromSteam(app))
assertEquals(BootMovie.DROIDDECK_30, BootMovie.choice(app))
}
@Test fun aMovieBoughtInThePointsShopIsListedAndAdopted() {
val file = File(BootMovieLibrary.steamRoot(app), "appcache/startupmovies/Bought.webm").also { it.parentFile!!.mkdirs(); it.writeText("movie") }
val entry = BootMovieLibrary.list(app).first { it.id == "steam:/appcache/startupmovies/Bought.webm" }
@@ -0,0 +1,135 @@
package com.droiddeck.launcher.session
import android.content.Context
import com.droiddeck.launcher.core.Hashes
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.assertThrows
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.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class ComponentImportTest {
private lateinit var context: Context
@Before fun setUp() {
context = RuntimeEnvironment.getApplication()
File(context.filesDir, "components").deleteRecursively()
LinuxRuntime.rootDir(context).deleteRecursively()
}
@Test fun refusesOverwritingReferencedPackageWithDifferentContent() {
val wcpA = createWcp("src-a.wcp", "A")
val wcpB = createWcp("src-b.wcp", "B")
val shaA = Hashes.sha256(wcpA)
ComponentsManager.importPackage(context, wcpA, "dxvk.wcp")
ComponentsManager.setGameComponent(context, "10", "dxvk", "dxvk.wcp")
assertThrows(IllegalStateException::class.java) {
ComponentsManager.importPackage(context, wcpB, "dxvk.wcp")
}
val stored = File(context.filesDir, "components/packages/dxvk.wcp")
assertEquals(shaA, Hashes.sha256(stored))
assertFalse(File(context.filesDir, "components/packages/dxvk.wcp.part").exists())
}
@Test fun allowsReimportingIdenticalPackageWhileReferenced() {
val wcpA = createWcp("src-a.wcp", "A")
val shaA = Hashes.sha256(wcpA)
ComponentsManager.importPackage(context, wcpA, "dxvk.wcp")
ComponentsManager.setGameComponent(context, "10", "dxvk", "dxvk.wcp")
val reimported = ComponentsManager.importPackage(context, wcpA, "dxvk.wcp")
assertEquals("A", reimported.version)
assertEquals("dxvk.wcp", reimported.file)
val stored = File(context.filesDir, "components/packages/dxvk.wcp")
assertEquals(shaA, Hashes.sha256(stored))
assertFalse(File(context.filesDir, "components/packages/dxvk.wcp.part").exists())
}
@Test fun invalidatesUnpackedStoreWhenReplacingUnreferencedPackage() {
val wcpA = createWcp("src-a.wcp", "A")
val wcpB = createWcp("src-b.wcp", "B")
val shaB = Hashes.sha256(wcpB)
ComponentsManager.importPackage(context, wcpA, "dxvk.wcp")
val unpacked = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-components/store/dxvk")
unpacked.mkdirs()
File(unpacked, ".complete").writeText("ok")
assertTrue(File(unpacked, ".complete").isFile)
val replaced = ComponentsManager.importPackage(context, wcpB, "dxvk.wcp")
assertEquals("B", replaced.version)
val stored = File(context.filesDir, "components/packages/dxvk.wcp")
assertEquals(shaB, Hashes.sha256(stored))
assertFalse(unpacked.exists())
}
@Test fun deletingAPackageAGameProfileUsesClearsThatProfileEntry() {
val wcpA = createWcp("src-a.wcp", "A")
ComponentsManager.importPackage(context, wcpA, "dxvk.wcp")
writeGameProfile("10", "dxvk", "dxvk.wcp")
ComponentsManager.deletePackage(context, "dxvk.wcp")
assertFalse(File(context.filesDir, "components/packages/dxvk.wcp").exists())
val state = JSONObject(File(context.filesDir, "components/state.json").readText())
assertFalse(state.optJSONObject("profiles")?.optJSONObject("10")?.has("dxvk") == true)
}
private fun writeGameProfile(scope: String, comp: String, file: String) {
val state = File(context.filesDir, "components/state.json")
state.parentFile!!.mkdirs()
state.writeText(
JSONObject()
.put("active", JSONObject())
.put("queued", JSONObject())
.put("profiles", JSONObject().put(scope, JSONObject().put(comp, file)))
.toString(),
)
}
private fun createWcp(fileName: String, version: String): File {
val out = File(context.cacheDir, fileName)
val profile = JSONObject()
.put("type", "DXVK-Linux")
.put("versionName", version)
.put("description", "DXVK $version")
.toString()
.toByteArray(Charsets.UTF_8)
val dll = "dxvk-dll-$version".toByteArray(Charsets.UTF_8)
TarArchiveOutputStream(ZstdOutputStream(BufferedOutputStream(FileOutputStream(out)))).use { tar ->
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX)
val profEntry = TarArchiveEntry("profile.json").apply { size = profile.size.toLong() }
tar.putArchiveEntry(profEntry)
tar.write(profile)
tar.closeArchiveEntry()
val dllEntry = TarArchiveEntry("files/lib/wine/dxvk/aarch64-windows/d3d11.dll").apply { size = dll.size.toLong() }
tar.putArchiveEntry(dllEntry)
tar.write(dll)
tar.closeArchiveEntry()
}
return out
}
}
@@ -0,0 +1,30 @@
package com.droiddeck.launcher.session
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class ComponentsCarryOverTest {
@Test
fun swappedPackagesFollowTheBuildThatReplacesTheirProton() {
val state = JSONObject("""
{"active": {"DroidDeck-Proton_11-11.2": {
"dxvk": {"file": "dxvk-2.7.wcp", "label": "2.7", "protonVersion": "11-11.2"},
"vkd3d": {"file": "original 11-11.1", "label": "Original from 11-11.1"},
"fex": {"file": "gone.wcp", "label": "old"}}},
"queued": {"DroidDeck-Proton_11-11.2": {
"vkd3d": {"kind": "package", "file": "vkd3d-3.0.wcp", "label": "3.0"},
"fex": {"kind": "original", "protonVersion": "11-11.1", "label": "Original 11-11.1"}}}}
""".trimIndent())
val carried = ComponentsManager.carried(state, "DroidDeck-Proton_11-11.2") { it != "gone.wcp" }
assertEquals(setOf("dxvk", "vkd3d"), carried.keys)
assertEquals("package", carried.getValue("dxvk").getString("kind"))
assertEquals("dxvk-2.7.wcp", carried.getValue("dxvk").getString("file"))
assertEquals("2.7", carried.getValue("dxvk").getString("label"))
assertEquals("vkd3d-3.0.wcp", carried.getValue("vkd3d").getString("file"))
assertEquals(emptyMap<String, JSONObject>(), ComponentsManager.carried(state, "GE-Proton11-7") { true })
}
}
@@ -0,0 +1,32 @@
package com.droiddeck.launcher.session
import org.json.JSONObject
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import java.io.File
@RunWith(RobolectricTestRunner::class)
class ComponentsSelectionTest {
private val proton = ComponentsManager.Proton("DroidDeck-Proton_11-11.1", "DroidDeck-Proton 11-11.1", File("/p"), "/p", "DroidDeck-Proton-11-11.1", false)
private val entry = JSONObject().put("file", "dxvk-low-latency-arm64ec-3.1.1-2-linux.wcp").put("protonVersion", "DroidDeck-Proton-11-11.1")
@Test
fun `a package swapped into an installed Proton is in use`() {
assertTrue(ComponentsManager.liveSelection("active", entry, proton))
assertTrue(ComponentsManager.liveSelection("queued", JSONObject().put("file", "x.wcp"), proton))
}
@Test
fun `a package left on a removed Proton is not in use`() {
assertFalse(ComponentsManager.liveSelection("active", entry, null))
assertFalse(ComponentsManager.liveSelection("queued", entry, null))
}
@Test
fun `a package from before a Proton update is not in use`() {
assertFalse(ComponentsManager.liveSelection("active", JSONObject(entry.toString()).put("protonVersion", "DroidDeck-Proton-11-9.1"), proton))
}
}
@@ -1,7 +1,6 @@
package com.droiddeck.launcher.session
import android.content.Context
import com.droiddeck.launcher.core.CpuAllocationDefaults
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
@@ -14,36 +13,22 @@ import org.robolectric.annotation.Config
@Config(sdk = [33])
class CoreAllocationPrefsTest {
private val app get() = RuntimeEnvironment.getApplication()
private val defaults = CpuAllocationDefaults.Allocation("7", "3,4,5,6")
private val saved get() = app.getSharedPreferences("session", Context.MODE_PRIVATE)
@Before fun clear() { saved.edit().clear().commit() }
@Test fun absentPreferencesUseTheDeviceDefaultWithoutWritingIt() {
assertEquals(SessionPrefs.CoreAllocation(true, "7", "3,4,5,6"), SessionPrefs.coreAllocation(app, defaults))
assertTrue(saved.all.isEmpty())
assertEquals(SessionPrefs.CoreAllocation(false, "", ""), SessionPrefs.coreAllocation(app, null))
@Test fun absentPreferencesLeaveEveryCoreToTheScheduler() {
assertFalse(SessionPrefs.clientCpusOverride(app))
assertEquals("", SessionPrefs.clientCpus(app))
assertEquals("", SessionPrefs.gameCpus(app))
}
@Test fun explicitDisableAndAllCoreChoicesSurviveAnUpdate() {
saved.edit().putBoolean("clientCpusOverride", false).putString("clientCpus", "").putString("gameCpus", "").commit()
assertEquals(SessionPrefs.CoreAllocation(false, "", ""), SessionPrefs.coreAllocation(app, defaults))
}
@Test fun existingCustomMasksArePreserved() {
saved.edit().putBoolean("clientCpusOverride", true).putString("clientCpus", "0,1").putString("gameCpus", "2,7").commit()
assertEquals(SessionPrefs.CoreAllocation(true, "0,1", "2,7"), SessionPrefs.coreAllocation(app, defaults))
}
@Test fun anOldClientMaskIsNotEnabledWithoutAnOverrideChoice() {
saved.edit().putString("clientCpus", "0,1").commit()
assertEquals(SessionPrefs.CoreAllocation(false, "0,1", "3,4,5,6"), SessionPrefs.coreAllocation(app, defaults))
}
@Test fun changingOneChoiceDoesNotReplaceTheOtherDefaults() {
SessionPrefs.setGameCpus(app, "0,1,2,3,4,5,6,7")
assertEquals(SessionPrefs.CoreAllocation(true, "7", "0,1,2,3,4,5,6,7"), SessionPrefs.coreAllocation(app, defaults))
SessionPrefs.setClientCpusOverride(app, false)
assertEquals(SessionPrefs.CoreAllocation(false, "7", "0,1,2,3,4,5,6,7"), SessionPrefs.coreAllocation(app, defaults))
@Test fun savedChoicesAreKept() {
SessionPrefs.setClientCpusOverride(app, true)
SessionPrefs.setClientCpus(app, "7")
SessionPrefs.setGameCpus(app, "3,4,5,6")
assertTrue(SessionPrefs.clientCpusOverride(app))
assertEquals("7", SessionPrefs.clientCpus(app))
assertEquals("3,4,5,6", SessionPrefs.gameCpus(app))
}
}
@@ -29,6 +29,18 @@ class ForcedPackageTest {
LinuxRuntime.rootDir(context).deleteRecursively()
}
@Test fun unpackedCacheNameCannotEscapeStoreDirectory() {
assertEquals("dxvk-2.7.1-linux", ComponentsManager.unpackedCacheKey(dxvk2))
for (filename in listOf("..wcp", "...wcp")) {
try {
ComponentsManager.unpackedCacheKey(filename)
fail("Expected cache traversal name to be rejected: $filename")
} catch (_: IllegalArgumentException) {
// Expected: the derived path would be a dot segment.
}
}
}
@Test fun adreno6xxForcesDxvk2AndNothingElseDoes() {
val rule = ComponentsManager.FORCED_PACKAGES.single { GpuInfo.Family.A6XX in it.families }
assertEquals("dxvk", rule.comp)
@@ -13,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)
@@ -83,6 +85,45 @@ class GameEnvironmentStoreTest {
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() {
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))
@@ -0,0 +1,36 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class LoadingStateTest {
@Test fun clientDownloadCountsMegabytesWhenTheRuntimeSaysThem() {
assertEquals(
"45 / 360 MB" to 12,
LoadingState.clientDownload("== STEP 17:38:20 downloading Steam: bins_linuxarm64_linuxarm64 (2/17), 45 of 360 MB"),
)
}
@Test fun aStalledDownloadStillShowsWhereItIs() {
assertEquals(
"45 / 360 MB" to 12,
LoadingState.clientDownload(
"== STEP 17:39:20 downloading Steam: bins_linuxarm64_linuxarm64 (2/17), 45 of 360 MB" +
" - interrupted (curl exit 28), trying again in 5 s",
),
)
}
@Test fun anOlderRuntimeShowsThePartAndItsNumber() {
assertEquals(
"bins_linuxarm64_linuxarm64" to 11,
LoadingState.clientDownload("== STEP 17:38:17 downloading Steam: bins_linuxarm64_linuxarm64 (2/17)"),
)
assertEquals("a_all" to 50, LoadingState.clientDownload("== STEP 00:00:00 downloading Steam: a_all (1/2), 0 of 0 MB"))
}
@Test fun otherStepsAreNotClientDownloads() {
assertNull(LoadingState.clientDownload("== STEP 17:38:14 checking the Steam client (a first run downloads it)"))
}
}
@@ -0,0 +1,66 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
class MemoryReadoutTest {
private val meminfo = """
MemTotal: 11379920 kB
MemFree: 527864 kB
MemAvailable: 3235768 kB
Buffers: 1024 kB
SwapTotal: 16777212 kB
SwapFree: 10358080 kB
""".trimIndent()
@Test fun memoryAndSwapInUseComeFromMeminfo() {
val device = MemoryReadout.parseMeminfo(meminfo)!!
assertEquals(11379920L - 3235768L, device.usedKb)
assertEquals(16777212L - 10358080L, device.swapUsedKb)
assertEquals("7.8", MemoryReadout.gb(device.usedKb))
assertEquals("10.9", MemoryReadout.gb(device.totalKb))
assertEquals(0L, MemoryReadout.parseMeminfo("MemTotal: 100 kB\nMemAvailable: 40 kB\n")!!.swapUsedKb)
assertNull(MemoryReadout.parseMeminfo("MemTotal: 100 kB\n"))
}
@Test fun aProcessCountsItsResidentAnonymousAndSharedMemory() {
val status = """
Name: Diablo IV.exe
VmRSS: 2000000 kB
RssAnon: 1500000 kB
RssFile: 400000 kB
RssShmem: 100000 kB
VmSwap: 300000 kB
""".trimIndent()
assertEquals(1600000L, MemoryReadout.residentKb(status))
assertEquals(0L, MemoryReadout.residentKb("Name:\tkthreadd\n"))
}
@Test fun theGameIsWhatRunsInAWinePrefix() {
fun env(vararg vars: String) = vars.joinToString("\u0000", postfix = "\u0000").toByteArray()
assertTrue(MemoryReadout.inWinePrefix(env("HOME=/root", "WINEPREFIX=/root/pfx", "DISPLAY=:0")))
assertTrue(MemoryReadout.inWinePrefix("WINEPREFIX=/x".toByteArray()))
assertFalse(MemoryReadout.inWinePrefix(env("HOME=/root", "STEAM_COMPAT_DATA_PATH=/x", "MY_WINEPREFIX=/y")))
assertFalse(MemoryReadout.inWinePrefix(ByteArray(0)))
}
@Test fun androidIsWhatIsLeftOfTheMemoryInUse() {
val device = MemoryReadout.Device(totalKb = 10_000, availableKb = 3_000, swapTotalKb = 0, swapFreeKb = 0)
assertEquals(3_000L, MemoryReadout.androidKb(device, MemoryReadout.Split(gameKb = 2_000, droiddeckKb = 1_000, gpuKb = 1_000)))
assertEquals(4_000L, MemoryReadout.androidKb(device, MemoryReadout.Split(gameKb = 2_000, droiddeckKb = 1_000, gpuKb = null)))
assertEquals(0L, MemoryReadout.androidKb(device, MemoryReadout.Split(gameKb = 6_000, droiddeckKb = 2_000, gpuKb = 1_000)))
}
@Test fun theLogLineSaysEveryPartInMegabytes() {
val device = MemoryReadout.Device(totalKb = 11_379_920, availableKb = 1_048_576, swapTotalKb = 16_777_212, swapFreeKb = 8_388_606)
val split = MemoryReadout.Split(gameKb = 2_097_152, droiddeckKb = 524_288, gpuKb = 3_145_728)
assertEquals(
"used 10089/11113 MB, available 1024 MB, swap 8191/16383 MB | game 2048, droiddeck 512, android 4457, gpu 3072 MB",
MemoryLog.line(device, split),
)
assertTrue(MemoryLog.line(device, split.copy(gpuKb = null)).endsWith("gpu ? MB"))
}
}
@@ -61,6 +61,8 @@ class NoSteamLaunchTest {
listOf("--app", "2733369024", "--dir", game.guestDir, "--options", "-windowed", "--", game.guestExe),
added.args,
)
val plain = NoSteamLaunch.addedCommand(AddedGames.Game(game.folder, game.name, game.exe, game.guestExe, game.guestDir, 2733369024L, 0L, emptyList(), source = "gog"))
assertEquals(listOf("--app", "2733369024", "--dir", game.guestDir, "--", game.guestExe), plain.args)
assertNull(NoSteamLaunch.command(shortcut, null))
val steam = NoSteamLaunch.command(steamGame, null)!!
assertEquals(listOf("--app", "413150"), steam.args)
@@ -20,7 +20,7 @@ class OrientationTest {
}
@Test fun landscapeChoicesPersistGloballyAndCanRestoreAutomaticRotation() {
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, SessionPrefs.orientation(context))
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
for (value in listOf(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,
@@ -34,7 +34,7 @@ class OrientationTest {
@Test fun invalidStoredOrientationFallsBackAndInvalidChoicePreservesTheSavedValue() {
val prefs = context.getSharedPreferences("session", Context.MODE_PRIVATE)
prefs.edit().putInt("orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT).commit()
assertEquals(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, SessionPrefs.orientation(context))
assertEquals(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, SessionPrefs.orientation(context))
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE)
assertThrows(IllegalArgumentException::class.java) {
SessionPrefs.setOrientation(context, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
@@ -0,0 +1,42 @@
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 offKeepsTodaysPacing() {
assertEquals(0, SessionPrefs.compositorFpsLimit(0, false))
assertEquals(60, SessionPrefs.compositorFpsLimit(60, false))
}
@Test fun onWithoutALimitIsUnpacedAndAChosenLimitStillPaces() {
assertEquals(SessionPrefs.FPS_UNPACED, SessionPrefs.compositorFpsLimit(0, true))
assertEquals(60, SessionPrefs.compositorFpsLimit(60, true))
}
@Test fun anOldUncappedFrameLimitReadsAsOff() {
session.edit().putInt("fpsLimit.steam", -1).commit()
assertEquals(0, SessionPrefs.fpsLimit(app, SessionService.MODE_STEAM))
assertFalse(SessionPrefs.fpsLimitChoices.any { it.first < 0 })
}
}
@@ -103,4 +103,28 @@ class ProtonDefaultTest {
assertNull(ProtonDefault.gameSelectedId(context, "42", listOf(proton("GE-Proton11-7", false))))
assertEquals(ProtonDefault.GameChoice(false, "GE-Proton9-1"), ProtonDefault.parseGames(file.readText())["42"])
}
@Test
fun aReplacedBuildsPerGamePicksMoveToTheNewest() {
val old = ProtonDefault.GameChoice(false, "DroidDeck-Proton 11-11.2")
val ge = ProtonDefault.GameChoice(false, "GE-Proton11-7")
val valve = ProtonDefault.GameChoice(true, "DroidDeck-Proton 11-11.2")
val moved = ProtonDefault.movedGames(mapOf("42" to old, "43" to ge, "44" to null, "45" to valve), setOf("DroidDeck-Proton 11-11.2"), "DroidDeck-Proton 11-11.4")
assertEquals(mapOf("42" to ProtonDefault.GameChoice(false, "DroidDeck-Proton 11-11.4"), "43" to ge, "44" to null, "45" to valve), moved)
assertNull(ProtonDefault.movedGames(mapOf("43" to ge, "44" to null), setOf("DroidDeck-Proton 11-11.2"), "DroidDeck-Proton 11-11.4"))
}
@Test
fun movingPicksRewritesTheGamesFile() {
val context = RuntimeEnvironment.getApplication()
val file = File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-compat/games.json")
file.parentFile?.deleteRecursively()
ProtonDefault.requestGame(context, "42", proton("DroidDeck-Proton 11-11.2", false))
ProtonDefault.requestGame(context, "43", null)
ProtonDefault.moveGames(context, setOf("DroidDeck-Proton 11-11.2"), "DroidDeck-Proton 11-11.4")
val games = ProtonDefault.parseGames(file.readText())
assertEquals(ProtonDefault.GameChoice(false, "DroidDeck-Proton 11-11.4"), games["42"])
assertTrue(games.containsKey("43"))
assertNull(games["43"])
}
}
@@ -171,4 +171,62 @@ class ProtonExtrasTest {
assertEquals(listOf("DroidDeck-Proton 11-7.10"), ProtonExtras.installedAll(context, tool("droiddeck")))
assertEquals("DroidDeck-Proton 11-7.10", ProtonExtras.installed(context, tool("droiddeck")))
}
@Test
fun removingABuildDropsItsStoredOriginalsAndSelections() {
val context = RuntimeEnvironment.getApplication()
val tools = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/compatibilitytools.d")
File(LinuxRuntime.rootDir(context), "root/.local/share/droiddeck-components").mkdirs()
installTool(tools, "GE-Proton11-7")
val kept = installTool(tools, "GE-Proton11-8").apply {
File(this, "files/lib/wine").mkdirs()
File(this, "proton").writeText("")
}
val originals = File(context.filesDir, "components/originals")
for (id in listOf("GE-Proton11-7", "GE-Proton11-8")) File(originals, "$id/$id/dxvk.wcp").apply { parentFile?.mkdirs(); writeText("x") }
val pick = JSONObject().put("dxvk", JSONObject().put("file", "dxvk.wcp").put("protonVersion", "GE-Proton11-7"))
File(context.filesDir, "components/state.json").writeText(JSONObject()
.put("active", JSONObject().put("GE-Proton11-7", pick).put("GE-Proton11-8", pick))
.put("queued", JSONObject().put("GE-Proton11-7", pick)).toString())
ProtonExtras.remove(context, tool("ge"), "GE-Proton11-7")
assertFalse(File(originals, "GE-Proton11-7").exists())
assertTrue(File(originals, "GE-Proton11-8/GE-Proton11-8/dxvk.wcp").isFile)
val state = JSONObject(File(context.filesDir, "components/state.json").readText())
assertFalse(state.getJSONObject("active").has("GE-Proton11-7"))
assertFalse(state.getJSONObject("queued").has("GE-Proton11-7"))
assertTrue(state.getJSONObject("active").has("GE-Proton11-8"))
ComponentsManager.forgetProton(context, kept.name)
assertTrue(File(originals, "GE-Proton11-8/GE-Proton11-8/dxvk.wcp").isFile)
}
@Test
fun anUpdateKeepsTheUsersProtonSettingsFile() {
val context = RuntimeEnvironment.getApplication()
val tools = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/compatibilitytools.d")
tools.deleteRecursively()
File(installTool(tools, "DroidDeck-Proton 11-11.1"), "user_settings.py").writeText("old")
File(installTool(tools, "DroidDeck-Proton 11-11.4"), "user_settings.py").writeText("mine")
installTool(tools, "DroidDeck-Proton 11-11.5")
ProtonExtras.tidy(context)
assertEquals(listOf("DroidDeck-Proton 11-11.5"), ProtonExtras.installedAll(context, tool("droiddeck")))
assertEquals("mine", File(tools, "DroidDeck-Proton 11-11.5/user_settings.py").readText())
}
@Test
fun droidDeckProtonIsFetchedWhenMissingUnlessTheUserRemovedIt() {
val context = RuntimeEnvironment.getApplication()
val tools = File(LinuxRuntime.rootDir(context), "root/.local/share/Steam/compatibilitytools.d")
tools.deleteRecursively()
File(context.filesDir, "proton-latest.json").writeText(
"""{"droiddeck":{"tag":"DroidDeck-Proton-11-11.4","at":1},"ge":{"tag":"GE-Proton11-7","at":1}}""")
ProtonExtras.setDeclined(context, false)
assertEquals("DroidDeck-Proton-11-11.4", ProtonExtras.missing(context, tool("droiddeck")))
assertNull(ProtonExtras.missing(context, tool("ge")))
ProtonExtras.setDeclined(context, true)
assertNull(ProtonExtras.missing(context, tool("droiddeck")))
ProtonExtras.setDeclined(context, false)
installTool(tools, "DroidDeck-Proton 11-11.2")
assertNull(ProtonExtras.missing(context, tool("droiddeck")))
assertEquals("DroidDeck-Proton-11-11.4", ProtonExtras.update(context, tool("droiddeck")))
}
}
@@ -96,7 +96,10 @@ class SessionDisplayTest {
@Test fun gameStretchAvailabilityMatchesTheRuntimeIncludingRounding() {
assertTrue(SessionDisplay.canStretch16x9(960 to 720))
assertFalse(SessionDisplay.canStretch16x9(1280 to 720))
assertFalse(SessionDisplay.canStretch16x9(1600 to 720))
assertTrue(SessionDisplay.canStretch16x9(1600 to 720))
assertTrue(SessionDisplay.canStretch16x9(2400 to 1080))
assertFalse(SessionDisplay.canStretch16x9(1920 to 1080))
assertFalse(SessionDisplay.canStretch16x9(1366 to 768))
val wide = SessionDisplay.resolve(1440 to 1080, 0, SessionPrefs.SHAPE_WIDE)
assertFalse(SessionDisplay.canStretch16x9(wide))
}
@@ -232,6 +232,20 @@ class SessionLogShareTest {
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") }
@@ -41,7 +41,7 @@ class SessionLogShareZipTest {
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 = "<unsupported or oversized line withheld>\n"
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) {
@@ -94,6 +94,34 @@ class SessionLogShareZipTest {
assertFalse(zip.exists())
}
@Test fun battleNetAndBlizzardLogsComeAlongScrubbedAndNewestFirst() {
val session = File(LinuxRuntime.logDir(app), "2026-10-25-05-battle-net").apply { mkdirs() }
File(session, "session.log").writeText("droiddeck-battlenet: open (from the menu)\n")
val root = LinuxRuntime.rootDir(app)
File(root, "root/.cache/droiddeck/battlenet").apply { mkdirs() }.apply {
resolve("battlenet.log").writeText("launching WoW\n")
resolve("other.log").writeText("other\n")
}
val drive = File(com.droiddeck.launcher.runtime.BattleNet.prefix(app), "pfx/drive_c")
val client = File(drive, "users/steamuser/AppData/Local/Battle.net/Logs").apply { mkdirs() }
val now = System.currentTimeMillis()
for (i in 1..8) client.resolve("battle.net-$i.log").apply { writeText("client $i accountId=1:0:5ca1ab1e\n"); setLastModified(now - i * 60_000L) }
client.resolve("battle.net-old.log").apply { writeText("old\n"); setLastModified(now - 30L * 86_400_000L) }
File(drive, "ProgramData/Battle.net/Agent/Agent.9824/Logs").apply { mkdirs() }.resolve("Agent-1.log").writeText("agent someone@example.com\n")
File(drive, "ProgramData/Battle.net/Agent/Agent.9900/Logs").apply { mkdirs() }.resolve("Agent-1.log").writeText("agent 9900\n")
File(drive, "ProgramData/Battle.net/Setup/bna_2/Logs").apply { mkdirs() }.resolve("battle.net-setup-1.log").writeText("setup\n")
val zip = SessionLogShare.zipFolder(app, session)!!
val text = ZipFile(zip).use { z -> z.entries().toList().associate { e -> e.name to z.getInputStream(e).bufferedReader().readText() } }
assertTrue(text.keys.containsAll(listOf("battlenet/droiddeck/battlenet.log", "battlenet/agent/Agent.9824/Agent-1.log", "battlenet/agent/Agent.9900/Agent-1.log", "battlenet/setup/bna_2/battle.net-setup-1.log")))
assertFalse(text.containsKey("battlenet/droiddeck/other.log"))
assertEquals((1..6).map { "battlenet/client/battle.net-$it.log" }.toSet(), text.keys.filter { it.startsWith("battlenet/client/") }.toSet())
val all = text.values.joinToString("\n")
assertFalse(all.contains("5ca1ab1e"))
assertFalse(all.contains("someone@example.com"))
SessionLogShare.clear(app)
}
@Test fun theSharePassChangesNothingInACleanLine() {
val line = "dxvk: Device 0x5 (Adreno 750) https://github.com/doitsujin/dxvk/releases code 403"
assertEquals(line, com.droiddeck.launcher.core.LogRedactor.redactForShare(line))
@@ -0,0 +1,62 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
class SessionSteamLogsTest {
@get:Rule val tmp = TemporaryFolder()
private fun names(files: List<File>) = files.map { it.name }.sorted()
@Test fun onlyWhatTheSessionWroteIsCollected() {
val logs = tmp.newFolder("logs")
val session = tmp.newFolder("session")
val out = tmp.newFolder("out")
File(logs, "console_log.txt").writeText("old line\n")
File(logs, "cef_log.txt").writeText("old cef\n")
File(logs, "cef_log.previous.txt").writeText("older cef\n")
File(logs, "shrunk.txt").writeText("a long old line\n")
File(logs, "untouched.txt").writeText("nothing new\n")
SessionArtifacts.markSteamLogs(session, logs)
File(logs, "console_log.txt").appendText("new line\n")
File(logs, "cef_log.previous.txt").delete()
File(logs, "cef_log.txt").renameTo(File(logs, "cef_log.previous.txt"))
File(logs, "cef_log.txt").writeText("this session's cef\n")
File(logs, "shrunk.txt").writeText("short\n")
File(logs, "content_log.txt").writeText("created this session\n")
val copied = SessionArtifacts.copySessionLogs(logs, session, out)
assertEquals(listOf("cef_log.txt", "console_log.txt", "content_log.txt", "shrunk.txt"), names(copied))
assertEquals("new line\n", File(out, "console_log.txt").readText())
assertEquals("this session's cef\n", File(out, "cef_log.txt").readText())
assertEquals("short\n", File(out, "shrunk.txt").readText())
assertFalse(File(out, "cef_log.previous.txt").exists())
assertFalse(File(out, "untouched.txt").exists())
}
@Test fun aLineCutByTheMarkIsLeftOut() {
val logs = tmp.newFolder("logs")
val session = tmp.newFolder("session")
val out = tmp.newFolder("out")
File(logs, "web.txt").writeText("old\nGET /x?sessionid=")
SessionArtifacts.markSteamLogs(session, logs)
File(logs, "web.txt").appendText("abcdef123456 200\nnext line\n")
SessionArtifacts.copySessionLogs(logs, session, out)
assertEquals("next line\n", File(out, "web.txt").readText())
}
@Test fun withoutMarksEveryLogUnderTheCapIsCollectedAndRedacted() {
val logs = tmp.newFolder("logs")
val out = tmp.newFolder("out")
File(logs, "web.txt").writeText("GET /x?sessionid=abcdef123456 200\n")
File(logs, "big.txt").outputStream().use { it.write(ByteArray(8 * 1024 * 1024)) }
val copied = SessionArtifacts.copySessionLogs(logs, tmp.newFolder("session"), out)
assertEquals(listOf("web.txt"), names(copied))
assertFalse(File(out, "web.txt").readText().contains("abcdef123456"))
}
}
@@ -101,6 +101,28 @@ class SteamDownloadMonitorTest {
}
}
@Test fun aLongLogIsFollowedFromWhereTheLastPollStopped() {
val root = Files.createTempDirectory("droiddeck-steam-download-").toFile()
try {
val contentLog = File(root, "root/.local/share/Steam/logs/content_log.txt").apply {
check(parentFile?.mkdirs() != false)
writeText(buildString {
repeat(5_000) { append("[2026-10-06 14:40:00] Detected write gap 64 MB in file \"data_$it.dat\"\r\n") }
append("[2026-10-06 14:44:17] AppID 44 App update changed : Running Update,Downloading,\r\n")
})
}
val monitor = SteamDownloadMonitor()
assertTrue(monitor.poll(root, now = 1_000L))
contentLog.appendText("[2026-10-06 14:45:03] AppID 44 App update changed : None\r\n")
assertFalse(monitor.poll(root, now = 2_000L))
contentLog.appendText("[2026-10-06 14:46:00] AppID 45 App update changed : Running Update,Downloading,\r\n")
assertTrue(monitor.poll(root, now = 3_000L))
} finally {
root.deleteRecursively()
}
}
@Test fun theOtherClientsLogIsReadFromItsStart() {
val root = Files.createTempDirectory("droiddeck-steam-download-").toFile()
try {
@@ -203,6 +225,38 @@ class SteamDownloadMonitorTest {
}
}
@Test fun theClientIsPendingUntilItIsInstalledAndStamped() {
val root = Files.createTempDirectory("droiddeck-steam-client-").toFile()
try {
val steam = File(root, "root/.local/share/Steam")
assertTrue(SteamDownloadMonitor.clientInstallPending(root))
File(steam, "steamrtarm64").mkdirs()
File(steam, "steamrtarm64/steam").writeText("client")
assertTrue(SteamDownloadMonitor.clientInstallPending(root))
File(steam, "package").mkdirs()
File(steam, "package/droiddeck-installed").writeText("1791686101\n")
assertFalse(SteamDownloadMonitor.clientInstallPending(root))
} finally {
root.deleteRecursively()
}
}
@Test fun anOlderStampCountsAndARepairRequestIsPending() {
val root = Files.createTempDirectory("droiddeck-steam-client-").toFile()
try {
val steam = File(root, "root/.local/share/Steam")
File(steam, "steamrtarm64").mkdirs()
File(steam, "steamrtarm64/steam").writeText("client")
File(steam, "package").mkdirs()
File(steam, "package/bannerlator-installed").writeText("1\n")
assertFalse(SteamDownloadMonitor.clientInstallPending(root))
File(root, "root/.bl-steam-repair").writeText("1\n")
assertTrue(SteamDownloadMonitor.clientInstallPending(root))
} finally {
root.deleteRecursively()
}
}
private fun manifest(root: File, appId: String, downloaded: Long, total: Long, flags: Int): File {
val file = File(root, "steamapps/appmanifest_$appId.acf")
check(file.parentFile?.mkdirs() != false)
@@ -13,9 +13,33 @@ class SyncBackendTest {
private val context: Context = RuntimeEnvironment.getApplication()
@Test
fun aFreshInstallStartsOnEsync() {
assertEquals(SessionPrefs.SYNC_ESYNC, SessionPrefs.syncBackend(context))
fun aFreshInstallStartsOnNtsync() {
assertEquals(SessionPrefs.SYNC_NTSYNC, SessionPrefs.syncBackend(context))
assertEquals(false, SessionPrefs.fsyncFirst(context))
SessionPrefs.applyNtsyncDefault(context)
assertEquals(SessionPrefs.SYNC_NTSYNC, SessionPrefs.syncBackend(context))
}
@Test
fun anEarlierChoiceMovesToNtsyncOnce() {
for (earlier in listOf(SessionPrefs.SYNC_ESYNC, SessionPrefs.SYNC_FSYNC, SessionPrefs.SYNC_WINESERVER)) {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
SessionPrefs.setSyncBackend(context, earlier)
SessionPrefs.applyNtsyncDefault(context)
assertEquals(SessionPrefs.SYNC_NTSYNC, SessionPrefs.syncBackend(context))
}
}
@Test
fun aChoiceMadeAfterTheMoveIsKept() {
SessionPrefs.setSyncBackend(context, SessionPrefs.SYNC_ESYNC)
SessionPrefs.applyNtsyncDefault(context)
SessionPrefs.setSyncBackend(context, SessionPrefs.SYNC_ESYNC)
SessionPrefs.applyNtsyncDefault(context)
assertEquals(SessionPrefs.SYNC_ESYNC, SessionPrefs.syncBackend(context))
SessionPrefs.setSyncBackend(context, SessionPrefs.SYNC_WINESERVER)
SessionPrefs.applyNtsyncDefault(context)
assertEquals(SessionPrefs.SYNC_WINESERVER, SessionPrefs.syncBackend(context))
}
@Test
@@ -34,6 +58,7 @@ class SyncBackendTest {
@Test
fun pickingATabTurnsSyncBackOn() {
SessionPrefs.setFastSync(context, false)
SessionPrefs.setSyncFallback(context, false)
SessionPrefs.setFsyncFirst(context, false)
assertEquals(SessionPrefs.SYNC_WINESERVER, SessionPrefs.syncBackend(context))
@@ -0,0 +1,55 @@
package com.droiddeck.launcher.session
import android.content.Context
import com.droiddeck.launcher.gpu.TpUbwcHint
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 org.robolectric.util.ReflectionHelpers
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class TpUbwcPrefsTest {
private val context: Context get() = RuntimeEnvironment.getApplication()
@Before fun reset() {
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "resolved", false)
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "cached", null)
ReflectionHelpers.setStaticField(TpUbwcHint::class.java, "activeMode", null)
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun missingOrInvalidChoiceUsesAuto() {
assertEquals(SessionPrefs.TP_UBWC_AUTO, SessionPrefs.tpUbwcMode(context))
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit().putString("tpUbwcMode", "invalid").commit()
assertEquals(SessionPrefs.TP_UBWC_AUTO, SessionPrefs.tpUbwcMode(context))
}
@Test fun overrideIsStoredWithoutChangingDriverChoices() {
SessionPrefs.setAndroidDriver(context, "display")
SessionPrefs.setLinuxDriver(context, "runtime")
for (mode in listOf(SessionPrefs.TP_UBWC_ON, SessionPrefs.TP_UBWC_OFF, SessionPrefs.TP_UBWC_AUTO)) {
SessionPrefs.setTpUbwcMode(context, mode)
assertEquals(mode, SessionPrefs.tpUbwcMode(context))
assertEquals("display", SessionPrefs.androidDriver(context))
assertEquals("runtime", SessionPrefs.linuxDriver(context))
}
}
@Test fun changingTheSavedChoiceKeepsTheProcessChoiceUntilRestart() {
SessionPrefs.setTpUbwcMode(context, SessionPrefs.TP_UBWC_ON)
val initial = TpUbwcHint.forThisDevice(context)
SessionPrefs.setTpUbwcMode(context, SessionPrefs.TP_UBWC_OFF)
assertTrue(TpUbwcHint.restartRequired(context))
assertEquals(SessionPrefs.TP_UBWC_ON, TpUbwcHint.activeMode)
assertEquals(initial, TpUbwcHint.forThisDevice(context))
SessionPrefs.setTpUbwcMode(context, SessionPrefs.TP_UBWC_ON)
assertFalse(TpUbwcHint.restartRequired(context))
}
}
@@ -31,6 +31,14 @@ class WinComponentsSupportTest {
step("install_msi", "url" to "$base/ps-x86.msi"), step("install_msi", "url" to "$base/ps-x64.msi"))))
}
@Test fun builtInArm64RuntimeIsRegistryOnlyInBothViews() {
val c = WinComponents.builtInArm64Runtime()
assertEquals(Support.READY, support(c))
assertEquals(12, c.steps.count { it.action == "set_register_key" })
assertEquals(setOf("HKLM\\Software\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\arm64",
"HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\arm64"), c.steps.map { it.str("key") }.toSet())
}
@Test fun installerWrappersInstallHere() {
assertEquals(Support.READY, support(component("vcredist2022",
step("install_exe", "url" to "$base/vcredist2022__VC_redist.x86.exe", "file_name" to "VC_redist.x86.exe"),
@@ -0,0 +1,23 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class WineProcessesTest {
private fun argv(vararg args: String) = args.joinToString("\u0000", postfix = "\u0000").toByteArray()
@Test fun aWineserverIsKnownByItsProgramOrItsName() {
assertTrue(WineProcesses.isWineserver(argv("/root/.local/share/droiddeck-esync/dist/valve-11/files/bin-arm64/wineserver"), "wineserver\n"))
assertTrue(WineProcesses.isWineserver(argv("wineserver", "-p0"), null))
assertTrue(WineProcesses.isWineserver(null, "wineserver\n"))
assertTrue(WineProcesses.isWineserver(ByteArray(0), "wineserver"))
}
@Test fun nothingElseIs() {
assertFalse(WineProcesses.isWineserver(argv("C:\\windows\\system32\\services.exe"), "services.exe\n"))
assertFalse(WineProcesses.isWineserver(argv("/usr/bin/python3", "/x/files/bin-arm64/wineserver"), "python3\n"))
assertFalse(WineProcesses.isWineserver(argv("/opt/wineserver-helper"), "wineserver-help"))
assertFalse(WineProcesses.isWineserver(null, null))
}
}