KeyMint VTS: fix flipped error messages

Also make main() shorter by `using`.

Bug: 317693523
Test: VtsAidlKeyMintTargetTest
Change-Id: Ife6048001a003e387927338dfcf7a4b2293576c7
This commit is contained in:
David Drysdale 2024-01-03 11:22:56 +00:00
parent 5df990f75d
commit 77a86d8dae
2 changed files with 20 additions and 16 deletions

View file

@ -258,7 +258,8 @@ class KeyBlobUpgradeTest : public KeyMintAidlTestBase {
if (upgraded_keyblob.empty()) {
std::cerr << "Keyblob '" << name << "' did not require upgrade\n";
EXPECT_TRUE(!expectUpgrade) << "Keyblob '" << name << "' unexpectedly upgraded";
EXPECT_FALSE(expectUpgrade)
<< "Keyblob '" << name << "' unexpectedly left as-is";
} else {
// Ensure the old format keyblob is deleted (so any secure deletion data is
// cleaned up).
@ -275,8 +276,7 @@ class KeyBlobUpgradeTest : public KeyMintAidlTestBase {
save_keyblob(subdir, name, upgraded_keyblob, key_characteristics);
// Cert file is left unchanged.
std::cerr << "Keyblob '" << name << "' upgraded\n";
EXPECT_TRUE(expectUpgrade)
<< "Keyblob '" << name << "' unexpectedly left as-is";
EXPECT_TRUE(expectUpgrade) << "Keyblob '" << name << "' unexpectedly upgraded";
}
}
}

View file

@ -8796,10 +8796,11 @@ INSTANTIATE_KEYMINT_AIDL_TEST(VsrRequirementTest);
} // namespace aidl::android::hardware::security::keymint::test
using aidl::android::hardware::security::keymint::test::KeyMintAidlTestBase;
int main(int argc, char** argv) {
std::cout << "Testing ";
auto halInstances =
aidl::android::hardware::security::keymint::test::KeyMintAidlTestBase::build_params();
auto halInstances = KeyMintAidlTestBase::build_params();
std::cout << "HAL instances:\n";
for (auto& entry : halInstances) {
std::cout << " " << entry << '\n';
@ -8809,12 +8810,10 @@ int main(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
if (argv[i][0] == '-') {
if (std::string(argv[i]) == "--arm_deleteAllKeys") {
aidl::android::hardware::security::keymint::test::KeyMintAidlTestBase::
arm_deleteAllKeys = true;
KeyMintAidlTestBase::arm_deleteAllKeys = true;
}
if (std::string(argv[i]) == "--dump_attestations") {
aidl::android::hardware::security::keymint::test::KeyMintAidlTestBase::
dump_Attestations = true;
KeyMintAidlTestBase::dump_Attestations = true;
} else {
std::cout << "NOT dumping attestations" << std::endl;
}
@ -8829,8 +8828,7 @@ int main(int argc, char** argv) {
std::cerr << "Missing argument for --keyblob_dir\n";
return 1;
}
aidl::android::hardware::security::keymint::test::KeyMintAidlTestBase::keyblob_dir =
std::string(argv[i + 1]);
KeyMintAidlTestBase::keyblob_dir = std::string(argv[i + 1]);
++i;
}
if (std::string(argv[i]) == "--expect_upgrade") {
@ -8839,11 +8837,17 @@ int main(int argc, char** argv) {
return 1;
}
std::string arg = argv[i + 1];
aidl::android::hardware::security::keymint::test::KeyMintAidlTestBase::
expect_upgrade =
arg == "yes"
? true
: (arg == "no" ? false : std::optional<bool>(std::nullopt));
KeyMintAidlTestBase::expect_upgrade =
arg == "yes" ? true
: (arg == "no" ? false : std::optional<bool>(std::nullopt));
if (KeyMintAidlTestBase::expect_upgrade.has_value()) {
std::cout << "expect_upgrade = "
<< (KeyMintAidlTestBase::expect_upgrade.value() ? "true" : "false")
<< std::endl;
} else {
std::cerr << "Error! Option --expect_upgrade " << arg << " unrecognized"
<< std::endl;
}
++i;
}
}