Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit febf3030 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Write dumpOnFailure to app files

The DumpOnFailure utility was trying to write to /sdcard/DumpOnFailure,
which would fail if the test app did not have the permission for
external storage. Instead, we can simply write to the files of the test
app, and pull from there, removing and requirements on permissions.

This also removes the manual cleanup of these files, instead delegating
it to the FilePullerLogCollector, which will only clean up after
successfully reading the files.

This also adds the dumpOnFailure for IME tests that use UiDevice.
Lastly, it changes the manifest of these tests to refer to the real
package name, for consistency.

Flag: EXEMPT testfix
Bug: 395783236
Test: atest InputMethodServiceTest
Change-Id: I6dece3f39a2f3ee3273b6ef12e3314f807d3457f
parent 4fb4149e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
  -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.inputmethod.imetests">
          package="com.android.inputmethodservice">

    <!-- Permissions required for granting and logging -->
    <uses-permission android:name="android.permission.LOG_COMPAT_CHANGE"/>
@@ -33,7 +33,7 @@
    </application>

    <!-- The "targetPackage" reference the instruments APK package, which is the SimpleTestIme.apk,
    while the test package is "com.android.inputmethod.imetests" (FrameworksImeTests.apk).-->
    while the test package is "com.android.inputmethodservice" (FrameworksImeTests.apk).-->
    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="com.android.apps.inputmethod.simpleime"
+4 −3
Original line number Diff line number Diff line
@@ -34,14 +34,15 @@
    <option name="test-tag" value="FrameworksImeTests" />

    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="com.android.inputmethod.imetests" />
        <option name="package" value="com.android.inputmethodservice" />
        <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
        <option name="hidden-api-checks" value="false"/>
    </test>

    <!-- Collect the files in the dump directory for debugging -->
    <!-- Collect output of DumpOnFailure -->
    <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
        <option name="directory-keys" value="/sdcard/FrameworksImeTests/" />
        <option name="directory-keys" value="/data/user/0/com.android.apps.inputmethod.simpleime/files" />
        <option name="collect-on-run-ended-only" value="true" />
        <option name="clean-up" value="true" />
    </metrics_collector>
</configuration>
+10 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.os.Build;
import android.os.RemoteException;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.Settings;
import android.server.wm.DumpOnFailure;
import android.server.wm.WindowManagerStateHelper;
import android.util.Log;
import android.view.WindowManagerGlobal;
@@ -118,6 +119,9 @@ public class InputMethodServiceTest {
    @Rule
    public final TestName mName = new TestName();

    @Rule
    public final DumpOnFailure mDumpOnFailure = new DumpOnFailure();

    private Instrumentation mInstrumentation;
    private UiDevice mUiDevice;
    private InputMethodManager mImm;
@@ -1210,8 +1214,13 @@ public class InputMethodServiceTest {

    @NonNull
    private UiObject2 getUiObject(@NonNull BySelector bySelector) {
        final var preScreenshot = mInstrumentation.getUiAutomation().takeScreenshot();
        mDumpOnFailure.dumpOnFailure("pre-getUiObject", preScreenshot);
        final var uiObject = mUiDevice.wait(Until.findObject(bySelector), TIMEOUT_MS);
        assertWithMessage("UiObject with " + bySelector + " was found").that(uiObject).isNotNull();
        mInstrumentation.waitForIdleSync();
        final var postScreenshot = mInstrumentation.getUiAutomation().takeScreenshot();
        mDumpOnFailure.dumpOnFailure("post-getUiObject", postScreenshot);
        assertWithMessage("UiObject with " + bySelector + " was found").that(uiObject).isNull();
        return uiObject;
    }