Merge "This fixes the potential vts test failures for devices with no registered shared secret services. It aso fixes the static dependency issue. Test: atest VtsAidlSharedSecretTargetTest, atest VtsAidlSecureClockTargetTest Bug: b/182913582"

This commit is contained in:
Treehugger Robot
2021-03-25 00:33:00 +00:00
committed by Gerrit Code Review
5 changed files with 29 additions and 82 deletions

View File

@@ -39,11 +39,11 @@ cc_test {
shared_libs: [
"libbinder_ndk",
"libcrypto",
"libkeymint",
],
static_libs: [
"android.hardware.security.keymint-V1-ndk_platform",
"android.hardware.security.secureclock-V1-ndk_platform",
"libkeymint",
],
test_suites: [
"general-tests",

View File

@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration description="Runs VtsAidlSecureClockTargetTest.">
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="apct-native" />
<target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer">
</target_preparer>
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
<option name="cleanup" value="true" />
<option name="push"
value="VtsAidlSecureClockTargetTest->/data/local/tmp/VtsAidlSecureClockTargetTest" />
</target_preparer>
<test class="com.android.tradefed.testtype.GTest" >
<option name="native-test-device-path" value="/data/local/tmp" />
<option name="module-name" value="VtsAidlSecureClockTargetTest" />
<option name="native-test-timeout" value="900000"/>
</test>
</configuration>

View File

@@ -39,11 +39,11 @@ cc_test {
shared_libs: [
"libbinder_ndk",
"libcrypto",
"libkeymint",
],
static_libs: [
"android.hardware.security.keymint-V1-ndk_platform",
"android.hardware.security.sharedsecret-V1-ndk_platform",
"libkeymint",
],
test_suites: [
"general-tests",

View File

@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration description="Runs VtsAidlSharedSecretTargetTest.">
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="apct-native" />
<target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer">
</target_preparer>
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
<option name="cleanup" value="true" />
<option name="push"
value="VtsAidlSharedSecretTargetTest->/data/local/tmp/VtsAidlSharedSecretTargetTest" />
</target_preparer>
<test class="com.android.tradefed.testtype.GTest" >
<option name="native-test-device-path" value="/data/local/tmp" />
<option name="module-name" value="VtsAidlSharedSecretTargetTest" />
<option name="native-test-timeout" value="900000"/>
</test>
</configuration>

View File

@@ -114,14 +114,14 @@ class SharedSecretAidlTest : public ::testing::Test {
const vector<shared_ptr<ISharedSecret>>& allSharedSecrets() { return allSharedSecrets_; }
static void SetUpTestCase() {
if (allSharedSecrets_.empty()) {
auto names = ::android::getAidlHalInstanceNames(ISharedSecret::descriptor);
for (const auto& name : names) {
auto servicePtr = getSharedSecretService(name.c_str());
if (servicePtr != nullptr) allSharedSecrets_.push_back(std::move(servicePtr));
}
ASSERT_TRUE(allSharedSecrets_.empty()) << "The Shared Secret vector is not empty.";
auto names = ::android::getAidlHalInstanceNames(ISharedSecret::descriptor);
for (const auto& name : names) {
auto servicePtr = getSharedSecretService(name.c_str());
if (servicePtr != nullptr) allSharedSecrets_.push_back(std::move(servicePtr));
}
}
static void TearDownTestCase() {}
void SetUp() override {}
void TearDown() override {}
@@ -134,6 +134,9 @@ vector<shared_ptr<ISharedSecret>> SharedSecretAidlTest::allSharedSecrets_;
TEST_F(SharedSecretAidlTest, GetParameters) {
auto sharedSecrets = allSharedSecrets();
if (sharedSecrets.empty()) {
GTEST_SKIP() << "Skipping the test because no shared secret service is found.";
}
for (auto sharedSecret : sharedSecrets) {
auto result1 = getSharedSecretParameters(sharedSecret);
EXPECT_EQ(ErrorCode::OK, result1.error);
@@ -148,14 +151,18 @@ TEST_F(SharedSecretAidlTest, GetParameters) {
}
TEST_F(SharedSecretAidlTest, ComputeSharedSecret) {
auto sharedSecrets = allSharedSecrets();
if (sharedSecrets.empty()) {
GTEST_SKIP() << "Skipping the test as no shared secret service is found.";
}
auto params = getAllSharedSecretParameters();
ASSERT_EQ(allSharedSecrets().size(), params.size())
ASSERT_EQ(sharedSecrets.size(), params.size())
<< "One or more shared secret services failed to provide parameters.";
auto nonces = copyNonces(params);
EXPECT_EQ(allSharedSecrets().size(), nonces.size());
EXPECT_EQ(sharedSecrets.size(), nonces.size());
std::sort(nonces.begin(), nonces.end());
std::unique(nonces.begin(), nonces.end());
EXPECT_EQ(allSharedSecrets().size(), nonces.size());
EXPECT_EQ(sharedSecrets.size(), nonces.size());
auto responses = computeAllSharedSecrets(params);
ASSERT_GT(responses.size(), 0U);
@@ -163,7 +170,7 @@ TEST_F(SharedSecretAidlTest, ComputeSharedSecret) {
// Do it a second time. Should get the same answers.
params = getAllSharedSecretParameters();
ASSERT_EQ(allSharedSecrets().size(), params.size())
ASSERT_EQ(sharedSecrets.size(), params.size())
<< "One or more shared secret services failed to provide parameters.";
responses = computeAllSharedSecrets(params);
@@ -188,10 +195,14 @@ inline final_action<F> finally(const F& f) {
}
TEST_F(SharedSecretAidlTest, ComputeSharedSecretCorruptNonce) {
auto sharedSecrets = allSharedSecrets();
if (sharedSecrets.empty()) {
GTEST_SKIP() << "Skipping the test as no shared secret service is found.";
}
auto fixup_hmac = finally([&]() { computeAllSharedSecrets(getAllSharedSecretParameters()); });
auto params = getAllSharedSecretParameters();
ASSERT_EQ(allSharedSecrets().size(), params.size())
ASSERT_EQ(sharedSecrets.size(), params.size())
<< "One or more shared secret services failed to provide parameters.";
// All should be well in the normal case
@@ -224,9 +235,13 @@ TEST_F(SharedSecretAidlTest, ComputeSharedSecretCorruptNonce) {
}
TEST_F(SharedSecretAidlTest, ComputeSharedSecretCorruptSeed) {
auto sharedSecrets = allSharedSecrets();
if (sharedSecrets.empty()) {
GTEST_SKIP() << "Skipping the test as no shared secret service is found.";
}
auto fixup_hmac = finally([&]() { computeAllSharedSecrets(getAllSharedSecretParameters()); });
auto params = getAllSharedSecretParameters();
ASSERT_EQ(allSharedSecrets().size(), params.size())
ASSERT_EQ(sharedSecrets.size(), params.size())
<< "One or more shared secret service failed to provide parameters.";
// All should be well in the normal case