Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import java.util.concurrent.atomic.AtomicInteger
import org.apache.commons.io.FileUtils
import org.junit.Assert
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.pytorch.executorch.TestFileUtils.getTestFilePath
Expand All @@ -40,48 +39,49 @@ class ModuleInstrumentationTest {
inputStream.close()
}

@Ignore(
"The forward has failure that needs to be fixed before enabling this test: [Executorch Error 0x12] Invalid argument: Execution failed for method: forward "
)
@Test
@Throws(IOException::class, URISyntaxException::class)
fun testModuleLoadAndForward() {
val module = Module.load(getTestFilePath(TEST_FILE_NAME))

val results = module.forward()
Assert.assertTrue(results[0].isTensor)
try {
val results = module.forward(EValue.from(dummyInput()))
Assert.assertTrue(results[0].isTensor)
} finally {
module.destroy()
}
}

@Test
@Throws(IOException::class, URISyntaxException::class)
fun testMethodMetadata() {
val module = Module.load(getTestFilePath(TEST_FILE_NAME))
module.destroy()
}

@Ignore(
"The forward has failure that needs to be fixed before enabling this test: [Executorch Error 0x12] Invalid argument: Execution failed for method: forward "
)
@Test
@Throws(IOException::class)
fun testModuleLoadMethodAndForward() {
val module = Module.load(getTestFilePath(TEST_FILE_NAME))
try {
module.loadMethod(FORWARD_METHOD)

module.loadMethod(FORWARD_METHOD)

val results = module.forward()
Assert.assertTrue(results[0].isTensor)
val results = module.forward(EValue.from(dummyInput()))
Assert.assertTrue(results[0].isTensor)
} finally {
module.destroy()
}
}

@Ignore(
"The forward has failure that needs to be fixed before enabling this test: [Executorch Error 0x12] Invalid argument: Execution failed for method: forward "
)
@Test
@Throws(IOException::class)
fun testModuleLoadForwardExplicit() {
val module = Module.load(getTestFilePath(TEST_FILE_NAME))

val results = module.execute(FORWARD_METHOD)
Assert.assertTrue(results[0].isTensor)
try {
val results = module.execute(FORWARD_METHOD, EValue.from(dummyInput()))
Assert.assertTrue(results[0].isTensor)
} finally {
module.destroy()
}
}

@Test(expected = RuntimeException::class)
Expand All @@ -94,15 +94,18 @@ class ModuleInstrumentationTest {
@Throws(IOException::class)
fun testModuleLoadMethodNonExistantMethod() {
val module = Module.load(getTestFilePath(TEST_FILE_NAME))

val exception =
Assert.assertThrows(ExecutorchRuntimeException::class.java) {
module.loadMethod(NONE_METHOD)
}
Assert.assertEquals(
ExecutorchRuntimeException.INVALID_ARGUMENT,
exception.getErrorCode(),
)
try {
val exception =
Assert.assertThrows(ExecutorchRuntimeException::class.java) {
module.loadMethod(NONE_METHOD)
}
Assert.assertEquals(
ExecutorchRuntimeException.INVALID_ARGUMENT,
exception.getErrorCode(),
)
} finally {
module.destroy()
}
}

@Test(expected = RuntimeException::class)
Expand Down Expand Up @@ -135,9 +138,6 @@ class ModuleInstrumentationTest {
Assert.assertThrows(IllegalStateException::class.java) { module.forward() }
}

@Ignore(
"The forward has failure that needs to be fixed before enabling this test: [Executorch Error 0x12] Invalid argument: Execution failed for method: forward "
)
@Test
@Throws(InterruptedException::class, IOException::class)
fun testForwardFromMultipleThreads() {
Expand All @@ -151,7 +151,7 @@ class ModuleInstrumentationTest {
try {
latch.countDown()
latch.await(5000, TimeUnit.MILLISECONDS)
val results = module.forward()
val results = module.forward(EValue.from(dummyInput()))
Assert.assertTrue(results[0].isTensor)
Comment on lines +154 to 155
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the multi-thread test each worker allocates a new 1x3x224x224 float tensor via dummyInput(). With 100 threads this can create significant short-lived allocations (~60MB+), which can make the instrumentation test flaky on memory-constrained devices. Consider pre-creating a single Tensor (or even EValue) and reusing it across threads/tests to avoid repeated allocations.

Copilot uses AI. Check for mistakes.
Comment thread
psiddh marked this conversation as resolved.
completed.incrementAndGet()
} catch (_: InterruptedException) {}
Expand All @@ -168,6 +168,7 @@ class ModuleInstrumentationTest {
}

Assert.assertEquals(numThreads.toLong(), completed.get().toLong())
module.destroy()
}

companion object {
Expand All @@ -176,5 +177,8 @@ class ModuleInstrumentationTest {
private const val NON_PTE_FILE_NAME = "/test.txt"
private const val FORWARD_METHOD = "forward"
private const val NONE_METHOD = "none"
private val inputShape = longArrayOf(1, 3, 224, 224)

private fun dummyInput(): Tensor = Tensor.ones(inputShape, DType.FLOAT)
}
}
Loading