summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-09-06 17:13:54 +0200
committerStephan Bergmann <sbergman@redhat.com>2018-09-07 07:31:48 +0200
commite7a3329fd0a68c95f00e6cdfdc3e40e6afa5411c (patch)
treea79054d20a3904d73347dcd6af696dcbb9897a78 /sw
parentdbb444e4ed7c19a11733ce8438bbb6546d42f852 (diff)
DeInitVCL in PythonTest
After b9757f5cfdb62b24e79eeb4c0ef0c8b98056cecf "loplugin:useuniqueptr in vcl/svdata" ASan/UBSan builds started to fail (like <https://ci.libreoffice.org//job/lo_ubsan/1025/>) at the end of PythonTest_dbaccess_python (and probably other PythonTests), when during exit the static utl::ConfigManager instance already happens to be destroyed by the time the static ImplSVData's mpSettingsConfigItem is destroyed (which would normally be cleared during DeInitVCL, if PythonTests would call that, and which in the past had thus simply been leaked in PythonTests when that mpSettingsConfigItem was a plain pointer instead of std::unique_ptr). So ensure that PythonTests that initialize VCL also call DeInitVCL, via a new private_deinitTestEnvironment, complementing the existing private_initTestEnvironment. However, while private_initTestEnvironment is called once (typically via UnoInProcess.setUp, which internally makes sure to only call it once) as soon as the first executed test needs it, private_deinitTestEnvironment must be called once after the lasts test needing it has executed. The only way that I found to do that is to override unittest.TextTestResult's stopTestRun method, which is called once after all tests have been executed. Hence a new test runner setup in unotest/source/python/org/libreoffice/unittest.py that is now called from solenv/gbuild/PythonTest.mk. That revealed a few places in PythonTests that didn't yet close/delete documents that they had opened, which has now been added. One remaining problem then is that classes like SwXTextDocument and friends call Application::GetSolarMutex from their dtors, via sw::UnoImplPtrDeleter (a "Smart pointer class ensuring that the pointed object is deleted with a locked SolarMutex", sw/inc/unobaseclass.hxx). That means that any PyUNO proxies to such C++ objects that remain alive after private_deinitTestEnvironment will cause issues at exit, when Python does a final garbage collection of those objects. The ultimate fix will be to remove that unhelpful UnoImplPtrDeleter and its locking of SolarMutex from the dtors of UNO objects; until then, the Python code is now sprinkled with some HACKs to make sure all those PyUNO proxies are released in a timely fashion (see the comment in unotest/source/python/org/libreoffice/unittest.py for details). (Also, it would probably help if UnoInProcess didn't keep a local self.xDoc around referencing (just) the last result of calling one of its open* methods, confusingly making it the responsibility of UnoInProcess to close that one document while making it the responsibility of the test code making the other UnoInProcess.open* calls to close any other documents.) Change-Id: Ief27c81e2b763e9be20cbf3234b68924315f13be Reviewed-on: https://gerrit.libreoffice.org/60100 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/python/check_bookmarks.py4
-rw-r--r--sw/qa/python/check_change_color.py1
-rw-r--r--sw/qa/python/check_cross_references.py4
-rw-r--r--sw/qa/python/check_fields.py8
-rw-r--r--sw/qa/python/check_flies.py8
-rw-r--r--sw/qa/python/check_indexed_property_values.py1
-rw-r--r--sw/qa/python/check_named_property_values.py1
-rw-r--r--sw/qa/python/check_table.py4
-rw-r--r--sw/qa/python/get_expression.py4
-rw-r--r--sw/qa/python/set_expression.py4
-rw-r--r--sw/qa/python/text_portion_enumeration_test.py5
-rw-r--r--sw/qa/python/var_fields.py3
12 files changed, 32 insertions, 15 deletions
diff --git a/sw/qa/python/check_bookmarks.py b/sw/qa/python/check_bookmarks.py
index 73fd9bb6b98e..8210b4eb005a 100644
--- a/sw/qa/python/check_bookmarks.py
+++ b/sw/qa/python/check_bookmarks.py
@@ -47,6 +47,10 @@ class CheckBookmarks(unittest.TestCase):
@classmethod
def tearDownClass(cls):
cls._uno.tearDown()
+ # HACK in case cls._xDoc holds a UNO proxy to an SwXTextDocument (whose dtor calls
+ # Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
+ # garbage-collected after VCL has already been deinitialized:
+ cls._xDoc = None
def test_bookmarks(self):
self.xDoc = self.__class__._xDoc
diff --git a/sw/qa/python/check_change_color.py b/sw/qa/python/check_change_color.py
index d8562bc77b52..07b622031a61 100644
--- a/sw/qa/python/check_change_color.py
+++ b/sw/qa/python/check_change_color.py
@@ -27,7 +27,6 @@ class CheckChangeColor(unittest.TestCase):
def setUpClass(cls):
cls._uno = UnoInProcess()
cls._uno.setUp()
- cls._xEmptyDoc = cls._uno.openEmptyWriterDoc()
cls.RED = 0xFF0000
cls.BLUE = 0x0000FF
cls.GREEN = 0x008000
diff --git a/sw/qa/python/check_cross_references.py b/sw/qa/python/check_cross_references.py
index 742cc0d94ad5..6aad1c47ca3a 100644
--- a/sw/qa/python/check_cross_references.py
+++ b/sw/qa/python/check_cross_references.py
@@ -46,6 +46,10 @@ class CheckCrossReferences(unittest.TestCase):
@classmethod
def tearDownClass(cls):
cls._uno.tearDown()
+ # HACK in case cls.document holds a UNO proxy to an SwXTextDocument (whose dtor calls
+ # Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
+ # garbage-collected after VCL has already been deinitialized:
+ cls.document = None
def getNextField(self):
while True:
diff --git a/sw/qa/python/check_fields.py b/sw/qa/python/check_fields.py
index 60418a93001d..eb6dd2dc1c8a 100644
--- a/sw/qa/python/check_fields.py
+++ b/sw/qa/python/check_fields.py
@@ -17,8 +17,6 @@ class CheckFields(unittest.TestCase):
def setUpClass(cls):
cls._uno = UnoInProcess()
cls._uno.setUp()
- cls._xDoc = cls._uno.openTemplateFromTDOC("fdo39694.ott")
- cls._xEmptyDoc = cls._uno.openEmptyWriterDoc()
@classmethod
def tearDownClass(cls):
@@ -26,7 +24,7 @@ class CheckFields(unittest.TestCase):
def test_fdo39694_load(self):
placeholders = ["<Kadr1>", "<Kadr2>", "<Kadr3>", "<Kadr4>", "<Pnname>", "<Pvname>", "<Pgeboren>"]
- xDoc = self.__class__._xDoc
+ xDoc = self.__class__._uno.openTemplateFromTDOC("fdo39694.ott")
xEnumerationAccess = xDoc.getTextFields()
xFieldEnum = xEnumerationAccess.createEnumeration()
for xField in xFieldEnum:
@@ -35,9 +33,10 @@ class CheckFields(unittest.TestCase):
read_content = xAnchor.getString()
self.assertTrue(read_content in placeholders,
"field %s is not contained: " % read_content)
+ xDoc.close(True)
def test_fdo42073(self):
- xDoc = self.__class__._xEmptyDoc
+ xDoc = self.__class__._uno.openEmptyWriterDoc()
xBodyText = xDoc.getText()
xCursor = xBodyText.createTextCursor()
xTextField = xDoc.createInstance("com.sun.star.text.TextField.Input")
@@ -48,6 +47,7 @@ class CheckFields(unittest.TestCase):
xTextField.setPropertyValue("Content", content)
read_content = xTextField.getPropertyValue("Content")
self.assertEqual(content, read_content)
+ xDoc.close(True)
if __name__ == '__main__':
unittest.main()
diff --git a/sw/qa/python/check_flies.py b/sw/qa/python/check_flies.py
index 6353ccda150d..0e60b2195e89 100644
--- a/sw/qa/python/check_flies.py
+++ b/sw/qa/python/check_flies.py
@@ -26,18 +26,18 @@ class CheckFlies(unittest.TestCase):
def setUpClass(cls):
cls._uno = UnoInProcess()
cls._uno.setUp()
- cls.document = cls._uno.openDocFromTDOC("CheckFlies.odt")
@classmethod
def tearDownClass(cls):
cls._uno.tearDown()
def test_checkFlies(self):
- xTFS = self.__class__.document
+ document = self.__class__._uno.openDocFromTDOC("CheckFlies.odt")
+ xTFS = document
self.checkTextFrames(xTFS)
- xTGOS = self.__class__.document
+ xTGOS = document
self.checkGraphicFrames(xTGOS)
- xTEOS = self.__class__.document
+ xTEOS = document
self.checkEmbeddedFrames(xTEOS)
def checkEmbeddedFrames(self, xTGOS):
diff --git a/sw/qa/python/check_indexed_property_values.py b/sw/qa/python/check_indexed_property_values.py
index 5609aa4225cb..ceaf82a6cac6 100644
--- a/sw/qa/python/check_indexed_property_values.py
+++ b/sw/qa/python/check_indexed_property_values.py
@@ -34,7 +34,6 @@ class CheckIndexedPropertyValues(unittest.TestCase):
cls._uno = UnoInProcess()
cls._uno.setUp()
cls.xContext = cls._uno.getContext()
- cls.xDoc = cls._uno.openEmptyWriterDoc()
@classmethod
def tearDownClass(cls):
diff --git a/sw/qa/python/check_named_property_values.py b/sw/qa/python/check_named_property_values.py
index dd06adc60313..1a81d13a6323 100644
--- a/sw/qa/python/check_named_property_values.py
+++ b/sw/qa/python/check_named_property_values.py
@@ -36,7 +36,6 @@ class CheckNamedPropertyValues(unittest.TestCase):
cls._uno = UnoInProcess()
cls._uno.setUp()
cls.xContext = cls._uno.getContext()
- cls.xDoc = cls._uno.openEmptyWriterDoc()
@classmethod
def tearDownClass(cls):
diff --git a/sw/qa/python/check_table.py b/sw/qa/python/check_table.py
index 35da08fe8195..8fd888f187bd 100644
--- a/sw/qa/python/check_table.py
+++ b/sw/qa/python/check_table.py
@@ -583,6 +583,8 @@ class CheckTable(unittest.TestCase):
xCellRangeString = xChartDataProvider.convertRangeFromXML("Table1.$A$1:.$C$3")
self.assertEqual("Table1.A1:C3", xCellRangeString)
+ xDoc.dispose()
+
def test_splitRangeHorizontal(self):
xDoc = CheckTable._uno.openEmptyWriterDoc()
xTable = xDoc.createInstance("com.sun.star.text.TextTable")
@@ -600,6 +602,7 @@ class CheckTable(unittest.TestCase):
self.assertTrue(math.isnan(xTable.Data[1][1]))
self.assertTrue(math.isnan(xTable.Data[2][0]))
self.assertTrue(math.isnan(xTable.Data[2][1]))
+ xDoc.dispose()
def test_mergeRangeHorizontal(self):
xDoc = CheckTable._uno.openEmptyWriterDoc()
@@ -618,6 +621,7 @@ class CheckTable(unittest.TestCase):
self.assertEqual(xTable.Data[1][1], float(5))
self.assertEqual(xTable.Data[1][2], float(6))
self.assertEqual(xTable.Data[2], (float(7), float(8), float(9)))
+ xDoc.dispose()
if __name__ == '__main__':
unittest.main()
diff --git a/sw/qa/python/get_expression.py b/sw/qa/python/get_expression.py
index 7462db68a730..98e9402bb602 100644
--- a/sw/qa/python/get_expression.py
+++ b/sw/qa/python/get_expression.py
@@ -22,6 +22,10 @@ class TestGetExpression(unittest.TestCase):
@classmethod
def tearDownClass(cls):
cls._uno.tearDown()
+ # HACK in case cls._xDoc holds a UNO proxy to an SwXTextDocument (whose dtor calls
+ # Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
+ # garbage-collected after VCL has already been deinitialized:
+ cls._xDoc = None
def test_get_expression(self):
self.__class__._uno.checkProperties(
diff --git a/sw/qa/python/set_expression.py b/sw/qa/python/set_expression.py
index 220952536fea..c5dc5e6ae2e9 100644
--- a/sw/qa/python/set_expression.py
+++ b/sw/qa/python/set_expression.py
@@ -18,15 +18,15 @@ class TestSetExpression(unittest.TestCase):
def setUpClass(cls):
cls._uno = UnoInProcess()
cls._uno.setUp()
- cls._xDoc = cls._uno.openEmptyWriterDoc()
@classmethod
def tearDownClass(cls):
cls._uno.tearDown()
def test_set_expression(self):
+ xDoc = self.__class__._uno.openEmptyWriterDoc()
self.__class__._uno.checkProperties(
- self.__class__._xDoc.createInstance("com.sun.star.text.textfield.SetExpression"),
+ xDoc.createInstance("com.sun.star.text.textfield.SetExpression"),
{"NumberingType": 0,
"Content": "foo",
"CurrentPresentation": "bar",
diff --git a/sw/qa/python/text_portion_enumeration_test.py b/sw/qa/python/text_portion_enumeration_test.py
index 3a7e9d8586be..c379138db303 100644
--- a/sw/qa/python/text_portion_enumeration_test.py
+++ b/sw/qa/python/text_portion_enumeration_test.py
@@ -934,6 +934,11 @@ class TextPortionEnumerationTest(unittest.TestCase):
@classmethod
def tearDownClass(cls):
cls.xDoc.close(True)
+ cls._uno.tearDown()
+ # HACK in case cls.xDoc holds a UNO proxy to an SwXTextDocument (whose dtor calls
+ # Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
+ # garbage-collected after VCL has already been deinitialized:
+ cls.xDoc = None
def test_text(self):
root = TreeNode()
diff --git a/sw/qa/python/var_fields.py b/sw/qa/python/var_fields.py
index c2af7a40f408..52fe3ddd6938 100644
--- a/sw/qa/python/var_fields.py
+++ b/sw/qa/python/var_fields.py
@@ -19,7 +19,6 @@ class TestVarFields(unittest.TestCase):
def setUpClass(cls):
cls._uno = UnoInProcess()
cls._uno.setUp()
- cls._xDoc = cls._uno.openEmptyWriterDoc()
@classmethod
def tearDownClass(cls):
@@ -32,7 +31,7 @@ class TestVarFields(unittest.TestCase):
sw/qa/complex/writer/VarFields.java
"""
- xDoc = self.__class__._xDoc
+ xDoc = self.__class__._uno.openEmptyWriterDoc()
xBodyText = xDoc.getText()
xCursor = xBodyText.createTextCursor()
# 0. create text field