summaryrefslogtreecommitdiff
path: root/nn/runtime/test/TestGenerated.cpp
diff options
context:
space:
mode:
authorXusong Wang <xusongw@google.com>2020-04-28 16:05:48 -0700
committerXusong Wang <xusongw@google.com>2020-04-30 18:13:25 -0700
commit7f7e3874339e9ff4fe3bdb24e627f4e0f7edcf97 (patch)
tree9e42c78bfd8ab2f669b386e2701b6d57d400611f /nn/runtime/test/TestGenerated.cpp
parent5d35af6b9f37fcb97d493bcfbfb0a99f5ed44357 (diff)
downloadml-7f7e3874339e9ff4fe3bdb24e627f4e0f7edcf97.tar.gz
Add internal NNT_static tests for buffer copying.
This helps cover the code path of data copying between hidl memory and IBuffer, as well as data copying between IBuffers. These code paths may not be covered by CTS because of the lack of driver support. This CL additionally extracts TestAshmem class from TestGenerated to a common TestUtils. Bug: 152209365 Test: NNT_static Change-Id: I617bfbc391c7d0ada0c32b31ee2e6e493d5dc6a2
Diffstat (limited to 'nn/runtime/test/TestGenerated.cpp')
-rw-r--r--nn/runtime/test/TestGenerated.cpp47
1 files changed, 1 insertions, 46 deletions
diff --git a/nn/runtime/test/TestGenerated.cpp b/nn/runtime/test/TestGenerated.cpp
index 60f866cab..cc0b61983 100644
--- a/nn/runtime/test/TestGenerated.cpp
+++ b/nn/runtime/test/TestGenerated.cpp
@@ -15,9 +15,6 @@
*/
#include <android-base/logging.h>
-#include <android-base/mapped_file.h>
-#include <android-base/unique_fd.h>
-#include <android/sharedmem.h>
#include <ftw.h>
#include <gtest/gtest.h>
#include <unistd.h>
@@ -37,6 +34,7 @@
#include "GeneratedTestUtils.h"
#include "TestHarness.h"
#include "TestNeuralNetworksWrapper.h"
+#include "TestUtils.h"
// Systrace is not available from CTS tests due to platform layering
// constraints. We reuse the NNTEST_ONLY_PUBLIC_API flag, as that should also be
@@ -140,49 +138,6 @@ static void computeWithPtrs(const TestModel& testModel, Execution* execution, Re
*result = execution->compute();
}
-// Convenience class to manage the file, mapping, and memory object.
-class TestAshmem {
- public:
- TestAshmem(::android::base::unique_fd fd, std::unique_ptr<::android::base::MappedFile> mapped,
- Memory memory)
- : mFd(std::move(fd)), mMapped(std::move(mapped)), mMemory(std::move(memory)) {}
-
- // Factory function for TestAshmem; prefer this over the raw constructor
- static std::unique_ptr<TestAshmem> createFrom(const TestBuffer& buffer) {
- // Create ashmem-based fd.
- int fd = ASharedMemory_create(nullptr, buffer.size());
- if (fd <= 0) return nullptr;
- ::android::base::unique_fd managedFd(fd);
-
- // Map and populate ashmem.
- auto mappedFile =
- ::android::base::MappedFile::FromFd(fd, 0, buffer.size(), PROT_READ | PROT_WRITE);
- if (!mappedFile) return nullptr;
- memcpy(mappedFile->data(), buffer.get<void>(), buffer.size());
-
- // Create NNAPI memory object.
- Memory memory(buffer.size(), PROT_READ | PROT_WRITE, fd, 0);
- if (!memory.isValid()) return nullptr;
-
- // Store everything in managing class.
- return std::make_unique<TestAshmem>(std::move(managedFd), std::move(mappedFile),
- std::move(memory));
- }
-
- size_t size() { return mMapped->size(); }
- Memory* get() { return &mMemory; }
-
- template <typename Type>
- Type* dataAs() {
- return static_cast<Type*>(static_cast<void*>(mMapped->data()));
- }
-
- private:
- ::android::base::unique_fd mFd;
- std::unique_ptr<::android::base::MappedFile> mMapped;
- Memory mMemory;
-};
-
static ANeuralNetworksMemory* createDeviceMemoryForInput(const Compilation& compilation,
uint32_t index) {
ANeuralNetworksMemoryDesc* desc = nullptr;