Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.cpp +32 −24 Original line number Diff line number Diff line Loading @@ -71,32 +71,42 @@ android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onSetP } android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onGetProperty( int32_t prop) { ALOGV("onGetProperty(%d)", prop); switch (prop) { const VehiclePropValue& value) { ALOGV("onGetProperty(%s)", toString(value).c_str()); switch (value.prop) { case INITIAL_USER_INFO: case SWITCH_USER: case CREATE_USER: case REMOVE_USER: ALOGE("onGetProperty(): %d is only supported on SET", prop); ALOGE("onGetProperty(): %d is only supported on SET", value.prop); return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG)) << "only supported on SET"; case USER_IDENTIFICATION_ASSOCIATION: return onGetUserIdentificationAssociation(value); default: ALOGE("onGetProperty(): %d is not supported", value.prop); return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG)) << "not supported by User HAL"; } } android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onGetUserIdentificationAssociation(const VehiclePropValue& value) { if (mSetUserIdentificationAssociationResponseFromCmd != nullptr) { ALOGI("onGetProperty(%d): returning %s", prop, ALOGI("get(USER_IDENTIFICATION_ASSOCIATION): returning %s", toString(*mSetUserIdentificationAssociationResponseFromCmd).c_str()); auto value = std::unique_ptr<VehiclePropValue>( auto newValue = std::unique_ptr<VehiclePropValue>( new VehiclePropValue(*mSetUserIdentificationAssociationResponseFromCmd)); return value; // Must use the same requestId if (value.value.int32Values.size() > 0) { newValue->value.int32Values[0] = value.value.int32Values[0]; } else { ALOGE("get(USER_IDENTIFICATION_ASSOCIATION): no requestId on %s", toString(value).c_str()); } ALOGE("onGetProperty(%d): USER_IDENTIFICATION_ASSOCIATION not set by lshal", prop); return android::base::Error(static_cast<int>(StatusCode::NOT_AVAILABLE)) << "not set by lshal"; default: ALOGE("onGetProperty(): %d is not supported", prop); return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG)) << "not supported by User HAL"; return newValue; } return defaultUserIdentificationAssociation(value); } android::base::Result<std::unique_ptr<VehiclePropValue>> Loading Loading @@ -250,16 +260,14 @@ EmulatedUserHal::onSetUserIdentificationAssociation(const VehiclePropValue& valu } // Returns default response auto updatedValue = std::unique_ptr<VehiclePropValue>(new VehiclePropValue); updatedValue->prop = USER_IDENTIFICATION_ASSOCIATION; updatedValue->timestamp = elapsedRealtimeNano(); updatedValue->value.int32Values.resize(1); updatedValue->value.int32Values[0] = requestId; updatedValue->value.stringValue = "Response not set by LSHAL"; ALOGI("no lshal response; replying with an error message: %s", toString(*updatedValue).c_str()); return defaultUserIdentificationAssociation(value); } return updatedValue; android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::defaultUserIdentificationAssociation(const VehiclePropValue& request) { // TODO(b/159498909): return a response with NOT_ASSOCIATED_ANY_USER for all requested types ALOGE("no lshal response for %s; replying with NOT_AVAILABLE", toString(request).c_str()); return android::base::Error(static_cast<int>(StatusCode::NOT_AVAILABLE)) << "not set by lshal"; } android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::sendUserHalResponse( Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.h +16 −2 Original line number Diff line number Diff line Loading @@ -58,7 +58,8 @@ class EmulatedUserHal { * * @return property value and StatusCode */ android::base::Result<std::unique_ptr<VehiclePropValue>> onGetProperty(int32_t prop); android::base::Result<std::unique_ptr<VehiclePropValue>> onGetProperty( const VehiclePropValue& value); /** * Shows the User HAL emulation help. Loading Loading @@ -111,12 +112,25 @@ class EmulatedUserHal { const VehiclePropValue& value); /** * Used to emulate USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for * Used to emulate set USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for * usage. */ android::base::Result<std::unique_ptr<VehiclePropValue>> onSetUserIdentificationAssociation( const VehiclePropValue& value); /** * Used to emulate get USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for * usage. */ android::base::Result<std::unique_ptr<VehiclePropValue>> onGetUserIdentificationAssociation( const VehiclePropValue& value); /** * Creates a default USER_IDENTIFICATION_ASSOCIATION when it was not set by lshal. */ android::base::Result<std::unique_ptr<VehiclePropValue>> defaultUserIdentificationAssociation( const VehiclePropValue& request); android::base::Result<std::unique_ptr<VehiclePropValue>> sendUserHalResponse( std::unique_ptr<VehiclePropValue> response, int32_t requestId); Loading automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -153,7 +153,7 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( default: if (mEmulatedUserHal != nullptr && mEmulatedUserHal->isSupported(propId)) { ALOGI("get(): getting value for prop %d from User HAL", propId); const auto& ret = mEmulatedUserHal->onGetProperty(propId); const auto& ret = mEmulatedUserHal->onGetProperty(requestedPropValue); if (!ret.ok()) { ALOGE("get(): User HAL returned error: %s", ret.error().message().c_str()); *outStatus = StatusCode(ret.error().code()); Loading graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp +50 −0 Original line number Diff line number Diff line Loading @@ -661,6 +661,56 @@ TEST_P(GraphicsMapperHidlTest, Lock_YCRCB_420_SP) { ASSERT_NO_FATAL_FAILURE(fence.reset(mGralloc->unlock(bufferHandle))); } TEST_P(GraphicsMapperHidlTest, YV12SubsampleMetadata) { auto info = mDummyDescriptorInfo; info.format = PixelFormat::YV12; const native_handle_t* bufferHandle; uint32_t stride; ASSERT_NO_FATAL_FAILURE( bufferHandle = mGralloc->allocate(info, true, Tolerance::kToleranceStrict, &stride)); const IMapper::Rect region{0, 0, static_cast<int32_t>(info.width), static_cast<int32_t>(info.height)}; unique_fd fence; ASSERT_NO_FATAL_FAILURE(mGralloc->lock(bufferHandle, info.usage, region, fence.release())); hidl_vec<uint8_t> vec; ASSERT_EQ(Error::NONE, mGralloc->get(bufferHandle, gralloc4::MetadataType_PlaneLayouts, &vec)); std::vector<PlaneLayout> planeLayouts; ASSERT_EQ(NO_ERROR, gralloc4::decodePlaneLayouts(vec, &planeLayouts)); ASSERT_EQ(3, planeLayouts.size()); auto yPlane = planeLayouts[0]; auto crPlane = planeLayouts[1]; auto cbPlane = planeLayouts[2]; constexpr uint32_t kCbCrSubSampleFactor = 2; EXPECT_EQ(kCbCrSubSampleFactor, crPlane.horizontalSubsampling); EXPECT_EQ(kCbCrSubSampleFactor, crPlane.verticalSubsampling); EXPECT_EQ(kCbCrSubSampleFactor, cbPlane.horizontalSubsampling); EXPECT_EQ(kCbCrSubSampleFactor, cbPlane.verticalSubsampling); const long chromaSampleWidth = info.width / kCbCrSubSampleFactor; const long chromaSampleHeight = info.height / kCbCrSubSampleFactor; EXPECT_EQ(info.width, yPlane.widthInSamples); EXPECT_EQ(info.height, yPlane.heightInSamples); EXPECT_EQ(chromaSampleWidth, crPlane.widthInSamples); EXPECT_EQ(chromaSampleHeight, crPlane.heightInSamples); EXPECT_EQ(chromaSampleWidth, cbPlane.widthInSamples); EXPECT_EQ(chromaSampleHeight, cbPlane.heightInSamples); EXPECT_LE(crPlane.widthInSamples, crPlane.strideInBytes); EXPECT_LE(cbPlane.widthInSamples, cbPlane.strideInBytes); ASSERT_NO_FATAL_FAILURE(fence.reset(mGralloc->unlock(bufferHandle))); } TEST_P(GraphicsMapperHidlTest, Lock_YV12) { auto info = mDummyDescriptorInfo; info.format = PixelFormat::YV12; Loading neuralnetworks/1.2/vts/functional/CompilationCachingTests.cpp +9 −38 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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); Loading Loading @@ -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; Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.cpp +32 −24 Original line number Diff line number Diff line Loading @@ -71,32 +71,42 @@ android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onSetP } android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onGetProperty( int32_t prop) { ALOGV("onGetProperty(%d)", prop); switch (prop) { const VehiclePropValue& value) { ALOGV("onGetProperty(%s)", toString(value).c_str()); switch (value.prop) { case INITIAL_USER_INFO: case SWITCH_USER: case CREATE_USER: case REMOVE_USER: ALOGE("onGetProperty(): %d is only supported on SET", prop); ALOGE("onGetProperty(): %d is only supported on SET", value.prop); return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG)) << "only supported on SET"; case USER_IDENTIFICATION_ASSOCIATION: return onGetUserIdentificationAssociation(value); default: ALOGE("onGetProperty(): %d is not supported", value.prop); return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG)) << "not supported by User HAL"; } } android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::onGetUserIdentificationAssociation(const VehiclePropValue& value) { if (mSetUserIdentificationAssociationResponseFromCmd != nullptr) { ALOGI("onGetProperty(%d): returning %s", prop, ALOGI("get(USER_IDENTIFICATION_ASSOCIATION): returning %s", toString(*mSetUserIdentificationAssociationResponseFromCmd).c_str()); auto value = std::unique_ptr<VehiclePropValue>( auto newValue = std::unique_ptr<VehiclePropValue>( new VehiclePropValue(*mSetUserIdentificationAssociationResponseFromCmd)); return value; // Must use the same requestId if (value.value.int32Values.size() > 0) { newValue->value.int32Values[0] = value.value.int32Values[0]; } else { ALOGE("get(USER_IDENTIFICATION_ASSOCIATION): no requestId on %s", toString(value).c_str()); } ALOGE("onGetProperty(%d): USER_IDENTIFICATION_ASSOCIATION not set by lshal", prop); return android::base::Error(static_cast<int>(StatusCode::NOT_AVAILABLE)) << "not set by lshal"; default: ALOGE("onGetProperty(): %d is not supported", prop); return android::base::Error(static_cast<int>(StatusCode::INVALID_ARG)) << "not supported by User HAL"; return newValue; } return defaultUserIdentificationAssociation(value); } android::base::Result<std::unique_ptr<VehiclePropValue>> Loading Loading @@ -250,16 +260,14 @@ EmulatedUserHal::onSetUserIdentificationAssociation(const VehiclePropValue& valu } // Returns default response auto updatedValue = std::unique_ptr<VehiclePropValue>(new VehiclePropValue); updatedValue->prop = USER_IDENTIFICATION_ASSOCIATION; updatedValue->timestamp = elapsedRealtimeNano(); updatedValue->value.int32Values.resize(1); updatedValue->value.int32Values[0] = requestId; updatedValue->value.stringValue = "Response not set by LSHAL"; ALOGI("no lshal response; replying with an error message: %s", toString(*updatedValue).c_str()); return defaultUserIdentificationAssociation(value); } return updatedValue; android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::defaultUserIdentificationAssociation(const VehiclePropValue& request) { // TODO(b/159498909): return a response with NOT_ASSOCIATED_ANY_USER for all requested types ALOGE("no lshal response for %s; replying with NOT_AVAILABLE", toString(request).c_str()); return android::base::Error(static_cast<int>(StatusCode::NOT_AVAILABLE)) << "not set by lshal"; } android::base::Result<std::unique_ptr<VehiclePropValue>> EmulatedUserHal::sendUserHalResponse( Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedUserHal.h +16 −2 Original line number Diff line number Diff line Loading @@ -58,7 +58,8 @@ class EmulatedUserHal { * * @return property value and StatusCode */ android::base::Result<std::unique_ptr<VehiclePropValue>> onGetProperty(int32_t prop); android::base::Result<std::unique_ptr<VehiclePropValue>> onGetProperty( const VehiclePropValue& value); /** * Shows the User HAL emulation help. Loading Loading @@ -111,12 +112,25 @@ class EmulatedUserHal { const VehiclePropValue& value); /** * Used to emulate USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for * Used to emulate set USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for * usage. */ android::base::Result<std::unique_ptr<VehiclePropValue>> onSetUserIdentificationAssociation( const VehiclePropValue& value); /** * Used to emulate get USER_IDENTIFICATION_ASSOCIATION - see onSetInitialUserInfoResponse() for * usage. */ android::base::Result<std::unique_ptr<VehiclePropValue>> onGetUserIdentificationAssociation( const VehiclePropValue& value); /** * Creates a default USER_IDENTIFICATION_ASSOCIATION when it was not set by lshal. */ android::base::Result<std::unique_ptr<VehiclePropValue>> defaultUserIdentificationAssociation( const VehiclePropValue& request); android::base::Result<std::unique_ptr<VehiclePropValue>> sendUserHalResponse( std::unique_ptr<VehiclePropValue> response, int32_t requestId); Loading
automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -153,7 +153,7 @@ VehicleHal::VehiclePropValuePtr EmulatedVehicleHal::get( default: if (mEmulatedUserHal != nullptr && mEmulatedUserHal->isSupported(propId)) { ALOGI("get(): getting value for prop %d from User HAL", propId); const auto& ret = mEmulatedUserHal->onGetProperty(propId); const auto& ret = mEmulatedUserHal->onGetProperty(requestedPropValue); if (!ret.ok()) { ALOGE("get(): User HAL returned error: %s", ret.error().message().c_str()); *outStatus = StatusCode(ret.error().code()); Loading
graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp +50 −0 Original line number Diff line number Diff line Loading @@ -661,6 +661,56 @@ TEST_P(GraphicsMapperHidlTest, Lock_YCRCB_420_SP) { ASSERT_NO_FATAL_FAILURE(fence.reset(mGralloc->unlock(bufferHandle))); } TEST_P(GraphicsMapperHidlTest, YV12SubsampleMetadata) { auto info = mDummyDescriptorInfo; info.format = PixelFormat::YV12; const native_handle_t* bufferHandle; uint32_t stride; ASSERT_NO_FATAL_FAILURE( bufferHandle = mGralloc->allocate(info, true, Tolerance::kToleranceStrict, &stride)); const IMapper::Rect region{0, 0, static_cast<int32_t>(info.width), static_cast<int32_t>(info.height)}; unique_fd fence; ASSERT_NO_FATAL_FAILURE(mGralloc->lock(bufferHandle, info.usage, region, fence.release())); hidl_vec<uint8_t> vec; ASSERT_EQ(Error::NONE, mGralloc->get(bufferHandle, gralloc4::MetadataType_PlaneLayouts, &vec)); std::vector<PlaneLayout> planeLayouts; ASSERT_EQ(NO_ERROR, gralloc4::decodePlaneLayouts(vec, &planeLayouts)); ASSERT_EQ(3, planeLayouts.size()); auto yPlane = planeLayouts[0]; auto crPlane = planeLayouts[1]; auto cbPlane = planeLayouts[2]; constexpr uint32_t kCbCrSubSampleFactor = 2; EXPECT_EQ(kCbCrSubSampleFactor, crPlane.horizontalSubsampling); EXPECT_EQ(kCbCrSubSampleFactor, crPlane.verticalSubsampling); EXPECT_EQ(kCbCrSubSampleFactor, cbPlane.horizontalSubsampling); EXPECT_EQ(kCbCrSubSampleFactor, cbPlane.verticalSubsampling); const long chromaSampleWidth = info.width / kCbCrSubSampleFactor; const long chromaSampleHeight = info.height / kCbCrSubSampleFactor; EXPECT_EQ(info.width, yPlane.widthInSamples); EXPECT_EQ(info.height, yPlane.heightInSamples); EXPECT_EQ(chromaSampleWidth, crPlane.widthInSamples); EXPECT_EQ(chromaSampleHeight, crPlane.heightInSamples); EXPECT_EQ(chromaSampleWidth, cbPlane.widthInSamples); EXPECT_EQ(chromaSampleHeight, cbPlane.heightInSamples); EXPECT_LE(crPlane.widthInSamples, crPlane.strideInBytes); EXPECT_LE(cbPlane.widthInSamples, cbPlane.strideInBytes); ASSERT_NO_FATAL_FAILURE(fence.reset(mGralloc->unlock(bufferHandle))); } TEST_P(GraphicsMapperHidlTest, Lock_YV12) { auto info = mDummyDescriptorInfo; info.format = PixelFormat::YV12; Loading
neuralnetworks/1.2/vts/functional/CompilationCachingTests.cpp +9 −38 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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); Loading Loading @@ -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; Loading Loading @@ -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. Loading Loading @@ -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. Loading