Merge "Use unique_ptr to free objects when ASSERT* fail."
This commit is contained in:
commit
93aedcaf2b
libion/tests
|
@ -17,8 +17,9 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_CLANG := true
|
||||
LOCAL_MODULE := ion-unit-tests
|
||||
LOCAL_CFLAGS += -g -Wall -Werror -std=gnu++11 -Wno-missing-field-initializers
|
||||
LOCAL_CFLAGS += -g -Wall -Werror -Wno-missing-field-initializers
|
||||
LOCAL_SHARED_LIBRARIES += libion
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../kernel-headers
|
||||
LOCAL_SRC_FILES := \
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
@ -90,7 +91,7 @@ TEST_F(Allocate, RepeatedAllocate)
|
|||
|
||||
TEST_F(Allocate, Zeroed)
|
||||
{
|
||||
void *zeroes = calloc(4096, 1);
|
||||
auto zeroes_ptr = std::make_unique<char[]>(4096);
|
||||
|
||||
for (unsigned int heapMask : m_allHeaps) {
|
||||
SCOPED_TRACE(::testing::Message() << "heap " << heapMask);
|
||||
|
@ -125,14 +126,11 @@ TEST_F(Allocate, Zeroed)
|
|||
ptr = mmap(NULL, 4096, PROT_READ, MAP_SHARED, map_fd, 0);
|
||||
ASSERT_TRUE(ptr != NULL);
|
||||
|
||||
ASSERT_EQ(0, memcmp(ptr, zeroes, 4096));
|
||||
ASSERT_EQ(0, memcmp(ptr, zeroes_ptr.get(), 4096));
|
||||
|
||||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(zeroes);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(Allocate, Large)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <memory>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -133,8 +134,8 @@ void Device::dirtyCache(void *ptr, size_t size)
|
|||
|
||||
TEST_F(Device, KernelReadCached)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (unsigned int heapMask : m_allHeaps) {
|
||||
SCOPED_TRACE(::testing::Message() << "heap " << heapMask);
|
||||
|
@ -161,14 +162,12 @@ TEST_F(Device, KernelReadCached)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, KernelWriteCached)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
((char *)buf)[i] = i;
|
||||
|
@ -195,14 +194,12 @@ TEST_F(Device, KernelWriteCached)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, DMAReadCached)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (unsigned int heapMask : m_allHeaps) {
|
||||
SCOPED_TRACE(::testing::Message() << "heap " << heapMask);
|
||||
|
@ -227,14 +224,12 @@ TEST_F(Device, DMAReadCached)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, DMAWriteCached)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
((char *)buf)[i] = i;
|
||||
|
@ -261,14 +256,12 @@ TEST_F(Device, DMAWriteCached)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, KernelReadCachedNeedsSync)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (unsigned int heapMask : m_allHeaps) {
|
||||
SCOPED_TRACE(::testing::Message() << "heap " << heapMask);
|
||||
|
@ -295,14 +288,12 @@ TEST_F(Device, KernelReadCachedNeedsSync)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, KernelWriteCachedNeedsSync)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
((char *)buf)[i] = i;
|
||||
|
@ -329,14 +320,12 @@ TEST_F(Device, KernelWriteCachedNeedsSync)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, DMAReadCachedNeedsSync)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (unsigned int heapMask : m_allHeaps) {
|
||||
SCOPED_TRACE(::testing::Message() << "heap " << heapMask);
|
||||
|
@ -363,14 +352,12 @@ TEST_F(Device, DMAReadCachedNeedsSync)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, DMAWriteCachedNeedsSync)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
((char *)buf)[i] = i;
|
||||
|
@ -399,13 +386,11 @@ TEST_F(Device, DMAWriteCachedNeedsSync)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
TEST_F(Device, KernelRead)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (unsigned int heapMask : m_allHeaps) {
|
||||
SCOPED_TRACE(::testing::Message() << "heap " << heapMask);
|
||||
|
@ -432,14 +417,12 @@ TEST_F(Device, KernelRead)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, KernelWrite)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
((char *)buf)[i] = i;
|
||||
|
@ -466,14 +449,12 @@ TEST_F(Device, KernelWrite)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, DMARead)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (unsigned int heapMask : m_allHeaps) {
|
||||
SCOPED_TRACE(::testing::Message() << "heap " << heapMask);
|
||||
|
@ -498,14 +479,12 @@ TEST_F(Device, DMARead)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, DMAWrite)
|
||||
{
|
||||
void *alloc = malloc(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc, 4096) + 1024);
|
||||
auto alloc_ptr = std::make_unique<char[]>(8192 + 1024);
|
||||
void *buf = (void *)(ALIGN((unsigned long)alloc_ptr.get(), 4096) + 1024);
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
((char *)buf)[i] = i;
|
||||
|
@ -532,13 +511,12 @@ TEST_F(Device, DMAWrite)
|
|||
ASSERT_EQ(0, munmap(ptr, 4096));
|
||||
ASSERT_EQ(0, close(map_fd));
|
||||
}
|
||||
|
||||
free(alloc);
|
||||
}
|
||||
|
||||
TEST_F(Device, IsCached)
|
||||
{
|
||||
void *buf = malloc(4096);
|
||||
auto buf_ptr = std::make_unique<char[]>(4096);
|
||||
void *buf = buf_ptr.get();
|
||||
|
||||
for (unsigned int heapMask : m_allHeaps) {
|
||||
SCOPED_TRACE(::testing::Message() << "heap " << heapMask);
|
||||
|
|
Loading…
Reference in New Issue