Revert "[lldb][test] Remove compiler version check and use regex" (#124101)
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / io-cleanup.c
blob8c0ad8f6391ae68b78a48728587c8e9145998cc5
1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
4 #include <dispatch/dispatch.h>
6 #include <stdio.h>
7 #include <stdlib.h>
9 long my_global = 0;
11 int main(int argc, const char *argv[]) {
12 fprintf(stderr, "Hello world.\n");
14 dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
15 dispatch_semaphore_t sem = dispatch_semaphore_create(0);
16 const char *path = tempnam(NULL, "libdispatch-io-cleanup-");
17 dispatch_io_t channel;
19 dispatch_fd_t fd = open(path, O_CREAT | O_WRONLY, 0666);
20 my_global++;
21 channel = dispatch_io_create(DISPATCH_IO_STREAM, fd, queue, ^(int error) {
22 my_global++;
23 dispatch_semaphore_signal(sem);
24 });
25 if (! channel) abort();
26 my_global++;
27 dispatch_io_close(channel, 0);
28 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
30 my_global++;
31 channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY, 0666, queue, ^(int error) {
32 my_global++;
33 dispatch_semaphore_signal(sem);
34 });
35 if (! channel) abort();
36 my_global++;
37 dispatch_io_close(channel, 0);
38 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
40 my_global++;
41 dispatch_io_t other_channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY, 0666, queue, ^(int error) { });
42 channel = dispatch_io_create_with_io(DISPATCH_IO_STREAM, other_channel, queue, ^(int error) {
43 my_global++;
44 dispatch_semaphore_signal(sem);
45 });
46 if (! channel) abort();
47 my_global++;
48 dispatch_io_close(channel, 0);
49 dispatch_io_close(other_channel, 0);
50 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
52 fprintf(stderr, "Done.\n");
53 return 0;
56 // CHECK: Hello world.
57 // CHECK: Done.