Skip to content

Commit

Permalink
Support test_imperative container_sequential and signal_handler with …
Browse files Browse the repository at this point in the history
…eager_guard (#38614)
  • Loading branch information
veyron95 authored Jan 4, 2022
1 parent 30be931 commit a7b13d3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
import unittest
import paddle.fluid as fluid
import numpy as np
from paddle.fluid.framework import _test_eager_guard


class TestImperativeContainerSequential(unittest.TestCase):
def test_sequential(self):
def func_sequential(self):
data = np.random.uniform(-1, 1, [5, 10]).astype('float32')
with fluid.dygraph.guard():
data = fluid.dygraph.to_variable(data)
Expand Down Expand Up @@ -55,7 +56,12 @@ def test_sequential(self):
loss2 = fluid.layers.reduce_mean(res2)
loss2.backward()

def test_sequential_list_params(self):
def test_sequential(self):
with _test_eager_guard():
self.func_sequential()
self.func_sequential()

def func_sequential_list_params(self):
data = np.random.uniform(-1, 1, [5, 10]).astype('float32')
with fluid.dygraph.guard():
data = fluid.dygraph.to_variable(data)
Expand Down Expand Up @@ -90,6 +96,11 @@ def test_sequential_list_params(self):
loss2 = fluid.layers.reduce_mean(res2)
loss2.backward()

def test_sequential_list_params(self):
with _test_eager_guard():
self.func_sequential_list_params()
self.func_sequential_list_params()


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import paddle.compat as cpt
from paddle.fluid import core
from paddle.fluid.framework import _test_eager_guard


def set_child_signal_handler(self, child_pid):
Expand All @@ -37,8 +38,8 @@ def __handler__(signum, frame):
signal.signal(signal.SIGCHLD, __handler__)


class TestDygraphDataLoaderSingalHandler(unittest.TestCase):
def test_child_process_exit_with_error(self):
class DygraphDataLoaderSingalHandler(unittest.TestCase):
def func_child_process_exit_with_error(self):
def __test_process__():
core._set_process_signal_handler()
sys.exit(1)
Expand All @@ -65,7 +66,12 @@ def try_except_exit():

self.assertIsNotNone(exception)

def test_child_process_killed_by_sigsegv(self):
def test_child_process_exit_with_error(self):
with _test_eager_guard():
self.func_child_process_exit_with_error()
self.func_child_process_exit_with_error()

def func_child_process_killed_by_sigsegv(self):
def __test_process__():
core._set_process_signal_handler()
os.kill(os.getpid(), signal.SIGSEGV)
Expand Down Expand Up @@ -93,7 +99,12 @@ def try_except_exit():

self.assertIsNotNone(exception)

def test_child_process_killed_by_sigbus(self):
def test_child_process_killed_by_sigsegv(self):
with _test_eager_guard():
self.func_child_process_killed_by_sigsegv()
self.func_child_process_killed_by_sigsegv()

def func_child_process_killed_by_sigbus(self):
def __test_process__():
core._set_process_signal_handler()
os.kill(os.getpid(), signal.SIGBUS)
Expand All @@ -120,7 +131,12 @@ def try_except_exit():

self.assertIsNotNone(exception)

def test_child_process_killed_by_sigterm(self):
def test_child_process_killed_by_sigbus(self):
with _test_eager_guard():
self.func_child_process_killed_by_sigbus()
self.func_child_process_killed_by_sigbus()

def func_child_process_killed_by_sigterm(self):
def __test_process__():
core._set_process_signal_handler()
time.sleep(10)
Expand All @@ -132,6 +148,11 @@ def __test_process__():
set_child_signal_handler(id(self), test_process.pid)
time.sleep(1)

def test_child_process_killed_by_sigterm(self):
with _test_eager_guard():
self.func_child_process_killed_by_sigterm()
self.func_child_process_killed_by_sigterm()


if __name__ == '__main__':
unittest.main()

0 comments on commit a7b13d3

Please sign in to comment.