adding unit test for vx_malloc

This commit is contained in:
Blaise Tine
2022-01-30 05:57:18 -05:00
parent 3750c672a7
commit e3e2609f7e
8 changed files with 298 additions and 168 deletions

8
tests/unittest/Makefile Normal file
View File

@@ -0,0 +1,8 @@
all:
$(MAKE) -C vx_malloc
run:
$(MAKE) -C vx_malloc run
clean:
$(MAKE) -C vx_malloc clean

View File

@@ -0,0 +1,34 @@
VORTEX_DRV_PATH ?= $(realpath ../../../driver)
CXXFLAGS += -std=c++11 -Wall -Wextra -pedantic -Wfatal-errors
CXXFLAGS += -I$(VORTEX_DRV_PATH)/common
# Debugigng
ifdef DEBUG
CXXFLAGS += -g -O0
else
CXXFLAGS += -O2 -DNDEBUG
endif
PROJECT = vx_malloc
SRCS = main.cpp
all: $(PROJECT)
$(PROJECT): $(SRCS)
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
run:
./$(PROJECT)
clean:
rm -rf $(PROJECT) *.o .depend
clean-all: clean
rm -rf *.elf *.bin *.dump
ifneq ($(MAKECMDGOALS),clean)
-include .depend
endif

View File

@@ -0,0 +1,52 @@
#include <vx_malloc.h>
#include <stdio.h>
#define RT_CHECK(_expr) \
do { \
int _ret = _expr; \
if (0 == _ret) \
break; \
printf("Error: '%s' returned %d!\n", #_expr, (int)_ret); \
return -1; \
} while (false)
static uint64_t minAddress = 0;
static uint64_t maxAddress = 0xffffffff;
static uint32_t pageAlign = 4096;
static uint32_t blockAlign = 64;
int main() {
auto allocator = new vortex::MemoryAllocator(
minAddress, maxAddress, pageAlign, blockAlign
);
uint64_t a0, a1, a2, a3;
RT_CHECK(allocator->allocate(128, &a0));
RT_CHECK(allocator->release(a0));
RT_CHECK(allocator->allocate(1, &a0));
RT_CHECK(allocator->allocate(1, &a1));
RT_CHECK(allocator->allocate(1, &a2));
RT_CHECK(allocator->release(a1));
RT_CHECK(allocator->allocate(1, &a3));
RT_CHECK(allocator->release(a0));
RT_CHECK(allocator->release(a2));
RT_CHECK(allocator->release(a3));
RT_CHECK(allocator->allocate(5878, &a0));
RT_CHECK(allocator->allocate(4095, &a1));
RT_CHECK(allocator->allocate(1, &a2));
RT_CHECK(allocator->allocate(1, &a3));
RT_CHECK(allocator->release(a0));
RT_CHECK(allocator->release(a1));
RT_CHECK(allocator->release(a2));
RT_CHECK(allocator->release(a3));
delete allocator;
printf("PASSED!\n");
return 0;
}