Skip to content

Commit bfcbd67

Browse files
committed
[TSan][libdispatch] Replace NSTemporaryDirectory in tests
After this change, most tests don't have a dependency on Foundation. Note: To hold the file name `tempnam` allocates a new buffer. We leak this buffer (omit the free), but I don't think we need to care. Reviewed By: kubamracek Differential Revision: https://reviews.llvm.org/D60591 llvm-svn: 358308
1 parent 0d0334f commit bfcbd67

File tree

6 files changed

+8
-13
lines changed

6 files changed

+8
-13
lines changed

compiler-rt/test/tsan/Darwin/gcd-fd.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ int main(int argc, const char *argv[]) {
1111
dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
1212
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
1313

14-
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
14+
const char *path = tempnam(NULL, "libdispatch-fd-");
1515

16-
dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path.fileSystemRepresentation, O_CREAT | O_WRONLY,
16+
dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY,
1717
0666, queue, ^(int error) { });
1818
dispatch_io_set_high_water(channel, 1);
1919

@@ -34,7 +34,7 @@ int main(int argc, const char *argv[]) {
3434
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
3535
my_global++;
3636
dispatch_io_close(channel, 0);
37-
channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path.fileSystemRepresentation, O_RDONLY,
37+
channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_RDONLY,
3838
0, queue, ^(int error) { });
3939
dispatch_io_set_high_water(channel, 1);
4040

compiler-rt/test/tsan/Darwin/gcd-io-barrier-race.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ int main(int argc, const char *argv[]) {
1919

2020
queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
2121
sem = dispatch_semaphore_create(0);
22-
NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
23-
path = ns_path.fileSystemRepresentation;
22+
path = tempnam(NULL, "libdispatch-io-barrier-race-");
2423
char buf[1000];
2524
data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
2625

compiler-rt/test/tsan/Darwin/gcd-io-barrier.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ int main(int argc, const char *argv[]) {
1515

1616
queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
1717
sem = dispatch_semaphore_create(0);
18-
NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
19-
path = ns_path.fileSystemRepresentation;
18+
path = tempnam(NULL, "libdispatch-io-barrier");
2019
char buf[1000];
2120
data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
2221

compiler-rt/test/tsan/Darwin/gcd-io-cleanup.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ int main(int argc, const char *argv[]) {
1010

1111
dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
1212
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
13-
NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
14-
const char *path = ns_path.fileSystemRepresentation;
13+
const char *path = tempnam(NULL, "libdispatch-io-cleanup-");
1514
dispatch_io_t channel;
1615

1716
dispatch_fd_t fd = open(path, O_CREAT | O_WRONLY, 0666);

compiler-rt/test/tsan/Darwin/gcd-io-race.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ int main(int argc, const char *argv[]) {
2121

2222
queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
2323
sem = dispatch_semaphore_create(0);
24-
NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
25-
path = ns_path.fileSystemRepresentation;
24+
path = tempnam(NULL, "libdispatch-io-race");
2625
char buf[1000];
2726
data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
2827

compiler-rt/test/tsan/Darwin/gcd-io.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ int main(int argc, const char *argv[]) {
9898

9999
queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
100100
sem = dispatch_semaphore_create(0);
101-
NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
102-
path = ns_path.fileSystemRepresentation;
101+
path = tempnam(NULL, "libdispatch-io-");
103102
char buf[1000];
104103
data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
105104

0 commit comments

Comments
 (0)