mirror of
https://github.com/chipsec/chipsec
synced 2026-06-08 13:31:00 +00:00
Add basic tests
This commit is contained in:
@@ -160,7 +160,7 @@ class ChipsecUtil:
|
||||
logger().warn("*******************************************************************")
|
||||
except (None,Exception) , msg:
|
||||
logger().error(str(msg))
|
||||
exit(-1)
|
||||
sys.exit(-1)
|
||||
|
||||
logger().log( "[CHIPSEC] Executing command '%s' with args %s\n" % (cmd,argv[2:]) )
|
||||
self.commands[ cmd ]['func']( argv )
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from tests.hardware import test_ubuntu
|
||||
|
||||
class EliteBook1040UbuntuTest(test_ubuntu.GenericUbuntuTest):
|
||||
|
||||
PRODUCT_NAME = 'HP EliteBook Folio 1040 G1'
|
||||
BIOS_VERSION = 'L83 Ver. 01.21'
|
||||
PASS = ["chipsec.modules.common.spi_desc",
|
||||
"chipsec.modules.common.bios_wp",
|
||||
"chipsec.modules.common.spi_lock",
|
||||
"chipsec.modules.common.smrr",
|
||||
"chipsec.modules.common.smm",
|
||||
"chipsec.modules.common.bios_ts",
|
||||
"chipsec.modules.common.bios_smi",
|
||||
"chipsec.modules.smm_dma",
|
||||
"chipsec.modules.remap"]
|
||||
|
||||
SKIPPED = ["chipsec.modules.common.secureboot.variables",
|
||||
"chipsec.modules.common.uefi.s3bootscript",
|
||||
"chipsec.modules.common.uefi.access_uefispec",
|
||||
"chipsec.modules.module_template"]
|
||||
|
||||
def setUp(self):
|
||||
super(EliteBook1040UbuntuTest, self).setUp()
|
||||
|
||||
def test_main(self):
|
||||
self._generic_main()
|
||||
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import platform
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import chipsec_main
|
||||
from chipsec import logger
|
||||
|
||||
class GenericHardwareTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
if hasattr(self, "SYSTEM") and platform.system() != self.SYSTEM:
|
||||
self.skipTest("Unsupported system {}".format(self.SYSTEM))
|
||||
if hasattr(self, "DIST") and platform.dist() != self.DIST:
|
||||
self.skipTest("Unsupported distribution {}".format(self.DIST))
|
||||
if hasattr(self, "PRODUCT_NAME") and self.product_name() != self.PRODUCT_NAME:
|
||||
self.skipTest("Unsupported platform {}".format(self.PRODUCT_NAME))
|
||||
if hasattr(self, "BIOS_VERSION") and self.bios_version() != self.BIOS_VERSION:
|
||||
self.skipTest("Unsupported BIOS version {}".format(self.BIOS_VERSION))
|
||||
_, self.log_file = tempfile.mkstemp()
|
||||
|
||||
def tearDown(self):
|
||||
os.remove(self.log_file)
|
||||
|
||||
def _generic_main(self):
|
||||
cm = chipsec_main.ChipsecMain(["-l", self.log_file])
|
||||
error_code = cm.main()
|
||||
logger.logger().close()
|
||||
self.log = open(self.log_file).read()
|
||||
self.assertLessEqual(error_code, 31, "At least one test raised an error")
|
||||
for test in self.PASS:
|
||||
self.assertIn("PASSED: {}".format(test), self.log)
|
||||
for test in self.SKIPPED:
|
||||
self.assertIn("SKIPPED: {}".format(test), self.log)
|
||||
@@ -0,0 +1,43 @@
|
||||
import os.path
|
||||
import subprocess
|
||||
|
||||
from tests.hardware import test_generic
|
||||
|
||||
from chipsec.helper import oshelper
|
||||
|
||||
class GenericUbuntuTest(test_generic.GenericHardwareTest):
|
||||
|
||||
SYSTEM = 'Linux'
|
||||
DIST = ('Ubuntu', '14.04', 'trusty')
|
||||
|
||||
def setUp(self):
|
||||
super(GenericUbuntuTest, self).setUp()
|
||||
self.load_driver()
|
||||
|
||||
def tearDown(self):
|
||||
self.unload_driver()
|
||||
super(GenericUbuntuTest, self).tearDown()
|
||||
|
||||
def load_driver(self):
|
||||
subprocess.call(["insmod",
|
||||
os.path.join(os.path.dirname(__file__),
|
||||
"..", "..", "..",
|
||||
"drivers", "linux", "chipsec.ko")])
|
||||
|
||||
def unload_driver(self):
|
||||
oshelper.helper().helper.close()
|
||||
subprocess.call(["rmmod", "chipsec"])
|
||||
|
||||
def product_name(self):
|
||||
try:
|
||||
product_name = open("/sys/class/dmi/id/product_name").read().strip()
|
||||
return product_name
|
||||
except:
|
||||
return None
|
||||
|
||||
def bios_version(self):
|
||||
try:
|
||||
bios_version = open("/sys/class/dmi/id/bios_version").read().strip()
|
||||
return bios_version
|
||||
except:
|
||||
return None
|
||||
@@ -0,0 +1,29 @@
|
||||
from tests.hardware import test_ubuntu
|
||||
|
||||
class Z420UbuntuTest(test_ubuntu.GenericUbuntuTest):
|
||||
|
||||
PRODUCT_NAME = 'HP Z420 Workstation'
|
||||
BIOS_VERSION = 'J61 v03.88'
|
||||
PASS = ["chipsec.modules.common.spi_desc",
|
||||
"chipsec.modules.common.bios_wp",
|
||||
"chipsec.modules.common.spi_lock",
|
||||
"chipsec.modules.common.smrr",
|
||||
"chipsec.modules.common.bios_ts",
|
||||
"chipsec.modules.common.bios_smi"]
|
||||
|
||||
SKIPPED = ["chipsec.modules.common.smm",
|
||||
"chipsec.modules.common.secureboot.variables",
|
||||
"chipsec.modules.common.uefi.s3bootscript",
|
||||
"chipsec.modules.common.uefi.access_uefispec",
|
||||
"chipsec.modules.smm_dma",
|
||||
"chipsec.modules.remap",
|
||||
"chipsec.modules.module_template"]
|
||||
|
||||
def setUp(self):
|
||||
super(Z420UbuntuTest, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
super(Z420UbuntuTest, self).tearDown()
|
||||
|
||||
def test_main(self):
|
||||
self._generic_main()
|
||||
@@ -0,0 +1,23 @@
|
||||
from chipsec.helper import oshelper
|
||||
|
||||
class TestHelper(oshelper.Helper):
|
||||
|
||||
def __init__(self):
|
||||
self.os_system = "test_helper"
|
||||
self.os_release = "0"
|
||||
self.os_version = "0"
|
||||
self.os_machine = "test"
|
||||
self.driver_loaded = True
|
||||
|
||||
def create(self):
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
# This will be used to probe the device, fake a Broadwell CPU
|
||||
def read_pci_reg(self, bus, device, function, address, size):
|
||||
return 0x16008086
|
||||
@@ -0,0 +1,71 @@
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tests.software import mock_helper
|
||||
|
||||
import chipsec_util
|
||||
from chipsec import logger
|
||||
from chipsec import chipset
|
||||
from chipsec.helper import oshelper
|
||||
|
||||
class TestChipsec(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
fileno, self.log_file = tempfile.mkstemp()
|
||||
os.close(fileno)
|
||||
self.old_registry = oshelper.Helper.registry
|
||||
oshelper.Helper.registry = []
|
||||
oshelper._helper = None
|
||||
chipset._chipset = None
|
||||
|
||||
def tearDown(self):
|
||||
os.remove(self.log_file)
|
||||
oshelper._helper = None
|
||||
chipset._chipset = None
|
||||
chipsec_util._cs = None
|
||||
oshelper.Helper.registry = self.old_registry
|
||||
|
||||
def _chipsec_util(self, arg, helper_class=mock_helper.TestHelper):
|
||||
oshelper.Helper.registry = [(helper_class.__name__, helper_class)]
|
||||
chipsec_util._cs = chipset.cs()
|
||||
util = chipsec_util.ChipsecUtil()
|
||||
util.VERBOSE = True
|
||||
util.set_logfile(self.log_file)
|
||||
err_code = util.main(["chipsec_utils.py"] + arg.split())
|
||||
logger.logger().close()
|
||||
self.log = open(self.log_file).read()
|
||||
self.assertEqual(err_code, 0)
|
||||
|
||||
def test_platform(self):
|
||||
self._chipsec_util("platform")
|
||||
|
||||
def test_msr(self):
|
||||
|
||||
class MSRHelper(mock_helper.TestHelper):
|
||||
|
||||
def get_threads_count(self):
|
||||
return 1
|
||||
|
||||
def read_msr(self, thread_id, msr_addr):
|
||||
if msr_addr == 0x2FF:
|
||||
return [0x1234, 0xcdef]
|
||||
else:
|
||||
return [0x0, 0x0]
|
||||
|
||||
self._chipsec_util("msr 0x2FF", MSRHelper)
|
||||
self.assertIn("EAX=00001234, EDX=0000CDEF", self.log)
|
||||
|
||||
def test_gdt(self):
|
||||
|
||||
class GDTHelper(mock_helper.TestHelper):
|
||||
|
||||
def get_descriptor_table(self, cpu_thread_id, desc_table_code):
|
||||
return (63, 0x1000, 0x0)
|
||||
|
||||
def read_phys_mem(self, pa_hi, pa_lo, length):
|
||||
return "\xff" * length
|
||||
|
||||
self._chipsec_util("gdt 0", GDTHelper)
|
||||
self.assertIn("# of entries : 4", self.log)
|
||||
|
||||
Reference in New Issue
Block a user