Skip to content

Commit c82e76b

Browse files
committed
[ModuleInterface] Overhaul module-cache tests for clarity, independence.
1 parent 0a3bd3e commit c82e76b

10 files changed

+351
-124
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
#
3+
# check-is-new.py - a more-legible way to read a timestamp test than test(1)
4+
#
5+
# This source file is part of the Swift.org open source project
6+
#
7+
# Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
8+
# Licensed under Apache License v2.0 with Runtime Library Exception
9+
#
10+
# See https://swift.org/LICENSE.txt for license information
11+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
#
13+
# ----------------------------------------------------------------------------
14+
#
15+
# Compares the mtime of the provided files to a constant "old" reference time.
16+
# Fails if any file is as-old-or-older than old.
17+
#
18+
# ----------------------------------------------------------------------------
19+
20+
import os
21+
import sys
22+
23+
OLD = 1390550700 # 2014-01-24T08:05:00+00:00
24+
for f in sys.argv[1:]:
25+
if os.stat(f).st_mtime <= OLD:
26+
print("%s is not new!" % f)
27+
exit(1)
28+
29+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
#
3+
# check-is-old.py - a more-legible way to read a timestamp test than test(1)
4+
#
5+
# This source file is part of the Swift.org open source project
6+
#
7+
# Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
8+
# Licensed under Apache License v2.0 with Runtime Library Exception
9+
#
10+
# See https://swift.org/LICENSE.txt for license information
11+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
#
13+
# ----------------------------------------------------------------------------
14+
#
15+
# Compares the mtime of the provided files to a constant "old" reference time.
16+
# Fails if any file has mtime not-equal to old.
17+
#
18+
# ----------------------------------------------------------------------------
19+
20+
import os
21+
import sys
22+
23+
OLD = 1390550700 # 2014-01-24T08:05:00+00:00
24+
for f in sys.argv[1:]:
25+
if os.stat(f).st_mtime != OLD:
26+
print("%s is not old!" % f)
27+
exit(1)
28+
29+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
#
3+
# make-old.py - /bin/touch that writes a constant "old" timestamp.
4+
#
5+
# This source file is part of the Swift.org open source project
6+
#
7+
# Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
8+
# Licensed under Apache License v2.0 with Runtime Library Exception
9+
#
10+
# See https://swift.org/LICENSE.txt for license information
11+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
#
13+
# ----------------------------------------------------------------------------
14+
#
15+
# Like /bin/touch, but writes a constant "old" timestamp.
16+
#
17+
# ----------------------------------------------------------------------------
18+
19+
import os
20+
import sys
21+
22+
OLD = 1390550700 # 2014-01-24T08:05:00+00:00
23+
for f in sys.argv[1:]:
24+
os.utime(f, (OLD, OLD))

test/ParseableInterface/client.swift

Lines changed: 0 additions & 124 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/modulecache)
3+
//
4+
// Test will build a module TestModule that depends on OtherModule and LeafModule (built from other.swift and leaf.swift).
5+
//
6+
// RUN: echo 'public func LeafFunc() -> Int { return 10; }' >%t/leaf.swift
7+
//
8+
// RUN: echo 'import LeafModule' >%t/other.swift
9+
// RUN: echo 'public func OtherFunc() -> Int { return LeafFunc(); }' >>%t/other.swift
10+
//
11+
// Phase 1: build LeafModule into a .swiftinterface file:
12+
//
13+
// RUN: %target-swift-frontend -I %t -emit-parseable-module-interface-path %t/LeafModule.swiftinterface -module-name LeafModule %t/leaf.swift -emit-module -o /dev/null
14+
// RUN: test -f %t/LeafModule.swiftinterface
15+
// RUN: %FileCheck %s -check-prefix=CHECK-LEAFINTERFACE <%t/LeafModule.swiftinterface
16+
// CHECK-LEAFINTERFACE: LeafFunc
17+
//
18+
//
19+
// Phase 2: build OtherModule into a .swiftinterface _using_ LeafModule via LeafModule.swiftinterface, creating LeafModule-*.swiftmodule along the way.
20+
//
21+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-parseable-module-interface-path %t/OtherModule.swiftinterface -module-name OtherModule %t/other.swift -emit-module -o /dev/null
22+
// RUN: test -f %t/OtherModule.swiftinterface
23+
// RUN: %FileCheck %s -check-prefix=CHECK-OTHERINTERFACE <%t/OtherModule.swiftinterface
24+
// CHECK-OTHERINTERFACE: OtherFunc
25+
// RUN: test -f %t/modulecache/LeafModule-*.swiftmodule
26+
// RUN: llvm-bcanalyzer -dump %t/modulecache/LeafModule-*.swiftmodule | %FileCheck %s -check-prefix=CHECK-LEAFMODULE
27+
// CHECK-LEAFMODULE: {{MODULE_NAME.*blob data = 'LeafModule'}}
28+
// CHECK-LEAFMODULE: {{FILE_DEPENDENCY.*Swift.swiftmodule'}}
29+
// CHECK-LEAFMODULE: {{FILE_DEPENDENCY.*SwiftOnoneSupport.swiftmodule'}}
30+
// CHECK-LEAFMODULE: {{FILE_DEPENDENCY.*LeafModule.swiftinterface'}}
31+
// CHECK-LEAFMODULE: FUNC_DECL
32+
//
33+
//
34+
// Phase 3: build TestModule into a .swiftmodule explicitly us OtherModule via OtherModule.swiftinterface, creating OtherModule-*.swiftmodule along the way.
35+
//
36+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
37+
// RUN: test -f %t/TestModule.swiftmodule
38+
// RUN: test -f %t/modulecache/OtherModule-*.swiftmodule
39+
// RUN: llvm-bcanalyzer -dump %t/modulecache/OtherModule-*.swiftmodule | %FileCheck %s -check-prefix=CHECK-OTHERMODULE
40+
// CHECK-OTHERMODULE: {{MODULE_NAME.*blob data = 'OtherModule'}}
41+
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*Swift.swiftmodule'}}
42+
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*SwiftOnoneSupport.swiftmodule'}}
43+
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*LeafModule-.*.swiftmodule'}}
44+
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*OtherModule.swiftinterface'}}
45+
// CHECK-OTHERMODULE: FUNC_DECL
46+
47+
import OtherModule
48+
49+
public func TestFunc() {
50+
print(OtherFunc())
51+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/modulecache)
3+
//
4+
// Setup builds a module TestModule that depends on OtherModule and LeafModule (built from other.swift and leaf.swift).
5+
// During setup, input and intermediate mtimes are all set to a constant 'old' time (long in the past).
6+
//
7+
// We then modify OtherModule.swiftinterface, and check only OtherModule-*.swiftmodule has a new mtime, LeafModule is unchanged.
8+
//
9+
//
10+
// Setup phase 1: Write input files.
11+
//
12+
// RUN: echo 'public func LeafFunc() -> Int { return 10; }' >%t/leaf.swift
13+
//
14+
// RUN: echo 'import LeafModule' >%t/other.swift
15+
// RUN: echo 'public func OtherFunc() -> Int { return LeafFunc(); }' >>%t/other.swift
16+
//
17+
//
18+
// Setup phase 2: build modules, pushing timestamps of inputs and intermediates into the past as we go.
19+
//
20+
// RUN: %S/Inputs/make-old.py %t/leaf.swift %t/other.swift
21+
// RUN: %target-swift-frontend -I %t -emit-parseable-module-interface-path %t/LeafModule.swiftinterface -module-name LeafModule %t/leaf.swift -emit-module -o /dev/null
22+
// RUN: %S/Inputs/make-old.py %t/LeafModule.swiftinterface
23+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-parseable-module-interface-path %t/OtherModule.swiftinterface -module-name OtherModule %t/other.swift -emit-module -o /dev/null
24+
// RUN: %S/Inputs/make-old.py %t/modulecache/LeafModule-*.swiftmodule %t/OtherModule.swiftinterface
25+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
26+
// RUN: %S/Inputs/make-old.py %t/modulecache/OtherModule-*.swiftmodule
27+
//
28+
//
29+
// Actual test: make OtherModule.swiftinterface newer, check we only rebuild its cached module.
30+
//
31+
// RUN: %S/Inputs/check-is-old.py %t/OtherModule.swiftinterface %t/LeafModule.swiftinterface
32+
// RUN: %S/Inputs/check-is-old.py %t/modulecache/OtherModule-*.swiftmodule %t/modulecache/LeafModule-*.swiftmodule
33+
// RUN: touch %t/OtherModule.swiftinterface
34+
// RUN: %S/Inputs/check-is-new.py %t/OtherModule.swiftinterface
35+
// RUN: rm %t/TestModule.swiftmodule
36+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
37+
// RUN: %S/Inputs/check-is-new.py %t/modulecache/OtherModule-*.swiftmodule
38+
// RUN: %S/Inputs/check-is-old.py %t/modulecache/LeafModule-*.swiftmodule
39+
40+
import OtherModule
41+
42+
public func TestFunc() {
43+
print(OtherFunc())
44+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/modulecache)
3+
//
4+
// Setup builds a module TestModule that depends on OtherModule and LeafModule (built from other.swift and leaf.swift).
5+
// During setup, input and intermediate mtimes are all set to a constant 'old' time (long in the past).
6+
//
7+
// We then modify OtherModule.swiftinterface's size (but not mtime), and check only OtherModule-*.swiftmodule has a new mtime, LeafModule is unchanged.
8+
//
9+
//
10+
// Setup phase 1: Write input files.
11+
//
12+
// RUN: echo 'public func LeafFunc() -> Int { return 10; }' >%t/leaf.swift
13+
//
14+
// RUN: echo 'import LeafModule' >%t/other.swift
15+
// RUN: echo 'public func OtherFunc() -> Int { return LeafFunc(); }' >>%t/other.swift
16+
//
17+
//
18+
// Setup phase 2: build modules, pushing timestamps of inputs and intermediates into the past as we go.
19+
//
20+
// RUN: %S/Inputs/make-old.py %t/leaf.swift %t/other.swift
21+
// RUN: %target-swift-frontend -I %t -emit-parseable-module-interface-path %t/LeafModule.swiftinterface -module-name LeafModule %t/leaf.swift -emit-module -o /dev/null
22+
// RUN: %S/Inputs/make-old.py %t/LeafModule.swiftinterface
23+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-parseable-module-interface-path %t/OtherModule.swiftinterface -module-name OtherModule %t/other.swift -emit-module -o /dev/null
24+
// RUN: %S/Inputs/make-old.py %t/modulecache/LeafModule-*.swiftmodule %t/OtherModule.swiftinterface
25+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
26+
// RUN: %S/Inputs/make-old.py %t/modulecache/OtherModule-*.swiftmodule
27+
//
28+
//
29+
// Actual test: make OtherModule.swiftinterface change size without changing mtime, check we only rebuild its cached module.
30+
//
31+
// RUN: %S/Inputs/check-is-old.py %t/OtherModule.swiftinterface %t/LeafModule.swiftinterface
32+
// RUN: %S/Inputs/check-is-old.py %t/modulecache/OtherModule-*.swiftmodule %t/modulecache/LeafModule-*.swiftmodule
33+
// RUN: echo "// size change" >>%t/OtherModule.swiftinterface
34+
// RUN: %S/Inputs/make-old.py %t/OtherModule.swiftinterface
35+
// RUN: %S/Inputs/check-is-old.py %t/OtherModule.swiftinterface
36+
// RUN: rm %t/TestModule.swiftmodule
37+
// RUN: %target-swift-frontend -I %t -module-cache-path %t/modulecache -enable-parseable-module-interface -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %s
38+
// RUN: %S/Inputs/check-is-new.py %t/modulecache/OtherModule-*.swiftmodule
39+
// RUN: %S/Inputs/check-is-old.py %t/modulecache/LeafModule-*.swiftmodule
40+
41+
import OtherModule
42+
43+
public func TestFunc() {
44+
print(OtherFunc())
45+
}

0 commit comments

Comments
 (0)