]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blob - test/unit/core/test_mem.c
Fixed bug #28679: mem_realloc calculates mem_stats wrong and added test case for it
[pes-rpp/rpp-lwip.git] / test / unit / core / test_mem.c
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_SNMP || LWIP_DNS
10 #error "This test needs SNMP and DNS turned off (as they malloc 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
28 /** Call mem_malloc, mem_free and mem_realloc and check stats */
29 START_TEST(test_mem_one)
30 {
31 #define SIZE1   16
32 #define SIZE1_2 12
33 #define SIZE2   16
34   void *p1, *p2, *p3, *p4, *p5;
35   mem_size_t s1, s2;
36   LWIP_UNUSED_ARG(_i);
37
38   fail_unless(lwip_stats.mem.used == 0);
39
40   p1 = mem_malloc(SIZE1);
41   fail_unless(p1 != NULL);
42   fail_unless(lwip_stats.mem.used >= SIZE1);
43   s1 = lwip_stats.mem.used;
44
45   p2 = mem_malloc(SIZE2);
46   fail_unless(p2 != NULL);
47   fail_unless(lwip_stats.mem.used >= SIZE2 + s1);
48   s2 = lwip_stats.mem.used;
49
50   mem_realloc(p1, SIZE1_2);
51
52   mem_free(p2);
53   fail_unless(lwip_stats.mem.used <= s2 - SIZE2);
54
55   mem_free(p1);
56   fail_unless(lwip_stats.mem.used == 0);
57 }
58 END_TEST
59
60
61 /** Create the suite including all tests for this module */
62 Suite *
63 mem_suite(void)
64 {
65   TFun tests[] = {
66     test_mem_one,
67   };
68   return create_suite("MEM", tests, sizeof(tests)/sizeof(TFun), mem_setup, mem_teardown);
69 }