Skip to content

Commit f731d4f

Browse files
committed
build-script: allow to run host-side iOS tests
This change allows to easily run iOS tests that require only running the compiler, and don't require running the generated code.
1 parent 9993d11 commit f731d4f

File tree

4 files changed

+102
-19
lines changed

4 files changed

+102
-19
lines changed

docs/Testing.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ these targets in the build directory:
5151

5252
Runs all tests.
5353

54-
For day-to-day work on the Swift compiler, using check-swift should be
54+
For day-to-day work on the Swift compiler, using ``check-swift`` should be
5555
sufficient. The buildbot runs validation tests, so if those are accidentally
5656
broken, it should not go unnoticed.
5757

@@ -62,17 +62,21 @@ test suite.
6262
For every target above, there are variants for different optimizations:
6363

6464
* the target itself (e.g., ``check-swift``) -- runs execution tests in
65-
``-Onone`` mode;
65+
``-Onone`` mode.
6666

6767
* the target with ``-optimize`` suffix (e.g., ``check-swift-optimize``) -- runs
68-
execution tests in ``-O`` mode; This target will only run tests marked as
68+
execution tests in ``-O`` mode. This target will only run tests marked as
6969
``executable_test``.
7070

7171
* the target with ``-optimize-unchecked`` suffix (e.g.,
7272
``check-swift-optimize-unchecked``) -- runs execution tests in
7373
``-Ounchecked`` mode. This target will only run tests marked as
7474
``executable_test``.
7575

76+
* the target with ``-non-executable`` suffix (e.g.,
77+
``check-swift-non-executable-iphoneos-arm64``) -- runs tests not marked with
78+
``executable_test`` in ``-Onone`` mode.
79+
7680
If you need to manually run certain tests, you can invoke LLVM's lit.py script
7781
directly. For example::
7882

test/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ if(PYTHONINTERP_FOUND)
115115
set(SWIFT_ASAN_BUILD TRUE)
116116
endif()
117117

118-
set(TEST_MODES optimize_none optimize optimize_unchecked)
118+
set(TEST_MODES optimize_none optimize optimize_unchecked non_executable)
119119

120120
foreach(SDK ${SWIFT_SDKS})
121121
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
@@ -147,11 +147,15 @@ if(PYTHONINTERP_FOUND)
147147
if(NOT TEST_MODE STREQUAL "optimize_none")
148148
if(TEST_MODE STREQUAL "optimize")
149149
set(test_mode_target_suffix "-optimize")
150-
list(APPEND LIT_ARGS "--param" "run_only_tests=executable_test")
150+
list(APPEND LIT_ARGS "--param" "run_only_tests=executable_tests")
151151
endif()
152152
if(TEST_MODE STREQUAL "optimize_unchecked")
153153
set(test_mode_target_suffix "-optimize-unchecked")
154-
list(APPEND LIT_ARGS "--param" "run_only_tests=executable_test")
154+
list(APPEND LIT_ARGS "--param" "run_only_tests=executable_tests")
155+
endif()
156+
if(TEST_MODE STREQUAL "non_executable")
157+
set(test_mode_target_suffix "-non-executable")
158+
list(APPEND LIT_ARGS "--param" "run_only_tests=non_executable_tests")
155159
endif()
156160
list(APPEND LIT_ARGS "--param" "swift_test_mode=${TEST_MODE}")
157161
endif()
@@ -233,6 +237,9 @@ if(PYTHONINTERP_FOUND)
233237
if(TEST_MODE STREQUAL "optimize_unchecked")
234238
set(test_mode_target_suffix "-optimize-unchecked")
235239
endif()
240+
if(TEST_MODE STREQUAL "non_executable")
241+
set(test_mode_target_suffix "-non-executable")
242+
endif()
236243

237244
add_custom_target(check-swift${test_mode_target_suffix}
238245
DEPENDS "check-swift${test_mode_target_suffix}${SWIFT_PRIMARY_VARIANT_SUFFIX}")

test/lit.cfg

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,23 @@ elif swift_test_mode == 'optimize_unchecked':
396396
config.available_features.add("swift_test_mode_optimize_unchecked_" + run_cpu)
397397
config.available_features.add("swift_test_mode_optimize_unchecked")
398398
swift_execution_tests_extra_flags = '-Ounchecked'
399+
elif swift_test_mode == 'non_executable':
400+
# No extra flags needed.
401+
pass
399402
else:
400403
lit_config.fatal("Unknown test mode %r" % swift_test_mode)
401404

402405
# Only run the subset of tests that require 'executable_test'?
403406
swift_run_only_tests = lit_config.params.get('run_only_tests', 'all')
404-
if swift_run_only_tests != 'all':
405-
config.available_features.add("executable_test")
406-
config.limit_to_features.add(swift_run_only_tests)
407+
if swift_run_only_tests == 'all':
408+
config.available_features.add("executable_test")
409+
elif swift_run_only_tests == 'executable_tests':
410+
config.available_features.add("executable_test")
411+
config.limit_to_features.add(swift_run_only_tests)
412+
elif swift_run_only_tests == 'non_executable_tests':
413+
pass
407414
else:
408-
config.available_features.add("executable_test")
415+
lit_config.fatal("Unknown test mode %r" % swift_run_only_tests)
409416

410417
# Add substitutions for the run target triple, CPU, OS, and pointer size.
411418
config.substitutions.append(('%target-triple', config.variant_triple))
@@ -450,11 +457,48 @@ if run_vendor == 'apple':
450457
(config.variant_triple, stdlib_resource_dir_opt, mcp_opt))
451458
target_options_for_mock_sdk_after = sdk_overlay_dir_opt
452459

453-
if 'arm' in run_cpu:
460+
if 'arm' in run_cpu and swift_test_mode != 'non_executable':
454461
raise RuntimeError('Device tests are not currently supported.')
455462

463+
if 'arm' in run_cpu:
464+
# iOS/tvOS/watchOS device
465+
if run_os == 'ios':
466+
lit_config.note('Testing iOS ' + config.variant_triple)
467+
xcrun_sdk_name = "iphoneos"
468+
elif run_os == 'tvos':
469+
lit_config.note('Testing AppleTV ' + config.variant_triple)
470+
xcrun_sdk_name = "appletvos"
471+
elif run_os == 'watchos':
472+
lit_config.note('Testing watchOS ' + config.variant_triple)
473+
xcrun_sdk_name = "watchos"
474+
475+
if run_cpu == "armv7" or run_cpu == "armv7k":
476+
config.target_swiftmodule_name = "arm.swiftmodule"
477+
config.target_swiftdoc_name = "arm.swiftdoc"
478+
elif run_cpu == "arm64":
479+
config.target_swiftmodule_name = "arm64.swiftmodule"
480+
config.target_swiftdoc_name = "arm64.swiftdoc"
481+
else:
482+
lit_config.fatal("Unknown CPU '%s'" % run_cpu)
483+
484+
config.target_cc_options = (
485+
"-arch %s -m%s-version-min=%s %s" %
486+
(run_cpu, run_os, run_vers, clang_mcp_opt))
487+
488+
config.target_build_swift = (
489+
"%s %s %s -F %s -Xlinker -rpath -Xlinker %s %s %s %s" %
490+
(xcrun_prefix, config.swiftc, target_options,
491+
extra_frameworks_dir,
492+
"/tmp/swifttest-device/lib",
493+
sdk_overlay_linker_opt, config.swift_test_options,
494+
swift_execution_tests_extra_flags))
495+
config.target_run = "unsupported"
496+
497+
(sw_vers_name, sw_vers_vers, sw_vers_build) = \
498+
darwin_get_sdk_version(config.variant_sdk)
499+
456500
elif run_os == 'ios' or run_os == 'tvos' or run_os == 'watchos':
457-
# iOS/TVOS simulator
501+
# iOS/tvOS/watchOS simulator
458502
if run_os == 'ios':
459503
lit_config.note("Testing iOS simulator " + config.variant_triple)
460504
xcrun_sdk_name = "iphonesimulator"

utils/build-script-impl

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,13 @@ KNOWN_SETTINGS=(
128128
skip-test-osx "" "set to skip testing Swift stdlibs for OSX"
129129
skip-test-ios "" "set to skip testing Swift stdlibs for iOS"
130130
skip-test-ios-simulator "" "set to skip testing Swift stdlibs for iOS simulators (i.e. test devices only)"
131+
skip-test-ios-host "" "set to skip testing the host parts of the iOS toolchain"
131132
skip-test-tvos "" "set to skip testing Swift stdlibs for tvOS"
132133
skip-test-tvos-simulator "" "set to skip testing Swift stdlibs for tvOS simulators (i.e. test devices only)"
134+
skip-test-tvos-host "" "set to skip testing the host parts of the tvOS toolchain"
133135
skip-test-watchos "" "set to skip testing Swift stdlibs for Apple watchOS"
134136
skip-test-watchos-simulator "" "set to skip testing Swift stdlibs for Apple watchOS simulators (i.e. test devices only)"
137+
skip-test-watchos-host "" "set to skip testing the host parts of the watchOS toolchain"
135138
skip-test-validation "" "set to skip validation test suite"
136139
skip-test-optimized "" "set to skip testing the test suite in optimized mode"
137140
stress-test-sourcekit "" "set to run the stress-SourceKit target"
@@ -544,6 +547,7 @@ if [[ "${SKIP_IOS}" ]] ; then
544547
SKIP_BUILD_IOS_DEVICE=1
545548
SKIP_BUILD_IOS_SIMULATOR=1
546549
SKIP_TEST_IOS=1
550+
SKIP_TEST_IOS_HOST=1
547551
SKIP_TEST_IOS_SIMULATOR=1
548552
fi
549553

@@ -552,6 +556,7 @@ if [[ "${SKIP_TVOS}" ]] ; then
552556
SKIP_BUILD_TVOS_DEVICE=1
553557
SKIP_BUILD_TVOS_SIMULATOR=1
554558
SKIP_TEST_TVOS=1
559+
SKIP_TEST_TVOS_HOST=1
555560
SKIP_TEST_TVOS_SIMULATOR=1
556561
fi
557562

@@ -560,6 +565,7 @@ if [[ "${SKIP_WATCHOS}" ]] ; then
560565
SKIP_BUILD_WATCHOS_DEVICE=1
561566
SKIP_BUILD_WATCHOS_SIMULATOR=1
562567
SKIP_TEST_WATCHOS=1
568+
SKIP_TEST_WATCHOS_HOST=1
563569
SKIP_TEST_WATCHOS_SIMULATOR=1
564570
fi
565571

@@ -568,6 +574,7 @@ if [[ "${SKIP_BUILD_IOS}" ]] ; then
568574
SKIP_BUILD_IOS_DEVICE=1
569575
SKIP_BUILD_IOS_SIMULATOR=1
570576
SKIP_TEST_IOS=1
577+
SKIP_TEST_IOS_HOST=1
571578
SKIP_TEST_IOS_SIMULATOR=1
572579
fi
573580

@@ -576,6 +583,7 @@ if [[ "${SKIP_BUILD_TVOS}" ]] ; then
576583
SKIP_BUILD_TVOS_DEVICE=1
577584
SKIP_BUILD_TVOS_SIMULATOR=1
578585
SKIP_TEST_TVOS=1
586+
SKIP_TEST_TVOS_HOST=1
579587
SKIP_TEST_TVOS_SIMULATOR=1
580588
fi
581589

@@ -584,6 +592,7 @@ if [[ "${SKIP_BUILD_WATCHOS}" ]] ; then
584592
SKIP_BUILD_WATCHOS_DEVICE=1
585593
SKIP_BUILD_WATCHOS_SIMULATOR=1
586594
SKIP_TEST_WATCHOS=1
595+
SKIP_TEST_WATCHOS_HOST=1
587596
SKIP_TEST_WATCHOS_SIMULATOR=1
588597
fi
589598

@@ -615,14 +624,17 @@ if [[ "${SKIP_BUILD_WATCHOS_SIMULATOR}" ]] ; then
615624
fi
616625

617626
if [[ "${SKIP_TEST_IOS}" ]] ; then
627+
SKIP_TEST_IOS_HOST=1
618628
SKIP_TEST_IOS_SIMULATOR=1
619629
fi
620630

621631
if [[ "${SKIP_TEST_TVOS}" ]] ; then
632+
SKIP_TEST_TVOS_HOST=1
622633
SKIP_TEST_TVOS_SIMULATOR=1
623634
fi
624635

625636
if [[ "${SKIP_TEST_WATCHOS}" ]] ; then
637+
SKIP_TEST_WATCHOS_HOST=1
626638
SKIP_TEST_WATCHOS_SIMULATOR=1
627639
fi
628640

@@ -938,6 +950,7 @@ for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
938950
build_for_this_target=1
939951
perftest_this_target=
940952
test_this_target=1
953+
test_host_only=
941954
case ${deployment_target} in
942955
linux-*)
943956
build_for_this_target=1
@@ -955,7 +968,11 @@ for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
955968
iphoneos-*)
956969
build_for_this_target=$(not ${SKIP_BUILD_IOS_DEVICE})
957970
perftest_this_target=$(not ${SKIP_BUILD_IOS_DEVICE})
958-
test_this_target=
971+
if [[ ! "${SKIP_TEST_IOS_HOST}" ]] ; then
972+
test_host_only=1
973+
else
974+
test_this_target=
975+
fi
959976
;;
960977
iphonesimulator-*)
961978
build_for_this_target=$(not ${SKIP_BUILD_IOS_SIMULATOR})
@@ -964,7 +981,11 @@ for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
964981
appletvos-*)
965982
build_for_this_target=$(not ${SKIP_BUILD_TVOS_DEVICE})
966983
perftest_this_target=$(not ${SKIP_BUILD_TVOS_DEVICE})
967-
test_this_target=
984+
if [[ ! "${SKIP_TEST_TVOS_HOST}" ]] ; then
985+
test_host_only=1
986+
else
987+
test_this_target=
988+
fi
968989
;;
969990
appletvsimulator-*)
970991
build_for_this_target=$(not ${SKIP_BUILD_TVOS_SIMULATOR})
@@ -973,7 +994,11 @@ for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
973994
watchos-*)
974995
build_for_this_target=$(not ${SKIP_BUILD_WATCHOS_DEVICE})
975996
perftest_this_target=$(not ${SKIP_BUILD_WATCHOS_DEVICE})
976-
test_this_target=
997+
if [[ ! "${SKIP_TEST_WATCHOS_HOST}" ]] ; then
998+
test_host_only=1
999+
else
1000+
test_this_target=
1001+
fi
9771002
;;
9781003
watchsimulator-*)
9791004
build_for_this_target=$(not ${SKIP_BUILD_WATCHOS_SIMULATOR})
@@ -993,17 +1018,20 @@ for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
9931018
"${SWIFT_PERFTEST_TARGETS[@]}" "swift-perftest-${deployment_target}")
9941019
fi
9951020
if [[ "${test_this_target}" ]] ; then
1021+
if [[ -n "${test_host_only}" ]] ; then
1022+
test_target_suffix="-non-executable"
1023+
fi
9961024
if [[ "${SKIP_TEST_VALIDATION}" ]] ; then
9971025
SWIFT_TEST_TARGETS=(
998-
"${SWIFT_TEST_TARGETS[@]}" "check-swift-${deployment_target}")
999-
if [[ $(not ${SKIP_TEST_OPTIMIZED}) ]] ; then
1026+
"${SWIFT_TEST_TARGETS[@]}" "check-swift${test_target_suffix}-${deployment_target}")
1027+
if [[ $(not ${SKIP_TEST_OPTIMIZED}) && ! -n "${test_host_only}" ]] ; then
10001028
SWIFT_TEST_TARGETS=(
10011029
"${SWIFT_TEST_TARGETS[@]}" "check-swift-optimize-${deployment_target}")
10021030
fi
10031031
else
10041032
SWIFT_TEST_TARGETS=(
1005-
"${SWIFT_TEST_TARGETS[@]}" "check-swift-all-${deployment_target}")
1006-
if [[ $(not ${SKIP_TEST_OPTIMIZED}) ]] ; then
1033+
"${SWIFT_TEST_TARGETS[@]}" "check-swift-all${test_target_suffix}-${deployment_target}")
1034+
if [[ $(not ${SKIP_TEST_OPTIMIZED}) && ! -n "${test_host_only}" ]] ; then
10071035
SWIFT_TEST_TARGETS=(
10081036
"${SWIFT_TEST_TARGETS[@]}" "check-swift-all-optimize-${deployment_target}")
10091037
fi

0 commit comments

Comments
 (0)