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

Commit 708e800c authored by Chalard Jean's avatar Chalard Jean
Browse files

Add a test for the interpreter

Just a basic test. If the interpreter is broken one of the tests
using it will break anyway ; the only important thing is to make
sure that it's actually running the tests and actually reporting
failures, if any. So here's a test doing that.

Test: atest FrameworksNetTests NetworkStackTests
Change-Id: I84ce651a6e3b64aa94daa5ee1fe014b27d2fba76
parent e601bd12
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
package com.android.testutils

// This function is private because the 2 is hardcoded here, and is not correct if not called
// directly from __LINE__ or __FILE__.
private fun callerStackTrace(): StackTraceElement = try {
    throw RuntimeException()
} catch (e: RuntimeException) {
    e.stackTrace[2] // 0 is here, 1 is get() in __FILE__ or __LINE__
}
val __FILE__: String get() = callerStackTrace().fileName
val __LINE__: Int get() = callerStackTrace().lineNumber
+23 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.net.testutils
import android.os.SystemClock
import com.android.testutils.ArrayTrackRecord
import com.android.testutils.TrackRecord
import com.android.testutils.__FILE__
import com.android.testutils.__LINE__
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
@@ -207,6 +209,27 @@ class TrackRecordTest {
        assertTrue(delay > SHORT_TIMEOUT)
    }

    // Just make sure the interpreter actually throws an exception when the spec
    // does not conform to the behavior. The interpreter is just a tool to test a
    // tool used for a tool for test, let's not have hundreds of tests for it ;
    // if it's broken one of the tests using it will break.
    @Test
    fun testInterpreter() {
        val interpretLine = __LINE__ + 2
        try {
            interpretTestSpec(useReadHeads = true, spec = """
                add(4) | poll(1, 0) = 5
            """)
            fail("This spec should have thrown")
        } catch (e: InterpretException) {
            assertTrue(e.cause is AssertionError)
            assertEquals(interpretLine + 1, e.stackTrace[0].lineNumber)
            assertTrue(e.stackTrace[0].fileName.contains(__FILE__))
            assertTrue(e.stackTrace[0].methodName.contains("testInterpreter"))
            assertTrue(e.stackTrace[0].methodName.contains("thread1"))
        }
    }

    @Test
    fun testMultiplePoll() {
        interpretTestSpec(useReadHeads = false, spec = """