|
1 |
| -// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) 2>&1 | %FileCheck %s --dump-input=always |
| 1 | +// RUN: %target-run-simple-leaks-swift( -Xfrontend -disable-availability-checking -parse-as-library) |
| 2 | + |
| 3 | +// This test uses `leaks` which is only available on apple platforms; limit it to macOS: |
| 4 | +// REQUIRES: OS=macosx |
| 5 | + |
2 | 6 | // REQUIRES: executable_test
|
3 | 7 | // REQUIRES: concurrency
|
4 |
| -// REQUIRES: swift_task_debug_log |
5 | 8 |
|
6 | 9 | // REQUIRES: concurrency_runtime
|
7 | 10 | // UNSUPPORTED: back_deployment_runtime
|
8 | 11 |
|
9 |
| -#if os(Linux) |
10 |
| -import Glibc |
11 |
| -#elseif os(Windows) |
12 |
| -import MSVCRT |
13 |
| -#else |
14 | 12 | import Darwin
|
15 |
| -#endif |
| 13 | + |
| 14 | +final class Something { |
| 15 | + let int: Int |
| 16 | + init(int: Int) { |
| 17 | + self.int = int |
| 18 | + } |
| 19 | +} |
16 | 20 |
|
17 | 21 | func test_taskGroup_next() async {
|
18 |
| - // CHECK: creating task [[MAIN_TASK:0x.*]] with parent 0x0 |
19 |
| - // CHECK: creating task [[GROUP_TASK_1:0x.*]] with parent [[MAIN_TASK]] |
20 |
| - // CHECK: creating task [[GROUP_TASK_2:0x.*]] with parent [[MAIN_TASK]] |
21 |
| - // CHECK: creating task [[GROUP_TASK_3:0x.*]] with parent [[MAIN_TASK]] |
22 |
| - // CHECK: creating task [[GROUP_TASK_4:0x.*]] with parent [[MAIN_TASK]] |
23 |
| - // CHECK: creating task [[GROUP_TASK_5:0x.*]] with parent [[MAIN_TASK]] |
24 |
| - |
25 |
| - _ = await withTaskGroup(of: Int.self, returning: Int.self) { group in |
26 |
| - for n in 0..<5 { |
| 22 | + let tasks = 5 |
| 23 | + _ = await withTaskGroup(of: Something.self, returning: Int.self) { group in |
| 24 | + for n in 0..<tasks { |
27 | 25 | group.spawn {
|
28 |
| - return n |
| 26 | + Something(int: n) |
29 | 27 | }
|
30 | 28 | }
|
31 |
| - await Task.sleep(2_000_000) |
32 | 29 |
|
33 | 30 | var sum = 0
|
34 | 31 | for await value in group {
|
35 |
| - sum += 1 |
| 32 | + sum += value.int |
36 | 33 | }
|
37 | 34 |
|
38 | 35 | return sum
|
39 | 36 | }
|
40 |
| - // as we exit the group, it must be guaranteed that its child tasks were destroyed |
41 |
| - // |
42 |
| - // NOTE: there is no great way to express "any of GROUP_TASK_n", |
43 |
| - // so we just check that 5 tasks were destroyed |
44 |
| - // |
45 |
| - // CHECK: destroy task [[DESTROY_GROUP_TASK_1:0x.*]] |
46 |
| - // CHECK: destroy task [[DESTROY_GROUP_TASK_2:0x.*]] |
47 |
| - // CHECK: destroy task [[DESTROY_GROUP_TASK_3:0x.*]] |
48 |
| - // CHECK: destroy task [[DESTROY_GROUP_TASK_4:0x.*]] |
49 |
| - // CHECK: destroy task [[DESTROY_GROUP_TASK_5:0x.*]] |
50 | 37 | }
|
51 | 38 |
|
52 | 39 | @main struct Main {
|
|
0 commit comments