]> git.proxmox.com Git - mirror_edk2.git/blob - PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootServicesTableLibUnitTest.c
PrmPkg: Apply uncrustify changes
[mirror_edk2.git] / PrmPkg / Test / UnitTest / Library / UefiBootServicesTableLibUnitTest / UefiBootServicesTableLibUnitTest.c
1 /** @file
2 This library supports a Boot Services table library implementation that allows code dependent
3 upon UefiBootServicesTableLib to operate in an isolated execution environment such as within
4 the context of a host-based unit test framework.
5
6 The unit test should initialize the Boot Services database with any required elements
7 (e.g. protocols, events, handles, etc.) prior to the services being invoked by code under test.
8
9 It is strongly recommended to clean any global databases (e.g. protocol, event, handles, etc.) after
10 every unit test so the tests execute in a predictable manner from a clean state.
11
12 Copyright (c) Microsoft Corporation
13 SPDX-License-Identifier: BSD-2-Clause-Patent
14
15 **/
16
17 #include "UefiBootServicesTableLibUnitTest.h"
18
19 EFI_HANDLE gImageHandle = NULL;
20 EFI_SYSTEM_TABLE *gST = NULL;
21
22 STATIC EFI_BOOT_SERVICES mBootServices = {
23 {
24 EFI_BOOT_SERVICES_SIGNATURE, // Signature
25 EFI_BOOT_SERVICES_REVISION, // Revision
26 sizeof (EFI_BOOT_SERVICES), // HeaderSize
27 0, // CRC32
28 0 // Reserved
29 },
30 (EFI_RAISE_TPL)UnitTestRaiseTpl, // RaiseTPL
31 (EFI_RESTORE_TPL)UnitTestRestoreTpl, // RestoreTPL
32 (EFI_ALLOCATE_PAGES)UnitTestAllocatePages, // AllocatePages
33 (EFI_FREE_PAGES)UnitTestFreePages, // FreePages
34 (EFI_GET_MEMORY_MAP)UnitTestGetMemoryMap, // GetMemoryMap
35 (EFI_ALLOCATE_POOL)UnitTestAllocatePool, // AllocatePool
36 (EFI_FREE_POOL)UnitTestFreePool, // FreePool
37 (EFI_CREATE_EVENT)UnitTestCreateEvent, // CreateEvent
38 (EFI_SET_TIMER)UnitTestSetTimer, // SetTimer
39 (EFI_WAIT_FOR_EVENT)UnitTestWaitForEvent, // WaitForEvent
40 (EFI_SIGNAL_EVENT)UnitTestSignalEvent, // SignalEvent
41 (EFI_CLOSE_EVENT)UnitTestCloseEvent, // CloseEvent
42 (EFI_CHECK_EVENT)UnitTestCheckEvent, // CheckEvent
43 (EFI_INSTALL_PROTOCOL_INTERFACE)UnitTestInstallProtocolInterface, // InstallProtocolInterface
44 (EFI_REINSTALL_PROTOCOL_INTERFACE)UnitTestReinstallProtocolInterface, // ReinstallProtocolInterface
45 (EFI_UNINSTALL_PROTOCOL_INTERFACE)UnitTestUninstallProtocolInterface, // UninstallProtocolInterface
46 (EFI_HANDLE_PROTOCOL)UnitTestHandleProtocol, // HandleProtocol
47 (VOID *)NULL, // Reserved
48 (EFI_REGISTER_PROTOCOL_NOTIFY)UnitTestRegisterProtocolNotify, // RegisterProtocolNotify
49 (EFI_LOCATE_HANDLE)UnitTestLocateHandle, // LocateHandle
50 (EFI_LOCATE_DEVICE_PATH)UnitTestLocateDevicePath, // LocateDevicePath
51 (EFI_INSTALL_CONFIGURATION_TABLE)UnitTestInstallConfigurationTable, // InstallConfigurationTable
52 (EFI_IMAGE_LOAD)UnitTestLoadImage, // LoadImage
53 (EFI_IMAGE_START)UnitTestStartImage, // StartImage
54 (EFI_EXIT)UnitTestExit, // Exit
55 (EFI_IMAGE_UNLOAD)UnitTestUnloadImage, // UnloadImage
56 (EFI_EXIT_BOOT_SERVICES)UnitTestExitBootServices, // ExitBootServices
57 (EFI_GET_NEXT_MONOTONIC_COUNT)UnitTestGetNextMonotonicCount, // GetNextMonotonicCount
58 (EFI_STALL)UnitTestStall, // Stall
59 (EFI_SET_WATCHDOG_TIMER)UnitTestSetWatchdogTimer, // SetWatchdogTimer
60 (EFI_CONNECT_CONTROLLER)UnitTestConnectController, // ConnectController
61 (EFI_DISCONNECT_CONTROLLER)UnitTestDisconnectController, // DisconnectController
62 (EFI_OPEN_PROTOCOL)UnitTestOpenProtocol, // OpenProtocol
63 (EFI_CLOSE_PROTOCOL)UnitTestCloseProtocol, // CloseProtocol
64 (EFI_OPEN_PROTOCOL_INFORMATION)UnitTestOpenProtocolInformation, // OpenProtocolInformation
65 (EFI_PROTOCOLS_PER_HANDLE)UnitTestProtocolsPerHandle, // ProtocolsPerHandle
66 (EFI_LOCATE_HANDLE_BUFFER)UnitTestLocateHandleBuffer, // LocateHandleBuffer
67 (EFI_LOCATE_PROTOCOL)UnitTestLocateProtocol, // LocateProtocol
68 (EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)UnitTestInstallMultipleProtocolInterfaces, // InstallMultipleProtocolInterfaces
69 (EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)UnitTestUninstallMultipleProtocolInterfaces, // UninstallMultipleProtocolInterfaces
70 (EFI_CALCULATE_CRC32)UnitTestCalculateCrc32, // CalculateCrc32
71 (EFI_COPY_MEM)CopyMem, // CopyMem
72 (EFI_SET_MEM)SetMem, // SetMem
73 (EFI_CREATE_EVENT_EX)UnitTestCreateEventEx // CreateEventEx
74 };
75
76 EFI_BOOT_SERVICES *gBS = &mBootServices;
77
78 /**
79 The constructor function caches the pointer of Boot Services Table.
80
81 The constructor function caches the pointer of Boot Services Table through System Table.
82 It will ASSERT() if the pointer of System Table is NULL.
83 It will ASSERT() if the pointer of Boot Services Table is NULL.
84 It will always return EFI_SUCCESS.
85
86 @param ImageHandle The firmware allocated handle for the EFI image.
87 @param SystemTable A pointer to the EFI System Table.
88
89 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
90
91 **/
92 EFI_STATUS
93 EFIAPI
94 UefiBootServicesTableLibConstructor (
95 IN EFI_HANDLE ImageHandle,
96 IN EFI_SYSTEM_TABLE *SystemTable
97 )
98 {
99 //
100 // Cache the Image Handle
101 //
102 gImageHandle = ImageHandle;
103 ASSERT (gImageHandle != NULL);
104
105 //
106 // Cache pointer to the EFI System Table
107 //
108
109 // Note: The system table is not implemented
110 gST = NULL;
111
112 //
113 // Cache pointer to the EFI Boot Services Table
114 //
115 gBS = SystemTable->BootServices;
116 ASSERT (gBS != NULL);
117
118 return EFI_SUCCESS;
119 }