Skip to content

Commit e640e14

Browse files
[Caching] Add swift-scan-test to test libSwiftScan APIs
Add a new test tool, that is a very simple driver to call into libSwiftScan APIs. This enables testing libSwiftScan interfaces directly, without relying on cross repo testing from swift-driver. This allows adding new tests for cache replay feature, that has quite some unique code path from how replay works in swift-frontend.
1 parent 9d8eac2 commit e640e14

File tree

10 files changed

+1158
-838
lines changed

10 files changed

+1158
-838
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ SWIFTSCAN_PUBLIC void swiftscan_cache_query_async(
567567
SWIFTSCAN_PUBLIC void
568568
swiftscan_cached_compilation_dispose(swiftscan_cached_compilation_t);
569569

570-
/// Download and materialized the CASObject referenced by the CASID in the local
570+
/// Download and materialize the CASObject referenced by the CASID in the local
571571
/// CAS if needed from a remote CAS.
572572
/// If the return value is SWIFTSCAN_CACHE_RESULT_ERROR, the error message is
573573
/// returned via \c error parameter and its caller needs to free the message

test/CAS/swift-scan-test.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %swift-scan-test -action compute_cache_key -cas-path %t/cas -input %s -- %target-swift-frontend -cache-compile-job -Rcache-compile-job %s \
4+
// RUN: -emit-module -emit-module-path %t/Test.swiftmodule -c -emit-dependencies -module-name Test -o %t/test.o -cas-path %t/cas \
5+
// RUN: -allow-unstable-cache-key-for-testing > %t/key.casid
6+
7+
// RUN: not %swift-scan-test -action cache_query -id @%t/key.casid -cas-path %t/cas 2>&1 | %FileCheck %s --check-prefix=CHECK-QUERY-NOT-FOUND
8+
9+
// RUN: %target-swift-frontend -cache-compile-job -Rcache-compile-job %s -emit-module -emit-module-path %t/Test.swiftmodule -c -emit-dependencies \
10+
// RUN: -module-name Test -o %t/test.o -cas-path %t/cas -allow-unstable-cache-key-for-testing
11+
12+
// RUN: %swift-scan-test -action cache_query -id @%t/key.casid -cas-path %t/cas | %FileCheck %s --check-prefix=CHECK-QUERY
13+
14+
// RUN: %swift-scan-test -action replay_result -cas-path %t/cas -id @%t/key.casid -- %target-swift-frontend -cache-compile-job -Rcache-compile-job %s \
15+
// RUN: -emit-module -emit-module-path %t/Test2.swiftmodule -c -emit-dependencies -module-name Test -o %t/test2.o -cas-path %t/cas \
16+
// RUN: -allow-unstable-cache-key-for-testing
17+
18+
// RUN: diff %t/Test.swiftmodule %t/Test2.swiftmodule
19+
// RUN: diff %t/test.o %t/test.o
20+
21+
// CHECK-QUERY-NOT-FOUND: cached output not found
22+
// CHECK-QUERY: Cached Compilation for key "llvmcas://{{.*}}" has 4 outputs: (object) (swiftmodule) (dependencies) (cached-diagnostics)
23+
24+
func testFunc() {}

test/lit.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ config.benchmark_o = inferSwiftBinary('Benchmark_O')
345345
config.benchmark_driver = inferSwiftBinary('Benchmark_Driver')
346346
config.wasm_ld = inferSwiftBinary('wasm-ld')
347347
config.swift_plugin_server = inferSwiftBinary('swift-plugin-server')
348+
config.swift_scan_test = inferSwiftBinary('swift-scan-test')
348349

349350
config.swift_utils = make_path(config.swift_src_root, 'utils')
350351
config.line_directive = make_path(config.swift_utils, 'line-directive')
@@ -636,6 +637,7 @@ config.substitutions.append( ('%llvm-strings', config.llvm_strings) )
636637
config.substitutions.append( ('%target-ptrauth', run_ptrauth ) )
637638
config.substitutions.append( ('%swift-path', config.swift) )
638639
config.substitutions.append( ('%swift-plugin-server', config.swift_plugin_server) )
640+
config.substitutions.append( ('%swift-scan-test', config.swift_scan_test) )
639641
config.substitutions.append( ('%validate-json', f"{config.python} -m json.tool") )
640642

641643
# This must come after all substitutions containing "%swift".

tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ add_swift_tool_subdirectory(libSwiftScan)
2828
add_swift_tool_subdirectory(libStaticMirror)
2929
add_swift_tool_subdirectory(libMockPlugin)
3030
add_swift_tool_subdirectory(swift-plugin-server)
31+
add_swift_tool_subdirectory(swift-scan-test)
3132

3233
if(SWIFT_INCLUDE_TESTS OR SWIFT_INCLUDE_TEST_BINARIES)
3334
add_swift_tool_subdirectory(swift-ide-test)

tools/libSwiftScan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE
77
add_swift_host_library(libSwiftScan SHARED
88
libSwiftScan.cpp
99
c-include-check.c
10+
SwiftCaching.cpp
1011
HAS_SWIFT_MODULES)
1112

1213
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)

0 commit comments

Comments
 (0)