Skip to content

Commit

Permalink
python: Added stdout, stderr to TaskResult and use it from OppTestTask.
Browse files Browse the repository at this point in the history
  • Loading branch information
levy committed Oct 14, 2024
1 parent 42f8944 commit 1cd9b16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion python/inet/common/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TaskResult:
result are the result, reason and error_message.
"""

def __init__(self, task=None, result="DONE", expected_result="DONE", reason=None, error_message=None, exception=None, store_complete_binary_hash=False, store_complete_source_hash=False, store_partial_binary_hash=False, store_partial_source_hash=False, elapsed_wall_time=None, possible_results=["DONE", "SKIP", "CANCEL", "ERROR"], possible_result_colors=[COLOR_GREEN, COLOR_CYAN, COLOR_CYAN, COLOR_RED], **kwargs):
def __init__(self, task=None, result="DONE", expected_result="DONE", reason=None, stdout=None, stderr=None, error_message=None, exception=None, store_complete_binary_hash=False, store_complete_source_hash=False, store_partial_binary_hash=False, store_partial_source_hash=False, elapsed_wall_time=None, possible_results=["DONE", "SKIP", "CANCEL", "ERROR"], possible_result_colors=[COLOR_GREEN, COLOR_CYAN, COLOR_CYAN, COLOR_RED], **kwargs):
"""
Initializes a new task result object.
Expand Down Expand Up @@ -96,6 +96,8 @@ def __init__(self, task=None, result="DONE", expected_result="DONE", reason=None
self.expected_result = expected_result
self.expected = expected_result == result
self.reason = reason
self.stdout = stdout
self.stderr = stderr
self.error_message = error_message
self.exception = exception
self.elapsed_wall_time = elapsed_wall_time
Expand Down
3 changes: 2 additions & 1 deletion python/inet/test/opp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ def run_protected(self, capture_output=True, **kwargs):
args = [executable, "runtest", self.test_file_name]
subprocess_result = subprocess.run(args, cwd=self.working_directory, capture_output=capture_output, env=self.simulation_project.get_env())
stdout = subprocess_result.stdout.decode("utf-8")
stderr = subprocess_result.stderr.decode("utf-8")
match = re.search(r"Aggregate result: (\w+)", stdout)
if subprocess_result.returncode == signal.SIGINT.value or subprocess_result.returncode == -signal.SIGINT.value:
return self.task_result_class(self, result="CANCEL", reason="Cancel by user")
elif match and subprocess_result.returncode == 0:
return self.task_result_class(self, result=match.group(1))
else:
return self.task_result_class(self, result="FAIL", reason=f"Non-zero exit code: {subprocess_result.returncode}")
return self.task_result_class(self, result="FAIL", reason=f"Non-zero exit code: {subprocess_result.returncode}", stdout=stdout, stderr=stderr)

def get_opp_test_tasks(test_folder, simulation_project=None, filter=".*", full_match=False, **kwargs):
"""
Expand Down

0 comments on commit 1cd9b16

Please sign in to comment.