Skip to content

Commit 6773d7e

Browse files
[NFC] [ModuleTrace] Add negative test for cycles in trace emission.
Context: rdar://66512316.
1 parent 3882beb commit 6773d7e

File tree

7 files changed

+244
-0
lines changed

7 files changed

+244
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
typedef void Runner(int);
2+
3+
struct Daemon {
4+
Runner *run;
5+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
struct MemoryMapRegion {
2+
void *start;
3+
void *end;
4+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <CoreDaemon.h>
2+
3+
struct DaemonPair {
4+
struct Daemon daemons[2];
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <CoreFilesystem-Generated.h>
2+
3+
struct FileStorage {
4+
MyNode *nodes[4];
5+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import <CoreMemory.h>
2+
#import <CoreMemory-Generated.h>
3+
4+
struct MemoryMap {
5+
MemoryMapEntry *entries;
6+
unsigned count;
7+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module CoreFilesystem {
2+
header "CoreFilesystem-Generated.h"
3+
export *
4+
}
5+
6+
module FilesystemKit {
7+
header "FilesystemKit.h"
8+
export *
9+
}
10+
11+
module CoreDaemon {
12+
header "CoreDaemon.h"
13+
export *
14+
}
15+
16+
module DaemonKit {
17+
header "DaemonKit.h"
18+
export *
19+
}
20+
21+
module CoreMemory {
22+
header "CoreMemory.h"
23+
export *
24+
}
25+
26+
module MemoryKit {
27+
header "MemoryKit.h"
28+
export *
29+
}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp -r %S/Inputs/imported_modules/ComplexModuleGraph2 %t/include
3+
4+
// REQUIRES: objc_interop
5+
6+
// Dependency graph:
7+
//
8+
// * CoreFilesystem - Swift module with generated ObjC header
9+
// * FilesystemKit - ObjC module without overlay, has #import <CoreFileystem-Generated.h>
10+
// * TestFilesystem - Swift module, has import CoreFilesystem or FilesystemKit.
11+
//
12+
// * CoreDaemon - ObjC module with overlay, the overlay has import DaemonKit
13+
// * DaemonKit - ObjC module without overlay, has #import <CoreDaemon.h>
14+
// * TestDaemon - Swift module, has import CoreDaemon or DaemonKit.
15+
// NOTE: This mimics the Darwin -> SwiftOverlayShims -> Darwin dependency "cycle".
16+
//
17+
// * CoreMemory - ObjC module with overlay and generated header for overlay, the overlay has import MemoryKit
18+
// * MemoryKit - ObjC module without overlay, has #import <CoreMemory-Generated.h>
19+
// * TestMemory - Swift module, has import CoreMemory or MemoryKit.
20+
21+
// 1. CoreFilesystem - Build.
22+
23+
// RUN: %target-swift-frontend %s -emit-module -o %t/include/CoreFilesystem.swiftmodule -DCoreFilesystem -module-name CoreFilesystem -emit-objc-header-path %t/include/CoreFilesystem-Generated.h -disable-objc-attr-requires-foundation-module
24+
25+
#if CoreFilesystem
26+
@objc
27+
public class MyNode {
28+
public var number: Int
29+
public init(_ n: Int) { number = n }
30+
}
31+
#endif
32+
33+
// 2. FilesystemKit - Nothing to do (pure Clang module).
34+
35+
// 3. TestFilesystem - Check that CoreFilesystem and Filesytem can be imported.
36+
37+
// RUN: %target-swift-frontend %s -typecheck -DTestFilesystem -DV1 -module-name TestFilesystemV1 -emit-loaded-module-trace-path %t/TestFilesystemV1.trace.json -I %t/include
38+
// RUN: %FileCheck %s --check-prefix=TESTFILESYSTEM < %t/TestFilesystemV1.trace.json
39+
// RUN: %target-swift-frontend %s -typecheck -DTestFilesystem -DV2 -module-name TestFilesystemV2 -emit-loaded-module-trace-path %t/TestFilesystemV2.trace.json -I %t/include
40+
// RUN: %FileCheck %s --check-prefix=TESTFILESYSTEM < %t/TestFilesystemV2.trace.json
41+
// RUN: %target-swift-frontend %s -typecheck -DTestFilesystem -DV3 -module-name TestFilesystemV3 -emit-loaded-module-trace-path %t/TestFilesystemV3.trace.json -I %t/include
42+
// RUN: %FileCheck %s --check-prefix=TESTFILESYSTEM < %t/TestFilesystemV3.trace.json
43+
// RUN: %target-swift-frontend %s -typecheck -DTestFilesystem -DV4 -module-name TestFilesystemV4 -emit-loaded-module-trace-path %t/TestFilesystemV4.trace.json -I %t/include
44+
// RUN: %FileCheck %s --check-prefix=TESTFILESYSTEM < %t/TestFilesystemV4.trace.json
45+
46+
#if TestFilesystem
47+
#if V1
48+
import CoreFilesystem
49+
#endif
50+
#if V2
51+
import FilesystemKit
52+
public func noop(_: CoreFilesystem.MyNode) {}
53+
#endif
54+
#if V3
55+
import CoreFilesystem
56+
import FilesystemKit
57+
#endif
58+
#if V4
59+
import FilesystemKit
60+
import CoreFilesystem
61+
#endif
62+
#endif
63+
64+
// FilesystemKit has no overlay, so it shouldn't show up.
65+
// TESTFILESYSTEM: "swiftmodulesDetailedInfo":[
66+
// TESTFILESYSTEM-NOT: FilesystemKit
67+
// TESTFILESYSTEM-DAG: {"name":"CoreFilesystem","path":"{{[^"]*}}CoreFilesystem.swiftmodule","isImportedDirectly":true,
68+
// TESTFILESYSTEM: ]
69+
70+
// 4. CoreDaemon - Build.
71+
72+
// FIXME: Trace emission shouldn't crash.
73+
// RUN: %target-swift-frontend %s -emit-module -o %t/include/CoreDaemon.swiftmodule -DCoreDaemon -module-name CoreDaemon -I %t/include
74+
// RUN: not --crash %target-swift-frontend %s -typecheck -DCoreDaemon -module-name CoreDaemon -emit-loaded-module-trace-path %t/CoreDaemon.trace.json -I %t/include 2>/dev/null
75+
// SKIP: %FileCheck %s --check-prefix=COREDAEMON < %t/CoreDaemon.trace.json
76+
77+
// * CoreDaemon - ObjC module with overlay, the overlay has import DaemonKit
78+
// * DaemonKit - ObjC module without overlay, has #import <CoreDaemon.h>
79+
// * TestDaemon - Swift module, has import CoreDaemon or DaemonKit.
80+
81+
#if CoreDaemon
82+
@_exported import CoreDaemon
83+
import DaemonKit
84+
85+
public func runBoth(_ pair: DaemonKit.DaemonPair) {
86+
let daemons : (CoreDaemon.Daemon, CoreDaemon.Daemon) = pair.daemons;
87+
daemons.0.run(0);
88+
daemons.1.run(1);
89+
}
90+
#endif
91+
92+
// COREDAEMON: "swiftmodulesDetailedInfo":[
93+
// COREDAEMON-NOT: CoreDaemon
94+
// COREDAEMON-NOT: DaemonKit
95+
// COREDAEMON: ]
96+
97+
// 5. DaemonKit - Nothing to do (pure Clang module).
98+
99+
// 6. TestCoreDaemon
100+
101+
// RUN: %target-swift-frontend %s -typecheck -DTestDaemon -DV1 -module-name TestDaemonV1 -emit-loaded-module-trace-path %t/TestDaemonV1.trace.json -I %t/include
102+
// RUN: %FileCheck %s --check-prefix=TESTDAEMON < %t/TestDaemonV1.trace.json
103+
104+
// FIXME: Trace emission shouldn't crash.
105+
// RUN: not --crash %target-swift-frontend %s -typecheck -DTestDaemon -DV2 -module-name TestDaemonV2 -emit-loaded-module-trace-path %t/TestDaemonV2.trace.json -I %t/include 2>/dev/null
106+
// SKIP: %FileCheck %s --check-prefix=TESTDAEMON < %t/TestDaemonV2.trace.json
107+
108+
// RUN: %target-swift-frontend %s -typecheck -DTestDaemon -DV3 -module-name TestDaemonV3 -emit-loaded-module-trace-path %t/TestDaemonV3.trace.json -I %t/include
109+
// RUN: %FileCheck %s --check-prefix=TESTDAEMON < %t/TestDaemonV3.trace.json
110+
111+
// FIXME: Trace emission shouldn't crash.
112+
// RUN: not --crash %target-swift-frontend %s -typecheck -DTestDaemon -DV4 -module-name TestDaemonV4 -emit-loaded-module-trace-path %t/TestDaemonV4.trace.json -I %t/include 2>/dev/null
113+
// SKIP: %FileCheck %s --check-prefix=TESTDAEMON < %t/TestDaemonV4.trace.json
114+
115+
#if TestDaemon
116+
#if V1
117+
import CoreDaemon
118+
#endif
119+
#if V2
120+
import DaemonKit
121+
public func noop(_: CoreDaemon.Daemon) {}
122+
#endif
123+
#if V3
124+
import CoreDaemon
125+
import DaemonKit
126+
#endif
127+
#if V4
128+
import DaemonKit
129+
import CoreDaemon
130+
#endif
131+
#endif
132+
133+
// DaemonKit has no overlay, so it shouldn't show up.
134+
// TESTDAEMON: "swiftmodulesDetailedInfo":[
135+
// TESTDAEMON-NOT: DaemonKit
136+
// TESTDAEMON-DAG: {"name":"CoreDaemon","path":"{{[^"]*}}CoreDaemon.swiftmodule","isImportedDirectly":true,
137+
// TESTDAEMON: ]
138+
139+
// 7. CoreMemory - Build.
140+
141+
// RUN: %target-swift-frontend %s -emit-module -o %t/include/CoreMemory.swiftmodule -DCoreMemory -module-name CoreMemory -emit-objc-header-path %t/include/CoreMemory-Generated.h -disable-objc-attr-requires-foundation-module -I %t/include
142+
143+
#if CoreMemory
144+
@_exported import CoreMemory
145+
146+
@objc
147+
public class MemoryMapEntry {
148+
public var region: MemoryMapRegion
149+
public var permissions: Int = 0
150+
public init(_ r: MemoryMapRegion) { region = r }
151+
}
152+
#endif
153+
154+
// 8. MemoryKit - Nothing to do (pure Clang module).
155+
156+
// 9. TestMemory - Check that CoreMemory and MemoryKit can be imported.
157+
158+
// RUN: %target-swift-frontend %s -typecheck -DTestMemory -DV1 -module-name TestMemoryV1 -emit-loaded-module-trace-path %t/TestMemoryV1.trace.json -I %t/include
159+
// RUN: %FileCheck %s --check-prefix=TESTMEMORY < %t/TestMemoryV1.trace.json
160+
// RUN: %target-swift-frontend %s -typecheck -DTestMemory -DV2 -module-name TestMemoryV2 -emit-loaded-module-trace-path %t/TestMemoryV2.trace.json -I %t/include
161+
// RUN: %FileCheck %s --check-prefix=TESTMEMORY < %t/TestMemoryV2.trace.json
162+
// RUN: %target-swift-frontend %s -typecheck -DTestMemory -DV3 -module-name TestMemoryV3 -emit-loaded-module-trace-path %t/TestMemoryV3.trace.json -I %t/include
163+
// RUN: %FileCheck %s --check-prefix=TESTMEMORY < %t/TestMemoryV3.trace.json
164+
// RUN: %target-swift-frontend %s -typecheck -DTestMemory -DV4 -module-name TestMemoryV4 -emit-loaded-module-trace-path %t/TestMemoryV4.trace.json -I %t/include
165+
// RUN: %FileCheck %s --check-prefix=TESTMEMORY < %t/TestMemoryV4.trace.json
166+
167+
#if TestMemory
168+
#if V1
169+
import CoreMemory
170+
#endif
171+
#if V2
172+
import MemoryKit
173+
public func noop(_: CoreMemory.MemoryMapRegion, _: CoreMemory.MemoryMapEntry) {}
174+
#endif
175+
#if V3
176+
import CoreMemory
177+
import MemoryKit
178+
#endif
179+
#if V4
180+
import MemoryKit
181+
import CoreMemory
182+
#endif
183+
#endif
184+
185+
// MemoryKit has no overlay, so it shouldn't show up.
186+
// TESTMEMORY: "swiftmodulesDetailedInfo":[
187+
// TESTMEMORY-NOT: MemoryKit
188+
// TESTMEMORY-DAG: {"name":"CoreMemory","path":"{{[^"]*}}CoreMemory.swiftmodule","isImportedDirectly":true,
189+
// TESTMEMORY: ]

0 commit comments

Comments
 (0)