vulkan游戏引擎test文件memory实现

1.linear_allocator_test.h

#pragma once

void linear_allocator_register_tests();

2.linear_allocator_test.c

#include "linear_allocator_tests.h"

#include "../test_manager.h"

#include "../expect.h"

#include <memory/linear_allocator.h>

#include <defines.h>

u8 linear_allocator_should_create_and_destroy()

{

linear_allocator alloc;

linear_allocator_create(sizeof(u64),0,&alloc);

expect_should_not_be(0,alloc.memory);

expect_should_be(sizeof(u64),alloc.total_size);

expect_should_be(0,alloc.allocated);

linear_allocator_destroy(&alloc);

expect_should_be(0,alloc.memory);

expect_should_be(0,alloc.total_size);

expect_should_be(0,alloc.allocated);

return true;

}

u8 linear_allocator_single_allocation_all_space()

{

linear_allocator alloc;

linear_allocator_create(sizeof(u64),0,&alloc);

void* block = linear_allocator_allocate(&alloc,sizeof(u64));

expect_should_not_be(0,block);

expect_should_be(sizeof(u64),alloc.allocated);

}

u8 linear_allocator_multi_allocation_all_space()

{

u64 max_allocs = 1024;

linear_allocator alloc;

linear_allocator_create(sizeof(u64) * max_allocs,0,&alloc);

void* block;

for(u64 i = 0;i<max_allocs;++i)

{

block = linear_allocator_allocate(&alloc,sizeof(u64));

expect_should_not_be(0,block);

expect_should_be(sizeof(u64)*(i+1),alloc.allocated);

}

linear_allocator_destroy(&alloc);

return true;

}

u8 linear_allocator_multi_allocation_over_allocate()

{

u64 max_allocs = 3;

linear_allocator alloc;

linear_allocator_create(sizeof(u64)*max_allocs,0,&alloc);

void* block;

for(u64 i = 0;i <max_allocs;++i)

{

block = linear_allocator_allocate(&alloc,sizeof(u64));

//Validate it

expect_should_not_be(0,block);

expect_should_be(sizeof(u64)*(i+1),alloc.allocated);

}

KDEBUG("Note:L The following error is intentionally caused by this test.");

block = linear_allocator_allocate(&alloc,sizeof(u64));

expect_should_be(0,block);

expect_should_be(sizeof(u64)*(max_allocs),alloc.allocated);

linear_allocator_destroy(&alloc);

return true;

}

u8 linear_allocator_multi_allocation_all_space_then_free()

{

u64 max_allocs = 1024;

linear_allocator alloc;

linear_allocator_create(sizeof(u64) * max_allocs,0,&alloc);

void* block;

for(u64 i = 0;i<max_allocs;++i)

{

block = linear_allocator_allocate(&alloc,sizeof(u64));

expect_should_not_be(0,block);

expect_should_be(sizeof(u64)*(i+1),alloc.allocated);

}

linear_allocator_free_all(&alloc);

expect_should_be(0,alloc.allocated);

linear_allocator_destroy(&alloc);

return true;

}

void linear_allocator_register_tests()

{

test_manager_register_test(linear_allocator_should_create_and_destroy,"Linear allocator should create and destroy");

test_manager_register_test(linear_allocator_single_allocation_all_space,"linear_allocator_single_allocation_all_space");

test_manager_register_test(linear_allocator_multi_allocation_all_space,"linear_allocator_multi_allocation_all_space");

test_manager_register_test(linear_allocator_multi_allocation_over_allocate,"linear_allocator_multi_allocation_over_allocate");

test_manager_register_test(linear_allocator_multi_allocation_all_space_then_free,"linear_allocator_multi_allocation_all_space_then_free");

}

相关推荐
Magnum Lehar13 小时前
vulkan游戏引擎test_manager实现
java·算法·游戏引擎
快乐觉主吖17 小时前
Unity的日志管理类
android·unity·游戏引擎
WarPigs1 天前
Unity性能优化笔记
笔记·unity·游戏引擎
一线灵2 天前
跨平台游戏引擎 Axmol-2.6.1 发布
游戏引擎
Clank的游戏栈2 天前
Unity基于GraphView的可视化关卡编辑器开发指南
unity·编辑器·游戏引擎
三巧2 天前
Godot 敌人生成半径和围墙不匹配,导致敌人错误的生成在围墙外的解决代码
游戏引擎·godot
技术小甜甜2 天前
【Godot引擎】如何使用内置的全局搜索功能提升开发效率
游戏引擎·godot
技术小甜甜2 天前
【Godot】如何导出 Release 版本的安卓项目
android·游戏引擎·godot
ChiLi_Lin3 天前
Unity异常上报飞书工具
unity·游戏引擎·飞书