Currently `test_tpm_eventlog_firmware_blob` generates a TPM event with
16 bytes (`struct.pack("QQ",...)`) to check the decoding of
`EFIFirmwareBlob`. But the code expects a "native unsigned long", as
documented in `chipsec/hal/tpm_eventlog.py`:
class EFIFirmwareBlob(TcgPcrEvent):
# Although [4] 9.2.5 mentions UNIT64 for the length, [1] 7.7 uses
# a UINTN. Use a native unsigned long to cover the most general case.
_event_fmt = "@QL"
On Windows, the size of `unsigned long` is 32 bits, and the test fails:
File "d:\a\chipsec\chipsec\chipsec\hal\tpm_eventlog.py", line 115, in __init__
base, length = struct.unpack(self._event_fmt, self.event)
struct.error: unpack requires a buffer of 12 bytes
Use `"QL"` in the test in order to fix this test on Windows.
When running "python setup.py test" on Windows, the following failure is
reported:
======================================================================
ERROR: test_platform_invalid (tests.software.test_cs.TestPlatformChipsecCs)
----------------------------------------------------------------------
Traceback (most recent call last):
File "d:\a\chipsec\chipsec\tests\software\cs.py", line 46, in tearDown
os.remove(self.log_file)
PermissionError: [WinError 32] The process cannot access the file
because it is being used by another process:
'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpg5_6bcaz'
This is because when `_cs.init()` (in `tests/software/cs.py`) throws an
exception, the temporary log file is not closed. Then the function
`TestChipsecUtil.tearDown` attempts to remove the temporary file with
`os.remove(self.log_file)` and it fails, as it is still used by the
logger.
Fix this by putting `_cs.init()` inside a `try`/`finally` construction
which always calls `logger.logger().close()` when an exception happens.
While at it, use `with open(...) as log` instead of `log.open()` +
`log.close()`, which is a more usual way of reading files in Python.
Updated mock_helper to use BaseHelper
Updated util harness to correctly override helper with testhelper
Signed-off-by: BrentHoltsclaw <brent.holtsclaw@intel.com>
* Updated util_cmds starting within d to use argparse
* Add get_thread_count to unittest mock_helper to fix unit_test error
Signed-off-by: BrentHoltsclaw <brent.holtsclaw@intel.com>
* More operation in chipsec_util reg command
Added write, read_field, write_field, get_control, set_control
operations
* reg read util command updated
Returned back "chipsec_util reg read" syntax and added tests.
* Commented out test_reg_get_control
Need to implement get_MMIO_BAR_base_address or read_pci_reg for SPIBAR
in mock_helper.py