Skip to content

Commit

Permalink
feat(apple): improve detectTestType (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy authored Jul 4, 2024
1 parent f7542b1 commit 3c52c1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ open class AppleApplicationInstaller<in T : AppleDevice>(
* Detect presence of XCUIApplication in the test binary
*/
private suspend fun detectTestType(device: AppleDevice, remoteTestBinary: String): TestType {
val output = device.binaryEnvironment.nm.list(remoteTestBinary)
val output = device.binaryEnvironment.nm.list(remoteTestBinary, setOf("KIFTestCase", "XCUIApplication"))
/**
* All bundles containing XCUIApplication should be treated as xcuitest target except:
* - KIF-Framework where tests are actually xctest unit tests. This is detected by presence of test case base class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ class Nm(
private val timeoutConfiguration: TimeoutConfiguration,
) {
private val logger = MarathonLogging.logger {}
suspend fun list(path: String): List<String> {
return criticalExec(timeoutConfiguration.shell, path).successfulOrNull()?.stdout
?: throw DeviceSetupException("failed to extract symbol table from $path")

/**
* Instead of listing all the symbols (potentially hundreds of MBs)
* we grep for substrings we're interested in and return only the
* strings we might be interested in
*
* Warning: prefilter should not contain ' characters
*/
suspend fun list(path: String, prefilter: Set<String>): List<String> {
if (prefilter.any { it.contains("'") }) {
throw RuntimeException("nm list prefilter should not contain symbol \"'\"")
}
val filter = prefilter.joinToString(" ") { "-e \"$it\"" }
return listSymbolsVia(path, "'nm \"$path\" | grep $filter'")
}


/**
*
* -g Display only global (external) symbols.
Expand Down Expand Up @@ -64,7 +76,6 @@ class Nm(
): CommandResult {
return commandExecutor.criticalExecute(timeout, "nm", *args)
}

companion object {
const val MAX_XARGS = 131072
}
Expand Down

0 comments on commit 3c52c1d

Please sign in to comment.