uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_mem.c
Go to the documentation of this file.
1 #include "test_mem.h"
2 
3 #include "lwip/mem.h"
4 #include "lwip/stats.h"
5 
6 #if !LWIP_STATS || !MEM_STATS
7 #error "This tests needs MEM-statistics enabled"
8 #endif
9 #if LWIP_DNS
10 /*#error "This test needs DNS turned off (as it mallocs on init)"*/
11 #endif
12 
13 /* Setups/teardown functions */
14 
15 static void
16 mem_setup(void)
17 {
18 }
19 
20 static void
21 mem_teardown(void)
22 {
23 }
24 
25 
26 /* Test functions */
27 
29 START_TEST(test_mem_one)
30 {
31 #define SIZE1 16
32 #define SIZE1_2 12
33 #define SIZE2 16
34  void *p1, *p2;
35  mem_size_t s1, s2;
36  LWIP_UNUSED_ARG(_i);
37 
38 #if LWIP_DNS
39  fail("This test needs DNS turned off (as it mallocs on init)");
40 #endif
41 
42  fail_unless(lwip_stats.mem.used == 0);
43 
44  p1 = mem_malloc(SIZE1);
45  fail_unless(p1 != NULL);
46  fail_unless(lwip_stats.mem.used >= SIZE1);
47  s1 = lwip_stats.mem.used;
48 
49  p2 = mem_malloc(SIZE2);
50  fail_unless(p2 != NULL);
51  fail_unless(lwip_stats.mem.used >= SIZE2 + s1);
52  s2 = lwip_stats.mem.used;
53 
54  mem_trim(p1, SIZE1_2);
55 
56  mem_free(p2);
57  fail_unless(lwip_stats.mem.used <= s2 - SIZE2);
58 
59  mem_free(p1);
60  fail_unless(lwip_stats.mem.used == 0);
61 }
62 END_TEST
63 
64 
66 Suite *
67 mem_suite(void)
68 {
69  TFun tests[] = {
70  test_mem_one,
71  };
72  return create_suite("MEM", tests, sizeof(tests)/sizeof(TFun), mem_setup, mem_teardown);
73 }