30#define UNIT_TEST_APP_NAME "SecureBootVariableLib Unit Tests"
31#define UNIT_TEST_APP_VERSION "1.0"
32#define VAR_AUTH_DESC_SIZE OFFSET_OF (EFI_VARIABLE_AUTHENTICATION_2, AuthInfo) + OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)
35extern EFI_TIME mDefaultPayloadTimestamp;
75 IN CHAR16 *VariableName,
84 "%a %s %g %x %x %p\n",
92 check_expected_ptr (VariableName);
93 check_expected_ptr (VendorGuid);
94 check_expected_ptr (Attributes);
95 check_expected (DataSize);
96 check_expected (Data);
129 IN CHAR16 *VariableName,
131 OUT UINT32 *Attributes OPTIONAL,
133 OUT VOID *Data OPTIONAL
141 "%a %s %g %p %x %p\n",
149 assert_non_null (DataSize);
150 check_expected_ptr (VariableName);
151 check_expected_ptr (VendorGuid);
152 check_expected (*DataSize);
154 Exist = (BOOLEAN)mock ();
157 return EFI_NOT_FOUND;
160 TargetSize = (
UINTN)mock ();
161 if (TargetSize > *DataSize) {
162 *DataSize = TargetSize;
163 return EFI_BUFFER_TOO_SMALL;
165 assert_non_null (Data);
177 EFI_RUNTIME_SERVICES_SIGNATURE,
178 EFI_RUNTIME_SERVICES_REVISION,
220 UINT8 SecureBootMode;
223 SecureBootMode = 0xAB;
228 expect_memory (
MockSetVariable, Data, &SecureBootMode,
sizeof (SecureBootMode));
236 return UNIT_TEST_PASSED;
278 return UNIT_TEST_PASSED;
305 TargetMode = SECURE_BOOT_MODE_ENABLE;
325 return UNIT_TEST_PASSED;
351 UINTN SigListSize = 0;
353 UINT8 TestData[] = { 0 };
356 KeyInfo.Data = TestData;
357 KeyInfo.DataSize =
sizeof (TestData);
374 return UNIT_TEST_PASSED;
399 UINTN SigListSize = 0;
412 return UNIT_TEST_PASSED;
438 UINTN SigListSize = 0;
441 UINT8 TestData1[] = { 0 };
442 UINT8 TestData2[] = { 1, 2 };
446 KeyInfo[0].Data = TestData1;
447 KeyInfo[0].DataSize =
sizeof (TestData1);
448 KeyInfo[1].Data = TestData2;
449 KeyInfo[1].DataSize =
sizeof (TestData2);
456 for (Index = 0; Index < 2; Index++) {
473 return UNIT_TEST_PASSED;
497 UINT8 Data[] = { 2 };
498 UINTN DataSize =
sizeof (Data);
536 return UNIT_TEST_PASSED;
574 return UNIT_TEST_PASSED;
600 UINT8 *Payload =
NULL;
601 UINTN PayloadSize = 0;
604 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
611 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
623 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
633 return UNIT_TEST_PASSED;
659 UINT8 *Payload =
NULL;
660 UINTN PayloadSize = 0;
663 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
670 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
682 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
692 return UNIT_TEST_PASSED;
718 UINT8 *Payload =
NULL;
719 UINTN PayloadSize = 0;
722 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
729 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
741 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
751 return UNIT_TEST_PASSED;
777 UINT8 *Payload =
NULL;
778 UINTN PayloadSize = 0;
810 return UNIT_TEST_PASSED;
836 UINT8 *Payload =
NULL;
837 UINTN PayloadSize = 0;
838 UINT8 BootMode = CUSTOM_SECURE_BOOT_MODE;
878 return UNIT_TEST_PASSED;
904 UINT8 *Payload =
NULL;
905 UINTN PayloadSize = 0;
906 UINT8 BootMode = CUSTOM_SECURE_BOOT_MODE;
969 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
976 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
984 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
992 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
999 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1007 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1015 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1022 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1030 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1040 return UNIT_TEST_PASSED;
1071 return UNIT_TEST_PASSED;
1096 UINT8 BootMode = CUSTOM_SECURE_BOOT_MODE;
1101 expect_value (
MockSetVariable, VendorGuid, &gEfiCustomModeEnableGuid);
1121 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1127 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1133 expect_value (
MockGetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1141 return UNIT_TEST_PASSED;
1167 UINT8 *Payload =
NULL;
1168 UINTN PayloadSize =
sizeof (Dummy);
1178 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (Dummy));
1179 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (Dummy));
1186 return UNIT_TEST_PASSED;
1211 UINT8 DbDummy = 0xDE;
1212 UINT8 DbtDummy = 0xAD;
1213 UINT8 DbxDummy = 0xBE;
1214 UINT8 KekDummy = 0xEF;
1215 UINT8 PkDummy = 0xFE;
1216 UINT8 *Payload =
NULL;
1217 UINTN PayloadSize =
sizeof (DbDummy);
1220 PayloadInfo.DbPtr = &DbDummy;
1221 PayloadInfo.DbSize =
sizeof (DbDummy);
1222 PayloadInfo.DbxPtr = &DbxDummy;
1223 PayloadInfo.DbxSize =
sizeof (DbxDummy);
1224 PayloadInfo.DbtPtr = &DbtDummy;
1225 PayloadInfo.DbtSize =
sizeof (DbtDummy);
1226 PayloadInfo.KekPtr = &KekDummy;
1227 PayloadInfo.KekSize =
sizeof (KekDummy);
1228 PayloadInfo.PkPtr = &PkDummy;
1229 PayloadInfo.PkSize =
sizeof (PkDummy);
1230 PayloadInfo.SecureBootKeyName = L
"Food";
1241 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1244 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1246 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1247 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1251 CopyMem (Payload, &DbDummy,
sizeof (DbDummy));
1252 PayloadSize =
sizeof (DbDummy);
1258 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1260 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1261 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1265 CopyMem (Payload, &DbtDummy,
sizeof (DbtDummy));
1266 PayloadSize =
sizeof (DbtDummy);
1269 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1272 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1274 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1275 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1279 CopyMem (Payload, &KekDummy,
sizeof (KekDummy));
1280 PayloadSize =
sizeof (KekDummy);
1283 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1288 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1289 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1293 CopyMem (Payload, &PkDummy,
sizeof (PkDummy));
1294 PayloadSize =
sizeof (PkDummy);
1302 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (PkDummy));
1303 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (PkDummy));
1310 return UNIT_TEST_PASSED;
1335 UINT8 TargetMode = SECURE_BOOT_MODE_ENABLE;
1356 return UNIT_TEST_PASSED;
1381 UINT8 DbxDummy = 0xBE;
1382 UINT8 *Payload =
NULL;
1383 UINTN PayloadSize =
sizeof (DbxDummy);
1386 PayloadInfo.DbxPtr = &DbxDummy;
1387 PayloadInfo.DbxSize =
sizeof (DbxDummy);
1388 PayloadInfo.SecureBootKeyName = L
"Fail DBX";
1399 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1402 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1404 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1405 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1412 return UNIT_TEST_PASSED;
1437 UINT8 DbDummy = 0xDE;
1438 UINT8 DbxDummy = 0xBE;
1439 UINT8 *Payload =
NULL;
1440 UINTN PayloadSize =
sizeof (DbDummy);
1443 PayloadInfo.DbPtr = &DbDummy;
1444 PayloadInfo.DbSize =
sizeof (DbDummy);
1445 PayloadInfo.DbxPtr = &DbxDummy;
1446 PayloadInfo.DbxSize =
sizeof (DbxDummy);
1447 PayloadInfo.SecureBootKeyName = L
"Fail DB";
1458 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1461 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1463 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1464 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1468 CopyMem (Payload, &DbDummy,
sizeof (DbDummy));
1469 PayloadSize =
sizeof (DbDummy);
1475 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1477 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1478 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1485 return UNIT_TEST_PASSED;
1510 UINT8 DbDummy = 0xDE;
1511 UINT8 DbtDummy = 0xAD;
1512 UINT8 DbxDummy = 0xBE;
1513 UINT8 *Payload =
NULL;
1514 UINTN PayloadSize =
sizeof (DbDummy);
1517 PayloadInfo.DbPtr = &DbDummy;
1518 PayloadInfo.DbSize =
sizeof (DbDummy);
1519 PayloadInfo.DbxPtr = &DbxDummy;
1520 PayloadInfo.DbxSize =
sizeof (DbxDummy);
1521 PayloadInfo.DbtPtr = &DbtDummy;
1522 PayloadInfo.DbtSize =
sizeof (DbtDummy);
1523 PayloadInfo.SecureBootKeyName = L
"Fail DBT";
1534 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1537 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1539 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1540 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1544 CopyMem (Payload, &DbDummy,
sizeof (DbDummy));
1545 PayloadSize =
sizeof (DbDummy);
1551 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1553 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1554 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1558 CopyMem (Payload, &DbtDummy,
sizeof (DbtDummy));
1559 PayloadSize =
sizeof (DbtDummy);
1562 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1565 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1567 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1568 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1575 return UNIT_TEST_PASSED;
1600 UINT8 DbDummy = 0xDE;
1601 UINT8 DbtDummy = 0xAD;
1602 UINT8 DbxDummy = 0xBE;
1603 UINT8 KekDummy = 0xEF;
1604 UINT8 PkDummy = 0xFE;
1605 UINT8 *Payload =
NULL;
1606 UINTN PayloadSize =
sizeof (DbDummy);
1609 PayloadInfo.DbPtr = &DbDummy;
1610 PayloadInfo.DbSize =
sizeof (DbDummy);
1611 PayloadInfo.DbxPtr = &DbxDummy;
1612 PayloadInfo.DbxSize =
sizeof (DbxDummy);
1613 PayloadInfo.DbtPtr = &DbtDummy;
1614 PayloadInfo.DbtSize =
sizeof (DbtDummy);
1615 PayloadInfo.KekPtr = &KekDummy;
1616 PayloadInfo.KekSize =
sizeof (KekDummy);
1617 PayloadInfo.PkPtr = &PkDummy;
1618 PayloadInfo.PkSize =
sizeof (PkDummy);
1619 PayloadInfo.SecureBootKeyName = L
"Food";
1630 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1633 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1635 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1636 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1640 CopyMem (Payload, &DbDummy,
sizeof (DbDummy));
1641 PayloadSize =
sizeof (DbDummy);
1647 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1649 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1650 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1654 CopyMem (Payload, &DbtDummy,
sizeof (DbtDummy));
1655 PayloadSize =
sizeof (DbtDummy);
1658 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1661 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1663 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1664 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1668 CopyMem (Payload, &KekDummy,
sizeof (KekDummy));
1669 PayloadSize =
sizeof (KekDummy);
1672 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1677 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1678 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1685 return UNIT_TEST_PASSED;
1710 UINT8 DbDummy = 0xDE;
1711 UINT8 DbtDummy = 0xAD;
1712 UINT8 DbxDummy = 0xBE;
1713 UINT8 KekDummy = 0xEF;
1714 UINT8 PkDummy = 0xFE;
1715 UINT8 *Payload =
NULL;
1716 UINTN PayloadSize =
sizeof (DbDummy);
1719 PayloadInfo.DbPtr = &DbDummy;
1720 PayloadInfo.DbSize =
sizeof (DbDummy);
1721 PayloadInfo.DbxPtr = &DbxDummy;
1722 PayloadInfo.DbxSize =
sizeof (DbxDummy);
1723 PayloadInfo.DbtPtr = &DbtDummy;
1724 PayloadInfo.DbtSize =
sizeof (DbtDummy);
1725 PayloadInfo.KekPtr = &KekDummy;
1726 PayloadInfo.KekSize =
sizeof (KekDummy);
1727 PayloadInfo.PkPtr = &PkDummy;
1728 PayloadInfo.PkSize =
sizeof (PkDummy);
1729 PayloadInfo.SecureBootKeyName = L
"Food";
1740 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1743 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1745 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1746 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1750 CopyMem (Payload, &DbDummy,
sizeof (DbDummy));
1751 PayloadSize =
sizeof (DbDummy);
1757 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1759 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1760 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1764 CopyMem (Payload, &DbtDummy,
sizeof (DbtDummy));
1765 PayloadSize =
sizeof (DbtDummy);
1768 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1771 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1773 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1774 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbtDummy));
1778 CopyMem (Payload, &KekDummy,
sizeof (KekDummy));
1779 PayloadSize =
sizeof (KekDummy);
1782 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1787 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1788 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1792 CopyMem (Payload, &PkDummy,
sizeof (PkDummy));
1793 PayloadSize =
sizeof (PkDummy);
1801 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (PkDummy));
1802 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (PkDummy));
1809 return UNIT_TEST_PASSED;
1834 UINT8 DbDummy = 0xDE;
1835 UINT8 DbxDummy = 0xBE;
1836 UINT8 KekDummy = 0xEF;
1837 UINT8 PkDummy = 0xFE;
1838 UINT8 *Payload =
NULL;
1839 UINTN PayloadSize =
sizeof (DbDummy);
1842 PayloadInfo.DbPtr = &DbDummy;
1843 PayloadInfo.DbSize =
sizeof (DbDummy);
1844 PayloadInfo.DbxPtr = &DbxDummy;
1845 PayloadInfo.DbxSize =
sizeof (DbxDummy);
1846 PayloadInfo.DbtPtr =
NULL;
1847 PayloadInfo.DbtSize = 0;
1848 PayloadInfo.KekPtr = &KekDummy;
1849 PayloadInfo.KekSize =
sizeof (KekDummy);
1850 PayloadInfo.PkPtr = &PkDummy;
1851 PayloadInfo.PkSize =
sizeof (PkDummy);
1852 PayloadInfo.SecureBootKeyName = L
"Food";
1863 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1866 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1868 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1869 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbxDummy));
1873 CopyMem (Payload, &DbDummy,
sizeof (DbDummy));
1874 PayloadSize =
sizeof (DbDummy);
1880 expect_value (
MockSetVariable, VendorGuid, &gEfiImageSecurityDatabaseGuid);
1882 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1883 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (DbDummy));
1887 CopyMem (Payload, &KekDummy,
sizeof (KekDummy));
1888 PayloadSize =
sizeof (KekDummy);
1891 UT_ASSERT_EQUAL (PayloadSize, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1896 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1897 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (KekDummy));
1901 CopyMem (Payload, &PkDummy,
sizeof (PkDummy));
1902 PayloadSize =
sizeof (PkDummy);
1910 expect_value (
MockSetVariable, DataSize, VAR_AUTH_DESC_SIZE +
sizeof (PkDummy));
1911 expect_memory (
MockSetVariable, Data, Payload, VAR_AUTH_DESC_SIZE +
sizeof (PkDummy));
1918 return UNIT_TEST_PASSED;
1937 UNIT_TEST_FRAMEWORK_HANDLE Framework;
1938 UNIT_TEST_SUITE_HANDLE SecureBootVarMiscTests;
1939 UNIT_TEST_SUITE_HANDLE SecureBootVarDeleteTests;
1940 UNIT_TEST_SUITE_HANDLE SecureBootVarEnrollTests;
1944 DEBUG ((DEBUG_INFO,
"%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
1949 Status =
InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
1950 if (EFI_ERROR (Status)) {
1951 DEBUG ((DEBUG_ERROR,
"Failed in InitUnitTestFramework. Status = %r\n", Status));
1958 Status =
CreateUnitTestSuite (&SecureBootVarMiscTests, Framework,
"SecureBootVariableLib Miscellaneous Tests",
"SecureBootVariableLib.Miscellaneous",
NULL,
NULL);
1959 if (EFI_ERROR (Status)) {
1960 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for SecureBootVariableLib\n"));
1961 Status = EFI_OUT_OF_RESOURCES;
1965 Status =
CreateUnitTestSuite (&SecureBootVarDeleteTests, Framework,
"SecureBootVariableLib Deletion Tests",
"SecureBootVariableLib.Deletion",
NULL,
NULL);
1966 if (EFI_ERROR (Status)) {
1967 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for SecureBootVariableLib\n"));
1968 Status = EFI_OUT_OF_RESOURCES;
1972 Status =
CreateUnitTestSuite (&SecureBootVarEnrollTests, Framework,
"SecureBootVariableLib Enrollment Tests",
"SecureBootVariableLib.Enrollment",
NULL,
NULL);
1973 if (EFI_ERROR (Status)) {
1974 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for SecureBootVariableLib\n"));
1975 Status = EFI_OUT_OF_RESOURCES;
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
int main()
=== TEST ENGINE ================================================================================
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define EFI_SETUP_MODE_NAME
#define EFI_KEY_EXCHANGE_KEY_NAME
#define EFI_PLATFORM_KEY_NAME
#define EFI_SECURE_BOOT_MODE_NAME
#define EFI_IMAGE_SECURITY_DATABASE2
#define EFI_IMAGE_SECURITY_DATABASE1
#define EFI_IMAGE_SECURITY_DATABASE
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
EFI_STATUS CreateTimeBasedPayload(IN OUT UINTN *DataSize, IN OUT UINT8 **Data)
EFI_STATUS EFIAPI SetSecureBootMode(IN UINT8 SecureBootMode)
BOOLEAN EFIAPI IsSecureBootEnabled(VOID)
EFI_STATUS EFIAPI GetSetupMode(OUT UINT8 *SetupMode)
EFI_STATUS EFIAPI SecureBootCreateDataFromInput(OUT UINTN *SigListsSize, OUT EFI_SIGNATURE_LIST **SigListOut, IN UINTN KeyInfoCount, IN CONST SECURE_BOOT_CERTIFICATE_INFO *KeyInfo)
EFI_STATUS EFIAPI DeleteDbx(VOID)
EFI_STATUS EFIAPI SetSecureBootVariablesToDefault(IN CONST SECURE_BOOT_PAYLOAD_INFO *SecureBootPayload)
EFI_STATUS EFIAPI DeletePlatformKey(VOID)
EFI_STATUS EFIAPI DeleteDb(VOID)
EFI_STATUS EFIAPI DeleteKEK(VOID)
EFI_STATUS EFIAPI DeleteDbt(VOID)
EFI_STATUS EFIAPI DeleteSecureBootVariables(VOID)
EFI_STATUS EFIAPI EnrollFromInput(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINTN DataSize, IN VOID *Data)
STATIC EFI_STATUS EFIAPI MockGetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data OPTIONAL)
UNIT_TEST_STATUS EFIAPI DeleteKEKShouldDelete(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SetSecureBootVariablesShouldStopFailDBT(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI CreateTimeBasedPayloadShouldCheckInput(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI DeleteDbShouldDelete(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI IsSecureBootEnableShouldGetVar(IN UNIT_TEST_CONTEXT Context)
STATIC EFI_STATUS EFIAPI MockSetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
UNIT_TEST_STATUS EFIAPI SetSecureBootVariablesShouldStopWhenSecure(IN UNIT_TEST_CONTEXT Context)
EFI_RUNTIME_SERVICES gMockRuntime
UNIT_TEST_STATUS EFIAPI DeleteSecureBootVariablesShouldProceedWithNotFound(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI DeleteSecureBootVariablesShouldCheckProtection(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI CreateTimeBasedPayloadShouldPopulateDescriptor(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI EnrollFromInputShouldComplete(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI DeleteSecureBootVariablesShouldDelete(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI DeleteDbtShouldDelete(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SetSecureBootVariablesShouldStopFailDB(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SetSecureBootVariablesShouldStopFailKEK(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI DeleteDbxShouldDelete(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SecureBootCreateDataFromInputNull(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SecureBootCreateDataFromInputSimple(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SecureBootCreateDataFromInputMultiple(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SetSecureBootVariablesShouldComplete(IN UNIT_TEST_CONTEXT Context)
STATIC EFI_STATUS EFIAPI UnitTestingEntry(VOID)
UNIT_TEST_STATUS EFIAPI SetSecureBootModeShouldSetVar(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI DeletePKShouldDelete(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SetSecureBootVariablesDBTOptional(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SetSecureBootVariablesShouldStopFailPK(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI GetSetupModeShouldGetVar(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI SetSecureBootVariablesShouldStopFailDBX(IN UNIT_TEST_CONTEXT Context)
#define EFI_VARIABLE_NON_VOLATILE
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
#define UT_ASSERT_NOT_NULL(Pointer)
#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length)
#define UT_ASSERT_TRUE(Expression)
#define UT_ASSERT_EQUAL(ValueA, ValueB)
#define UT_ASSERT_STATUS_EQUAL(Status, Expected)
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
#define UT_ASSERT_NOT_EFI_ERROR(Status)
UINT32 SignatureHeaderSize
WIN_CERTIFICATE_UEFI_GUID AuthInfo