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

}

相关推荐
心疼你的一切4 小时前
Unity开发利器:ScriptableObject的数据容器设计与内存优化原理
microsoft·unity·c#·游戏引擎
至善迎风5 小时前
将跨平台框架或游戏引擎开发的 Windows 应用上架 Microsoft Store
windows·microsoft·游戏引擎
worxfr5 小时前
小游戏引擎架构设计案例分析
游戏引擎
Brianna Home1 天前
从零到一:用Godot打造2D游戏《丛林探险》
算法·游戏·性能优化·游戏引擎·bug·godot·动画
郭逍遥1 天前
[Godot] C#简单实现2D节点图生成
游戏引擎·godot
AA陈超1 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P05-11 消息小部件
c++·游戏·ue5·游戏引擎·虚幻
AA陈超1 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-09 玩家等级与战斗接口
c++·游戏·ue5·游戏引擎·虚幻
开发游戏的老王2 天前
虚幻引擎虚拟制片入门教程 之 Sequencer 常用技巧
游戏引擎·虚幻
开发游戏的老王2 天前
虚幻引擎入门教程:虚幻编辑器的基本操作
编辑器·游戏引擎·虚幻
AA陈超3 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P05-08 UI 部件数据表
c++·游戏·ue5·游戏引擎·虚幻