summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc')
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/Makefile14
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py58
-rw-r--r--gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/main.m21
3 files changed, 93 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/Makefile
new file mode 100644
index 00000000000..f27f57aeebf
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/Makefile
@@ -0,0 +1,14 @@
+OBJC_SOURCES := main.m
+UI_FRAMEWORK = AppKit
+
+ifneq ("$(SDKROOT)", "")
+ ifeq (,$(findstring macOS,$(SDKROOT)))
+ ifeq (,$(findstring MacOS,$(SDKROOT)))
+ UI_FRAMEWORK = UIKit
+ endif
+ endif
+endif
+
+LD_EXTRAS = -lobjc -framework Foundation -framework $(UI_FRAMEWORK)
+
+include Makefile.rules
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
new file mode 100644
index 00000000000..e3751e02c45
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/TestMTCSimple.py
@@ -0,0 +1,58 @@
+"""
+Tests basic Main Thread Checker support (detecting a main-thread-only violation).
+"""
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbplatformutil import *
+import json
+
+
+class MTCSimpleTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipUnlessDarwin
+ def test(self):
+ self.mtc_dylib_path = findMainThreadCheckerDylib()
+ if self.mtc_dylib_path == "":
+ self.skipTest("This test requires libMainThreadChecker.dylib")
+
+ self.build()
+ self.mtc_tests()
+
+ @skipIf(archs=['i386'])
+ def mtc_tests(self):
+ self.assertTrue(self.mtc_dylib_path != "")
+
+ # Load the test
+ exe = self.getBuildArtifact("a.out")
+ self.expect("file " + exe, patterns=["Current executable set to .*a.out"])
+
+ self.runCmd("env DYLD_INSERT_LIBRARIES=%s" % self.mtc_dylib_path)
+ self.runCmd("run")
+
+ process = self.dbg.GetSelectedTarget().process
+ thread = process.GetSelectedThread()
+ frame = thread.GetSelectedFrame()
+
+ view = "NSView" if lldbplatformutil.getPlatform() == "macosx" else "UIView"
+
+ self.expect("thread info",
+ substrs=['stop reason = -[' + view +
+ ' superview] must be used from main thread only'])
+
+ self.expect(
+ "thread info -s",
+ substrs=["instrumentation_class", "api_name", "class_name", "selector", "description"])
+ self.assertEqual(thread.GetStopReason(), lldb.eStopReasonInstrumentation)
+ output_lines = self.res.GetOutput().split('\n')
+ json_line = '\n'.join(output_lines[2:])
+ data = json.loads(json_line)
+ self.assertEqual(data["instrumentation_class"], "MainThreadChecker")
+ self.assertEqual(data["api_name"], "-[" + view + " superview]")
+ self.assertEqual(data["class_name"], view)
+ self.assertEqual(data["selector"], "superview")
+ self.assertEqual(data["description"], "-[" + view + " superview] must be used from main thread only")
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/main.m
new file mode 100644
index 00000000000..a967dee4692
--- /dev/null
+++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/functionalities/mtc/simple/main.m
@@ -0,0 +1,21 @@
+#import <Foundation/Foundation.h>
+#if __has_include(<AppKit/AppKit.h>)
+#import <AppKit/AppKit.h>
+#define XXView NSView
+#else
+#import <UIKit/UIKit.h>
+#define XXView UIView
+#endif
+
+int main() {
+ XXView *view = [[XXView alloc] init];
+ dispatch_group_t g = dispatch_group_create();
+ dispatch_group_enter(g);
+ [NSThread detachNewThreadWithBlock:^{
+ @autoreleasepool {
+ [view superview];
+ }
+ dispatch_group_leave(g);
+ }];
+ dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
+}