Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/vmalloc/talign.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
static char Mem[13*1024];
23
24
#if __STD_C
25
static Void_t* alignmem(Vmalloc_t* vm, Void_t* ca, size_t cs, size_t ns, Vmdisc_t* dc)
26
#else
27
static Void_t* alignmem(vm, ca, cs, ns, dc)
28
Vmalloc_t* vm;
29
Void_t* ca;
30
size_t cs;
31
size_t ns;
32
Vmdisc_t* dc;
33
#endif
34
{
35
return (Void_t*)Mem;
36
}
37
38
static Vmdisc_t Disc = { alignmem, NIL(Vmexcept_f), 10*1024};
39
40
tmain()
41
{
42
Vmalloc_t* vm;
43
Void_t* data;
44
int i, j;
45
46
if(!(vm = vmopen(&Disc,Vmbest,0)) )
47
terror("Opening region0");
48
if(!(data = vmalign(vm,10,13)) )
49
terror("vmalign0");
50
if(((Vmulong_t)data%13) != 0)
51
terror("Not aligned0");
52
vmclose(vm);
53
54
if(!(vm = vmopen(&Disc,Vmlast,0)) )
55
terror("Opening region0.1");
56
if(!(data = vmalign(vm,10,13)) )
57
terror("vmalign0.1");
58
if(((Vmulong_t)data%13) != 0)
59
terror("Not aligned0.1");
60
61
Vmdcheap->round = ALIGN;
62
if(!(vm = vmopen(Vmdcheap,Vmbest,0)) )
63
terror("Opening region1");
64
if(!(data = vmalloc(vm,10)) )
65
terror("vmalloc1");
66
if(!(data = vmalign(vm,10,13)) )
67
terror("vmalign1");
68
if(((Vmulong_t)data%13) != 0)
69
terror("Not aligned1");
70
vmclose(vm);
71
72
if(!(vm = vmopen(Vmdcheap,Vmdebug,0)) )
73
terror("Opening region");
74
if(!(data = vmalloc(vm,10)) )
75
terror("vmalloc3");
76
if(!(data = vmalign(vm,10,13)) )
77
terror("vmalign3");
78
if(((Vmulong_t)data%13) != 0)
79
terror("Not aligned3");
80
vmclose(vm);
81
82
if(!(vm = vmopen(Vmdcheap,Vmbest,0)) )
83
terror("Opening region2");
84
for(i = 0; i < 100; ++i)
85
{ for(j = 0; j < 10; ++j)
86
if(!(data = vmalloc(vm,17)) )
87
terror("vmalloc failed");
88
if(!(data = vmalign(vm,64,4096)) )
89
terror("vmalign failed");
90
if(((Vmulong_t)data % 4096) != 0)
91
terror("Not aligned");
92
}
93
vmclose(vm);
94
95
if(!(vm = vmopen(Vmdcheap,Vmdebug,0)) )
96
terror("Opening region2");
97
for(i = 0; i < 100; ++i)
98
{ for(j = 0; j < 10; ++j)
99
if(!(data = vmalloc(vm,17)) )
100
terror("vmalloc failed");
101
if(!(data = vmalign(vm,64,4096)) )
102
terror("vmalign failed");
103
if(((Vmulong_t)data % 4096) != 0)
104
terror("Not aligned");
105
}
106
vmclose(vm);
107
108
texit(0);
109
}
110
111