Add patches for failing tests

- Replace COUNT_ALLOCS patches with upstreamed one
  (patches added: 283; patches removed: 125, 134, 135, 141)
  https://bugs.python.org/issue31692
- Add a patch to skip a failing test on s390x: 280
  https://bugs.python.org/issue31719
This commit is contained in:
Iryna Shcherbina 2017-10-18 15:33:53 +02:00 committed by Charalampos Stratakis
parent f50e49e7fb
commit a8ced1c5b0
7 changed files with 274 additions and 105 deletions

View File

@ -1,20 +0,0 @@
diff -up Python-2.7/Python/pythonrun.c.less-verbose-COUNT_ALLOCS Python-2.7/Python/pythonrun.c
--- Python-2.7/Python/pythonrun.c.less-verbose-COUNT_ALLOCS 2010-08-17 14:49:33.321913909 -0400
+++ Python-2.7/Python/pythonrun.c 2010-08-17 14:54:48.750910403 -0400
@@ -470,7 +470,15 @@ Py_Finalize(void)
/* Debugging stuff */
#ifdef COUNT_ALLOCS
- dump_counts(stdout);
+ /* This is a downstream Fedora modification.
+ The upstream default with COUNT_ALLOCS is to always dump the counts to
+ stdout on exit. For our debug builds its useful to have the info from
+ COUNT_ALLOCS available, but the stdout info here gets in the way, so
+ we make it optional, wrapping it in an environment variable (modelled
+ on the other PYTHONDUMP* env variables):
+ */
+ if (Py_GETENV("PYTHONDUMPCOUNTS"))
+ dump_counts(stdout);
#endif
PRINT_TOTAL_REFS();

View File

@ -1,16 +0,0 @@
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 0dd4258..d9b3267 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -769,6 +769,11 @@ class SizeofTest(unittest.TestCase):
'10P' # PySequenceMethods
'6P' # PyBufferProcs
'2P')
+
+ # COUNT_ALLOCS adds further fields to the end of a PyTypeObject:
+ if hasattr(sys, 'getcounts'):
+ s += size('P')
+
class newstyleclass(object):
pass
check(newstyleclass, s)

View File

@ -1,18 +0,0 @@
diff -up Python-2.7.2/Lib/test/test_weakref.py.skip-test-within-test_weakref-in-debug-build Python-2.7.2/Lib/test/test_weakref.py
--- Python-2.7.2/Lib/test/test_weakref.py.skip-test-within-test_weakref-in-debug-build 2011-09-08 17:55:09.675392260 -0400
+++ Python-2.7.2/Lib/test/test_weakref.py 2011-09-08 17:59:08.857375903 -0400
@@ -550,6 +550,14 @@ class ReferencesTestCase(TestBase):
del c1, c2, C, D
gc.collect()
+ # In a debug build, this fails with:
+ # AssertionError: Lists differ: [] != ['C went away']
+ # Second list contains 1 additional elements.
+ # First extra element 0:
+ # C went away
+ # - []
+ # + ['C went away']
+ @unittest.skipIf(hasattr(sys, 'getobjects'), 'debug build')
def test_callback_in_cycle_resurrection(self):
import gc

View File

@ -1,24 +0,0 @@
diff -up Python-2.7.2/Lib/test/test_gc.py.fix-test_gc_with_COUNT_ALLOCS Python-2.7.2/Lib/test/test_gc.py
--- Python-2.7.2/Lib/test/test_gc.py.fix-test_gc_with_COUNT_ALLOCS 2011-09-08 19:49:13.045924309 -0400
+++ Python-2.7.2/Lib/test/test_gc.py 2011-09-08 19:50:07.035920617 -0400
@@ -102,11 +102,17 @@ class GCTests(unittest.TestCase):
del a
self.assertNotEqual(gc.collect(), 0)
del B, C
- self.assertNotEqual(gc.collect(), 0)
+ if hasattr(sys, 'getcounts'):
+ self.assertEqual(gc.collect(), 0)
+ else:
+ self.assertNotEqual(gc.collect(), 0)
A.a = A()
del A
- self.assertNotEqual(gc.collect(), 0)
- self.assertEqual(gc.collect(), 0)
+ if hasattr(sys, 'getcounts'):
+ self.assertEqual(gc.collect(), 0)
+ else:
+ self.assertNotEqual(gc.collect(), 0)
+ self.assertEqual(gc.collect(), 0)
def test_method(self):
# Tricky: self.__init__ is a bound method, it references the instance.

View File

@ -0,0 +1,88 @@
From ab35adc682ec51800aa19a77de9947c6aaa50f41 Mon Sep 17 00:00:00 2001
From: Victor Stinner <victor.stinner@gmail.com>
Date: Fri, 6 Oct 2017 22:28:59 +0200
Subject: [PATCH] bpo-31719: Fix test_regrtest.test_crashed() on s390x
Add a new _testcapi._read_null() function to crash Python in a
reliable way on s390x.
On s390x, ctypes.string_at(0) returns an empty string rather than
crashing.
---
Lib/test/support/__init__.py | 4 ++--
Lib/test/test_regrtest.py | 2 ++
.../next/Tests/2017-10-06-22-37-38.bpo-31719.gHyrV3.rst | 3 +++
Modules/_testcapimodule.c | 17 +++++++++++++++++
4 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 Misc/NEWS.d/next/Tests/2017-10-06-22-37-38.bpo-31719.gHyrV3.rst
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index ef474e00b68..25df3ed0c41 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1960,6 +1960,6 @@ def _crash_python():
Use SuppressCrashReport() to prevent a crash report from popping up.
"""
- import ctypes
+ import _testcapi
with SuppressCrashReport():
- ctypes.string_at(0)
+ _testcapi._read_null()
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 264c74d22ba..aae274384c7 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -543,6 +543,8 @@ def test_method2(self):
testname)
self.assertEqual(output.splitlines(), all_methods)
+ @unittest.skipIf(sys.platform.startswith('aix'),
+ "support._crash_python() doesn't work on AIX")
def test_crashed(self):
# Any code which causes a crash
code = 'import test.support; test.support._crash_python()'
diff --git a/Misc/NEWS.d/next/Tests/2017-10-06-22-37-38.bpo-31719.gHyrV3.rst b/Misc/NEWS.d/next/Tests/2017-10-06-22-37-38.bpo-31719.gHyrV3.rst
new file mode 100644
index 00000000000..a06c5267251
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2017-10-06-22-37-38.bpo-31719.gHyrV3.rst
@@ -0,0 +1,3 @@
+Fix test_regrtest.test_crashed() on s390x. Add a new _testcapi._read_null()
+function to crash Python in a reliable way on s390x. On s390x,
+ctypes.string_at(0) returns an empty string rather than crashing.
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 7691b5188ff..5902de07823 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2566,6 +2566,22 @@ py_w_stopcode(PyObject *self, PyObject *args)
#endif
+/* Read memory from NULL (address 0) to raise a SIGSEGV or SIGBUS signal
+ depending on the platform. This function is used by
+ test.support._crash_python() to "crash" Python. */
+static PyObject *
+read_null(PyObject *self, PyObject *args)
+{
+ volatile int *x;
+ volatile int y;
+
+ x = NULL;
+ y = *x;
+ return PyLong_FromLong(y);
+
+}
+
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"set_errno", set_errno, METH_VARARGS},
@@ -2685,6 +2701,7 @@ static PyMethodDef TestMethods[] = {
#ifdef W_STOPCODE
{"W_STOPCODE", py_w_stopcode, METH_VARARGS},
#endif
+ {"_read_null", (PyCFunction)read_null, METH_NOARGS},
{NULL, NULL} /* sentinel */
};

View File

@ -0,0 +1,172 @@
From 7b4ba62e388474e811268322b47f80d464933541 Mon Sep 17 00:00:00 2001
From: Victor Stinner <victor.stinner@gmail.com>
Date: Tue, 17 Oct 2017 02:25:23 -0700
Subject: [PATCH] [2.7] bpo-31692: Add PYTHONSHOWALLOCCOUNT env var (GH-3927)
bpo-31692, bpo-19527:
* Add a new PYTHONSHOWALLOCCOUNT environment variable, similar to
the Python 3 "-X showalloccount" option
* When Python is compiled with COUNT_ALLOCS, the new
PYTHONSHOWALLOCCOUNT environment variable now has to be set to dump
allocation counts into stderr on shutdown. Moreover, allocations
statistics are now dumped into stderr rather than stdout.
* Add @test.support.requires_type_collecting decorator: skip test if
COUNT_ALLOCS is defined
* Fix tests for COUNT_ALLOCS: decorate some methods with
@requires_type_collecting
* test_sys.test_objecttypes(): update object type when COUNT_ALLOCS
is defined
---
Doc/c-api/typeobj.rst | 2 +-
Doc/using/cmdline.rst | 7 +++++++
Lib/test/support/__init__.py | 3 +++
Lib/test/test_abc.py | 1 +
Lib/test/test_gc.py | 4 +++-
Lib/test/test_regrtest.py | 1 +
Lib/test/test_sys.py | 5 ++++-
Lib/test/test_weakref.py | 1 +
.../Core and Builtins/2017-10-09-11-03-13.bpo-31692.5-bpdk.rst | 4 ++++
Python/pythonrun.c | 4 +++-
10 files changed, 28 insertions(+), 4 deletions(-)
create mode 100644 Misc/NEWS.d/next/Core and Builtins/2017-10-09-11-03-13.bpo-31692.5-bpdk.rst
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst
index 18edcdd7e5a..f0ccf2ea5fe 100644
--- a/Doc/c-api/typeobj.rst
+++ b/Doc/c-api/typeobj.rst
@@ -1101,7 +1101,7 @@ The next fields, up to and including :c:member:`~PyTypeObject.tp_weaklist`, only
The remaining fields are only defined if the feature test macro
:const:`COUNT_ALLOCS` is defined, and are for internal use only. They are
documented here for completeness. None of these fields are inherited by
-subtypes.
+subtypes. See the :envvar:`PYTHONSHOWALLOCCOUNT` environment variable.
.. c:member:: Py_ssize_t PyTypeObject.tp_allocs
diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst
index f00f7f6026a..55bc12893d6 100644
--- a/Doc/using/cmdline.rst
+++ b/Doc/using/cmdline.rst
@@ -663,3 +663,10 @@ if Python was configured with the ``--with-pydebug`` build option.
If set, Python will print memory allocation statistics every time a new
object arena is created, and on shutdown.
+
+.. envvar:: PYTHONSHOWALLOCCOUNT
+
+ If set and Python was compiled with ``COUNT_ALLOCS`` defined, Python will
+ dump allocations counts into stderr on shutdown.
+
+ .. versionadded:: 2.7.15
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 25df3ed0c41..d14a6620b5d 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1795,6 +1795,9 @@ def py3k_bytes(b):
except TypeError:
return bytes(b)
+requires_type_collecting = unittest.skipIf(hasattr(sys, 'getcounts'),
+ 'types are immortal if COUNT_ALLOCS is defined')
+
def args_from_interpreter_flags():
"""Return a list of command-line arguments reproducing the current
settings in sys.flags."""
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index 6a8c3a13274..dbba37cdb6f 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -208,6 +208,7 @@ class C(A, B):
C()
self.assertEqual(B.counter, 1)
+ @test_support.requires_type_collecting
def test_cache_leak(self):
# See issue #2521.
class A(object):
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index ed01c9802fc..7e47b2d3a27 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -1,5 +1,6 @@
import unittest
-from test.test_support import verbose, run_unittest, start_threads, import_module
+from test.support import (verbose, run_unittest, start_threads, import_module,
+ requires_type_collecting)
import sys
import sysconfig
import time
@@ -90,6 +91,7 @@ class A:
del a
self.assertNotEqual(gc.collect(), 0)
+ @requires_type_collecting
def test_newinstance(self):
class A(object):
pass
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index aae274384c7..988a72c1099 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -493,6 +493,7 @@ def check_leak(self, code, what):
self.assertIn(line2, reflog)
@unittest.skipUnless(Py_DEBUG, 'need a debug build')
+ @support.requires_type_collecting
def test_huntrleaks(self):
# test --huntrleaks
code = textwrap.dedent("""
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 5baaa352c0b..9342716272a 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -748,7 +748,10 @@ def delx(self): del self.__x
# tupleiterator
check(iter(()), size('lP'))
# type
- s = vsize('P2P15Pl4PP9PP11PI' # PyTypeObject
+ fmt = 'P2P15Pl4PP9PP11PI'
+ if hasattr(sys, 'getcounts'):
+ fmt += '3P2P'
+ s = vsize(fmt + # PyTypeObject
'39P' # PyNumberMethods
'3P' # PyMappingMethods
'10P' # PySequenceMethods
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 415d5ebbd72..418481dadd8 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -601,6 +601,7 @@ class D:
del c1, c2, C, D
gc.collect()
+ @test_support.requires_type_collecting
def test_callback_in_cycle_resurrection(self):
import gc
diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-10-09-11-03-13.bpo-31692.5-bpdk.rst b/Misc/NEWS.d/next/Core and Builtins/2017-10-09-11-03-13.bpo-31692.5-bpdk.rst
new file mode 100644
index 00000000000..f32548c67bd
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2017-10-09-11-03-13.bpo-31692.5-bpdk.rst
@@ -0,0 +1,4 @@
+Add a new PYTHONSHOWALLOCCOUNT environment variable. When Python is compiled
+with COUNT_ALLOCS, PYTHONSHOWALLOCCOUNT now has to be set to dump allocation
+counts into stderr on shutdown. Moreover, allocations statistics are now dumped
+into stderr rather than stdout.
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 677f6e48111..44fe13d2f7d 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -488,7 +488,9 @@ Py_Finalize(void)
/* Debugging stuff */
#ifdef COUNT_ALLOCS
- dump_counts(stdout);
+ if (Py_GETENV("PYTHONSHOWALLOCCOUNT")) {
+ dump_counts(stderr);
+ }
#endif
PRINT_TOTAL_REFS();

View File

@ -465,14 +465,6 @@ Patch114: 00114-statvfs-f_flag-constants.patch
# This patch adds the build Modules directory to build path.
Patch121: 00121-add-Modules-to-build-path.patch
# 00125 #
# COUNT_ALLOCS is useful for debugging, but the upstream behaviour of always
# emitting debug info to stdout on exit is too verbose and makes it harder to
# use the debug build. Add a "PYTHONDUMPCOUNTS" environment variable which
# must be set to enable the output on exit
# Not yet sent upstream
Patch125: 00125-less-verbose-COUNT_ALLOCS.patch
# 2.7.1 (in r84230) added a test to test_abc which fails if python is
# configured with COUNT_ALLOCS, which is the case for our debug build
# (the COUNT_ALLOCS instrumentation keeps "C" alive).
@ -521,16 +513,6 @@ Patch132: 00132-add-rpmbuild-hooks-to-unittest.patch
# "dl" is deprecated, and test_dl doesn't work on 64-bit builds:
Patch133: 00133-skip-test_dl.patch
# 00134 #
# Fix a failure in test_sys.py when configured with COUNT_ALLOCS enabled
# Not yet sent upstream
Patch134: 00134-fix-COUNT_ALLOCS-failure-in-test_sys.patch
# 00135 #
# Skip "test_callback_in_cycle_resurrection" in a debug build, where it fails:
# Not yet sent upstream
Patch135: 00135-skip-test-within-test_weakref-in-debug-build.patch
# 00136 #
# Some tests try to seek on sys.stdin, but don't work as expected when run
# within Koji/mock; skip them within the rpm build:
@ -555,11 +537,6 @@ Patch139: 00139-skip-test_float-known-failure-on-arm.patch
# which appears to be a libffi bug
Patch140: 00140-skip-test_ctypes-known-failure-on-sparc.patch
# 00141 #
# Fix test_gc's test_newinstance case when configured with COUNT_ALLOCS:
# Not yet sent upstream
Patch141: 00141-fix-test_gc_with_COUNT_ALLOCS.patch
# 00142 #
# Some pty tests fail when run in mock (rhbz#714627):
Patch142: 00142-skip-failing-pty-tests-in-rpmbuild.patch
@ -738,6 +715,17 @@ Patch193: 00193-enable-loading-sqlite-extensions.patch
# 00198 #
Patch198: 00198-add-rewheel-module.patch
# 00280 #
# The test `test_regrtest.test_crashed` fails on s390x architecture.
# https://bugs.python.org/issue31719
Patch280: 00280-Fix-test_regrtest-test_crashed-on-s390x.patch
# 00283 #
# Fix tests on debug build configured with COUNT_ALLOCS,
# and add a new environment variable PYTHONSHOWALLOCCOUNT:
# https://bugs.python.org/issue31692
Patch283: 00283-fix-tests_with_COUNT_ALLOCS.patch
# (New patches go here ^^^)
#
# When adding new patches to "python2" and "python3" in Fedora, EL, etc.,
@ -996,7 +984,6 @@ rm -r Modules/zlib || exit 1
%patch121 -p1
%patch125 -p1 -b .less-verbose-COUNT_ALLOCS
%patch128 -p1
%patch130 -p1
@ -1007,8 +994,6 @@ rm -r Modules/zlib || exit 1
%patch132 -p1
%patch133 -p1
%patch134 -p1
%patch135 -p1
%patch136 -p1 -b .stdin-test
%patch137 -p1
%patch138 -p1
@ -1018,7 +1003,6 @@ rm -r Modules/zlib || exit 1
%ifarch %{sparc}
%patch140 -p1
%endif
%patch141 -p1
%patch142 -p1 -b .tty-fail
%patch143 -p1 -b .tsc-on-ppc
%if !%{with_gdbm}
@ -1047,6 +1031,9 @@ mv Modules/cryptmodule.c Modules/_cryptmodule.c
%if 0%{with_rewheel}
%patch198 -p1
%endif
%patch283 -p1
%patch280 -p1
%if 0%{?_module_build}
%patch4000 -p1