xref: /minix3/tests/kernel/t_extent.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /* $NetBSD: t_extent.c,v 1.4 2012/01/27 18:53:10 para Exp $ */
2*11be35a1SLionel Sambuc 
3*11be35a1SLionel Sambuc /*-
4*11be35a1SLionel Sambuc  * Copyright (c) 2008 The NetBSD Foundation, Inc.
5*11be35a1SLionel Sambuc  * All rights reserved.
6*11be35a1SLionel Sambuc  *
7*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
9*11be35a1SLionel Sambuc  * are met:
10*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
11*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
13*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
14*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
15*11be35a1SLionel Sambuc  *
16*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17*11be35a1SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18*11be35a1SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19*11be35a1SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20*11be35a1SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*11be35a1SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*11be35a1SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*11be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*11be35a1SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*11be35a1SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*11be35a1SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
27*11be35a1SLionel Sambuc  */
28*11be35a1SLionel Sambuc 
29*11be35a1SLionel Sambuc #include <sys/cdefs.h>
30*11be35a1SLionel Sambuc __COPYRIGHT("@(#) Copyright (c) 2008\
31*11be35a1SLionel Sambuc  The NetBSD Foundation, inc. All rights reserved.");
32*11be35a1SLionel Sambuc __RCSID("$NetBSD: t_extent.c,v 1.4 2012/01/27 18:53:10 para Exp $");
33*11be35a1SLionel Sambuc 
34*11be35a1SLionel Sambuc #include <sys/types.h>
35*11be35a1SLionel Sambuc #include <sys/queue.h>
36*11be35a1SLionel Sambuc #include <sys/extent.h>
37*11be35a1SLionel Sambuc 
38*11be35a1SLionel Sambuc #include <stdio.h>
39*11be35a1SLionel Sambuc #include <stdlib.h>
40*11be35a1SLionel Sambuc #include <string.h>
41*11be35a1SLionel Sambuc 
42*11be35a1SLionel Sambuc #include <atf-c.h>
43*11be35a1SLionel Sambuc 
44*11be35a1SLionel Sambuc #include "../h_macros.h"
45*11be35a1SLionel Sambuc 
46*11be35a1SLionel Sambuc static int ret;
47*11be35a1SLionel Sambuc static struct extent *ex;
48*11be35a1SLionel Sambuc 
49*11be35a1SLionel Sambuc #define h_create(name, start, end, flags) \
50*11be35a1SLionel Sambuc 	ATF_REQUIRE((ex = extent_create(name, \
51*11be35a1SLionel Sambuc 	    start, end, 0, 0, flags)) != NULL);
52*11be35a1SLionel Sambuc 
53*11be35a1SLionel Sambuc #define h_alloc_region(start, size) \
54*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ_MSG(ret = extent_alloc_region(ex, \
55*11be35a1SLionel Sambuc 	    start, size, 0), 0, "%s", strerror(ret));
56*11be35a1SLionel Sambuc 
57*11be35a1SLionel Sambuc #define h_free(start, size) \
58*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ_MSG(ret = extent_free(ex, \
59*11be35a1SLionel Sambuc 	    start, size, 0), 0, "%s", strerror(ret));
60*11be35a1SLionel Sambuc 
61*11be35a1SLionel Sambuc static void
h_alloc_subregion(u_long substart,u_long subend,u_long size,u_long alignment,u_long boundary,int expret,u_long expres)62*11be35a1SLionel Sambuc h_alloc_subregion(u_long substart, u_long subend, u_long size,
63*11be35a1SLionel Sambuc     u_long alignment, u_long boundary, int expret, u_long expres)
64*11be35a1SLionel Sambuc {
65*11be35a1SLionel Sambuc 	u_long result;
66*11be35a1SLionel Sambuc 
67*11be35a1SLionel Sambuc #define FAIL(fmt, ...) \
68*11be35a1SLionel Sambuc 	atf_tc_fail("extent_alloc_subregion1(ex, %#lx, %#lx, %#lx, %#lx, 0, " \
69*11be35a1SLionel Sambuc 	    "%#lx, 0, &result): " fmt, substart, subend, size, alignment, \
70*11be35a1SLionel Sambuc 	    boundary, ##__VA_ARGS__)
71*11be35a1SLionel Sambuc 
72*11be35a1SLionel Sambuc 	ret = extent_alloc_subregion1(ex, substart, subend, size,
73*11be35a1SLionel Sambuc 	    alignment, 0, boundary, 0, &result);
74*11be35a1SLionel Sambuc 
75*11be35a1SLionel Sambuc 	if (ret != expret)
76*11be35a1SLionel Sambuc 		FAIL("%s", strerror(errno));
77*11be35a1SLionel Sambuc 
78*11be35a1SLionel Sambuc 	if (expret == 0 && result != expres)
79*11be35a1SLionel Sambuc 		FAIL("result should be: %#lx, got: %#lx", expres, result);
80*11be35a1SLionel Sambuc #undef FAIL
81*11be35a1SLionel Sambuc }
82*11be35a1SLionel Sambuc 
83*11be35a1SLionel Sambuc static void
h_require(const char * name,u_long start,u_long end,int flags,const char * exp)84*11be35a1SLionel Sambuc h_require(const char *name, u_long start,
85*11be35a1SLionel Sambuc 	u_long end, int flags, const char *exp)
86*11be35a1SLionel Sambuc {
87*11be35a1SLionel Sambuc 	char buf[4096];
88*11be35a1SLionel Sambuc 	struct extent_region *rp;
89*11be35a1SLionel Sambuc 	int n = 0;
90*11be35a1SLionel Sambuc 
91*11be35a1SLionel Sambuc 	ATF_REQUIRE_STREQ_MSG(ex->ex_name, name,
92*11be35a1SLionel Sambuc 	    "expected: \"%s\", got: \"%s\"", name, ex->ex_name);
93*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ_MSG(ex->ex_start, start,
94*11be35a1SLionel Sambuc 	    "expected: %#lx, got: %#lx", start, ex->ex_start);
95*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ_MSG(ex->ex_end, end,
96*11be35a1SLionel Sambuc 	    "expected: %#lx, got: %#lx", end, ex->ex_end);
97*11be35a1SLionel Sambuc 	ATF_REQUIRE_EQ_MSG(ex->ex_flags, flags,
98*11be35a1SLionel Sambuc 	    "expected: %#x, got: %#x", flags, ex->ex_flags);
99*11be35a1SLionel Sambuc 
100*11be35a1SLionel Sambuc 	(void)memset(buf, 0, sizeof(buf));
101*11be35a1SLionel Sambuc 	LIST_FOREACH(rp, &ex->ex_regions, er_link)
102*11be35a1SLionel Sambuc 		n += snprintf(buf + n, sizeof(buf) - n,
103*11be35a1SLionel Sambuc 		    "0x%lx - 0x%lx\n", rp->er_start, rp->er_end);
104*11be35a1SLionel Sambuc 
105*11be35a1SLionel Sambuc 	if (strcmp(buf, exp) == 0)
106*11be35a1SLionel Sambuc 		return;
107*11be35a1SLionel Sambuc 
108*11be35a1SLionel Sambuc 	printf("Incorrect extent map\n");
109*11be35a1SLionel Sambuc 	printf("Expected:\n%s\n", exp);
110*11be35a1SLionel Sambuc 	printf("Got:\n%s\n", buf);
111*11be35a1SLionel Sambuc 	atf_tc_fail("incorrect extent map");
112*11be35a1SLionel Sambuc }
113*11be35a1SLionel Sambuc 
114*11be35a1SLionel Sambuc ATF_TC(coalesce);
ATF_TC_HEAD(coalesce,tc)115*11be35a1SLionel Sambuc ATF_TC_HEAD(coalesce, tc)
116*11be35a1SLionel Sambuc {
117*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Checks coalescing of regions");
118*11be35a1SLionel Sambuc }
ATF_TC_BODY(coalesce,tc)119*11be35a1SLionel Sambuc ATF_TC_BODY(coalesce, tc)
120*11be35a1SLionel Sambuc {
121*11be35a1SLionel Sambuc 	h_create("test1", 0, 0x4f, 0);
122*11be35a1SLionel Sambuc 
123*11be35a1SLionel Sambuc 	h_alloc_region(0x00, 0x10);
124*11be35a1SLionel Sambuc 	h_alloc_region(0x20, 0x10);
125*11be35a1SLionel Sambuc 	h_alloc_region(0x40, 0x10);
126*11be35a1SLionel Sambuc 	h_alloc_region(0x10, 0x10);
127*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 0x4f, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x30);
128*11be35a1SLionel Sambuc 
129*11be35a1SLionel Sambuc 	h_require("test1", 0x00, 0x4f, 0x00,
130*11be35a1SLionel Sambuc 	    "0x0 - 0x4f\n");
131*11be35a1SLionel Sambuc 
132*11be35a1SLionel Sambuc 	extent_destroy(ex);
133*11be35a1SLionel Sambuc }
134*11be35a1SLionel Sambuc 
135*11be35a1SLionel Sambuc ATF_TC(subregion1);
ATF_TC_HEAD(subregion1,tc)136*11be35a1SLionel Sambuc ATF_TC_HEAD(subregion1, tc)
137*11be35a1SLionel Sambuc {
138*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
139*11be35a1SLionel Sambuc 	    "Checks that subregions work (PR kern/7539)");
140*11be35a1SLionel Sambuc }
ATF_TC_BODY(subregion1,tc)141*11be35a1SLionel Sambuc ATF_TC_BODY(subregion1, tc)
142*11be35a1SLionel Sambuc {
143*11be35a1SLionel Sambuc 	h_create("test2", 0, 0x2f, EX_NOCOALESCE);
144*11be35a1SLionel Sambuc 
145*11be35a1SLionel Sambuc 	h_alloc_region(0x00, 0x10);
146*11be35a1SLionel Sambuc 	h_alloc_subregion(0x20, 0x30, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
147*11be35a1SLionel Sambuc 
148*11be35a1SLionel Sambuc 	h_require("test2", 0x00, 0x2f, 0x2,
149*11be35a1SLionel Sambuc 	    "0x0 - 0xf\n"
150*11be35a1SLionel Sambuc 	    "0x20 - 0x2f\n");
151*11be35a1SLionel Sambuc 
152*11be35a1SLionel Sambuc 	extent_destroy(ex);
153*11be35a1SLionel Sambuc }
154*11be35a1SLionel Sambuc 
155*11be35a1SLionel Sambuc ATF_TC(subregion2);
ATF_TC_HEAD(subregion2,tc)156*11be35a1SLionel Sambuc ATF_TC_HEAD(subregion2, tc)
157*11be35a1SLionel Sambuc {
158*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
159*11be35a1SLionel Sambuc 	    "Checks that subregion allocations don't overlap with existing "
160*11be35a1SLionel Sambuc 	    "ones (fixed in 1.25)");
161*11be35a1SLionel Sambuc }
ATF_TC_BODY(subregion2,tc)162*11be35a1SLionel Sambuc ATF_TC_BODY(subregion2, tc)
163*11be35a1SLionel Sambuc {
164*11be35a1SLionel Sambuc 	h_create("test3", 0, 0x3f, EX_NOCOALESCE);
165*11be35a1SLionel Sambuc 
166*11be35a1SLionel Sambuc 	h_alloc_region(0x00, 0x20);
167*11be35a1SLionel Sambuc 	h_alloc_region(0x30, 0x10);
168*11be35a1SLionel Sambuc 	h_alloc_subregion(0x10, 0x3f, 0x10,
169*11be35a1SLionel Sambuc 	    EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
170*11be35a1SLionel Sambuc 
171*11be35a1SLionel Sambuc 	h_require("test3", 0x00, 0x3f, 0x2,
172*11be35a1SLionel Sambuc 	    "0x0 - 0x1f\n"
173*11be35a1SLionel Sambuc 	    "0x20 - 0x2f\n"
174*11be35a1SLionel Sambuc 	    "0x30 - 0x3f\n");
175*11be35a1SLionel Sambuc 
176*11be35a1SLionel Sambuc 	extent_destroy(ex);
177*11be35a1SLionel Sambuc }
178*11be35a1SLionel Sambuc 
179*11be35a1SLionel Sambuc ATF_TC(bound1);
ATF_TC_HEAD(bound1,tc)180*11be35a1SLionel Sambuc ATF_TC_HEAD(bound1, tc)
181*11be35a1SLionel Sambuc {
182*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
183*11be35a1SLionel Sambuc 	    "Checks for overflow in boundary check, before an allocated region "
184*11be35a1SLionel Sambuc 	    "(fixed in 1.32)");
185*11be35a1SLionel Sambuc }
ATF_TC_BODY(bound1,tc)186*11be35a1SLionel Sambuc ATF_TC_BODY(bound1, tc)
187*11be35a1SLionel Sambuc {
188*11be35a1SLionel Sambuc 	h_create("test4", 0xf0000000, 0xffffffff, 0);
189*11be35a1SLionel Sambuc 
190*11be35a1SLionel Sambuc 	h_alloc_region(0xf1000000, 0x1);
191*11be35a1SLionel Sambuc 	h_alloc_subregion(0xf0000000, 0xffffffff, 0x1,
192*11be35a1SLionel Sambuc 	    EX_NOALIGN, 0x20000000, 0, 0xf0000000);
193*11be35a1SLionel Sambuc 
194*11be35a1SLionel Sambuc 	h_require("test4", 0xf0000000, 0xffffffff, 0x0,
195*11be35a1SLionel Sambuc 	    "0xf0000000 - 0xf0000000\n"
196*11be35a1SLionel Sambuc 	    "0xf1000000 - 0xf1000000\n");
197*11be35a1SLionel Sambuc 
198*11be35a1SLionel Sambuc 	extent_destroy(ex);
199*11be35a1SLionel Sambuc }
200*11be35a1SLionel Sambuc 
201*11be35a1SLionel Sambuc ATF_TC(bound2);
ATF_TC_HEAD(bound2,tc)202*11be35a1SLionel Sambuc ATF_TC_HEAD(bound2, tc)
203*11be35a1SLionel Sambuc {
204*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
205*11be35a1SLionel Sambuc 	    "Checks for overflow in boundary checks, before the subregion end "
206*11be35a1SLionel Sambuc 	    "(fixed in 1.32)");
207*11be35a1SLionel Sambuc }
ATF_TC_BODY(bound2,tc)208*11be35a1SLionel Sambuc ATF_TC_BODY(bound2, tc)
209*11be35a1SLionel Sambuc {
210*11be35a1SLionel Sambuc 	h_create("test5", 0xf0000000, 0xffffffff, 0);
211*11be35a1SLionel Sambuc 
212*11be35a1SLionel Sambuc 	h_alloc_subregion(0xf0000000, 0xffffffff, 0x1,
213*11be35a1SLionel Sambuc 	    EX_NOALIGN, 0x20000000, 0, 0xf0000000);
214*11be35a1SLionel Sambuc 
215*11be35a1SLionel Sambuc 	h_require("test5", 0xf0000000, 0xffffffff, 0x0,
216*11be35a1SLionel Sambuc 	    "0xf0000000 - 0xf0000000\n");
217*11be35a1SLionel Sambuc 
218*11be35a1SLionel Sambuc 	extent_destroy(ex);
219*11be35a1SLionel Sambuc }
220*11be35a1SLionel Sambuc 
221*11be35a1SLionel Sambuc ATF_TC(bound3);
ATF_TC_HEAD(bound3,tc)222*11be35a1SLionel Sambuc ATF_TC_HEAD(bound3, tc)
223*11be35a1SLionel Sambuc {
224*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
225*11be35a1SLionel Sambuc 	    "Checks allocation beyond last boundary line: last two "
226*11be35a1SLionel Sambuc 	    "allocations should succeed without boundary \"fixups\"");
227*11be35a1SLionel Sambuc }
ATF_TC_BODY(bound3,tc)228*11be35a1SLionel Sambuc ATF_TC_BODY(bound3, tc)
229*11be35a1SLionel Sambuc {
230*11be35a1SLionel Sambuc 	h_create("test6", 0, 11, 0);
231*11be35a1SLionel Sambuc 
232*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 11, 8, EX_NOALIGN, 8, 0, 0);
233*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 11, 2, EX_NOALIGN, 8, 0, 0x8);
234*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 11, 2, EX_NOALIGN, 8, 0, 0xa);
235*11be35a1SLionel Sambuc 
236*11be35a1SLionel Sambuc 	h_require("test6", 0x0, 0xb, 0x0, "0x0 - 0xb\n");
237*11be35a1SLionel Sambuc 
238*11be35a1SLionel Sambuc 	extent_destroy(ex);
239*11be35a1SLionel Sambuc }
240*11be35a1SLionel Sambuc 
241*11be35a1SLionel Sambuc ATF_TC(bound4);
ATF_TC_HEAD(bound4,tc)242*11be35a1SLionel Sambuc ATF_TC_HEAD(bound4, tc)
243*11be35a1SLionel Sambuc {
244*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
245*11be35a1SLionel Sambuc 	    "Checks allocation beyond last boundary line: last allocation "
246*11be35a1SLionel Sambuc 	    "should be bumped to the next boundary and exactly fit the "
247*11be35a1SLionel Sambuc 	    "remaining space");
248*11be35a1SLionel Sambuc }
ATF_TC_BODY(bound4,tc)249*11be35a1SLionel Sambuc ATF_TC_BODY(bound4, tc)
250*11be35a1SLionel Sambuc {
251*11be35a1SLionel Sambuc 	h_create("test7", 0, 11, 0);
252*11be35a1SLionel Sambuc 
253*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 11, 7, EX_NOALIGN, 8, 0, 0);
254*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 11, 4, EX_NOALIGN, 8, 0, 8);
255*11be35a1SLionel Sambuc 
256*11be35a1SLionel Sambuc 	h_require("test7", 0x0, 0xb, 0x0,
257*11be35a1SLionel Sambuc 	    "0x0 - 0x6\n"
258*11be35a1SLionel Sambuc 	    "0x8 - 0xb\n");
259*11be35a1SLionel Sambuc 
260*11be35a1SLionel Sambuc 	extent_destroy(ex);
261*11be35a1SLionel Sambuc }
262*11be35a1SLionel Sambuc 
263*11be35a1SLionel Sambuc ATF_TC(subregion3);
ATF_TC_HEAD(subregion3,tc)264*11be35a1SLionel Sambuc ATF_TC_HEAD(subregion3, tc)
265*11be35a1SLionel Sambuc {
266*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
267*11be35a1SLionel Sambuc 	    "Checks that we don't allocate a region pasts the end of "
268*11be35a1SLionel Sambuc 	    "subregion (i.e., the second alloc_subregion should fail). "
269*11be35a1SLionel Sambuc 	    "subr_extent.c prior to rev. 1.43 allocated region starting "
270*11be35a1SLionel Sambuc 	    "from 0x10");
271*11be35a1SLionel Sambuc }
ATF_TC_BODY(subregion3,tc)272*11be35a1SLionel Sambuc ATF_TC_BODY(subregion3, tc)
273*11be35a1SLionel Sambuc {
274*11be35a1SLionel Sambuc 	h_create("test8", 0, 0x4f, EX_NOCOALESCE);
275*11be35a1SLionel Sambuc 
276*11be35a1SLionel Sambuc 	h_alloc_region(0x30, 0x10);
277*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 0xf, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0);
278*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 0xf, 0x10, EX_NOALIGN, EX_NOBOUNDARY, EAGAIN, 0);
279*11be35a1SLionel Sambuc 
280*11be35a1SLionel Sambuc 	h_require("test8", 0x0, 0x4f, 0x2,
281*11be35a1SLionel Sambuc 	    "0x0 - 0xf\n"
282*11be35a1SLionel Sambuc 	    "0x30 - 0x3f\n");
283*11be35a1SLionel Sambuc 
284*11be35a1SLionel Sambuc 	extent_destroy(ex);
285*11be35a1SLionel Sambuc }
286*11be35a1SLionel Sambuc 
287*11be35a1SLionel Sambuc ATF_TC(bound5);
ATF_TC_HEAD(bound5,tc)288*11be35a1SLionel Sambuc ATF_TC_HEAD(bound5, tc)
289*11be35a1SLionel Sambuc {
290*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
291*11be35a1SLionel Sambuc 	    "When allocating a region with a boundary constraint, checks "
292*11be35a1SLionel Sambuc 	    "proper detection of overflaps once the candidate region has "
293*11be35a1SLionel Sambuc 	    "been aligned. subr_extent.c prior 1.45 could corrupt the extent "
294*11be35a1SLionel Sambuc 	    "map in this situation");
295*11be35a1SLionel Sambuc }
ATF_TC_BODY(bound5,tc)296*11be35a1SLionel Sambuc ATF_TC_BODY(bound5, tc)
297*11be35a1SLionel Sambuc {
298*11be35a1SLionel Sambuc 	h_create("test9", 0, 0x4f, 0);
299*11be35a1SLionel Sambuc 
300*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 0x10, 4, EX_NOALIGN, 0, 0, 0);
301*11be35a1SLionel Sambuc 	h_alloc_subregion(0xd, 0x20, 2, EX_NOALIGN, 0, 0, 0xd);
302*11be35a1SLionel Sambuc 	h_alloc_subregion(0, 0x4f, 8, EX_NOALIGN, 8, 0, 0x10);
303*11be35a1SLionel Sambuc 
304*11be35a1SLionel Sambuc 	h_require("test9", 0x0, 0x4f, 0x0,
305*11be35a1SLionel Sambuc 	    "0x0 - 0x3\n"
306*11be35a1SLionel Sambuc 	    "0xd - 0xe\n"
307*11be35a1SLionel Sambuc 	    "0x10 - 0x17\n");
308*11be35a1SLionel Sambuc 
309*11be35a1SLionel Sambuc 	extent_destroy(ex);
310*11be35a1SLionel Sambuc }
311*11be35a1SLionel Sambuc 
312*11be35a1SLionel Sambuc ATF_TC(free);
ATF_TC_HEAD(free,tc)313*11be35a1SLionel Sambuc ATF_TC_HEAD(free, tc)
314*11be35a1SLionel Sambuc {
315*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Checks extent_free()");
316*11be35a1SLionel Sambuc }
ATF_TC_BODY(free,tc)317*11be35a1SLionel Sambuc ATF_TC_BODY(free, tc)
318*11be35a1SLionel Sambuc {
319*11be35a1SLionel Sambuc 	h_create("test10", 0xc0002000, 0xffffe000, EX_BOUNDZERO);
320*11be35a1SLionel Sambuc 
321*11be35a1SLionel Sambuc 	h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000,
322*11be35a1SLionel Sambuc 	    0x10000, 0x10000, 0, 0xc0010000);
323*11be35a1SLionel Sambuc 	h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000,
324*11be35a1SLionel Sambuc 	    0x10000, 0x10000, 0, 0xc0020000);
325*11be35a1SLionel Sambuc 
326*11be35a1SLionel Sambuc 	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
327*11be35a1SLionel Sambuc 	    "0xc0010000 - 0xc0011fff\n"
328*11be35a1SLionel Sambuc 	    "0xc0020000 - 0xc0021fff\n");
329*11be35a1SLionel Sambuc 
330*11be35a1SLionel Sambuc 	h_free(0xc0020000, 0x2000);
331*11be35a1SLionel Sambuc 	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
332*11be35a1SLionel Sambuc 	    "0xc0010000 - 0xc0011fff\n");
333*11be35a1SLionel Sambuc 
334*11be35a1SLionel Sambuc 	h_alloc_subregion(0xc0002000, 0xffffe000, 0x10000,
335*11be35a1SLionel Sambuc 	    0x10000, 0x10000, 0, 0xc0022000);
336*11be35a1SLionel Sambuc 
337*11be35a1SLionel Sambuc 	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
338*11be35a1SLionel Sambuc 	    "0xc0010000 - 0xc0011fff\n"
339*11be35a1SLionel Sambuc 	    "0xc0022000 - 0xc0031fff\n");
340*11be35a1SLionel Sambuc 
341*11be35a1SLionel Sambuc 	extent_destroy(ex);
342*11be35a1SLionel Sambuc }
343*11be35a1SLionel Sambuc 
344*11be35a1SLionel Sambuc ATF_TC(subregion4);
ATF_TC_HEAD(subregion4,tc)345*11be35a1SLionel Sambuc ATF_TC_HEAD(subregion4, tc)
346*11be35a1SLionel Sambuc {
347*11be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr",
348*11be35a1SLionel Sambuc 	    "Checks for off-by-one bug which would cause a region at the end "
349*11be35a1SLionel Sambuc 	    "of the extent to be allocated multiple times (fixed in 1.51)");
350*11be35a1SLionel Sambuc }
ATF_TC_BODY(subregion4,tc)351*11be35a1SLionel Sambuc ATF_TC_BODY(subregion4, tc)
352*11be35a1SLionel Sambuc {
353*11be35a1SLionel Sambuc 	h_create("test11", 0x10, 0x20, EX_NOCOALESCE);
354*11be35a1SLionel Sambuc 
355*11be35a1SLionel Sambuc 	h_alloc_subregion(0x10, 0x13, 0x4, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x10);
356*11be35a1SLionel Sambuc 	h_alloc_subregion(0x1e, 0x1f, 0x2, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x1e);
357*11be35a1SLionel Sambuc 	h_alloc_subregion(0x20, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
358*11be35a1SLionel Sambuc 	h_alloc_subregion(0x20, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, EAGAIN, 0);
359*11be35a1SLionel Sambuc 	h_alloc_subregion(0x10, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x14);
360*11be35a1SLionel Sambuc 
361*11be35a1SLionel Sambuc 	h_require("test11", 0x10, 0x20, 0x2,
362*11be35a1SLionel Sambuc 	    "0x10 - 0x13\n"
363*11be35a1SLionel Sambuc 	    "0x14 - 0x14\n"
364*11be35a1SLionel Sambuc 	    "0x1e - 0x1f\n"
365*11be35a1SLionel Sambuc 	    "0x20 - 0x20\n");
366*11be35a1SLionel Sambuc 
367*11be35a1SLionel Sambuc 	extent_destroy(ex);
368*11be35a1SLionel Sambuc }
369*11be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)370*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
371*11be35a1SLionel Sambuc {
372*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, coalesce);
373*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, subregion1);
374*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, subregion2);
375*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, bound1);
376*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, bound2);
377*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, bound3);
378*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, bound4);
379*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, subregion3);
380*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, bound5);
381*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, free);
382*11be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, subregion4);
383*11be35a1SLionel Sambuc 
384*11be35a1SLionel Sambuc 	return atf_no_error();
385*11be35a1SLionel Sambuc }
386