From 14c8a40eabc2011ae999aedb5bdc9f2648ad6a07 Mon Sep 17 00:00:00 2001 From: Nathaniel Mitchell Date: Fri, 14 Jun 2024 00:53:49 -0700 Subject: [PATCH] Add basic characterization test Signed-off-by: Nathaniel Mitchell --- tests/characterization/__init__.py | 19 +++ tests/characterization/characterize.log | 131 ++++++++++++++++++ tests/characterization/test_modulerefactor.py | 52 +++++++ 3 files changed, 202 insertions(+) create mode 100644 tests/characterization/__init__.py create mode 100644 tests/characterization/characterize.log create mode 100644 tests/characterization/test_modulerefactor.py diff --git a/tests/characterization/__init__.py b/tests/characterization/__init__.py new file mode 100644 index 0000000000..06c0ee1f0d --- /dev/null +++ b/tests/characterization/__init__.py @@ -0,0 +1,19 @@ +# CHIPSEC: Platform Security Assessment Framework +# Copyright (c) 2023, Intel Corporation +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; Version 2. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Contact information: +# chipsec@intel.com +# \ No newline at end of file diff --git a/tests/characterization/characterize.log b/tests/characterization/characterize.log new file mode 100644 index 0000000000..794425854b --- /dev/null +++ b/tests/characterization/characterize.log @@ -0,0 +1,131 @@ + +################################################################ +## ## +## CHIPSEC: Platform Hardware Security Assessment Framework ## +## ## +################################################################ +[CHIPSEC] Version : 1.13.1 +[CHIPSEC] Arguments: -m common.cpu.cpu_info -l tmp.log + + +WARNING: ******************************************************************* +WARNING: Chipsec should only be used on test systems! +WARNING: It should not be installed/deployed on production end-user systems. +WARNING: See WARNING.txt +WARNING: ******************************************************************* + + +[CHIPSEC] OS : Windows 10 10.0.22631 AMD64 +[CHIPSEC] Python : 3.10.1 (64-bit) +[CHIPSEC] Helper : WindowsHelper (\??\C:\Users\Nathaniel\git\chipsec\chipsec\helper\windows\windows_amd64\chipsec_hlpr.sys) +[CHIPSEC] Platform: ADL-P/H 4+8 +[CHIPSEC] CPUID: 906A2 +[CHIPSEC] VID: 8086 +[CHIPSEC] DID: 4621 +[CHIPSEC] RID: 01 +[CHIPSEC] PCH : Intel ADL-P (600) PCH +[CHIPSEC] VID: 8086 +[CHIPSEC] DID: 5182 +[CHIPSEC] RID: 01 + + +[+] loaded chipsec.modules.common.cpu.cpu_info +[*] running loaded modules .. + +[*] Running module: chipsec.modules.common.cpu.cpu_info +[x][ ======================================================================= +[x][ Module: Current Processor Information: +[x][ ======================================================================= +[*] Thread 0000 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0001 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0002 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0003 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0004 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0005 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0006 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0007 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0008 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0009 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0010 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0011 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0012 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0013 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0014 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[*] Thread 0015 +[*] Processor: 12th Gen Intel(R) Core(TM) i5-1240P +[*] Family: 06 Model: 9A Stepping: 2 +[*] Microcode: 0000030D +[*] +[#] INFORMATION: Processor information displayed + +[CHIPSEC] *************************** SUMMARY *************************** +[CHIPSEC] +[CHIPSEC] Modules total 1 +[CHIPSEC] Modules failed to run 0: +[CHIPSEC] Modules passed 0: +[CHIPSEC] Modules information 1: +[#] INFORMATION: chipsec.modules.common.cpu.cpu_info +[CHIPSEC] Modules failed 0: +[CHIPSEC] Modules with warnings 0: +[CHIPSEC] Modules not applicable 0: +[CHIPSEC] ***************************************************************** diff --git a/tests/characterization/test_modulerefactor.py b/tests/characterization/test_modulerefactor.py new file mode 100644 index 0000000000..e476abae39 --- /dev/null +++ b/tests/characterization/test_modulerefactor.py @@ -0,0 +1,52 @@ + +# CHIPSEC: Platform Security Assessment Framework +# Copyright (c) 2023, Intel Corporation +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; Version 2. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Contact information: +# chipsec@intel.com +# + +import unittest +# from unittest.mock import patch, Mock, MagicMock, call +from chipsec_main import run +from io import StringIO +from contextlib import redirect_stdout +import os +import re + + + + +class TestHalCpu(unittest.TestCase): + + def test_with_module_cpuinfo(self): + with open("tests\\characterization\\characterize.log") as f: + EXPECTED_LOG_CPUINFO = f.read() + + os.remove("chipsec\\logs\\characterize.log") + run("-m common.cpu.cpu_info -l characterize.log") + with open("chipsec\\logs\\characterize.log") as f: + filetext = f.read() + + cleaned = re.sub(r"Time elapsed [.0-9]{5}","", filetext) + self.assertEqual(cleaned, EXPECTED_LOG_CPUINFO) + + +if __name__ == '__main__': + unittest.main() + + +