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

}

相关推荐
不绝1912 天前
ARPG开发流程第一章——方法合集
算法·游戏·unity·游戏引擎
贵州晓智信息科技2 天前
Unity 性能优化全攻略
unity·性能优化·游戏引擎
unicrom_深圳市由你创科技2 天前
Unity 的UI动画调节
ui·unity·游戏引擎
咩咩觉主2 天前
Unity编辑器拓展 IMGUI与部分Utility知识总结(代码+思维导图)
unity·c#·编辑器·游戏引擎
龚子亦2 天前
【Unity开发】数据存储——XML
xml·unity·游戏引擎·数据存储·游戏开发
write_the_code3 天前
Unity国际版下载链接分享(非c1国内版)
unity·游戏引擎
Bulling_3 天前
unity动态背景制作
unity·游戏引擎
枯萎穿心攻击3 天前
响应式编程入门教程第八节:UniRX性能分析与优化
ui·unity·架构·c#·游戏引擎
我寄人间雪满头丶4 天前
Unity使用Luna Playworks开发试玩广告问题处理
unity·游戏引擎
伽蓝_游戏4 天前
Unity UI的未来之路:从UGUI到UI Toolkit的架构演进与特性剖析(2)
游戏·ui·unity·架构·c#·游戏引擎·.net