[compiler-rt] r358308 - [TSan][libdispatch] Replace NSTemporaryDirectory in tests

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 12 13:27:02 PDT 2019


Author: yln
Date: Fri Apr 12 13:27:02 2019
New Revision: 358308

URL: http://llvm.org/viewvc/llvm-project?rev=358308&view=rev
Log:
[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

Modified:
    compiler-rt/trunk/test/tsan/Darwin/gcd-fd.mm
    compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier-race.mm
    compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier.mm
    compiler-rt/trunk/test/tsan/Darwin/gcd-io-cleanup.mm
    compiler-rt/trunk/test/tsan/Darwin/gcd-io-race.mm
    compiler-rt/trunk/test/tsan/Darwin/gcd-io.mm

Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-fd.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-fd.mm?rev=358308&r1=358307&r2=358308&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-fd.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-fd.mm Fri Apr 12 13:27:02 2019
@@ -11,9 +11,9 @@ int main(int argc, const char *argv[]) {
   dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
   dispatch_semaphore_t sem = dispatch_semaphore_create(0);
 
-  NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
+  const char *path = tempnam(NULL, "libdispatch-fd-");
 
-  dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path.fileSystemRepresentation, O_CREAT | O_WRONLY,
+  dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY,
       0666, queue, ^(int error) { });
   dispatch_io_set_high_water(channel, 1);
 
@@ -34,7 +34,7 @@ int main(int argc, const char *argv[]) {
   dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
   my_global++;
   dispatch_io_close(channel, 0);
-  channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path.fileSystemRepresentation, O_RDONLY,
+  channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_RDONLY,
       0, queue, ^(int error) { });
   dispatch_io_set_high_water(channel, 1);
 

Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier-race.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier-race.mm?rev=358308&r1=358307&r2=358308&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier-race.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier-race.mm Fri Apr 12 13:27:02 2019
@@ -19,8 +19,7 @@ int main(int argc, const char *argv[]) {
 
   queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
   sem = dispatch_semaphore_create(0);
-  NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
-  path = ns_path.fileSystemRepresentation;
+  path = tempnam(NULL, "libdispatch-io-barrier-race-");
   char buf[1000];
   data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
   

Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier.mm?rev=358308&r1=358307&r2=358308&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-io-barrier.mm Fri Apr 12 13:27:02 2019
@@ -15,8 +15,7 @@ int main(int argc, const char *argv[]) {
   
   queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
   sem = dispatch_semaphore_create(0);
-  NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
-  path = ns_path.fileSystemRepresentation;
+  path = tempnam(NULL, "libdispatch-io-barrier");
   char buf[1000];
   data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
   

Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-io-cleanup.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-io-cleanup.mm?rev=358308&r1=358307&r2=358308&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-io-cleanup.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-io-cleanup.mm Fri Apr 12 13:27:02 2019
@@ -10,8 +10,7 @@ int main(int argc, const char *argv[]) {
   
   dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
   dispatch_semaphore_t sem = dispatch_semaphore_create(0);
-  NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
-  const char *path = ns_path.fileSystemRepresentation;
+  const char *path = tempnam(NULL, "libdispatch-io-cleanup-");
   dispatch_io_t channel;
   
   dispatch_fd_t fd = open(path, O_CREAT | O_WRONLY, 0666);

Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-io-race.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-io-race.mm?rev=358308&r1=358307&r2=358308&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-io-race.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-io-race.mm Fri Apr 12 13:27:02 2019
@@ -21,8 +21,7 @@ int main(int argc, const char *argv[]) {
   
   queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
   sem = dispatch_semaphore_create(0);
-  NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
-  path = ns_path.fileSystemRepresentation;
+  path = tempnam(NULL, "libdispatch-io-race");
   char buf[1000];
   data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
   

Modified: compiler-rt/trunk/test/tsan/Darwin/gcd-io.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/Darwin/gcd-io.mm?rev=358308&r1=358307&r2=358308&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/Darwin/gcd-io.mm (original)
+++ compiler-rt/trunk/test/tsan/Darwin/gcd-io.mm Fri Apr 12 13:27:02 2019
@@ -98,8 +98,7 @@ int main(int argc, const char *argv[]) {
   
   queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
   sem = dispatch_semaphore_create(0);
-  NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
-  path = ns_path.fileSystemRepresentation;
+  path = tempnam(NULL, "libdispatch-io-");
   char buf[1000];
   data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
   




More information about the llvm-commits mailing list