Android UI Test crashing on Android Emulator (but fine on physical devices) running Android P+ due to various SIGSEGV at random time
See original GitHub issuePrerequisites
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
Expected Behavior
Using MockK on Android UI Tests should work on any emulator running Android 9+ as it does on physical devices.
Current Behavior
On the emulator, most of the time, a test (as part of a test class file) using mockK feature will fail randomly with the following message:
Test failed to run to completion. Reason: ‘Instrumentation run failed due to ‘Process crashed.’’. Check device logcat for details Test running failed: Instrumentation run failed due to ‘Process crashed.’
This so-called crash can come as early as right before the 1st test could event start or happen right in the middle of the tests sequence. It’s quite random regardless of the test order.
Also, in very rare cases, the crash might not occur and all tests pass. But again, way too random.
Failure Information (for bugs)
In most cases, the crash reason was printed in the logs. Most of them are SIGENV but the cause of it can vary, without any clear reasons. Looking deeper in the logs there seem to be an issue related to the InputDispatcher:
InputDispatcher: channel ‘9fa7335 my.company.com.android.debug/my.company.com.ui.login.LoginActivity(server)’ ~ Channel is unrecoverably broken and will be disposed!
Looking on SO about that message, it seams it could be related to some threading issue when manipulating Activities that are not “active”.
Steps to Reproduce
Unfortunately I cannot provide the code to reproduce the issue. However, my usage of mockK features is as follow, in a MVP architecture:
@Before fun setUp()will callmockkObjectbefore each test to mock various Repositories and Services Kotlin Objects@After fun teardDown()will callunmockkAllto clean mocks after each test.coEveryandeveryto mock the relevent methods call in order to return custom values for the SUTverifywhen I need to make sure a specific method was used
These tests also include Espresso View assertions to validate the UI being displayed.
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- MockK version: 1.10.0
- OS: Windows 10
- Kotlin version: 1.3.72’
- JDK version: 1.8.0_242-release
- JUnit version: 4.12
- Type of test: android instrumented test
Failure Logs
Here are some of the SIGSEGV I could catch in the logs:
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 10425 (e.android.debug), pid 10425 (e.android.debug)
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xc in tid 10968 (HeapTaskDaemon), pid 10957 (e.android.debug)
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 15050 (firebase-instal), pid 14972 (e.android.debug)
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xd in tid 8902 (Measurement Wor), pid 8858 (e.android.debug)
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 22004 (Binder:21832_5), pid 21832 (e.android.debug)
In two cases, I had very different reasons:
E/OpenGLRenderer: GL error: 0x506 A/OpenGLRenderer: glViewport error! UNKNOWN (0x506) A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 11968 (RenderThread), pid 11862 (e.android.debug)
E/e.android.debu: Thread[ThreadState[0],Thread*=0xe9481c10,peer=0x0,“null”] suspend count already zero.
Minimal reproducible code (the gist of this issue)
// -----------------------[ GRADLE DEFINITIONS ] -----------------------
dependencies {
// JUnit
testImplementation "junit:junit:$junit_version"
androidTestImplementation "androidx.test.ext:junit-ktx:$androidx_test_junit_ktx_version"
// Unit Testing
testImplementation "io.mockk:mockk:$mockk_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_test_version"
testImplementation "org.robolectric:robolectric:$robolectric_version"
// Android X Testing
androidTestImplementation "androidx.test:core:$androidx_test_version"
androidTestImplementation "androidx.test:rules:$androidx_test_version"
androidTestImplementation "androidx.test:runner:$androidx_test_version"
// Fragment Testing
debugImplementation "androidx.fragment:fragment-testing:$fragment_test_version"
debugImplementation "androidx.fragment:fragment-ktx:$fragment_test_version"
// Espresso Testing
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espresso_version"
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
// Mock Testing
androidTestImplementation "io.mockk:mockk-android:$mockk_version"
// variables for versions
androidx_test_version = "1.2.0"
androidx_test_junit_ktx_version = "1.1.1"
espresso_version = "3.2.0"
fragment_test_version = "1.2.5"
junit_version = "4.12"
kotlin_coroutines_test_version = "1.3.7"
robolectric_version = "4.3.1"
mockk_version = "1.10.0"
}
Finally, before deciding to poste this issue, I investigated more and I posted my issue on SO: https://stackoverflow.com/questions/63059986/android-ui-tests-with-espresso-mockk-crash-with-sigsegv
And after further investigation, some other people posted it on the android-test Github repo more than a year ago: https://github.com/android/android-test/issues/352.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:20
- Comments:32 (2 by maintainers)

Top Related StackOverflow Question
This should not be closed
This was in our stacktrace:
Switching to a 64 bit emulator solved the problem.