[pypy-svn] r11513 - in pypy/dist: lib-python-2.3.4/test lib-python-2.3.4/test/result pypy/tool

hpk at codespeak.net hpk at codespeak.net
Wed Apr 27 14:28:10 CEST 2005


Author: hpk
Date: Wed Apr 27 14:28:10 2005
New Revision: 11513

Added:
   pypy/dist/lib-python-2.3.4/test/result/
   pypy/dist/pypy/tool/alarm.py
Modified:
   pypy/dist/lib-python-2.3.4/test/conftest.py
Log:

- introduce a new test running mechanism 
  that invokes compliance tests (those
  in lib-python-2.3.4/test and pypy/lib/test2) 
  in a subprocess run by PyPy.   The output
  is recorded into files in result/*.txt 
  together with system and failure information 
  Note that currently such test runs time out 
  after 15*60 seconds by default (see the new
  '-T seconds' option). 

- also we now run this subprocess/pypy test run 
  mode by default until we have catched up with 
  extracting tests properly to have more fine 
  grained information about which tests failed 
  and how many we pass alltogether ... 

- you can get back to the old "extract the 
  tests" behaviour with the '-E' or '--extracttests' 
  option 

(Armin, Holger) 



Modified: pypy/dist/lib-python-2.3.4/test/conftest.py
==============================================================================
--- pypy/dist/lib-python-2.3.4/test/conftest.py	(original)
+++ pypy/dist/lib-python-2.3.4/test/conftest.py	Wed Apr 27 14:28:10 2005
@@ -26,7 +26,13 @@
     Option('-D', '--withdisabled', action="store_true", 
            default=False, dest="withdisabled", 
            help="include all disabled tests in the test run."), 
-)
+    Option('-E', '--extracttests', action="store_true", 
+           default=False, dest="extracttests", 
+           help="try to extract single tests and run them via py.test/PyPy"), 
+    Option('-T', '--timeout', action="store", type="int", 
+           default=15*60, dest="timeout", 
+           help="timeout running of a test module (default 15*60 seconds)"), 
+    ) 
 
 
 mydir = py.magic.autopath().dirpath()
@@ -91,7 +97,7 @@
     # we once and for all want to patch run_unittest 
     # to get us the list of intended unittest-TestClasses
     # from each regression test 
-    if w_utestlist is None: 
+    if w_utestlist is None and option.extracttests: 
         callex(space, hack_test_support, space) 
     return space 
 
@@ -176,6 +182,9 @@
 
     def getfspath(self): 
         if self.parent.testdecl.modified: 
+            # we have to use a modified test ... (this could probably
+            # be done by just looking for the according test file 
+            # but i found this more explicit) 
             return pypydir.join('lib', 'test2', self.fspath.basename) 
         else: 
             return self.fspath # unmodified regrtest
@@ -727,8 +736,8 @@
 }
 
 class RegrDirectory(py.test.collect.Directory): 
-    """ A special collector for the compliance tests 
-        of CPython.  Basically we work off the above 'testmap' 
+    """ The central hub for gathering CPython's compliance tests
+        Basically we work off the above 'testmap' 
         which describes for all test modules their specific 
         type.  XXX If you find errors in the classification 
         please correct them! 
@@ -747,7 +756,82 @@
         if name in self.testmap: 
             testdecl = self.testmap[name]
             fspath = self.fspath.join(name) 
-            return testdecl.testclass(fspath, parent=self, testdecl=testdecl) 
+            if option.extracttests:  
+                return testdecl.testclass(fspath, parent=self, testdecl=testdecl) 
+            else: 
+                return RunFileExternal(fspath, parent=self, testdecl=testdecl) 
 
 Directory = RegrDirectory
 
+
+def getrev(path): 
+    try: 
+        return py.path.svnwc(mydir).info().rev
+    except: 
+        return 'unknown'  # on windows people not always have 'svn' in their path
+
+class RunFileExternal(OpErrorModule): 
+    # a Module shows more nicely with the session reporting 
+    # (i know this needs to become nicer) 
+    def tryiter(self, stopitems=()): 
+        return []
+    def run(self): 
+        return ['pypy-ext']
+    def join(self, name): 
+        if name == 'pypy-ext': 
+            return ReallyRunFileExternal(name, parent=self, fspath=self.fspath) 
+
+class ReallyRunFileExternal(RunAppFileItem): 
+
+    def run(self): 
+        """ invoke a subprocess running the test file via PyPy. 
+            record its output into the 'result' subdirectory. 
+            (we might want to create subdirectories for 
+            each user, because we will probably all produce 
+            such result runs and they will not be the same
+            i am afraid. 
+        """ 
+        import os
+        import time
+        import socket
+        import getpass
+        fspath = self.getfspath() 
+        python = sys.executable 
+        pypy_dir = py.path.local(pypy.__file__).dirpath()
+        pypy_script = pypy_dir.join('interpreter', 'py.py')
+        alarm_script = pypy_dir.join('tool', 'alarm.py')
+        TIMEOUT = option.timeout 
+        cmd = "%s %s %d %s %s" %(python, alarm_script, TIMEOUT, pypy_script, fspath)
+        resultfilename = mydir.join('result', fspath.new(ext='.txt').basename)
+        resultfile = resultfilename.open('w')
+
+        try:
+            username = getpass.getuser()
+        except:
+            username = 'unknown' 
+        print >> resultfile, "command:", cmd
+        print >> resultfile, "run by: %s@%s" % (username, socket.gethostname())
+        print >> resultfile, "sys.platform:", sys.platform 
+        print >> resultfile, "sys.version_info:", sys.version_info 
+        print >> resultfile, "startdate:", time.ctime()
+        print >> resultfile, 'pypy-revision:', getrev(pypydir)
+        print >> resultfile, '='*60
+        print "executing", cmd 
+        starttime = time.time()
+        resultfile.close()
+
+        status = os.system("%s >>%s 2>&1" %(cmd, resultfilename) )
+        if os.WIFEXITED(status):
+            status = os.WEXITSTATUS(status)
+        else:
+            status = 'abnormal termination 0x%x' % status
+
+        resultfile = resultfilename.open('a')
+        print >> resultfile, '='*26, 'closed', '='*26
+        print >> resultfile, 'execution time:', time.time() - starttime, 'seconds'
+        print >> resultfile, 'exit status:', status
+        resultfile.close()
+        if status != 0:
+            time.sleep(0.5)   # time for a Ctrl-C to reach us :-)
+        #print output 
+        assert status == 0, "exitstatus is %d" %(status,)

Added: pypy/dist/pypy/tool/alarm.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/alarm.py	Wed Apr 27 14:28:10 2005
@@ -0,0 +1,24 @@
+
+import traceback 
+
+def _main_with_alarm():
+    import sys, os
+    import time
+    import thread
+
+
+    def timeout_thread(timeout):
+        stderr = sys.stderr
+        interrupt_main = thread.interrupt_main
+        time.sleep(timeout)
+        stderr.write("="*26 + "timeout" + "="*26 + "\n")
+        interrupt_main()
+
+
+    timeout = float(sys.argv[1])
+    thread.start_new_thread(timeout_thread, (timeout,))
+    del sys.argv[:2]
+    sys.path.insert(0, os.path.dirname(sys.argv[0]))
+    return sys.argv[0]
+
+execfile(_main_with_alarm())



More information about the Pypy-commit mailing list