Skip to content

Commit 280123c

Browse files
committed
[embedded] Add a test checking the dependencies of Embedded Concurrency runtime
1 parent 44a2661 commit 280123c

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

stdlib/public/Concurrency/TaskAlloc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ static TaskAllocator &allocator(AsyncTask *task) {
4040
if (task)
4141
return task->Private.get().Allocator;
4242

43+
#if !SWIFT_CONCURRENCY_EMBEDDED
4344
// FIXME: this fall-back shouldn't be necessary, but it's useful
4445
// for now, since the current execution tests aren't setting up a task
4546
// properly.
4647
static GlobalAllocator global;
4748
return global.allocator;
49+
#else
50+
fprintf(stderr, "global allocator fallback not available\n");
51+
abort();
52+
#endif
4853
}
4954

5055
void *swift::swift_task_alloc(size_t size) {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -target %target-cpu-apple-macos14 -disable-availability-checking -parse-as-library -enable-experimental-feature Embedded %s -c -o %t/a.o
3+
// RUN: %target-clang %t/a.o -o %t/a.out %swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos/libswift_Concurrency.a -dead_strip
4+
5+
// RUN: grep DEP\: %s | sed 's#// DEP\: ##' | sort > %t/allowed-dependencies.txt
6+
7+
// RUN: %llvm-nm --undefined-only --format=just-symbols %t/a.out | sort | tee %t/actual-dependencies.txt
8+
9+
// Fail if there is any entry in actual-dependencies.txt that's not in allowed-dependencies.txt
10+
// RUN: test -z "`comm -13 %t/allowed-dependencies.txt %t/actual-dependencies.txt`"
11+
12+
// DEP: __ZNSt3__111this_thread9sleep_forERKNS_6chrono8durationIxNS_5ratioILl1ELl1000000000EEEEE
13+
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc
14+
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKcm
15+
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6insertEmPKc
16+
// DEP: __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev
17+
// DEP: __ZNSt3__16chrono12steady_clock3nowEv
18+
// DEP: __ZNSt3__19to_stringEj
19+
// DEP: __ZNSt3__19to_stringEy
20+
// DEP: __ZdlPv
21+
// DEP: __Znwm
22+
// DEP: ___assert_rtn
23+
// DEP: ___stack_chk_fail
24+
// DEP: ___stack_chk_guard
25+
// DEP: ___stderrp
26+
// DEP: _abort
27+
// DEP: _asl_log
28+
// DEP: _exit
29+
// DEP: _fprintf
30+
// DEP: _free
31+
// DEP: _malloc
32+
// DEP: _memcpy
33+
// DEP: _memset_s
34+
// DEP: _os_unfair_lock_lock
35+
// DEP: _os_unfair_lock_unlock
36+
// DEP: _posix_memalign
37+
// DEP: _pthread_equal
38+
// DEP: _pthread_getspecific
39+
// DEP: _pthread_self
40+
// DEP: _pthread_setspecific
41+
// DEP: _putchar
42+
// DEP: _strlen
43+
// DEP: _vfprintf
44+
// DEP: _vsnprintf
45+
// DEP: _write
46+
// DEP: dyld_stub_binder
47+
48+
// RUN: %target-run %t/a.out | %FileCheck %s
49+
50+
// REQUIRES: swift_in_compiler
51+
// REQUIRES: executable_test
52+
// REQUIRES: optimized_stdlib
53+
// REQUIRES: OS=macosx
54+
55+
import _Concurrency
56+
57+
public func test() async -> Int {
58+
print("test")
59+
let t = Task {
60+
print("return 42")
61+
return 42
62+
}
63+
print("await")
64+
let v = await t.value
65+
print("return")
66+
return v
67+
}
68+
69+
@main
70+
struct Main {
71+
static func main() async {
72+
print("main")
73+
// CHECK: main
74+
let t = Task {
75+
print("task")
76+
let x = await test()
77+
print(x == 42 ? "42" : "???")
78+
}
79+
print("after task")
80+
await t.value
81+
// CHECK-NEXT: after task
82+
// CHECK-NEXT: task
83+
// CHECK-NEXT: test
84+
// CHECK-NEXT: await
85+
// CHECK-NEXT: return 42
86+
// CHECK-NEXT: return
87+
// CHECK-NEXT: 42
88+
}
89+
}

0 commit comments

Comments
 (0)