Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions libkirk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ def _finjection_config(value: str) -> int:
return max(0, min(100, ret))


def _finterval_config(value: str) -> int:
"""
Return interval of fault injection.
"""
if not value:
return 100

try:
ret = int(value)
except TypeError as err:
raise argparse.ArgumentTypeError("Invalid number") from err

return 100 if ret < 0 else ret


def _get_skip_tests(skip_tests: str, skip_file: str) -> str:
"""
Return the skipped tests regexp.
Expand Down Expand Up @@ -361,6 +376,7 @@ async def session_run() -> None:
randomize=args.randomize,
runtime=args.runtime,
fault_prob=args.fault_injection,
fault_interval=args.fault_interval,
)
except asyncio.CancelledError:
await session.stop()
Expand Down Expand Up @@ -518,6 +534,12 @@ def run(cmd_args: Optional[List[str]] = None) -> None:
default=0,
help="Probability of failure (0-100)",
)
exec_opts.add_argument(
"--fault-interval",
type=_finterval_config,
default=100,
help="Fault injection interval (default: 100)",
)
exec_opts.add_argument(
"--optimize-sut",
"-O",
Expand Down
13 changes: 10 additions & 3 deletions libkirk/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ async def _run_scheduler(self, suites_obj: List[Suite], runtime: float) -> None:
except asyncio.TimeoutError:
await self._scheduler.stop()

async def _apply_fault_injection(self, fault_prob: int) -> None:
async def _apply_fault_injection(
self,
fault_prob: int,
fault_interval: int = 100,
) -> None:
"""
Check if we can apply fault injection configuration
and eventually does it.
Expand All @@ -415,7 +419,7 @@ async def _apply_fault_injection(self, fault_prob: int) -> None:
warn_msg = "Run as root to use kernel fault injection"
else:
if await self._sut.is_fault_injection_enabled():
await self._sut.setup_fault_injection(fault_prob)
await self._sut.setup_fault_injection(fault_prob, fault_interval)
else:
if fault_prob != 0:
warn_msg = "Fault injection is not enabled. Running tests normally"
Expand All @@ -436,6 +440,7 @@ async def run(
randomize: bool = False,
runtime: float = 0,
fault_prob: int = 0,
fault_interval: int = 100,
) -> None:
"""
Run a new session and store results inside a JSON file.
Expand All @@ -460,6 +465,8 @@ async def run(
:type runtime: float
:param fault_prob: Fault injection probability.
:type fault_prob: int
:param fault_interval: Fault injection interval.
:type fault_interval: int
"""
async with self._run_lock:
await libkirk.events.fire("session_started", suites, self._tmpdir.abspath)
Expand All @@ -477,7 +484,7 @@ async def run(
await self._exec_command(command)

if fault_prob != 0:
await self._apply_fault_injection(fault_prob)
await self._apply_fault_injection(fault_prob, fault_interval)

if suites:
suites_obj = await self._read_suites(
Expand Down
12 changes: 9 additions & 3 deletions libkirk/sut.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,24 @@ async def is_fault_injection_enabled(self) -> bool:

return True

async def setup_fault_injection(self, prob: int) -> None:
async def setup_fault_injection(
self,
prob: int,
interval_override: int = 100,
) -> None:
"""
Configure kernel fault injection. When prob is zero, the fault
injection is set to default values.

:param prob: Fault probabilty in between 0-100.
:param prob: Fault probability in between 0-100.
:type prob: int
:param interval_override: Fault interval.
:type interval_override: int
"""
if not await self.is_running():
raise SUTError("SUT is not running")

interval = 1 if prob == 0 else 100
interval = 1 if prob == 0 else interval_override
times = 1 if prob == 0 else -1

async def _set_value(value: int, path: str) -> None:
Expand Down
6 changes: 6 additions & 0 deletions libkirk/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def test_finjection_config_over_100(self):

def test_finjection_config_negative(self):
assert libkirk.main._finjection_config("-5") == 0

def test_finterval_config_empty(self):
assert libkirk.main._finterval_config("") == 100

def test_finterval_config_negative(self):
assert libkirk.main._finterval_config("-5") == 100

def test_get_skip_tests_empty(self):
assert libkirk.main._get_skip_tests("", "") == ""
Expand Down