aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity')
-rw-r--r--packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/Makefile5
-rw-r--r--packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/TestDarwinLogFilterMatchActivity.py127
-rw-r--r--packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/main.c43
3 files changed, 175 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/Makefile b/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/Makefile
new file mode 100644
index 000000000000..4f4176f23f3c
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/TestDarwinLogFilterMatchActivity.py b/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/TestDarwinLogFilterMatchActivity.py
new file mode 100644
index 000000000000..12a430295a77
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/TestDarwinLogFilterMatchActivity.py
@@ -0,0 +1,127 @@
+"""
+Test basic DarwinLog functionality provided by the StructuredDataDarwinLog
+plugin.
+
+These tests are currently only supported when running against Darwin
+targets.
+"""
+
+from __future__ import print_function
+
+import lldb
+import os
+import re
+
+from lldbsuite.test import decorators
+from lldbsuite.test import lldbtest
+from lldbsuite.test import darwin_log
+
+
+class TestDarwinLogFilterMatchActivity(darwin_log.DarwinLogTestBase):
+
+ mydir = lldbtest.TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ super(TestDarwinLogFilterMatchActivity, self).setUp()
+
+ # Source filename.
+ self.source = 'main.c'
+
+ # Output filename.
+ self.exe_name = 'a.out'
+ self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name}
+
+ # Locate breakpoint.
+ self.line = lldbtest.line_number(self.source, '// break here')
+
+ def tearDown(self):
+ # Shut down the process if it's still running.
+ if self.child:
+ self.runCmd('process kill')
+ self.expect_prompt()
+ self.runCmd('quit')
+
+ # Let parent clean up
+ super(TestDarwinLogFilterMatchActivity, self).tearDown()
+
+ # ==========================================================================
+ # activity filter tests
+ # ==========================================================================
+
+ @decorators.skipUnlessDarwin
+ def test_filter_accept_activity_match(self):
+ """Test that fall-through reject, accept match activity works."""
+ self.do_test(
+ ["--no-match-accepts false",
+ "--filter \"accept activity match child-activity\""]
+ )
+
+ # We should only see the second log message as we only accept
+ # that activity.
+ self.assertIsNotNone(self.child.match)
+ self.assertTrue(
+ (len(
+ self.child.match.groups()) > 1) and (
+ self.child.match.group(2) == "cat2"),
+ "first log line should not be present, second log line "
+ "should be")
+
+ @decorators.skipUnlessDarwin
+ def test_filter_reject_activity_partial_match(self):
+ """Test that fall-through reject, accept match activity via partial match does not accept."""
+ self.do_test(
+ ["--no-match-accepts false",
+ # Fully match second message.
+ "--filter \"accept activity match child-activity\"",
+ "--filter \"accept activity match parent-\""] # Only partially match first message.
+ )
+
+ # We should only see the second log message as we only accept
+ # that activity.
+ self.assertIsNotNone(self.child.match)
+ self.assertTrue(
+ (len(
+ self.child.match.groups()) > 1) and (
+ self.child.match.group(2) == "cat2"),
+ "first log line should not be present, second log line "
+ "should be")
+
+ @decorators.skipUnlessDarwin
+ def test_filter_reject_activity_full_match(self):
+ """Test that fall-through accept, reject match activity works."""
+ self.do_test(
+ ["--no-match-accepts true",
+ "--filter \"reject activity match parent-activity\""]
+ )
+
+ # We should only see the second log message as we rejected the first
+ # via activity rejection.
+ self.assertIsNotNone(self.child.match)
+ self.assertTrue(
+ (len(
+ self.child.match.groups()) > 1) and (
+ self.child.match.group(2) == "cat2"),
+ "first log line should not be present, second log line "
+ "should be")
+
+ @decorators.skipUnlessDarwin
+ def test_filter_accept_activity_second_rule(self):
+ """Test that fall-through reject, accept regex activity on second rule works."""
+ self.do_test(
+ ["--no-match-accepts false",
+ "--filter \"accept activity match non-existent\"",
+ "--filter \"accept activity match child-activity\""
+ ]
+ )
+
+ # We should only see the second message since we reject by default,
+ # the first filter doesn't match any, and the second filter matches
+ # the activity of the second log message.
+ self.assertIsNotNone(self.child.match)
+ self.assertTrue(
+ (len(
+ self.child.match.groups()) > 1) and (
+ self.child.match.group(2) == "cat2"),
+ "first log line should not be present, second log line "
+ "should be")
diff --git a/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/main.c b/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/main.c
new file mode 100644
index 000000000000..c93474eedb01
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/main.c
@@ -0,0 +1,43 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <os/activity.h>
+#include <os/log.h>
+#include <stdio.h>
+
+#include "../../../common/darwin_log_common.h"
+
+int main(int argc, char** argv)
+{
+ os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1");
+ os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2");
+ if (!logger_sub1 || !logger_sub2)
+ return 1;
+
+ // Note we cannot use the os_log() line as the breakpoint because, as of
+ // the initial writing of this test, we get multiple breakpoints for that
+ // line, which confuses the pexpect test logic.
+ printf("About to log\n"); // break here
+ os_activity_t parent_activity = os_activity_create("parent-activity",
+ OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT);
+ os_activity_apply(parent_activity, ^{
+ os_log(logger_sub1, "source-log-sub1-cat1");
+ os_activity_t child_activity = os_activity_create("child-activity",
+ OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT);
+ os_activity_apply(child_activity, ^{
+ os_log(logger_sub2, "source-log-sub2-cat2");
+ });
+ });
+
+ // Sleep, as the darwin log reporting doesn't always happen until a bit
+ // later. We need the message to come out before the process terminates.
+ sleep(FINAL_WAIT_SECONDS);
+
+ return 0;
+}