diff options
author | Adrian Prantl <aprantl@apple.com> | 2019-01-03 22:34:48 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2019-01-03 22:34:48 +0000 |
commit | a07bba60d0f0ee4890aa2939b0d66735a5cb616d (patch) | |
tree | 6305c5e699face428da6871ef9e3cc780d6c1edd /lldb/packages/Python/lldbsuite/test/macosx | |
parent | 58c61dce1d8313b875ccaa18913915a0717c845d (diff) | |
download | bcm5719-llvm-a07bba60d0f0ee4890aa2939b0d66735a5cb616d.tar.gz bcm5719-llvm-a07bba60d0f0ee4890aa2939b0d66735a5cb616d.zip |
TestQueues: Move the synchronisation code into the binary itself.
Thanks to Pavel Labath for the suggestion!
llvm-svn: 350360
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/macosx')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py | 18 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/macosx/queues/main.c | 39 |
2 files changed, 14 insertions, 43 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py b/lldb/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py index 2cd685bb758..c0becc51ad5 100644 --- a/lldb/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py +++ b/lldb/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py @@ -30,16 +30,6 @@ class TestQueues(TestBase): # Find the line numbers that we will step to in main: self.main_source = "main.c" - def remove_token(self, name): - for i in range(7): - token = name+'.token.%d'%i - if os.path.exists(token): - os.remove(token) - - def await_token(self, name): - for i in range(7): - lldbutil.wait_for_file_on_target(self, name+'.token.%d'%i) - def check_queue_for_valid_queue_id(self, queue): self.assertTrue( queue.GetQueueID() != 0, "Check queue %s for valid QueueID (got 0x%x)" % @@ -122,14 +112,12 @@ class TestQueues(TestBase): self.main_source_spec = lldb.SBFileSpec(self.main_source) break1 = target.BreakpointCreateByName("stopper", 'a.out') self.assertTrue(break1, VALID_BREAKPOINT) - self.remove_token(exe) process = target.LaunchSimple( - [exe+'.token.'], None, self.get_process_working_directory()) + [], None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1) if len(threads) != 1: self.fail("Failed to stop at breakpoint 1.") - self.await_token(exe) queue_submittor_1 = lldb.SBQueue() queue_performer_1 = lldb.SBQueue() @@ -283,9 +271,8 @@ class TestQueues(TestBase): if self.getArchitecture() in ['arm', 'arm64', 'arm64e', 'arm64_32', 'armv7', 'armv7k']: libbtr_path = "/Developer/usr/lib/libBacktraceRecording.dylib" - self.remove_token(exe) process = target.LaunchSimple( - [exe+'.token.'], + [], [ 'DYLD_INSERT_LIBRARIES=%s' % (libbtr_path), 'DYLD_LIBRARY_PATH=/usr/lib/system/introspection'], @@ -297,7 +284,6 @@ class TestQueues(TestBase): threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1) if len(threads) != 1: self.fail("Failed to stop at breakpoint 1.") - self.await_token(exe) libbtr_module_filespec = lldb.SBFileSpec("libBacktraceRecording.dylib") libbtr_module = target.FindModule(libbtr_module_filespec) diff --git a/lldb/packages/Python/lldbsuite/test/macosx/queues/main.c b/lldb/packages/Python/lldbsuite/test/macosx/queues/main.c index f2a73f19e9f..910853642a6 100644 --- a/lldb/packages/Python/lldbsuite/test/macosx/queues/main.c +++ b/lldb/packages/Python/lldbsuite/test/macosx/queues/main.c @@ -1,30 +1,16 @@ -#include <stdio.h> -#include <stdlib.h> +#include <stdatomic.h> #include <string.h> #include <unistd.h> #include <dispatch/dispatch.h> #include <pthread.h> int finished_enqueueing_work = 0; -char *name = NULL; - -void -touch (const char *name, unsigned n) -{ - char token[2048]; - snprintf (token, 2048, "%s%d", name, n); - FILE *f = fopen (token, "wx"); - if (!f) - exit (1); - fputs ("\n", f); - fflush (f); - fclose (f); -} +atomic_int thread_count = 0; void doing_the_work_1(void *in) { - touch (name, 0); + atomic_fetch_add(&thread_count, 1); while (1) sleep (1); } @@ -96,9 +82,6 @@ stopper () int main (int argc, const char **argv) { - if (argc != 2) - return 2; - name = argv[1]; dispatch_queue_t work_submittor_1 = dispatch_queue_create ("com.apple.work_submittor_1", DISPATCH_QUEUE_SERIAL); dispatch_queue_t work_submittor_2 = dispatch_queue_create ("com.apple.work_submittor_and_quit_2", DISPATCH_QUEUE_SERIAL); dispatch_queue_t work_submittor_3 = dispatch_queue_create ("com.apple.work_submittor_3", DISPATCH_QUEUE_SERIAL); @@ -117,44 +100,46 @@ int main (int argc, const char **argv) // Spin up threads with each of the different libdispatch QoS values. - dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ pthread_setname_np ("user initiated QoS"); - touch(name, 1); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{ pthread_setname_np ("user interactive QoS"); - touch(name, 2); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{ pthread_setname_np ("default QoS"); - touch(name, 3); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{ pthread_setname_np ("utility QoS"); - touch(name, 4); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ pthread_setname_np ("background QoS"); - touch(name, 5); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); }); dispatch_async (dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{ pthread_setname_np ("unspecified QoS"); - touch(name, 6); + atomic_fetch_add(&thread_count, 1); while (1) sleep (10); }); + // Unfortunately there is no pthread_barrier on darwin. + while (atomic_load(&thread_count) < 7) + sleep(1); while (finished_enqueueing_work == 0) sleep (1); |