* Add test cpu info unittest cases
Signed-off-by: Jason Zhou <jun2.zhou@intel.com>
* Add __init__.py to this folder to be picked up by cmd "py setup.py test"
Signed-off-by: Jason Zhou <jun2.zhou@intel.com>
* Remove unused import
Signed-off-by: Jason Zhou <jun2.zhou@intel.com>
---------
Signed-off-by: Jason Zhou <jun2.zhou@intel.com>
Commit 99f9052438 ("Remove filehelper") removed `from_file` and
`to_file` from `OsHelper` but it remained in `BaseHelper`. Remove these
parameters too.
While at it, remove the similar parameters from the mock helper used in
tests.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
the test invalid pch mock helper returned fake pch id, but valid plat id,
if plat id matched xml file defined reqs_pch=true, will cause exception,
the mocked plat id corresponding xml is reqs_pch=true.
Signed-off-by: Jason Zhou <jun2.zhou@intel.com>
In tests, `read_phys_mem` could return strings instead of bytes, which
prevents detecting issues with `chipsec_util.py gdt` and
`chipsec_util.py idt`.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
Introduce some configuration for GitHub Action jobs which:
* Build chipsec's Linux kernel module for several Linux distributions
(using Docker containers).
* Build chipsec's Windows kernel driver (using the Visual Studio
installation provided in Windows images of GitHub Actions) and run
`python setup.py install` on Windows.
* Install chipsec in some Ubuntu virtual machines and run
`python setup.py install` and `chipsec_main`.
For now, only x86_64 architecture is tested.
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.