70 Commits

Author SHA1 Message Date
Nathaniel Mitchell 39cf4bb620 Add UTs for ec_cmd and config_cmd
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2024-05-28 16:42:16 -07:00
Nathaniel Mitchell ed9c6e2896 Update how ACPI Tables are found
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2024-04-17 15:27:21 -07:00
Dan Scott 2a412e0cc0 Enumerate modules in modules folder using '-lm' 2024-03-28 13:49:05 -07:00
Sae86 4a7afd23cb Add unit testing for msr_cmd, mmcfg_cmd, mmcfg_base_cmd, desc_cmd and cpu_cmd
Signed-off-by: Sae86 <sara.batllori@intel.com>
2024-03-28 11:06:56 -07:00
Dan Scott 0e8192cfd0 Move files to library folder 2024-03-22 14:26:59 -07:00
Dan Scott a933b1337d Update references to functions in new library files 2024-03-22 14:26:59 -07:00
Sae86 6adf3dfae0 Add unit tests for acpi_cmd, chipset_cmd, cmos_cmd
Signed-off-by: Sae86 <sara.batllori@intel.com>
2023-12-11 13:35:11 -08:00
Nathaniel Mitchell 05805dd1f6 Set the logger.HAL flag to false for unit tests
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-12-11 10:46:46 -08:00
Nathaniel Mitchell bf69ab9391 Fix tgl debugenabled unit test replay
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-12-01 13:39:59 -08:00
Nathaniel Mitchell 0e44e6ae19 Remove mistakenly added log filters from tgl tests
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-11-20 16:37:42 -08:00
Nathaniel Mitchell f005fba0c6 Make sure DID/VID is printed when platform is unknown
And fixes unit tests

Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-11-13 16:36:49 -08:00
Nathaniel Mitchell a198b99b41 Add _logger.disable() to tests to reduce prints
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-11-09 16:17:50 -08:00
Sae86 c282cd9e2c Add tpm_cmd and txt_cmd unit testing
Signed-off-by: Sae86 <sara.batllori@intel.com>
2023-10-26 08:42:24 -07:00
Nathaniel Mitchell 4759db046f Add tgl tests for all modules
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-10-25 21:29:36 -07:00
Nathaniel Mitchell b1533ea07c Update strip_record to fix bug and update run_chipsec_module
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-10-25 16:34:37 -07:00
Nathaniel Mitchell a7df794272 Update sgx_check unit test and add script to shorten recordings
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-10-20 08:32:48 -07:00
Sae86 4a8057d904 Update remaining SKIPPED results and references
Signed-off-by: Sae86 <sara.batllori@intel.com>
2023-10-17 16:36:31 -07:00
Nathaniel Mitchell fbccec7756 Fix import and possible unbound errors
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-10-16 16:38:21 -07:00
Nathaniel Mitchell 6a23a6e968 Add initial windows helper unit tests
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-09-29 09:20:39 -07:00
Nathaniel Mitchell e3b4473bad Update assertRegexpMatch to assertRegex and base Helper to NoneHelper
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-08-21 16:36:12 -07:00
Nathaniel Mitchell 40413338a2 Update cfg_checker test to skip folders
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-08-18 01:16:48 -07:00
Nathaniel Mitchell 89f4be530f Update sgx_check and vbox_crash_apicbase
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-08-15 16:39:01 -07:00
Jason Zhou 1c74b78d41 Use better syntax remove close()
Signed-off-by: Jason Zhou <jun2.zhou@intel.com>
2023-08-07 16:37:50 -07:00
Jason Zhou dd5bd728b7 Fix helper record test
comparing test context by lines, ignore the Unix & window line ending difference.

Signed-off-by: Jason Zhou <jun2.zhou@intel.com>
2023-08-07 16:37:50 -07:00
Nathaniel Mitchell 483f9d99f6 Update unittests to match config parsing update
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-07-28 09:34:00 -07:00
Nathaniel Mitchell 435bf2ab06 Add cfg checking tests (non-unittest)
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-07-26 16:17:38 -07:00
Nathaniel Mitchell c3b27e7870 Add record and replay helpers
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-07-26 15:31:56 -07:00
Nathaniel Mitchell 27ee5eeb66 Clean up helper create/start/stop/delete functions
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-07-19 16:33:59 -07:00
jun2zhou e143924fdd Cpuinfo unittest (#1887)
* 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>
2023-07-11 16:37:29 -07:00
Nicolas Iooss f1dfa2dcdd Remove from_file from method start in base helper
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>
2023-07-10 16:42:07 -07:00
Jason Zhou 7f58472655 Fix test_pch_invalid() test failing on internal builds
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>
2023-07-10 16:41:29 -07:00
Nathaniel Mitchell ede85bfcbf Fix mocked module scoping issue in unittest
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-06-26 16:36:48 -07:00
Frinzell, Aaron 41ecf2cdb1 Implement basehelper.py as an ABC
Signed-off-by: Frinzell, Aaron <aaron.frinzell@intel.com>
2023-06-23 08:27:17 -07:00
Nathaniel Mitchell 2fbfb5fb89 Add initial set of linuxhelper unittests
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-06-21 16:41:46 -07:00
Nicolas Iooss a61dbc8d2b Make mocked function read_phys_mem return bytes
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>
2023-05-31 16:39:35 -07:00
Nathaniel Mitchell 745ae9084e Clean up HALs and Helpers
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-05-26 18:33:08 -07:00
Nathaniel Mitchell 0016b0c14c Clean up oshelper
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2023-05-26 18:32:51 -07:00
Frinzell, Aaron 54789d6f51 Add cpu.py unit tests
Signed-off-by: Frinzell, Aaron <aaron.frinzell@intel.com>
2023-05-24 16:37:35 -07:00
Zhou, Jun2 63b772344b Add a fake cpuid func to support invalid platform unit test
Signed-off-by: Zhou Jun, jun2.zhou@intel.com
2022-12-05 11:27:03 -08:00
Frinzell, Aaron fbde218dff Update tests for decoupling parse_arg()
Signed-off-by: Frinzell, Aaron <aaron.frinzell@intel.com>
2022-12-05 12:16:00 -06:00
Nathaniel Mitchell 291632c0ee Apply flake8 code formatting rules against repo
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2022-07-28 09:17:10 -07:00
brentholtsclaw 0e53326a83 Create exceptions.py for chipsec exceptions
Signed-off-by: brentholtsclaw <brent.holtsclaw@intel.com>
2021-08-26 10:50:51 -07:00
Nathaniel Mitchell c8c14e21be Remove shebang from all but the entry points. Update ep to py3
Signed-off-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
2021-08-12 08:27:33 -07:00
Nicolas Iooss 41ff0d4530 Configure GitHub Actions to test some features
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.
2021-05-18 20:07:47 -07:00
Nicolas Iooss a53c211f2f Generate 12-byte fake TPM event in EFIFirmwareBlob test
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.
2021-04-30 14:56:19 -07:00
Nicolas Iooss b4dd4ed572 Always close the temporary log file when a test fails
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.
2021-04-30 14:54:01 -07:00
brentholtsclaw 95bd9a4f0d Fix mock_helper for cs_exceptions
Signed-off-by: brentholtsclaw <brent.holtsclaw@intel.com>
2021-03-31 15:06:00 -07:00
brentholtsclaw 6cd7a3427e Add legacy support to unittest functions in test_generic
Signed-off-by: brentholtsclaw <brent.holtsclaw@intel.com>
2020-11-19 16:06:02 -08:00
Pedro Barbosa 2e1b81613c Implement cpuid method in mock_helper so we don't get NotImplementedError. 2020-10-29 22:26:45 +01:00
brentholtsclaw f7fe1be074 More whitespace cleanup
E231, E201, E226

Signed-off-by: brentholtsclaw <brent.holtsclaw@intel.com>
2020-07-31 13:46:13 -07:00