Default Snapdragon 8 Gen 2 core allocation (#654)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-12 16:26:24 -04:00
1 parent a7662ae13a
commit 5e5ffee93e
9 files changed
+209 -19

No files matched your search

@@ -0,0 +1,42 @@
package com.droiddeck.launcher.core
import org.junit.Assert.*
import org.junit.Test
class CpuAllocationDefaultsTest {
private val thor = (0..7).associateWith { when (it) { in 0..2 -> 2.016; in 3..6 -> 2.8032; else -> 3.1872 } }
@Test fun gen2UsesTheFourMiddleCoresAndOnePrime() {
for (model in listOf("SM8550", "QCS8550", "sm8550-ac")) {
assertEquals(CpuAllocationDefaults.Allocation("7", "3,4,5,6"), CpuAllocationDefaults.forDevice(model, "", thor))
}
assertEquals(CpuAllocationDefaults.Allocation("7", "3,4,5,6"), CpuAllocationDefaults.forDevice("", "kalama", thor))
}
@Test fun coreNumbersAndClockVariantsAreDetectedInsteadOfHardcoded() {
val reordered = mapOf(0 to 3.36, 1 to 2.0, 2 to 2.0, 3 to 2.0, 4 to 2.8, 5 to 2.8, 6 to 2.8, 7 to 2.8)
assertEquals(CpuAllocationDefaults.Allocation("0", "4,5,6,7"), CpuAllocationDefaults.forDevice("SM8550-AC", "kalama", reordered))
}
@Test fun anotherOrUnknownChipDoesNotAcquireThisDefault() {
assertNull(CpuAllocationDefaults.forDevice("SM8650", "pineapple", thor))
assertNull(CpuAllocationDefaults.forDevice("SM8650", "kalama", thor))
assertNull(CpuAllocationDefaults.forDevice("", "", thor))
}
@Test fun missingOrUnexpectedTopologyKeepsTheSchedulerDefault() {
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor - 7))
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to null)))
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to 0.0)))
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", thor + (7 to Double.NaN)))
assertNull(CpuAllocationDefaults.forDevice("SM8550", "kalama", (0..7).associateWith { 2.8 }))
}
@Test fun allCoreGamesUndoTheClientsInheritedRestriction() {
val all = CpuCores.listOrAll("")
assertEquals(all, CpuCores.gameLaunchList("", clientPinned = true))
assertEquals(all, CpuCores.gameLaunchList(all, clientPinned = true))
assertEquals("", CpuCores.gameLaunchList("", clientPinned = false))
assertEquals("0", CpuCores.gameLaunchList("0", clientPinned = true))
}
}
@@ -0,0 +1,49 @@
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
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 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 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))
}
}