def testParallel(self): """Test interprocesses actually sync.""" write_lock = locking.PipeLock() read_lock = locking.PipeLock() with osutils.TempDir() as tempdir: # Let the child create a file, but make sure the parent holds us off. # Then make the parent wait for the child to tell us it's done. flag_file = os.path.join(tempdir, 'foo') pid = os.fork() if pid == 0: # Child. # pylint: disable=protected-access try: write_lock.Wait() del write_lock osutils.Touch(flag_file) read_lock.Post() del read_lock except Exception: os._exit(1) finally: # No matter what happens, we must exit w/out running handlers. os._exit(0) else: # Parent. time.sleep(0.5) self.assertNotExists(flag_file) write_lock.Post() del write_lock read_lock.Wait() del read_lock self.assertExists(flag_file) status = os.waitpid(pid, 0)[1] self.assertEqual(process_util.GetExitStatus(status), 0)
def testSIGKILL(self): """Verify harsh signals get decoded.""" status = _SpawnChild(kill_signal=signal.SIGKILL) ret = process_util.GetExitStatus(status) self.assertEqual(ret, 128 + signal.SIGKILL)
def testSIGUSR1(self): """Verify normal kill signals get decoded.""" status = _SpawnChild(kill_signal=signal.SIGUSR1) ret = process_util.GetExitStatus(status) self.assertEqual(ret, 128 + signal.SIGUSR1)
def testExitWeird(self): """Verify weird exits (>=128) get decoded.""" status = _SpawnChild(exit_code=150) ret = process_util.GetExitStatus(status) self.assertEqual(ret, 150)
def testExitError(self): """Verify error exits (>0 && <128) get decoded.""" status = _SpawnChild(exit_code=10) ret = process_util.GetExitStatus(status) self.assertEqual(ret, 10)
def testExitNormal(self): """Verify normal exits get decoded.""" status = _SpawnChild(exit_code=0) ret = process_util.GetExitStatus(status) self.assertEqual(ret, 0)