Skip to content

Commit ba65cfb

Browse files
committed
Fix
1 parent 1aca428 commit ba65cfb

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

llm/android/LlamaDemo/app/src/androidTest/java/com/example/executorchllamademo/UIWorkflowTest.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,23 @@ class UIWorkflowTest {
181181
*/
182182
private fun waitForModelLoaded(timeoutMs: Long = 60000): Boolean {
183183
return try {
184+
var wasSuccess = false
184185
composeTestRule.waitUntil(timeoutMillis = timeoutMs) {
185186
val successNodes = composeTestRule.onAllNodesWithText("Successfully loaded", substring = true)
186187
.fetchSemanticsNodes()
187-
val errorNodes = composeTestRule.onAllNodesWithText("Model Load failure", substring = true)
188+
val errorNodes = composeTestRule.onAllNodesWithText("Model load failure", substring = true)
188189
.fetchSemanticsNodes()
190+
wasSuccess = successNodes.isNotEmpty()
189191
successNodes.isNotEmpty() || errorNodes.isNotEmpty()
190192
}
191-
// Check which one appeared
192-
val successNodes = composeTestRule.onAllNodesWithText("Successfully loaded", substring = true)
193-
.fetchSemanticsNodes()
194-
if (successNodes.isNotEmpty()) {
193+
if (wasSuccess) {
195194
Log.i(TAG, "Model loaded successfully")
196-
true
197195
} else {
198196
Log.e(TAG, "Model load failed")
199-
false
200197
}
198+
wasSuccess
201199
} catch (e: Exception) {
202-
Log.e(TAG, "Model loading timed out after ${timeoutMs}ms")
200+
Log.e(TAG, "Model loading timed out after ${timeoutMs}ms: ${e.message}")
203201
false
204202
}
205203
}
@@ -406,17 +404,21 @@ class UIWorkflowTest {
406404
composeTestRule.onAllNodes(hasContentDescription("Stop"))
407405
.fetchSemanticsNodes().isNotEmpty()
408406
}
409-
// Click stop
410-
composeTestRule.onNodeWithContentDescription("Stop").performClick()
411407
} catch (e: Exception) {
412408
// Generation might have already finished
413409
Log.i(TAG, "Stop button not found - generation may have completed")
414410
}
415411

412+
// Click stop
413+
composeTestRule.onNodeWithContentDescription("Stop").performClick()
414+
Log.i(TAG, "111")
415+
416416
composeTestRule.waitForIdle()
417+
Log.i(TAG, "222")
417418

418419
// Wait for generation to fully stop
419420
waitForGenerationComplete(30000)
421+
Log.i(TAG, "333")
420422

421423
// Verify that some response was generated (even if stopped early)
422424
assertModelResponseNotEmpty()

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/viewmodel/ChatViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
233233
var loadDuration = System.currentTimeMillis() - runStartTime
234234
var modelInfo: String
235235

236+
var loadSuccess = false
236237
try {
237238
module?.load()
238239
val pteName = modelPath.substringAfterLast('/')
@@ -245,8 +246,9 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
245246
module?.prefillPrompt(PromptFormat.getLlavaPresetPrompt())
246247
ETLogging.getInstance().log("Llava completes prefill prompt")
247248
}
249+
loadSuccess = true
248250
} catch (e: ExecutorchRuntimeException) {
249-
modelInfo = "${e.message}\n"
251+
modelInfo = "Model load failure: ${e.message}"
250252
loadDuration = 0
251253
modelLoadError = modelInfo
252254
showModelLoadErrorDialog = true
@@ -261,7 +263,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
261263
"Model loaded time: $loadDuration ms"
262264
ETLogging.getInstance().log("Load complete. $modelLoggingInfo")
263265

264-
isModelReady = true
266+
isModelReady = loadSuccess
265267
_messages.remove(modelLoadingMessage)
266268
_messages.add(modelLoadedMessage)
267269
}

0 commit comments

Comments
 (0)