Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/vmalloc/tmalloc.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "vmtest.h"
21
22
tmain()
23
{
24
Vmalloc_t *vm;
25
Void_t *addr[10];
26
Void_t *mem;
27
int i;
28
29
Vmdcheap->round = 64;
30
if(!(vm = vmopen(Vmdcheap, Vmbest, 0)) )
31
terror("Open failed");
32
33
for(i = 0; i < 10; ++i)
34
if(!(addr[i] = vmalloc(vm,15)) )
35
terror("vmalloc failed");
36
for(i = 0; i < 10; ++i)
37
if(vmfree(vm,addr[i]) < 0)
38
terror("vmfree failed");
39
for(i = 0; i < 10; ++i)
40
if(!(addr[i] = vmalloc(vm,15)) )
41
terror("vmalloc failed");
42
#ifdef DEBUG
43
for(i = 0; i < 10; ++i)
44
printf("size[%d]=%d\n",i,vmsize(vm,addr[i]));
45
printf("Extent=%d\n",vmsize(vm,NIL(Void_t*)));
46
#endif
47
48
mem = 0;
49
if(posix_memalign(&mem, 3, 128) != EINVAL)
50
terror("Bad return value from posix_memalign()");
51
if(mem)
52
terror("Bad memory");
53
54
if(posix_memalign(&mem, 3*sizeof(Void_t*), 128) != EINVAL)
55
terror("Bad return value from posix_memalign()");
56
if(mem)
57
terror("Bad memory");
58
59
if(posix_memalign(&mem, (sizeof(Void_t*)<<4), 128) != 0 )
60
terror("posix_memalign() failed");
61
if(!mem)
62
terror("Bad memory");
63
64
texit(0);
65
}
66
67