Skip to content

Commit

Permalink
Added allow kwarg to fault_simulate()
Browse files Browse the repository at this point in the history
  • Loading branch information
NikosDelijohn committed Sep 12, 2024
1 parent e97fae5 commit a0af523
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/unit_tests/test_zoix.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ def test_fault_simulate(self):
fault_simulation = test_obj.fault_simulate("mock_fsim_instruction1", "mock_fsim_instruction2")
self.assertEqual(fault_simulation, zoix.FaultSimulation.SUCCESS)

with mock.patch("zoix.ZoixInvoker.execute", return_value = ("Some fault sim text", "Stderr text but must be ignored!")) as mocked_execute:

fault_simulation = test_obj.fault_simulate("mock_fsim_instruction1", "mock_fsim_instruction2",
allow = [re.compile(r"Stderr text but must be ignored\!")])
self.assertEqual(fault_simulation, zoix.FaultSimulation.SUCCESS)

# FSIM Error
with mock.patch("zoix.ZoixInvoker.execute", return_value = ("Some fault sim text", "Stderr has text!")) as mocked_execute:

Expand Down
21 changes: 20 additions & 1 deletion src/zoix.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,10 @@ def fault_simulate(self, *instructions: str, **kwargs) -> FaultSimulation:
**kwargs: User-defined options for fault simulation control.
- timeout (float): A timeout in **seconds** for each fsim
instruction.
instruction.
- allow (list[re.Pattern]): Series of regexps to look for in
``stderr`` and allow continuation without raising any error
messages.
Returns:
FaultSimulation: A status Enum which is:
Expand All @@ -601,13 +604,29 @@ def fault_simulate(self, *instructions: str, **kwargs) -> FaultSimulation:
fault_simulation_status = FaultSimulation.SUCCESS

timeout: float = kwargs.get("timeout", None)
allow: list[re.Pattern] = kwargs.get("allow", None)

for cmd in instructions:

stdout, stderr = self.execute(cmd, timeout=timeout)

if stderr and stderr != "TimeoutExpired":

if allow:

continue_execution = False

for regexp in allow:

if regexp.search(stderr):

continue_execution = True
break

if continue_execution:

continue

log.debug(f"Error during execution of {cmd}\n\
------[STDERR STREAM]------\n\
{'-'.join(stderr.splitlines(keepends=True))}\n\
Expand Down

0 comments on commit a0af523

Please sign in to comment.