public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [RestJsonStructureDxe PATCH 0/2] EFI REST JSON Structure Protocol
@ 2020-10-08 15:10 Abner Chang
  2020-10-08 15:10 ` [RestJsonStructureDxe PATCH 1/2] MdePkg/Include: Definitions of " Abner Chang
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Abner Chang @ 2020-10-08 15:10 UTC (permalink / raw)
  To: devel
  Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Jiaxin Wu, Siyuan Fu,
	Fan Wang, Jiewen Yao, Nickle Wang

This is the implementation of EFI_REST_JSON_STRUCTURE_PROTOCOL,
refer to UEFI spec 2.8 Section 29.7.3 EFI REST JSON Resource to C Structure
Converter.

Signed-off-by: Abner Chang <abner.chang@hpe.com>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Fan Wang <fan.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Nickle Wang <nickle.wang@hpe.com>

Abner Chang (2):
  MdePkg/Include: Definitions of EFI REST JSON Structure Protocol
  RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol

 MdePkg/Include/Protocol/RestJsonStructure.h   | 160 +++++
 MdePkg/MdePkg.dec                             |   6 +
 RedfishPkg/RedfishPkg.dsc                     |   3 +
 .../RestJsonStructureDxe.c                    | 583 ++++++++++++++++++
 .../RestJsonStructureDxe.inf                  |  40 ++
 .../RestJsonStructureInternal.h               |  35 ++
 6 files changed, 827 insertions(+)
 create mode 100644 MdePkg/Include/Protocol/RestJsonStructure.h
 create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c
 create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
 create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h

-- 
2.17.1


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

* [RestJsonStructureDxe PATCH 1/2] MdePkg/Include: Definitions of EFI REST JSON Structure Protocol
  2020-10-08 15:10 [RestJsonStructureDxe PATCH 0/2] EFI REST JSON Structure Protocol Abner Chang
@ 2020-10-08 15:10 ` Abner Chang
  2020-10-14  5:42   ` 回复: [edk2-devel] " gaoliming
  2020-10-08 15:10 ` [RestJsonStructureDxe PATCH 2/2] RedfishPkg/RestJsonStructureDxe: " Abner Chang
  2020-10-09  3:02 ` [edk2-devel] [RestJsonStructureDxe PATCH 0/2] " Sean
  2 siblings, 1 reply; 8+ messages in thread
From: Abner Chang @ 2020-10-08 15:10 UTC (permalink / raw)
  To: devel
  Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Jiaxin Wu, Siyuan Fu,
	Fan Wang, Jiewen Yao, Nickle Wang

Add definitions of EFI REST JSON Structure according to UEFI spec
2.8 Section 29.7.3 EFI REST JSON Resource to C Structure Converter.

Signed-off-by: Abner Chang <abner.chang@hpe.com>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Fan Wang <fan.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
---
 MdePkg/Include/Protocol/RestJsonStructure.h | 160 ++++++++++++++++++++
 MdePkg/MdePkg.dec                           |   6 +
 2 files changed, 166 insertions(+)
 create mode 100644 MdePkg/Include/Protocol/RestJsonStructure.h

diff --git a/MdePkg/Include/Protocol/RestJsonStructure.h b/MdePkg/Include/Protocol/RestJsonStructure.h
new file mode 100644
index 0000000000..5e4fef8cff
--- /dev/null
+++ b/MdePkg/Include/Protocol/RestJsonStructure.h
@@ -0,0 +1,160 @@
+/** @file
+  This file defines the EFI REST JSON Structure Protocol interface.
+
+  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef EFI_REST_JSON_STRUCTURE_PROTOCOL_H_
+#define EFI_REST_JSON_STRUCTURE_PROTOCOL_H_
+
+#include <Uefi.h>
+
+//
+// GUID definitions
+//
+#define EFI_REST_JSON_STRUCTURE_PROTOCOL_GUID \
+  { \
+    0xa9a048f6, 0x48a0, 0x4714, {0xb7, 0xda, 0xa9, 0xad,0x87, 0xd4, 0xda, 0xc9 } \
+  }
+
+typedef struct _EFI_REST_JSON_STRUCTURE_PROTOCOL EFI_REST_JSON_STRUCTURE_PROTOCOL;
+typedef CHAR8 * EFI_REST_JSON_RESOURCE_TYPE_DATATYPE;
+typedef CHAR8 * EFI_REST_RESOURCE_RELATIVE_PATH;
+
+/** Structure defintions of resource name space.
+  *
+  * The fields declared in this structure define the
+  * name and revision of payload delievered throught
+  * REST API.
+**/
+typedef struct _EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE {
+  CHAR8 *ResourceTypeName;   ///< Resource type name
+  CHAR8 *MajorVersion;       ///< Resource major version
+  CHAR8 *MinorVersion;       ///< Resource minor version
+  CHAR8 *ErrataVersion;      ///< Resource errata version
+} EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE;
+
+/** REST resource type identifier
+  *
+  * REST resource type consists of name space and data type.
+**/
+typedef struct _EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER {
+  EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE NameSpace; ///< Namespace of this resource type.
+  EFI_REST_JSON_RESOURCE_TYPE_DATATYPE DataType;   ///< Name of data type declared in this
+                                                   ///< resource type.
+} EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER;
+
+/** List of JSON to C structure conversions which this convertor supports.
+  *
+**/
+typedef struct _EFI_REST_JSON_STRUCTURE_SUPPORTED {
+  LIST_ENTRY NextSupportedRsrcInterp;                        ///< Linklist to next supported conversion.
+  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER RestResourceInterp; ///< JSON resource type this convertor supports.
+} EFI_REST_JSON_STRUCTURE_SUPPORTED;
+
+/** The header file of JSON C structure
+  *
+**/
+typedef struct _EFI_REST_JSON_STRUCTURE_HEADER {
+  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER    JsonRsrcIdentifier; ///< Resource identifier which use to
+                                                                ///< choice the proper interpreter.
+  ///< Follow by a pointer points to JSON structure, the content in the
+  ///< JSON structure is implementation-specific according to converter producer.
+  ///
+  VOID  *JsonStructurePointer;
+}  EFI_REST_JSON_STRUCTURE_HEADER;
+
+/**
+  JSON-IN C Structure-OUT function. Convert the given REST JSON resource into structure.
+
+  @param[in]    This                This is the EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    JsonRsrcIdentifier  This indicates the resource type and version is given in
+                                    ResourceJsonText.
+  @param[in]    ResourceJsonText    REST JSON resource in text format.
+  @param[out]   JsonStructure       Pointer to receive the pointer to EFI_REST_JSON_STRUCTURE_HEADER
+
+  @retval EFI_SUCCESS
+  @retval Others
+--*/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_REST_JSON_STRUCTURE_TO_STRUCTURE)(
+  IN  EFI_REST_JSON_STRUCTURE_PROTOCOL        *This,
+  IN  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *JsonRsrcIdentifier OPTIONAL,
+  IN  CHAR8                                   *ResourceJsonText,
+  OUT  EFI_REST_JSON_STRUCTURE_HEADER         **JsonStructure
+);
+
+/**
+  Convert the given REST JSON structure into JSON text.
+
+  @param[in]    This                 This is the EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    JsonStructureHeader  The point to EFI_REST_JSON_STRUCTURE_HEADER  structure.
+  @param[out]   ResourceJsonText     Pointer to receive REST JSON resource in text format.
+
+  @retval EFI_SUCCESS
+  @retval Others
+
+--*/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_REST_JSON_STRUCTURE_TO_JSON)(
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL     *This,
+  IN EFI_REST_JSON_STRUCTURE_HEADER       *JsonStructureHeader,
+  OUT CHAR8                               **ResourceJsonText
+);
+
+/**
+  This function destroys the REST JSON structure.
+
+  @param[in]    This                 This is the EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    JsonStructureHeader  JSON structure to destroy.
+
+  @retval EFI_SUCCESS
+  @retval Others
+
+--*/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE)(
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL   *This,
+  IN EFI_REST_JSON_STRUCTURE_HEADER     *JsonStructureHeader
+);
+/**
+  This function provides REST JSON resource to structure converter registration.
+
+  @param[in]    This                     This is the EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    JsonStructureSupported   The type and version of REST JSON resource which this converter
+                                         supports.
+  @param[in]    ToStructure              The function to convert REST JSON resource to structure.
+  @param[in]    ToJson                   The function to convert REST JSON structure to JSON in text format.
+  @param[out]   DestroyStructure         Destroy REST JSON structure returned in ToStructure()  function.
+
+  @retval EFI_SUCCESS             Register successfully.
+  @retval Others                  Fail to register.
+
+--*/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_REST_JSON_STRUCTURE_REGISTER)(
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL       *This,
+  IN EFI_REST_JSON_STRUCTURE_SUPPORTED      *JsonStructureSupported,
+  IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE   ToStructure,
+  IN EFI_REST_JSON_STRUCTURE_TO_JSON        ToJson,
+  IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure
+);
+
+/** EFI REST JSON to C structure protocol definition.
+  *
+**/
+typedef struct _EFI_REST_JSON_STRUCTURE_PROTOCOL {
+  EFI_REST_JSON_STRUCTURE_REGISTER           Register;          ///< Register JSON to C structure convertor
+  EFI_REST_JSON_STRUCTURE_TO_STRUCTURE       ToStructure;       ///< The function to convert JSON to C structure
+  EFI_REST_JSON_STRUCTURE_TO_JSON            ToJson;            ///< The function to convert C structure to JSON
+  EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE  DestoryStructure;  ///< Destory C structure.
+} EFI_REST_JSON_STRUCTURE_PROTOCOL;
+
+#endif
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 812be75fb3..0943816825 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1848,6 +1848,12 @@
   ## Include/Protocol/NvdimmLabel.h
   gEfiNvdimmLabelProtocolGuid               = { 0xd40b6b80, 0x97d5, 0x4282, { 0xbb, 0x1d, 0x22, 0x3a, 0x16, 0x91, 0x80, 0x58 }}
 
+  #
+  # Protocols defined in UEFI2.8
+  #
+  ## Include/Protocol/RestJsonStructure.h
+  gEfiRestJsonStructureProtocolGuid  = { 0xa9a048f6, 0x48a0, 0x4714, {0xb7, 0xda, 0xa9, 0xad,0x87, 0xd4, 0xda, 0xc9 }}
+
   #
   # Protocols defined in Shell2.0
   #
-- 
2.17.1


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

* [RestJsonStructureDxe PATCH 2/2] RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol
  2020-10-08 15:10 [RestJsonStructureDxe PATCH 0/2] EFI REST JSON Structure Protocol Abner Chang
  2020-10-08 15:10 ` [RestJsonStructureDxe PATCH 1/2] MdePkg/Include: Definitions of " Abner Chang
@ 2020-10-08 15:10 ` Abner Chang
  2020-10-09  3:02 ` [edk2-devel] [RestJsonStructureDxe PATCH 0/2] " Sean
  2 siblings, 0 replies; 8+ messages in thread
From: Abner Chang @ 2020-10-08 15:10 UTC (permalink / raw)
  To: devel; +Cc: Jiaxin Wu, Siyuan Fu, Fan Wang, Jiewen Yao, Nickle Wang

Implementation of EFI_REST_JSON_STRUCTURE_PROTOCOL, refer to UEFI spec
2.8 Section 29.7.3 EFI REST JSON Resource to C Structure Converter.

Signed-off-by: Abner Chang <abner.chang@hpe.com>

Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Fan Wang <fan.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
---
 RedfishPkg/RedfishPkg.dsc                     |   3 +
 .../RestJsonStructureDxe.c                    | 583 ++++++++++++++++++
 .../RestJsonStructureDxe.inf                  |  40 ++
 .../RestJsonStructureInternal.h               |  35 ++
 4 files changed, 661 insertions(+)
 create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c
 create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
 create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h

diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc
index 8acadddefc..5ef375ce40 100644
--- a/RedfishPkg/RedfishPkg.dsc
+++ b/RedfishPkg/RedfishPkg.dsc
@@ -38,3 +38,6 @@
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
   DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
+
+[Components]
+  RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c
new file mode 100644
index 0000000000..8aabf32c68
--- /dev/null
+++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c
@@ -0,0 +1,583 @@
+/** @file
+
+  The implementation of EFI REST Resource JSON to C structure convertor
+  Protocol.
+
+  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Protocol/RestJsonStructure.h>
+#include "RestJsonStructureInternal.h"
+
+LIST_ENTRY mRestJsonStructureList;
+EFI_HANDLE mProtocolHandle;
+
+/**
+  This function registers Restful resource interpreter for the
+  specific schema.
+
+  @param[in]    This                     This is the EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    JsonStructureSupported   The type and version of REST JSON resource which this converter
+                                         supports.
+  @param[in]    ToStructure              The function to convert REST JSON resource to structure.
+  @param[in]    ToJson                   The function to convert REST JSON structure to JSON in text format.
+  @param[in]    DestroyStructure         Destroy REST JSON structure returned in ToStructure()  function.
+
+  @retval EFI_SUCCESS             Register successfully.
+  @retval Others                  Fail to register.
+
+**/
+EFI_STATUS
+EFIAPI
+RestJsonStructureRegister (
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL       *This,
+  IN EFI_REST_JSON_STRUCTURE_SUPPORTED      *JsonStructureSupported,
+  IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE   ToStructure,
+  IN EFI_REST_JSON_STRUCTURE_TO_JSON        ToJson,
+  IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure
+)
+{
+  UINTN NumberOfNS;
+  UINTN Index;
+  LIST_ENTRY *ThisList;
+  REST_JSON_STRUCTURE_INSTANCE *Instance;
+  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *CloneSupportedInterpId;
+  EFI_REST_JSON_STRUCTURE_SUPPORTED *ThisSupportedInterp;
+
+  if (This == NULL ||
+      ToStructure == NULL ||
+      ToJson == NULL ||
+      DestroyStructure == NULL ||
+      JsonStructureSupported == NULL
+      ) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check how many name space interpreter can interpret.
+  //
+  ThisList = &JsonStructureSupported->NextSupportedRsrcInterp;
+  NumberOfNS = 1;
+  while (TRUE) {
+    if (ThisList->ForwardLink == &JsonStructureSupported->NextSupportedRsrcInterp) {
+      break;
+    } else {
+      ThisList = ThisList->ForwardLink;
+      NumberOfNS ++;
+    }
+  };
+
+  Instance =
+    (REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
+  if (Instance == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+  InitializeListHead (&Instance->NextRestJsonStructureInstance);
+  Instance->NumberOfNameSpaceToConvert = NumberOfNS;
+  Instance->SupportedRsrcIndentifier = (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *)((REST_JSON_STRUCTURE_INSTANCE *)Instance + 1);
+  //
+  // Copy supported resource identifer interpreter.
+  //
+  CloneSupportedInterpId = Instance->SupportedRsrcIndentifier;
+  ThisSupportedInterp = JsonStructureSupported;
+  for (Index = 0; Index < NumberOfNS; Index ++) {
+    CopyMem ((VOID *)CloneSupportedInterpId, (VOID *)&ThisSupportedInterp->RestResourceInterp, sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
+    ThisSupportedInterp = (EFI_REST_JSON_STRUCTURE_SUPPORTED *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink;
+    CloneSupportedInterpId ++;
+  }
+  Instance->JsonToStructure = ToStructure;
+  Instance->StructureToJson = ToJson;
+  Instance->DestroyStructure = DestroyStructure;
+  InsertTailList (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
+  return EFI_SUCCESS;
+}
+
+/**
+  This function check if this interpreter instance support the given namesapce.
+
+  @param[in]    This                EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    InterpreterInstance REST_JSON_STRUCTURE_INSTANCE
+  @param[in]    RsrcTypeIdentifier  Resource type identifier.
+  @param[in]    ResourceRaw         Given Restful resource.
+  @param[out]   InterpProp          Property interpreted from given ResourceRaw.
+
+  @retval EFI_SUCCESS
+  @retval Others.
+
+**/
+EFI_STATUS
+InterpreterInstanceToStruct (
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL         *This,
+  IN REST_JSON_STRUCTURE_INSTANCE             *InterpreterInstance,
+  IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER   *RsrcTypeIdentifier OPTIONAL,
+  IN CHAR8                                    *ResourceRaw,
+  OUT EFI_REST_JSON_STRUCTURE_HEADER          **InterpProp
+ )
+{
+  UINTN Index;
+  EFI_STATUS Status;
+  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
+
+  if (This == NULL ||
+      InterpreterInstance == NULL ||
+      ResourceRaw == NULL ||
+      InterpProp == NULL
+      ) {
+      return EFI_INVALID_PARAMETER;
+  }
+
+  Status = EFI_UNSUPPORTED;
+  if (RsrcTypeIdentifier == NULL) {
+    //
+    // No resource type identifier, send to intepreter anyway.
+    // Interpreter may recognize this resource.
+    //
+    Status = InterpreterInstance->JsonToStructure (
+                This,
+                NULL,
+                ResourceRaw,
+                InterpProp
+                );
+  } else {
+    //
+    // Check if the namesapce and version is supported by this interpreter.
+    //
+    ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
+    for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){
+      if (AsciiStrCmp (
+            RsrcTypeIdentifier->NameSpace.ResourceTypeName,
+            ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0){
+        if ((RsrcTypeIdentifier->NameSpace.MajorVersion == NULL) &&
+            (RsrcTypeIdentifier->NameSpace.MinorVersion == NULL) &&
+            (RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL)
+            ) {
+          //
+          // Don't check version of this resource type identifier.
+          //
+          Status = InterpreterInstance->JsonToStructure (
+                      This,
+                      RsrcTypeIdentifier,
+                      ResourceRaw,
+                      InterpProp
+                      );
+          break;
+        } else {
+          //
+          // Check version.
+          //
+          if ((AsciiStrCmp (
+                RsrcTypeIdentifier->NameSpace.MajorVersion,
+                ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&
+              (AsciiStrCmp (
+                RsrcTypeIdentifier->NameSpace.MinorVersion,
+                ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
+              (AsciiStrCmp (
+                RsrcTypeIdentifier->NameSpace.ErrataVersion,
+                ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
+            Status = InterpreterInstance->JsonToStructure (
+                      This,
+                      RsrcTypeIdentifier,
+                      ResourceRaw,
+                      InterpProp
+                      );
+            break;
+          }
+        }
+      }
+      ThisSupportedRsrcTypeId ++;
+    }
+  }
+  return Status;
+}
+/**
+  This function converts JSON C structure to JSON property.
+
+  @param[in]    This                EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    InterpreterInstance REST_JSON_STRUCTURE_INSTANCE
+  @param[in]    RsrcTypeIdentifier  Resource type identifier.
+  @param[out]   ResourceRaw         Output in JSON text format.
+
+  @retval EFI_SUCCESS
+  @retval Others.
+
+**/
+EFI_STATUS
+InterpreterEfiStructToInstance (
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL   *This,
+  IN REST_JSON_STRUCTURE_INSTANCE       *InterpreterInstance,
+  IN EFI_REST_JSON_STRUCTURE_HEADER     *InterpProp,
+  OUT CHAR8 **ResourceRaw
+)
+{
+  UINTN Index;
+  EFI_STATUS Status;
+  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
+  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier;
+
+  if (This == NULL ||
+      InterpreterInstance == NULL ||
+      InterpProp == NULL ||
+      ResourceRaw == NULL
+      ) {
+    return EFI_INVALID_PARAMETER;
+  }
+  RsrcTypeIdentifier = &InterpProp->JsonRsrcIdentifier;
+  if (RsrcTypeIdentifier == NULL ||
+      RsrcTypeIdentifier->NameSpace.ResourceTypeName == NULL ||
+      RsrcTypeIdentifier->NameSpace.MajorVersion == NULL ||
+      RsrcTypeIdentifier->NameSpace.MinorVersion == NULL ||
+      RsrcTypeIdentifier->NameSpace.ErrataVersion == NULL
+      ) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check if the namesapce and version is supported by this interpreter.
+  //
+  Status = EFI_UNSUPPORTED;
+  ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
+  for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){
+    if (AsciiStrCmp (
+          RsrcTypeIdentifier->NameSpace.ResourceTypeName,
+          ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0){
+      //
+      // Check version.
+      //
+      if ((AsciiStrCmp (
+            RsrcTypeIdentifier->NameSpace.MajorVersion,
+            ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&
+          (AsciiStrCmp (
+            RsrcTypeIdentifier->NameSpace.MinorVersion,
+            ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
+          (AsciiStrCmp (
+            RsrcTypeIdentifier->NameSpace.ErrataVersion,
+            ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
+        Status = InterpreterInstance->StructureToJson (
+                  This,
+                  InterpProp,
+                  ResourceRaw
+                  );
+        break;
+      }
+    }
+    ThisSupportedRsrcTypeId ++;
+  }
+  return Status;
+}
+
+/**
+  This function destory REST property structure.
+
+  @param[in]    This                 EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    InterpreterInstance  REST_JSON_STRUCTURE_INSTANCE
+  @param[out]   InterpProp           Property interpreted from given ResourceRaw.
+
+  @retval EFI_SUCCESS
+  @retval Others.
+
+**/
+EFI_STATUS
+InterpreterInstanceDestoryJsonStruct (
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL       *This,
+  IN REST_JSON_STRUCTURE_INSTANCE           *InterpreterInstance,
+  IN EFI_REST_JSON_STRUCTURE_HEADER         *InterpProp
+ )
+{
+  UINTN Index;
+  EFI_STATUS Status;
+  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
+
+  if (This == NULL ||
+      InterpreterInstance == NULL ||
+      InterpProp == NULL
+      ) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Status = EFI_UNSUPPORTED;
+  //
+  // Check if the namesapce and version is supported by this interpreter.
+  //
+  ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
+  for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index ++){
+    if (AsciiStrCmp (
+          InterpProp->JsonRsrcIdentifier.NameSpace.ResourceTypeName,
+          ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName) == 0) {
+      if ((InterpProp->JsonRsrcIdentifier.NameSpace.MajorVersion == NULL) &&
+          (InterpProp->JsonRsrcIdentifier.NameSpace.MinorVersion == NULL) &&
+          (InterpProp->JsonRsrcIdentifier.NameSpace.ErrataVersion == NULL)
+          ) {
+        //
+        // Don't check version of this resource type identifier.
+        //
+        Status = InterpreterInstance->DestroyStructure (
+                    This,
+                    InterpProp
+                    );
+        break;
+      } else {
+        //
+        // Check version.
+        //
+        if ((AsciiStrCmp (
+              InterpProp->JsonRsrcIdentifier.NameSpace.MajorVersion,
+              ThisSupportedRsrcTypeId->NameSpace.MajorVersion) == 0) &&
+            (AsciiStrCmp (
+              InterpProp->JsonRsrcIdentifier.NameSpace.MinorVersion,
+              ThisSupportedRsrcTypeId->NameSpace.MinorVersion) == 0) &&
+            (AsciiStrCmp (
+              InterpProp->JsonRsrcIdentifier.NameSpace.ErrataVersion,
+              ThisSupportedRsrcTypeId->NameSpace.ErrataVersion) == 0)) {
+          Status = InterpreterInstance->DestroyStructure (
+                    This,
+                    InterpProp
+                    );
+          break;
+        }
+      }
+    }
+    ThisSupportedRsrcTypeId ++;
+  }
+  return Status;
+}
+
+/**
+  This function translates the given JSON text to JSON C Structure.
+
+  @param[in]    This                EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    RsrcTypeIdentifier  Resource type identifier.
+  @param[in]    ResourceJsonText    Given Restful resource.
+  @param[out]   JsonStructure       Property interpreted from given ResourceRaw.
+
+  @retval EFI_SUCCESS
+  @retval Others.
+
+**/
+EFI_STATUS
+EFIAPI
+RestJsonStructureToStruct (
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL       *This,
+  IN EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier OPTIONAL,
+  IN CHAR8                                  *ResourceJsonText,
+  OUT EFI_REST_JSON_STRUCTURE_HEADER        **JsonStructure
+)
+{
+  EFI_STATUS Status;
+  REST_JSON_STRUCTURE_INSTANCE *Instance;
+
+  if (This == NULL ||
+      ResourceJsonText == NULL ||
+      JsonStructure == NULL
+    ) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (IsListEmpty (&mRestJsonStructureList)) {
+    return EFI_UNSUPPORTED;
+  }
+  Status = EFI_SUCCESS;
+  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
+  while (TRUE) {
+    Status = InterpreterInstanceToStruct (
+                This,
+                Instance,
+                RsrcTypeIdentifier,
+                ResourceJsonText,
+                JsonStructure
+              );
+    if (!EFI_ERROR (Status)) {
+      break;
+    }
+    if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
+      Status = EFI_UNSUPPORTED;
+      break;
+    }
+    Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
+  };
+  return Status;
+}
+
+/**
+  This function destory REST property EFI structure which returned in
+  JsonToStructure().
+
+  @param[in]    This            EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    InterpProp      Property to destory.
+
+  @retval EFI_SUCCESS
+  @retval Others
+
+**/
+EFI_STATUS
+RestJsonStructureDestroyStruct (
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
+  IN EFI_REST_JSON_STRUCTURE_HEADER  *InterpProp
+)
+{
+  EFI_STATUS Status;
+  REST_JSON_STRUCTURE_INSTANCE *Instance;
+
+  if (This == NULL || InterpProp == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (IsListEmpty (&mRestJsonStructureList)) {
+    return EFI_UNSUPPORTED;
+  }
+  Status = EFI_SUCCESS;
+  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
+  while (TRUE) {
+    Status = InterpreterInstanceDestoryJsonStruct (
+                This,
+                Instance,
+                InterpProp
+              );
+    if (!EFI_ERROR (Status)) {
+      break;
+    }
+    if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
+      Status = EFI_UNSUPPORTED;
+      break;
+    }
+    Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
+  };
+  return Status;
+}
+
+/**
+  This function translates the given JSON C Structure to JSON text.
+
+  @param[in]    This            EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
+  @param[in]    InterpProp      Given Restful resource.
+  @param[out]   ResourceRaw     Resource in RESTfuls service oriented.
+
+  @retval EFI_SUCCESS
+  @retval Others             Fail to remove the entry
+
+**/
+EFI_STATUS
+EFIAPI
+RestJsonStructureToJson (
+  IN EFI_REST_JSON_STRUCTURE_PROTOCOL *This,
+  IN EFI_REST_JSON_STRUCTURE_HEADER *InterpProp,
+  OUT CHAR8 **ResourceRaw
+)
+{
+  EFI_STATUS Status;
+  REST_JSON_STRUCTURE_INSTANCE *Instance;
+
+  if (This == NULL || InterpProp == NULL || ResourceRaw == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (IsListEmpty (&mRestJsonStructureList)) {
+    return EFI_UNSUPPORTED;
+  }
+  Status = EFI_SUCCESS;
+  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
+  while (TRUE) {
+    Status = InterpreterEfiStructToInstance (
+                This,
+                Instance,
+                InterpProp,
+                ResourceRaw
+              );
+    if (!EFI_ERROR (Status)) {
+      break;
+    }
+    if (IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
+      Status = EFI_UNSUPPORTED;
+      break;
+    }
+    Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
+  };
+  return Status;
+}
+
+EFI_REST_JSON_STRUCTURE_PROTOCOL mRestJsonStructureProtocol = {
+  RestJsonStructureRegister,
+  RestJsonStructureToStruct,
+  RestJsonStructureToJson,
+  RestJsonStructureDestroyStruct,
+};
+
+/**
+  This is the declaration of an EFI image entry point.
+
+  @param  ImageHandle           The firmware allocated handle for the UEFI image.
+  @param  SystemTable           A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS           The operation completed successfully.
+  @retval Others                An unexpected error occurred.
+**/
+EFI_STATUS
+EFIAPI
+RestJsonStructureEntryPoint (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS Status;
+
+  InitializeListHead (&mRestJsonStructureList);
+  //
+  // Install the Restful Resource Interpreter Protocol.
+  //
+  mProtocolHandle = NULL;
+  Status = gBS->InstallProtocolInterface (
+                  &mProtocolHandle,
+                  &gEfiRestJsonStructureProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  (VOID *)&mRestJsonStructureProtocol
+                  );
+  return Status;
+}
+
+/**
+  This is the unload handle for Redfish discover module.
+
+  Disconnect the driver specified by ImageHandle from all the devices in the handle database.
+  Uninstall all the protocols installed in the driver entry point.
+
+  @param[in] ImageHandle           The drivers' driver image.
+
+  @retval    EFI_SUCCESS           The image is unloaded.
+  @retval    Others                Failed to unload the image.
+
+**/
+EFI_STATUS
+EFIAPI
+RestJsonStructureUnload (
+  IN EFI_HANDLE ImageHandle
+  )
+{
+  EFI_STATUS Status;
+  REST_JSON_STRUCTURE_INSTANCE *Instance;
+  REST_JSON_STRUCTURE_INSTANCE *NextInstance;
+
+  if (IsListEmpty (&mRestJsonStructureList)) {
+    return EFI_SUCCESS;
+  }
+  //
+  // Free memory of REST_JSON_STRUCTURE_INSTANCE instance.
+  //
+  Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
+  do {
+    NextInstance = NULL;
+    if (!IsNodeAtEnd(&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
+      NextInstance = (REST_JSON_STRUCTURE_INSTANCE *)GetNextNode (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance);
+    }
+    FreePool ((VOID *)Instance);
+    Instance = NextInstance;
+  } while (Instance != NULL);
+
+  Status = gBS->UninstallProtocolInterface (
+                  mProtocolHandle,
+                  &gEfiRestJsonStructureProtocolGuid,
+                  (VOID *)&mRestJsonStructureProtocol
+                  );
+  return EFI_SUCCESS;
+}
diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
new file mode 100644
index 0000000000..df774de715
--- /dev/null
+++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
@@ -0,0 +1,40 @@
+## @file
+# Implementation of EFI REST JSON Structure Protocol.
+#
+#  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION               = 0x00010005
+  BASE_NAME                 = RestJsonStructureDxe
+  FILE_GUID                 = 83FAAFBF-FC4B-469F-892A-798E66A6F50A
+  MODULE_TYPE               = DXE_DRIVER
+  VERSION_STRING            = 1.0
+  ENTRY_POINT               = RestJsonStructureEntryPoint
+  UNLOAD_IMAGE              = RestJsonStructureUnload
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  RedfishPkg/RedfishPkg.dec
+
+[Sources]
+  RestJsonStructureDxe.c
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  UefiBootServicesTableLib
+  UefiDriverEntryPoint
+  UefiLib
+
+[Protocols]
+  gEfiRestJsonStructureProtocolGuid    ## Producing
+
+[Depex]
+  TRUE
+
diff --git a/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h
new file mode 100644
index 0000000000..7610fd4d9a
--- /dev/null
+++ b/RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h
@@ -0,0 +1,35 @@
+/** @file
+  The internal definitions of EFI REST Resource JSON to C structure convertor
+  Protocol.
+
+  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef EFI_REST_JSON_STRUCTURE_INTERNAL_H_
+#define EFI_REST_JSON_STRUCTURE_INTERNAL_H_
+
+#include <Uefi.h>
+
+#include <Library/BaseLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+/** Internal structure to maintain the information of JSON to
+  * C structure convertor.
+  *
+**/
+typedef struct _REST_JSON_STRUCTURE_INSTANCE {
+  LIST_ENTRY NextRestJsonStructureInstance;  ///< Next convertor instance
+  UINTN NumberOfNameSpaceToConvert;          ///< Number of resource type this convertor supports.
+  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER     *SupportedRsrcIndentifier; ///< The resource type linklist
+  EFI_REST_JSON_STRUCTURE_TO_STRUCTURE        JsonToStructure;          ///< JSON to C structure function
+  EFI_REST_JSON_STRUCTURE_TO_JSON             StructureToJson;          ///< C structure to JSON function
+  EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE   DestroyStructure;         ///< Destory C struture function.
+} REST_JSON_STRUCTURE_INSTANCE;
+#endif
-- 
2.17.1


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

* Re: [edk2-devel] [RestJsonStructureDxe PATCH 0/2] EFI REST JSON Structure Protocol
  2020-10-08 15:10 [RestJsonStructureDxe PATCH 0/2] EFI REST JSON Structure Protocol Abner Chang
  2020-10-08 15:10 ` [RestJsonStructureDxe PATCH 1/2] MdePkg/Include: Definitions of " Abner Chang
  2020-10-08 15:10 ` [RestJsonStructureDxe PATCH 2/2] RedfishPkg/RestJsonStructureDxe: " Abner Chang
@ 2020-10-09  3:02 ` Sean
  2020-10-12  1:51   ` Abner Chang
  2 siblings, 1 reply; 8+ messages in thread
From: Sean @ 2020-10-09  3:02 UTC (permalink / raw)
  To: devel, abner.chang
  Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Jiaxin Wu, Siyuan Fu,
	Fan Wang, Jiewen Yao, Nickle Wang

Abner,

As you add this RedfishPkg and significant new code to edk2 have you 
thought about authoring unit tests.  One of the goals of the unit test 
work that was enabled nearly 1 year ago was to make it easy for 
developers to write unit tests and to continually run them during PR and 
CI runs in the hope that as a community we might start authoring unit 
tests with new code.

Personally i would like to see a process that new modules can not be 
added without unit tests and relatively high code coverage.

Was there any thought to that?  Has there been discussion i may have 
missed?

Thanks
Sean



On 10/8/2020 8:10 AM, Abner Chang wrote:
> This is the implementation of EFI_REST_JSON_STRUCTURE_PROTOCOL,
> refer to UEFI spec 2.8 Section 29.7.3 EFI REST JSON Resource to C Structure
> Converter.
> 
> Signed-off-by: Abner Chang <abner.chang@hpe.com>
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> Cc: Siyuan Fu <siyuan.fu@intel.com>
> Cc: Fan Wang <fan.wang@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Nickle Wang <nickle.wang@hpe.com>
> 
> Abner Chang (2):
>    MdePkg/Include: Definitions of EFI REST JSON Structure Protocol
>    RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol
> 
>   MdePkg/Include/Protocol/RestJsonStructure.h   | 160 +++++
>   MdePkg/MdePkg.dec                             |   6 +
>   RedfishPkg/RedfishPkg.dsc                     |   3 +
>   .../RestJsonStructureDxe.c                    | 583 ++++++++++++++++++
>   .../RestJsonStructureDxe.inf                  |  40 ++
>   .../RestJsonStructureInternal.h               |  35 ++
>   6 files changed, 827 insertions(+)
>   create mode 100644 MdePkg/Include/Protocol/RestJsonStructure.h
>   create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c
>   create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
>   create mode 100644 RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h
> 

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

* Re: [edk2-devel] [RestJsonStructureDxe PATCH 0/2] EFI REST JSON Structure Protocol
  2020-10-09  3:02 ` [edk2-devel] [RestJsonStructureDxe PATCH 0/2] " Sean
@ 2020-10-12  1:51   ` Abner Chang
  2020-10-20  1:05     ` Abner Chang
  0 siblings, 1 reply; 8+ messages in thread
From: Abner Chang @ 2020-10-12  1:51 UTC (permalink / raw)
  To: devel@edk2.groups.io, spbrogan@outlook.com
  Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Jiaxin Wu, Siyuan Fu,
	Fan Wang, Jiewen Yao, Wang, Nickle (HPS SW)

No you didn’t miss have discussions. However, you can help me to understand Unit test framework. 

There are some levels of the unit test, I don’t know how much we can do in the current CI/UnitTestFramework and how much effort would be left to the new (also the existing) package developers.

1. The code coverage test,  can this launched by CI? This one should be relatively simple if it can run automatically (like to launch Coverity) and gives report to developers.
2. Code path test, developers have to write the unit test drivers/apps under UnitTest? Developers decide how to run the function validations on input/output parameter and/or some other basic API functionality test?
3. The feature test for the hardware independent functionalities or some features which have the corresponding simulator like network stacks. But I think this is more like the platform-level test, right? Maybe this is not in UnittestFramework scope?

I take a look into UnitTestFramework and only see a simple sample unit test driver, is this the only implementation?  Any edk2 packages or drivers has its own unit test yet?
Do you have some links to the edk2 Unit Test Writer guide?

Thanks
Abner

> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Sean
> Sent: Friday, October 9, 2020 11:03 AM
> To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist)
> <abner.chang@hpe.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com>; Jiaxin
> Wu <jiaxin.wu@intel.com>; Siyuan Fu <siyuan.fu@intel.com>; Fan Wang
> <fan.wang@intel.com>; Jiewen Yao <jiewen.yao@intel.com>; Wang, Nickle
> (HPS SW) <nickle.wang@hpe.com>
> Subject: Re: [edk2-devel] [RestJsonStructureDxe PATCH 0/2] EFI REST JSON
> Structure Protocol
> 
> Abner,
> 
> As you add this RedfishPkg and significant new code to edk2 have you
> thought about authoring unit tests.  One of the goals of the unit test work
> that was enabled nearly 1 year ago was to make it easy for developers to
> write unit tests and to continually run them during PR and CI runs in the hope
> that as a community we might start authoring unit tests with new code.
> 
> Personally i would like to see a process that new modules can not be added
> without unit tests and relatively high code coverage.
> 
> Was there any thought to that?  Has there been discussion i may have missed?
> 
> Thanks
> Sean
> 
> 
> 
> On 10/8/2020 8:10 AM, Abner Chang wrote:
> > This is the implementation of EFI_REST_JSON_STRUCTURE_PROTOCOL,
> refer
> > to UEFI spec 2.8 Section 29.7.3 EFI REST JSON Resource to C Structure
> > Converter.
> >
> > Signed-off-by: Abner Chang <abner.chang@hpe.com>
> >
> > Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> > Cc: Siyuan Fu <siyuan.fu@intel.com>
> > Cc: Fan Wang <fan.wang@intel.com>
> > Cc: Jiewen Yao <jiewen.yao@intel.com>
> > Cc: Nickle Wang <nickle.wang@hpe.com>
> >
> > Abner Chang (2):
> >    MdePkg/Include: Definitions of EFI REST JSON Structure Protocol
> >    RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol
> >
> >   MdePkg/Include/Protocol/RestJsonStructure.h   | 160 +++++
> >   MdePkg/MdePkg.dec                             |   6 +
> >   RedfishPkg/RedfishPkg.dsc                     |   3 +
> >   .../RestJsonStructureDxe.c                    | 583 ++++++++++++++++++
> >   .../RestJsonStructureDxe.inf                  |  40 ++
> >   .../RestJsonStructureInternal.h               |  35 ++
> >   6 files changed, 827 insertions(+)
> >   create mode 100644 MdePkg/Include/Protocol/RestJsonStructure.h
> >   create mode 100644
> RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c
> >   create mode 100644
> RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
> >   create mode 100644
> > RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h
> >
> 
> 
> 
> 


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

* 回复: [edk2-devel] [RestJsonStructureDxe PATCH 1/2] MdePkg/Include: Definitions of EFI REST JSON Structure Protocol
  2020-10-08 15:10 ` [RestJsonStructureDxe PATCH 1/2] MdePkg/Include: Definitions of " Abner Chang
@ 2020-10-14  5:42   ` gaoliming
  2020-10-14 15:07     ` Abner Chang
  0 siblings, 1 reply; 8+ messages in thread
From: gaoliming @ 2020-10-14  5:42 UTC (permalink / raw)
  To: devel, abner.chang
  Cc: 'Michael D Kinney', 'Zhiguang Liu',
	'Jiaxin Wu', 'Siyuan Fu', 'Fan Wang',
	'Jiewen Yao', 'Nickle Wang'

Abner:

> -----邮件原件-----
> 发件人: bounce+27952+66030+4905953+8761045@groups.io
> <bounce+27952+66030+4905953+8761045@groups.io> 代表 Abner Chang
> 发送时间: 2020年10月8日 23:11
> 收件人: devel@edk2.groups.io
> 抄送: Michael D Kinney <michael.d.kinney@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com>; Jiaxin
> Wu <jiaxin.wu@intel.com>; Siyuan Fu <siyuan.fu@intel.com>; Fan Wang
> <fan.wang@intel.com>; Jiewen Yao <jiewen.yao@intel.com>; Nickle Wang
> <nickle.wang@hpe.com>
> 主题: [edk2-devel] [RestJsonStructureDxe PATCH 1/2] MdePkg/Include:
> Definitions of EFI REST JSON Structure Protocol
> 
> Add definitions of EFI REST JSON Structure according to UEFI spec
> 2.8 Section 29.7.3 EFI REST JSON Resource to C Structure Converter.
> 
> Signed-off-by: Abner Chang <abner.chang@hpe.com>
> 
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> Cc: Siyuan Fu <siyuan.fu@intel.com>
> Cc: Fan Wang <fan.wang@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Nickle Wang <nickle.wang@hpe.com>
> ---
>  MdePkg/Include/Protocol/RestJsonStructure.h | 160
> ++++++++++++++++++++
>  MdePkg/MdePkg.dec                           |   6 +
>  2 files changed, 166 insertions(+)
>  create mode 100644 MdePkg/Include/Protocol/RestJsonStructure.h
> 
> diff --git a/MdePkg/Include/Protocol/RestJsonStructure.h
> b/MdePkg/Include/Protocol/RestJsonStructure.h
> new file mode 100644
> index 0000000000..5e4fef8cff
> --- /dev/null
> +++ b/MdePkg/Include/Protocol/RestJsonStructure.h
> @@ -0,0 +1,160 @@
> +/** @file
> +  This file defines the EFI REST JSON Structure Protocol interface.
> +

Please also specify UEFI spec version.

> +  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef EFI_REST_JSON_STRUCTURE_PROTOCOL_H_
> +#define EFI_REST_JSON_STRUCTURE_PROTOCOL_H_
> +
> +#include <Uefi.h>
> +

Uefi.h is not required. The module will include this header file. 

> +//
> +// GUID definitions
> +//
> +#define EFI_REST_JSON_STRUCTURE_PROTOCOL_GUID \
> +  { \
> +    0xa9a048f6, 0x48a0, 0x4714, {0xb7, 0xda, 0xa9, 0xad,0x87, 0xd4, 0xda,
> 0xc9 } \
> +  }
> +
> +typedef struct _EFI_REST_JSON_STRUCTURE_PROTOCOL
> EFI_REST_JSON_STRUCTURE_PROTOCOL;
> +typedef CHAR8 * EFI_REST_JSON_RESOURCE_TYPE_DATATYPE;
> +typedef CHAR8 * EFI_REST_RESOURCE_RELATIVE_PATH;
EFI_REST_RESOURCE_RELATIVE_PATH is not in UEFI spec. Can you confirm it?

> +
> +/** Structure defintions of resource name space.
> +  *
> +  * The fields declared in this structure define the
> +  * name and revision of payload delievered throught
> +  * REST API.
> +**/

Structure comments start with /// or //. /**/ style is for the function.
Please update them. 

> +typedef struct _EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE {
> +  CHAR8 *ResourceTypeName;   ///< Resource type name
> +  CHAR8 *MajorVersion;       ///< Resource major version
> +  CHAR8 *MinorVersion;       ///< Resource minor version
> +  CHAR8 *ErrataVersion;      ///< Resource errata version
> +} EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE;
> +
> +/** REST resource type identifier
> +  *
> +  * REST resource type consists of name space and data type.
> +**/
> +typedef struct _EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER {
> +  EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE NameSpace; ///<
> Namespace of this resource type.
> +  EFI_REST_JSON_RESOURCE_TYPE_DATATYPE DataType;   ///< Name of
> data type declared in this
> +                                                   ///<
> resource type.
> +} EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER;
> +
> +/** List of JSON to C structure conversions which this convertor
supports.
> +  *
> +**/
> +typedef struct _EFI_REST_JSON_STRUCTURE_SUPPORTED {
> +  LIST_ENTRY NextSupportedRsrcInterp;                        ///<
> Linklist to next supported conversion.
> +  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER RestResourceInterp; ///<
> JSON resource type this convertor supports.
> +} EFI_REST_JSON_STRUCTURE_SUPPORTED;
> +
> +/** The header file of JSON C structure
> +  *
> +**/
> +typedef struct _EFI_REST_JSON_STRUCTURE_HEADER {
> +  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER    JsonRsrcIdentifier;
> ///< Resource identifier which use to
> +
> ///< choice the proper interpreter.
> +  ///< Follow by a pointer points to JSON structure, the content in the
> +  ///< JSON structure is implementation-specific according to converter
> producer.
> +  ///
> +  VOID  *JsonStructurePointer;
> +}  EFI_REST_JSON_STRUCTURE_HEADER;
> +
> +/**
> +  JSON-IN C Structure-OUT function. Convert the given REST JSON resource
> into structure.
> +
> +  @param[in]    This                This is the
> EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
> +  @param[in]    JsonRsrcIdentifier  This indicates the resource type and
> version is given in
> +                                    ResourceJsonText.
> +  @param[in]    ResourceJsonText    REST JSON resource in text
> format.
> +  @param[out]   JsonStructure       Pointer to receive the pointer to
> EFI_REST_JSON_STRUCTURE_HEADER
> +
> +  @retval EFI_SUCCESS
> +  @retval Others
> +--*/
> +typedef
> +EFI_STATUS
> +(EFIAPI *EFI_REST_JSON_STRUCTURE_TO_STRUCTURE)(
> +  IN  EFI_REST_JSON_STRUCTURE_PROTOCOL        *This,
> +  IN  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *JsonRsrcIdentifier
> OPTIONAL,
> +  IN  CHAR8
> *ResourceJsonText,
> +  OUT  EFI_REST_JSON_STRUCTURE_HEADER         **JsonStructure
> +);
> +
> +/**
> +  Convert the given REST JSON structure into JSON text.
> +
> +  @param[in]    This                 This is the
> EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
> +  @param[in]    JsonStructureHeader  The point to
> EFI_REST_JSON_STRUCTURE_HEADER  structure.
> +  @param[out]   ResourceJsonText     Pointer to receive REST JSON
> resource in text format.
> +
> +  @retval EFI_SUCCESS
> +  @retval Others
> +
> +--*/
> +typedef
> +EFI_STATUS
> +(EFIAPI *EFI_REST_JSON_STRUCTURE_TO_JSON)(
> +  IN EFI_REST_JSON_STRUCTURE_PROTOCOL     *This,
> +  IN EFI_REST_JSON_STRUCTURE_HEADER       *JsonStructureHeader,
> +  OUT CHAR8                               **ResourceJsonText
> +);
> +
> +/**
> +  This function destroys the REST JSON structure.
> +
> +  @param[in]    This                 This is the
> EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
> +  @param[in]    JsonStructureHeader  JSON structure to destroy.
> +
> +  @retval EFI_SUCCESS
> +  @retval Others
> +
> +--*/
> +typedef
> +EFI_STATUS
> +(EFIAPI *EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE)(
> +  IN EFI_REST_JSON_STRUCTURE_PROTOCOL   *This,
> +  IN EFI_REST_JSON_STRUCTURE_HEADER     *JsonStructureHeader
> +);
> +/**
> +  This function provides REST JSON resource to structure converter
> registration.
> +
> +  @param[in]    This                     This is the
> EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
> +  @param[in]    JsonStructureSupported   The type and version of REST
> JSON resource which this converter
> +                                         supports.
> +  @param[in]    ToStructure              The function to convert
> REST JSON resource to structure.
> +  @param[in]    ToJson                   The function to convert
> REST JSON structure to JSON in text format.
> +  @param[out]   DestroyStructure         Destroy REST JSON
> structure returned in ToStructure()  function.
> +
> +  @retval EFI_SUCCESS             Register successfully.
> +  @retval Others                  Fail to register.
> +
> +--*/
> +typedef
> +EFI_STATUS
> +(EFIAPI *EFI_REST_JSON_STRUCTURE_REGISTER)(
> +  IN EFI_REST_JSON_STRUCTURE_PROTOCOL       *This,
> +  IN EFI_REST_JSON_STRUCTURE_SUPPORTED
> *JsonStructureSupported,
> +  IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE   ToStructure,
> +  IN EFI_REST_JSON_STRUCTURE_TO_JSON        ToJson,
> +  IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure
> +);
> +
> +/** EFI REST JSON to C structure protocol definition.
> +  *
> +**/
> +typedef struct _EFI_REST_JSON_STRUCTURE_PROTOCOL {
> +  EFI_REST_JSON_STRUCTURE_REGISTER           Register;
> ///< Register JSON to C structure convertor
> +  EFI_REST_JSON_STRUCTURE_TO_STRUCTURE       ToStructure;
> ///< The function to convert JSON to C structure
> +  EFI_REST_JSON_STRUCTURE_TO_JSON            ToJson;
> ///< The function to convert C structure to JSON
> +  EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE  DestoryStructure;
> ///< Destory C structure.
> +} EFI_REST_JSON_STRUCTURE_PROTOCOL;

Here, typedef is not required, because EFI_REST_JSON_STRUCTURE_PROTOCOL has
been defined in the begin of this file. 

Thanks
Liming
> +
> +#endif
> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
> index 812be75fb3..0943816825 100644
> --- a/MdePkg/MdePkg.dec
> +++ b/MdePkg/MdePkg.dec
> @@ -1848,6 +1848,12 @@
>    ## Include/Protocol/NvdimmLabel.h
>    gEfiNvdimmLabelProtocolGuid               = { 0xd40b6b80, 0x97d5,
> 0x4282, { 0xbb, 0x1d, 0x22, 0x3a, 0x16, 0x91, 0x80, 0x58 }}
> 
> +  #
> +  # Protocols defined in UEFI2.8
> +  #
> +  ## Include/Protocol/RestJsonStructure.h
> +  gEfiRestJsonStructureProtocolGuid  = { 0xa9a048f6, 0x48a0, 0x4714,
> {0xb7, 0xda, 0xa9, 0xad,0x87, 0xd4, 0xda, 0xc9 }}
> +
>    #
>    # Protocols defined in Shell2.0
>    #
> --
> 2.17.1
> 
> 
> 
> 
> 




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

* Re: [edk2-devel] [RestJsonStructureDxe PATCH 1/2] MdePkg/Include: Definitions of EFI REST JSON Structure Protocol
  2020-10-14  5:42   ` 回复: [edk2-devel] " gaoliming
@ 2020-10-14 15:07     ` Abner Chang
  0 siblings, 0 replies; 8+ messages in thread
From: Abner Chang @ 2020-10-14 15:07 UTC (permalink / raw)
  To: gaoliming, devel@edk2.groups.io
  Cc: 'Michael D Kinney', 'Zhiguang Liu',
	'Jiaxin Wu', 'Siyuan Fu', 'Fan Wang',
	'Jiewen Yao', Wang, Nickle (HPS SW)



> -----Original Message-----
> From: gaoliming [mailto:gaoliming@byosoft.com.cn]
> Sent: Wednesday, October 14, 2020 1:42 PM
> To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist)
> <abner.chang@hpe.com>
> Cc: 'Michael D Kinney' <michael.d.kinney@intel.com>; 'Zhiguang Liu'
> <zhiguang.liu@intel.com>; 'Jiaxin Wu' <jiaxin.wu@intel.com>; 'Siyuan Fu'
> <siyuan.fu@intel.com>; 'Fan Wang' <fan.wang@intel.com>; 'Jiewen Yao'
> <jiewen.yao@intel.com>; Wang, Nickle (HPS SW) <nickle.wang@hpe.com>
> Subject: 回复: [edk2-devel] [RestJsonStructureDxe PATCH 1/2]
> MdePkg/Include: Definitions of EFI REST JSON Structure Protocol
> 
> Abner:
> 
> > -----邮件原件-----
> > 发件人: bounce+27952+66030+4905953+8761045@groups.io
> > <bounce+27952+66030+4905953+8761045@groups.io> 代表 Abner Chang
> > 发送时间: 2020年10月8日 23:11
> > 收件人: devel@edk2.groups.io
> > 抄送: Michael D Kinney <michael.d.kinney@intel.com>; Liming Gao
> > <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com>;
> > Jiaxin Wu <jiaxin.wu@intel.com>; Siyuan Fu <siyuan.fu@intel.com>; Fan
> > Wang <fan.wang@intel.com>; Jiewen Yao <jiewen.yao@intel.com>; Nickle
> > Wang <nickle.wang@hpe.com>
> > 主题: [edk2-devel] [RestJsonStructureDxe PATCH 1/2] MdePkg/Include:
> > Definitions of EFI REST JSON Structure Protocol
> >
> > Add definitions of EFI REST JSON Structure according to UEFI spec
> > 2.8 Section 29.7.3 EFI REST JSON Resource to C Structure Converter.
> >
> > Signed-off-by: Abner Chang <abner.chang@hpe.com>
> >
> > Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> > Cc: Siyuan Fu <siyuan.fu@intel.com>
> > Cc: Fan Wang <fan.wang@intel.com>
> > Cc: Jiewen Yao <jiewen.yao@intel.com>
> > Cc: Nickle Wang <nickle.wang@hpe.com>
> > ---
> >  MdePkg/Include/Protocol/RestJsonStructure.h | 160
> > ++++++++++++++++++++
> >  MdePkg/MdePkg.dec                           |   6 +
> >  2 files changed, 166 insertions(+)
> >  create mode 100644 MdePkg/Include/Protocol/RestJsonStructure.h
> >
> > diff --git a/MdePkg/Include/Protocol/RestJsonStructure.h
> > b/MdePkg/Include/Protocol/RestJsonStructure.h
> > new file mode 100644
> > index 0000000000..5e4fef8cff
> > --- /dev/null
> > +++ b/MdePkg/Include/Protocol/RestJsonStructure.h
> > @@ -0,0 +1,160 @@
> > +/** @file
> > +  This file defines the EFI REST JSON Structure Protocol interface.
> > +
> 
> Please also specify UEFI spec version.
> 
> > +  (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
> > +
> > +  SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +#ifndef EFI_REST_JSON_STRUCTURE_PROTOCOL_H_
> > +#define EFI_REST_JSON_STRUCTURE_PROTOCOL_H_
> > +
> > +#include <Uefi.h>
> > +
> 
> Uefi.h is not required. The module will include this header file.
> 
> > +//
> > +// GUID definitions
> > +//
> > +#define EFI_REST_JSON_STRUCTURE_PROTOCOL_GUID \
> > +  { \
> > +    0xa9a048f6, 0x48a0, 0x4714, {0xb7, 0xda, 0xa9, 0xad,0x87, 0xd4,
> > +0xda,
> > 0xc9 } \
> > +  }
> > +
> > +typedef struct _EFI_REST_JSON_STRUCTURE_PROTOCOL
> > EFI_REST_JSON_STRUCTURE_PROTOCOL;
> > +typedef CHAR8 * EFI_REST_JSON_RESOURCE_TYPE_DATATYPE;
> > +typedef CHAR8 * EFI_REST_RESOURCE_RELATIVE_PATH;
> EFI_REST_RESOURCE_RELATIVE_PATH is not in UEFI spec. Can you confirm it?
Good catch. We don’t use this anymore.
> 
> > +
> > +/** Structure defintions of resource name space.
> > +  *
> > +  * The fields declared in this structure define the
> > +  * name and revision of payload delievered throught
> > +  * REST API.
> > +**/
> 
> Structure comments start with /// or //. /**/ style is for the function.
> Please update them.
> 
> > +typedef struct _EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE {
> > +  CHAR8 *ResourceTypeName;   ///< Resource type name
> > +  CHAR8 *MajorVersion;       ///< Resource major version
> > +  CHAR8 *MinorVersion;       ///< Resource minor version
> > +  CHAR8 *ErrataVersion;      ///< Resource errata version
> > +} EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE;
> > +
> > +/** REST resource type identifier
> > +  *
> > +  * REST resource type consists of name space and data type.
> > +**/
> > +typedef struct _EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER {
> > +  EFI_REST_JSON_RESOURCE_TYPE_NAMESPACE NameSpace; ///<
> > Namespace of this resource type.
> > +  EFI_REST_JSON_RESOURCE_TYPE_DATATYPE DataType;   ///< Name of
> > data type declared in this
> > +                                                   ///<
> > resource type.
> > +} EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER;
> > +
> > +/** List of JSON to C structure conversions which this convertor
> supports.
> > +  *
> > +**/
> > +typedef struct _EFI_REST_JSON_STRUCTURE_SUPPORTED {
> > +  LIST_ENTRY NextSupportedRsrcInterp;                        ///<
> > Linklist to next supported conversion.
> > +  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER RestResourceInterp; ///<
> > JSON resource type this convertor supports.
> > +} EFI_REST_JSON_STRUCTURE_SUPPORTED;
> > +
> > +/** The header file of JSON C structure
> > +  *
> > +**/
> > +typedef struct _EFI_REST_JSON_STRUCTURE_HEADER {
> > +  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER    JsonRsrcIdentifier;
> > ///< Resource identifier which use to
> > +
> > ///< choice the proper interpreter.
> > +  ///< Follow by a pointer points to JSON structure, the content in
> > + the  ///< JSON structure is implementation-specific according to
> > + converter
> > producer.
> > +  ///
> > +  VOID  *JsonStructurePointer;
> > +}  EFI_REST_JSON_STRUCTURE_HEADER;
> > +
> > +/**
> > +  JSON-IN C Structure-OUT function. Convert the given REST JSON
> > +resource
> > into structure.
> > +
> > +  @param[in]    This                This is the
> > EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
> > +  @param[in]    JsonRsrcIdentifier  This indicates the resource type and
> > version is given in
> > +                                    ResourceJsonText.
> > +  @param[in]    ResourceJsonText    REST JSON resource in text
> > format.
> > +  @param[out]   JsonStructure       Pointer to receive the pointer to
> > EFI_REST_JSON_STRUCTURE_HEADER
> > +
> > +  @retval EFI_SUCCESS
> > +  @retval Others
> > +--*/
> > +typedef
> > +EFI_STATUS
> > +(EFIAPI *EFI_REST_JSON_STRUCTURE_TO_STRUCTURE)(
> > +  IN  EFI_REST_JSON_STRUCTURE_PROTOCOL        *This,
> > +  IN  EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *JsonRsrcIdentifier
> > OPTIONAL,
> > +  IN  CHAR8
> > *ResourceJsonText,
> > +  OUT  EFI_REST_JSON_STRUCTURE_HEADER         **JsonStructure
> > +);
> > +
> > +/**
> > +  Convert the given REST JSON structure into JSON text.
> > +
> > +  @param[in]    This                 This is the
> > EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
> > +  @param[in]    JsonStructureHeader  The point to
> > EFI_REST_JSON_STRUCTURE_HEADER  structure.
> > +  @param[out]   ResourceJsonText     Pointer to receive REST JSON
> > resource in text format.
> > +
> > +  @retval EFI_SUCCESS
> > +  @retval Others
> > +
> > +--*/
> > +typedef
> > +EFI_STATUS
> > +(EFIAPI *EFI_REST_JSON_STRUCTURE_TO_JSON)(
> > +  IN EFI_REST_JSON_STRUCTURE_PROTOCOL     *This,
> > +  IN EFI_REST_JSON_STRUCTURE_HEADER       *JsonStructureHeader,
> > +  OUT CHAR8                               **ResourceJsonText
> > +);
> > +
> > +/**
> > +  This function destroys the REST JSON structure.
> > +
> > +  @param[in]    This                 This is the
> > EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
> > +  @param[in]    JsonStructureHeader  JSON structure to destroy.
> > +
> > +  @retval EFI_SUCCESS
> > +  @retval Others
> > +
> > +--*/
> > +typedef
> > +EFI_STATUS
> > +(EFIAPI *EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE)(
> > +  IN EFI_REST_JSON_STRUCTURE_PROTOCOL   *This,
> > +  IN EFI_REST_JSON_STRUCTURE_HEADER     *JsonStructureHeader
> > +);
> > +/**
> > +  This function provides REST JSON resource to structure converter
> > registration.
> > +
> > +  @param[in]    This                     This is the
> > EFI_REST_JSON_STRUCTURE_PROTOCOL instance.
> > +  @param[in]    JsonStructureSupported   The type and version of REST
> > JSON resource which this converter
> > +                                         supports.
> > +  @param[in]    ToStructure              The function to convert
> > REST JSON resource to structure.
> > +  @param[in]    ToJson                   The function to convert
> > REST JSON structure to JSON in text format.
> > +  @param[out]   DestroyStructure         Destroy REST JSON
> > structure returned in ToStructure()  function.
> > +
> > +  @retval EFI_SUCCESS             Register successfully.
> > +  @retval Others                  Fail to register.
> > +
> > +--*/
> > +typedef
> > +EFI_STATUS
> > +(EFIAPI *EFI_REST_JSON_STRUCTURE_REGISTER)(
> > +  IN EFI_REST_JSON_STRUCTURE_PROTOCOL       *This,
> > +  IN EFI_REST_JSON_STRUCTURE_SUPPORTED
> > *JsonStructureSupported,
> > +  IN EFI_REST_JSON_STRUCTURE_TO_STRUCTURE   ToStructure,
> > +  IN EFI_REST_JSON_STRUCTURE_TO_JSON        ToJson,
> > +  IN EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE
> DestroyStructure );
> > +
> > +/** EFI REST JSON to C structure protocol definition.
> > +  *
> > +**/
> > +typedef struct _EFI_REST_JSON_STRUCTURE_PROTOCOL {
> > +  EFI_REST_JSON_STRUCTURE_REGISTER           Register;
> > ///< Register JSON to C structure convertor
> > +  EFI_REST_JSON_STRUCTURE_TO_STRUCTURE       ToStructure;
> > ///< The function to convert JSON to C structure
> > +  EFI_REST_JSON_STRUCTURE_TO_JSON            ToJson;
> > ///< The function to convert C structure to JSON
> > +  EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE  DestoryStructure;
> > ///< Destory C structure.
> > +} EFI_REST_JSON_STRUCTURE_PROTOCOL;
> 
> Here, typedef is not required, because
> EFI_REST_JSON_STRUCTURE_PROTOCOL has been defined in the begin of
> this file.
> 
All comments were addressed, v2 was sent.
Thanks.

> Thanks
> Liming
> > +
> > +#endif
> > diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index
> > 812be75fb3..0943816825 100644
> > --- a/MdePkg/MdePkg.dec
> > +++ b/MdePkg/MdePkg.dec
> > @@ -1848,6 +1848,12 @@
> >    ## Include/Protocol/NvdimmLabel.h
> >    gEfiNvdimmLabelProtocolGuid               = { 0xd40b6b80, 0x97d5,
> > 0x4282, { 0xbb, 0x1d, 0x22, 0x3a, 0x16, 0x91, 0x80, 0x58 }}
> >
> > +  #
> > +  # Protocols defined in UEFI2.8
> > +  #
> > +  ## Include/Protocol/RestJsonStructure.h
> > +  gEfiRestJsonStructureProtocolGuid  = { 0xa9a048f6, 0x48a0, 0x4714,
> > {0xb7, 0xda, 0xa9, 0xad,0x87, 0xd4, 0xda, 0xc9 }}
> > +
> >    #
> >    # Protocols defined in Shell2.0
> >    #
> > --
> > 2.17.1
> >
> >
> >
> > 
> >
> 
> 


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

* Re: [edk2-devel] [RestJsonStructureDxe PATCH 0/2] EFI REST JSON Structure Protocol
  2020-10-12  1:51   ` Abner Chang
@ 2020-10-20  1:05     ` Abner Chang
  0 siblings, 0 replies; 8+ messages in thread
From: Abner Chang @ 2020-10-20  1:05 UTC (permalink / raw)
  To: devel@edk2.groups.io, spbrogan@outlook.com
  Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Jiaxin Wu, Siyuan Fu,
	Fan Wang, Jiewen Yao, Wang, Nickle (HPS SW)

Hi Sean,
Any feedbacks on my reply?

Thanks
Abner

> -----Original Message-----
> From: Chang, Abner (HPS SW/FW Technologist)
> Sent: Monday, October 12, 2020 9:51 AM
> To: devel@edk2.groups.io; spbrogan@outlook.com
> Cc: Michael D Kinney <michael.d.kinney@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com>; Jiaxin
> Wu <jiaxin.wu@intel.com>; Siyuan Fu <siyuan.fu@intel.com>; Fan Wang
> <fan.wang@intel.com>; Jiewen Yao <jiewen.yao@intel.com>; Wang, Nickle
> (HPS SW) <nickle.wang@hpe.com>
> Subject: RE: [edk2-devel] [RestJsonStructureDxe PATCH 0/2] EFI REST JSON
> Structure Protocol
> 
> No you didn’t miss have discussions. However, you can help me to
> understand Unit test framework.
> 
> There are some levels of the unit test, I don’t know how much we can do in
> the current CI/UnitTestFramework and how much effort would be left to the
> new (also the existing) package developers.
> 
> 1. The code coverage test,  can this launched by CI? This one should be
> relatively simple if it can run automatically (like to launch Coverity) and gives
> report to developers.
> 2. Code path test, developers have to write the unit test drivers/apps under
> UnitTest? Developers decide how to run the function validations on
> input/output parameter and/or some other basic API functionality test?
> 3. The feature test for the hardware independent functionalities or some
> features which have the corresponding simulator like network stacks. But I
> think this is more like the platform-level test, right? Maybe this is not in
> UnittestFramework scope?
> 
> I take a look into UnitTestFramework and only see a simple sample unit test
> driver, is this the only implementation?  Any edk2 packages or drivers has its
> own unit test yet?
> Do you have some links to the edk2 Unit Test Writer guide?
> 
> Thanks
> Abner
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> > Sean
> > Sent: Friday, October 9, 2020 11:03 AM
> > To: devel@edk2.groups.io; Chang, Abner (HPS SW/FW Technologist)
> > <abner.chang@hpe.com>
> > Cc: Michael D Kinney <michael.d.kinney@intel.com>; Liming Gao
> > <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com>;
> > Jiaxin Wu <jiaxin.wu@intel.com>; Siyuan Fu <siyuan.fu@intel.com>; Fan
> > Wang <fan.wang@intel.com>; Jiewen Yao <jiewen.yao@intel.com>; Wang,
> > Nickle (HPS SW) <nickle.wang@hpe.com>
> > Subject: Re: [edk2-devel] [RestJsonStructureDxe PATCH 0/2] EFI REST
> > JSON Structure Protocol
> >
> > Abner,
> >
> > As you add this RedfishPkg and significant new code to edk2 have you
> > thought about authoring unit tests.  One of the goals of the unit test
> > work that was enabled nearly 1 year ago was to make it easy for
> > developers to write unit tests and to continually run them during PR
> > and CI runs in the hope that as a community we might start authoring unit
> tests with new code.
> >
> > Personally i would like to see a process that new modules can not be
> > added without unit tests and relatively high code coverage.
> >
> > Was there any thought to that?  Has there been discussion i may have
> missed?
> >
> > Thanks
> > Sean
> >
> >
> >
> > On 10/8/2020 8:10 AM, Abner Chang wrote:
> > > This is the implementation of EFI_REST_JSON_STRUCTURE_PROTOCOL,
> > refer
> > > to UEFI spec 2.8 Section 29.7.3 EFI REST JSON Resource to C
> > > Structure Converter.
> > >
> > > Signed-off-by: Abner Chang <abner.chang@hpe.com>
> > >
> > > Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > > Cc: Zhiguang Liu <zhiguang.liu@intel.com>
> > > Cc: Jiaxin Wu <jiaxin.wu@intel.com>
> > > Cc: Siyuan Fu <siyuan.fu@intel.com>
> > > Cc: Fan Wang <fan.wang@intel.com>
> > > Cc: Jiewen Yao <jiewen.yao@intel.com>
> > > Cc: Nickle Wang <nickle.wang@hpe.com>
> > >
> > > Abner Chang (2):
> > >    MdePkg/Include: Definitions of EFI REST JSON Structure Protocol
> > >    RedfishPkg/RestJsonStructureDxe: EFI REST JSON Structure Protocol
> > >
> > >   MdePkg/Include/Protocol/RestJsonStructure.h   | 160 +++++
> > >   MdePkg/MdePkg.dec                             |   6 +
> > >   RedfishPkg/RedfishPkg.dsc                     |   3 +
> > >   .../RestJsonStructureDxe.c                    | 583 ++++++++++++++++++
> > >   .../RestJsonStructureDxe.inf                  |  40 ++
> > >   .../RestJsonStructureInternal.h               |  35 ++
> > >   6 files changed, 827 insertions(+)
> > >   create mode 100644 MdePkg/Include/Protocol/RestJsonStructure.h
> > >   create mode 100644
> > RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.c
> > >   create mode 100644
> > RedfishPkg/RestJsonStructureDxe/RestJsonStructureDxe.inf
> > >   create mode 100644
> > > RedfishPkg/RestJsonStructureDxe/RestJsonStructureInternal.h
> > >
> >
> >
> > 
> >


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

end of thread, other threads:[~2020-10-20  1:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-08 15:10 [RestJsonStructureDxe PATCH 0/2] EFI REST JSON Structure Protocol Abner Chang
2020-10-08 15:10 ` [RestJsonStructureDxe PATCH 1/2] MdePkg/Include: Definitions of " Abner Chang
2020-10-14  5:42   ` 回复: [edk2-devel] " gaoliming
2020-10-14 15:07     ` Abner Chang
2020-10-08 15:10 ` [RestJsonStructureDxe PATCH 2/2] RedfishPkg/RestJsonStructureDxe: " Abner Chang
2020-10-09  3:02 ` [edk2-devel] [RestJsonStructureDxe PATCH 0/2] " Sean
2020-10-12  1:51   ` Abner Chang
2020-10-20  1:05     ` Abner Chang

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