未验证 提交 a0ed04a3 编写于 作者: O openharmony_ci 提交者: Gitee

!9014 bugfix: 测试用例执行失败Map fd to address failed!

Merge pull request !9014 from 汤石华/master
......@@ -42,6 +42,14 @@ MockIDevice::~MockIDevice()
}
}
MockIPreparedModel::~MockIPreparedModel()
{
for (auto ash : m_ashmems) {
ash.second->UnmapAshmem();
ash.second->CloseAshmem();
}
}
MockIDevice *MockIDevice::GetInstance()
{
static MockIDevice iDevice;
......@@ -148,6 +156,11 @@ int32_t MockIDevice::IsModelCacheSupported(bool& isSupported)
int32_t MockIDevice::AllocateBuffer(uint32_t length, SharedBuffer &buffer)
{
std::lock_guard<std::mutex> lock(m_mtx);
for(auto ash:m_ashmems){
if(ash.second->GetAshmemSize() <= 0){
ash.second->CloseAshmem();
}
}
sptr<Ashmem> ashptr = Ashmem::CreateAshmem("allocateBuffer", length);
if (ashptr == nullptr) {
LOGE("[NNRtTest] Create shared memory failed.");
......@@ -231,6 +244,9 @@ int32_t MockIPreparedModel::ExportModelCache(std::vector<SharedBuffer>& modelCac
LOGE("[NNRtTest] Map fd to write cache failed.");
return HDF_FAILURE;
}
int fd = cache->GetAshmemFd();
m_ashmems[fd] = cache;
ret = cache->WriteToAshmem(buffer, size, 0);
cache->UnmapAshmem();
......@@ -238,6 +254,7 @@ int32_t MockIPreparedModel::ExportModelCache(std::vector<SharedBuffer>& modelCac
LOGE("[NNRtTest] Write cache failed.");
return HDF_FAILURE;
}
// SharedBuffer: fd, bufferSize, offset, dataSize
modelCache.emplace_back(SharedBuffer {cache->GetAshmemFd(), cache->GetAshmemSize(), 0, cache->GetAshmemSize()});
return HDF_SUCCESS;
......
......@@ -111,6 +111,9 @@ public:
std::vector<std::vector<int32_t>>& outputsDims, std::vector<bool>& isOutputBufferEnough) override;
int32_t GetVersion(uint32_t &majorVersion, uint32_t &minorVersion) override;
MockIPreparedModel() = default;
virtual ~MockIPreparedModel();
private:
std::unordered_map<int, sptr<Ashmem>> m_ashmems;
};
} // namespace V1_0
......
......@@ -42,6 +42,14 @@ MockIDevice::~MockIDevice()
}
}
MockIPreparedModel::~MockIPreparedModel()
{
for (auto ash : m_ashmems) {
ash.second->UnmapAshmem();
ash.second->CloseAshmem();
}
}
MockIDevice *MockIDevice::GetInstance()
{
static MockIDevice iDevice;
......@@ -148,6 +156,11 @@ int32_t MockIDevice::IsModelCacheSupported(bool& isSupported)
int32_t MockIDevice::AllocateBuffer(uint32_t length, SharedBuffer &buffer)
{
std::lock_guard<std::mutex> lock(m_mtx);
for(auto ash:m_ashmems){
if(ash.second->GetAshmemSize() <= 0){
ash.second->CloseAshmem();
}
}
sptr<Ashmem> ashptr = Ashmem::CreateAshmem("allocateBuffer", length);
if (ashptr == nullptr) {
LOGE("[NNRtTest] Create shared memory failed.");
......@@ -238,6 +251,8 @@ int32_t MockIPreparedModel::ExportModelCache(std::vector<SharedBuffer>& modelCac
LOGE("[NNRtTest] Map fd to write cache failed.");
return HDF_FAILURE;
}
int fd = cache->GetAshmemFd();
m_ashmems[fd] = cache;
ret = cache->WriteToAshmem(buffer, size, 0);
cache->UnmapAshmem();
......
......@@ -115,6 +115,9 @@ public:
int32_t GetInputDimRanges(std::vector<std::vector<uint32_t>>& minInputDims, std::vector<std::vector<uint32_t>>& maxInputDims) override;
int32_t GetVersion(uint32_t &majorVersion, uint32_t &minorVersion) override;
MockIPreparedModel() = default;
virtual ~MockIPreparedModel();
private:
std::unordered_map<int, sptr<Ashmem>> m_ashmems;
};
} // namespace V2_0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册