question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Prerequisites

  • 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 call mockkObject before each test to mock various Repositories and Services Kotlin Objects
  • @After fun teardDown() will call unmockkAll to clean mocks after each test.
  • coEvery and every to mock the relevent methods call in order to return custom values for the SUT
  • verify when 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:open
  • Created 3 years ago
  • Reactions:20
  • Comments:32 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
eric-labellecommented, Jun 28, 2021

This should not be closed

5reactions
cristancommented, Nov 27, 2020

This was in our stacktrace:

  W  Unexpected CPU variant for X86 using defaults: x86
         ActivityThread  W  Package uses different ABI(s) than its instrumentation:

Switching to a 64 bit emulator solved the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android UI tests with Espresso + MockK crash with SIGSEGV ...
This is far from a true solution, but I've noticed that running MY tests with Android Test Orchestrator greatly reduces the chance of...
Read more >
Troubleshoot known issues with Android Emulator
This page lists known issues, workarounds, and troubleshooting tips for the Android Emulator. If you encounter an issue not listed here or ...
Read more >
Snapshot - Emulator start produces segmentation fault after ...
Create avd with default settings: android create avd -n test -t 5 ... Emulator start crashes and produces a segmentation fault when "Initializing...
Read more >
Dealing with emulator issues and Android UI test failures on CI
Let's dig deeper into emulator and UI test-related issues for Android! The last article of our Android testing series by Richard Bogdan, ...
Read more >
Crash on Android with signal 11 (SIGSEGV), code 1 ...
It launches one time in five, then works ok (relatively - stable 30 fps without any crashes for the whole game). I stopped...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found