public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes
@ 2023-12-28 20:47 Jeff Brasen via groups.io
  2023-12-28 20:47 ` [edk2-devel] [PATCH v2 1/3] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool Jeff Brasen via groups.io
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jeff Brasen via groups.io @ 2023-12-28 20:47 UTC (permalink / raw)
  To: devel; +Cc: abner.chang, ardb+tianocore, quic_llindhol, Jeff Brasen

Adding Mock support for DtPlatformLoaderLib and changing ci.yaml to support this
Adding ReallocatePool support to PrePi Library.

Passing CI in https://github.com/tianocore/edk2/pull/5197

Change log
v2 -
  Fix uncrustify errors
  Fix ci allowed packages entries
  Fix cast on 32-bit systems

Jeff Brasen (3):
  EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
  EmbeddedPkg: Add host based dependency to ci
  EmbeddedPkg: Add DtPlatformLoaderLib gmock support

 EmbeddedPkg/EmbeddedPkg.dec                   |  1 +
 .../MockDtPlatformDtbLoaderLib.inf            | 29 ++++++++++
 .../Library/MockDtPlatformDtbLoaderLib.h      | 31 ++++++++++
 .../MemoryAllocationLib.c                     | 57 +++++++++++++++++++
 EmbeddedPkg/EmbeddedPkg.ci.yaml               |  4 +-
 .../MockDtPlatformDtbLoaderLib.cpp            | 13 +++++
 6 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.inf
 create mode 100644 EmbeddedPkg/Test/Mock/Include/GoogleTest/Library/MockDtPlatformDtbLoaderLib.h
 create mode 100644 EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.cpp

-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112989): https://edk2.groups.io/g/devel/message/112989
Mute This Topic: https://groups.io/mt/103407482/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [edk2-devel] [PATCH v2 1/3] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
  2023-12-28 20:47 [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes Jeff Brasen via groups.io
@ 2023-12-28 20:47 ` Jeff Brasen via groups.io
  2023-12-28 20:47 ` [edk2-devel] [PATCH v2 2/3] EmbeddedPkg: Add host based dependency to ci Jeff Brasen via groups.io
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jeff Brasen via groups.io @ 2023-12-28 20:47 UTC (permalink / raw)
  To: devel; +Cc: abner.chang, ardb+tianocore, quic_llindhol, Jeff Brasen

Add implementation of ReallocatePool which is defined in the
MemoryAllocationLib header file to allow components to not
need special handling for PrePi module types.

Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
---
 .../MemoryAllocationLib.c                     | 57 +++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
index 08a0add340cf..fa81cc9d595a 100644
--- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
@@ -269,3 +269,60 @@ FreePool (
 {
   // Not implemented yet
 }
+
+/**
+  Reallocates a buffer of type EfiBootServicesData.
+
+  Allocates and zeros the number bytes specified by NewSize from memory of type
+  EfiBootServicesData.  If OldBuffer is not NULL, then the smaller of OldSize and
+  NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
+  OldBuffer is freed.  A pointer to the newly allocated buffer is returned.
+  If NewSize is 0, then a valid buffer of 0 size is  returned.  If there is not
+  enough memory remaining to satisfy the request, then NULL is returned.
+
+  If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
+  is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
+
+  @param  OldSize        The size, in bytes, of OldBuffer.
+  @param  NewSize        The size, in bytes, of the buffer to reallocate.
+  @param  OldBuffer      The buffer to copy to the allocated buffer.  This is an optional
+                         parameter that may be NULL.
+
+  @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+ReallocatePool (
+  IN UINTN  OldSize,
+  IN UINTN  NewSize,
+  IN VOID   *OldBuffer  OPTIONAL
+  )
+{
+  VOID  *NewBuffer;
+
+  // Validate the OldBuffer is HobAllocated.
+  DEBUG_CODE_BEGIN ();
+  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHob;
+
+  if (OldBuffer != NULL) {
+    HandOffHob = GetHobList ();
+    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom));
+    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
+  }
+
+  DEBUG_CODE_END ();
+
+  // If new buffer would be smaller just return old buffer as FreePool isn't supported.
+  if ((OldBuffer != NULL) && (OldSize >= NewSize)) {
+    return OldBuffer;
+  }
+
+  NewBuffer = AllocateZeroPool (NewSize);
+  if ((NewBuffer != NULL) && (OldBuffer != NULL)) {
+    CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
+    FreePool (OldBuffer);
+  }
+
+  return NewBuffer;
+}
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112991): https://edk2.groups.io/g/devel/message/112991
Mute This Topic: https://groups.io/mt/103407484/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [edk2-devel] [PATCH v2 2/3] EmbeddedPkg: Add host based dependency to ci
  2023-12-28 20:47 [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes Jeff Brasen via groups.io
  2023-12-28 20:47 ` [edk2-devel] [PATCH v2 1/3] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool Jeff Brasen via groups.io
@ 2023-12-28 20:47 ` Jeff Brasen via groups.io
  2023-12-28 20:47 ` [edk2-devel] [PATCH v2 3/3] EmbeddedPkg: Add DtPlatformLoaderLib gmock support Jeff Brasen via groups.io
  2024-01-03 13:43 ` [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes Ard Biesheuvel
  3 siblings, 0 replies; 5+ messages in thread
From: Jeff Brasen via groups.io @ 2023-12-28 20:47 UTC (permalink / raw)
  To: devel; +Cc: abner.chang, ardb+tianocore, quic_llindhol, Jeff Brasen

Add UnitTestFrameworkPkg to AcceptableDependencies-HOST_APPLICATION list

Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
---
 EmbeddedPkg/EmbeddedPkg.ci.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/EmbeddedPkg/EmbeddedPkg.ci.yaml b/EmbeddedPkg/EmbeddedPkg.ci.yaml
index 96a60a6f8b4d..6d042fc721ab 100644
--- a/EmbeddedPkg/EmbeddedPkg.ci.yaml
+++ b/EmbeddedPkg/EmbeddedPkg.ci.yaml
@@ -50,7 +50,9 @@
             "MdePkg/MdePkg.dec"
         ],
         # For host based unit tests
-        "AcceptableDependencies-HOST_APPLICATION":[],
+        "AcceptableDependencies-HOST_APPLICATION":[
+            "UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec"
+        ],
         # For UEFI shell based apps
         "AcceptableDependencies-UEFI_APPLICATION":[],
         "IgnoreInf": []
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112990): https://edk2.groups.io/g/devel/message/112990
Mute This Topic: https://groups.io/mt/103407483/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [edk2-devel] [PATCH v2 3/3] EmbeddedPkg: Add DtPlatformLoaderLib gmock support
  2023-12-28 20:47 [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes Jeff Brasen via groups.io
  2023-12-28 20:47 ` [edk2-devel] [PATCH v2 1/3] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool Jeff Brasen via groups.io
  2023-12-28 20:47 ` [edk2-devel] [PATCH v2 2/3] EmbeddedPkg: Add host based dependency to ci Jeff Brasen via groups.io
@ 2023-12-28 20:47 ` Jeff Brasen via groups.io
  2024-01-03 13:43 ` [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes Ard Biesheuvel
  3 siblings, 0 replies; 5+ messages in thread
From: Jeff Brasen via groups.io @ 2023-12-28 20:47 UTC (permalink / raw)
  To: devel; +Cc: abner.chang, ardb+tianocore, quic_llindhol, Jeff Brasen

Add Google Mock Library for DtPlatformLoaderDtbLib

Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
---
 EmbeddedPkg/EmbeddedPkg.dec                   |  1 +
 .../MockDtPlatformDtbLoaderLib.inf            | 29 +++++++++++++++++
 .../Library/MockDtPlatformDtbLoaderLib.h      | 31 +++++++++++++++++++
 .../MockDtPlatformDtbLoaderLib.cpp            | 13 ++++++++
 4 files changed, 74 insertions(+)
 create mode 100644 EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.inf
 create mode 100644 EmbeddedPkg/Test/Mock/Include/GoogleTest/Library/MockDtPlatformDtbLoaderLib.h
 create mode 100644 EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.cpp

diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec
index 94dc3c9b76ca..b4834e8b4f88 100644
--- a/EmbeddedPkg/EmbeddedPkg.dec
+++ b/EmbeddedPkg/EmbeddedPkg.dec
@@ -28,6 +28,7 @@ [Defines]
 ################################################################################
 [Includes.common]
   Include                        # Root include for the package
+  Test/Mock/Include
 
 [LibraryClasses.common]
   PrePiLib|Include/Library/PrePiLib.h
diff --git a/EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.inf b/EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.inf
new file mode 100644
index 000000000000..9618efd86470
--- /dev/null
+++ b/EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.inf
@@ -0,0 +1,29 @@
+## @file
+# Google Test mocks for MockDtPlatformDtbLoaderLib
+#
+# Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = MockDtPlatformDtbLoaderLib
+  FILE_GUID                      = 34c05e81-3c56-4c78-b4b7-a39be19163a4
+  MODULE_TYPE                    = HOST_APPLICATION
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = DtPlatformDtbLoaderLib
+
+[Sources]
+MockDtPlatformDtbLoaderLib.cpp
+
+[Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdePkg/MdePkg.dec
+  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+  GoogleTestLib
+
+[BuildOptions]
+  MSFT:*_*_*_CC_FLAGS = /EHsc
diff --git a/EmbeddedPkg/Test/Mock/Include/GoogleTest/Library/MockDtPlatformDtbLoaderLib.h b/EmbeddedPkg/Test/Mock/Include/GoogleTest/Library/MockDtPlatformDtbLoaderLib.h
new file mode 100644
index 000000000000..ce0fca2c3293
--- /dev/null
+++ b/EmbeddedPkg/Test/Mock/Include/GoogleTest/Library/MockDtPlatformDtbLoaderLib.h
@@ -0,0 +1,31 @@
+/** @file
+  Google Test mocks for DtPlatformDtbLoaderLib
+
+  Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (c) 2023, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_DT_PLATFORM_DTB_LOADER_LIB_H_
+#define MOCK_DT_PLATFORM_DTB_LOADER_LIB_H_
+
+#include <Library/GoogleTestLib.h>
+#include <Library/FunctionMockLib.h>
+extern "C" {
+  #include <Pi/PiMultiPhase.h>
+  #include <Uefi.h>
+  #include <Library/DtPlatformDtbLoaderLib.h>
+}
+
+struct MockDtPlatformDtbLoaderLib {
+  MOCK_INTERFACE_DECLARATION (MockDtPlatformDtbLoaderLib);
+
+  MOCK_FUNCTION_DECLARATION (
+    EFI_STATUS,
+    DtPlatformLoadDtb,
+    (OUT   VOID   **Dtb,
+     OUT   UINTN  *DtbSize)
+    );
+};
+
+#endif
diff --git a/EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.cpp b/EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.cpp
new file mode 100644
index 000000000000..a5db68e59a09
--- /dev/null
+++ b/EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.cpp
@@ -0,0 +1,13 @@
+/** @file
+  Google Test mocks for MockDtPlatformDtbLoaderLib
+
+  Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (c) 2023, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <GoogleTest/Library/MockDtPlatformDtbLoaderLib.h>
+
+MOCK_INTERFACE_DEFINITION (MockDtPlatformDtbLoaderLib);
+
+MOCK_FUNCTION_DEFINITION (MockDtPlatformDtbLoaderLib, DtPlatformLoadDtb, 2, EFIAPI);
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112992): https://edk2.groups.io/g/devel/message/112992
Mute This Topic: https://groups.io/mt/103407486/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes
  2023-12-28 20:47 [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes Jeff Brasen via groups.io
                   ` (2 preceding siblings ...)
  2023-12-28 20:47 ` [edk2-devel] [PATCH v2 3/3] EmbeddedPkg: Add DtPlatformLoaderLib gmock support Jeff Brasen via groups.io
@ 2024-01-03 13:43 ` Ard Biesheuvel
  3 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2024-01-03 13:43 UTC (permalink / raw)
  To: Jeff Brasen; +Cc: devel, abner.chang, ardb+tianocore, quic_llindhol

On Thu, 28 Dec 2023 at 21:47, Jeff Brasen <jbrasen@nvidia.com> wrote:
>
> Adding Mock support for DtPlatformLoaderLib and changing ci.yaml to support this
> Adding ReallocatePool support to PrePi Library.
>
> Passing CI in https://github.com/tianocore/edk2/pull/5197
>
> Change log
> v2 -
>   Fix uncrustify errors
>   Fix ci allowed packages entries
>   Fix cast on 32-bit systems
>
> Jeff Brasen (3):
>   EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool
>   EmbeddedPkg: Add host based dependency to ci
>   EmbeddedPkg: Add DtPlatformLoaderLib gmock support
>

Merged as #5184

Thanks.

>  EmbeddedPkg/EmbeddedPkg.dec                   |  1 +
>  .../MockDtPlatformDtbLoaderLib.inf            | 29 ++++++++++
>  .../Library/MockDtPlatformDtbLoaderLib.h      | 31 ++++++++++
>  .../MemoryAllocationLib.c                     | 57 +++++++++++++++++++
>  EmbeddedPkg/EmbeddedPkg.ci.yaml               |  4 +-
>  .../MockDtPlatformDtbLoaderLib.cpp            | 13 +++++
>  6 files changed, 134 insertions(+), 1 deletion(-)
>  create mode 100644 EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.inf
>  create mode 100644 EmbeddedPkg/Test/Mock/Include/GoogleTest/Library/MockDtPlatformDtbLoaderLib.h
>  create mode 100644 EmbeddedPkg/Test/Mock/Library/GoogleTest/MockDtPlatformDtbLoaderLib/MockDtPlatformDtbLoaderLib.cpp
>
> --
> 2.34.1
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113091): https://edk2.groups.io/g/devel/message/113091
Mute This Topic: https://groups.io/mt/103407482/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-03 13:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-28 20:47 [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes Jeff Brasen via groups.io
2023-12-28 20:47 ` [edk2-devel] [PATCH v2 1/3] EmbeddedPkg/PrePiMemoryAllocationLib: Add ReallocatePool Jeff Brasen via groups.io
2023-12-28 20:47 ` [edk2-devel] [PATCH v2 2/3] EmbeddedPkg: Add host based dependency to ci Jeff Brasen via groups.io
2023-12-28 20:47 ` [edk2-devel] [PATCH v2 3/3] EmbeddedPkg: Add DtPlatformLoaderLib gmock support Jeff Brasen via groups.io
2024-01-03 13:43 ` [edk2-devel] [PATCH v2 0/3] EmbeddedPkg ReallocatePool and Mock changes Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox