* limitations under the License.
*/
#include "NeuralNetworks.h"
-#if 0 // TODO-NNRT : Enable if we support OEM, shared memory
+#if 0 // TODO-NNRT : Enable if we support OEM
#include "NeuralNetworksOEM.h"
-#include <android/sharedmem.h>
#endif
-#include <cutils/ashmem.h>
#include <gtest/gtest.h>
#include <string>
#include <sys/mman.h>
+#include <stdio.h>
+#include <stdlib.h>
// This file tests all the validations done by the Neural Networks API.
namespace {
+
+#define PATH_MAX 256
+
+static int shmem_num = 0;
+static int shmem_create_region(size_t size)
+{
+ char temp[PATH_MAX];
+ snprintf(temp, sizeof(temp), "/tmp/nn-shmem-%d-%d-XXXXXXXXX", getpid(), shmem_num++);
+ int fd = mkstemp(temp);
+ if (fd == -1) return -1;
+
+ unlink(temp);
+
+ if (TEMP_FAILURE_RETRY(ftruncate(fd, size)) == -1) {
+ close(fd);
+ return -1;
+ }
+
+ return fd;
+}
+
class ValidationTest : public ::testing::Test {
protected:
virtual void SetUp() {}
.dimensions = dimensions};
EXPECT_EQ(ANeuralNetworksModel_addOperand(mModel, &floatType), ANEURALNETWORKS_NO_ERROR);
const size_t memorySize = 20;
- int memoryFd = ashmem_create_region("nnMemory", memorySize);
+ int memoryFd = shmem_create_region(memorySize);
ASSERT_GT(memoryFd, 0);
ANeuralNetworksMemory* memory;
EXPECT_EQ(ANeuralNetworksMemory_createFromFd(memorySize, PROT_READ | PROT_WRITE,
ANeuralNetworksExecution* execution;
EXPECT_EQ(ANeuralNetworksExecution_create(mCompilation, &execution), ANEURALNETWORKS_NO_ERROR);
const size_t memorySize = 20;
- int memoryFd = ashmem_create_region("nnMemory", memorySize);
+ int memoryFd = shmem_create_region(memorySize);
ASSERT_GT(memoryFd, 0);
ANeuralNetworksMemory* memory;
EXPECT_EQ(ANeuralNetworksMemory_createFromFd(memorySize, PROT_READ | PROT_WRITE,
ANeuralNetworksExecution* execution;
EXPECT_EQ(ANeuralNetworksExecution_create(mCompilation, &execution), ANEURALNETWORKS_NO_ERROR);
const size_t memorySize = 20;
- int memoryFd = ashmem_create_region("nnMemory", memorySize);
+ int memoryFd = shmem_create_region(memorySize);
ASSERT_GT(memoryFd, 0);
ANeuralNetworksMemory* memory;
EXPECT_EQ(ANeuralNetworksMemory_createFromFd(memorySize, PROT_READ | PROT_WRITE,