summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXusong Wang <xusongw@google.com>2020-06-22 18:04:33 +0000
committerXusong Wang <xusongw@google.com>2020-06-22 18:36:07 +0000
commit81fa7605cff32efbc62b5b74b975b51a9d7ab27b (patch)
tree5570321e5982f1cf1bcb64a368a0a5167212b451
parent362dfd64d5c2a431dc5138f0ac6dab4f0c23f690 (diff)
Revert "Allow compilations in TOCTOU tests to fail with GENERAL_FAILURE."
This reverts commit 362dfd64d5c2a431dc5138f0ac6dab4f0c23f690. Bug: 157489048 Test: 1.2/1.3 VTS TOCTOU tests Change-Id: Ifdf4a8fab129cd90a3be019c3c598d980b785aaa
-rw-r--r--neuralnetworks/1.2/vts/functional/CompilationCachingTests.cpp47
-rw-r--r--neuralnetworks/1.3/vts/functional/CompilationCachingTests.cpp47
2 files changed, 18 insertions, 76 deletions
diff --git a/neuralnetworks/1.2/vts/functional/CompilationCachingTests.cpp b/neuralnetworks/1.2/vts/functional/CompilationCachingTests.cpp
index 16b313a855..449b8f369d 100644
--- a/neuralnetworks/1.2/vts/functional/CompilationCachingTests.cpp
+++ b/neuralnetworks/1.2/vts/functional/CompilationCachingTests.cpp
@@ -315,8 +315,7 @@ class CompilationCachingTestBase : public testing::Test {
void saveModelToCache(const Model& model, const hidl_vec<hidl_handle>& modelCache,
const hidl_vec<hidl_handle>& dataCache,
- sp<IPreparedModel>* preparedModel = nullptr,
- bool allowGeneralFailure = false) {
+ sp<IPreparedModel>* preparedModel = nullptr) {
if (preparedModel != nullptr) *preparedModel = nullptr;
// Launch prepare model.
@@ -330,10 +329,7 @@ class CompilationCachingTestBase : public testing::Test {
// Retrieve prepared model.
preparedModelCallback->wait();
- const auto prepareCallbackStatus = preparedModelCallback->getStatus();
- if (!allowGeneralFailure || prepareCallbackStatus != ErrorStatus::GENERAL_FAILURE) {
- ASSERT_EQ(prepareCallbackStatus, ErrorStatus::NONE);
- }
+ ASSERT_EQ(preparedModelCallback->getStatus(), ErrorStatus::NONE);
if (preparedModel != nullptr) {
*preparedModel = IPreparedModel::castFrom(preparedModelCallback->getPreparedModel())
.withDefault(nullptr);
@@ -1026,8 +1022,7 @@ static void copyCacheFiles(const std::vector<std::vector<std::string>>& from,
// Number of operations in the large test model.
constexpr uint32_t kLargeModelSize = 100;
-constexpr uint32_t kNumSuccessfulIterationsTOCTOU = 100;
-constexpr uint32_t kMaxNumFailedIterationsTOCTOU = 100;
+constexpr uint32_t kNumIterationsTOCTOU = 100;
TEST_P(CompilationCachingTest, SaveToCache_TOCTOU) {
if (!mIsCachingSupported) return;
@@ -1055,30 +1050,18 @@ TEST_P(CompilationCachingTest, SaveToCache_TOCTOU) {
// Use a different token for modelAdd.
mToken[0]++;
- // This test is probabilistic, so we run it multiple times. We allow the compilation to fail
- // because it is not related to the security aspect of the TOCTOU test. However, we need to have
- // enough successful iterations to ensure the test coverage.
- uint32_t numSuccessfulIterations = 0, numFailedIterations = 0;
- while (numSuccessfulIterations < kNumSuccessfulIterationsTOCTOU) {
+ // This test is probabilistic, so we run it multiple times.
+ for (uint32_t i = 0; i < kNumIterationsTOCTOU; i++) {
// Save the modelAdd compilation to cache.
{
hidl_vec<hidl_handle> modelCache, dataCache;
createCacheHandles(mModelCache, AccessMode::READ_WRITE, &modelCache);
createCacheHandles(mDataCache, AccessMode::READ_WRITE, &dataCache);
- sp<IPreparedModel> preparedModel = nullptr;
// Spawn a thread to copy the cache content concurrently while saving to cache.
std::thread thread(copyCacheFiles, std::cref(modelCacheMul), std::cref(mModelCache));
- saveModelToCache(modelAdd, modelCache, dataCache, &preparedModel,
- /*allowGeneralFailure=*/true);
+ saveModelToCache(modelAdd, modelCache, dataCache);
thread.join();
-
- if (preparedModel == nullptr) {
- numFailedIterations++;
- ASSERT_LE(numFailedIterations, kMaxNumFailedIterationsTOCTOU);
- } else {
- numSuccessfulIterations++;
- }
}
// Retrieve preparedModel from cache.
@@ -1129,26 +1112,14 @@ TEST_P(CompilationCachingTest, PrepareFromCache_TOCTOU) {
// Use a different token for modelAdd.
mToken[0]++;
- // This test is probabilistic, so we run it multiple times. We allow the compilation to fail
- // because it is not related to the security aspect of the TOCTOU test. However, we need to have
- // enough successful iterations to ensure the test coverage.
- uint32_t numSuccessfulIterations = 0, numFailedIterations = 0;
- while (numSuccessfulIterations < kNumSuccessfulIterationsTOCTOU) {
+ // This test is probabilistic, so we run it multiple times.
+ for (uint32_t i = 0; i < kNumIterationsTOCTOU; i++) {
// Save the modelAdd compilation to cache.
{
hidl_vec<hidl_handle> modelCache, dataCache;
createCacheHandles(mModelCache, AccessMode::READ_WRITE, &modelCache);
createCacheHandles(mDataCache, AccessMode::READ_WRITE, &dataCache);
- sp<IPreparedModel> preparedModel = nullptr;
- saveModelToCache(modelAdd, modelCache, dataCache, &preparedModel,
- /*allowGeneralFailure=*/true);
-
- if (preparedModel == nullptr) {
- numFailedIterations++;
- ASSERT_LE(numFailedIterations, kMaxNumFailedIterationsTOCTOU);
- } else {
- numSuccessfulIterations++;
- }
+ saveModelToCache(modelAdd, modelCache, dataCache);
}
// Retrieve preparedModel from cache.
diff --git a/neuralnetworks/1.3/vts/functional/CompilationCachingTests.cpp b/neuralnetworks/1.3/vts/functional/CompilationCachingTests.cpp
index 382fc767f7..ac18c8ffcc 100644
--- a/neuralnetworks/1.3/vts/functional/CompilationCachingTests.cpp
+++ b/neuralnetworks/1.3/vts/functional/CompilationCachingTests.cpp
@@ -318,8 +318,7 @@ class CompilationCachingTestBase : public testing::Test {
void saveModelToCache(const Model& model, const hidl_vec<hidl_handle>& modelCache,
const hidl_vec<hidl_handle>& dataCache,
- sp<IPreparedModel>* preparedModel = nullptr,
- bool allowGeneralFailure = false) {
+ sp<IPreparedModel>* preparedModel = nullptr) {
if (preparedModel != nullptr) *preparedModel = nullptr;
// Launch prepare model.
@@ -333,10 +332,7 @@ class CompilationCachingTestBase : public testing::Test {
// Retrieve prepared model.
preparedModelCallback->wait();
- const auto prepareCallbackStatus = preparedModelCallback->getStatus();
- if (!allowGeneralFailure || prepareCallbackStatus != ErrorStatus::GENERAL_FAILURE) {
- ASSERT_EQ(prepareCallbackStatus, ErrorStatus::NONE);
- }
+ ASSERT_EQ(preparedModelCallback->getStatus(), ErrorStatus::NONE);
if (preparedModel != nullptr) {
*preparedModel = IPreparedModel::castFrom(preparedModelCallback->getPreparedModel())
.withDefault(nullptr);
@@ -1017,8 +1013,7 @@ static void copyCacheFiles(const std::vector<std::vector<std::string>>& from,
// Number of operations in the large test model.
constexpr uint32_t kLargeModelSize = 100;
-constexpr uint32_t kNumSuccessfulIterationsTOCTOU = 100;
-constexpr uint32_t kMaxNumFailedIterationsTOCTOU = 100;
+constexpr uint32_t kNumIterationsTOCTOU = 100;
TEST_P(CompilationCachingTest, SaveToCache_TOCTOU) {
if (!mIsCachingSupported) return;
@@ -1046,30 +1041,18 @@ TEST_P(CompilationCachingTest, SaveToCache_TOCTOU) {
// Use a different token for modelAdd.
mToken[0]++;
- // This test is probabilistic, so we run it multiple times. We allow the compilation to fail
- // because it is not related to the security aspect of the TOCTOU test. However, we need to have
- // enough successful iterations to ensure the test coverage.
- uint32_t numSuccessfulIterations = 0, numFailedIterations = 0;
- while (numSuccessfulIterations < kNumSuccessfulIterationsTOCTOU) {
+ // This test is probabilistic, so we run it multiple times.
+ for (uint32_t i = 0; i < kNumIterationsTOCTOU; i++) {
// Save the modelAdd compilation to cache.
{
hidl_vec<hidl_handle> modelCache, dataCache;
createCacheHandles(mModelCache, AccessMode::READ_WRITE, &modelCache);
createCacheHandles(mDataCache, AccessMode::READ_WRITE, &dataCache);
- sp<IPreparedModel> preparedModel = nullptr;
// Spawn a thread to copy the cache content concurrently while saving to cache.
std::thread thread(copyCacheFiles, std::cref(modelCacheMul), std::cref(mModelCache));
- saveModelToCache(modelAdd, modelCache, dataCache, &preparedModel,
- /*allowGeneralFailure=*/true);
+ saveModelToCache(modelAdd, modelCache, dataCache);
thread.join();
-
- if (preparedModel == nullptr) {
- numFailedIterations++;
- ASSERT_LE(numFailedIterations, kMaxNumFailedIterationsTOCTOU);
- } else {
- numSuccessfulIterations++;
- }
}
// Retrieve preparedModel from cache.
@@ -1120,26 +1103,14 @@ TEST_P(CompilationCachingTest, PrepareFromCache_TOCTOU) {
// Use a different token for modelAdd.
mToken[0]++;
- // This test is probabilistic, so we run it multiple times. We allow the compilation to fail
- // because it is not related to the security aspect of the TOCTOU test. However, we need to have
- // enough successful iterations to ensure the test coverage.
- uint32_t numSuccessfulIterations = 0, numFailedIterations = 0;
- while (numSuccessfulIterations < kNumSuccessfulIterationsTOCTOU) {
+ // This test is probabilistic, so we run it multiple times.
+ for (uint32_t i = 0; i < kNumIterationsTOCTOU; i++) {
// Save the modelAdd compilation to cache.
{
hidl_vec<hidl_handle> modelCache, dataCache;
createCacheHandles(mModelCache, AccessMode::READ_WRITE, &modelCache);
createCacheHandles(mDataCache, AccessMode::READ_WRITE, &dataCache);
- sp<IPreparedModel> preparedModel = nullptr;
- saveModelToCache(modelAdd, modelCache, dataCache, &preparedModel,
- /*allowGeneralFailure=*/true);
-
- if (preparedModel == nullptr) {
- numFailedIterations++;
- ASSERT_LE(numFailedIterations, kMaxNumFailedIterationsTOCTOU);
- } else {
- numSuccessfulIterations++;
- }
+ saveModelToCache(modelAdd, modelCache, dataCache);
}
// Retrieve preparedModel from cache.