[pypy-svn] r51683 - in pypy/dist/pypy/translator/c/gcc: . test

arigo at codespeak.net arigo at codespeak.net
Wed Feb 20 12:39:20 CET 2008


Author: arigo
Date: Wed Feb 20 12:39:18 2008
New Revision: 51683

Modified:
   pypy/dist/pypy/translator/c/gcc/test/test_asmgcroot.py
   pypy/dist/pypy/translator/c/gcc/trackgcroot.py
Log:
Improve the asmgcc tests by checking that the sorting done in
asmgcroot.py works correctly.  So far, at least on Linux, the
addresses were automatically sorted in these tests (but not
e.g. in faassen builds of PyPy, due to gcc profiling).


Modified: pypy/dist/pypy/translator/c/gcc/test/test_asmgcroot.py
==============================================================================
--- pypy/dist/pypy/translator/c/gcc/test/test_asmgcroot.py	(original)
+++ pypy/dist/pypy/translator/c/gcc/test/test_asmgcroot.py	Wed Feb 20 12:39:18 2008
@@ -38,6 +38,7 @@
         cbuilder = CStandaloneBuilder(t, main, config=config)
         c_source_filename = cbuilder.generate_source(
             defines = cbuilder.DEBUG_DEFINES)
+        self.patch_makefile(cbuilder.targetdir)
         if conftest.option.view:
             t.view()
         exe_name = cbuilder.compile()
@@ -63,6 +64,24 @@
                 return int(result)
         return run
 
+    def patch_makefile(self, targetdir):
+        # for testing, patch the Makefile to add the -r option to
+        # trackgcroot.py.
+        makefile = targetdir.join('Makefile')
+        f = makefile.open()
+        lines = f.readlines()
+        f.close()
+        found = False
+        for i in range(len(lines)):
+            if 'trackgcroot.py' in lines[i]:
+                lines[i] = lines[i].replace('trackgcroot.py',
+                                            'trackgcroot.py -r')
+                found = True
+        assert found
+        f = makefile.open('w')
+        f.writelines(lines)
+        f.close()
+
 
 class TestAsmGCRootWithSemiSpaceGC(AbstractTestAsmGCRoot,
                                    test_newgc.TestSemiSpaceGC):

Modified: pypy/dist/pypy/translator/c/gcc/trackgcroot.py
==============================================================================
--- pypy/dist/pypy/translator/c/gcc/trackgcroot.py	(original)
+++ pypy/dist/pypy/translator/c/gcc/trackgcroot.py	Wed Feb 20 12:39:18 2008
@@ -1,6 +1,6 @@
 #! /usr/bin/env python
 
-import re, sys, os
+import re, sys, os, random
 
 r_functionstart = re.compile(r"\t.type\s+(\w+),\s*[@]function\s*$")
 r_functionend   = re.compile(r"\t.size\s+(\w+),\s*[.]-(\w+)\s*$")
@@ -26,11 +26,12 @@
 
 class GcRootTracker(object):
 
-    def __init__(self, verbose=0):
+    def __init__(self, verbose=0, shuffle=False):
         self.gcmaptable = []
         self.verbose = verbose
         self.seen_main = False
         self.files_seen = 0
+        self.shuffle = shuffle     # to debug the sorting logic in asmgcroot.py
 
     def dump(self, output):
         assert self.seen_main
@@ -129,7 +130,11 @@
         if self.verbose > 1:
             for label, state in table:
                 print >> sys.stderr, label, '\t', format_callshape(state)
-        self.gcmaptable.extend(compress_gcmaptable(table))
+        table = compress_gcmaptable(table)
+        if self.shuffle and random.random() < 0.5:
+            self.gcmaptable[:0] = table
+        else:
+            self.gcmaptable.extend(table)
         self.seen_main |= tracker.is_main
         return tracker.lines
 
@@ -973,12 +978,18 @@
 
 
 if __name__ == '__main__':
-    if sys.argv and sys.argv[1] == '-v':
-        del sys.argv[1]
-        verbose = sys.maxint
-    else:
-        verbose = 1
-    tracker = GcRootTracker(verbose=verbose)
+    verbose = 1
+    shuffle = False
+    while len(sys.argv) > 1:
+        if sys.argv[1] == '-v':
+            del sys.argv[1]
+            verbose = sys.maxint
+        elif sys.argv[1] == '-r':
+            del sys.argv[1]
+            shuffle = True
+        else:
+            break
+    tracker = GcRootTracker(verbose=verbose, shuffle=shuffle)
     for fn in sys.argv[1:]:
         tmpfn = fn + '.TMP'
         f = open(fn, 'r')



More information about the Pypy-commit mailing list