public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-test][Patch 1/1] uefi-sct/SctPkg:Implement iSCSI DevicePathToText Test
@ 2019-03-11  2:43 Eric Jin
  2019-03-25 13:12 ` Supreeth Venkatesh
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Jin @ 2019-03-11  2:43 UTC (permalink / raw)
  To: edk2-devel

It is the new checkpoint of iSCSI DevicePathToText.
The Lun display is to follow with the UEFI Spec that
"The LUN is an 8 byte array that is displayed in
hexadecimal format with byte 0 first (i.e., on the
left) and byte 7 last (i.e, on the right).

Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Jin <eric.jin@intel.com>
---
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.h                           |  9 ++++++++-
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestCoverage.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestMain.c     | 41 +++++++++++++++++++++++++++++++++--------
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.c                           |  3 ++-
 4 files changed, 94 insertions(+), 12 deletions(-)

diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.h b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.h
index 41d2a8a837f5..b03903ca0971 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.h
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.h
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright 2006 - 2016 Unified EFI, Inc.<BR>
-  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -400,3 +400,10 @@ extern EFI_GUID gDevicePathToTextBBTestFunctionAssertionGuid133;
   }
 
 extern EFI_GUID gDevicePathToTextBBTestFunctionAssertionGuid134;
+
+#define EFI_TEST_DEVICEPATHTOTEXTBBTESTFUNCTION_ASSERTION_135_GUID \
+  { \
+    0xbf73c00e, 0x5a62, 0x4a20, { 0xbe, 0x15, 0x4d, 0x83, 0x7e, 0xe5, 0x7d, 0xdf } \
+  }
+extern EFI_GUID gDevicePathToTextBBTestFunctionAssertionGuid135;
+
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestCoverage.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestCoverage.c
index c30af4345158..ee91bdfb63d3 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestCoverage.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestCoverage.c
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright 2006 - 2017 Unified EFI, Inc.<BR>
-  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -2202,7 +2202,56 @@ DevicePathToTextConvertDeviceNodeToTextCoverageTest (
     SctFreePool (Text);
   }
 
-  
+  //
+  // The stardand Text in spec is iSCSI(TargetName, PortalGroup, LUN, HeaderDigest, DataDigest, Authentication, Protocol)
+  // The test use iSCSI(Name,0x12AB,0x0000005678000000,CRC32C,None,CHAP_BI,TCP) as the input to check binary/text convertion
+  //
+  // sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + 4 is the length of iSCSI Device Path Node plus Target Name
+  // The Targat Name is "Name" in this case
+  // The default protocol used by iSCSI is TCP(0), and 1+ is reserved in UEFI 2.7 spec
+  // The combination of HeaderDigest, DataDigest and Authentication in this case is 0002
+  // The Lun is 0x0000007856000000 in this case to detect the possible display order issue
+  // please refer to section 10.3.5.21 and Table 102 of UEFI 2.7 Spec for detail.
+  //
+  pDeviceNode1 = DevicePathUtilities->CreateDeviceNode (0x3, 0x13, sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + 4);
+  ((ISCSI_DEVICE_PATH_WITH_NAME *)pDeviceNode1)->NetworkProtocol = 0x0;
+  ((ISCSI_DEVICE_PATH_WITH_NAME *)pDeviceNode1)->LoginOption = 0x0002;
+  ((ISCSI_DEVICE_PATH_WITH_NAME *)pDeviceNode1)->Lun = 0x0000007856000000;
+  ((ISCSI_DEVICE_PATH_WITH_NAME *)pDeviceNode1)->TargetPortalGroupTag = 0x12AB;
+  ((ISCSI_DEVICE_PATH_WITH_NAME *)pDeviceNode1)->iSCSITargetName[0] = 'N';
+  ((ISCSI_DEVICE_PATH_WITH_NAME *)pDeviceNode1)->iSCSITargetName[1] = 'a';
+  ((ISCSI_DEVICE_PATH_WITH_NAME *)pDeviceNode1)->iSCSITargetName[2] = 'm';
+  ((ISCSI_DEVICE_PATH_WITH_NAME *)pDeviceNode1)->iSCSITargetName[3] = 'e';
+
+  Text = DevicePathToText->ConvertDeviceNodeToText (pDeviceNode1, FALSE, FALSE);
+  pDeviceNode2 = SctConvertTextToDeviceNode(Text);
+
+  if ((pDeviceNode2 != NULL) && (SctCompareMem (pDeviceNode2, pDeviceNode1, SctDevicePathNodeLength(pDeviceNode1)) == 0)) {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                StandardLib,
+                AssertionType,
+                gDevicePathToTextBBTestFunctionAssertionGuid135,
+                L"EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL - ConvertDeviceNodeToText must correctly recover the converting ConvertTextToDeviceNode has acted on the device node string",
+                L"%a:%d: Convert result: %s - Expected:iSCSI(MyTargetName,0x12AB,0x0000005678000000,CRC32C,None,CHAP_BI,TCP)",
+                __FILE__,
+                (UINTN)__LINE__,
+                Text
+                );
+  if (pDeviceNode1 != NULL) {
+    SctFreePool (pDeviceNode1);
+  }
+  if (pDeviceNode2 != NULL) {
+    SctFreePool (pDeviceNode2);
+  }
+  if (Text != NULL) {
+    SctFreePool (Text);
+  }
+
   return EFI_SUCCESS;
 }
 
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestMain.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestMain.c
index 41cf217b5f88..d08097769391 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestMain.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/DevicePathToTextBBTestMain.c
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright 2006 - 2017 Unified EFI, Inc.<BR>
-  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -2437,34 +2437,40 @@ BuildiSCSIDeviceNode (
   CHAR16                         *LunStr;
   UINT16                         Options;
   UINT64                         LunNum;
+  UINT64                         TempLunNum;
 
   Status = GetNextRequiredParam(&TextDeviceNode, L"TargetName", &ParamIdentifierStr, &ParamIdentifierVal);
   if ((!EFI_ERROR(Status)) && (ParamIdentifierVal != NULL)) {
     NameStr = ParamIdentifierVal;
   } else {
-  	return NULL;
+    return NULL;
   }
 
   Status = GetNextRequiredParam(&TextDeviceNode, L"PortalGroup", &ParamIdentifierStr, &ParamIdentifierVal);
   if ((!EFI_ERROR(Status)) && (ParamIdentifierVal != NULL)) {
     PortalGroupStr = ParamIdentifierVal;
   } else {
-  	return NULL;
+    return NULL;
   }
 
   Status = GetNextRequiredParam(&TextDeviceNode, L"LUN", &ParamIdentifierStr, &ParamIdentifierVal);
   if ((!EFI_ERROR(Status)) && (ParamIdentifierVal != NULL)) {
     LunStr = ParamIdentifierVal;
   } else {
-  	return NULL;
+    return NULL;
   }
 
-  Length = sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + (UINT16) (SctStrLen (NameStr) * 2 + 2);
+  Length = sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + (UINT16) (SctStrLen (NameStr));
   iSCSI = (ISCSI_DEVICE_PATH_WITH_NAME *) CreateDeviceNode (0x3, 0x13, Length);
   if (iSCSI == NULL) {
-  	return NULL;
+    return NULL;
   }
 
+
+  //
+  // The iSCSI Device Node Options describe iSCSI login options for the key values
+  // Please refer to the section 10.3.5.21 of the UEFI 2.7 spec for the detail
+  //
   Options = 0x0000;
 
   for (OptionalParamIndex = 0;OptionalParamIndex < 5; OptionalParamIndex++) {
@@ -2499,7 +2505,7 @@ BuildiSCSIDeviceNode (
         if (SctStrCmp (ParamIdentifierVal, L"CRC32C") == 0) {
           Options |= 0x0002;
         }
-		break;
+        break;
 
       case 1:  // DataDigest
         if (SctStrCmp (ParamIdentifierVal, L"CRC32C") == 0) {
@@ -2514,6 +2520,9 @@ BuildiSCSIDeviceNode (
         if (SctStrCmp (ParamIdentifierVal, L"CHAP_UNI") == 0) {
           Options |= 0x1000;
         }
+        if (SctStrCmp (ParamIdentifierVal, L"CHAP_BI") == 0) {
+          Options |= 0x0000;
+        }
         break;
 
       case 3:  // Protocol
@@ -2533,8 +2542,24 @@ BuildiSCSIDeviceNode (
 
   SctUnicodeToAscii (iSCSI->iSCSITargetName, NameStr, SctStrLen (NameStr));
   iSCSI->TargetPortalGroupTag = (UINT16) SctStrToUInt (PortalGroupStr);
-  SctStrToUInt64 (LunStr, &LunNum);
+
+  //
+  // The LUN is an 8 byte array that is displayed in hexadecimal format with byte
+  // 0 first (i.e., on the left) and byte 7 last (i.e, on the right), and is required.
+  //
+  SctStrToUInt64 (LunStr, &TempLunNum);
+  LunNum = 0;
+
+  LunNum = SctLShiftU64((TempLunNum & 0x00000000000000FF), 56);;
+  LunNum = LunNum | SctLShiftU64((TempLunNum & 0x000000000000FF00), 40);
+  LunNum = LunNum | SctLShiftU64((TempLunNum & 0x0000000000FF0000), 24);
+  LunNum = LunNum | SctLShiftU64((TempLunNum & 0x00000000FF000000), 8);
+  LunNum = LunNum | SctRShiftU64((TempLunNum & 0x000000FF00000000), 8);
+  LunNum = LunNum | SctRShiftU64((TempLunNum & 0x0000FF0000000000), 24);
+  LunNum = LunNum | SctRShiftU64((TempLunNum & 0x00FF000000000000), 40);
+  LunNum = LunNum | SctRShiftU64((TempLunNum & 0xFF00000000000000), 56);
   iSCSI->Lun = LunNum;
+
   iSCSI->LoginOption = (UINT16) Options;
 
   return (EFI_DEVICE_PATH_PROTOCOL *) iSCSI;
diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.c
index 9cad8d31d384..1eeb3552093f 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/DevicePathToText/BlackBoxTest/Guid.c
@@ -1,7 +1,7 @@
 /** @file
 
   Copyright 2006 - 2015 Unified EFI, Inc.<BR>
-  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -136,3 +136,4 @@ EFI_GUID  gDevicePathToTextBBTestFunctionAssertionGuid133 = EFI_TEST_DEVICEPATHT
 
 EFI_GUID  gDevicePathToTextBBTestFunctionAssertionGuid134 = EFI_TEST_DEVICEPATHTOTEXTBBTESTFUNCTION_ASSERTION_134_GUID;
 
+EFI_GUID  gDevicePathToTextBBTestFunctionAssertionGuid135 = EFI_TEST_DEVICEPATHTOTEXTBBTESTFUNCTION_ASSERTION_135_GUID;
-- 
2.20.0.windows.1



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

end of thread, other threads:[~2019-03-25 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-11  2:43 [edk2-test][Patch 1/1] uefi-sct/SctPkg:Implement iSCSI DevicePathToText Test Eric Jin
2019-03-25 13:12 ` Supreeth Venkatesh

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