public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: "Liu, Zhiguang" <zhiguang.liu@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>,
	Michael Kubacki <mikuback@linux.microsoft.com>,
	"Sean Brogan" <sean.brogan@microsoft.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>
Cc: "Ni, Ray" <ray.ni@intel.com>
Subject: Re: [edk2-devel] [PATCH] UnitTestFrameworkPkg: Modify APIs in UnitTestPersistenceLib
Date: Tue, 13 Dec 2022 23:56:29 +0000	[thread overview]
Message-ID: <CO1PR11MB492987F256E5A01E32A50FF8D2E39@CO1PR11MB4929.namprd11.prod.outlook.com> (raw)
In-Reply-To: <PH0PR11MB5048EBC6F33C9636F221F85290E29@PH0PR11MB5048.namprd11.prod.outlook.com>

Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>

Mike

> -----Original Message-----
> From: Liu, Zhiguang <zhiguang.liu@intel.com>
> Sent: Sunday, December 11, 2022 11:33 PM
> To: devel@edk2.groups.io; Liu, Zhiguang <zhiguang.liu@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Michael
> Kubacki <mikuback@linux.microsoft.com>; Sean Brogan <sean.brogan@microsoft.com>
> Cc: Ni, Ray <ray.ni@intel.com>
> Subject: RE: [edk2-devel] [PATCH] UnitTestFrameworkPkg: Modify APIs in UnitTestPersistenceLib
> 
> Hi UnitTestFrameworkPkg Maintainers and reviewers,
> 
> Could you help review this patch?
> 
> Thanks
> Zhiguang
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> > Zhiguang Liu
> > Sent: Tuesday, December 6, 2022 1:26 PM
> > To: devel@edk2.groups.io
> > Cc: Liu, Zhiguang <zhiguang.liu@intel.com>; Kinney, Michael D
> > <michael.d.kinney@intel.com>; Michael Kubacki
> > <mikuback@linux.microsoft.com>; Sean Brogan
> > <sean.brogan@microsoft.com>; Ni, Ray <ray.ni@intel.com>
> > Subject: [edk2-devel] [PATCH] UnitTestFrameworkPkg: Modify APIs in
> > UnitTestPersistenceLib
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4183
> >
> > UnitTestPersistenceLib now consumes private struct definition.
> > Modify APIs in UnitTestPersistenceLib to make it easy to become a public
> > library.
> >
> > Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > Cc: Michael Kubacki <mikuback@linux.microsoft.com>
> > Cc: Sean Brogan <sean.brogan@microsoft.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
> > ---
> >  .../Include/Library/UnitTestPersistenceLib.h  | 14 +++++++----
> >  .../Library/UnitTestLib/UnitTestLib.c         |  6 +++--
> >  .../UnitTestPersistenceLibNull.c              | 11 ++++++---
> >  .../UnitTestPersistenceLibSimpleFileSystem.c  | 23 ++++++++++++-------
> >  4 files changed, 36 insertions(+), 18 deletions(-)
> >
> > diff --git a/UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h
> > b/UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h
> > index be29e079ec..5543b79a0d 100644
> > --- a/UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h
> > +++ b/UnitTestFrameworkPkg/Include/Library/UnitTestPersistenceLib.h
> > @@ -4,7 +4,7 @@
> >    (eg. a reboot-based test).
> >
> >    Copyright (c) Microsoft Corporation.<BR>
> > -  Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
> > +  Copyright (c) 2019 - 2022, Intel Corporation. All rights
> > + reserved.<BR>
> >    SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> >  **/
> > @@ -12,7 +12,7 @@
> >  #ifndef _UNIT_TEST_PERSISTENCE_LIB_H_
> >  #define _UNIT_TEST_PERSISTENCE_LIB_H_
> >
> > -#include <UnitTestFrameworkTypes.h>
> > +#include <Library/UnitTestLib.h>
> >
> >  #define UNIT_TEST_PERSISTENCE_LIB_VERSION  1
> >
> > @@ -40,6 +40,7 @@ DoesCacheExist (
> >    @param[in]  FrameworkHandle   A pointer to the framework that is being
> > persisted.
> >    @param[in]  SaveData          A pointer to the buffer containing the serialized
> >                                  framework internal state.
> > +  @param[in]  SaveStateSize     The size of SaveData in bytes.
> >
> >    @retval     EFI_SUCCESS   Data is persisted and the test can be safely quit.
> >    @retval     Others        Data is not persisted and test cannot be resumed
> > upon exit.
> > @@ -49,7 +50,8 @@ EFI_STATUS
> >  EFIAPI
> >  SaveUnitTestCache (
> >    IN UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle,
> > -  IN UNIT_TEST_SAVE_HEADER       *SaveData
> > +  IN VOID                        *SaveData,
> > +  IN UINTN                       SaveStateSize
> >    );
> >
> >  /**
> > @@ -57,8 +59,9 @@ SaveUnitTestCache (
> >    Will allocate a buffer to hold the loaded data.
> >
> >    @param[in]  FrameworkHandle   A pointer to the framework that is being
> > persisted.
> > -  @param[in]  SaveData          A pointer pointer that will be updated with the
> > address
> > +  @param[out] SaveData          A pointer pointer that will be updated with
> > the address
> >                                  of the loaded data buffer.
> > +  @param[out] SaveStateSize     Return the size of SaveData in bytes.
> >
> >    @retval     EFI_SUCCESS       Data has been loaded successfully and SaveData
> > is updated
> >                                  with a pointer to the buffer.
> > @@ -70,7 +73,8 @@ EFI_STATUS
> >  EFIAPI
> >  LoadUnitTestCache (
> >    IN  UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle,
> > -  OUT UNIT_TEST_SAVE_HEADER       **SaveData
> > +  OUT VOID                        **SaveData,
> > +  OUT UINTN                       *SaveStateSize
> >    );
> >
> >  #endif
> > diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
> > b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
> > index 64d5880783..5b442ed122 100644
> > --- a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
> > +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
> > @@ -2,6 +2,7 @@
> >    Implement UnitTestLib
> >
> >    Copyright (c) Microsoft Corporation.
> > +  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
> >    SPDX-License-Identifier: BSD-2-Clause-Patent  **/
> >
> > @@ -210,6 +211,7 @@ InitUnitTestFramework (
> >    EFI_STATUS                  Status;
> >    UNIT_TEST_FRAMEWORK_HANDLE  NewFrameworkHandle;
> >    UNIT_TEST_FRAMEWORK         *NewFramework;
> > +  UINTN                       SaveStateSize;
> >
> >    Status       = EFI_SUCCESS;
> >    NewFramework = NULL;
> > @@ -267,7 +269,7 @@ InitUnitTestFramework (
> >    // If there is a persisted context, load it now.
> >    //
> >    if (DoesCacheExist (NewFrameworkHandle)) {
> > -    Status = LoadUnitTestCache (NewFrameworkHandle,
> > (UNIT_TEST_SAVE_HEADER **)(&NewFramework->SavedState));
> > +    Status = LoadUnitTestCache (NewFrameworkHandle, (VOID
> > + **)(&NewFramework->SavedState), &SaveStateSize);
> >      if (EFI_ERROR (Status)) {
> >        //
> >        // Don't actually report it as an error, but emit a warning.
> > @@ -852,7 +854,7 @@ SaveFrameworkState (
> >    //
> >    // All that should be left to do is save it using the associated persistence lib.
> >    //
> > -  Status = SaveUnitTestCache (FrameworkHandle, Header);
> > +  Status = SaveUnitTestCache (FrameworkHandle, Header,
> > + Header->SaveStateSize);
> >    if (EFI_ERROR (Status)) {
> >      DEBUG ((DEBUG_ERROR, "%a - Could not save state! %r\n",
> > __FUNCTION__, Status));
> >      Status = EFI_DEVICE_ERROR;
> > diff --git
> > a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersis
> > tenceLibNull.c
> > b/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersis
> > tenceLibNull.c
> > index e28327652e..abb24cff98 100644
> > ---
> > a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersis
> > tenceLibNull.c
> > +++
> > b/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPe
> > +++ rsistenceLibNull.c
> > @@ -2,6 +2,7 @@
> >    This is an instance of the Unit Test Persistence Lib that does nothing.
> >
> >    Copyright (c) Microsoft Corporation.<BR>
> > +  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
> >    SPDX-License-Identifier: BSD-2-Clause-Patent  **/
> >
> > @@ -35,6 +36,7 @@ DoesCacheExist (
> >    @param[in]  FrameworkHandle  A pointer to the framework that is being
> > persisted.
> >    @param[in]  SaveData         A pointer to the buffer containing the serialized
> >                                 framework internal state.
> > +  @param[in]  SaveStateSize    The size of SaveData in bytes.
> >
> >    @retval  EFI_SUCCESS  Data is persisted and the test can be safely quit.
> >    @retval  Others       Data is not persisted and test cannot be resumed upon
> > exit.
> > @@ -44,7 +46,8 @@ EFI_STATUS
> >  EFIAPI
> >  SaveUnitTestCache (
> >    IN UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle,
> > -  IN UNIT_TEST_SAVE_HEADER       *SaveData
> > +  IN VOID                        *SaveData,
> > +  IN UINTN                       SaveStateSize
> >    )
> >  {
> >    return EFI_UNSUPPORTED;
> > @@ -55,8 +58,9 @@ SaveUnitTestCache (
> >    Will allocate a buffer to hold the loaded data.
> >
> >    @param[in]  FrameworkHandle  A pointer to the framework that is being
> > persisted.
> > -  @param[in]  SaveData         A pointer pointer that will be updated with the
> > address
> > +  @param[out] SaveData         A pointer pointer that will be updated with the
> > address
> >                                 of the loaded data buffer.
> > +  @param[out] SaveStateSize    Return the size of SaveData in bytes.
> >
> >    @retval  EFI_SUCCESS  Data has been loaded successfully and SaveData is
> > updated
> >                          with a pointer to the buffer.
> > @@ -68,7 +72,8 @@ EFI_STATUS
> >  EFIAPI
> >  LoadUnitTestCache (
> >    IN  UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle,
> > -  OUT UNIT_TEST_SAVE_HEADER       **SaveData
> > +  OUT VOID                        **SaveData,
> > +  OUT UINTN                       *SaveStateSize
> >    )
> >  {
> >    return EFI_UNSUPPORTED;
> > diff --git
> > a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/
> > UnitTestPersistenceLibSimpleFileSystem.c
> > b/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/
> > UnitTestPersistenceLibSimpleFileSystem.c
> > index ed4a7d1615..d7a62145da 100644
> > ---
> > a/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/
> > UnitTestPersistenceLibSimpleFileSystem.c
> > +++
> > b/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSyste
> > +++ m/UnitTestPersistenceLibSimpleFileSystem.c
> > @@ -4,6 +4,7 @@
> >    version of the internal test state in case the test needs to quit and restore.
> >
> >    Copyright (c) Microsoft Corporation.<BR>
> > +  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
> >    SPDX-License-Identifier: BSD-2-Clause-Patent  **/
> >
> > @@ -16,6 +17,7 @@
> >  #include <Library/DevicePathLib.h>
> >  #include <Library/ShellLib.h>
> >  #include <Protocol/LoadedImage.h>
> > +#include <UnitTestFrameworkTypes.h>
> >
> >  #define CACHE_FILE_SUFFIX  L"_Cache.dat"
> >
> > @@ -213,6 +215,7 @@ DoesCacheExist (
> >    @param[in]  FrameworkHandle  A pointer to the framework that is being
> > persisted.
> >    @param[in]  SaveData         A pointer to the buffer containing the serialized
> >                                 framework internal state.
> > +  @param[in]  SaveStateSize    The size of SaveData in bytes.
> >
> >    @retval  EFI_SUCCESS  Data is persisted and the test can be safely quit.
> >    @retval  Others       Data is not persisted and test cannot be resumed upon
> > exit.
> > @@ -222,7 +225,8 @@ EFI_STATUS
> >  EFIAPI
> >  SaveUnitTestCache (
> >    IN UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle,
> > -  IN UNIT_TEST_SAVE_HEADER       *SaveData
> > +  IN VOID                        *SaveData,
> > +  IN UINTN                       SaveStateSize
> >    )
> >  {
> >    EFI_DEVICE_PATH_PROTOCOL  *FileDevicePath; @@ -280,7 +284,7 @@
> > SaveUnitTestCache (
> >    //
> >    // Write the data to the file.
> >    //
> > -  WriteCount = SaveData->SaveStateSize;
> > +  WriteCount = SaveStateSize;
> >    DEBUG ((DEBUG_INFO, "%a - Writing %d bytes to file...\n", __FUNCTION__,
> > WriteCount));
> >    Status = ShellWriteFile (
> >               FileHandle,
> > @@ -288,7 +292,7 @@ SaveUnitTestCache (
> >               SaveData
> >               );
> >
> > -  if (EFI_ERROR (Status) || (WriteCount != SaveData->SaveStateSize)) {
> > +  if (EFI_ERROR (Status) || (WriteCount != SaveStateSize)) {
> >      DEBUG ((DEBUG_ERROR, "%a - Writing to file failed! %r\n",
> > __FUNCTION__, Status));
> >    } else {
> >      DEBUG ((DEBUG_INFO, "%a - SUCCESS!\n", __FUNCTION__)); @@ -312,8
> > +316,9 @@ Exit:
> >    Will allocate a buffer to hold the loaded data.
> >
> >    @param[in]  FrameworkHandle  A pointer to the framework that is being
> > persisted.
> > -  @param[in]  SaveData         A pointer pointer that will be updated with the
> > address
> > +  @param[out] SaveData         A pointer pointer that will be updated with the
> > address
> >                                 of the loaded data buffer.
> > +  @param[out] SaveStateSize    Return the size of SaveData in bytes.
> >
> >    @retval  EFI_SUCCESS  Data has been loaded successfully and SaveData is
> > updated
> >                          with a pointer to the buffer.
> > @@ -325,7 +330,8 @@ EFI_STATUS
> >  EFIAPI
> >  LoadUnitTestCache (
> >    IN  UNIT_TEST_FRAMEWORK_HANDLE  FrameworkHandle,
> > -  OUT UNIT_TEST_SAVE_HEADER       **SaveData
> > +  OUT VOID                        **SaveData,
> > +  OUT UINTN                       *SaveStateSize
> >    )
> >  {
> >    EFI_STATUS                Status;
> > @@ -334,7 +340,7 @@ LoadUnitTestCache (
> >    BOOLEAN                   IsFileOpened;
> >    UINT64                    LargeFileSize;
> >    UINTN                     FileSize;
> > -  UNIT_TEST_SAVE_HEADER     *Buffer;
> > +  VOID                      *Buffer;
> >
> >    IsFileOpened = FALSE;
> >    Buffer       = NULL;
> > @@ -380,8 +386,9 @@ LoadUnitTestCache (
> >    //
> >    // Now that we know the size, let's allocated a buffer to hold the contents.
> >    //
> > -  FileSize = (UINTN)LargeFileSize;    // You know what... if it's too large, this lib
> > don't care.
> > -  Buffer   = AllocatePool (FileSize);
> > +  FileSize       = (UINTN)LargeFileSize; // You know what... if it's too large, this
> > lib don't care.
> > +  *SaveStateSize = FileSize;
> > +  Buffer         = AllocatePool (FileSize);
> >    if (Buffer == NULL) {
> >      DEBUG ((DEBUG_ERROR, "%a - Failed to allocate a pool to hold the file
> > contents! %r\n", __FUNCTION__, Status));
> >      Status = EFI_OUT_OF_RESOURCES;
> > --
> > 2.31.1.windows.1
> >
> >
> >
> > 
> >


  reply	other threads:[~2022-12-13 23:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <172E1CF5498F8F29.13790@groups.io>
2022-12-12  7:32 ` [edk2-devel] [PATCH] UnitTestFrameworkPkg: Modify APIs in UnitTestPersistenceLib Zhiguang Liu
2022-12-13 23:56   ` Michael D Kinney [this message]
2022-12-14  0:23   ` Michael Kubacki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CO1PR11MB492987F256E5A01E32A50FF8D2E39@CO1PR11MB4929.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox