forked from overdesigned/RenderPipelineShaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_device.cpp
62 lines (51 loc) · 1.71 KB
/
test_device.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2024 Advanced Micro Devices, Inc.
//
// This file is part of the AMD Render Pipeline Shaders SDK which is
// released under the MIT LICENSE.
//
// See file LICENSE.txt for full license details.
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <stdarg.h>
#include "rps/rps.h"
#include "utils/rps_test_common.h"
void* FailingMalloc(void* pContext, size_t size, size_t alignment)
{
return NULL;
}
// Test device creation APIs
TEST_CASE("DeviceCreation")
{
RpsDevice device = RPS_NULL_HANDLE;
RpsDeviceCreateInfo createInfo;
// Invalid Input
memset(&createInfo, 0, sizeof(createInfo));
RpsResult result = rpsDeviceCreate(&createInfo, NULL);
REQUIRE(result == RPS_ERROR_INVALID_ARGUMENTS);
REQUIRE(device == RPS_NULL_HANDLE);
// Default allocator
result = rpsDeviceCreate(&createInfo, &device);
REQUIRE(result == RPS_OK);
REQUIRE(device != RPS_NULL_HANDLE);
rpsDeviceDestroy(device);
device = RPS_NULL_HANDLE;
// OOM
createInfo.allocator.pfnAlloc = FailingMalloc;
createInfo.allocator.pfnFree = CountedFree;
createInfo.printer.pfnPrintf = NULL;
result = rpsDeviceCreate(&createInfo, &device);
REQUIRE(result == RPS_ERROR_OUT_OF_MEMORY);
REQUIRE(device == RPS_NULL_HANDLE);
REQUIRE(g_NumMallocs == 0);
// Success
createInfo.allocator.pfnAlloc = CountedMalloc;
createInfo.allocator.pfnFree = CountedFree;
createInfo.printer.pfnPrintf = NULL;
result = rpsDeviceCreate(&createInfo, &device);
REQUIRE(result == RPS_OK);
REQUIRE(device != RPS_NULL_HANDLE);
REQUIRE(g_NumMallocs > 0);
// Clean up
rpsDeviceDestroy(device);
REQUIRE(g_NumMallocs == 0);
}