ReactOS 0.4.15-dev-7907-g95bf896
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
15static void
17{
18}
19
20static void
22{
23}
24
25
26/* Test functions */
27
29START_TEST(test_mem_one)
30{
31#define SIZE1 16
32#define SIZE1_2 12
33#define SIZE2 16
34 void *p1, *p2;
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}
62END_TEST
63
64
66Suite *
68{
69 TFun tests[] = {
70 test_mem_one
71 };
72 return create_suite("MEM", tests, sizeof(tests)/sizeof(TFun), mem_setup, mem_teardown);
73}
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:73
#define START_TEST(x)
Definition: atltest.h:75
#define mem_free(ptr, bsize)
Definition: types.h:124
#define NULL
Definition: types.h:112
#define mem_trim(_m_, _s_)
Definition: cc.h:20
void * mem_malloc(mem_size_t size)
Definition: mem.c:494
u16_t mem_size_t
Definition: mem.h:76
static Suite * create_suite(const char *name, TFun *tests, size_t num_tests, SFun setup, SFun teardown)
Definition: lwip_check.h:20
struct S1 s1
struct S2 s2
static struct test_info tests[]
static void mem_teardown(void)
Definition: test_mem.c:21
END_TEST Suite * mem_suite(void)
Definition: test_mem.c:67
#define SIZE2
#define SIZE1
static void mem_setup(void)
Definition: test_mem.c:16
#define SIZE1_2