From b04fda290848d0e5d876b196ab643ea86b5168ef Mon Sep 17 00:00:00 2001 From: Vicky Min Date: Fri, 1 Sep 2023 19:06:25 +0000 Subject: [PATCH] Skip API and time rollback tests with GTEST_SKIP Bug: 251240681 Change-Id: Ie1cee828f239ddca03ad18aac4139e2e42038df3 --- .../oemcrypto/test/oec_device_features.cpp | 13 +---- .../oemcrypto/test/oemcrypto_basic_test.cpp | 9 ++++ .../oemcrypto/test/oemcrypto_cast_test.cpp | 3 ++ .../oemcrypto/test/oemcrypto_license_test.cpp | 3 ++ .../test/oemcrypto_provisioning_test.cpp | 9 ++++ .../oemcrypto/test/oemcrypto_test.cpp | 54 +++++++++++++++++++ .../test/oemcrypto_usage_table_test.cpp | 31 +++++++++++ 7 files changed, 110 insertions(+), 12 deletions(-) diff --git a/libwvdrmengine/oemcrypto/test/oec_device_features.cpp b/libwvdrmengine/oemcrypto/test/oec_device_features.cpp index cfb742b7..b61e4a76 100644 --- a/libwvdrmengine/oemcrypto/test/oec_device_features.cpp +++ b/libwvdrmengine/oemcrypto/test/oec_device_features.cpp @@ -147,23 +147,12 @@ void DeviceFeatures::Initialize() { std::string DeviceFeatures::RestrictFilter(const std::string& initial_filter) { std::string filter = initial_filter; - // clang-format off - if (api_version < 17) FilterOut(&filter, "*API17*"); - if (api_version < 18) FilterOut(&filter, "*API18*"); - // clang-format on - // Some tests may require root access. If user is not root, filter these tests - // out. - if (!wvutil::TestSleep::CanChangeSystemTime()) { - printf("Filtering out TimeRollbackPrevention.\n"); - FilterOut(&filter, "*TimeRollbackPrevention*"); - } else { - printf("Can change time. I will run TimeRollbackPrevention.\n"); - } // Performance tests take a long time. Filter them out if they are not // specifically requested. if (filter.find("Performance") == std::string::npos) { FilterOut(&filter, "*Performance*"); } + return filter; } diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_basic_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_basic_test.cpp index 89671d07..835d60d3 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_basic_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_basic_test.cpp @@ -288,6 +288,9 @@ TEST_F(OEMCryptoClientTest, CheckSRMCapabilityV13) { } TEST_F(OEMCryptoClientTest, CheckNullBuildInformationAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } OEMCryptoResult sts; std::string build_info; sts = OEMCrypto_BuildInformation(&build_info[0], nullptr); @@ -314,6 +317,9 @@ TEST_F(OEMCryptoClientTest, CheckNullBuildInformationAPI17) { } TEST_F(OEMCryptoClientTest, CheckJsonBuildInformationAPI18) { + if (wvoec::global_features.api_version < 18) { + GTEST_SKIP() << "Test for versions 18 and up only."; + } std::string build_info; OEMCryptoResult sts = OEMCrypto_BuildInformation(&build_info[0], nullptr); ASSERT_EQ(OEMCrypto_ERROR_INVALID_CONTEXT, sts); @@ -416,6 +422,9 @@ TEST_F(OEMCryptoClientTest, NormalInitTermination) { } TEST_F(OEMCryptoClientTest, CheckDTCP2CapabilityAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } OEMCryptoResult sts; OEMCrypto_DTCP2_Capability capability; sts = OEMCrypto_GetDTCP2Capability(&capability); diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_cast_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_cast_test.cpp index 83848145..abdc28eb 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_cast_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_cast_test.cpp @@ -1009,6 +1009,9 @@ TEST_F(OEMCryptoCastReceiverTest, TestSignaturePKCS1_15_20) { } TEST_P(OEMCryptoSessionTestLoadCasKeysWithHDCP, CasOnlyLoadCasKeysAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } if (!global_features.supports_cas) { GTEST_SKIP() << "OEMCrypto does not support CAS"; } diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_license_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_license_test.cpp index 93065b22..d586501a 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_license_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_license_test.cpp @@ -674,6 +674,9 @@ TEST_P(OEMCryptoLicenseTest, QueryKeyControl) { // implementation should be able to handle the clear KCB in the 16.4.x response // and load the license correctly. TEST_F(OEMCryptoSessionTests, ClearKcbAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } Session s; ASSERT_NO_FATAL_FAILURE(s.open()); ASSERT_NO_FATAL_FAILURE(InstallTestDrmKey(&s)); diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_provisioning_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_provisioning_test.cpp index 33101bad..379ec306 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_provisioning_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_provisioning_test.cpp @@ -363,6 +363,9 @@ TEST_F(OEMCryptoProv40Test, GenerateCertificateKeyPairsAreDifferent) { } TEST_F(OEMCryptoProv40Test, GetDeviceInformationAPI18) { + if (wvoec::global_features.api_version < 18) { + GTEST_SKIP() << "Test for versions 18 and up only."; + } std::vector device_info; size_t device_info_length = 0; OEMCryptoResult sts = @@ -377,6 +380,9 @@ TEST_F(OEMCryptoProv40Test, GetDeviceInformationAPI18) { } TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadAPI18) { + if (wvoec::global_features.api_version < 18) { + GTEST_SKIP() << "Test for versions 18 and up only."; + } std::vector challenge(64, 0xaa); // TODO: add cppbor support for oemcrypto tests for all targets. Before that, // use hex values which are equivalent of the commented cppbor statement. @@ -693,6 +699,9 @@ TEST_F(OEMCryptoLoadsCertificate, ForbidRSASignatureForDRMKey2) { } TEST_F(OEMCryptoLoadsCertificate, PrepAndSignLicenseRequestCounterAPI18) { + if (wvoec::global_features.api_version < 18) { + GTEST_SKIP() << "Test for versions 18 and up only."; + } // TODO(b/197141970): Need to revisit OEMCryptoLoadsCert* tests for // provisioning 4. Disabled here temporarily. if (global_features.provisioning_method == OEMCrypto_BootCertificateChain) { diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index 1b6d5b48..a2c4db74 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -281,6 +281,9 @@ class OEMCryptoEntitlementLicenseTest : public OEMCryptoLicenseTest { /** This verifies that entitlement keys and entitled content keys can be loaded. */ TEST_P(OEMCryptoEntitlementLicenseTest, LoadEntitlementKeysAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } LoadEntitlementLicense(); uint32_t key_session_id = 0; ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_CreateEntitledKeySession( @@ -296,6 +299,9 @@ TEST_P(OEMCryptoEntitlementLicenseTest, LoadEntitlementKeysAPI17) { } TEST_P(OEMCryptoEntitlementLicenseTest, CasOnlyLoadCasKeysAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } if (!global_features.supports_cas) { GTEST_SKIP() << "OEMCrypto does not support CAS"; } @@ -329,6 +335,9 @@ TEST_P(OEMCryptoEntitlementLicenseTest, CasOnlyLoadCasKeysAPI17) { */ TEST_P(OEMCryptoEntitlementLicenseTest, LoadEntitlementKeysNoEntitlementKeysAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -373,6 +382,9 @@ TEST_P(OEMCryptoEntitlementLicenseTest, */ TEST_P(OEMCryptoEntitlementLicenseTest, LoadEntitlementKeysWrongEntitlementKeysAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } LoadEntitlementLicense(); uint32_t key_session_id = 0; ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_CreateEntitledKeySession( @@ -388,6 +400,9 @@ TEST_P(OEMCryptoEntitlementLicenseTest, TEST_P(OEMCryptoEntitlementLicenseTest, CasOnlyLoadCasKeysWrongEntitlementKeysAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } if (!global_features.supports_cas) { GTEST_SKIP() << "OEMCrypto does not support CAS"; } @@ -411,6 +426,9 @@ TEST_P(OEMCryptoEntitlementLicenseTest, */ TEST_P(OEMCryptoEntitlementLicenseTest, LoadEntitlementKeysWrongEntitledKeySessionAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } LoadEntitlementLicense(); uint32_t key_session_id = 0; ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_CreateEntitledKeySession( @@ -425,6 +443,9 @@ TEST_P(OEMCryptoEntitlementLicenseTest, TEST_P(OEMCryptoEntitlementLicenseTest, CasOnlyLoadCasKeysWrongEntitledKeySessionAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } if (!global_features.supports_cas) { GTEST_SKIP() << "OEMCrypto does not support CAS"; } @@ -451,6 +472,9 @@ TEST_P(OEMCryptoEntitlementLicenseTest, if (!global_features.supports_cas) { GTEST_SKIP() << "OEMCrypto does not support CAS"; } + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } LoadEntitlementLicense(); uint32_t key_session_id = 0; ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_CreateEntitledKeySession( @@ -469,6 +493,9 @@ TEST_P(OEMCryptoEntitlementLicenseTest, TEST_P(OEMCryptoEntitlementLicenseTest, CasOnlyLoadCasKeysOemcryptoSessionAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } if (!global_features.supports_cas) { GTEST_SKIP() << "OEMCrypto does not support CAS"; } @@ -697,6 +724,9 @@ TEST_F(OEMCryptoMemoryLicenseTest, /// @{ TEST_P(OEMCryptoLicenseTest, GetKeyHandleEntitledKeyAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -724,6 +754,9 @@ TEST_P(OEMCryptoLicenseTest, GetKeyHandleEntitledKeyAPI17) { // SelectEntitledKey should fail if we attempt to select a key that has not been // loaded. Also, the error should be NO_CONTENT_KEY. TEST_P(OEMCryptoLicenseTest, SelectKeyEntitledKeyNotThereAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -753,6 +786,9 @@ TEST_P(OEMCryptoLicenseTest, SelectKeyEntitlementKeyAPI17) { if (!global_features.supports_cas) { GTEST_SKIP() << "OEMCrypto does not support CAS"; } + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -780,6 +816,9 @@ TEST_P(OEMCryptoLicenseTest, SelectKeyEntitlementKeyAPI17) { // This verifies that entitled key sessions can be created and removed. TEST_P(OEMCryptoLicenseTest, EntitledKeySessionsAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -806,6 +845,9 @@ TEST_P(OEMCryptoLicenseTest, EntitledKeySessionsAPI17) { TEST_P(OEMCryptoLicenseTest, EntitledKeySessionsCloseWithOEMCryptoSessionAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -831,6 +873,9 @@ TEST_P(OEMCryptoLicenseTest, EntitledKeySessionMultipleKeySessionsAPI17) { if (!global_features.supports_cas) { GTEST_SKIP() << "OEMCrypto does not support CAS"; } + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -895,6 +940,9 @@ TEST_P(OEMCryptoLicenseTest, EntitledKeySessionMultipleKeySessionsAPI17) { // corresponds to only one content key at most. TEST_P(OEMCryptoLicenseTest, EntitledKeySessionOneContentKeyPerEntitlementAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -940,6 +988,9 @@ TEST_P(OEMCryptoLicenseTest, // instead). TEST_P(OEMCryptoLicenseTest, RejectOecSessionDecryptWithEntitlementLicenseAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -979,6 +1030,9 @@ TEST_P(OEMCryptoLicenseTest, // This verifies that an entitled key session can be reassociated to an // OEMCrypto session. TEST_P(OEMCryptoEntitlementLicenseTest, ReassociateEntitledKeySessionAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } license_messages_.set_license_type(OEMCrypto_EntitlementLicense); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_usage_table_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_usage_table_test.cpp index 40491b42..658726b5 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_usage_table_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_usage_table_test.cpp @@ -13,6 +13,9 @@ namespace wvoec { // Test that successive calls to PrepAndSignProvisioningRequest only increase // the provisioning count in the ODK message TEST_F(OEMCryptoSessionTests, Provisioning_IncrementCounterAPI18) { + if (wvoec::global_features.api_version < 18) { + GTEST_SKIP() << "Test for versions 18 and up only."; + } // local struct to hold count values from core message typedef struct counts { uint32_t prov; @@ -90,6 +93,9 @@ TEST_F(OEMCryptoSessionTests, Provisioning_IncrementCounterAPI18) { // Test that successive calls to PrepAndSignLicenseRequest only increase // the license count in the ODK message TEST_F(OEMCryptoSessionTests, License_IncrementCounterAPI18) { + if (wvoec::global_features.api_version < 18) { + GTEST_SKIP() << "Test for versions 18 and up only."; + } Session s; s.open(); LicenseRoundTrip license_messages(&s); @@ -128,6 +134,9 @@ TEST_F(OEMCryptoSessionTests, License_IncrementCounterAPI18) { // it is incremented correctly after usage table modification (save offline // license) and decrypt. Also test that decrypt count increments. TEST_F(OEMCryptoSessionTests, MasterGeneration_IncrementCounterAPI18) { + if (wvoec::global_features.api_version < 18) { + GTEST_SKIP() << "Test for versions 18 and up only."; + } if (!OEMCrypto_SupportsUsageTable()) { GTEST_SKIP() << "Usage table not supported, so master generation number " "does not need to be checked."; @@ -1235,6 +1244,9 @@ TEST_P(OEMCryptoUsageTableDefragTest, ManyUsageEntries) { // Verify that usage entries can be created in the position of existing entry // indexes. TEST_P(OEMCryptoUsageTableDefragTest, ReuseUsageEntryAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } LicenseWithUsageEntry entry0; entry0.set_pst("pst 0"); LicenseWithUsageEntry entry1; @@ -1252,6 +1264,9 @@ TEST_P(OEMCryptoUsageTableDefragTest, ReuseUsageEntryAPI17) { // Verify that usage entries cannot replace an entry that is currently in // use by a session. TEST_P(OEMCryptoUsageTableDefragTest, ReuseUsageEntryIndexInUseAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } LicenseWithUsageEntry entry0; entry0.set_pst("pst 0"); LicenseWithUsageEntry entry1; @@ -1268,6 +1283,9 @@ TEST_P(OEMCryptoUsageTableDefragTest, ReuseUsageEntryIndexInUseAPI17) { // Verify that usage entries cannot be created if the usage entry index is // too large. TEST_P(OEMCryptoUsageTableDefragTest, ReuseUsageEntryWithInvalidIndexAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } LicenseWithUsageEntry entry0; entry0.set_pst("pst 0"); LicenseWithUsageEntry entry1; @@ -1287,6 +1305,9 @@ TEST_P(OEMCryptoUsageTableDefragTest, ReuseUsageEntryWithInvalidIndexAPI17) { // entry. TEST_P(OEMCryptoUsageTableDefragTest, ReuseUsageEntrySessionAlreadyHasEntryAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } LicenseWithUsageEntry entry; entry.set_pst("pst 0"); @@ -1620,6 +1641,13 @@ class OEMCryptoUsageTableTestWallClock : public OEMCryptoUsageTableTest { // clang-format on TEST_P(OEMCryptoUsageTableTestWallClock, TimeRollbackPrevention) { + // This test may require root access. If user is not root, filter this test + // out. + if (!wvutil::TestSleep::CanChangeSystemTime()) { + GTEST_SKIP() << "Filtering out TimeRollbackPrevention."; + } else { + printf("Can change time. I will run TimeRollbackPrevention.\n"); + } cout << "This test temporarily rolls back the system time in order to " "verify " << "that the usage report accounts for the change. After the test, it " @@ -1729,6 +1757,9 @@ TEST_P(OEMCryptoUsageTableTest, UsageEntryWithInvalidSession) { // Verify that a usage entry with an invalid session cannot be used. TEST_P(OEMCryptoUsageTableTest, ReuseUsageEntryWithInvalidSessionAPI17) { + if (wvoec::global_features.api_version < 17) { + GTEST_SKIP() << "Test for versions 17 and up only."; + } std::string pst("pst"); LicenseWithUsageEntry entry; entry.license_messages().set_pst(pst);