DavidSpickett created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Previously we would "process continue" then wait for the number of
threads to be 3 before proceeding with the test.

Testing this on QEMU I saw it would sometimes get stuck at this check,
with one of the threads on a breakpoint before the other had started.
We do want it to be on a breakpoint, but we need the other thread to have
at least started so lldb can interact with both.

I've also seen it timeout on the Graviton buildbot, likely the same
cause.

To fix this add 2 variables to stall either thread until the other
has started up. Then it doesn't matter which one hits its breakpoint
first, the test will just continue the one that didn't, until both
are on the expected breakpoint.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157967

Files:
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/main.c


Index: 
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/main.c
===================================================================
--- 
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/main.c
+++ 
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/main.c
@@ -1,4 +1,6 @@
 #include <pthread.h>
+#include <stdatomic.h>
+#include <stdbool.h>
 #include <sys/prctl.h>
 
 #ifndef PR_SME_SET_VL
@@ -62,7 +64,18 @@
 
 int SET_VL_OPT = PR_SVE_SET_VL;
 
+// These ensure that when lldb stops in one of threadX / threadY, the other has
+// at least been created. That means we can continue the other onto the 
expected
+// breakpoint. Otherwise we could get to the breakpoint in one thread before 
the
+// other has started.
+atomic_bool threadX_ready = false;
+atomic_bool threadY_ready = false;
+
 void *threadX_func(void *x_arg) {
+  threadX_ready = true;
+  while (!threadY_ready) {
+  }
+
   prctl(SET_VL_OPT, 8 * 4);
 #ifdef USE_SSVE
   SMSTART();
@@ -73,6 +86,10 @@
 }
 
 void *threadY_func(void *y_arg) {
+  threadY_ready = true;
+  while (!threadX_ready) {
+  }
+
   prctl(SET_VL_OPT, 8 * 2);
 #ifdef USE_SSVE
   SMSTART();
Index: 
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
===================================================================
--- 
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
+++ 
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
@@ -148,10 +148,6 @@
 
         self.runCmd("process continue", RUN_SUCCEEDED)
 
-        # If we start the checks too quickly, thread 3 may not have started.
-        while process.GetNumThreads() < 3:
-            pass
-
         for idx in range(1, process.GetNumThreads()):
             thread = process.GetThreadAtIndex(idx)
             if thread.GetStopReason() != lldb.eStopReasonBreakpoint:


Index: lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/main.c
===================================================================
--- lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/main.c
+++ lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/main.c
@@ -1,4 +1,6 @@
 #include <pthread.h>
+#include <stdatomic.h>
+#include <stdbool.h>
 #include <sys/prctl.h>
 
 #ifndef PR_SME_SET_VL
@@ -62,7 +64,18 @@
 
 int SET_VL_OPT = PR_SVE_SET_VL;
 
+// These ensure that when lldb stops in one of threadX / threadY, the other has
+// at least been created. That means we can continue the other onto the expected
+// breakpoint. Otherwise we could get to the breakpoint in one thread before the
+// other has started.
+atomic_bool threadX_ready = false;
+atomic_bool threadY_ready = false;
+
 void *threadX_func(void *x_arg) {
+  threadX_ready = true;
+  while (!threadY_ready) {
+  }
+
   prctl(SET_VL_OPT, 8 * 4);
 #ifdef USE_SSVE
   SMSTART();
@@ -73,6 +86,10 @@
 }
 
 void *threadY_func(void *y_arg) {
+  threadY_ready = true;
+  while (!threadX_ready) {
+  }
+
   prctl(SET_VL_OPT, 8 * 2);
 #ifdef USE_SSVE
   SMSTART();
Index: lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
===================================================================
--- lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
+++ lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
@@ -148,10 +148,6 @@
 
         self.runCmd("process continue", RUN_SUCCEEDED)
 
-        # If we start the checks too quickly, thread 3 may not have started.
-        while process.GetNumThreads() < 3:
-            pass
-
         for idx in range(1, process.GetNumThreads()):
             thread = process.GetThreadAtIndex(idx)
             if thread.GetStopReason() != lldb.eStopReasonBreakpoint:
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to