This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
#include <chimera/gfx/chimera_gfx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int failures;
|
||||
|
||||
#define CHECK(expression) \
|
||||
do { \
|
||||
if (!(expression)) { \
|
||||
(void)fprintf(stderr, "%s:%d: check failed: %s\n", __FILE__, \
|
||||
__LINE__, #expression); \
|
||||
failures += 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static void test_valid_mock_context(void) {
|
||||
chimera_gfx_config config = CHIMERA_GFX_CONFIG_INIT;
|
||||
chimera_gfx_context *context = NULL;
|
||||
chimera_gfx_capabilities capabilities = CHIMERA_GFX_CAPABILITIES_INIT;
|
||||
|
||||
CHECK(chimera_gfx_create(&config, &context) == CHIMERA_GFX_STATUS_OK);
|
||||
CHECK(context != NULL);
|
||||
CHECK(chimera_gfx_get_capabilities(context, &capabilities) ==
|
||||
CHIMERA_GFX_STATUS_OK);
|
||||
CHECK(capabilities.api_version == CHIMERA_GFX_API_VERSION);
|
||||
CHECK(capabilities.backend == CHIMERA_GFX_BACKEND_MOCK);
|
||||
CHECK((capabilities.flags & CHIMERA_GFX_CAPABILITY_BACKEND_AVAILABLE) !=
|
||||
0u);
|
||||
CHECK((capabilities.flags & CHIMERA_GFX_CAPABILITY_NON_RENDERING) != 0u);
|
||||
CHECK((capabilities.flags & CHIMERA_GFX_CAPABILITY_HOST_TEST_ONLY) != 0u);
|
||||
CHECK((capabilities.flags & CHIMERA_GFX_CAPABILITY_PRESENT_MODEL) != 0u);
|
||||
CHECK(capabilities.max_live_surfaces == 16u);
|
||||
CHECK(capabilities.max_live_textures == 16u);
|
||||
CHECK(chimera_gfx_context_destroy(context) == CHIMERA_GFX_STATUS_OK);
|
||||
chimera_gfx_destroy(NULL);
|
||||
}
|
||||
|
||||
static void test_context_validation(void) {
|
||||
chimera_gfx_config config = CHIMERA_GFX_CONFIG_INIT;
|
||||
chimera_gfx_context *context = NULL;
|
||||
|
||||
CHECK(chimera_gfx_create(NULL, &context) ==
|
||||
CHIMERA_GFX_STATUS_INVALID_ARGUMENT);
|
||||
CHECK(context == NULL);
|
||||
CHECK(chimera_gfx_create(&config, NULL) ==
|
||||
CHIMERA_GFX_STATUS_INVALID_ARGUMENT);
|
||||
|
||||
config.struct_size = sizeof(config) - 1u;
|
||||
CHECK(chimera_gfx_create(&config, &context) ==
|
||||
CHIMERA_GFX_STATUS_INVALID_ARGUMENT);
|
||||
config.struct_size = sizeof(config);
|
||||
|
||||
config.api_version += 1u;
|
||||
CHECK(chimera_gfx_create(&config, &context) ==
|
||||
CHIMERA_GFX_STATUS_VERSION_MISMATCH);
|
||||
config.api_version = CHIMERA_GFX_API_VERSION;
|
||||
|
||||
config.flags = CHIMERA_GFX_CONFIG_ALLOW_HARDWARE_RENDERING;
|
||||
CHECK(chimera_gfx_create(&config, &context) ==
|
||||
CHIMERA_GFX_STATUS_SAFETY_POLICY);
|
||||
config.flags = 0u;
|
||||
|
||||
config.backend = CHIMERA_GFX_BACKEND_PS5;
|
||||
CHECK(chimera_gfx_create(&config, &context) ==
|
||||
CHIMERA_GFX_STATUS_SAFETY_POLICY);
|
||||
CHECK(context == NULL);
|
||||
config.backend = 99u;
|
||||
CHECK(chimera_gfx_create(&config, &context) ==
|
||||
CHIMERA_GFX_STATUS_UNSUPPORTED);
|
||||
}
|
||||
|
||||
static void test_capability_validation(void) {
|
||||
chimera_gfx_config config = CHIMERA_GFX_CONFIG_INIT;
|
||||
chimera_gfx_context *context = NULL;
|
||||
chimera_gfx_capabilities capabilities = CHIMERA_GFX_CAPABILITIES_INIT;
|
||||
|
||||
CHECK(chimera_gfx_create(&config, &context) == CHIMERA_GFX_STATUS_OK);
|
||||
CHECK(chimera_gfx_get_capabilities(NULL, &capabilities) ==
|
||||
CHIMERA_GFX_STATUS_INVALID_ARGUMENT);
|
||||
CHECK(chimera_gfx_get_capabilities(context, NULL) ==
|
||||
CHIMERA_GFX_STATUS_INVALID_ARGUMENT);
|
||||
capabilities.struct_size = sizeof(capabilities) - 1u;
|
||||
CHECK(chimera_gfx_get_capabilities(context, &capabilities) ==
|
||||
CHIMERA_GFX_STATUS_INVALID_ARGUMENT);
|
||||
CHECK(chimera_gfx_context_destroy(context) == CHIMERA_GFX_STATUS_OK);
|
||||
}
|
||||
|
||||
static void test_status_strings(void) {
|
||||
chimera_gfx_status status;
|
||||
|
||||
for (status = CHIMERA_GFX_STATUS_OK;
|
||||
status <= CHIMERA_GFX_STATUS_LIMIT_EXCEEDED;
|
||||
status = (chimera_gfx_status)((int)status + 1)) {
|
||||
CHECK(strcmp(chimera_gfx_status_string(status), "unknown status") != 0);
|
||||
}
|
||||
CHECK(strcmp(chimera_gfx_status_string((chimera_gfx_status)999),
|
||||
"unknown status") == 0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_valid_mock_context();
|
||||
test_context_validation();
|
||||
test_capability_validation();
|
||||
test_status_strings();
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user