Files
android/libwvdrmengine/oemcrypto/test/oemcrypto_serialization_version_test.cpp
Kyle Zhang 11255b7426 Pick widevine oemcrypto-v18 change
No-Typo-Check: From a third party header file
Bug: 260918793
Test: unit tests
Test: atp v2/widevine-eng/drm_compliance
Change-Id: I36effd6a10a99bdb2399ab1f4a0fad026d607c70
2022-12-21 00:03:50 +00:00

110 lines
3.6 KiB
C++

// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine
// License Agreement.
//
#include <iostream>
#include <gtest/gtest.h>
#include "OEMCryptoCENC.h"
#include "log.h"
#include "odk_structs.h"
#include "oec_test_data.h"
using namespace std;
namespace wvoec {
class OEMCryptoTest : public ::testing::Test {
protected:
OEMCryptoTest() {}
void SetUp() override {
::testing::Test::SetUp();
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
LOGD("Running test %s.%s", test_info->test_case_name(), test_info->name());
OEMCrypto_SetSandbox(kTestSandbox, sizeof(kTestSandbox));
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize());
OEMCrypto_EnterTestMode();
}
void TearDown() override {
OEMCrypto_Terminate();
::testing::Test::TearDown();
}
};
TEST_F(OEMCryptoTest, OPK_SerializationVersion) {
uint32_t ree_major = 0;
uint32_t ree_minor = 0;
uint32_t tee_major = 0;
uint32_t tee_minor = 0;
OEMCryptoResult sts = OEMCrypto_OPK_SerializationVersion(
&ree_major, &ree_minor, &tee_major, &tee_minor);
if (sts != OEMCrypto_ERROR_NOT_IMPLEMENTED) {
EXPECT_EQ(OEMCrypto_SUCCESS, sts);
cout << "OPK REE serialization version is " << ree_major << "." << ree_minor
<< "\n";
cout << "OPK TEE serialization version is " << tee_major << "." << tee_minor
<< "\n";
EXPECT_NE(ree_major, 0u);
EXPECT_NE(tee_major, 0u);
const uint32_t orig_ree_major = ree_major;
const uint32_t orig_ree_minor = ree_minor;
const uint32_t orig_tee_major = tee_major;
const uint32_t orig_tee_minor = tee_minor;
/* test requiring a specific version, should create incompatibility */
ree_major = 100;
ree_minor = 1;
sts = OEMCrypto_OPK_SerializationVersion(&ree_major, &ree_minor, &tee_major,
&tee_minor);
EXPECT_EQ(OPK_ERROR_INCOMPATIBLE_VERSION, sts);
EXPECT_EQ(ree_major, 100u);
EXPECT_EQ(ree_minor, 1u);
/* now OEMCrypto_Initialize should fail with incompatible version */
OEMCrypto_Terminate();
EXPECT_EQ(OPK_ERROR_INCOMPATIBLE_VERSION, OEMCrypto_Initialize());
/* restore the default versions */
ree_major = 0;
ree_minor = 0;
sts = OEMCrypto_OPK_SerializationVersion(&ree_major, &ree_minor, &tee_major,
&tee_minor);
EXPECT_EQ(OEMCrypto_SUCCESS, sts);
EXPECT_EQ(ree_major, orig_ree_major);
EXPECT_EQ(ree_minor, orig_ree_minor);
EXPECT_EQ(tee_major, orig_tee_major);
EXPECT_EQ(tee_minor, orig_tee_minor);
/* OEMCrypto_Initialize should work now */
OEMCrypto_Terminate();
EXPECT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize());
/* changing minor version shouldn't create incompatibility */
ree_minor++;
sts = OEMCrypto_OPK_SerializationVersion(&ree_major, &ree_minor, &tee_major,
&tee_minor);
EXPECT_EQ(ree_minor, orig_ree_minor + 1);
EXPECT_EQ(OEMCrypto_SUCCESS, sts);
/* OEMCrypto_Initialize should still work */
OEMCrypto_Terminate();
EXPECT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize());
/* remove the REE version override so subsequent tests work */
ree_major = 0;
ree_minor = 0;
sts = OEMCrypto_OPK_SerializationVersion(&ree_major, &ree_minor, &tee_major,
&tee_minor);
EXPECT_EQ(OEMCrypto_SUCCESS, sts);
EXPECT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize());
}
}
} // namespace wvoec