home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 July / maximum-cd-2011-07.iso / DiscContents / LibO_3.3.2_Win_x86_install_multi.exe / libreoffice1.cab / test_fork1.py < prev    next >
Encoding:
Python Source  |  2011-03-15  |  903 b   |  33 lines

  1. """This test checks for correct fork() behavior.
  2. """
  3.  
  4. import os
  5. import time
  6. from test.fork_wait import ForkWait
  7. from test.test_support import TestSkipped, run_unittest, reap_children
  8.  
  9. try:
  10.     os.fork
  11. except AttributeError:
  12.     raise TestSkipped, "os.fork not defined -- skipping test_fork1"
  13.  
  14. class ForkTest(ForkWait):
  15.     def wait_impl(self, cpid):
  16.         for i in range(10):
  17.             # waitpid() shouldn't hang, but some of the buildbots seem to hang
  18.             # in the forking tests.  This is an attempt to fix the problem.
  19.             spid, status = os.waitpid(cpid, os.WNOHANG)
  20.             if spid == cpid:
  21.                 break
  22.             time.sleep(1.0)
  23.  
  24.         self.assertEqual(spid, cpid)
  25.         self.assertEqual(status, 0, "cause = %d, exit = %d" % (status&0xff, status>>8))
  26.  
  27. def test_main():
  28.     run_unittest(ForkTest)
  29.     reap_children()
  30.  
  31. if __name__ == "__main__":
  32.     test_main()
  33.