Skip to content
Merged
Show file tree
Hide file tree
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
78 changes: 71 additions & 7 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,23 @@ jobs:
fail-fast: false
matrix:
include:
# wrapper-lifetime-pass: "<mode>:<scope>" to run the suite a second
# time, on the same build, under that wrapper lifetime mode.
- name: Test
xcodebuild-args: ""
artifact-suffix: ""
cache-variant: default
wrapper-lifetime-pass: "canary:all"
# Only code compiled here is instrumented: the runtime and the test
# fixtures, not the prebuilt V8 archives.
- name: Test (ASan)
xcodebuild-args: "-enableAddressSanitizer YES"
artifact-suffix: "-asan"
cache-variant: asan
wrapper-lifetime-pass: ""
env:
# Must match the simulator named in "Wait for the test simulator".
TEST_DESTINATION: "platform=iOS Simulator,OS=latest,name=iPhone 16 Pro"
steps:
- uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1.7.0
with:
Expand Down Expand Up @@ -133,25 +140,30 @@ jobs:
run: |
mkdir -p dist-test
echo TEST_FOLDER=$(pwd)/dist-test >> $GITHUB_ENV
# Must match the simulator named in the Xcode Tests -destination.
# Must match the simulator named in TEST_DESTINATION.
# --boot leaves the simulator booting in the background, so the boot
# overlaps build-for-testing instead of delaying the first test run.
- name: Wait for the test simulator
run: ./scripts/wait-for-simulator.sh --name "iPhone 16 Pro"
run: ./scripts/wait-for-simulator.sh --name "iPhone 16 Pro" --boot
- name: Build for testing
id: build-for-testing
run: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} build-for-testing | xcpretty
- name: Xcode Tests
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
# try to run the tests with xcpretty. If it fails then try again without xcpretty twice for better log output
# the xcode tests are a bit flaky and they should never fail on this step, as this step only collects the JS test results as junit xml
with:
# Build (~10m) + the runtime suite's report-wait (up to 10m, see
# TestRunnerTests.swift) need more than 20m headroom per attempt.
timeout_minutes: 40
# The runtime suite's report-wait alone can take 10m (see
# TestRunnerTests.swift), plus app install and launch.
timeout_minutes: 25
max_attempts: 2
command: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $TEST_FOLDER/test_results -destination platform\=iOS\ Simulator,OS\=latest,name\=iPhone\ 16\ Pro ${{ matrix.xcodebuild-args }} test | xcpretty
command: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $TEST_FOLDER/test_results -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} test-without-building | xcpretty
# Keep the failed attempt's bundle — it holds the diagnostics of the
# failure being retried. Everything else at the result path must go
# (including extensionless staging leftovers), or the retry dies with
# "Existing file at -resultBundlePath".
on_retry_command: rm -rf $TEST_FOLDER/test_results_attempt1.xcresult; mv $TEST_FOLDER/test_results.xcresult $TEST_FOLDER/test_results_attempt1.xcresult 2>/dev/null; for f in $TEST_FOLDER/test_results*; do [ "$f" = "$TEST_FOLDER/test_results_attempt1.xcresult" ] || rm -rf "$f"; done; xcrun simctl shutdown all
new_command_on_retry: xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $TEST_FOLDER/test_results -destination platform\=iOS\ Simulator,OS\=latest,name\=iPhone\ 16\ Pro ${{ matrix.xcodebuild-args }} test
new_command_on_retry: xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $TEST_FOLDER/test_results -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} test-without-building
- name: Xcode compilation cache size
if: ${{ !cancelled() }}
run: du -sh "$NS_COMPILATION_CACHE_DIR" || true
Expand Down Expand Up @@ -179,6 +191,56 @@ jobs:
ls "$TEST_FOLDER"/test-out/*junit*.xml > /dev/null 2>&1 || { echo "::error::No JUnit report in $TEST_FOLDER/test-out"; exit 1; }
find $TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx junit-cli-report-viewer
find $TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml
# Second pass: the same build with "wrapperLifetime" set in the built
# app's package.json. It runs whatever the first pass's outcome, so a
# default-mode failure still yields this pass's results and diagnostics.
# test-without-building runs no build phases, so the rewrite stands.
- name: Configure the built app for the wrapper lifetime pass
id: wrapper-lifetime-app
if: ${{ !cancelled() && matrix.wrapper-lifetime-pass != '' && steps.build-for-testing.outcome == 'success' }}
env:
WRAPPER_LIFETIME: ${{ matrix.wrapper-lifetime-pass }}
run: |
APP="$(find build -maxdepth 2 -type d -path 'build/*-iphonesimulator/TestRunner.app')"
[ -n "$APP" ] && [ "$(printf '%s\n' "$APP" | wc -l)" -eq 1 ] || { echo "::error::Expected one built TestRunner.app under build/, found: ${APP:-none}"; exit 1; }
node tools/apply-test-app-config.mjs --source TestRunner/app/package.json --out "$APP/app/package.json" --wrapper-lifetime "$WRAPPER_LIFETIME"
# Rewriting a resource breaks the bundle's seal; re-seal it ad hoc,
# keeping the build's entitlements.
codesign --force --sign - --timestamp=none --preserve-metadata=entitlements "$APP"
echo "WL_TEST_FOLDER=$TEST_FOLDER/wrapper-lifetime" >> "$GITHUB_ENV"
mkdir -p "$TEST_FOLDER/wrapper-lifetime"
- name: Xcode Tests (wrapper lifetime ${{ matrix.wrapper-lifetime-pass }})
if: ${{ !cancelled() && steps.wrapper-lifetime-app.outcome == 'success' }}
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
with:
timeout_minutes: 25
max_attempts: 2
command: set -o pipefail && xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $WL_TEST_FOLDER/test_results -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} test-without-building | xcpretty
on_retry_command: rm -rf $WL_TEST_FOLDER/test_results_attempt1.xcresult; mv $WL_TEST_FOLDER/test_results.xcresult $WL_TEST_FOLDER/test_results_attempt1.xcresult 2>/dev/null; for f in $WL_TEST_FOLDER/test_results*; do [ "$f" = "$WL_TEST_FOLDER/test_results_attempt1.xcresult" ] || rm -rf "$f"; done; xcrun simctl shutdown all
new_command_on_retry: xcodebuild -project v8ios.xcodeproj -scheme TestRunner -resultBundlePath $WL_TEST_FOLDER/test_results -destination "$TEST_DESTINATION" ${{ matrix.xcodebuild-args }} test-without-building
- name: Extract test results (wrapper lifetime)
if: ${{ !cancelled() && steps.wrapper-lifetime-app.outcome == 'success' }}
run: |
if [ -d "$WL_TEST_FOLDER/test_results.xcresult" ]; then
./scripts/export-test-attachments.sh --result "$WL_TEST_FOLDER/test_results.xcresult" --output "$WL_TEST_FOLDER/test-out"
fi
- name: Test report summary (wrapper lifetime)
if: ${{ !cancelled() && steps.wrapper-lifetime-app.outcome == 'success' }}
uses: mikepenz/action-junit-report@6ef3fdcfcd5f0b5d14df3e659ef19b8c6820f93d # v6.6.1
with:
check_name: JUnit Test Report (wrapper lifetime ${{ matrix.wrapper-lifetime-pass }})
report_paths: dist-test/wrapper-lifetime/test-out/*junit*.xml
annotate_only: true
detailed_summary: true
- name: Validate Test Results (wrapper lifetime)
if: ${{ !cancelled() && steps.wrapper-lifetime-app.outcome == 'success' }}
env:
WRAPPER_LIFETIME: ${{ matrix.wrapper-lifetime-pass }}
run: |
ls "$WL_TEST_FOLDER"/test-out/*junit*.xml > /dev/null 2>&1 || { echo "::error::No JUnit report in $WL_TEST_FOLDER/test-out"; exit 1; }
find $WL_TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx junit-cli-report-viewer
find $WL_TEST_FOLDER/test-out -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml
./scripts/check-wrapper-lifetime-report.sh --reports "$WL_TEST_FOLDER/test-out" --expect "$(printf '%s' "$WRAPPER_LIFETIME" | tr ':' '/')"
- name: Collect test diagnostics
if: failure()
uses: ./.github/actions/collect-test-diagnostics
Expand All @@ -193,6 +255,8 @@ jobs:
path: |
${{env.TEST_FOLDER}}/test_results.xcresult
${{env.TEST_FOLDER}}/test_results_attempt1.xcresult
${{env.TEST_FOLDER}}/wrapper-lifetime/test_results.xcresult
${{env.TEST_FOLDER}}/wrapper-lifetime/test_results_attempt1.xcresult
test-catalyst:
name: Test (Mac Catalyst)
runs-on: macos-15
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ Runtime initialization took 55ms

If all tests pass, everything is good! At this point you can make changes to the runtime, add breakpoints and step through with the debugger. In the next section we'll see how to attach the runtime to an existing NativeScript application allowing us to debug runtime issues in actual apps.

## Running the suite from the command line

`./run_tests.sh` builds TestRunner, runs the suite on a simulator and leaves the results in `build/tests/<simulator udid>`. `./run_tests.sh --help` lists every option; the common ones:

- `--temp-sim` runs on a throwaway simulator that is deleted afterwards; `--keep-sim` creates (once) and reuses a simulator named after the checkout.
- `-a` / `--asan` runs under AddressSanitizer.
- `--wrapper-lifetime <mode>[:<scope>]` runs the suite under a wrapper lifetime mode (`resurrecting`, `rooted` or `canary`; scope `extended` or `all`, default `extended`), e.g. `./run_tests.sh --temp-sim --wrapper-lifetime canary:all`. It sets `"wrapperLifetime"` in the built app's `package.json` only; `TestRunner/app/package.json` is left untouched. From `xcodebuild`, pass the build setting `NS_TEST_WRAPPER_LIFETIME=<mode>:<scope>` instead.

## Node.js in Xcode builds

Building the `NativeScript` target generates the runtime JS builtins with `tools/js2c.mjs`, and building the `TestRunner` target copies jasmine-core from `node_modules` into the test app with `tools/stage-test-runner-deps.mjs`; both need Node.js. Xcode runs build phases with a minimal `PATH` and never reads your shell profile, so a node managed by nvm/fnm/volta/asdf is invisible to it. The build phase instead sources two files from the repo root:
Expand Down
43 changes: 41 additions & 2 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ Simulator options:

Run options:
-a, --asan Run under AddressSanitizer (-enableAddressSanitizer YES)
--wrapper-lifetime <mode>[:<scope>]
Run the suite under a wrapper lifetime mode: the built app's
package.json gets "wrapperLifetime": { mode, scope } (the
source TestRunner/app/package.json is not modified), and the
run fails unless the suite reports that mode.
mode: resurrecting | rooted | canary
scope: extended | all (default: extended)
-t, --temp-folder Write results to a random temp folder instead of build/tests/<udid>
-h, --help Show this help

Expand All @@ -320,6 +327,7 @@ SIM_RUNTIME=""
DELETE_TARGET=""
TEST_FOLDER=""
CATALYST=0
WRAPPER_LIFETIME=""

set_sim_mode() {
if [ -n "$SIM_MODE" ] && [ "$SIM_MODE" != "$1" ]; then
Expand Down Expand Up @@ -367,6 +375,8 @@ while [ $# -gt 0 ]; do
--list-sims) set_sim_mode "list-sims"; shift ;;
--delete-sims) set_sim_mode "delete-sims"; shift ;;
--catalyst) CATALYST=1; shift ;;
--wrapper-lifetime|--wrapper-lifetime=*)
take_value "--wrapper-lifetime" "$1" "${2:-}" "$has_next"; WRAPPER_LIFETIME="$OPT_VALUE"; shift "$OPT_SHIFT" ;;
-a|--asan) ASAN=1; shift ;;
-t|--temp-folder) TEMP_FOLDER=1; shift ;;
-h|--help) usage; exit 0 ;;
Expand Down Expand Up @@ -407,10 +417,23 @@ if { [ -n "$SIM_DEVICE_TYPE" ] || [ -n "$SIM_RUNTIME" ]; } && [ "$CREATES_SIM" -
die_usage "--device-type and --runtime only apply when a simulator may be created."
fi
if [ -n "$SIM_MODE" ] && [ "$SIM_MODE" != "temp-sim" ] && [ "$SIM_MODE" != "keep-sim" ]; then
if [ "$ASAN" -eq 1 ] || [ "$TEMP_FOLDER" -eq 1 ]; then
die_usage "--asan and --temp-folder do not apply to --$SIM_MODE."
if [ "$ASAN" -eq 1 ] || [ "$TEMP_FOLDER" -eq 1 ] || [ -n "$WRAPPER_LIFETIME" ]; then
die_usage "--asan, --temp-folder and --wrapper-lifetime do not apply to --$SIM_MODE."
fi
fi
if [ -n "$WRAPPER_LIFETIME" ]; then
WL_MODE="${WRAPPER_LIFETIME%%:*}"
WL_SCOPE="extended"
[[ "$WRAPPER_LIFETIME" == *:* ]] && WL_SCOPE="${WRAPPER_LIFETIME#*:}"
case "$WL_MODE" in
resurrecting|rooted|canary) ;;
*) die_usage "--wrapper-lifetime: unknown mode '$WL_MODE' (resurrecting, rooted or canary)." ;;
esac
case "$WL_SCOPE" in
extended|all) ;;
*) die_usage "--wrapper-lifetime: unknown scope '$WL_SCOPE' (extended or all)." ;;
esac
fi

sim_label() {
local name
Expand Down Expand Up @@ -562,6 +585,11 @@ if [ "$ASAN" -eq 1 ]; then
echo "AddressSanitizer: enabled"
XCODEBUILD_ARGS+=(-enableAddressSanitizer YES)
fi
if [ -n "$WRAPPER_LIFETIME" ]; then
echo "Wrapper lifetime: $WL_MODE/$WL_SCOPE"
# Read by the TestRunner target's "Apply Test App Config" build phase.
XCODEBUILD_ARGS+=("NS_TEST_WRAPPER_LIFETIME=$WL_MODE:$WL_SCOPE")
fi

set -o pipefail
xcodebuild -project "$SCRIPT_DIR/v8ios.xcodeproj" -scheme TestRunner \
Expand All @@ -582,4 +610,15 @@ if command -v xcparse &>/dev/null; then
find "$TEST_FOLDER/test-out" -name "*junit*.xml" -maxdepth 1 -print0 | xargs -n 1 -0 npx verify-junit-xml
fi

if [ -n "$WRAPPER_LIFETIME" ]; then
if ! ls "$TEST_FOLDER"/test-out/*junit*.xml >/dev/null 2>&1 && [ -d "$TEST_FOLDER/test_results.xcresult" ]; then
"$SCRIPT_DIR/scripts/export-test-attachments.sh" --result "$TEST_FOLDER/test_results.xcresult" \
--output "$TEST_FOLDER/test-out" >/dev/null
fi
if ! "$SCRIPT_DIR/scripts/check-wrapper-lifetime-report.sh" --reports "$TEST_FOLDER/test-out" \
--expect "$WL_MODE/$WL_SCOPE"; then
[ $TEST_EXIT -ne 0 ] || TEST_EXIT=1
fi
fi

exit $TEST_EXIT
70 changes: 70 additions & 0 deletions scripts/check-wrapper-lifetime-report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
# Fails unless the JS suite's junit reports show it ran under the expected
# wrapper lifetime mode and scope. The mode reaches the app through a build
# phase, so a passing suite alone does not prove which mode it exercised; the
# "Wrapper lifetime modes" suite names a spec after the mode the runtime read.
set -euo pipefail

usage() {
echo "Usage: ./scripts/check-wrapper-lifetime-report.sh --reports <dir> --expect <mode>/<scope>"
echo ""
echo " --reports <dir> directory holding the suite's *junit*.xml reports"
echo " --expect <m>/<s> mode and scope the suite must report, e.g. canary/all"
echo " -h, --help show this help"
}

REPORTS=""
EXPECT=""
while [ $# -gt 0 ]; do
case "$1" in
--reports)
[ $# -ge 2 ] || { echo "--reports needs a value" >&2; usage >&2; exit 1; }
REPORTS="$2"
shift 2
;;
--reports=*) REPORTS="${1#*=}"; shift ;;
--expect)
[ $# -ge 2 ] || { echo "--expect needs a value" >&2; usage >&2; exit 1; }
EXPECT="$2"
shift 2
;;
--expect=*) EXPECT="${1#*=}"; shift ;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 1
;;
esac
done

if [ -z "$REPORTS" ] || [ -z "$EXPECT" ]; then
echo "--reports and --expect are required" >&2
usage >&2
exit 1
fi

REPORT_FILES=()
while IFS= read -r -d '' f; do
REPORT_FILES+=("$f")
done < <(find "$REPORTS" -maxdepth 1 -name "*junit*.xml" -print0 2>/dev/null)

if [ "${#REPORT_FILES[@]}" -eq 0 ]; then
echo "error: no *junit*.xml report in $REPORTS" >&2
exit 1
fi

# Must match the spec title in TestRunner/app/tests/WrapperLifetimeModesTests.js.
NEEDLE="reports the configured mode and scope ($EXPECT)"
if grep -qF "$NEEDLE" "${REPORT_FILES[@]}"; then
echo "Wrapper lifetime: suite ran under $EXPECT"
exit 0
fi

echo "error: the suite did not report wrapper lifetime $EXPECT" >&2
FOUND=$(grep -ohE 'reports the configured mode and scope \([a-z]+/[a-z]+\)' "${REPORT_FILES[@]}" | sort -u || true)
echo " reported: ${FOUND:-no wrapper lifetime mode spec in the reports}" >&2
exit 1
14 changes: 13 additions & 1 deletion scripts/wait-for-simulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
set -euo pipefail

usage() {
echo "Usage: ./scripts/wait-for-simulator.sh --name <device name> [--timeout <seconds>]"
echo "Usage: ./scripts/wait-for-simulator.sh --name <device name> [--timeout <seconds>] [--boot]"
echo ""
echo " --name <name> simulator device name, e.g. \"iPhone 16 Pro\""
echo " --timeout <seconds> give up after this long (default: 300)"
echo " --boot once found, start booting it in the background and return"
echo " -h, --help show this help"
}

NAME=""
TIMEOUT=300
BOOT=0
while [ $# -gt 0 ]; do
case "$1" in
--name)
Expand All @@ -36,6 +38,10 @@ while [ $# -gt 0 ]; do
TIMEOUT="${1#--timeout=}"
shift
;;
--boot)
BOOT=1
shift
;;
-h|--help)
usage
exit 0
Expand Down Expand Up @@ -79,6 +85,12 @@ while :; do
found="$(find_device || true)"
if [ -n "$found" ]; then
echo "Found simulator \"$NAME\": $found (after ${SECONDS}s)"
if [ "$BOOT" -eq 1 ]; then
# Detached so later steps (the build) run while it boots; xcodebuild
# waits for a booting device on its own.
nohup xcrun simctl bootstatus "${found%% *}" -b > /dev/null 2>&1 &
echo "Booting ${found%% *} in the background"
fi
exit 0
fi
if [ "$SECONDS" -ge "$deadline" ]; then
Expand Down
Loading
Loading