SAMV71 Xplained Ultra Software Package 1.0

test_mem.c

00001 #include "test_mem.h"
00002 
00003 #include "lwip/mem.h"
00004 #include "lwip/stats.h"
00005 
00006 #if !LWIP_STATS || !MEM_STATS
00007 #error "This tests needs MEM-statistics enabled"
00008 #endif
00009 #if LWIP_DNS
00010 #error "This test needs DNS turned off (as it mallocs on init)"
00011 #endif
00012 
00013 /* Setups/teardown functions */
00014 
00015 static void
00016 mem_setup(void)
00017 {
00018 }
00019 
00020 static void
00021 mem_teardown(void)
00022 {
00023 }
00024 
00025 
00026 /* Test functions */
00027 
00028 /** Call mem_malloc, mem_free and mem_trim and check stats */
00029 START_TEST(test_mem_one)
00030 {
00031 #define SIZE1   16
00032 #define SIZE1_2 12
00033 #define SIZE2   16
00034   void *p1, *p2;
00035   mem_size_t s1, s2;
00036   LWIP_UNUSED_ARG(_i);
00037 
00038 #if LWIP_DNS
00039   fail("This test needs DNS turned off (as it mallocs on init)");
00040 #endif
00041 
00042   fail_unless(lwip_stats.mem.used == 0);
00043 
00044   p1 = mem_malloc(SIZE1);
00045   fail_unless(p1 != NULL);
00046   fail_unless(lwip_stats.mem.used >= SIZE1);
00047   s1 = lwip_stats.mem.used;
00048 
00049   p2 = mem_malloc(SIZE2);
00050   fail_unless(p2 != NULL);
00051   fail_unless(lwip_stats.mem.used >= SIZE2 + s1);
00052   s2 = lwip_stats.mem.used;
00053 
00054   mem_trim(p1, SIZE1_2);
00055 
00056   mem_free(p2);
00057   fail_unless(lwip_stats.mem.used <= s2 - SIZE2);
00058 
00059   mem_free(p1);
00060   fail_unless(lwip_stats.mem.used == 0);
00061 }
00062 END_TEST
00063 
00064 
00065 /** Create the suite including all tests for this module */
00066 Suite *
00067 mem_suite(void)
00068 {
00069   TFun tests[] = {
00070     test_mem_one
00071   };
00072   return create_suite("MEM", tests, sizeof(tests)/sizeof(TFun), mem_setup, mem_teardown);
00073 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines