From: Joseph Hemann <joseph.hem...@arm.com>

-add test for GetEventLog()
  -test for valid and invalid event log format
  -test event log header
  -verify expected event log entry

Signed-off-by: Joseph Hemann <joseph.hem...@arm.com>
Signed-off-by: Stuart Yoder <stuart.yo...@arm.com>
---
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h            
              |  20 ++
 
uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h
            |  17 ++
 uefi-sct/SctPkg/UEFI/Protocol/TCG2.h                                           
              |  46 +++++
 uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c            
              |   8 +
 
uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c
 | 207 +++++++++++++++++++-
 5 files changed, 297 insertions(+), 1 deletion(-)

diff --git 
a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h 
b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h
index dcfd5919acda..746ff83f899c 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.h
@@ -85,3 +85,23 @@ extern EFI_GUID gTcg2ConformanceTestAssertionGuid011;
 { 0x9cd6d636, 0x603a, 0x4b78, {0x80, 0xa3, 0xa3, 0xb9, 0xcc, 0x6a, 0x0b, 0x08 
}}
 
 extern EFI_GUID gTcg2ConformanceTestAssertionGuid012;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_013_GUID \
+{ 0xfc80408e, 0x9a3c, 0x4054, {0x96, 0xf9, 0x31, 0x23, 0x35, 0xc2, 0x31, 0x35 
}}
+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid013;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_014_GUID \
+{ 0x45fa1a42, 0x912a, 0x5124, {0x84, 0xf4, 0x41, 0x67, 0xab, 0xb5, 0x89, 0x90 
}}
+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid014;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_015_GUID \
+{ 0x1689bc3a, 0x2298, 0xa116, {0x28, 0x4c, 0xc1, 0xdd, 0xaa, 0xd8, 0xef, 0x51 
}}
+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid015;
+
+#define EFI_TEST_TCG2CONFORMANCE_ASSERTION_016_GUID \
+{ 0x126a789a, 0x1932, 0x3234, {0x21, 0xab, 0x42, 0x64, 0x8a, 0x7b, 0x63, 0x76 
}}
+
+extern EFI_GUID gTcg2ConformanceTestAssertionGuid016;
diff --git 
a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h
 
b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h
index cbbadef4a5c7..5ce275dc6258 100644
--- 
a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h
+++ 
b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTest.h
@@ -43,8 +43,13 @@ Abstract:
 #define EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0103 \
  {0x907a7878, 0xb294, 0xf147, {0xe9, 0x0a, 0x65, 0x43, 0xab, 0x55, 0x76, 0x46} 
}
 
+#define EFI_TCG2_PROTOCOL_TEST_ENTRY_GUID0104 \
+ {0x9087ad78, 0x9ad2, 0x4172, {0x9a, 0xbc, 0x98, 0x23, 0x08, 0xf5, 0x6d, 0x26} 
}
+
 #define EV_POST_CODE 0x01
 
+#define EV_NO_ACTION 0x03
+
 #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001
 
 #define PE_COFF_IMAGE 0x0000000000000010
@@ -103,6 +108,18 @@ BBTestHashLogExtendEventConformanceTestCheckpoint2 (
   IN EFI_TCG2_PROTOCOL                     *TCG2
   );
 
+EFI_STATUS
+BBTestGetEventLogConformanceTestCheckpoint1 (
+  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,
+  IN EFI_TCG2_PROTOCOL                     *TCG2
+  );
+
+EFI_STATUS
+BBTestGetEventLogConformanceTestCheckpoint2 (
+  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,
+  IN EFI_TCG2_PROTOCOL                     *TCG2
+  );
+
 EFI_STATUS
 BBTestGetCapabilityConformanceTest (
   IN EFI_BB_TEST_PROTOCOL       *This,
diff --git a/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h 
b/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h
index 659c61a741e7..73e800af6205 100644
--- a/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h
+++ b/uefi-sct/SctPkg/UEFI/Protocol/TCG2.h
@@ -50,6 +50,8 @@ Abstract:
 
 #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
 
+#define HASH_NUMBER 0x04
+
 typedef struct _EFI_TCG2_PROTOCOL EFI_TCG2_PROTOCOL;
 
 typedef UINT64 EFI_PHYSICAL_ADDRESS;
@@ -117,6 +119,50 @@ typedef struct tdEFI_TCG2_EVENT {
   UINT8 Event[];
 } EFI_TCG2_EVENT;
 
+typedef struct {
+  UINT16     hashAlg;
+  UINT8      digest[];
+} TPMT_HA;
+
+typedef struct tdTPML_DIGEST_VALUES {
+  UINT32 Count;                    // number of digests
+  TPMT_HA Digests[HASH_NUMBER];    // Count digests
+} TPML_DIGEST_VALUES;
+
+// This Declaration is for parsing the eventlog header which is defined to be 
20 bytes in TCG EFI Protocol Spec
+typedef UINT8 TCG_DIGEST[20];
+
+typedef struct tdTCG_PCR_EVENT2 {
+  TCG_PCRINDEX PCRIndex;       // PCRIndex event extended to
+  TCG_EVENTTYPE EventType;     // Type of event (see [2])
+  TPML_DIGEST_VALUES Digests;  // List of digests extended to //PCRIndex
+  UINT32 EventSize;            // Size of the event data
+  UINT8 *Event;                // The event data
+} TCG_PCR_EVENT2;
+
+typedef struct tdTCG_PCR_EVENT {
+  UINT32 PCRIndex; // PCRIndex event extended to
+  UINT32 EventType; // Type of event (see EFI specs)
+  TCG_DIGEST Digest; // Value extended into PCRIndex
+  UINT32 EventSize; // Size of the event data
+  UINT8 Event[0]; // The event data
+} TCG_PCR_EVENT;
+// Structure to be added to the Event Log
+
+typedef struct tdTCG_EfiSpecIdEventAlgorithmSize {
+  UINT16 algorithmId;
+  UINT16 digestSize;
+} TCG_EfiSpecIdEventAlgorithmSize;
+
+typedef struct tdTCG_EfiSpecIdEventStruct {
+   UINT8 signature[16];
+   UINT32 platformClass;
+   UINT8 specVersionMinor;
+   UINT8 specVersionMajor;
+   UINT8 specErrata;
+   UINT8 uintnSize;
+} TCG_EfiSpecIDEventStruct;
+
 #pragma pack()
 
 typedef
diff --git 
a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c 
b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c
index ccc20259d128..8c528aa8ddfc 100644
--- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c
+++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/Guid.c
@@ -51,3 +51,11 @@ EFI_GUID gTcg2ConformanceTestAssertionGuid010 = 
EFI_TEST_TCG2CONFORMANCE_ASSERTI
 EFI_GUID gTcg2ConformanceTestAssertionGuid011 = 
EFI_TEST_TCG2CONFORMANCE_ASSERTION_011_GUID;
 
 EFI_GUID gTcg2ConformanceTestAssertionGuid012 = 
EFI_TEST_TCG2CONFORMANCE_ASSERTION_012_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid013 = 
EFI_TEST_TCG2CONFORMANCE_ASSERTION_013_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid014 = 
EFI_TEST_TCG2CONFORMANCE_ASSERTION_014_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid015 = 
EFI_TEST_TCG2CONFORMANCE_ASSERTION_015_GUID;
+
+EFI_GUID gTcg2ConformanceTestAssertionGuid016 = 
EFI_TEST_TCG2CONFORMANCE_ASSERTION_016_GUID;
diff --git 
a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c
 
b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c
index 2768eef725e8..ebe04d42aff5 100644
--- 
a/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c
+++ 
b/uefi-sct/SctPkg/TestCase/UEFI/EFI/Protocol/TCG2/BlackBoxTest/TCG2ProtocolBBTestConformance.c
@@ -142,7 +142,7 @@ BBTestGetActivePcrBanksConformanceTest (
 
 /**
  *  @brief Entrypoint for HashLogExtendEvent() Function Test.
- *         2 checkpoints will be tested.
+ *         4 checkpoints will be tested.
  *  @param This a pointer of EFI_BB_TEST_PROTOCOL
  *  @param ClientInterface A pointer to the interface array under test
  *  @param TestLevel Test "thoroughness" control
@@ -188,6 +188,12 @@ BBTestHashLogExtendEventConformanceTest (
   // Test HashLogExtendEvent with valid arguments
   BBTestHashLogExtendEventConformanceTestCheckpoint2 (StandardLib, TCG2);
 
+  // Test GetEventLog using invalid EventLog Format
+  BBTestGetEventLogConformanceTestCheckpoint1 (StandardLib, TCG2);
+
+  // Test GetEventLog using valid EventLog Format
+  BBTestGetEventLogConformanceTestCheckpoint2 (StandardLib, TCG2);
+
   return EFI_SUCCESS;
 }
 
@@ -801,3 +807,202 @@ BBTestHashLogExtendEventConformanceTestCheckpoint2 (
 
   return EFI_SUCCESS;
 }
+
+#define EFI_TCG2_INVALID_EVENT_LOG_FORMAT 0x20
+
+EFI_STATUS
+BBTestGetEventLogConformanceTestCheckpoint1 (
+  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,
+  IN EFI_TCG2_PROTOCOL                     *TCG2
+  )
+{
+  EFI_TEST_ASSERTION                    AssertionType;
+  EFI_STATUS                            Status;
+  EFI_TCG2_EVENT_LOG_FORMAT             EventLogFormat;
+  EFI_PHYSICAL_ADDRESS                  EventLogLocation;
+  EFI_PHYSICAL_ADDRESS                  EventLogLastEntry;
+  BOOLEAN                               EventLogTruncated;
+
+  // Ensure Get EventLog returns Invalid Parameter when passed invalid format
+  EventLogFormat = EFI_TCG2_INVALID_EVENT_LOG_FORMAT;
+
+  Status = TCG2->GetEventLog (
+                           TCG2,
+                           EventLogFormat,
+                           &EventLogLocation,
+                           &EventLogLastEntry,
+                           &EventLogTruncated);
+
+  if (EFI_INVALID_PARAMETER != Status) {
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  } else {
+    AssertionType = EFI_TEST_ASSERTION_PASSED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gTcg2ConformanceTestAssertionGuid013,
+                 L"TCG2_PROTOCOL.GetEventLog - GetEventLog() should return 
EFI_INVALID_PARAMETER when passed in invalid EventLog Format",
+                 L"%a:%d: Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+BBTestGetEventLogConformanceTestCheckpoint2 (
+  IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL    *StandardLib,
+  IN EFI_TCG2_PROTOCOL                     *TCG2
+  )
+{
+  EFI_TEST_ASSERTION                    AssertionType;
+  EFI_STATUS                            Status;
+  EFI_TCG2_EVENT_LOG_FORMAT             EventLogFormat;
+  EFI_PHYSICAL_ADDRESS                  EventLogLocation;
+  EFI_PHYSICAL_ADDRESS                  EventLogLastEntry;
+  BOOLEAN                               EventLogTruncated;
+  TCG_PCR_EVENT                         *EventLogHeader;
+  TCG_EfiSpecIDEventStruct              *EventLogHeaderSpecEvent;
+  TCG_PCR_EVENT2                        *LastEvent;
+  // signature as defined in the EFI protocol spec: "Spec ID Event03"
+  UINT8 signature[] = {0x53, 0x70, 0x65, 0x63, 0x20, 0x49, 0x44, 0x20, 0x45, 
0x76, 0x65, 0x6e, 0x74, 0x30, 0x33, 0x00};
+
+  EventLogFormat = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
+
+  // Call GetEventLog with valid EventLogFormat
+  Status = TCG2->GetEventLog (
+                           TCG2,
+                           EventLogFormat,
+                           &EventLogLocation,
+                           &EventLogLastEntry,
+                           &EventLogTruncated);
+
+  AssertionType = EFI_TEST_ASSERTION_PASSED;
+
+  // Verify GetEventLog returns EFI_SUCCESS
+  if (Status != EFI_SUCCESS) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: GetEventLog should 
return EFI_SUCCESS with valid EventLogFormat, Status = %r",
+                     Status
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gTcg2ConformanceTestAssertionGuid014,
+                 L"TCG2_PROTOCOL.GetEventLog - GetEventLog() should return 
EFI_SUCCESS",
+                 L"%a:%d: Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  // If GetEventLog doesn't return EFI_SUCCESS abort test
+  if (Status != EFI_SUCCESS) {
+    return Status;
+  }
+
+  EventLogHeader = (TCG_PCR_EVENT *) EventLogLocation;
+  EventLogHeaderSpecEvent = (TCG_EfiSpecIDEventStruct *) EventLogHeader->Event;
+
+  AssertionType = EFI_TEST_ASSERTION_PASSED;
+
+
+  // Verify valid eventlog header is returned
+  // Verify EventLogHeader PCR index == 0
+  if (EventLogHeader->PCRIndex != 0) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: EventLogHeader 
should have PCR index == 0"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  // Verify EventLogHeader event type = EV_NO_ACTION
+  if (EventLogHeader->EventType != EV_NO_ACTION) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: EventLogHeader 
should be EventType == EV_NO_ACTION"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  // Verify EventLog Signature
+  Status = SctCompareMem(EventLogHeaderSpecEvent->signature, signature, 
sizeof(signature));
+
+  if (Status != EFI_SUCCESS) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: EventLogHeader 
Signature did not match \'Spec ID Event03\'"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gTcg2ConformanceTestAssertionGuid015,
+                 L"TCG2_PROTOCOL.GetEventLog - GetEventLog() should return 
correct EventLogHeader",
+                 L"%a:%d: Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  // Verify that the event log created by HashLogExtendEvent in the
+  // BBTestHashLogExtendEventConformanceTestCheckpoint2 function
+  // is actually in Eventlog
+  LastEvent = (TCG_PCR_EVENT2 *) EventLogLastEntry;
+  Status = EFI_SUCCESS;
+
+  // Verify Last Event PCR = 16
+  if (LastEvent->PCRIndex != 16) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: PCR Index of Last 
event should be 16"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  // Verify last event type = EV_POST_CODE
+  if (LastEvent->EventType != EV_POST_CODE) {
+    StandardLib->RecordMessage (
+                     StandardLib,
+                     EFI_VERBOSE_LEVEL_DEFAULT,
+                     L"\r\nTCG2 Protocol GetEventLog Test: PCR Index of last 
event should be type EV_POST_CODE"
+                     );
+
+    AssertionType = EFI_TEST_ASSERTION_FAILED;
+  }
+
+  StandardLib->RecordAssertion (
+                 StandardLib,
+                 AssertionType,
+                 gTcg2ConformanceTestAssertionGuid016,
+                 L"TCG2_PROTOCOL.GetEventLog - verify that event log has 
expected entry from previous HashLogExtendEvent",
+                 L"%a:%d: Status - %r",
+                 __FILE__,
+                 (UINTN)__LINE__,
+                 Status
+                 );
+
+  return EFI_SUCCESS;
+}
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112571): https://edk2.groups.io/g/devel/message/112571
Mute This Topic: https://groups.io/mt/103181272/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to