Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(41177)

Delta Between Two Patch Sets: Lib/test/test_sys.py

Issue 13390: Hunt memory allocations in addition to reference leaks
Left Patch Set: Created 7 years, 10 months ago
Right Patch Set: Created 6 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/support.py ('k') | Objects/obmalloc.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 import unittest, test.support 1 import unittest, test.support
2 import sys, io, os 2 import sys, io, os
3 import struct 3 import struct
4 import subprocess 4 import subprocess
5 import textwrap 5 import textwrap
6 import warnings 6 import warnings
7 import operator 7 import operator
8 import codecs 8 import codecs
9 import gc
9 10
10 # count the number of test runs, used to create unique 11 # count the number of test runs, used to create unique
11 # strings to intern in test_intern() 12 # strings to intern in test_intern()
12 numruns = 0 13 numruns = 0
13 14
14 try: 15 try:
15 import threading 16 import threading
16 except ImportError: 17 except ImportError:
17 threading = None 18 threading = None
18 19
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 # PEP 421 requires that .name be lower case. 604 # PEP 421 requires that .name be lower case.
604 self.assertEqual(sys.implementation.name, 605 self.assertEqual(sys.implementation.name,
605 sys.implementation.name.lower()) 606 sys.implementation.name.lower())
606 607
607 def test_debugmallocstats(self): 608 def test_debugmallocstats(self):
608 # Test sys._debugmallocstats() 609 # Test sys._debugmallocstats()
609 from test.script_helper import assert_python_ok 610 from test.script_helper import assert_python_ok
610 args = ['-c', 'import sys; sys._debugmallocstats()'] 611 args = ['-c', 'import sys; sys._debugmallocstats()']
611 ret, out, err = assert_python_ok(*args) 612 ret, out, err = assert_python_ok(*args)
612 self.assertIn(b"free PyDictObjects", err) 613 self.assertIn(b"free PyDictObjects", err)
614
615 @unittest.skipUnless(hasattr(sys, "getallocatedblocks"),
616 "sys.getallocatedblocks unavailable on this build")
617 def test_getallocatedblocks(self):
618 # Some sanity checks
619 a = sys.getallocatedblocks()
620 self.assertIs(type(a), int)
621 self.assertGreater(a, 0)
622 try:
623 # While we could imagine a Python session where the number of
624 # multiple buffer objects would exceed the sharing of references,
625 # it is unlikely to happen in a normal test run.
626 self.assertLess(a, sys.gettotalrefcount())
627 except AttributeError:
628 # gettotalrefcount() not available
629 pass
630 gc.collect()
631 b = sys.getallocatedblocks()
632 self.assertLessEqual(b, a)
633 gc.collect()
634 c = sys.getallocatedblocks()
635 self.assertIn(c, range(b - 50, b + 50))
636
613 637
614 class SizeofTest(unittest.TestCase): 638 class SizeofTest(unittest.TestCase):
615 639
616 def setUp(self): 640 def setUp(self):
617 self.P = struct.calcsize('P') 641 self.P = struct.calcsize('P')
618 self.longdigit = sys.int_info.sizeof_digit 642 self.longdigit = sys.int_info.sizeof_digit
619 import _testcapi 643 import _testcapi
620 self.gc_headsize = _testcapi.SIZEOF_PYGC_HEAD 644 self.gc_headsize = _testcapi.SIZEOF_PYGC_HEAD
621 self.file = open(test.support.TESTFN, 'wb') 645 self.file = open(test.support.TESTFN, 'wb')
622 646
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 # XXX 927 # XXX
904 # sys.flags 928 # sys.flags
905 check(sys.flags, vsize('') + self.P * len(sys.flags)) 929 check(sys.flags, vsize('') + self.P * len(sys.flags))
906 930
907 931
908 def test_main(): 932 def test_main():
909 test.support.run_unittest(SysModuleTest, SizeofTest) 933 test.support.run_unittest(SysModuleTest, SizeofTest)
910 934
911 if __name__ == "__main__": 935 if __name__ == "__main__":
912 test_main() 936 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+