diff options
| author | Peter Jones <pjones@redhat.com> | 2021-08-03 11:15:29 -0400 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2021-09-07 17:05:04 -0400 |
| commit | 5ed27307d4854e67cf999fd7785b48f5cf488a51 (patch) | |
| tree | c223f1ea3b8cc6df1f03aff789d5476d03d6ac56 | |
| parent | 1368d9ac37b985454ff1b9a28f9a46b82b5eba9b (diff) | |
| download | efi-boot-shim-5ed27307d4854e67cf999fd7785b48f5cf488a51.tar.gz efi-boot-shim-5ed27307d4854e67cf999fd7785b48f5cf488a51.zip | |
tests: add some slightly better EFIAPI error mocks
This adds more mock functions that just return various EFI error codes
in the EFIAPI ABI.
Signed-off-by: Peter Jones <pjones@redhat.com>
| -rw-r--r-- | include/test.h | 6 | ||||
| -rw-r--r-- | test.c | 151 |
2 files changed, 145 insertions, 12 deletions
diff --git a/include/test.h b/include/test.h index f6b0e929..fcaa1cdf 100644 --- a/include/test.h +++ b/include/test.h @@ -304,6 +304,12 @@ extern int debug; #define dprint(fmt, ...) {( if (debug) printf("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); }) #endif +void EFIAPI mock_efi_void(); +EFI_STATUS EFIAPI mock_efi_success(); +EFI_STATUS EFIAPI mock_efi_unsupported(); +EFI_STATUS EFIAPI mock_efi_not_found(); +void init_efi_system_table(void); +void reset_efi_system_table(void); void print_traceback(int skip); #define eassert(cond, fmt, ...) \ @@ -4,9 +4,6 @@ * Copyright Peter Jones <pjones@redhat.com> */ -#ifndef SHIM_UNIT_TEST -#define SHIM_UNIT_TEST -#endif #include "shim.h" #include <execinfo.h> @@ -87,32 +84,162 @@ mock_efi_free_pool(void *buf) return EFI_SUCCESS; } -EFI_BOOT_SERVICES mock_bs = { - .RaiseTPL = NULL, - .RestoreTPL = NULL, +void EFIAPI +mock_efi_void() +{ + ; +} + +EFI_STATUS EFIAPI +mock_efi_success() +{ + return EFI_SUCCESS; +} + +EFI_STATUS EFIAPI +mock_efi_unsupported() +{ + return EFI_UNSUPPORTED; +} + +EFI_STATUS EFIAPI +mock_efi_not_found() +{ + return EFI_NOT_FOUND; +} + +EFI_BOOT_SERVICES mock_bs, mock_default_bs = { + .Hdr = { + .Signature = EFI_BOOT_SERVICES_SIGNATURE, + .Revision = EFI_1_10_BOOT_SERVICES_REVISION, + .HeaderSize = offsetof(EFI_BOOT_SERVICES, SetMem) + + sizeof(mock_bs.SetMem), + }, + + .RaiseTPL = mock_efi_unsupported, + .RestoreTPL = mock_efi_void, .AllocatePages = mock_efi_allocate_pages, .FreePages = mock_efi_free_pages, + .GetMemoryMap = mock_efi_unsupported, .AllocatePool = mock_efi_allocate_pool, .FreePool = mock_efi_free_pool, + + .CreateEvent = mock_efi_unsupported, + .SetTimer = mock_efi_unsupported, + .WaitForEvent = mock_efi_unsupported, + .SignalEvent = mock_efi_unsupported, + .CloseEvent = mock_efi_unsupported, + .CheckEvent = mock_efi_unsupported, + + .InstallProtocolInterface = mock_efi_unsupported, + .ReinstallProtocolInterface = mock_efi_unsupported, + .UninstallProtocolInterface = mock_efi_unsupported, + .HandleProtocol = mock_efi_unsupported, +#if 0 + /* + * EFI 1.10 has a "Reserved" field here that's not in later + * revisions. + * + * I don't think it's in any actual *firmware* either. + */ + .Reserved = NULL, +#endif + .RegisterProtocolNotify = mock_efi_unsupported, + .LocateHandle = mock_efi_not_found, + .LocateDevicePath = mock_efi_unsupported, + .InstallConfigurationTable = mock_efi_unsupported, + + .LoadImage = (void *)mock_efi_unsupported, + .StartImage = mock_efi_unsupported, + .Exit = mock_efi_unsupported, + .UnloadImage = mock_efi_unsupported, + .ExitBootServices = mock_efi_unsupported, + + .GetNextMonotonicCount = mock_efi_unsupported, + .Stall = mock_efi_unsupported, + .SetWatchdogTimer = mock_efi_unsupported, + + .ConnectController = (void *)mock_efi_unsupported, + .DisconnectController = mock_efi_unsupported, + + .OpenProtocol = mock_efi_unsupported, + .CloseProtocol = mock_efi_unsupported, + .OpenProtocolInformation = mock_efi_unsupported, + + .ProtocolsPerHandle = mock_efi_unsupported, + .LocateHandleBuffer = mock_efi_unsupported, + .LocateProtocol = mock_efi_unsupported, + + .InstallMultipleProtocolInterfaces = (void *)mock_efi_unsupported, + .UninstallMultipleProtocolInterfaces = (void *)mock_efi_unsupported, + + .CalculateCrc32 = mock_efi_unsupported, + + .CopyMem = NULL, + .SetMem = NULL, + .CreateEventEx = mock_efi_unsupported, }; -EFI_RUNTIME_SERVICES mock_rt = { - .Hdr = { 0, }, - .GetVariable = NULL, +EFI_RUNTIME_SERVICES mock_rt, mock_default_rt = { + .Hdr = { + .Signature = EFI_RUNTIME_SERVICES_SIGNATURE, + .Revision = EFI_1_10_RUNTIME_SERVICES_REVISION, + .HeaderSize = offsetof(EFI_RUNTIME_SERVICES, ResetSystem) + + sizeof(mock_rt.ResetSystem), + }, + + .GetTime = mock_efi_unsupported, + .SetTime = mock_efi_unsupported, + .GetWakeupTime = mock_efi_unsupported, + .SetWakeupTime = (void *)mock_efi_unsupported, + + .SetVirtualAddressMap = mock_efi_unsupported, + .ConvertPointer = mock_efi_unsupported, + + .GetVariable = mock_efi_unsupported, + .SetVariable = mock_efi_unsupported, + .GetNextVariableName = mock_efi_unsupported, + + .GetNextHighMonotonicCount = mock_efi_unsupported, + .ResetSystem = mock_efi_unsupported, + + .UpdateCapsule = mock_efi_unsupported, + .QueryCapsuleCapabilities = mock_efi_unsupported, + + .QueryVariableInfo = mock_efi_unsupported, }; -EFI_SYSTEM_TABLE mock_st = { - .Hdr = { 0, }, +EFI_SYSTEM_TABLE mock_st, mock_default_st = { + .Hdr = { + .Signature = EFI_SYSTEM_TABLE_SIGNATURE, + .Revision = EFI_1_10_SYSTEM_TABLE_REVISION, + .HeaderSize = sizeof(EFI_SYSTEM_TABLE), + }, .BootServices = &mock_bs, .RuntimeServices = &mock_rt, }; -void CONSTRUCTOR init_efi_system_table(void) +void CONSTRUCTOR +init_efi_system_table(void) +{ + static bool once = true; + if (once) { + once = false; + reset_efi_system_table(); + } +} + +void +reset_efi_system_table(void) { ST = &mock_st; BS = &mock_bs; RT = &mock_rt; + + memcpy(&mock_bs, &mock_default_bs, sizeof(mock_bs)); + memcpy(&mock_rt, &mock_default_rt, sizeof(mock_rt)); + memcpy(&mock_st, &mock_default_st, sizeof(mock_st)); } EFI_STATUS EFIAPI |
