Skip to content
Snippets Groups Projects
Commit 1bf4d377 authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

Add TEST_malloc function for round trip test

parent d6e7fa9d
No related branches found
No related tags found
1 merge request!28Updated debug_print(): Enhanced Adaptability for Various Environments
......@@ -884,7 +884,7 @@ static int32_t chunk_round_trip(void *data, uint32_t data_size,
*/
if (model) {
if (up_model == model) {
model_cpy = cmp_test_malloc(data_size);
model_cpy = TEST_malloc(data_size);
memcpy(model_cpy, model, data_size);
} else {
model_cpy = model;
......@@ -925,9 +925,9 @@ static int32_t chunk_round_trip(void *data, uint32_t data_size,
TEST_ASSERT_EQUAL((uint32_t)decmp_size, data_size);
if (use_decmp_buf)
decmp_data = cmp_test_malloc(data_size);
decmp_data = TEST_malloc(data_size);
if (use_decmp_up_model)
up_model_decmp = cmp_test_malloc(data_size);
up_model_decmp = TEST_malloc(data_size);
decmp_size = decompress_cmp_entiy((struct cmp_entity *)cmp_data, model_cpy,
up_model_decmp, decmp_data);
......
......@@ -4,5 +4,5 @@ pcb_dep = pcg_proj.get_variable('libpcg_basic_dep')
test_common_lib = static_library(
'test_common',
'test_common.c',
dependencies: pcb_dep,
dependencies: [pcb_dep, unity_dep]
)
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "pcg_basic.h"
#include <unity.h>
void cmp_rand_seed(uint64_t seed)
{
......@@ -27,7 +30,7 @@ uint32_t cmp_rand32(void)
uint32_t cmp_rand_between(uint32_t min, uint32_t max)
{
assert(min < max);
TEST_ASSERT(min < max);
return min + pcg32_boundedrand(max-min+1);
}
......@@ -35,7 +38,26 @@ uint32_t cmp_rand_between(uint32_t min, uint32_t max)
uint32_t cmp_rand_nbits(unsigned int nbits)
{
assert(nbits > 0);
TEST_ASSERT(nbits > 0);
return cmp_rand32() >> (32 - nbits);
}
/**
* @brief allocates memory safely for tests
*
* @param size The size of memory to allocate.
*
* @returns a pointer to the allocated memory, or NULL if allocation fails
*/
void* TEST_malloc(size_t size)
{
if (size > 0) {
void* const mem = malloc(size);
TEST_ASSERT(mem);
return mem;
}
return NULL;
}
......@@ -2,6 +2,7 @@
#define TEST_COMMON_H
#include <stdint.h>
#include <stddef.h>
void cmp_rand_seed(uint64_t seed);
......@@ -11,4 +12,6 @@ uint32_t cmp_rand_between(uint32_t min, uint32_t max);
uint32_t cmp_rand_nbits(unsigned int nbits);
void* TEST_malloc(size_t size);
#endif /* TEST_COMMON_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment