Improve testing framework

Replaced Criterrion with CMock. Added few tests, currently not working
properly. Random test upgrades.
This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent 56c0b7922f
commit f5ab5f3f27
29 files changed
+140082 -310

No files matched your search

+7 -1
View File
@@ -7,6 +7,8 @@ find_package(FreeType REQUIRED)
find_package(Vulkan COMPONENTS glslc)
find_program(glslc_executable NAMES glslc HINTS ${Vulkan_GLSLC_EXECUTABLE}/..)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders)
cmake_policy(SET CMP0116 NEW)
@@ -35,7 +37,11 @@ shaders/solid_objects.frag
shaders/on_screen_text.frag
)
add_library(rse_graphics SHARED shaders/shader.vert.num shaders/shader.frag.num)
add_library(rse_graphics SHARED
shaders/shader.vert.num
shaders/solid_objects.frag.num
shaders/on_screen_text.frag.num
)
target_include_directories(rse_graphics PRIVATE
${PROJECT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
+1 -1
View File
@@ -14,5 +14,5 @@ layout(location = 0) out vec4 outColor;
void main() {
vec4 texturePixels = texture(texSampler[instanceTextureId], fragTexCoord);
outColor = vec4(fragColor * texturePixels, texturePixels.a);
outColor = vec4(fragColor * texturePixels.rgb, texturePixels.a);
}
+8 -7
View File
@@ -1,6 +1,7 @@
#include "vulkan_buffers.h"
#include "src/vulkan_commons.h"
#include "utilities/rse_commons.h"
#include "vulkan_errors.h"
#include "locale_vulkan.h"
#include "utilities/logger.h"
@@ -212,7 +213,7 @@ void update_uniform_buffers()
g_vulkan_state.swapchain_extent.width / (float)g_vulkan_state.swapchain_extent.height,
z_near,
z_far);
memcpy(g_vulkan_state.uniform_buffers[g_vulkan_state.current_frame].allocation_info.pMappedData, &ubo, sizeof(ubo));
rse_memcpy(g_vulkan_state.uniform_buffers[g_vulkan_state.current_frame].allocation_info.pMappedData, &ubo, sizeof(ubo));
}
rse_err_t rse_add_vertices(uint16_t mesh_id,
@@ -239,7 +240,7 @@ rse_err_t rse_add_vertices(uint16_t mesh_id,
/* Fill staging buffer with vertex data */
memset(staging_buffer.allocation_info.pMappedData, 0, MAX_VERTEX_BUFFER_SIZE);
memcpy(staging_buffer.allocation_info.pMappedData, vertices, vertices_size);
rse_memcpy(staging_buffer.allocation_info.pMappedData, vertices, vertices_size);
copy_buffer(staging_buffer.buffer,
g_vertex_buffer.buffer,
vertices_size,
@@ -251,7 +252,7 @@ rse_err_t rse_add_vertices(uint16_t mesh_id,
/* Fill staging buffer with index data */
memset(staging_buffer.allocation_info.pMappedData, 0, indices_size);
memcpy(staging_buffer.allocation_info.pMappedData, indices, indices_size);
rse_memcpy(staging_buffer.allocation_info.pMappedData, indices, indices_size);
copy_buffer(staging_buffer.buffer,
index_buffer->buffer,
indices_size,
@@ -267,7 +268,7 @@ rse_err_t rse_add_vertices(uint16_t mesh_id,
draw_indirect_command.vertexOffset = vertex_data->buffer_offset;
draw_indirect_command.firstInstance = 0;
memcpy(g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), &draw_indirect_command, sizeof(VkDrawIndexedIndirectCommand));
rse_memcpy(g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), &draw_indirect_command, sizeof(VkDrawIndexedIndirectCommand));
return RSE_ERROR_NO_ERROR;
}
@@ -289,7 +290,7 @@ rse_err_t update_mesh_instances(uint16_t mesh_id, struct rse_instance_data_t* in
&staging_buffer));
/* Copy transformation information about instance */
memcpy(staging_buffer.allocation_info.pMappedData, instance_data, instance_size);
rse_memcpy(staging_buffer.allocation_info.pMappedData, instance_data, instance_size);
copy_buffer(staging_buffer.buffer,
instance_buffer->buffer,
instance_size,
@@ -299,9 +300,9 @@ rse_err_t update_mesh_instances(uint16_t mesh_id, struct rse_instance_data_t* in
instance_buffer->allocated_size += instance_size;
memcpy(&draw_indirect_command, g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), sizeof(VkDrawIndexedIndirectCommand));
rse_memcpy(&draw_indirect_command, g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), sizeof(VkDrawIndexedIndirectCommand));
draw_indirect_command.instanceCount++;
memcpy(g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), &draw_indirect_command, sizeof(VkDrawIndexedIndirectCommand));
rse_memcpy(g_draw_indirect_command_buffer.allocation_info.pMappedData + (mesh_id * sizeof(VkDrawIndexedIndirectCommand)), &draw_indirect_command, sizeof(VkDrawIndexedIndirectCommand));
return RSE_ERROR_NO_ERROR;
}
+34 -26
View File
@@ -5,6 +5,7 @@
#include "src/window.h"
#include "utilities/file_utils.h"
#include "utilities/logger.h"
#include "utilities/rse_commons.h"
#include "utilities/rse_errors_common.h"
#include "vulkan/vulkan_core.h"
#include "vulkan_errors.h"
@@ -16,7 +17,7 @@
#include <stdlib.h>
#include <string.h>
#define SHADER_MODULES_COUNT 3U
#define SHADER_MODULES_COUNT 2U
enum shader_stage_t
{
@@ -146,7 +147,7 @@ static rse_err_t create_swapchain()
/* Obtain swapchain images */
vkGetSwapchainImagesKHR(g_vulkan_state.device, g_vulkan_state.swapchain, &g_swapchain_images_count, NULL);
g_swapchain_images = (VkImage*)malloc(sizeof(VkImage) * g_swapchain_images_count);
rse_malloc(g_swapchain_images, sizeof(VkImage) * g_swapchain_images_count);
vkGetSwapchainImagesKHR(g_vulkan_state.device, g_vulkan_state.swapchain, &g_swapchain_images_count, g_swapchain_images);
return RSE_ERROR_NO_ERROR;
@@ -159,7 +160,7 @@ static rse_err_t create_swapchain()
*/
static rse_err_t create_swapchain_image_views()
{
g_vulkan_state.swapchain_image_views = malloc(sizeof(VkImageView) * g_swapchain_images_count);
rse_malloc(g_vulkan_state.swapchain_image_views, sizeof(VkImageView) * g_swapchain_images_count);
for (size_t i = 0; i < g_swapchain_images_count; i++) {
VkImageViewCreateInfo create_info;
@@ -381,18 +382,18 @@ static rse_err_t fill_shader_stages(VkPipelineShaderStageCreateInfo* shader_stag
VkPipelineShaderStageCreateInfo frag_shader_stage_info = {};
rse_read_file(g_shader_paths[VERTEX], &buffer_size, NULL);
buffer = malloc(buffer_size);
rse_malloc(buffer, buffer_size);
rse_read_file(g_shader_paths[VERTEX], &buffer_size, buffer);
STATUS_CHECK(create_shader_module(buffer, buffer_size, &vertex_shader_module));
free(buffer);
rse_free(buffer);
rse_read_file(g_shader_paths[FRAGMENTS], &buffer_size, NULL);
buffer = malloc(buffer_size);
rse_malloc(buffer, buffer_size);
rse_read_file(g_shader_paths[FRAGMENTS], &buffer_size, buffer);
STATUS_CHECK(create_shader_module(buffer, buffer_size, &fragments_shader_module));
free(buffer);
rse_free(buffer);
/* Vertex Shader Pipeline Stage */
vert_shader_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
@@ -415,8 +416,8 @@ static rse_err_t fill_shader_stages(VkPipelineShaderStageCreateInfo* shader_stag
shader_stages[VERTEX] = vert_shader_stage_info;
shader_stages[FRAGMENTS] = frag_shader_stage_info;
memcpy(&g_shader_modules[0], &vertex_shader_module, sizeof(VkShaderModule));
memcpy(&g_shader_modules[1], &fragments_shader_module, sizeof(VkShaderModule));
rse_memcpy(&g_shader_modules[0], &vertex_shader_module, sizeof(VkShaderModule));
rse_memcpy(&g_shader_modules[1], &fragments_shader_module, sizeof(VkShaderModule));
return RSE_ERROR_NO_ERROR;
}
@@ -434,7 +435,7 @@ static void fill_dynamic_pipeline_state_info(VkPipelineDynamicStateCreateInfo* d
* pipeline create structures. I'll list ignored members of structs, that will be ignored due to the
* settings and also functions, that will need to be called to set specific state.
*/
dynamic_states = malloc(sizeof(VkDynamicState) * 2);
rse_malloc(dynamic_states, sizeof(VkDynamicState) * 2);
dynamic_states[0] = VK_DYNAMIC_STATE_VIEWPORT; /* VkPipelineViewportStateCreateInfo:pViewport; vkCmdSetViewport() */
dynamic_states[1] = VK_DYNAMIC_STATE_SCISSOR; /* VkPipelineViewportStateCreateInfo:pScissors; vkCmdSetScissors() */
@@ -456,7 +457,7 @@ static void fill_dynamic_pipeline_state_info(VkPipelineDynamicStateCreateInfo* d
*/
static void free_dynamic_pipeline_state_info(VkPipelineDynamicStateCreateInfo* dynamic_state)
{
free((VkDynamicState*)dynamic_state->pDynamicStates);
rse_free((VkDynamicState*)dynamic_state->pDynamicStates);
}
/**
@@ -468,14 +469,15 @@ static void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_
{
const size_t binding_descriptions_count = 2;
const size_t attribute_descriptions_count = 7;
/* This is clusterfuck with some magic numbers here and there and unneeded malloc and memcpy stuff. Change,
/* TODO: This is clusterfuck with some magic numbers here and there and unneeded malloc and memcpy stuff. Change,
* so you won't feel ashamed. */
VkVertexInputBindingDescription vertex_binding_description = get_binding_description();
VkVertexInputAttributeDescription* vertex_attribute_descriptions = get_attribute_descriptions();
VkVertexInputBindingDescription* binding_descriptions = malloc(sizeof(VkVertexInputBindingDescription)
* binding_descriptions_count);
VkVertexInputAttributeDescription* attribute_descriptions = malloc(sizeof(VkVertexInputAttributeDescription)
* attribute_descriptions_count);
VkVertexInputBindingDescription* binding_descriptions = NULL;
VkVertexInputAttributeDescription* attribute_descriptions = NULL;
rse_malloc(binding_descriptions, sizeof(VkVertexInputBindingDescription) * binding_descriptions_count);
rse_malloc(attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * attribute_descriptions_count);
binding_descriptions[0] = vertex_binding_description;
@@ -483,7 +485,7 @@ static void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_
binding_descriptions[1].stride = sizeof(struct rse_instance_data_t);
binding_descriptions[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
memcpy(attribute_descriptions, vertex_attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * 3);
rse_memcpy(attribute_descriptions, vertex_attribute_descriptions, sizeof(VkVertexInputAttributeDescription) * 3);
attribute_descriptions[3].binding = 1;
attribute_descriptions[3].location = 3;
@@ -523,8 +525,8 @@ static void fill_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_
*/
static void free_vertex_input_info(VkPipelineVertexInputStateCreateInfo* vertex_input_info)
{
free((VkVertexInputBindingDescription*)vertex_input_info->pVertexBindingDescriptions);
free((VkVertexInputAttributeDescription*)vertex_input_info->pVertexAttributeDescriptions);
rse_free((VkVertexInputBindingDescription*)vertex_input_info->pVertexBindingDescriptions);
rse_free((VkVertexInputAttributeDescription*)vertex_input_info->pVertexAttributeDescriptions);
}
/**
@@ -548,9 +550,11 @@ static void fill_input_assembly_info(VkPipelineInputAssemblyStateCreateInfo* inp
*/
static void fill_viewport_state_info(VkPipelineViewportStateCreateInfo* viewport_state)
{
VkViewport* viewport = malloc(sizeof(VkViewport));
VkRect2D* scissor = malloc(sizeof(VkRect2D));
VkViewport* viewport = NULL;
VkRect2D* scissor = NULL;
rse_malloc(viewport, sizeof(VkViewport));
rse_malloc(scissor, sizeof(VkRect2D));
viewport->x = 0.0f;
viewport->y = 0.0f;
viewport->width = (float)(g_vulkan_state.swapchain_extent.width);
@@ -577,8 +581,8 @@ static void fill_viewport_state_info(VkPipelineViewportStateCreateInfo* viewport
*/
static void free_viewport_state_info(VkPipelineViewportStateCreateInfo* viewport_state)
{
free((VkViewport*)viewport_state->pViewports);
free((VkRect2D*)viewport_state->pScissors);
rse_free((VkViewport*)viewport_state->pViewports);
rse_free((VkRect2D*)viewport_state->pScissors);
}
/**
@@ -628,7 +632,9 @@ static void fill_multisampling_state_info(VkPipelineMultisampleStateCreateInfo*
*/
static void fill_color_blend_state_info(VkPipelineColorBlendStateCreateInfo* color_blending)
{
VkPipelineColorBlendAttachmentState* color_blend_attachment = malloc(sizeof(VkPipelineColorBlendAttachmentState));
VkPipelineColorBlendAttachmentState* color_blend_attachment = NULL;
rse_malloc(color_blend_attachment, sizeof(VkPipelineColorBlendAttachmentState));
color_blend_attachment->blendEnable = VK_TRUE;
color_blend_attachment->srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
@@ -660,7 +666,7 @@ static void fill_color_blend_state_info(VkPipelineColorBlendStateCreateInfo* col
*/
static void free_color_blend_info(VkPipelineColorBlendStateCreateInfo* color_blending)
{
free((VkPipelineColorBlendAttachmentState*)color_blending->pAttachments);
rse_free((VkPipelineColorBlendAttachmentState*)color_blending->pAttachments);
}
static void fill_depth_stencil_info(VkPipelineDepthStencilStateCreateInfo* depth_stencil)
@@ -749,7 +755,9 @@ static rse_err_t create_graphics_pipeline()
*/
static rse_err_t create_framebuffers()
{
g_vulkan_state.swapchain_framebuffers = malloc(sizeof(VkFramebuffer) * g_swapchain_images_count);
g_vulkan_state.swapchain_framebuffers = NULL;
rse_malloc(g_vulkan_state.swapchain_framebuffers, sizeof(VkFramebuffer) * g_swapchain_images_count);
for (size_t i = 0; i < g_swapchain_images_count; i++) {
VkImageView attachments[] = {rse_get_color_image_view(), rse_get_depth_image_view(), g_vulkan_state.swapchain_image_views[i]};