@@ -347,6 +347,7 @@ ri_log "Running DeviceRunner on destination '$SIM_DESTINATION'"
347347DERIVED_DATA_DIR=" $SCREENSHOT_TMP_DIR /derived"
348348rm -rf " $DERIVED_DATA_DIR "
349349BUILD_LOG=" $ARTIFACTS_DIR /xcodebuild-build.log"
350+ APP_CONSOLE_LOG=" $ARTIFACTS_DIR /device-runner-console.log"
350351
351352ri_log " Building simulator app with xcodebuild"
352353COMPILE_START=$( date +%s)
@@ -461,16 +462,17 @@ APP_PROCESS_NAME="${WRAPPER_NAME%.app}"
461462 trap cleanup EXIT
462463
463464 ri_log " Streaming simulator logs to $TEST_LOG "
465+ CN1SS_PREDICATE=' (eventMessage CONTAINS "CN1SS" OR composedMessage CONTAINS "CN1SS")'
464466 if [ -n " $SIM_DEVICE_ID " ]; then
465467 xcrun simctl terminate " $SIM_DEVICE_ID " " $BUNDLE_IDENTIFIER " > /dev/null 2>&1 || true
466468 xcrun simctl uninstall " $SIM_DEVICE_ID " " $BUNDLE_IDENTIFIER " > /dev/null 2>&1 || true
467469
468- xcrun simctl spawn " $SIM_DEVICE_ID " \
470+ stdbuf -oL xcrun simctl spawn " $SIM_DEVICE_ID " \
469471 log stream --style json --level debug \
470- --predicate ' eventMessage CONTAINS "CN1SS" ' \
472+ --predicate " $CN1SS_PREDICATE " \
471473 > " $TEST_LOG " 2>&1 &
472474 else
473- xcrun simctl spawn booted log stream --style compact --level debug --predicate ' composedMessage CONTAINS "CN1SS" ' > " $TEST_LOG " 2>&1 &
475+ stdbuf -oL xcrun simctl spawn booted log stream --style json --level debug --predicate " $CN1SS_PREDICATE " > " $TEST_LOG " 2>&1 &
474476 fi
475477 LOG_STREAM_PID=$!
476478 sleep 2
@@ -485,7 +487,8 @@ APP_PROCESS_NAME="${WRAPPER_NAME%.app}"
485487 INSTALL_END=$( date +%s)
486488
487489 LAUNCH_START=$( date +%s)
488- if ! xcrun simctl launch " $SIM_DEVICE_ID " " $BUNDLE_IDENTIFIER " > /dev/null 2>&1 ; then
490+ ri_log " Launching app with console capture -> $APP_CONSOLE_LOG "
491+ if ! xcrun simctl launch --console-pty " $SIM_DEVICE_ID " " $BUNDLE_IDENTIFIER " 2>&1 | tee " $APP_CONSOLE_LOG " ; then
489492 ri_log " FATAL: simctl launch failed"
490493 exit 11
491494 fi
@@ -498,7 +501,8 @@ APP_PROCESS_NAME="${WRAPPER_NAME%.app}"
498501 INSTALL_END=$( date +%s)
499502
500503 LAUNCH_START=$( date +%s)
501- if ! xcrun simctl launch booted " $BUNDLE_IDENTIFIER " > /dev/null 2>&1 ; then
504+ ri_log " Launching app with console capture -> $APP_CONSOLE_LOG "
505+ if ! xcrun simctl launch --console-pty booted " $BUNDLE_IDENTIFIER " 2>&1 | tee " $APP_CONSOLE_LOG " ; then
502506 ri_log " FATAL: simctl launch failed"
503507 exit 11
504508 fi
@@ -547,12 +551,34 @@ declare -a CN1SS_SOURCES=("SIMLOG:$TEST_LOG")
547551LOG_CHUNKS=" $( cn1ss_count_chunks " $TEST_LOG " ) " ; LOG_CHUNKS=" ${LOG_CHUNKS// [^0-9]/ } " ; : " ${LOG_CHUNKS:= 0} "
548552ri_log " Chunk counts -> simulator log: ${LOG_CHUNKS} "
549553
550- if [ " ${LOG_CHUNKS:- 0} " = " 0" ]; then
551- ri_log " STAGE:MARKERS_NOT_FOUND -> simulator output did not include CN1SS chunks"
552- ri_log " ---- CN1SS lines (if any) ----"
553- (grep " CN1SS:" " $TEST_LOG " || true) | sed ' s/^/[CN1SS] /'
554- exit 12
555- fi
554+ if [ " ${LOG_CHUNKS:- 0} " = " 0" ]; then
555+ COLLECTED_LOG_DIR=" $ARTIFACTS_DIR /simulator-logs"
556+ ensure_dir " $COLLECTED_LOG_DIR "
557+ DEBUG_LOG=" $COLLECTED_LOG_DIR /device-runner-debug.log"
558+ if [ -n " $SIM_DEVICE_ID " ]; then
559+ ri_log " Capturing simulator debug log to $DEBUG_LOG "
560+ xcrun simctl spawn " $SIM_DEVICE_ID " log show --style syslog --last 30m > " $DEBUG_LOG " 2> /dev/null || true
561+ else
562+ ri_log " Capturing host simulator debug log to $DEBUG_LOG "
563+ log show --style syslog --last 30m > " $DEBUG_LOG " 2> /dev/null || true
564+ fi
565+ CRASH_LOG_DIR=" $COLLECTED_LOG_DIR /crash-reports"
566+ ensure_dir " $CRASH_LOG_DIR "
567+ ri_log " Collecting recent crash reports into $CRASH_LOG_DIR "
568+ find " $HOME /Library/Logs/DiagnosticReports" -type f -name ' *.crash' -mmin -120 -print -exec cp {} " $CRASH_LOG_DIR " \; 2> /dev/null || true
569+ if [ -s " $FALLBACK_LOG " ]; then
570+ ri_log " Appending fallback CN1SS log to $TEST_LOG "
571+ {
572+ echo " ---- BEGIN FALLBACK CN1SS LOG ----"
573+ cat " $FALLBACK_LOG "
574+ echo " ---- END FALLBACK CN1SS LOG ----"
575+ } >> " $TEST_LOG " 2> /dev/null || true
576+ fi
577+ ri_log " STAGE:MARKERS_NOT_FOUND -> simulator output did not include CN1SS chunks"
578+ ri_log " ---- CN1SS lines (if any) ----"
579+ (grep " CN1SS:" " $TEST_LOG " || true) | sed ' s/^/[CN1SS] /'
580+ exit 12
581+ fi
556582
557583TEST_NAMES_RAW=" $( cn1ss_list_tests " $TEST_LOG " 2> /dev/null | awk ' NF' | sort -u || true) "
558584declare -a TEST_NAMES=()
@@ -657,6 +683,7 @@ comment_rc=$?
657683
658684cp -f " $BUILD_LOG " " $ARTIFACTS_DIR /xcodebuild-build.log" 2> /dev/null || true
659685cp -f " $TEST_LOG " " $ARTIFACTS_DIR /device-runner.log" 2> /dev/null || true
686+ cp -f " $APP_CONSOLE_LOG " " $ARTIFACTS_DIR /device-runner-console.log" 2> /dev/null || true
660687
661688exit $comment_rc
662689
0 commit comments