summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-09-14 02:46:21 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-09-14 02:46:21 +0000
commit58b11ca46b05aec56c4ed2323dc39ae7f37082ef (patch)
treed5e92d583b2b5792ba20132a7762c6cbb82cbe1e
parenta2931e6d20bf6941b5d98488d98571da68c29370 (diff)
parent3997833994e1e4b8c40618a81834ba995549bc74 (diff)
Merge "UinputRecordingIntegrationTests: Add a debug mode to log received events" into main
-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 -")