-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmalloctest.c
46 lines (38 loc) · 1.22 KB
/
malloctest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/****************************************************************
* Test for memory allocator
*
* Copyright Alastair Reid 2020
* SPDX-Licence-Identifier: BSD-3-Clause
****************************************************************/
#include "stddef.h"
#include "stdint.h"
#include "stdlib.h"
#include "malloc1.h"
/****************************************************************
* Sequential tests
****************************************************************/
struct slab myslab;
#define HEAP_SIZE 10000
char heap[HEAP_SIZE];
// Sequential test code
void test_slab_sequential()
//@ requires slab_raw(&myslab) &*& chars(heap, HEAP_SIZE, _);
//@ ensures true;
//@ terminates;
{
size_t objsize = 256; // size of objects
//@ assume (&heap != 0);
//@ assume (sizeof(struct freelist) <= objsize);
//@ assume (is_aligned(&heap, MIN_ALIGNMENT));
slab_init(&myslab, heap, HEAP_SIZE, objsize);
void *t1 = slab_alloc(&myslab);
if (t1 == 0) abort();
void *t2 = slab_alloc(&myslab);
if (t2 == 0) abort();
slab_free(&myslab, t1);
slab_free(&myslab, t2);
//@ leak slab(&myslab, _, _, _, _);
}
/****************************************************************
* End
****************************************************************/