[Lldb-commits] [lldb] r350247 - Add file-based synchronization to flaky test

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 2 11:06:22 PST 2019


Author: adrian
Date: Wed Jan  2 11:06:22 2019
New Revision: 350247

URL: http://llvm.org/viewvc/llvm-project?rev=350247&view=rev
Log:
Add file-based synchronization to flaky test

TestQueues is failing randomly on green dragon and I suspect it is
because the enqueued threads haven't executed by the time we expect
them. This patch adds file-based synchronization to the queues.

Differential Revision: https://reviews.llvm.org/D56208

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=350247&r1=350246&r2=350247&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/TestQueues.py Wed Jan  2 11:06:22 2019
@@ -30,6 +30,16 @@ 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(6):
+            token = name+'.token.%d'%(i+1)
+            if os.path.exists(token):
+                os.remove(token)
+
+    def await_token(self, name):
+        for i in range(6):
+            lldbutil.wait_for_file_on_target(self, name+'.token.%d'%(i+1))
+
     def check_queue_for_valid_queue_id(self, queue):
         self.assertTrue(
             queue.GetQueueID() != 0, "Check queue %s for valid QueueID (got 0x%x)" %
@@ -112,12 +122,14 @@ 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(
-            None, None, self.get_process_working_directory())
+            [exe+'.token.'], 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()
@@ -271,8 +283,9 @@ 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(
-            None,
+            [exe+'.token.'],
             [
                 'DYLD_INSERT_LIBRARIES=%s' % (libbtr_path),
                 'DYLD_LIBRARY_PATH=/usr/lib/system/introspection'],
@@ -284,6 +297,7 @@ 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=350247&r1=350246&r2=350247&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/main.c (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/macosx/queues/main.c Wed Jan  2 11:06:22 2019
@@ -1,4 +1,6 @@
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <dispatch/dispatch.h>
 #include <pthread.h>
@@ -6,6 +8,19 @@
 int finished_enqueueing_work = 0;
 
 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);
+}
+
+void
 doing_the_work_1(void *in)
 {
     while (1)
@@ -77,7 +92,7 @@ stopper ()
 }
 
 
-int main ()
+int main (int argc, const char **argv)
 {
     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);
@@ -100,31 +115,37 @@ int main ()
 
     dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
             pthread_setname_np ("user initiated QoS");
+            touch(argv[1], 1);
             while (1)
                 sleep (10);
                 });
     dispatch_async (dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
             pthread_setname_np ("user interactive QoS");
+            touch(argv[1], 2);
             while (1)
                 sleep (10);
                 });
     dispatch_async (dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
             pthread_setname_np ("default QoS");
+            touch(argv[1], 3);
             while (1)
                 sleep (10);
                 });
     dispatch_async (dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
             pthread_setname_np ("utility QoS");
+            touch(argv[1], 4);
             while (1)
                 sleep (10);
                 });
     dispatch_async (dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
             pthread_setname_np ("background QoS");
+            touch(argv[1], 5);
             while (1)
                 sleep (10);
                 });
     dispatch_async (dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0), ^{
             pthread_setname_np ("unspecified QoS");
+            touch(argv[1], 6);
             while (1)
                 sleep (10);
                 });




More information about the lldb-commits mailing list