yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaCorrect include dir for libslang (#5539)7b570feed

master
1.2 KiB50 linesraw
1// unit-test-free-list.cpp
2
3#include "../../source/core/slang-free-list.h"
4#include "../../source/core/slang-list.h"
5#include "../../source/core/slang-random-generator.h"
6#include "unit-test/slang-unit-test.h"
7
8#include <stdio.h>
9#include <stdlib.h>
10
11using namespace Slang;
12
13SLANG_UNIT_TEST(freeList)
14{
15    FreeList freeList;
16    freeList.init(sizeof(int), sizeof(void*), 10);
17
18    DefaultRandomGenerator randGen(0x24343);
19
20    List<int*> allocs;
21
22    for (int i = 0; i < 1000; i++)
23    {
24        const int numAlloc = randGen.nextInt32UpTo(20);
25
26        for (int j = 0; j < numAlloc; j++)
27        {
28            int* ptr = (int*)freeList.allocate();
29            *ptr = i;
30            allocs.add(ptr);
31        }
32
33        int numDealloc = randGen.nextInt32UpTo(19);
34        numDealloc = int(allocs.getCount()) < numDealloc ? int(allocs.getCount()) : numDealloc;
35
36        for (int j = 0; j < numDealloc; j++)
37        {
38            const int index = randGen.nextInt32UpTo(int(allocs.getCount()));
39
40            int* alloc = allocs[index];
41
42            SLANG_CHECK(*alloc <= i);
43            SLANG_CHECK(*alloc >= 0);
44
45            freeList.deallocate(alloc);
46
47            allocs.fastRemoveAt(index);
48        }
49    }
50}