[Lldb-commits] [lldb] r350360 - TestQueues: Move the synchronisation code into the binary itself.
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 3 14:34:48 PST 2019
Author: adrian
Date: Thu Jan 3 14:34:48 2019
New Revision: 350360
URL: http://llvm.org/viewvc/llvm-project?rev=350360&view=rev
Log:
TestQueues: Move the synchronisation code into the binary itself.
Thanks to Pavel Labath for the suggestion!
Modified:
lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py
lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/main.c
Modified: lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py?rev=350360&r1=350359&r2=350360&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py Thu Jan 3 14:34:48 2019
@@ -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)
Modified: lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/main.c?rev=350360&r1=350359&r2=350360&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/main.c (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/main.c Thu Jan 3 14:34:48 2019
@@ -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);
More information about the lldb-commits
mailing list