From 3636f9dd7144952dfd1bd26a739b1bbbb67dc3c6 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 9 Aug 2023 20:33:08 +0200 Subject: [PATCH] [FP/MT Test] Fix CPU affinity for thread isolation on hardware agents In some builds on hardware agents, we use a linux container without `ps` command; it causes isolation logic to execute partially. This change removes the usage of `ps` and replaces it with a direct listing of the procfs. --- .../kotlin/fir/FirResolveModularizedTotalKotlinTest.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt index 5134359c081..36d64c5cad7 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt @@ -39,6 +39,7 @@ import java.io.File import java.io.FileOutputStream import java.io.PrintStream import java.lang.management.ManagementFactory +import java.util.regex.Pattern private const val FAIL_FAST = true @@ -71,7 +72,12 @@ internal fun isolate() { println("Trying to set affinity, other: '$othersList', isolated: '$isolatedList'") if (othersList != null) { println("Will move others affinity to '$othersList'") - ProcessBuilder().command("bash", "-c", "ps -ae -o pid= | xargs -n 1 taskset -cap $othersList ").inheritIO().start().waitFor() + val pidRegex = "[0-9]+".toRegex() + File("/proc/").listFiles()?.forEach { + if (it.resolve("stat").exists() && it.name.matches(pidRegex)) { + ProcessBuilder().command("taskset", "-cap", othersList, it.name).inheritIO().start().waitFor() + } + } } if (isolatedList != null) { val selfPid = CLibrary.INSTANCE.getpid() @@ -292,7 +298,7 @@ class FirResolveModularizedTotalKotlinTest : AbstractFrontendModularizedTest() { class FirCheckersResolveProcessor( session: FirSession, - scopeSession: ScopeSession + scopeSession: ScopeSession, ) : FirTransformerBasedResolveProcessor(session, scopeSession, phase = null) { val diagnosticCollector: AbstractDiagnosticCollector = FirDiagnosticsCollector.create(session, scopeSession)