MNN/test/core/MemoryUtilsTest.cpp

34 lines
912 B
C++
Raw Normal View History

2019-04-17 10:49:11 +08:00
//
// MemoryUtilsTest.cpp
// MNNTests
//
// Created by MNN on 2019/01/17.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include "MNNTestSuite.h"
2020-11-05 16:41:56 +08:00
#include "core/MNNMemoryUtils.h"
2019-04-17 10:49:11 +08:00
#ifndef MNN_DEBUG_MEMORY
class MemoryUtilsTest : public MNNTestCase {
public:
virtual ~MemoryUtilsTest() = default;
virtual bool run(int precision) {
2019-04-17 10:49:11 +08:00
{
void *ptr = MNNMemoryAllocAlign(5, 0b111111 + 1);
MNNTEST_ASSERT(((intptr_t)ptr & 0b111111) == 0);
2019-04-17 10:49:11 +08:00
MNNMemoryFreeAlign(ptr);
}
{
void *ptr = MNNMemoryCallocAlign(8 * sizeof(int), 0b111 + 1);
MNNTEST_ASSERT(((intptr_t)ptr & 0b111) == 0);
2019-04-17 10:49:11 +08:00
for (int i = 0; i < 8; i++)
MNNTEST_ASSERT(((int *)ptr)[i] == 0);
2019-04-17 10:49:11 +08:00
MNNMemoryFreeAlign(ptr);
}
return true;
2019-04-17 10:49:11 +08:00
}
};
MNNTestSuiteRegister(MemoryUtilsTest, "core/memory_utils");
#endif