From 4ab90db99afafcf3d6ab91deeaf35e5f4874502b Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 13 Apr 2017 09:41:43 +0530 Subject: added test case to check for stray processes --- yaksh/evaluator_tests/test_bash_evaluation.py | 8 ++++++++ yaksh/evaluator_tests/test_c_cpp_evaluation.py | 10 ++++++++++ yaksh/evaluator_tests/test_java_evaluation.py | 12 ++++++++++++ yaksh/evaluator_tests/test_scilab_evaluation.py | 6 +++++- 4 files changed, 35 insertions(+), 1 deletion(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index 482d45e..ee6949d 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -3,6 +3,8 @@ import unittest import os import shutil import tempfile +from psutil import Process, pid_exists +# Local Imports from yaksh.grader import Grader from yaksh.bash_code_evaluator import BashCodeEvaluator from yaksh.bash_stdio_evaluator import BashStdIOEvaluator @@ -103,6 +105,12 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) + + def test_file_based_assert(self): # Given diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index 304f1cb..d3147f5 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -4,6 +4,7 @@ import os import shutil import tempfile from textwrap import dedent +from psutil import Process # Local import from yaksh.grader import Grader @@ -151,6 +152,11 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) + def test_file_based_assert(self): # Given @@ -401,6 +407,10 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) def test_only_stdout(self): # Given diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 3d127af..2c49a50 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -4,6 +4,9 @@ import os import shutil import tempfile from textwrap import dedent +from psutil import Process, pid_exists +import time + # Local Import from yaksh import grader as gd @@ -158,6 +161,10 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) def test_file_based_assert(self): # Given @@ -398,6 +405,11 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) + def test_only_stdout(self): # Given diff --git a/yaksh/evaluator_tests/test_scilab_evaluation.py b/yaksh/evaluator_tests/test_scilab_evaluation.py index 5a452a3..1792937 100644 --- a/yaksh/evaluator_tests/test_scilab_evaluation.py +++ b/yaksh/evaluator_tests/test_scilab_evaluation.py @@ -8,7 +8,7 @@ from yaksh import grader as gd from yaksh.grader import Grader from yaksh.scilab_code_evaluator import ScilabCodeEvaluator from yaksh.evaluator_tests.test_python_evaluation import EvaluatorBaseTest - +from psutil import Process class ScilabEvaluationTestCases(EvaluatorBaseTest): def setUp(self): @@ -136,6 +136,10 @@ class ScilabEvaluationTestCases(EvaluatorBaseTest): self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) if __name__ == '__main__': unittest.main() -- cgit From c431c255738b741698adffcbf894930ae298b8c0 Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 27 Apr 2017 12:13:22 +0530 Subject: added tests to check killing of stray processes in hook evaluator --- yaksh/evaluator_tests/test_bash_evaluation.py | 5 +++++ yaksh/evaluator_tests/test_c_cpp_evaluation.py | 5 ++++- yaksh/evaluator_tests/test_java_evaluation.py | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index ee6949d..352e95f 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -536,6 +536,11 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get('success')) self.assert_correct_output(self.timeout_msg, result.get('error')) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) + if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index d3147f5..79227f5 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -977,7 +977,10 @@ class CppHookEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get('success')) self.assert_correct_output(self.timeout_msg, result.get('error')) - + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) if __name__ == '__main__': unittest.main() diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 2c49a50..39c5ee9 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -844,8 +844,13 @@ class JavaHookEvaluationTestCases(EvaluatorBaseTest): result = grader.evaluate(kwargs) # Then + self.assertFalse(result.get('success')) self.assert_correct_output(self.timeout_msg, result.get('error')) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) if __name__ == '__main__': -- cgit From 4a8f9a117f6a784fe722b8b381368c41be86024a Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 27 Apr 2017 12:51:10 +0530 Subject: made pep8 changes --- yaksh/evaluator_tests/test_bash_evaluation.py | 11 ++++------- yaksh/evaluator_tests/test_c_cpp_evaluation.py | 14 +++++++------- yaksh/evaluator_tests/test_java_evaluation.py | 13 ++++++------- yaksh/evaluator_tests/test_scilab_evaluation.py | 9 ++++++--- 4 files changed, 23 insertions(+), 24 deletions(-) (limited to 'yaksh/evaluator_tests') diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index 352e95f..8bb8c81 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -107,10 +107,8 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) - - + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_file_based_assert(self): # Given @@ -538,9 +536,8 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get('error')) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) - + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index 79227f5..b15f766 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -154,9 +154,8 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) - + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_file_based_assert(self): # Given @@ -409,8 +408,8 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_only_stdout(self): # Given @@ -979,8 +978,9 @@ class CppHookEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get('error')) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) + if __name__ == '__main__': unittest.main() diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 39c5ee9..ea558ed 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -163,8 +163,8 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_file_based_assert(self): # Given @@ -407,9 +407,8 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) - + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_only_stdout(self): # Given @@ -849,8 +848,8 @@ class JavaHookEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get('error')) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_scilab_evaluation.py b/yaksh/evaluator_tests/test_scilab_evaluation.py index 1792937..c3a1c83 100644 --- a/yaksh/evaluator_tests/test_scilab_evaluation.py +++ b/yaksh/evaluator_tests/test_scilab_evaluation.py @@ -3,12 +3,14 @@ import unittest import os import shutil import tempfile +from psutil import Process from textwrap import dedent + +#Local Import from yaksh import grader as gd from yaksh.grader import Grader from yaksh.scilab_code_evaluator import ScilabCodeEvaluator from yaksh.evaluator_tests.test_python_evaluation import EvaluatorBaseTest -from psutil import Process class ScilabEvaluationTestCases(EvaluatorBaseTest): def setUp(self): @@ -138,8 +140,9 @@ class ScilabEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) + if __name__ == '__main__': unittest.main() -- cgit