summaryrefslogtreecommitdiffstats
path: root/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2016-01-06 20:12:03 +0000
committerdim <dim@FreeBSD.org>2016-01-06 20:12:03 +0000
commit78b9749c0a4ea980a8b934645da6ae98fcc665e8 (patch)
treedd2a1ddf0476664c2b823409c36cbccd52662ca7 /packages/Python/lldbsuite/test/functionalities/thread/exit_during_break
parent60cb593f9d55fa5ca7a5372b731f2330345b4b9a (diff)
downloadFreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.zip
FreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.tar.gz
Vendor import of lldb trunk r256945:
https://llvm.org/svn/llvm-project/lldb/trunk@256945
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/thread/exit_during_break')
-rw-r--r--packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/Makefile5
-rw-r--r--packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/TestExitDuringBreak.py81
-rw-r--r--packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/main.cpp130
3 files changed, 216 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/Makefile b/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/Makefile
new file mode 100644
index 0000000..67aa166
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+ENABLE_THREADS := YES
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/TestExitDuringBreak.py b/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/TestExitDuringBreak.py
new file mode 100644
index 0000000..f999ffe
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/TestExitDuringBreak.py
@@ -0,0 +1,81 @@
+"""
+Test number of threads.
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+class ExitDuringBreakpointTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number for our breakpoint.
+ self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
+
+ @expectedFailureDarwin("llvm.org/pr15824") # thread states not properly maintained
+ @expectedFailureFreeBSD("llvm.org/pr18190") # thread states not properly maintained
+ @expectedFailureLinux("llvm.org/pr15824") # thread states not properly maintained
+ @expectedFailureWindows("llvm.org/pr24668") # Breakpoints not resolved correctly
+ def test(self):
+ """Test thread exit during breakpoint handling."""
+ self.build(dictionary=self.getBuildFlags())
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # This should create a breakpoint in the main thread.
+ lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.breakpoint, num_expected_locations=1)
+
+ # The breakpoint list should show 1 location.
+ self.expect("breakpoint list -f", "Breakpoint location shown correctly",
+ substrs = ["1: file = 'main.cpp', line = %d, locations = 1" % self.breakpoint])
+
+ # Run the program.
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs = ['stopped',
+ 'stop reason = breakpoint'])
+
+ # Get the target process
+ target = self.dbg.GetSelectedTarget()
+ process = target.GetProcess()
+
+ # The exit probably occurred during breakpoint handling, but it isn't
+ # guaranteed. The main thing we're testing here is that the debugger
+ # handles this cleanly is some way.
+
+ # Get the number of threads
+ num_threads = process.GetNumThreads()
+
+ # Make sure we see at least five threads
+ self.assertTrue(num_threads >= 5, 'Number of expected threads and actual threads do not match.')
+
+ # Get the thread objects
+ thread1 = process.GetThreadAtIndex(0)
+ thread2 = process.GetThreadAtIndex(1)
+ thread3 = process.GetThreadAtIndex(2)
+ thread4 = process.GetThreadAtIndex(3)
+ thread5 = process.GetThreadAtIndex(4)
+
+ # Make sure all threads are stopped
+ self.assertTrue(thread1.IsStopped(), "Thread 1 didn't stop during breakpoint")
+ self.assertTrue(thread2.IsStopped(), "Thread 2 didn't stop during breakpoint")
+ self.assertTrue(thread3.IsStopped(), "Thread 3 didn't stop during breakpoint")
+ self.assertTrue(thread4.IsStopped(), "Thread 4 didn't stop during breakpoint")
+ self.assertTrue(thread5.IsStopped(), "Thread 5 didn't stop during breakpoint")
+
+ # Run to completion
+ self.runCmd("continue")
+
+ # At this point, the inferior process should have exited.
+ self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)
diff --git a/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/main.cpp b/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/main.cpp
new file mode 100644
index 0000000..3570637
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/thread/exit_during_break/main.cpp
@@ -0,0 +1,130 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// This test is intended to create a situation in which one thread will exit
+// while a breakpoint is being handled in another thread. This may not always
+// happen because it's possible that the exiting thread will exit before the
+// breakpoint is hit. The test case should be flexible enough to treat that
+// as success.
+
+#include <atomic>
+#include <chrono>
+#include <thread>
+
+volatile int g_test = 0;
+
+// Note that although hogging the CPU while waiting for a variable to change
+// would be terrible in production code, it's great for testing since it
+// avoids a lot of messy context switching to get multiple threads synchronized.
+#define do_nothing()
+
+#define pseudo_barrier_wait(bar) \
+ --bar; \
+ while (bar > 0) \
+ do_nothing();
+
+#define pseudo_barrier_init(bar, count) (bar = count)
+
+// A barrier to synchronize all the threads except the one that will exit.
+std::atomic_int g_barrier1;
+
+// A barrier to synchronize all the threads including the one that will exit.
+std::atomic_int g_barrier2;
+
+// A barrier to keep the first group of threads from exiting until after the
+// breakpoint has been passed.
+std::atomic_int g_barrier3;
+
+void *
+break_thread_func ()
+{
+ // Wait until the entire first group of threads is running
+ pseudo_barrier_wait(g_barrier1);
+
+ // Wait for the exiting thread to start
+ pseudo_barrier_wait(g_barrier2);
+
+ // Do something
+ g_test++; // Set breakpoint here
+
+ // Synchronize after the breakpoint
+ pseudo_barrier_wait(g_barrier3);
+
+ // Return
+ return NULL;
+}
+
+void *
+wait_thread_func ()
+{
+ // Wait until the entire first group of threads is running
+ pseudo_barrier_wait(g_barrier1);
+
+ // Wait for the exiting thread to start
+ pseudo_barrier_wait(g_barrier2);
+
+ // Wait until the breakpoint has been passed
+ pseudo_barrier_wait(g_barrier3);
+
+ // Return
+ return NULL;
+}
+
+void *
+exit_thread_func ()
+{
+ // Sync up with the rest of the threads.
+ pseudo_barrier_wait(g_barrier2);
+
+ // Try to make sure this thread doesn't exit until the breakpoint is hit.
+ std::this_thread::sleep_for(std::chrono::microseconds(1));
+
+ // Return
+ return NULL;
+}
+
+int main ()
+{
+
+ // The first barrier waits for the non-exiting threads to start.
+ // This thread will also participate in that barrier.
+ // The idea here is to guarantee that the exiting thread will be
+ // last in the internal list maintained by the debugger.
+ pseudo_barrier_init(g_barrier1, 5);
+
+ // The second break synchronyizes thread exection with the breakpoint.
+ pseudo_barrier_init(g_barrier2, 5);
+
+ // The third barrier keeps the waiting threads around until the breakpoint
+ // has been passed.
+ pseudo_barrier_init(g_barrier3, 4);
+
+ // Create a thread to hit the breakpoint
+ std::thread thread_1(break_thread_func);
+
+ // Create more threads to slow the debugger down during processing.
+ std::thread thread_2(wait_thread_func);
+ std::thread thread_3(wait_thread_func);
+ std::thread thread_4(wait_thread_func);
+
+ // Wait for all these threads to get started.
+ pseudo_barrier_wait(g_barrier1);
+
+ // Create a thread to exit during the breakpoint
+ std::thread thread_5(exit_thread_func);
+
+ // Wait for the threads to finish
+ thread_5.join();
+ thread_4.join();
+ thread_3.join();
+ thread_2.join();
+ thread_1.join();
+
+ return 0;
+}
OpenPOWER on IntegriCloud