Skip to content

Commit

Permalink
Add _logger.disable() to tests to reduce prints
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
  • Loading branch information
npmitche committed Nov 6, 2023
1 parent 9f13a48 commit 1a5f33d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
20 changes: 11 additions & 9 deletions tests/modules/run_chipsec_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ def run_chipsec_module(csm: ChipsecMain, module_replay_file: str) -> int:
ret = csm.run_loaded_modules()
return ret

def setup_run_destroy_module(init_replay_file: str, module_str: str, module_args: str = "", module_replay_file: str = "", mock_logger = True) -> int:
if mock_logger:
chipsec.logger._logger = Mock()
chipsec.logger._logger.VERBOSE = False
chipsec.logger._logger.DEBUG = False
def setup_run_destroy_module_with_mock_logger(init_replay_file: str, module_str: str, module_args: str = "", module_replay_file: str = "") -> int:
chipsec.logger._logger.disable()
chipsec.logger._logger = Mock()
chipsec.logger._logger.VERBOSE = False
chipsec.logger._logger.DEBUG = False
retval = setup_run_destroy_module(init_replay_file, module_str, module_args, module_replay_file)
chipsec.logger._logger = chipsec.logger.Logger()
return retval

def setup_run_destroy_module(init_replay_file: str, module_str: str, module_args: str = "", module_replay_file: str = "") -> int:
arg_str = f" {module_args}" if module_args else ""
cli_cmds = f"-m {module_str}{arg_str}".strip().split(' ')
cs._chipset = None
par = parse_args(cli_cmds)
csm = ChipsecMain(par, cli_cmds)
replayHelper = rph.ReplayHelper(init_replay_file)
csm._helper = replayHelper
retval = run_chipsec_module(csm, module_replay_file)
if mock_logger:
chipsec.logger._logger = chipsec.logger.Logger()
return retval
return run_chipsec_module(csm, module_replay_file)
6 changes: 3 additions & 3 deletions tests/modules/test_tgl_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from chipsec.file import get_main_dir
from chipsec.testcase import ExitCode
from tests.modules.run_chipsec_module import setup_run_destroy_module
from tests.modules.run_chipsec_module import setup_run_destroy_module_with_mock_logger

class TestTglModules(unittest.TestCase):
def setUp(self) -> None:
Expand All @@ -35,10 +35,10 @@ def setUp(self) -> None:
def derive_filename(self, module_name:str) -> str:
return f"{module_name.replace('.', '-')}_test.json"

def run_and_test_module(self, module_name:str, expected_returncode:int, mock_logger = True) -> None:
def run_and_test_module(self, module_name:str, expected_returncode:int) -> None:
test_recording = self.derive_filename(module_name)
replay_file = os.path.join(self.folder_path, test_recording)
retval = setup_run_destroy_module(self.init_replay_file, module_name, module_replay_file=replay_file, mock_logger=mock_logger)
retval = setup_run_destroy_module_with_mock_logger(self.init_replay_file, module_name, module_replay_file=replay_file)
self.assertEqual(retval, expected_returncode, f"Expected: {expected_returncode} but got: {retval}")

def test_tgl_module_bios_smi(self):
Expand Down
5 changes: 3 additions & 2 deletions tests/utilcmd/run_chipsec_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import chipsec.logger


def run_chipsec_util(csu: ChipsecUtil, util_replay_file: str) -> bool:
def run_chipsec_util(csu: ChipsecUtil, util_replay_file: str) -> int:
csu._cs.init(csu._platform, csu._pch, csu._helper, not csu._no_driver, csu._load_config, csu._ignore_platform)
if util_replay_file:
csu._helper.config_file = util_replay_file
Expand All @@ -38,7 +38,8 @@ def run_chipsec_util(csu: ChipsecUtil, util_replay_file: str) -> bool:
comm.tear_down()
return comm.ExitCode

def setup_run_destroy_util(init_replay_file: str, util_name: str, util_args: str = "", util_replay_file: str = "") -> bool:
def setup_run_destroy_util(init_replay_file: str, util_name: str, util_args: str = "", util_replay_file: str = "") -> int:
chipsec.logger._logger.disable()
chipsec.logger._logger = Mock()
arg_str = f" {util_args}" if util_args else ""
cli_cmds = f"{util_name}{arg_str}".strip().split(' ')
Expand Down

0 comments on commit 1a5f33d

Please sign in to comment.