summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2024-09-06 19:05:03 +0000
committer Prabir Pradhan <prabirmsp@google.com> 2024-09-13 19:09:28 +0000
commit3997833994e1e4b8c40618a81834ba995549bc74 (patch)
treee514982d0d344b9bb71334cf0c67dccf8d6039b4
parent00f0da0e826a6e5c3ec6cb9fe093b11d0043bc3e (diff)
UinputRecordingIntegrationTests: Add a debug mode to log received events
This will make it easier to initially generate the source-of-truth file for received events. Bug: 310997010 Test: Presubmit Flag: TEST_ONLY Change-Id: If5ea181283ceef0441df5d29da7e1f2b34e14fbd
-rw-r--r--tests/Input/src/com/android/test/input/UinputRecordingIntegrationTests.kt29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/Input/src/com/android/test/input/UinputRecordingIntegrationTests.kt b/tests/Input/src/com/android/test/input/UinputRecordingIntegrationTests.kt
index 5d45c44a53cd..aa73c397a663 100644
--- a/tests/Input/src/com/android/test/input/UinputRecordingIntegrationTests.kt
+++ b/tests/Input/src/com/android/test/input/UinputRecordingIntegrationTests.kt
@@ -21,7 +21,9 @@ import android.cts.input.EventVerifier
import android.graphics.PointF
import android.hardware.input.InputManager
import android.os.ParcelFileDescriptor
+import android.util.Log
import android.util.Size
+import android.view.InputEvent
import android.view.MotionEvent
import androidx.test.platform.app.InstrumentationRegistry
import com.android.cts.input.BatchedEventSplitter
@@ -35,6 +37,7 @@ import com.android.cts.input.inputeventmatchers.withPressure
import com.android.cts.input.inputeventmatchers.withRawCoords
import com.android.cts.input.inputeventmatchers.withSource
import java.io.InputStream
+import junit.framework.Assert.fail
import org.hamcrest.Matchers.allOf
import org.junit.Before
import org.junit.Rule
@@ -70,7 +73,13 @@ class UinputRecordingIntegrationTests {
),
)
+ /**
+ * Use the debug mode to see the JSON-encoded received events in logcat.
+ */
+ const val DEBUG_RECEIVED_EVENTS = false
+
const val INPUT_DEVICE_SOURCE_ALL = -1
+ val TAG = UinputRecordingIntegrationTests::class.java.simpleName
}
class TestData(
@@ -121,9 +130,15 @@ class UinputRecordingIntegrationTests {
scenario.virtualDisplay.display.uniqueId!!,
)
+ injectUinputEvents()
+
+ if (DEBUG_RECEIVED_EVENTS) {
+ printReceivedEventsToLogcat(scenario.activity)
+ fail("Test cannot pass in debug mode!")
+ }
+
val verifier =
EventVerifier(BatchedEventSplitter { scenario.activity.getInputEvent() })
- injectUinputEvents()
verifyEvents(verifier)
scenario.activity.assertNoEvents()
} finally {
@@ -135,6 +150,18 @@ class UinputRecordingIntegrationTests {
}
}
+ private fun printReceivedEventsToLogcat(activity: CaptureEventActivity) {
+ val getNextEvent = BatchedEventSplitter { activity.getInputEvent() }
+ var receivedEvent: InputEvent? = getNextEvent()
+ while (receivedEvent != null) {
+ Log.d(TAG,
+ parser.encodeEvent(receivedEvent)?.toString()
+ ?: "(Failed to encode received event)"
+ )
+ receivedEvent = getNextEvent()
+ }
+ }
+
private fun injectUinputEvents() {
val fds = instrumentation.uiAutomation!!.executeShellCommandRw("uinput -")