@@ -407,6 +407,27 @@ async def _run_scheduler(self, suites_obj: list, runtime: int) -> None:
407407 except asyncio .TimeoutError :
408408 await self ._scheduler .stop ()
409409
410+ async def _apply_fault_injection (self , fault_prob ) -> None :
411+ """
412+ Check if we can apply fault injection configuration
413+ and eventually does it.
414+ """
415+ warn_msg = ""
416+
417+ if not await self ._sut .logged_as_root ():
418+ if fault_prob != 0 :
419+ warn_msg = "Run as root to use kernel fault injection"
420+ else :
421+ if await self ._sut .is_fault_injection_enabled ():
422+ await self ._sut .setup_fault_injection (fault_prob )
423+ else :
424+ if fault_prob != 0 :
425+ warn_msg = "Fault injection is not enabled. Running tests normally"
426+
427+ if warn_msg :
428+ self ._logger .info (warn_msg )
429+ await libkirk .events .fire ("session_warning" , warn_msg )
430+
410431 async def run (self , ** kwargs : dict ) -> None :
411432 """
412433 Run a new session and store results inside a JSON file.
@@ -428,6 +449,8 @@ async def run(self, **kwargs: dict) -> None:
428449 :type randomize: bool
429450 :param runtime: for how long we want to run the session
430451 :type runtime: int
452+ :param fault_prob: fault injection probability
453+ :type fault_prob: int
431454 """
432455 async with self ._run_lock :
433456 await libkirk .events .fire ("session_started" , self ._tmpdir .abspath )
@@ -437,13 +460,18 @@ async def run(self, **kwargs: dict) -> None:
437460 "session_warning" ,
438461 "SUT doesn't support parallel execution" )
439462
463+ fault_prob = kwargs .get ("fault_prob" , 0 )
464+
440465 try :
441466 await self ._start_sut ()
442467
443468 command = kwargs .get ("command" , None )
444469 if command :
445470 await self ._exec_command (command )
446471
472+ if fault_prob != 0 :
473+ await self ._apply_fault_injection (fault_prob )
474+
447475 suites = kwargs .get ("suites" , None )
448476 if suites :
449477 suites_obj = await self ._read_suites (
@@ -470,6 +498,10 @@ async def run(self, **kwargs: dict) -> None:
470498 raise err
471499 finally :
472500 try :
501+ # configure fault injection to the original values
502+ if fault_prob != 0 :
503+ await self ._apply_fault_injection (0 )
504+
473505 if self ._results :
474506 exporter = JSONExporter ()
475507
0 commit comments