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

}

相关推荐
相信神话202112 小时前
Godot Shader 中 mix 函数的用法
游戏引擎·godot
郝学胜-神的一滴12 小时前
Horse3D游戏引擎研发笔记(七):在QtOpenGL环境下,使用改进的Uniform变量管理方式绘制多彩四边形
c++·3d·unity·游戏引擎·图形渲染·虚幻·unreal engine
巨龙之路15 小时前
Unity的Cursor.lockState
unity·游戏引擎
枯萎穿心攻击1 天前
从 Unity UGUI 到 Unreal UMG 的交互与高效实践:UI 事件、坐标系适配与性能优化
开发语言·ui·unity·性能优化·ue5·游戏引擎·虚幻引擎
Thomas_YXQ3 天前
Unity3D编辑器扩展-物体批量替换设置材质
游戏·unity·编辑器·游戏引擎·材质
雪下的新火3 天前
Unity-HDRP场景搭建-那山
经验分享·笔记·unity·游戏引擎·场景搭建
郝学胜-神的一滴3 天前
深度解析游戏引擎中的相机:视图矩阵
程序人生·unity·矩阵·游戏引擎·godot·图形渲染·虚幻
小蜗 strong4 天前
unity中实现机械臂自主运动
unity·游戏引擎
三只坚果6 天前
blender制作动画导入unity两种方式
unity·游戏引擎·blender
YF云飞6 天前
Unity音频管理:打造沉浸式游戏音效
游戏·unity·游戏引擎·游戏程序·个人开发