-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Save am instrument
logs to file & handle parsing error.
#2049
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfb2b89
Save `am instrument` logs to file.
jan-goral 0ece007
Update flank_corellium.md
jan-goral 6504f83
Fix lint
jan-goral 492ccac
Fix formatting
jan-goral 1c5e909
Merge branch 'master' into 2037_Handle_am_instrument_errors
Sloox ebf3411
Add unmockkAll to ExecuteAndroidTestPlanKtTest.kt
jan-goral File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
corellium/adapter/src/test/kotlin/flank/corellium/adapter/ExecuteAndroidTestPlanKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package flank.corellium.adapter | ||
|
||
import flank.corellium.api.AndroidTestPlan | ||
import flank.corellium.client.console.Console | ||
import flank.corellium.client.console.close | ||
import flank.corellium.client.console.flowLogs | ||
import flank.corellium.client.console.sendCommand | ||
import flank.corellium.client.core.Corellium | ||
import flank.corellium.client.core.connectConsole | ||
import io.mockk.coEvery | ||
import io.mockk.coVerify | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkAll | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.channelFlow | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class ExecuteAndroidTestPlanKtTest { | ||
|
||
/** | ||
* Connection to [Console] should be closed once subscription detach. | ||
*/ | ||
@Test | ||
fun closeConsole() { | ||
// given | ||
mockkStatic( | ||
"flank.corellium.client.console.ApiKt", | ||
"flank.corellium.client.core.ApiKt", | ||
) | ||
|
||
val instanceId = "1" | ||
val command = "command" | ||
val emitted = mutableListOf<Char>() | ||
val range = ('a'..'z') | ||
val linesFlow: Flow<String> = channelFlow { range.forEach { send("$it"); emitted += it; delay(10) } } | ||
val config = AndroidTestPlan.Config(mapOf(instanceId to listOf(command))) | ||
|
||
val console: Console = mockk(relaxed = true) { | ||
val context = Job() | ||
every { flowLogs() } returns linesFlow | ||
every { coroutineContext } returns context | ||
} | ||
|
||
val corellium: Corellium = mockk(relaxed = true) { | ||
coEvery { connectConsole(instanceId) } returns console | ||
} | ||
|
||
val flow: Flow<String> = executeAndroidTestPlan { corellium } | ||
.invoke(config).first().second | ||
|
||
// when | ||
runBlocking { flow.first { it == "c" } } // Detach the subscription after "c" element | ||
|
||
// then | ||
coVerify(exactly = 1) { console.sendCommand(command) } // Verify sendCommand called. | ||
coVerify(exactly = 1) { console.close() } // Verify console close. | ||
Assert.assertNotEquals(range.last, emitted.last()) // Check the emission not reach last element. | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
unmockkAll() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,6 +232,13 @@ internal val format = buildFormatter<String> { | |
else -> null | ||
} | ||
} | ||
ExecuteTests.Error::class { | ||
""" | ||
Error while parsing results from instance $id. | ||
For details check $logFile lines $lines. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line left intentionally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup |
||
""".trimIndent() + cause.stackTraceToString() | ||
} | ||
RunTestCorelliumAndroid.Created { "Created $path" } | ||
RunTestCorelliumAndroid.AlreadyExist { "Already exist $path" } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
unmockkAll()
tear down method -- unmocked tests may interact between test suites (we had this issue couple of times in the past)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed