From 7162c5eed91a8e22a4b768110011df28bfd86455 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 13 Jul 2017 15:58:03 +0200 Subject: forgot to add test_malloc.c remove buffer memory functions again (can be done with a simple cast in the caller) --- tests/libc/test_malloc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/libc/test_malloc.c (limited to 'tests') diff --git a/tests/libc/test_malloc.c b/tests/libc/test_malloc.c new file mode 100644 index 0000000..0f74fad --- /dev/null +++ b/tests/libc/test_malloc.c @@ -0,0 +1,24 @@ +#include "stdlib.h" +#include "string.h" + +#define HEAP_SIZE 128 * 1024 + +int main( void ) +{ + memory_manager_t memory_manager; + char buf[HEAP_SIZE]; + uint32_t heap_offset = (uint32_t)&buf; + size_t heap_size = HEAP_SIZE; + memory_manager_init( &memory_manager, heap_offset, heap_size ); + __stdlib_set_memory_manager( &memory_manager ); + + char *s; + char *s1 = "test_string"; + + s = (char *)malloc( strlen( s1 ) + 1 ); + size_t n = strlcpy( s, s1, strlen( s1 ) + 1 ); + if( n != 11 ) return 1; + if( strcmp( s, s1 ) != 0 ) return 1; + + return 0; +} -- cgit v1.2.3-54-g00ecf