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");

}

相关推荐
B0URNE4 小时前
【Unity基础详解】Unity3D全程学习路线
学习·unity·游戏引擎
一步一个foot-print8 小时前
[Unity Shader Base] RayMarching in Cloud Rendering
unity·游戏引擎
立刀人13 小时前
关于Unity 轴心点 Pivot、锚点 Anchor和控制轴
unity·游戏引擎
AA陈超2 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P07-11 实现自动运行
c++·游戏·ue5·游戏引擎·虚幻
Hody912 天前
【XR开发系列】Unity下载与安装详细教程(UnityHub、Unity)
unity·游戏引擎·xr
雪下的新火4 天前
Blender-一个简单的水
游戏引擎·blender·特效制作·笔记分享
weixin_424294674 天前
在 Unity 游戏开发中,为视频选择 VP8 还是 H.264
unity·游戏引擎
一步一个foot-print5 天前
【Unity】Light Probe 替代点光源给环境动态物体加光照
unity·游戏引擎
@LYZY5 天前
Unity 中隐藏文件规则
unity·游戏引擎·游戏程序·vr
Sator15 天前
使用Unity ASE插件设置数值不会生效的问题
unity·游戏引擎