mirror of https://github.com/ARMmbed/mbed-os.git
Squashed 'features/frameworks/nanostack-libservice/' changes from bb56e37..1d4c358
1d4c358 Use Mbed OS coding style (#77) git-subtree-dir: features/frameworks/nanostack-libservice git-subtree-split: 1d4c35848b1733020e0532fddd17dcadf78c79c7pull/8647/head
parent
0ca91df590
commit
661681f65c
|
|
@ -82,7 +82,7 @@ extern "C" {
|
|||
typedef struct ns_list {
|
||||
void *first_entry; ///< Pointer to first entry, or NULL if list is empty
|
||||
void **last_nextptr; ///< Pointer to last entry's `next` pointer, or
|
||||
///< to head's `first_entry` pointer if list is empty
|
||||
///< to head's `first_entry` pointer if list is empty
|
||||
} ns_list_t;
|
||||
|
||||
/** \brief Declare a list head type
|
||||
|
|
|
|||
|
|
@ -213,17 +213,17 @@ typedef int_fast32_t int_fast24_t;
|
|||
# define NS_STATIC_ASSERT(test, str) _Static_assert(test, str);
|
||||
# elif defined __GNUC__ && NS_GCC_VERSION >= 40600 && !defined __CC_ARM
|
||||
# ifdef _Static_assert
|
||||
/*
|
||||
* Some versions of glibc cdefs.h (which comes in via <stdint.h> above)
|
||||
* attempt to define their own _Static_assert (if GCC < 4.6 or
|
||||
* __STRICT_ANSI__) using an extern declaration, which doesn't work in a
|
||||
* struct/union.
|
||||
*
|
||||
* For GCC >= 4.6 and __STRICT_ANSI__, we can do better - just use
|
||||
* the built-in _Static_assert with __extension__. We have to do this, as
|
||||
* ns_list.h needs to use it in a union. No way to get at it though, without
|
||||
* overriding their define.
|
||||
*/
|
||||
/*
|
||||
* Some versions of glibc cdefs.h (which comes in via <stdint.h> above)
|
||||
* attempt to define their own _Static_assert (if GCC < 4.6 or
|
||||
* __STRICT_ANSI__) using an extern declaration, which doesn't work in a
|
||||
* struct/union.
|
||||
*
|
||||
* For GCC >= 4.6 and __STRICT_ANSI__, we can do better - just use
|
||||
* the built-in _Static_assert with __extension__. We have to do this, as
|
||||
* ns_list.h needs to use it in a union. No way to get at it though, without
|
||||
* overriding their define.
|
||||
*/
|
||||
# undef _Static_assert
|
||||
# define _Static_assert(x, y) __extension__ _Static_assert(x, y)
|
||||
# endif
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ uint_fast8_t ip4tos(const void *ip4addr, char *p)
|
|||
//Append a dot if this is not the last digit
|
||||
if (component < 3) {
|
||||
p[outputPos++] = '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return length of generated string, excluding the terminating null character
|
||||
|
|
@ -59,7 +59,7 @@ static void ipv4_itoa(char *string, uint8_t byte)
|
|||
do {
|
||||
*string++ = '0' + byte % 10;
|
||||
byte /= 10;
|
||||
} while(byte);
|
||||
} while (byte);
|
||||
|
||||
//We put the final \0, then go back one step on the last digit for the swap
|
||||
*string-- = '\0';
|
||||
|
|
|
|||
|
|
@ -74,8 +74,7 @@ bool stoip6(const char *ip6addr, size_t len, void *dest)
|
|||
coloncolon = field_no;
|
||||
q++;
|
||||
len -= 2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
len -= 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -150,11 +149,13 @@ int stoip6_prefix(const char *ip6addr, void *dest, int_fast16_t *prefix_len_out)
|
|||
static bool is_hex(char c)
|
||||
{
|
||||
// 'A' (0x41) and 'a' (0x61) are mapped in the ASCII table in such a way that masking the 0x20 bit turn 'a' in 'A'
|
||||
if ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F')
|
||||
if ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
if (c >= '0' && c <= '9') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ const mem_stat_t *ns_dyn_mem_get_mem_stat(void)
|
|||
|
||||
|
||||
ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
|
||||
void (*passed_fptr)(heap_fail_t),
|
||||
mem_stat_t *info_ptr)
|
||||
void (*passed_fptr)(heap_fail_t),
|
||||
mem_stat_t *info_ptr)
|
||||
{
|
||||
#ifndef STANDARD_MALLOC
|
||||
ns_mem_book_t *book;
|
||||
|
|
@ -108,7 +108,7 @@ ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
|
|||
h_size -= (sizeof(ns_mem_word_size_t) - temp_int);
|
||||
}
|
||||
book = heap;
|
||||
book->heap_main = (ns_mem_word_size_t *)&(book[1]); // SET Heap Pointer
|
||||
book->heap_main = (ns_mem_word_size_t *) & (book[1]); // SET Heap Pointer
|
||||
book->heap_size = h_size - sizeof(ns_mem_book_t); //Set Heap Size
|
||||
temp_int = (book->heap_size / sizeof(ns_mem_word_size_t));
|
||||
temp_int -= 2;
|
||||
|
|
@ -127,7 +127,7 @@ ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
|
|||
memset(book->mem_stat_info_ptr, 0, sizeof(mem_stat_t));
|
||||
book->mem_stat_info_ptr->heap_sector_size = book->heap_size;
|
||||
}
|
||||
book->temporary_alloc_heap_limit = book->heap_size/100 * (100-TEMPORARY_ALLOC_FREE_HEAP_THRESHOLD);
|
||||
book->temporary_alloc_heap_limit = book->heap_size / 100 * (100 - TEMPORARY_ALLOC_FREE_HEAP_THRESHOLD);
|
||||
#endif
|
||||
//There really is no support to standard malloc in this library anymore
|
||||
book->heap_failure_callback = passed_fptr;
|
||||
|
|
@ -154,12 +154,12 @@ int ns_mem_set_temporary_alloc_free_heap_threshold(ns_mem_book_t *book, uint8_t
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (free_heap_amount && free_heap_amount < book->heap_size/2) {
|
||||
if (free_heap_amount && free_heap_amount < book->heap_size / 2) {
|
||||
heap_limit = book->heap_size - free_heap_amount;
|
||||
}
|
||||
|
||||
if (!free_heap_amount && free_heap_percentage && free_heap_percentage < 50) {
|
||||
heap_limit = book->heap_size/100 * (100 - free_heap_percentage);
|
||||
heap_limit = book->heap_size / 100 * (100 - free_heap_percentage);
|
||||
}
|
||||
|
||||
if (free_heap_amount == 0 && free_heap_percentage == 0) {
|
||||
|
|
@ -215,7 +215,7 @@ static ns_mem_word_size_t convert_allocation_size(ns_mem_book_t *book, ns_mem_bl
|
|||
heap_failure(book, NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED);
|
||||
} else if (requested_bytes < 1) {
|
||||
heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID);
|
||||
} else if (requested_bytes > (book->heap_size - 2 * sizeof(ns_mem_word_size_t)) ) {
|
||||
} else if (requested_bytes > (book->heap_size - 2 * sizeof(ns_mem_word_size_t))) {
|
||||
heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID);
|
||||
}
|
||||
return (requested_bytes + sizeof(ns_mem_word_size_t) - 1) / sizeof(ns_mem_word_size_t);
|
||||
|
|
@ -266,10 +266,10 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
|
|||
|
||||
// ns_list_foreach, either forwards or backwards, result to ptr
|
||||
for (hole_t *cur_hole = direction > 0 ? ns_list_get_first(&book->holes_list)
|
||||
: ns_list_get_last(&book->holes_list);
|
||||
cur_hole;
|
||||
cur_hole = direction > 0 ? ns_list_get_next(&book->holes_list, cur_hole)
|
||||
: ns_list_get_previous(&book->holes_list, cur_hole)
|
||||
: ns_list_get_last(&book->holes_list);
|
||||
cur_hole;
|
||||
cur_hole = direction > 0 ? ns_list_get_next(&book->holes_list, cur_hole)
|
||||
: ns_list_get_previous(&book->holes_list, cur_hole)
|
||||
) {
|
||||
ns_mem_word_size_t *p = block_start_from_hole(cur_hole);
|
||||
if (ns_mem_block_validate(p) != 0 || *p >= 0) {
|
||||
|
|
@ -295,7 +295,7 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
|
|||
ns_mem_word_size_t hole_size = block_data_size - data_size - 2;
|
||||
ns_mem_word_size_t *hole_ptr;
|
||||
//There is enough room for a new hole so create it first
|
||||
if ( direction > 0 ) {
|
||||
if (direction > 0) {
|
||||
hole_ptr = block_ptr + 1 + data_size + 1;
|
||||
// Hole will be left at end of area.
|
||||
// Would like to just replace this block_ptr with new descriptor, but
|
||||
|
|
@ -324,7 +324,7 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
|
|||
block_ptr[0] = data_size;
|
||||
block_ptr[1 + data_size] = data_size;
|
||||
|
||||
done:
|
||||
done:
|
||||
if (book->mem_stat_info_ptr) {
|
||||
if (block_ptr) {
|
||||
//Update Allocate OK
|
||||
|
|
@ -433,7 +433,7 @@ static void ns_mem_free_and_merge_with_adjacent_blocks(ns_mem_book_t *book, ns_m
|
|||
} else {
|
||||
// Didn't find adjacent descriptors, but may still
|
||||
// be merging with small blocks without descriptors.
|
||||
if ( merged_data_size >= HOLE_T_SIZE ) {
|
||||
if (merged_data_size >= HOLE_T_SIZE) {
|
||||
// Locate hole position in list, if we don't already know
|
||||
// from merging with the block above.
|
||||
if (!existing_end) {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ static NS_LIST_DEFINE(ns_nvm_request_list, ns_nvm_request_t, link);
|
|||
*/
|
||||
void ns_nvm_callback_func(platform_nvm_status status, void *args)
|
||||
{
|
||||
ns_nvm_request_t *ns_nvm_request_ptr = (ns_nvm_request_t*)args;
|
||||
ns_nvm_request_t *ns_nvm_request_ptr = (ns_nvm_request_t *)args;
|
||||
int client_retval = NS_NVM_OK;
|
||||
|
||||
if (status == PLATFORM_NVM_ERROR) {
|
||||
|
|
@ -69,7 +69,7 @@ void ns_nvm_callback_func(platform_nvm_status status, void *args)
|
|||
client_retval = NS_NVM_DATA_NOT_FOUND;
|
||||
}
|
||||
|
||||
switch(ns_nvm_request_ptr->operation) {
|
||||
switch (ns_nvm_request_ptr->operation) {
|
||||
case NS_NVM_INIT:
|
||||
ns_nvm_operation_continue(ns_nvm_request_ptr->original_request, true);
|
||||
ns_dyn_mem_free(ns_nvm_request_ptr);
|
||||
|
|
@ -185,7 +185,7 @@ static int ns_nvm_operation_continue(ns_nvm_request_t *request, bool free_reques
|
|||
platform_nvm_status ret = PLATFORM_NVM_OK;
|
||||
|
||||
ns_nvm_operation_in_progress = true;
|
||||
switch(request->operation) {
|
||||
switch (request->operation) {
|
||||
case NS_NVM_KEY_WRITE:
|
||||
request->operation = NS_NVM_KEY_CREATE;
|
||||
ret = platform_nvm_key_create(ns_nvm_callback_func, request->client_key_name, *request->buffer_len, 0, request);
|
||||
|
|
|
|||
|
|
@ -64,8 +64,7 @@ TEST(ip6tos, ip6_prefix_tos_func)
|
|||
/***********************************************************/
|
||||
/* Second test group for the old tests that were once lost */
|
||||
|
||||
const char string_addr[][40] =
|
||||
{
|
||||
const char string_addr[][40] = {
|
||||
"2001:db8::1:0:0:1", // 1
|
||||
"2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2
|
||||
"2001:db8::1", // 3
|
||||
|
|
@ -81,20 +80,19 @@ const char string_addr[][40] =
|
|||
};
|
||||
|
||||
|
||||
const uint8_t hex_addr[][16] =
|
||||
{
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 },
|
||||
const uint8_t hex_addr[][16] = {
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0xee, 0xee, 0x00, 0x01 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,0,0,0,0,0,0,1 },
|
||||
{ 0x20, 0x01, 0xd,0xb8, 0,0,0,0,0,0,0,0, 0,2,0,1 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0,0, 0x00, 0x01 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 },
|
||||
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,1 },
|
||||
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,0 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8 },
|
||||
{ 0,0,0,0,0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 },
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
char buf[40];
|
||||
|
|
@ -102,13 +100,11 @@ int i = 0;
|
|||
|
||||
TEST_GROUP(ip6tos_2)
|
||||
{
|
||||
void setUp(void)
|
||||
{
|
||||
void setUp(void) {
|
||||
memset(buf, 0, 40);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
void tearDown(void) {
|
||||
i++;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ TEST_GROUP(dynmem)
|
|||
TEST(dynmem, init)
|
||||
{
|
||||
uint16_t size = 1000;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
mem_stat_t info;
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
CHECK(info.heap_sector_size >= (size-72));
|
||||
CHECK(info.heap_sector_size >= (size - 72));
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(ns_dyn_mem_get_mem_stat() == &info);
|
||||
free(heap);
|
||||
|
|
@ -46,11 +46,11 @@ TEST(dynmem, init)
|
|||
TEST(dynmem, different_sizes)
|
||||
{
|
||||
reset_heap_error();
|
||||
for (uint16_t size = 1000; size<32768; size++) {
|
||||
for (uint16_t size = 1000; size < 32768; size++) {
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
CHECK(info.heap_sector_size >= (size-72));
|
||||
CHECK(info.heap_sector_size >= (size - 72));
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(ns_dyn_mem_alloc(10));
|
||||
free(heap);
|
||||
|
|
@ -61,14 +61,15 @@ TEST(dynmem, diff_alignment)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *ptr = heap;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
for (int i=0; i<16; i++) {
|
||||
ptr++; size--;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ptr++;
|
||||
size--;
|
||||
ns_dyn_mem_init(ptr, size, &heap_fail_callback, &info);
|
||||
CHECK(info.heap_sector_size >= (size-72));
|
||||
CHECK(info.heap_sector_size >= (size - 72));
|
||||
CHECK(!heap_have_failed());
|
||||
}
|
||||
free(heap);
|
||||
|
|
@ -79,7 +80,7 @@ TEST(dynmem, ns_dyn_mem_alloc)
|
|||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
void *p[size];
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
|
|
@ -87,17 +88,18 @@ TEST(dynmem, ns_dyn_mem_alloc)
|
|||
int block = 1;
|
||||
|
||||
int i;
|
||||
for (i=0; i<size; i++) {
|
||||
for (i = 0; i < size; i++) {
|
||||
p[i] = ns_dyn_mem_alloc(block);
|
||||
if (!p[i])
|
||||
if (!p[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(info.heap_alloc_fail_cnt == 1);
|
||||
CHECK(info.heap_sector_alloc_cnt == i);
|
||||
CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max);
|
||||
|
||||
for (; i>=0; i--) {
|
||||
for (; i >= 0; i--) {
|
||||
ns_dyn_mem_free(p[i]);
|
||||
}
|
||||
CHECK(!heap_have_failed());
|
||||
|
|
@ -110,7 +112,7 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc)
|
|||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
void *p[size];
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
|
|
@ -118,17 +120,18 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc)
|
|||
int block = 1;
|
||||
|
||||
int i;
|
||||
for (i=0; i<size; i++) {
|
||||
for (i = 0; i < size; i++) {
|
||||
p[i] = ns_dyn_mem_temporary_alloc(block);
|
||||
if (!p[i])
|
||||
if (!p[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(info.heap_alloc_fail_cnt == 1);
|
||||
CHECK(info.heap_sector_alloc_cnt == i);
|
||||
CHECK(info.heap_sector_allocated_bytes == info.heap_sector_allocated_bytes_max);
|
||||
|
||||
for (; i>=0; i--) {
|
||||
for (; i >= 0; i--) {
|
||||
ns_dyn_mem_free(p[i]);
|
||||
}
|
||||
CHECK(!heap_have_failed());
|
||||
|
|
@ -142,24 +145,24 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
|
|||
mem_stat_t info;
|
||||
void *p1, *p2;
|
||||
int ret_val;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
CHECK(!heap_have_failed());
|
||||
|
||||
// test1: temporary alloc will fail if there is less than 5% heap free
|
||||
p1 = ns_dyn_mem_temporary_alloc((size-72)*0.96);
|
||||
p1 = ns_dyn_mem_temporary_alloc((size - 72) * 0.96);
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(p1);
|
||||
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.02);
|
||||
p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.02);
|
||||
CHECK(p2 == NULL);
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(info.heap_alloc_fail_cnt == 1);
|
||||
|
||||
// Test2, disable threshold feature and try p2 allocation again
|
||||
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0);
|
||||
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.02);
|
||||
p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.02);
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(p2);
|
||||
ns_dyn_mem_free(p1);
|
||||
|
|
@ -169,10 +172,10 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
|
|||
|
||||
// Test3, enable feature by free heap percentage
|
||||
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(40, 0);
|
||||
p1 = ns_dyn_mem_temporary_alloc((size-72)*0.65);
|
||||
p1 = ns_dyn_mem_temporary_alloc((size - 72) * 0.65);
|
||||
CHECK(p1);
|
||||
p2 = ns_dyn_mem_temporary_alloc((size-72)*0.10);
|
||||
CHECK(p2==NULL);
|
||||
p2 = ns_dyn_mem_temporary_alloc((size - 72) * 0.10);
|
||||
CHECK(p2 == NULL);
|
||||
ns_dyn_mem_free(p1);
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(info.heap_alloc_fail_cnt == 2);
|
||||
|
|
@ -180,21 +183,21 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
|
|||
|
||||
// Test4, enable feature by free heap amount
|
||||
ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 200);
|
||||
p1 = ns_dyn_mem_temporary_alloc(size-72-100 /*828 bytes */);
|
||||
p1 = ns_dyn_mem_temporary_alloc(size - 72 - 100 /*828 bytes */);
|
||||
CHECK(p1);
|
||||
p2 = ns_dyn_mem_temporary_alloc(1);
|
||||
CHECK(p2==NULL);
|
||||
CHECK(p2 == NULL);
|
||||
ns_dyn_mem_free(p1);
|
||||
|
||||
// Test5, illegal API parameters
|
||||
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size/2);
|
||||
CHECK(ret_val==-2);
|
||||
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size*2);
|
||||
CHECK(ret_val==-2);
|
||||
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size / 2);
|
||||
CHECK(ret_val == -2);
|
||||
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, size * 2);
|
||||
CHECK(ret_val == -2);
|
||||
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(51, 0);
|
||||
CHECK(ret_val==-2);
|
||||
CHECK(ret_val == -2);
|
||||
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(255, 0);
|
||||
CHECK(ret_val==-2);
|
||||
CHECK(ret_val == -2);
|
||||
|
||||
CHECK(!heap_have_failed());
|
||||
CHECK(info.heap_alloc_fail_cnt == 3);
|
||||
|
|
@ -202,20 +205,21 @@ TEST(dynmem, ns_dyn_mem_temporary_alloc_with_heap_threshold)
|
|||
free(heap);
|
||||
|
||||
// Test6, feature is disabled if info is not set
|
||||
heap = (uint8_t*)malloc(size);
|
||||
heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL);
|
||||
ret_val = ns_dyn_mem_set_temporary_alloc_free_heap_threshold(0, 0);
|
||||
CHECK(ret_val==-1);
|
||||
CHECK(ret_val == -1);
|
||||
CHECK(!heap_have_failed());
|
||||
free(heap);
|
||||
}
|
||||
|
||||
TEST(dynmem, test_both_allocs_with_hole_usage) {
|
||||
TEST(dynmem, test_both_allocs_with_hole_usage)
|
||||
{
|
||||
uint16_t size = 112;
|
||||
mem_stat_t info;
|
||||
void *p[size];
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
|
|
@ -240,11 +244,12 @@ TEST(dynmem, test_both_allocs_with_hole_usage) {
|
|||
free(heap);
|
||||
}
|
||||
|
||||
TEST(dynmem, test_temp_alloc_with_skipping_hole) {
|
||||
TEST(dynmem, test_temp_alloc_with_skipping_hole)
|
||||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
void *p[size];
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
|
|
@ -268,7 +273,7 @@ TEST(dynmem, zero_allocate)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *ptr = heap;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -284,7 +289,7 @@ TEST(dynmem, too_big)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *ptr = heap;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -300,7 +305,7 @@ TEST(dynmem, corrupted_memory)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *ptr = heap;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -315,10 +320,11 @@ TEST(dynmem, corrupted_memory)
|
|||
free(heap);
|
||||
}
|
||||
|
||||
TEST(dynmem, no_big_enough_sector) {
|
||||
TEST(dynmem, no_big_enough_sector)
|
||||
{
|
||||
uint16_t size = 112;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *ptr = heap;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -342,13 +348,13 @@ TEST(dynmem, diff_sizes)
|
|||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
void *p;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
CHECK(!heap_have_failed());
|
||||
int i;
|
||||
for (i=1; i<(size-72); i++) {
|
||||
for (i = 1; i < (size - 72); i++) {
|
||||
p = ns_dyn_mem_temporary_alloc(i);
|
||||
CHECK(p);
|
||||
ns_dyn_mem_free(p);
|
||||
|
|
@ -363,7 +369,7 @@ TEST(dynmem, double_free)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
void *p;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -383,13 +389,13 @@ TEST(dynmem, middle_free)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
void *p[3];
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, &info);
|
||||
CHECK(!heap_have_failed());
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
p[i] = ns_dyn_mem_temporary_alloc(100);
|
||||
CHECK(p);
|
||||
}
|
||||
|
|
@ -406,7 +412,7 @@ TEST(dynmem, over_by_one)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *p;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -425,7 +431,7 @@ TEST(dynmem, not_from_this_heap)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *p;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -447,7 +453,7 @@ TEST(dynmem, free_on_empty_heap)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *p;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -463,7 +469,7 @@ TEST(dynmem, not_negative_stats)
|
|||
{
|
||||
uint16_t size = 1000;
|
||||
mem_stat_t info;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
void *p;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -479,7 +485,7 @@ TEST(dynmem, not_negative_stats)
|
|||
CHECK(info.heap_sector_allocated_bytes >= 16);
|
||||
CHECK(info.heap_sector_allocated_bytes < last_value);
|
||||
last_value = info.heap_sector_allocated_bytes;
|
||||
for (int i=0; i<10; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
p = ns_dyn_mem_alloc(1);
|
||||
ns_dyn_mem_free(p);
|
||||
}
|
||||
|
|
@ -487,9 +493,10 @@ TEST(dynmem, not_negative_stats)
|
|||
free(heap);
|
||||
}
|
||||
|
||||
TEST(dynmem, test_invalid_pointer_freed) {
|
||||
TEST(dynmem, test_invalid_pointer_freed)
|
||||
{
|
||||
uint16_t size = 92;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
ns_dyn_mem_init(heap, size, &heap_fail_callback, NULL);
|
||||
|
|
@ -503,9 +510,10 @@ TEST(dynmem, test_invalid_pointer_freed) {
|
|||
free(heap);
|
||||
}
|
||||
|
||||
TEST(dynmem, test_merge_corrupted_previous_block) {
|
||||
TEST(dynmem, test_merge_corrupted_previous_block)
|
||||
{
|
||||
uint16_t size = 1000;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *p;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -524,9 +532,10 @@ TEST(dynmem, test_merge_corrupted_previous_block) {
|
|||
free(heap);
|
||||
}
|
||||
|
||||
TEST(dynmem, test_free_corrupted_next_block) {
|
||||
TEST(dynmem, test_free_corrupted_next_block)
|
||||
{
|
||||
uint16_t size = 1000;
|
||||
uint8_t *heap = (uint8_t*)malloc(size);
|
||||
uint8_t *heap = (uint8_t *)malloc(size);
|
||||
uint8_t *p;
|
||||
CHECK(NULL != heap);
|
||||
reset_heap_error();
|
||||
|
|
@ -546,7 +555,8 @@ TEST(dynmem, test_free_corrupted_next_block) {
|
|||
}
|
||||
|
||||
//NOTE! This test must be last!
|
||||
TEST(dynmem, uninitialized_test){
|
||||
TEST(dynmem, uninitialized_test)
|
||||
{
|
||||
void *p = ns_dyn_mem_alloc(4);
|
||||
ns_dyn_mem_free(p);
|
||||
CHECK(p == NULL);
|
||||
|
|
|
|||
|
|
@ -19,15 +19,18 @@
|
|||
heap_fail_t current_heap_error;
|
||||
static bool failed;
|
||||
|
||||
void heap_fail_callback(heap_fail_t err) {
|
||||
current_heap_error = err;
|
||||
failed = true;
|
||||
void heap_fail_callback(heap_fail_t err)
|
||||
{
|
||||
current_heap_error = err;
|
||||
failed = true;
|
||||
}
|
||||
|
||||
void reset_heap_error() {
|
||||
failed = false;
|
||||
void reset_heap_error()
|
||||
{
|
||||
failed = false;
|
||||
}
|
||||
|
||||
bool heap_have_failed() {
|
||||
return failed;
|
||||
bool heap_have_failed()
|
||||
{
|
||||
return failed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ bool test_ns_nvm_helper_read()
|
|||
|
||||
bool test_ns_nvm_helper_delete()
|
||||
{
|
||||
int ret_val;
|
||||
int ret_val;
|
||||
|
||||
delete_callback_status = -1;
|
||||
delete_callback_context = NULL;
|
||||
|
|
@ -243,7 +243,7 @@ bool test_ns_nvm_helper_delete()
|
|||
|
||||
bool test_ns_nvm_helper_concurrent_requests()
|
||||
{
|
||||
int ret_val;
|
||||
int ret_val;
|
||||
|
||||
write_callback_status = -1;
|
||||
write_callback_context = NULL;
|
||||
|
|
@ -252,7 +252,7 @@ bool test_ns_nvm_helper_concurrent_requests()
|
|||
delete_callback_status = -1;
|
||||
delete_callback_context = NULL;
|
||||
|
||||
// read ok
|
||||
// read ok
|
||||
test_platform_nvm_api_set_retval(PLATFORM_NVM_OK);
|
||||
nsdynmemlib_stub.returnCounter = 1;
|
||||
ret_val = ns_nvm_data_read(test_ns_nvm_helper_read_callback, key1, &buf, &buf_len, TEST_NS_NVM_HELPER_CONTEXT1);
|
||||
|
|
@ -306,7 +306,7 @@ bool test_ns_nvm_helper_concurrent_requests()
|
|||
|
||||
bool test_ns_nvm_helper_platform_error()
|
||||
{
|
||||
int ret_val;
|
||||
int ret_val;
|
||||
|
||||
write_callback_status = -1;
|
||||
write_callback_context = NULL;
|
||||
|
|
@ -358,7 +358,7 @@ bool test_ns_nvm_helper_platform_error()
|
|||
|
||||
bool test_ns_nvm_helper_platform_error_in_write()
|
||||
{
|
||||
int ret_val;
|
||||
int ret_val;
|
||||
|
||||
write_callback_status = -1;
|
||||
write_callback_context = NULL;
|
||||
|
|
|
|||
|
|
@ -106,8 +106,7 @@ TEST(stoip6, InvalidAddresses)
|
|||
uint8_t ip[16];
|
||||
uint8_t correct[16] = {0};
|
||||
|
||||
const char *invalidArray[] =
|
||||
{
|
||||
const char *invalidArray[] = {
|
||||
"FFFF:FFFF::FFFF::FFFF", // Two ::
|
||||
"F:F:F:FqF:F:F:F:F", // Non-hex character
|
||||
"F:F:F:FFFFF:F:F:F:F" // >4 hex characters in a segment
|
||||
|
|
@ -122,8 +121,7 @@ TEST(stoip6, InvalidAddresses)
|
|||
/***********************************************************/
|
||||
/* Second test group for the old tests that were once lost */
|
||||
|
||||
const char string_addr[][40] =
|
||||
{
|
||||
const char string_addr[][40] = {
|
||||
"2001:db8::1:0:0:1", // 1
|
||||
"2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2
|
||||
"2001:db8::1", // 3
|
||||
|
|
@ -139,20 +137,19 @@ const char string_addr[][40] =
|
|||
};
|
||||
|
||||
|
||||
const uint8_t hex_addr[][16] =
|
||||
{
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 },
|
||||
const uint8_t hex_addr[][16] = {
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0xee, 0xee, 0x00, 0x01 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,0,0,0,0,0,0,1 },
|
||||
{ 0x20, 0x01, 0xd,0xb8, 0,0,0,0,0,0,0,0, 0,2,0,1 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0,0, 0x00, 0x01 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 },
|
||||
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,1 },
|
||||
{ 0x20, 0x01, 0,0 ,0,0 ,0,1,0,0,0,0,0,0,0,0 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0x20, 0x01, 0xd, 0xb8 },
|
||||
{ 0,0,0,0,0,0,0,0,0xaa,0xaa,0,0,0,0,0,1 },
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
char buf[40];
|
||||
|
|
@ -160,13 +157,11 @@ int i = 0;
|
|||
|
||||
TEST_GROUP(stoip6_2)
|
||||
{
|
||||
void setUp(void)
|
||||
{
|
||||
void setUp(void) {
|
||||
memset(buf, 0, 40);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
void tearDown(void) {
|
||||
i++;
|
||||
}
|
||||
};
|
||||
|
|
@ -240,8 +235,7 @@ TEST(stoip6_2, test_2_12)
|
|||
/***********************************************************/
|
||||
/* Third test group for stoip6_prefix */
|
||||
|
||||
const char string_prefix_addr[][40] =
|
||||
{
|
||||
const char string_prefix_addr[][40] = {
|
||||
"2001:db8::1:0:0:1/64", // 1
|
||||
"2001::/60", // 2
|
||||
"::1/48", // 3
|
||||
|
|
@ -254,12 +248,11 @@ const char string_prefix_addr[][40] =
|
|||
};
|
||||
|
||||
|
||||
const uint8_t hex_prefix_addr[][16] =
|
||||
{
|
||||
const uint8_t hex_prefix_addr[][16] = {
|
||||
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, // 1
|
||||
{ 0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 2
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }, // 3
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, // 4
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, // 3
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 4
|
||||
{ 0x20, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, // 5
|
||||
{ 0x20, 0x03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3 }, // 6
|
||||
{ 0x20, 0x04, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }, // 7
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ struct ip6_addresses_and_its_binary_form_t {
|
|||
{ "2001:db8::2:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1 }},
|
||||
{ "2001:db8:aaaa:bbbb:cccc:dddd:0:1", { 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0, 0, 0x00, 0x01 }},
|
||||
{ "2001:db8::aaaa:0:0:1", { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 }},
|
||||
{ "2001:0:0:1::1", { 0x20, 0x01, 0, 0 , 0, 0 , 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }},
|
||||
{ "2001:0:0:1::", { 0x20, 0x01, 0, 0 , 0, 0 , 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }},
|
||||
{ "2001:0:0:1::1", { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 }},
|
||||
{ "2001:0:0:1::", { 0x20, 0x01, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }},
|
||||
{ "2001:db8::", { 0x20, 0x01, 0xd, 0xb8 }},
|
||||
{ "::aaaa:0:0:1", { 0, 0, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa, 0, 0, 0, 0, 0, 1 }},
|
||||
{ "::1", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }},
|
||||
|
|
|
|||
|
|
@ -31,31 +31,25 @@ void ns_dyn_mem_init(void *heap, ns_mem_heap_size_t h_size, void (*passed_fptr)(
|
|||
|
||||
void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size)
|
||||
{
|
||||
if (nsdynmemlib_stub.returnCounter > 0)
|
||||
{
|
||||
if (nsdynmemlib_stub.returnCounter > 0) {
|
||||
nsdynmemlib_stub.returnCounter--;
|
||||
return malloc(alloc_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(nsdynmemlib_stub.expectedPointer);
|
||||
} else {
|
||||
return (nsdynmemlib_stub.expectedPointer);
|
||||
}
|
||||
}
|
||||
|
||||
void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size)
|
||||
{
|
||||
if (nsdynmemlib_stub.returnCounter > 0)
|
||||
{
|
||||
if (nsdynmemlib_stub.returnCounter > 0) {
|
||||
nsdynmemlib_stub.returnCounter--;
|
||||
return malloc(alloc_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(nsdynmemlib_stub.expectedPointer);
|
||||
} else {
|
||||
return (nsdynmemlib_stub.expectedPointer);
|
||||
}
|
||||
}
|
||||
|
||||
void ns_dyn_mem_free(void *block)
|
||||
{
|
||||
free(block);
|
||||
free(block);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ extern "C" {
|
|||
|
||||
typedef struct {
|
||||
uint8_t returnCounter;
|
||||
void* expectedPointer;
|
||||
void *expectedPointer;
|
||||
} nsdynmemlib_stub_data_t;
|
||||
|
||||
extern nsdynmemlib_stub_data_t nsdynmemlib_stub;
|
||||
|
|
|
|||
Loading…
Reference in New Issue