labath updated this revision to Diff 121287.
labath added a comment.
Herald added a subscriber: ki.stfu.

This removes the getCategories function altogether.  I've moved the
filesystem-based category computation (which was implemented as a getCategories
base case) into the consumer, so that it is impossible to override. I've
converted the existing getCategories usages to either @add_test_categories (if
they affected a single test) or to .categories.


https://reviews.llvm.org/D39515

Files:
  packages/Python/lldbsuite/test/example/TestSequenceFunctions.py
  
packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/TestExprDoesntBlock.py
  packages/Python/lldbsuite/test/functionalities/load_unload/.categories
  packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
  packages/Python/lldbsuite/test/functionalities/thread/step_until/.categories
  
packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
  
packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py
  
packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py
  packages/Python/lldbsuite/test/lang/c/step-target/.categories
  packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py
  packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py
  packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py
  packages/Python/lldbsuite/test/lldbtest.py
  packages/Python/lldbsuite/test/test_result.py
  packages/Python/lldbsuite/test/tools/lldb-mi/.categories
  packages/Python/lldbsuite/test/tools/lldb-mi/lldbmi_testcase.py

Index: packages/Python/lldbsuite/test/tools/lldb-mi/lldbmi_testcase.py
===================================================================
--- packages/Python/lldbsuite/test/tools/lldb-mi/lldbmi_testcase.py
+++ packages/Python/lldbsuite/test/tools/lldb-mi/lldbmi_testcase.py
@@ -14,9 +14,6 @@
     myexe = "a.out"
     mylog = "child.log"
 
-    def getCategories(self):
-        return ['lldb-mi']
-
     @classmethod
     def classCleanup(cls):
         TestBase.RemoveTempFile(cls.myexe)
Index: packages/Python/lldbsuite/test/tools/lldb-mi/.categories
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/tools/lldb-mi/.categories
@@ -0,0 +1 @@
+lldb-mi
Index: packages/Python/lldbsuite/test/test_result.py
===================================================================
--- packages/Python/lldbsuite/test/test_result.py
+++ packages/Python/lldbsuite/test/test_result.py
@@ -105,6 +105,32 @@
         else:
             return str(test)
 
+    @staticmethod
+    def _getFileBasedCategories(test):
+        """
+        Returns the list of categories to which this test case belongs by
+        looking for a ".categories" file. We start at the folder the test is in
+        an traverse the hierarchy upwards - we guarantee a .categories to exist
+        at the top level directory so we do not end up looping endlessly.
+        """
+        import inspect
+        import os.path
+        folder = inspect.getfile(test.__class__)
+        folder = os.path.dirname(folder)
+        while folder != '/':
+            categories_file_name = os.path.join(folder, ".categories")
+            if os.path.exists(categories_file_name):
+                categories_file = open(categories_file_name, 'r')
+                categories = categories_file.readline()
+                categories_file.close()
+                categories = str.replace(categories, '\n', '')
+                categories = str.replace(categories, '\r', '')
+                return categories.split(',')
+            else:
+                folder = os.path.dirname(folder)
+                continue
+
+
     def getCategoriesForTest(self, test):
         """
         Gets all the categories for the currently running test method in test case
@@ -114,7 +140,7 @@
         if test_method is not None and hasattr(test_method, "categories"):
             test_categories.extend(test_method.categories)
 
-        test_categories.extend(test.getCategories())
+        test_categories.extend(self._getFileBasedCategories(test))
 
         return test_categories
 
Index: packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- packages/Python/lldbsuite/test/lldbtest.py
+++ packages/Python/lldbsuite/test/lldbtest.py
@@ -1834,30 +1834,6 @@
     # Can be overridden by the LLDB_TIME_WAIT_NEXT_LAUNCH environment variable.
     timeWaitNextLaunch = 1.0
 
-    # Returns the list of categories to which this test case belongs
-    # by default, look for a ".categories" file, and read its contents
-    # if no such file exists, traverse the hierarchy - we guarantee
-    # a .categories to exist at the top level directory so we do not end up
-    # looping endlessly - subclasses are free to define their own categories
-    # in whatever way makes sense to them
-    def getCategories(self):
-        import inspect
-        import os.path
-        folder = inspect.getfile(self.__class__)
-        folder = os.path.dirname(folder)
-        while folder != '/':
-            categories_file_name = os.path.join(folder, ".categories")
-            if os.path.exists(categories_file_name):
-                categories_file = open(categories_file_name, 'r')
-                categories = categories_file.readline()
-                categories_file.close()
-                categories = str.replace(categories, '\n', '')
-                categories = str.replace(categories, '\r', '')
-                return categories.split(',')
-            else:
-                folder = os.path.dirname(folder)
-                continue
-
     def generateSource(self, source):
         template = source + '.template'
         temp = os.path.join(os.getcwd(), template)
Index: packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py
===================================================================
--- packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py
+++ packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py
@@ -13,9 +13,6 @@
 
 class TestObjCStepping(TestBase):
 
-    def getCategories(self):
-        return ['basic_process']
-
     mydir = TestBase.compute_mydir(__file__)
 
     def setUp(self):
@@ -35,7 +32,7 @@
             self.main_source, '// Step over nil should stop here.')
 
     @skipUnlessDarwin
-    @add_test_categories(['pyapi'])
+    @add_test_categories(['pyapi', 'basic_process'])
     def test_with_python_api(self):
         """Test stepping through ObjC method dispatch in various forms."""
         self.build()
Index: packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py
===================================================================
--- packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py
+++ packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py
@@ -15,16 +15,13 @@
 
     mydir = TestBase.compute_mydir(__file__)
 
-    def getCategories(self):
-        return ['basic_process']
-
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)
         # Find the line numbers that we will step to in main:
         self.main_source = "main.c"
 
-    @add_test_categories(['pyapi'])
+    @add_test_categories(['pyapi', 'basic_process'])
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr17932')
     @expectedFailureAll(oslist=["linux"], bugnumber="llvm.org/pr14437")
     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24777")
Index: packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py
===================================================================
--- packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py
+++ packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py
@@ -14,9 +14,6 @@
 
     mydir = TestBase.compute_mydir(__file__)
 
-    def getCategories(self):
-        return ['basic_process']
-
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)
Index: packages/Python/lldbsuite/test/lang/c/step-target/.categories
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/lang/c/step-target/.categories
@@ -0,0 +1 @@
+basic_process
Index: packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py
+++ packages/Python/lldbsuite/test/functionalities/watchpoint/step_over_watchpoint/TestStepOverWatchpoint.py
@@ -13,9 +13,6 @@
 
     mydir = TestBase.compute_mydir(__file__)
 
-    def getCategories(self):
-        return ['basic_process']
-
     @expectedFailureAll(
         oslist=["linux"],
         archs=[
@@ -28,6 +25,7 @@
     # Read-write watchpoints not supported on SystemZ
     @expectedFailureAll(archs=['s390x'])
     @expectedFailureAll(oslist=["ios", "watchos", "tvos", "bridgeos"], bugnumber="<rdar://problem/34027183>")  # watchpoint tests aren't working on arm64
+    @add_test_categories(["basic_process"])
     def test(self):
         """Test stepping over watchpoints."""
         self.build()
Index: packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py
+++ packages/Python/lldbsuite/test/functionalities/watchpoint/hello_watchpoint/TestMyFirstWatchpoint.py
@@ -15,9 +15,6 @@
 
 class HelloWatchpointTestCase(TestBase):
 
-    def getCategories(self):
-        return ['basic_process']
-
     mydir = TestBase.compute_mydir(__file__)
 
     def setUp(self):
@@ -37,6 +34,7 @@
     @expectedFailureAll(
         oslist=["windows"],
         bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
+    @add_test_categories(["basic_process"])
     def test_hello_watchpoint_using_watchpoint_set(self):
         """Test a simple sequence of watchpoint creation and watchpoint hit."""
         self.build(dictionary=self.d)
Index: packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
+++ packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
@@ -15,9 +15,6 @@
 
     mydir = TestBase.compute_mydir(__file__)
 
-    def getCategories(self):
-        return ['basic_process']
-
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)
Index: packages/Python/lldbsuite/test/functionalities/thread/step_until/.categories
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/thread/step_until/.categories
@@ -0,0 +1 @@
+basic_process
Index: packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
+++ packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py
@@ -17,9 +17,6 @@
 @skipIfWindows  # Windows doesn't have dlopen and friends, dynamic libraries work differently
 class LoadUnloadTestCase(TestBase):
 
-    def getCategories(self):
-        return ['basic_process']
-
     mydir = TestBase.compute_mydir(__file__)
 
     def setUp(self):
Index: packages/Python/lldbsuite/test/functionalities/load_unload/.categories
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/functionalities/load_unload/.categories
@@ -0,0 +1 @@
+basic_process
Index: packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/TestExprDoesntBlock.py
===================================================================
--- packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/TestExprDoesntBlock.py
+++ packages/Python/lldbsuite/test/functionalities/expr-doesnt-deadlock/TestExprDoesntBlock.py
@@ -16,15 +16,13 @@
 
 class ExprDoesntDeadlockTestCase(TestBase):
 
-    def getCategories(self):
-        return ['basic_process']
-
     mydir = TestBase.compute_mydir(__file__)
 
     @expectedFailureAll(oslist=['freebsd'], bugnumber='llvm.org/pr17946')
     @expectedFailureAll(
         oslist=["windows"],
         bugnumber="Windows doesn't have pthreads, test needs to be ported")
+    @add_test_categories(["basic_process"])
     def test_with_run_command(self):
         """Test that expr will time out and allow other threads to run if it blocks."""
         self.build()
Index: packages/Python/lldbsuite/test/example/TestSequenceFunctions.py
===================================================================
--- packages/Python/lldbsuite/test/example/TestSequenceFunctions.py
+++ packages/Python/lldbsuite/test/example/TestSequenceFunctions.py
@@ -30,8 +30,5 @@
         for element in random.sample(self.seq, 5):
             self.assertTrue(element in self.seq)
 
-    def getCategories(self):
-        return []
-
 if __name__ == '__main__':
     unittest.main()
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to