1*63d1fd59SEnji Cooper /* $NetBSD: t_extent.c,v 1.5 2017/01/13 21:30:41 christos Exp $ */
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2008 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
857718be8SEnji Cooper  * modification, are permitted provided that the following conditions
957718be8SEnji Cooper  * are met:
1057718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1157718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1257718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1357718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1457718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1557718be8SEnji Cooper  *
1657718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1757718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1857718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1957718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2057718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2157718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2257718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2357718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2457718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2557718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2657718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
2757718be8SEnji Cooper  */
2857718be8SEnji Cooper 
2957718be8SEnji Cooper #include <sys/cdefs.h>
3057718be8SEnji Cooper __COPYRIGHT("@(#) Copyright (c) 2008\
3157718be8SEnji Cooper  The NetBSD Foundation, inc. All rights reserved.");
32*63d1fd59SEnji Cooper __RCSID("$NetBSD: t_extent.c,v 1.5 2017/01/13 21:30:41 christos Exp $");
3357718be8SEnji Cooper 
3457718be8SEnji Cooper #include <sys/types.h>
3557718be8SEnji Cooper #include <sys/queue.h>
3657718be8SEnji Cooper #include <sys/extent.h>
3757718be8SEnji Cooper 
3857718be8SEnji Cooper #include <stdio.h>
3957718be8SEnji Cooper #include <stdlib.h>
4057718be8SEnji Cooper #include <string.h>
4157718be8SEnji Cooper 
4257718be8SEnji Cooper #include <atf-c.h>
4357718be8SEnji Cooper 
44*63d1fd59SEnji Cooper #include "h_macros.h"
4557718be8SEnji Cooper 
4657718be8SEnji Cooper static int ret;
4757718be8SEnji Cooper static struct extent *ex;
4857718be8SEnji Cooper 
4957718be8SEnji Cooper #define h_create(name, start, end, flags) \
5057718be8SEnji Cooper 	ATF_REQUIRE((ex = extent_create(name, \
5157718be8SEnji Cooper 	    start, end, 0, 0, flags)) != NULL);
5257718be8SEnji Cooper 
5357718be8SEnji Cooper #define h_alloc_region(start, size) \
5457718be8SEnji Cooper 	ATF_REQUIRE_EQ_MSG(ret = extent_alloc_region(ex, \
5557718be8SEnji Cooper 	    start, size, 0), 0, "%s", strerror(ret));
5657718be8SEnji Cooper 
5757718be8SEnji Cooper #define h_free(start, size) \
5857718be8SEnji Cooper 	ATF_REQUIRE_EQ_MSG(ret = extent_free(ex, \
5957718be8SEnji Cooper 	    start, size, 0), 0, "%s", strerror(ret));
6057718be8SEnji Cooper 
6157718be8SEnji Cooper 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)6257718be8SEnji Cooper h_alloc_subregion(u_long substart, u_long subend, u_long size,
6357718be8SEnji Cooper     u_long alignment, u_long boundary, int expret, u_long expres)
6457718be8SEnji Cooper {
6557718be8SEnji Cooper 	u_long result;
6657718be8SEnji Cooper 
6757718be8SEnji Cooper #define FAIL(fmt, ...) \
6857718be8SEnji Cooper 	atf_tc_fail("extent_alloc_subregion1(ex, %#lx, %#lx, %#lx, %#lx, 0, " \
6957718be8SEnji Cooper 	    "%#lx, 0, &result): " fmt, substart, subend, size, alignment, \
7057718be8SEnji Cooper 	    boundary, ##__VA_ARGS__)
7157718be8SEnji Cooper 
7257718be8SEnji Cooper 	ret = extent_alloc_subregion1(ex, substart, subend, size,
7357718be8SEnji Cooper 	    alignment, 0, boundary, 0, &result);
7457718be8SEnji Cooper 
7557718be8SEnji Cooper 	if (ret != expret)
7657718be8SEnji Cooper 		FAIL("%s", strerror(errno));
7757718be8SEnji Cooper 
7857718be8SEnji Cooper 	if (expret == 0 && result != expres)
7957718be8SEnji Cooper 		FAIL("result should be: %#lx, got: %#lx", expres, result);
8057718be8SEnji Cooper #undef FAIL
8157718be8SEnji Cooper }
8257718be8SEnji Cooper 
8357718be8SEnji Cooper static void
h_require(const char * name,u_long start,u_long end,int flags,const char * exp)8457718be8SEnji Cooper h_require(const char *name, u_long start,
8557718be8SEnji Cooper 	u_long end, int flags, const char *exp)
8657718be8SEnji Cooper {
8757718be8SEnji Cooper 	char buf[4096];
8857718be8SEnji Cooper 	struct extent_region *rp;
8957718be8SEnji Cooper 	int n = 0;
9057718be8SEnji Cooper 
9157718be8SEnji Cooper 	ATF_REQUIRE_STREQ_MSG(ex->ex_name, name,
9257718be8SEnji Cooper 	    "expected: \"%s\", got: \"%s\"", name, ex->ex_name);
9357718be8SEnji Cooper 	ATF_REQUIRE_EQ_MSG(ex->ex_start, start,
9457718be8SEnji Cooper 	    "expected: %#lx, got: %#lx", start, ex->ex_start);
9557718be8SEnji Cooper 	ATF_REQUIRE_EQ_MSG(ex->ex_end, end,
9657718be8SEnji Cooper 	    "expected: %#lx, got: %#lx", end, ex->ex_end);
9757718be8SEnji Cooper 	ATF_REQUIRE_EQ_MSG(ex->ex_flags, flags,
9857718be8SEnji Cooper 	    "expected: %#x, got: %#x", flags, ex->ex_flags);
9957718be8SEnji Cooper 
10057718be8SEnji Cooper 	(void)memset(buf, 0, sizeof(buf));
10157718be8SEnji Cooper 	LIST_FOREACH(rp, &ex->ex_regions, er_link)
10257718be8SEnji Cooper 		n += snprintf(buf + n, sizeof(buf) - n,
10357718be8SEnji Cooper 		    "0x%lx - 0x%lx\n", rp->er_start, rp->er_end);
10457718be8SEnji Cooper 
10557718be8SEnji Cooper 	if (strcmp(buf, exp) == 0)
10657718be8SEnji Cooper 		return;
10757718be8SEnji Cooper 
10857718be8SEnji Cooper 	printf("Incorrect extent map\n");
10957718be8SEnji Cooper 	printf("Expected:\n%s\n", exp);
11057718be8SEnji Cooper 	printf("Got:\n%s\n", buf);
11157718be8SEnji Cooper 	atf_tc_fail("incorrect extent map");
11257718be8SEnji Cooper }
11357718be8SEnji Cooper 
11457718be8SEnji Cooper ATF_TC(coalesce);
ATF_TC_HEAD(coalesce,tc)11557718be8SEnji Cooper ATF_TC_HEAD(coalesce, tc)
11657718be8SEnji Cooper {
11757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Checks coalescing of regions");
11857718be8SEnji Cooper }
ATF_TC_BODY(coalesce,tc)11957718be8SEnji Cooper ATF_TC_BODY(coalesce, tc)
12057718be8SEnji Cooper {
12157718be8SEnji Cooper 	h_create("test1", 0, 0x4f, 0);
12257718be8SEnji Cooper 
12357718be8SEnji Cooper 	h_alloc_region(0x00, 0x10);
12457718be8SEnji Cooper 	h_alloc_region(0x20, 0x10);
12557718be8SEnji Cooper 	h_alloc_region(0x40, 0x10);
12657718be8SEnji Cooper 	h_alloc_region(0x10, 0x10);
12757718be8SEnji Cooper 	h_alloc_subregion(0, 0x4f, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x30);
12857718be8SEnji Cooper 
12957718be8SEnji Cooper 	h_require("test1", 0x00, 0x4f, 0x00,
13057718be8SEnji Cooper 	    "0x0 - 0x4f\n");
13157718be8SEnji Cooper 
13257718be8SEnji Cooper 	extent_destroy(ex);
13357718be8SEnji Cooper }
13457718be8SEnji Cooper 
13557718be8SEnji Cooper ATF_TC(subregion1);
ATF_TC_HEAD(subregion1,tc)13657718be8SEnji Cooper ATF_TC_HEAD(subregion1, tc)
13757718be8SEnji Cooper {
13857718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
13957718be8SEnji Cooper 	    "Checks that subregions work (PR kern/7539)");
14057718be8SEnji Cooper }
ATF_TC_BODY(subregion1,tc)14157718be8SEnji Cooper ATF_TC_BODY(subregion1, tc)
14257718be8SEnji Cooper {
14357718be8SEnji Cooper 	h_create("test2", 0, 0x2f, EX_NOCOALESCE);
14457718be8SEnji Cooper 
14557718be8SEnji Cooper 	h_alloc_region(0x00, 0x10);
14657718be8SEnji Cooper 	h_alloc_subregion(0x20, 0x30, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
14757718be8SEnji Cooper 
14857718be8SEnji Cooper 	h_require("test2", 0x00, 0x2f, 0x2,
14957718be8SEnji Cooper 	    "0x0 - 0xf\n"
15057718be8SEnji Cooper 	    "0x20 - 0x2f\n");
15157718be8SEnji Cooper 
15257718be8SEnji Cooper 	extent_destroy(ex);
15357718be8SEnji Cooper }
15457718be8SEnji Cooper 
15557718be8SEnji Cooper ATF_TC(subregion2);
ATF_TC_HEAD(subregion2,tc)15657718be8SEnji Cooper ATF_TC_HEAD(subregion2, tc)
15757718be8SEnji Cooper {
15857718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
15957718be8SEnji Cooper 	    "Checks that subregion allocations don't overlap with existing "
16057718be8SEnji Cooper 	    "ones (fixed in 1.25)");
16157718be8SEnji Cooper }
ATF_TC_BODY(subregion2,tc)16257718be8SEnji Cooper ATF_TC_BODY(subregion2, tc)
16357718be8SEnji Cooper {
16457718be8SEnji Cooper 	h_create("test3", 0, 0x3f, EX_NOCOALESCE);
16557718be8SEnji Cooper 
16657718be8SEnji Cooper 	h_alloc_region(0x00, 0x20);
16757718be8SEnji Cooper 	h_alloc_region(0x30, 0x10);
16857718be8SEnji Cooper 	h_alloc_subregion(0x10, 0x3f, 0x10,
16957718be8SEnji Cooper 	    EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
17057718be8SEnji Cooper 
17157718be8SEnji Cooper 	h_require("test3", 0x00, 0x3f, 0x2,
17257718be8SEnji Cooper 	    "0x0 - 0x1f\n"
17357718be8SEnji Cooper 	    "0x20 - 0x2f\n"
17457718be8SEnji Cooper 	    "0x30 - 0x3f\n");
17557718be8SEnji Cooper 
17657718be8SEnji Cooper 	extent_destroy(ex);
17757718be8SEnji Cooper }
17857718be8SEnji Cooper 
17957718be8SEnji Cooper ATF_TC(bound1);
ATF_TC_HEAD(bound1,tc)18057718be8SEnji Cooper ATF_TC_HEAD(bound1, tc)
18157718be8SEnji Cooper {
18257718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
18357718be8SEnji Cooper 	    "Checks for overflow in boundary check, before an allocated region "
18457718be8SEnji Cooper 	    "(fixed in 1.32)");
18557718be8SEnji Cooper }
ATF_TC_BODY(bound1,tc)18657718be8SEnji Cooper ATF_TC_BODY(bound1, tc)
18757718be8SEnji Cooper {
18857718be8SEnji Cooper 	h_create("test4", 0xf0000000, 0xffffffff, 0);
18957718be8SEnji Cooper 
19057718be8SEnji Cooper 	h_alloc_region(0xf1000000, 0x1);
19157718be8SEnji Cooper 	h_alloc_subregion(0xf0000000, 0xffffffff, 0x1,
19257718be8SEnji Cooper 	    EX_NOALIGN, 0x20000000, 0, 0xf0000000);
19357718be8SEnji Cooper 
19457718be8SEnji Cooper 	h_require("test4", 0xf0000000, 0xffffffff, 0x0,
19557718be8SEnji Cooper 	    "0xf0000000 - 0xf0000000\n"
19657718be8SEnji Cooper 	    "0xf1000000 - 0xf1000000\n");
19757718be8SEnji Cooper 
19857718be8SEnji Cooper 	extent_destroy(ex);
19957718be8SEnji Cooper }
20057718be8SEnji Cooper 
20157718be8SEnji Cooper ATF_TC(bound2);
ATF_TC_HEAD(bound2,tc)20257718be8SEnji Cooper ATF_TC_HEAD(bound2, tc)
20357718be8SEnji Cooper {
20457718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
20557718be8SEnji Cooper 	    "Checks for overflow in boundary checks, before the subregion end "
20657718be8SEnji Cooper 	    "(fixed in 1.32)");
20757718be8SEnji Cooper }
ATF_TC_BODY(bound2,tc)20857718be8SEnji Cooper ATF_TC_BODY(bound2, tc)
20957718be8SEnji Cooper {
21057718be8SEnji Cooper 	h_create("test5", 0xf0000000, 0xffffffff, 0);
21157718be8SEnji Cooper 
21257718be8SEnji Cooper 	h_alloc_subregion(0xf0000000, 0xffffffff, 0x1,
21357718be8SEnji Cooper 	    EX_NOALIGN, 0x20000000, 0, 0xf0000000);
21457718be8SEnji Cooper 
21557718be8SEnji Cooper 	h_require("test5", 0xf0000000, 0xffffffff, 0x0,
21657718be8SEnji Cooper 	    "0xf0000000 - 0xf0000000\n");
21757718be8SEnji Cooper 
21857718be8SEnji Cooper 	extent_destroy(ex);
21957718be8SEnji Cooper }
22057718be8SEnji Cooper 
22157718be8SEnji Cooper ATF_TC(bound3);
ATF_TC_HEAD(bound3,tc)22257718be8SEnji Cooper ATF_TC_HEAD(bound3, tc)
22357718be8SEnji Cooper {
22457718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
22557718be8SEnji Cooper 	    "Checks allocation beyond last boundary line: last two "
22657718be8SEnji Cooper 	    "allocations should succeed without boundary \"fixups\"");
22757718be8SEnji Cooper }
ATF_TC_BODY(bound3,tc)22857718be8SEnji Cooper ATF_TC_BODY(bound3, tc)
22957718be8SEnji Cooper {
23057718be8SEnji Cooper 	h_create("test6", 0, 11, 0);
23157718be8SEnji Cooper 
23257718be8SEnji Cooper 	h_alloc_subregion(0, 11, 8, EX_NOALIGN, 8, 0, 0);
23357718be8SEnji Cooper 	h_alloc_subregion(0, 11, 2, EX_NOALIGN, 8, 0, 0x8);
23457718be8SEnji Cooper 	h_alloc_subregion(0, 11, 2, EX_NOALIGN, 8, 0, 0xa);
23557718be8SEnji Cooper 
23657718be8SEnji Cooper 	h_require("test6", 0x0, 0xb, 0x0, "0x0 - 0xb\n");
23757718be8SEnji Cooper 
23857718be8SEnji Cooper 	extent_destroy(ex);
23957718be8SEnji Cooper }
24057718be8SEnji Cooper 
24157718be8SEnji Cooper ATF_TC(bound4);
ATF_TC_HEAD(bound4,tc)24257718be8SEnji Cooper ATF_TC_HEAD(bound4, tc)
24357718be8SEnji Cooper {
24457718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
24557718be8SEnji Cooper 	    "Checks allocation beyond last boundary line: last allocation "
24657718be8SEnji Cooper 	    "should be bumped to the next boundary and exactly fit the "
24757718be8SEnji Cooper 	    "remaining space");
24857718be8SEnji Cooper }
ATF_TC_BODY(bound4,tc)24957718be8SEnji Cooper ATF_TC_BODY(bound4, tc)
25057718be8SEnji Cooper {
25157718be8SEnji Cooper 	h_create("test7", 0, 11, 0);
25257718be8SEnji Cooper 
25357718be8SEnji Cooper 	h_alloc_subregion(0, 11, 7, EX_NOALIGN, 8, 0, 0);
25457718be8SEnji Cooper 	h_alloc_subregion(0, 11, 4, EX_NOALIGN, 8, 0, 8);
25557718be8SEnji Cooper 
25657718be8SEnji Cooper 	h_require("test7", 0x0, 0xb, 0x0,
25757718be8SEnji Cooper 	    "0x0 - 0x6\n"
25857718be8SEnji Cooper 	    "0x8 - 0xb\n");
25957718be8SEnji Cooper 
26057718be8SEnji Cooper 	extent_destroy(ex);
26157718be8SEnji Cooper }
26257718be8SEnji Cooper 
26357718be8SEnji Cooper ATF_TC(subregion3);
ATF_TC_HEAD(subregion3,tc)26457718be8SEnji Cooper ATF_TC_HEAD(subregion3, tc)
26557718be8SEnji Cooper {
26657718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
26757718be8SEnji Cooper 	    "Checks that we don't allocate a region pasts the end of "
26857718be8SEnji Cooper 	    "subregion (i.e., the second alloc_subregion should fail). "
26957718be8SEnji Cooper 	    "subr_extent.c prior to rev. 1.43 allocated region starting "
27057718be8SEnji Cooper 	    "from 0x10");
27157718be8SEnji Cooper }
ATF_TC_BODY(subregion3,tc)27257718be8SEnji Cooper ATF_TC_BODY(subregion3, tc)
27357718be8SEnji Cooper {
27457718be8SEnji Cooper 	h_create("test8", 0, 0x4f, EX_NOCOALESCE);
27557718be8SEnji Cooper 
27657718be8SEnji Cooper 	h_alloc_region(0x30, 0x10);
27757718be8SEnji Cooper 	h_alloc_subregion(0, 0xf, 0x10, EX_NOALIGN, EX_NOBOUNDARY, 0, 0);
27857718be8SEnji Cooper 	h_alloc_subregion(0, 0xf, 0x10, EX_NOALIGN, EX_NOBOUNDARY, EAGAIN, 0);
27957718be8SEnji Cooper 
28057718be8SEnji Cooper 	h_require("test8", 0x0, 0x4f, 0x2,
28157718be8SEnji Cooper 	    "0x0 - 0xf\n"
28257718be8SEnji Cooper 	    "0x30 - 0x3f\n");
28357718be8SEnji Cooper 
28457718be8SEnji Cooper 	extent_destroy(ex);
28557718be8SEnji Cooper }
28657718be8SEnji Cooper 
28757718be8SEnji Cooper ATF_TC(bound5);
ATF_TC_HEAD(bound5,tc)28857718be8SEnji Cooper ATF_TC_HEAD(bound5, tc)
28957718be8SEnji Cooper {
29057718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
29157718be8SEnji Cooper 	    "When allocating a region with a boundary constraint, checks "
29257718be8SEnji Cooper 	    "proper detection of overflaps once the candidate region has "
29357718be8SEnji Cooper 	    "been aligned. subr_extent.c prior 1.45 could corrupt the extent "
29457718be8SEnji Cooper 	    "map in this situation");
29557718be8SEnji Cooper }
ATF_TC_BODY(bound5,tc)29657718be8SEnji Cooper ATF_TC_BODY(bound5, tc)
29757718be8SEnji Cooper {
29857718be8SEnji Cooper 	h_create("test9", 0, 0x4f, 0);
29957718be8SEnji Cooper 
30057718be8SEnji Cooper 	h_alloc_subregion(0, 0x10, 4, EX_NOALIGN, 0, 0, 0);
30157718be8SEnji Cooper 	h_alloc_subregion(0xd, 0x20, 2, EX_NOALIGN, 0, 0, 0xd);
30257718be8SEnji Cooper 	h_alloc_subregion(0, 0x4f, 8, EX_NOALIGN, 8, 0, 0x10);
30357718be8SEnji Cooper 
30457718be8SEnji Cooper 	h_require("test9", 0x0, 0x4f, 0x0,
30557718be8SEnji Cooper 	    "0x0 - 0x3\n"
30657718be8SEnji Cooper 	    "0xd - 0xe\n"
30757718be8SEnji Cooper 	    "0x10 - 0x17\n");
30857718be8SEnji Cooper 
30957718be8SEnji Cooper 	extent_destroy(ex);
31057718be8SEnji Cooper }
31157718be8SEnji Cooper 
31257718be8SEnji Cooper ATF_TC(free);
ATF_TC_HEAD(free,tc)31357718be8SEnji Cooper ATF_TC_HEAD(free, tc)
31457718be8SEnji Cooper {
31557718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Checks extent_free()");
31657718be8SEnji Cooper }
ATF_TC_BODY(free,tc)31757718be8SEnji Cooper ATF_TC_BODY(free, tc)
31857718be8SEnji Cooper {
31957718be8SEnji Cooper 	h_create("test10", 0xc0002000, 0xffffe000, EX_BOUNDZERO);
32057718be8SEnji Cooper 
32157718be8SEnji Cooper 	h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000,
32257718be8SEnji Cooper 	    0x10000, 0x10000, 0, 0xc0010000);
32357718be8SEnji Cooper 	h_alloc_subregion(0xc0002000, 0xffffe000, 0x2000,
32457718be8SEnji Cooper 	    0x10000, 0x10000, 0, 0xc0020000);
32557718be8SEnji Cooper 
32657718be8SEnji Cooper 	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
32757718be8SEnji Cooper 	    "0xc0010000 - 0xc0011fff\n"
32857718be8SEnji Cooper 	    "0xc0020000 - 0xc0021fff\n");
32957718be8SEnji Cooper 
33057718be8SEnji Cooper 	h_free(0xc0020000, 0x2000);
33157718be8SEnji Cooper 	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
33257718be8SEnji Cooper 	    "0xc0010000 - 0xc0011fff\n");
33357718be8SEnji Cooper 
33457718be8SEnji Cooper 	h_alloc_subregion(0xc0002000, 0xffffe000, 0x10000,
33557718be8SEnji Cooper 	    0x10000, 0x10000, 0, 0xc0022000);
33657718be8SEnji Cooper 
33757718be8SEnji Cooper 	h_require("test10", 0xc0002000, 0xffffe000, 0x0,
33857718be8SEnji Cooper 	    "0xc0010000 - 0xc0011fff\n"
33957718be8SEnji Cooper 	    "0xc0022000 - 0xc0031fff\n");
34057718be8SEnji Cooper 
34157718be8SEnji Cooper 	extent_destroy(ex);
34257718be8SEnji Cooper }
34357718be8SEnji Cooper 
34457718be8SEnji Cooper ATF_TC(subregion4);
ATF_TC_HEAD(subregion4,tc)34557718be8SEnji Cooper ATF_TC_HEAD(subregion4, tc)
34657718be8SEnji Cooper {
34757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
34857718be8SEnji Cooper 	    "Checks for off-by-one bug which would cause a region at the end "
34957718be8SEnji Cooper 	    "of the extent to be allocated multiple times (fixed in 1.51)");
35057718be8SEnji Cooper }
ATF_TC_BODY(subregion4,tc)35157718be8SEnji Cooper ATF_TC_BODY(subregion4, tc)
35257718be8SEnji Cooper {
35357718be8SEnji Cooper 	h_create("test11", 0x10, 0x20, EX_NOCOALESCE);
35457718be8SEnji Cooper 
35557718be8SEnji Cooper 	h_alloc_subregion(0x10, 0x13, 0x4, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x10);
35657718be8SEnji Cooper 	h_alloc_subregion(0x1e, 0x1f, 0x2, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x1e);
35757718be8SEnji Cooper 	h_alloc_subregion(0x20, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x20);
35857718be8SEnji Cooper 	h_alloc_subregion(0x20, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, EAGAIN, 0);
35957718be8SEnji Cooper 	h_alloc_subregion(0x10, 0x20, 0x1, EX_NOALIGN, EX_NOBOUNDARY, 0, 0x14);
36057718be8SEnji Cooper 
36157718be8SEnji Cooper 	h_require("test11", 0x10, 0x20, 0x2,
36257718be8SEnji Cooper 	    "0x10 - 0x13\n"
36357718be8SEnji Cooper 	    "0x14 - 0x14\n"
36457718be8SEnji Cooper 	    "0x1e - 0x1f\n"
36557718be8SEnji Cooper 	    "0x20 - 0x20\n");
36657718be8SEnji Cooper 
36757718be8SEnji Cooper 	extent_destroy(ex);
36857718be8SEnji Cooper }
36957718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)37057718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
37157718be8SEnji Cooper {
37257718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, coalesce);
37357718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, subregion1);
37457718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, subregion2);
37557718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bound1);
37657718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bound2);
37757718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bound3);
37857718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bound4);
37957718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, subregion3);
38057718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, bound5);
38157718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, free);
38257718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, subregion4);
38357718be8SEnji Cooper 
38457718be8SEnji Cooper 	return atf_no_error();
38557718be8SEnji Cooper }
386