xref: /freebsd/contrib/netbsd-tests/sys/uvm/t_uvm_physseg.c (revision 1a36faad54665288ed4eb839d2a4699ae2ead45e)
1*63d1fd59SEnji Cooper /* $NetBSD: t_uvm_physseg.c,v 1.2 2016/12/22 08:15:20 cherry Exp $ */
2*63d1fd59SEnji Cooper 
3*63d1fd59SEnji Cooper /*-
4*63d1fd59SEnji Cooper  * Copyright (c) 2015, 2016 The NetBSD Foundation, Inc.
5*63d1fd59SEnji Cooper  * All rights reserved.
6*63d1fd59SEnji Cooper  *
7*63d1fd59SEnji Cooper  * This code is derived from software contributed to The NetBSD Foundation
8*63d1fd59SEnji Cooper  * by Santhosh N. Raju <santhosh.raju@gmail.com> and
9*63d1fd59SEnji Cooper  * by Cherry G. Mathew
10*63d1fd59SEnji Cooper  *
11*63d1fd59SEnji Cooper  * Redistribution and use in source and binary forms, with or without
12*63d1fd59SEnji Cooper  * modification, are permitted provided that the following conditions
13*63d1fd59SEnji Cooper  * are met:
14*63d1fd59SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
15*63d1fd59SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
16*63d1fd59SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
17*63d1fd59SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
18*63d1fd59SEnji Cooper  *    documentation and/or other materials provided with the distribution.
19*63d1fd59SEnji Cooper  *
20*63d1fd59SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21*63d1fd59SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22*63d1fd59SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23*63d1fd59SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24*63d1fd59SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25*63d1fd59SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26*63d1fd59SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27*63d1fd59SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28*63d1fd59SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29*63d1fd59SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30*63d1fd59SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
31*63d1fd59SEnji Cooper  */
32*63d1fd59SEnji Cooper 
33*63d1fd59SEnji Cooper #include <sys/cdefs.h>
34*63d1fd59SEnji Cooper __RCSID("$NetBSD: t_uvm_physseg.c,v 1.2 2016/12/22 08:15:20 cherry Exp $");
35*63d1fd59SEnji Cooper 
36*63d1fd59SEnji Cooper /*
37*63d1fd59SEnji Cooper  * If this line is commented out tests related to uvm_physseg_get_pmseg()
38*63d1fd59SEnji Cooper  * wont run.
39*63d1fd59SEnji Cooper  *
40*63d1fd59SEnji Cooper  * Have a look at machine/uvm_physseg.h for more details.
41*63d1fd59SEnji Cooper  */
42*63d1fd59SEnji Cooper #define __HAVE_PMAP_PHYSSEG
43*63d1fd59SEnji Cooper 
44*63d1fd59SEnji Cooper /*
45*63d1fd59SEnji Cooper  * This is a dummy struct used for testing purposes
46*63d1fd59SEnji Cooper  *
47*63d1fd59SEnji Cooper  * In reality this struct would exist in the MD part of the code residing in
48*63d1fd59SEnji Cooper  * machines/vmparam.h
49*63d1fd59SEnji Cooper  */
50*63d1fd59SEnji Cooper 
51*63d1fd59SEnji Cooper #ifdef __HAVE_PMAP_PHYSSEG
52*63d1fd59SEnji Cooper struct pmap_physseg {
53*63d1fd59SEnji Cooper 	int dummy_variable;		/* Dummy variable use for testing */
54*63d1fd59SEnji Cooper };
55*63d1fd59SEnji Cooper #endif
56*63d1fd59SEnji Cooper 
57*63d1fd59SEnji Cooper /* Testing API - assumes userland */
58*63d1fd59SEnji Cooper /* Provide Kernel API equivalents */
59*63d1fd59SEnji Cooper #include <assert.h>
60*63d1fd59SEnji Cooper #include <errno.h>
61*63d1fd59SEnji Cooper #include <stdbool.h>
62*63d1fd59SEnji Cooper #include <string.h> /* memset(3) et. al */
63*63d1fd59SEnji Cooper #include <stdio.h> /* printf(3) */
64*63d1fd59SEnji Cooper #include <stdlib.h> /* malloc(3) */
65*63d1fd59SEnji Cooper #include <stdarg.h>
66*63d1fd59SEnji Cooper #include <stddef.h>
67*63d1fd59SEnji Cooper 
68*63d1fd59SEnji Cooper #define	PRIxPADDR	"lx"
69*63d1fd59SEnji Cooper #define	PRIxPSIZE	"lx"
70*63d1fd59SEnji Cooper #define	PRIuPSIZE	"lu"
71*63d1fd59SEnji Cooper #define	PRIxVADDR	"lx"
72*63d1fd59SEnji Cooper #define	PRIxVSIZE	"lx"
73*63d1fd59SEnji Cooper #define	PRIuVSIZE	"lu"
74*63d1fd59SEnji Cooper 
75*63d1fd59SEnji Cooper #define UVM_HOTPLUG /* Enable hotplug with rbtree. */
76*63d1fd59SEnji Cooper #define PMAP_STEAL_MEMORY
77*63d1fd59SEnji Cooper #define DEBUG /* Enable debug functionality. */
78*63d1fd59SEnji Cooper 
79*63d1fd59SEnji Cooper typedef unsigned long vaddr_t;
80*63d1fd59SEnji Cooper typedef unsigned long paddr_t;
81*63d1fd59SEnji Cooper typedef unsigned long psize_t;
82*63d1fd59SEnji Cooper typedef unsigned long vsize_t;
83*63d1fd59SEnji Cooper 
84*63d1fd59SEnji Cooper #include <uvm/uvm_physseg.h>
85*63d1fd59SEnji Cooper #include <uvm/uvm_page.h>
86*63d1fd59SEnji Cooper 
87*63d1fd59SEnji Cooper #ifndef DIAGNOSTIC
88*63d1fd59SEnji Cooper #define	KASSERTMSG(e, msg, ...)	/* NOTHING */
89*63d1fd59SEnji Cooper #define	KASSERT(e)		/* NOTHING */
90*63d1fd59SEnji Cooper #else
91*63d1fd59SEnji Cooper #define	KASSERT(a)		assert(a)
92*63d1fd59SEnji Cooper #define KASSERTMSG(exp, ...)    printf(__VA_ARGS__); assert((exp))
93*63d1fd59SEnji Cooper #endif
94*63d1fd59SEnji Cooper 
95*63d1fd59SEnji Cooper #define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH
96*63d1fd59SEnji Cooper 
97*63d1fd59SEnji Cooper #define VM_NFREELIST            4
98*63d1fd59SEnji Cooper #define VM_FREELIST_DEFAULT     0
99*63d1fd59SEnji Cooper #define VM_FREELIST_FIRST16     3
100*63d1fd59SEnji Cooper #define VM_FREELIST_FIRST1G     2
101*63d1fd59SEnji Cooper #define VM_FREELIST_FIRST4G     1
102*63d1fd59SEnji Cooper 
103*63d1fd59SEnji Cooper /*
104*63d1fd59SEnji Cooper  * Used in tests when Array implementation is tested
105*63d1fd59SEnji Cooper  */
106*63d1fd59SEnji Cooper #if !defined(VM_PHYSSEG_MAX)
107*63d1fd59SEnji Cooper #define VM_PHYSSEG_MAX          1
108*63d1fd59SEnji Cooper #endif
109*63d1fd59SEnji Cooper 
110*63d1fd59SEnji Cooper #define PAGE_SHIFT              12
111*63d1fd59SEnji Cooper #define PAGE_SIZE               (1 << PAGE_SHIFT)
112*63d1fd59SEnji Cooper #define	PAGE_MASK	(PAGE_SIZE - 1)
113*63d1fd59SEnji Cooper #define atop(x)         (((paddr_t)(x)) >> PAGE_SHIFT)
114*63d1fd59SEnji Cooper #define ptoa(x)         (((paddr_t)(x)) << PAGE_SHIFT)
115*63d1fd59SEnji Cooper 
116*63d1fd59SEnji Cooper #define	mutex_enter(l)
117*63d1fd59SEnji Cooper #define	mutex_exit(l)
118*63d1fd59SEnji Cooper 
119*63d1fd59SEnji Cooper psize_t physmem;
120*63d1fd59SEnji Cooper 
121*63d1fd59SEnji Cooper struct uvmexp uvmexp;        /* decl */
122*63d1fd59SEnji Cooper 
123*63d1fd59SEnji Cooper /*
124*63d1fd59SEnji Cooper  * uvm structure borrowed from uvm.h
125*63d1fd59SEnji Cooper  *
126*63d1fd59SEnji Cooper  * Remember this is a dummy structure used within the ATF Tests and
127*63d1fd59SEnji Cooper  * uses only necessary fields from the original uvm struct.
128*63d1fd59SEnji Cooper  * See uvm/uvm.h for the full struct.
129*63d1fd59SEnji Cooper  */
130*63d1fd59SEnji Cooper 
131*63d1fd59SEnji Cooper struct uvm {
132*63d1fd59SEnji Cooper 	/* vm_page related parameters */
133*63d1fd59SEnji Cooper 
134*63d1fd59SEnji Cooper 	bool page_init_done;		/* TRUE if uvm_page_init() finished */
135*63d1fd59SEnji Cooper } uvm;
136*63d1fd59SEnji Cooper 
137*63d1fd59SEnji Cooper #include <sys/kmem.h>
138*63d1fd59SEnji Cooper 
139*63d1fd59SEnji Cooper void *
kmem_alloc(size_t size,km_flag_t flags)140*63d1fd59SEnji Cooper kmem_alloc(size_t size, km_flag_t flags)
141*63d1fd59SEnji Cooper {
142*63d1fd59SEnji Cooper 	return malloc(size);
143*63d1fd59SEnji Cooper }
144*63d1fd59SEnji Cooper 
145*63d1fd59SEnji Cooper void *
kmem_zalloc(size_t size,km_flag_t flags)146*63d1fd59SEnji Cooper kmem_zalloc(size_t size, km_flag_t flags)
147*63d1fd59SEnji Cooper {
148*63d1fd59SEnji Cooper 	void *ptr;
149*63d1fd59SEnji Cooper 	ptr = malloc(size);
150*63d1fd59SEnji Cooper 
151*63d1fd59SEnji Cooper 	memset(ptr, 0, size);
152*63d1fd59SEnji Cooper 
153*63d1fd59SEnji Cooper 	return ptr;
154*63d1fd59SEnji Cooper }
155*63d1fd59SEnji Cooper 
156*63d1fd59SEnji Cooper void
kmem_free(void * mem,size_t size)157*63d1fd59SEnji Cooper kmem_free(void *mem, size_t size)
158*63d1fd59SEnji Cooper {
159*63d1fd59SEnji Cooper 	free(mem);
160*63d1fd59SEnji Cooper }
161*63d1fd59SEnji Cooper 
162*63d1fd59SEnji Cooper static void
panic(const char * fmt,...)163*63d1fd59SEnji Cooper panic(const char *fmt, ...)
164*63d1fd59SEnji Cooper {
165*63d1fd59SEnji Cooper 	va_list ap;
166*63d1fd59SEnji Cooper 
167*63d1fd59SEnji Cooper 	va_start(ap, fmt);
168*63d1fd59SEnji Cooper 	vprintf(fmt, ap);
169*63d1fd59SEnji Cooper 	printf("\n");
170*63d1fd59SEnji Cooper 	va_end(ap);
171*63d1fd59SEnji Cooper 	KASSERT(false);
172*63d1fd59SEnji Cooper 
173*63d1fd59SEnji Cooper 	/*NOTREACHED*/
174*63d1fd59SEnji Cooper }
175*63d1fd59SEnji Cooper 
176*63d1fd59SEnji Cooper static void
uvm_pagefree(struct vm_page * pg)177*63d1fd59SEnji Cooper uvm_pagefree(struct vm_page *pg)
178*63d1fd59SEnji Cooper {
179*63d1fd59SEnji Cooper 	return;
180*63d1fd59SEnji Cooper }
181*63d1fd59SEnji Cooper 
182*63d1fd59SEnji Cooper #if defined(UVM_HOTPLUG)
183*63d1fd59SEnji Cooper static void
uvmpdpol_reinit(void)184*63d1fd59SEnji Cooper uvmpdpol_reinit(void)
185*63d1fd59SEnji Cooper {
186*63d1fd59SEnji Cooper 	return;
187*63d1fd59SEnji Cooper }
188*63d1fd59SEnji Cooper #endif /* UVM_HOTPLUG */
189*63d1fd59SEnji Cooper 
190*63d1fd59SEnji Cooper /* end - Provide Kernel API equivalents */
191*63d1fd59SEnji Cooper 
192*63d1fd59SEnji Cooper 
193*63d1fd59SEnji Cooper #include "uvm/uvm_physseg.c"
194*63d1fd59SEnji Cooper 
195*63d1fd59SEnji Cooper #include <atf-c.h>
196*63d1fd59SEnji Cooper 
197*63d1fd59SEnji Cooper #define SIXTYFOUR_KILO (64 * 1024)
198*63d1fd59SEnji Cooper #define ONETWENTYEIGHT_KILO (128 * 1024)
199*63d1fd59SEnji Cooper #define TWOFIFTYSIX_KILO (256 * 1024)
200*63d1fd59SEnji Cooper #define FIVEONETWO_KILO (512 * 1024)
201*63d1fd59SEnji Cooper #define ONE_MEGABYTE (1024 * 1024)
202*63d1fd59SEnji Cooper #define TWO_MEGABYTE (2 * 1024 * 1024)
203*63d1fd59SEnji Cooper 
204*63d1fd59SEnji Cooper /* Sample Page Frame Numbers */
205*63d1fd59SEnji Cooper #define VALID_START_PFN_1 atop(0)
206*63d1fd59SEnji Cooper #define VALID_END_PFN_1 atop(ONE_MEGABYTE)
207*63d1fd59SEnji Cooper #define VALID_AVAIL_START_PFN_1 atop(0)
208*63d1fd59SEnji Cooper #define VALID_AVAIL_END_PFN_1 atop(ONE_MEGABYTE)
209*63d1fd59SEnji Cooper 
210*63d1fd59SEnji Cooper #define VALID_START_PFN_2 atop(ONE_MEGABYTE + 1)
211*63d1fd59SEnji Cooper #define VALID_END_PFN_2 atop(ONE_MEGABYTE * 2)
212*63d1fd59SEnji Cooper #define VALID_AVAIL_START_PFN_2 atop(ONE_MEGABYTE + 1)
213*63d1fd59SEnji Cooper #define VALID_AVAIL_END_PFN_2 atop(ONE_MEGABYTE * 2)
214*63d1fd59SEnji Cooper 
215*63d1fd59SEnji Cooper #define VALID_START_PFN_3 atop((ONE_MEGABYTE * 2) + 1)
216*63d1fd59SEnji Cooper #define VALID_END_PFN_3 atop(ONE_MEGABYTE * 3)
217*63d1fd59SEnji Cooper #define VALID_AVAIL_START_PFN_3 atop((ONE_MEGABYTE * 2) + 1)
218*63d1fd59SEnji Cooper #define VALID_AVAIL_END_PFN_3 atop(ONE_MEGABYTE * 3)
219*63d1fd59SEnji Cooper 
220*63d1fd59SEnji Cooper #define VALID_START_PFN_4 atop((ONE_MEGABYTE * 3) + 1)
221*63d1fd59SEnji Cooper #define VALID_END_PFN_4 atop(ONE_MEGABYTE * 4)
222*63d1fd59SEnji Cooper #define VALID_AVAIL_START_PFN_4 atop((ONE_MEGABYTE * 3) + 1)
223*63d1fd59SEnji Cooper #define VALID_AVAIL_END_PFN_4 atop(ONE_MEGABYTE * 4)
224*63d1fd59SEnji Cooper 
225*63d1fd59SEnji Cooper /*
226*63d1fd59SEnji Cooper  * Total number of pages (of 4K size each) should be 256 for 1MB of memory.
227*63d1fd59SEnji Cooper  */
228*63d1fd59SEnji Cooper #define PAGE_COUNT_1M      256
229*63d1fd59SEnji Cooper 
230*63d1fd59SEnji Cooper /*
231*63d1fd59SEnji Cooper  * A debug fucntion to print the content of upm.
232*63d1fd59SEnji Cooper  */
233*63d1fd59SEnji Cooper 	static inline void
uvm_physseg_dump_seg(uvm_physseg_t upm)234*63d1fd59SEnji Cooper 	uvm_physseg_dump_seg(uvm_physseg_t upm)
235*63d1fd59SEnji Cooper 	{
236*63d1fd59SEnji Cooper #if defined(DEBUG)
237*63d1fd59SEnji Cooper 		printf("%s: seg->start == %ld\n", __func__,
238*63d1fd59SEnji Cooper 		    uvm_physseg_get_start(upm));
239*63d1fd59SEnji Cooper 		printf("%s: seg->end == %ld\n", __func__,
240*63d1fd59SEnji Cooper 		    uvm_physseg_get_end(upm));
241*63d1fd59SEnji Cooper 		printf("%s: seg->avail_start == %ld\n", __func__,
242*63d1fd59SEnji Cooper 		    uvm_physseg_get_avail_start(upm));
243*63d1fd59SEnji Cooper 		printf("%s: seg->avail_end == %ld\n", __func__,
244*63d1fd59SEnji Cooper 		    uvm_physseg_get_avail_end(upm));
245*63d1fd59SEnji Cooper 
246*63d1fd59SEnji Cooper 		printf("====\n\n");
247*63d1fd59SEnji Cooper #else
248*63d1fd59SEnji Cooper 		return;
249*63d1fd59SEnji Cooper #endif /* DEBUG */
250*63d1fd59SEnji Cooper 	}
251*63d1fd59SEnji Cooper 
252*63d1fd59SEnji Cooper /*
253*63d1fd59SEnji Cooper  * Private accessor that gets the value of uvm_physseg_graph.nentries
254*63d1fd59SEnji Cooper  */
255*63d1fd59SEnji Cooper static int
uvm_physseg_get_entries(void)256*63d1fd59SEnji Cooper uvm_physseg_get_entries(void)
257*63d1fd59SEnji Cooper {
258*63d1fd59SEnji Cooper #if defined(UVM_HOTPLUG)
259*63d1fd59SEnji Cooper 	return uvm_physseg_graph.nentries;
260*63d1fd59SEnji Cooper #else
261*63d1fd59SEnji Cooper 	return vm_nphysmem;
262*63d1fd59SEnji Cooper #endif /* UVM_HOTPLUG */
263*63d1fd59SEnji Cooper }
264*63d1fd59SEnji Cooper 
265*63d1fd59SEnji Cooper #if !defined(UVM_HOTPLUG)
266*63d1fd59SEnji Cooper static void *
uvm_physseg_alloc(size_t sz)267*63d1fd59SEnji Cooper uvm_physseg_alloc(size_t sz)
268*63d1fd59SEnji Cooper {
269*63d1fd59SEnji Cooper 	return &vm_physmem[vm_nphysseg++];
270*63d1fd59SEnji Cooper }
271*63d1fd59SEnji Cooper #endif
272*63d1fd59SEnji Cooper 
273*63d1fd59SEnji Cooper /*
274*63d1fd59SEnji Cooper  * Test Fixture SetUp().
275*63d1fd59SEnji Cooper  */
276*63d1fd59SEnji Cooper static void
setup(void)277*63d1fd59SEnji Cooper setup(void)
278*63d1fd59SEnji Cooper {
279*63d1fd59SEnji Cooper 	/* Prerequisites for running certain calls in uvm_physseg */
280*63d1fd59SEnji Cooper 	uvmexp.pagesize = PAGE_SIZE;
281*63d1fd59SEnji Cooper 	uvmexp.npages = 0;
282*63d1fd59SEnji Cooper 	uvm.page_init_done = false;
283*63d1fd59SEnji Cooper 	uvm_physseg_init();
284*63d1fd59SEnji Cooper }
285*63d1fd59SEnji Cooper 
286*63d1fd59SEnji Cooper 
287*63d1fd59SEnji Cooper /* <---- Tests for Internal functions ----> */
288*63d1fd59SEnji Cooper #if defined(UVM_HOTPLUG)
289*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_alloc_atboot_mismatch);
ATF_TC_HEAD(uvm_physseg_alloc_atboot_mismatch,tc)290*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_alloc_atboot_mismatch, tc)
291*63d1fd59SEnji Cooper {
292*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "boot time uvm_physseg_alloc() sanity"
293*63d1fd59SEnji Cooper 	    "size mismatch alloc() test.");
294*63d1fd59SEnji Cooper }
295*63d1fd59SEnji Cooper 
ATF_TC_BODY(uvm_physseg_alloc_atboot_mismatch,tc)296*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_alloc_atboot_mismatch, tc)
297*63d1fd59SEnji Cooper {
298*63d1fd59SEnji Cooper 	uvm.page_init_done = false;
299*63d1fd59SEnji Cooper 
300*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT, "size mismatch alloc()");
301*63d1fd59SEnji Cooper 
302*63d1fd59SEnji Cooper 	uvm_physseg_alloc(sizeof(struct uvm_physseg) - 1);
303*63d1fd59SEnji Cooper }
304*63d1fd59SEnji Cooper 
305*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_alloc_atboot_overrun);
ATF_TC_HEAD(uvm_physseg_alloc_atboot_overrun,tc)306*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_alloc_atboot_overrun, tc)
307*63d1fd59SEnji Cooper {
308*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "boot time uvm_physseg_alloc() sanity"
309*63d1fd59SEnji Cooper 	    "array overrun alloc() test.");
310*63d1fd59SEnji Cooper }
311*63d1fd59SEnji Cooper 
ATF_TC_BODY(uvm_physseg_alloc_atboot_overrun,tc)312*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_alloc_atboot_overrun, tc)
313*63d1fd59SEnji Cooper {
314*63d1fd59SEnji Cooper 	uvm.page_init_done = false;
315*63d1fd59SEnji Cooper 
316*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT, "array overrun alloc()");
317*63d1fd59SEnji Cooper 
318*63d1fd59SEnji Cooper 	uvm_physseg_alloc((VM_PHYSSEG_MAX + 1) * sizeof(struct uvm_physseg));
319*63d1fd59SEnji Cooper 
320*63d1fd59SEnji Cooper }
321*63d1fd59SEnji Cooper 
322*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_alloc_sanity);
ATF_TC_HEAD(uvm_physseg_alloc_sanity,tc)323*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_alloc_sanity, tc)
324*63d1fd59SEnji Cooper {
325*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "further uvm_physseg_alloc() sanity checks");
326*63d1fd59SEnji Cooper }
327*63d1fd59SEnji Cooper 
ATF_TC_BODY(uvm_physseg_alloc_sanity,tc)328*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_alloc_sanity, tc)
329*63d1fd59SEnji Cooper {
330*63d1fd59SEnji Cooper 
331*63d1fd59SEnji Cooper 	/* At boot time */
332*63d1fd59SEnji Cooper 	uvm.page_init_done = false;
333*63d1fd59SEnji Cooper 
334*63d1fd59SEnji Cooper 	/* Correct alloc */
335*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_alloc(VM_PHYSSEG_MAX * sizeof(struct uvm_physseg)));
336*63d1fd59SEnji Cooper 
337*63d1fd59SEnji Cooper 	/* Retry static alloc()s as dynamic - we expect them to pass */
338*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
339*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_alloc(sizeof(struct uvm_physseg) - 1));
340*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_alloc(2 * VM_PHYSSEG_MAX * sizeof(struct uvm_physseg)));
341*63d1fd59SEnji Cooper }
342*63d1fd59SEnji Cooper 
343*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_free_atboot_mismatch);
ATF_TC_HEAD(uvm_physseg_free_atboot_mismatch,tc)344*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_free_atboot_mismatch, tc)
345*63d1fd59SEnji Cooper {
346*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "boot time uvm_physseg_free() sanity"
347*63d1fd59SEnji Cooper 	    "size mismatch free() test.");
348*63d1fd59SEnji Cooper }
349*63d1fd59SEnji Cooper 
ATF_TC_BODY(uvm_physseg_free_atboot_mismatch,tc)350*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_free_atboot_mismatch, tc)
351*63d1fd59SEnji Cooper {
352*63d1fd59SEnji Cooper 	uvm.page_init_done = false;
353*63d1fd59SEnji Cooper 
354*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT, "size mismatch free()");
355*63d1fd59SEnji Cooper 
356*63d1fd59SEnji Cooper 	uvm_physseg_free(&uvm_physseg[0], sizeof(struct uvm_physseg) - 1);
357*63d1fd59SEnji Cooper }
358*63d1fd59SEnji Cooper 
359*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_free_sanity);
ATF_TC_HEAD(uvm_physseg_free_sanity,tc)360*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_free_sanity, tc)
361*63d1fd59SEnji Cooper {
362*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "further uvm_physseg_free() sanity checks");
363*63d1fd59SEnji Cooper }
364*63d1fd59SEnji Cooper 
ATF_TC_BODY(uvm_physseg_free_sanity,tc)365*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_free_sanity, tc)
366*63d1fd59SEnji Cooper {
367*63d1fd59SEnji Cooper 
368*63d1fd59SEnji Cooper 	/* At boot time */
369*63d1fd59SEnji Cooper 	uvm.page_init_done = false;
370*63d1fd59SEnji Cooper 
371*63d1fd59SEnji Cooper 	struct uvm_physseg *seg;
372*63d1fd59SEnji Cooper 
373*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
374*63d1fd59SEnji Cooper 	/*
375*63d1fd59SEnji Cooper 	 * Note: free()ing the entire array is considered to be an
376*63d1fd59SEnji Cooper 	 * error. Thus VM_PHYSSEG_MAX - 1.
377*63d1fd59SEnji Cooper 	 */
378*63d1fd59SEnji Cooper 
379*63d1fd59SEnji Cooper 	seg = uvm_physseg_alloc((VM_PHYSSEG_MAX - 1) * sizeof(*seg));
380*63d1fd59SEnji Cooper 	uvm_physseg_free(seg, (VM_PHYSSEG_MAX - 1) * sizeof(struct uvm_physseg));
381*63d1fd59SEnji Cooper #endif
382*63d1fd59SEnji Cooper 
383*63d1fd59SEnji Cooper 	/* Retry static alloc()s as dynamic - we expect them to pass */
384*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
385*63d1fd59SEnji Cooper 
386*63d1fd59SEnji Cooper 	seg = uvm_physseg_alloc(sizeof(struct uvm_physseg) - 1);
387*63d1fd59SEnji Cooper 	uvm_physseg_free(seg, sizeof(struct uvm_physseg) - 1);
388*63d1fd59SEnji Cooper 
389*63d1fd59SEnji Cooper 	seg = uvm_physseg_alloc(2 * VM_PHYSSEG_MAX * sizeof(struct uvm_physseg));
390*63d1fd59SEnji Cooper 
391*63d1fd59SEnji Cooper 	uvm_physseg_free(seg, 2 * VM_PHYSSEG_MAX * sizeof(struct uvm_physseg));
392*63d1fd59SEnji Cooper }
393*63d1fd59SEnji Cooper 
394*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
395*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_atboot_free_leak);
ATF_TC_HEAD(uvm_physseg_atboot_free_leak,tc)396*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_atboot_free_leak, tc)
397*63d1fd59SEnji Cooper {
398*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
399*63d1fd59SEnji Cooper 	    "does free() leak at boot ?\n"
400*63d1fd59SEnji Cooper 	    "This test needs VM_PHYSSEG_MAX > 1)");
401*63d1fd59SEnji Cooper }
402*63d1fd59SEnji Cooper 
ATF_TC_BODY(uvm_physseg_atboot_free_leak,tc)403*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_atboot_free_leak, tc)
404*63d1fd59SEnji Cooper {
405*63d1fd59SEnji Cooper 
406*63d1fd59SEnji Cooper 	/* At boot time */
407*63d1fd59SEnji Cooper 	uvm.page_init_done = false;
408*63d1fd59SEnji Cooper 
409*63d1fd59SEnji Cooper 	/* alloc to array size */
410*63d1fd59SEnji Cooper 	struct uvm_physseg *seg;
411*63d1fd59SEnji Cooper 	seg = uvm_physseg_alloc(VM_PHYSSEG_MAX * sizeof(*seg));
412*63d1fd59SEnji Cooper 
413*63d1fd59SEnji Cooper 	uvm_physseg_free(seg, sizeof(*seg));
414*63d1fd59SEnji Cooper 
415*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT, "array overrun on alloc() after leak");
416*63d1fd59SEnji Cooper 
417*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_alloc(sizeof(struct uvm_physseg)));
418*63d1fd59SEnji Cooper }
419*63d1fd59SEnji Cooper #endif /* VM_PHYSSEG_MAX */
420*63d1fd59SEnji Cooper #endif /* UVM_HOTPLUG */
421*63d1fd59SEnji Cooper 
422*63d1fd59SEnji Cooper /*
423*63d1fd59SEnji Cooper  * Note: This function replicates verbatim what happens in
424*63d1fd59SEnji Cooper  * uvm_page.c:uvm_page_init().
425*63d1fd59SEnji Cooper  *
426*63d1fd59SEnji Cooper  * Please track any changes that happen there.
427*63d1fd59SEnji Cooper  */
428*63d1fd59SEnji Cooper static void
uvm_page_init_fake(struct vm_page * pagearray,psize_t pagecount)429*63d1fd59SEnji Cooper uvm_page_init_fake(struct vm_page *pagearray, psize_t pagecount)
430*63d1fd59SEnji Cooper {
431*63d1fd59SEnji Cooper 	uvm_physseg_t bank;
432*63d1fd59SEnji Cooper 	size_t n;
433*63d1fd59SEnji Cooper 
434*63d1fd59SEnji Cooper 	for (bank = uvm_physseg_get_first(),
435*63d1fd59SEnji Cooper 		 uvm_physseg_seg_chomp_slab(bank, pagearray, pagecount);
436*63d1fd59SEnji Cooper 	     uvm_physseg_valid_p(bank);
437*63d1fd59SEnji Cooper 	     bank = uvm_physseg_get_next(bank)) {
438*63d1fd59SEnji Cooper 
439*63d1fd59SEnji Cooper 		n = uvm_physseg_get_end(bank) - uvm_physseg_get_start(bank);
440*63d1fd59SEnji Cooper 		uvm_physseg_seg_alloc_from_slab(bank, n);
441*63d1fd59SEnji Cooper 		uvm_physseg_init_seg(bank, pagearray);
442*63d1fd59SEnji Cooper 
443*63d1fd59SEnji Cooper 		/* set up page array pointers */
444*63d1fd59SEnji Cooper 		pagearray += n;
445*63d1fd59SEnji Cooper 		pagecount -= n;
446*63d1fd59SEnji Cooper 	}
447*63d1fd59SEnji Cooper 
448*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
449*63d1fd59SEnji Cooper }
450*63d1fd59SEnji Cooper 
451*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_plug);
ATF_TC_HEAD(uvm_physseg_plug,tc)452*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_plug, tc)
453*63d1fd59SEnji Cooper {
454*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
455*63d1fd59SEnji Cooper 	    "Test plug functionality.");
456*63d1fd59SEnji Cooper }
457*63d1fd59SEnji Cooper /* Note: We only do the second boot time plug if VM_PHYSSEG_MAX > 1 */
ATF_TC_BODY(uvm_physseg_plug,tc)458*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_plug, tc)
459*63d1fd59SEnji Cooper {
460*63d1fd59SEnji Cooper 	int nentries = 0; /* Count of entries via plug done so far */
461*63d1fd59SEnji Cooper 	uvm_physseg_t upm1;
462*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
463*63d1fd59SEnji Cooper 	uvm_physseg_t upm2;
464*63d1fd59SEnji Cooper #endif
465*63d1fd59SEnji Cooper 
466*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
467*63d1fd59SEnji Cooper 	uvm_physseg_t upm3;
468*63d1fd59SEnji Cooper #endif
469*63d1fd59SEnji Cooper 	uvm_physseg_t upm4;
470*63d1fd59SEnji Cooper 	psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1);
471*63d1fd59SEnji Cooper 	psize_t npages2 = (VALID_END_PFN_2 - VALID_START_PFN_2);
472*63d1fd59SEnji Cooper 	psize_t npages3 = (VALID_END_PFN_3 - VALID_START_PFN_3);
473*63d1fd59SEnji Cooper 	psize_t npages4 = (VALID_END_PFN_4 - VALID_START_PFN_4);
474*63d1fd59SEnji Cooper 	struct vm_page *pgs, *slab = malloc(sizeof(struct vm_page) * (npages1
475*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
476*63d1fd59SEnji Cooper 		+ npages2
477*63d1fd59SEnji Cooper #endif
478*63d1fd59SEnji Cooper 		+ npages3));
479*63d1fd59SEnji Cooper 
480*63d1fd59SEnji Cooper 	/* Fake early boot */
481*63d1fd59SEnji Cooper 
482*63d1fd59SEnji Cooper 	setup();
483*63d1fd59SEnji Cooper 
484*63d1fd59SEnji Cooper 	/* Vanilla plug x 2 */
485*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(uvm_physseg_plug(VALID_START_PFN_1, npages1, &upm1), true);
486*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(++nentries, uvm_physseg_get_entries());
487*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
488*63d1fd59SEnji Cooper 
489*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
490*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(uvm_physseg_plug(VALID_START_PFN_2, npages2, &upm2), true);
491*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(++nentries, uvm_physseg_get_entries());
492*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
493*63d1fd59SEnji Cooper #endif
494*63d1fd59SEnji Cooper 	/* Post boot: Fake all segments and pages accounted for. */
495*63d1fd59SEnji Cooper 	uvm_page_init_fake(slab, npages1 + npages2 + npages3);
496*63d1fd59SEnji Cooper 
497*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(npages1
498*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
499*63d1fd59SEnji Cooper 	    + npages2
500*63d1fd59SEnji Cooper #endif
501*63d1fd59SEnji Cooper 	    , uvmexp.npages);
502*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
503*63d1fd59SEnji Cooper 	/* Scavenge plug - goes into the same slab */
504*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(uvm_physseg_plug(VALID_START_PFN_3, npages3, &upm3), true);
505*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(++nentries, uvm_physseg_get_entries());
506*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(npages1
507*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
508*63d1fd59SEnji Cooper 	    + npages2
509*63d1fd59SEnji Cooper #endif
510*63d1fd59SEnji Cooper 	    + npages3, uvmexp.npages);
511*63d1fd59SEnji Cooper 
512*63d1fd59SEnji Cooper 	/* Scavenge plug should fit right in the slab */
513*63d1fd59SEnji Cooper 	pgs = uvm_physseg_get_pg(upm3, 0);
514*63d1fd59SEnji Cooper 	ATF_REQUIRE(pgs > slab && pgs < (slab + npages1 + npages2 + npages3));
515*63d1fd59SEnji Cooper #endif
516*63d1fd59SEnji Cooper 	/* Hot plug - goes into a brand new slab */
517*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(uvm_physseg_plug(VALID_START_PFN_4, npages4, &upm4), true);
518*63d1fd59SEnji Cooper 	/* The hot plug slab should have nothing to do with the original slab */
519*63d1fd59SEnji Cooper 	pgs = uvm_physseg_get_pg(upm4, 0);
520*63d1fd59SEnji Cooper 	ATF_REQUIRE(pgs < slab || pgs > (slab + npages1
521*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
522*63d1fd59SEnji Cooper 		+ npages2
523*63d1fd59SEnji Cooper #endif
524*63d1fd59SEnji Cooper 		+ npages3));
525*63d1fd59SEnji Cooper 
526*63d1fd59SEnji Cooper }
527*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_unplug);
ATF_TC_HEAD(uvm_physseg_unplug,tc)528*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_unplug, tc)
529*63d1fd59SEnji Cooper {
530*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr",
531*63d1fd59SEnji Cooper 	    "Test unplug functionality.");
532*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_unplug,tc)533*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_unplug, tc)
534*63d1fd59SEnji Cooper {
535*63d1fd59SEnji Cooper 	paddr_t pa = 0;
536*63d1fd59SEnji Cooper 
537*63d1fd59SEnji Cooper 	psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1);
538*63d1fd59SEnji Cooper 	psize_t npages2 = (VALID_END_PFN_2 - VALID_START_PFN_2);
539*63d1fd59SEnji Cooper 	psize_t npages3 = (VALID_END_PFN_3 - VALID_START_PFN_3);
540*63d1fd59SEnji Cooper 
541*63d1fd59SEnji Cooper 	struct vm_page *slab = malloc(sizeof(struct vm_page) * (npages1 + npages2 + npages3));
542*63d1fd59SEnji Cooper 
543*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
544*63d1fd59SEnji Cooper 
545*63d1fd59SEnji Cooper 	/* Boot time */
546*63d1fd59SEnji Cooper 	setup();
547*63d1fd59SEnji Cooper 
548*63d1fd59SEnji Cooper 	/* We start with zero segments */
549*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm_physseg_plug(atop(0), atop(ONE_MEGABYTE), NULL));
550*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
551*63d1fd59SEnji Cooper 	/* Do we have an arbitrary offset in there ? */
552*63d1fd59SEnji Cooper 	uvm_physseg_find(atop(TWOFIFTYSIX_KILO), &pa);
553*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(pa, atop(TWOFIFTYSIX_KILO));
554*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages); /* Boot time sanity */
555*63d1fd59SEnji Cooper 
556*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX == 1
557*63d1fd59SEnji Cooper 	/*
558*63d1fd59SEnji Cooper 	 * This is the curious case at boot time, of having one
559*63d1fd59SEnji Cooper 	 * extent(9) static entry per segment, which means that a
560*63d1fd59SEnji Cooper 	 * fragmenting unplug will fail.
561*63d1fd59SEnji Cooper 	 */
562*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT, "fragmenting unplug for single segment");
563*63d1fd59SEnji Cooper 
564*63d1fd59SEnji Cooper 	/*
565*63d1fd59SEnji Cooper 	 * In order to test the fragmenting cases, please set
566*63d1fd59SEnji Cooper 	 * VM_PHYSSEG_MAX > 1
567*63d1fd59SEnji Cooper 	 */
568*63d1fd59SEnji Cooper #endif
569*63d1fd59SEnji Cooper 	/* Now let's unplug from the middle */
570*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm_physseg_unplug(atop(TWOFIFTYSIX_KILO), atop(FIVEONETWO_KILO)));
571*63d1fd59SEnji Cooper 	/* verify that a gap exists at TWOFIFTYSIX_KILO */
572*63d1fd59SEnji Cooper 	pa = 0; /* reset */
573*63d1fd59SEnji Cooper 	uvm_physseg_find(atop(TWOFIFTYSIX_KILO), &pa);
574*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(pa, 0);
575*63d1fd59SEnji Cooper 
576*63d1fd59SEnji Cooper 	/* Post boot: Fake all segments and pages accounted for. */
577*63d1fd59SEnji Cooper 	uvm_page_init_fake(slab, npages1 + npages2 + npages3);
578*63d1fd59SEnji Cooper 	/* Account for the unplug */
579*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(atop(FIVEONETWO_KILO), uvmexp.npages);
580*63d1fd59SEnji Cooper 
581*63d1fd59SEnji Cooper 	/* Original entry should fragment into two */
582*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
583*63d1fd59SEnji Cooper 
584*63d1fd59SEnji Cooper 	upm = uvm_physseg_find(atop(TWOFIFTYSIX_KILO + FIVEONETWO_KILO), NULL);
585*63d1fd59SEnji Cooper 
586*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_valid_p(upm));
587*63d1fd59SEnji Cooper 
588*63d1fd59SEnji Cooper 	/* Now unplug the tail fragment - should swallow the complete entry */
589*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm_physseg_unplug(atop(TWOFIFTYSIX_KILO + FIVEONETWO_KILO), atop(TWOFIFTYSIX_KILO)));
590*63d1fd59SEnji Cooper 
591*63d1fd59SEnji Cooper 	/* The "swallow" above should have invalidated the handle */
592*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(false, uvm_physseg_valid_p(upm));
593*63d1fd59SEnji Cooper 
594*63d1fd59SEnji Cooper 	/* Only the first one is left now */
595*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
596*63d1fd59SEnji Cooper 
597*63d1fd59SEnji Cooper 	/* Unplug from the back */
598*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm_physseg_unplug(atop(ONETWENTYEIGHT_KILO), atop(ONETWENTYEIGHT_KILO)));
599*63d1fd59SEnji Cooper 	/* Shouldn't change the number of segments */
600*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
601*63d1fd59SEnji Cooper 
602*63d1fd59SEnji Cooper 	/* Unplug from the front */
603*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm_physseg_unplug(0, atop(SIXTYFOUR_KILO)));
604*63d1fd59SEnji Cooper 	/* Shouldn't change the number of segments */
605*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
606*63d1fd59SEnji Cooper 
607*63d1fd59SEnji Cooper 	/* Unplugging the final fragment should fail */
608*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT, "Unplugging the last segment");
609*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm_physseg_unplug(atop(SIXTYFOUR_KILO), atop(SIXTYFOUR_KILO)));
610*63d1fd59SEnji Cooper }
611*63d1fd59SEnji Cooper 
612*63d1fd59SEnji Cooper 
613*63d1fd59SEnji Cooper /* <---- end Tests for Internal functions ----> */
614*63d1fd59SEnji Cooper 
615*63d1fd59SEnji Cooper /* Tests for functions exported via uvm_physseg.h */
616*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_init);
ATF_TC_HEAD(uvm_physseg_init,tc)617*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_init, tc)
618*63d1fd59SEnji Cooper {
619*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_init() call\
620*63d1fd59SEnji Cooper 	    initializes the vm_physmem struct which holds the rb_tree.");
621*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_init,tc)622*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_init, tc)
623*63d1fd59SEnji Cooper {
624*63d1fd59SEnji Cooper 	uvm_physseg_init();
625*63d1fd59SEnji Cooper 
626*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvm_physseg_get_entries());
627*63d1fd59SEnji Cooper }
628*63d1fd59SEnji Cooper 
629*63d1fd59SEnji Cooper ATF_TC(uvm_page_physload_preload);
ATF_TC_HEAD(uvm_page_physload_preload,tc)630*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physload_preload, tc)
631*63d1fd59SEnji Cooper {
632*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physload() \
633*63d1fd59SEnji Cooper 	    call works without a panic() in a preload scenario.");
634*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physload_preload,tc)635*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physload_preload, tc)
636*63d1fd59SEnji Cooper {
637*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
638*63d1fd59SEnji Cooper 
639*63d1fd59SEnji Cooper 	setup();
640*63d1fd59SEnji Cooper 
641*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
642*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
643*63d1fd59SEnji Cooper 
644*63d1fd59SEnji Cooper 	/* Should return a valid handle */
645*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_valid_p(upm));
646*63d1fd59SEnji Cooper 
647*63d1fd59SEnji Cooper 	/* No pages should be allocated yet */
648*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
649*63d1fd59SEnji Cooper 
650*63d1fd59SEnji Cooper 	/* After the first call one segment should exist */
651*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(1, uvm_physseg_get_entries());
652*63d1fd59SEnji Cooper 
653*63d1fd59SEnji Cooper 	/* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */
654*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
655*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
656*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
657*63d1fd59SEnji Cooper 
658*63d1fd59SEnji Cooper 	/* Should return a valid handle */
659*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_valid_p(upm));
660*63d1fd59SEnji Cooper 
661*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
662*63d1fd59SEnji Cooper 
663*63d1fd59SEnji Cooper 	/* After the second call two segments should exist */
664*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(2, uvm_physseg_get_entries());
665*63d1fd59SEnji Cooper #endif
666*63d1fd59SEnji Cooper }
667*63d1fd59SEnji Cooper 
668*63d1fd59SEnji Cooper ATF_TC(uvm_page_physload_postboot);
ATF_TC_HEAD(uvm_page_physload_postboot,tc)669*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physload_postboot, tc)
670*63d1fd59SEnji Cooper {
671*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physload() \
672*63d1fd59SEnji Cooper 	     panic()s in a post boot scenario.");
673*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physload_postboot,tc)674*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physload_postboot, tc)
675*63d1fd59SEnji Cooper {
676*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
677*63d1fd59SEnji Cooper 
678*63d1fd59SEnji Cooper 	psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1);
679*63d1fd59SEnji Cooper 	psize_t npages2 = (VALID_END_PFN_2 - VALID_START_PFN_2);
680*63d1fd59SEnji Cooper 
681*63d1fd59SEnji Cooper 	struct vm_page *slab = malloc(sizeof(struct vm_page) * (npages1 + npages2));
682*63d1fd59SEnji Cooper 
683*63d1fd59SEnji Cooper 	setup();
684*63d1fd59SEnji Cooper 
685*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
686*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
687*63d1fd59SEnji Cooper 
688*63d1fd59SEnji Cooper 	/* Should return a valid handle */
689*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_valid_p(upm));
690*63d1fd59SEnji Cooper 
691*63d1fd59SEnji Cooper 	/* No pages should be allocated yet */
692*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
693*63d1fd59SEnji Cooper 
694*63d1fd59SEnji Cooper 	/* After the first call one segment should exist */
695*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(1, uvm_physseg_get_entries());
696*63d1fd59SEnji Cooper 
697*63d1fd59SEnji Cooper 	/* Post boot: Fake all segments and pages accounted for. */
698*63d1fd59SEnji Cooper 	uvm_page_init_fake(slab, npages1 + npages2);
699*63d1fd59SEnji Cooper 
700*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT,
701*63d1fd59SEnji Cooper 	    "uvm_page_physload() called post boot");
702*63d1fd59SEnji Cooper 
703*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
704*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
705*63d1fd59SEnji Cooper 
706*63d1fd59SEnji Cooper 	/* Should return a valid handle */
707*63d1fd59SEnji Cooper 	ATF_REQUIRE(uvm_physseg_valid_p(upm));
708*63d1fd59SEnji Cooper 
709*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(npages1 + npages2, uvmexp.npages);
710*63d1fd59SEnji Cooper 
711*63d1fd59SEnji Cooper 	/* After the second call two segments should exist */
712*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(2, uvm_physseg_get_entries());
713*63d1fd59SEnji Cooper }
714*63d1fd59SEnji Cooper 
715*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_handle_immutable);
ATF_TC_HEAD(uvm_physseg_handle_immutable,tc)716*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_handle_immutable, tc)
717*63d1fd59SEnji Cooper {
718*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the uvm_physseg_t handle is \
719*63d1fd59SEnji Cooper 	    immutable.");
720*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_handle_immutable,tc)721*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_handle_immutable, tc)
722*63d1fd59SEnji Cooper {
723*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
724*63d1fd59SEnji Cooper 
725*63d1fd59SEnji Cooper 	/* We insert the segments in out of order */
726*63d1fd59SEnji Cooper 
727*63d1fd59SEnji Cooper 	setup();
728*63d1fd59SEnji Cooper 
729*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
730*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
731*63d1fd59SEnji Cooper 
732*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
733*63d1fd59SEnji Cooper 
734*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
735*63d1fd59SEnji Cooper 
736*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID_EMPTY, uvm_physseg_get_prev(upm));
737*63d1fd59SEnji Cooper 
738*63d1fd59SEnji Cooper 	/* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */
739*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
740*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
741*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
742*63d1fd59SEnji Cooper 
743*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
744*63d1fd59SEnji Cooper 
745*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
746*63d1fd59SEnji Cooper 
747*63d1fd59SEnji Cooper 	/* Fetch Previous, we inserted a lower value */
748*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_prev(upm);
749*63d1fd59SEnji Cooper 
750*63d1fd59SEnji Cooper #if !defined(UVM_HOTPLUG)
751*63d1fd59SEnji Cooper 	/*
752*63d1fd59SEnji Cooper 	 * This test is going to fail for the Array Implementation but is
753*63d1fd59SEnji Cooper 	 * expected to pass in the RB Tree implementation.
754*63d1fd59SEnji Cooper 	 */
755*63d1fd59SEnji Cooper 	/* Failure can be expected iff there are more than one handles */
756*63d1fd59SEnji Cooper 	atf_tc_expect_fail("Mutable handle in static array impl.");
757*63d1fd59SEnji Cooper #endif
758*63d1fd59SEnji Cooper 	ATF_CHECK(UVM_PHYSSEG_TYPE_INVALID_EMPTY != upm);
759*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm));
760*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm));
761*63d1fd59SEnji Cooper #endif
762*63d1fd59SEnji Cooper }
763*63d1fd59SEnji Cooper 
764*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_seg_chomp_slab);
ATF_TC_HEAD(uvm_physseg_seg_chomp_slab,tc)765*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_seg_chomp_slab, tc)
766*63d1fd59SEnji Cooper {
767*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "The slab import code.()");
768*63d1fd59SEnji Cooper 
769*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_seg_chomp_slab,tc)770*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_seg_chomp_slab, tc)
771*63d1fd59SEnji Cooper {
772*63d1fd59SEnji Cooper 	int err;
773*63d1fd59SEnji Cooper 	size_t i;
774*63d1fd59SEnji Cooper 	struct uvm_physseg *seg;
775*63d1fd59SEnji Cooper 	struct vm_page *slab, *pgs;
776*63d1fd59SEnji Cooper 	const size_t npages = UVM_PHYSSEG_BOOT_UNPLUG_MAX; /* Number of pages */
777*63d1fd59SEnji Cooper 
778*63d1fd59SEnji Cooper 	setup();
779*63d1fd59SEnji Cooper 
780*63d1fd59SEnji Cooper 	/* This is boot time */
781*63d1fd59SEnji Cooper 	slab = malloc(sizeof(struct vm_page) * npages * 2);
782*63d1fd59SEnji Cooper 
783*63d1fd59SEnji Cooper 	seg = uvm_physseg_alloc(sizeof(struct uvm_physseg));
784*63d1fd59SEnji Cooper 
785*63d1fd59SEnji Cooper 	uvm_physseg_seg_chomp_slab(PHYSSEG_NODE_TO_HANDLE(seg), slab, npages * 2);
786*63d1fd59SEnji Cooper 
787*63d1fd59SEnji Cooper 	/* Should be able to allocate two 128 * sizeof(*slab) */
788*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, extent_alloc(seg->ext, sizeof(*slab), 1, 0, EX_BOUNDZERO, (void *)&pgs));
789*63d1fd59SEnji Cooper 	err = extent_free(seg->ext, (u_long) pgs, sizeof(*slab), EX_BOUNDZERO);
790*63d1fd59SEnji Cooper 
791*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX == 1
792*63d1fd59SEnji Cooper 	/*
793*63d1fd59SEnji Cooper 	 * free() needs an extra region descriptor, but we only have
794*63d1fd59SEnji Cooper 	 * one! The classic alloc() at free() problem
795*63d1fd59SEnji Cooper 	 */
796*63d1fd59SEnji Cooper 
797*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(ENOMEM, err);
798*63d1fd59SEnji Cooper #else
799*63d1fd59SEnji Cooper 	/* Try alloc/free at static time */
800*63d1fd59SEnji Cooper 	for (i = 0; i < npages; i++) {
801*63d1fd59SEnji Cooper 		ATF_REQUIRE_EQ(0, extent_alloc(seg->ext, sizeof(*slab), 1, 0, EX_BOUNDZERO, (void *)&pgs));
802*63d1fd59SEnji Cooper 		err = extent_free(seg->ext, (u_long) pgs, sizeof(*slab), EX_BOUNDZERO);
803*63d1fd59SEnji Cooper 		ATF_REQUIRE_EQ(0, err);
804*63d1fd59SEnji Cooper 	}
805*63d1fd59SEnji Cooper #endif
806*63d1fd59SEnji Cooper 
807*63d1fd59SEnji Cooper 	/* Now setup post boot */
808*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
809*63d1fd59SEnji Cooper 
810*63d1fd59SEnji Cooper 	uvm_physseg_seg_chomp_slab(PHYSSEG_NODE_TO_HANDLE(seg), slab, npages * 2);
811*63d1fd59SEnji Cooper 
812*63d1fd59SEnji Cooper 	/* Try alloc/free after uvm_page.c:uvm_page_init() as well */
813*63d1fd59SEnji Cooper 	for (i = 0; i < npages; i++) {
814*63d1fd59SEnji Cooper 		ATF_REQUIRE_EQ(0, extent_alloc(seg->ext, sizeof(*slab), 1, 0, EX_BOUNDZERO, (void *)&pgs));
815*63d1fd59SEnji Cooper 		err = extent_free(seg->ext, (u_long) pgs, sizeof(*slab), EX_BOUNDZERO);
816*63d1fd59SEnji Cooper 		ATF_REQUIRE_EQ(0, err);
817*63d1fd59SEnji Cooper 	}
818*63d1fd59SEnji Cooper 
819*63d1fd59SEnji Cooper }
820*63d1fd59SEnji Cooper 
821*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_alloc_from_slab);
ATF_TC_HEAD(uvm_physseg_alloc_from_slab,tc)822*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_alloc_from_slab, tc)
823*63d1fd59SEnji Cooper {
824*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "The slab alloc code.()");
825*63d1fd59SEnji Cooper 
826*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_alloc_from_slab,tc)827*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_alloc_from_slab, tc)
828*63d1fd59SEnji Cooper {
829*63d1fd59SEnji Cooper 	struct uvm_physseg *seg;
830*63d1fd59SEnji Cooper 	struct vm_page *slab, *pgs;
831*63d1fd59SEnji Cooper 	const size_t npages = UVM_PHYSSEG_BOOT_UNPLUG_MAX; /* Number of pages */
832*63d1fd59SEnji Cooper 
833*63d1fd59SEnji Cooper 	setup();
834*63d1fd59SEnji Cooper 
835*63d1fd59SEnji Cooper 	/* This is boot time */
836*63d1fd59SEnji Cooper 	slab = malloc(sizeof(struct vm_page) * npages * 2);
837*63d1fd59SEnji Cooper 
838*63d1fd59SEnji Cooper 	seg = uvm_physseg_alloc(sizeof(struct uvm_physseg));
839*63d1fd59SEnji Cooper 
840*63d1fd59SEnji Cooper 	uvm_physseg_seg_chomp_slab(PHYSSEG_NODE_TO_HANDLE(seg), slab, npages * 2);
841*63d1fd59SEnji Cooper 
842*63d1fd59SEnji Cooper 	pgs = uvm_physseg_seg_alloc_from_slab(PHYSSEG_NODE_TO_HANDLE(seg), npages);
843*63d1fd59SEnji Cooper 
844*63d1fd59SEnji Cooper 	ATF_REQUIRE(pgs != NULL);
845*63d1fd59SEnji Cooper 
846*63d1fd59SEnji Cooper 	/* Now setup post boot */
847*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
848*63d1fd59SEnji Cooper 
849*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
850*63d1fd59SEnji Cooper 	pgs = uvm_physseg_seg_alloc_from_slab(PHYSSEG_NODE_TO_HANDLE(seg), npages);
851*63d1fd59SEnji Cooper 	ATF_REQUIRE(pgs != NULL);
852*63d1fd59SEnji Cooper #endif
853*63d1fd59SEnji Cooper 	atf_tc_expect_fail("alloc beyond extent");
854*63d1fd59SEnji Cooper 
855*63d1fd59SEnji Cooper 	pgs = uvm_physseg_seg_alloc_from_slab(PHYSSEG_NODE_TO_HANDLE(seg), npages);
856*63d1fd59SEnji Cooper 	ATF_REQUIRE(pgs != NULL);
857*63d1fd59SEnji Cooper }
858*63d1fd59SEnji Cooper 
859*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_init_seg);
ATF_TC_HEAD(uvm_physseg_init_seg,tc)860*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_init_seg, tc)
861*63d1fd59SEnji Cooper {
862*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if uvm_physseg_init_seg adds pages to"
863*63d1fd59SEnji Cooper 	    "uvmexp.npages");
864*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_init_seg,tc)865*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_init_seg, tc)
866*63d1fd59SEnji Cooper {
867*63d1fd59SEnji Cooper 	struct uvm_physseg *seg;
868*63d1fd59SEnji Cooper 	struct vm_page *slab, *pgs;
869*63d1fd59SEnji Cooper 	const size_t npages = UVM_PHYSSEG_BOOT_UNPLUG_MAX; /* Number of pages */
870*63d1fd59SEnji Cooper 
871*63d1fd59SEnji Cooper 	setup();
872*63d1fd59SEnji Cooper 
873*63d1fd59SEnji Cooper 	/* This is boot time */
874*63d1fd59SEnji Cooper 	slab = malloc(sizeof(struct vm_page) * npages * 2);
875*63d1fd59SEnji Cooper 
876*63d1fd59SEnji Cooper 	seg = uvm_physseg_alloc(sizeof(struct uvm_physseg));
877*63d1fd59SEnji Cooper 
878*63d1fd59SEnji Cooper 	uvm_physseg_seg_chomp_slab(PHYSSEG_NODE_TO_HANDLE(seg), slab, npages * 2);
879*63d1fd59SEnji Cooper 
880*63d1fd59SEnji Cooper 	pgs = uvm_physseg_seg_alloc_from_slab(PHYSSEG_NODE_TO_HANDLE(seg), npages);
881*63d1fd59SEnji Cooper 
882*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
883*63d1fd59SEnji Cooper 
884*63d1fd59SEnji Cooper 	seg->start = 0;
885*63d1fd59SEnji Cooper 	seg->end = npages;
886*63d1fd59SEnji Cooper 
887*63d1fd59SEnji Cooper 	seg->avail_start = 0;
888*63d1fd59SEnji Cooper 	seg->avail_end = npages;
889*63d1fd59SEnji Cooper 
890*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(PHYSSEG_NODE_TO_HANDLE(seg), pgs);
891*63d1fd59SEnji Cooper 
892*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(npages, uvmexp.npages);
893*63d1fd59SEnji Cooper }
894*63d1fd59SEnji Cooper 
895*63d1fd59SEnji Cooper #if 0
896*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_init_seg);
897*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_init_seg, tc)
898*63d1fd59SEnji Cooper {
899*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physload() \
900*63d1fd59SEnji Cooper 	    call works without a panic() after Segment is inited.");
901*63d1fd59SEnji Cooper }
902*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_init_seg, tc)
903*63d1fd59SEnji Cooper {
904*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
905*63d1fd59SEnji Cooper 	psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1);
906*63d1fd59SEnji Cooper 	struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages);
907*63d1fd59SEnji Cooper 
908*63d1fd59SEnji Cooper 	setup();
909*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
910*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
911*63d1fd59SEnji Cooper 
912*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
913*63d1fd59SEnji Cooper 
914*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(0, uvmexp.npages);
915*63d1fd59SEnji Cooper 
916*63d1fd59SEnji Cooper 	/*
917*63d1fd59SEnji Cooper 	 * Boot time physplug needs explicit external init,
918*63d1fd59SEnji Cooper 	 * Duplicate what uvm_page.c:uvm_page_init() does.
919*63d1fd59SEnji Cooper 	 * Note: not everything uvm_page_init() does gets done here.
920*63d1fd59SEnji Cooper 	 * Read the source.
921*63d1fd59SEnji Cooper 	 */
922*63d1fd59SEnji Cooper 	/* suck in backing slab, initialise extent. */
923*63d1fd59SEnji Cooper 	uvm_physseg_seg_chomp_slab(upm, pgs, npages);
924*63d1fd59SEnji Cooper 
925*63d1fd59SEnji Cooper 	/*
926*63d1fd59SEnji Cooper 	 * Actual pgs[] allocation, from extent.
927*63d1fd59SEnji Cooper 	 */
928*63d1fd59SEnji Cooper 	uvm_physseg_alloc_from_slab(upm, npages);
929*63d1fd59SEnji Cooper 
930*63d1fd59SEnji Cooper 	/* Now we initialize the segment */
931*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(upm, pgs);
932*63d1fd59SEnji Cooper 
933*63d1fd59SEnji Cooper 	/* Done with boot simulation */
934*63d1fd59SEnji Cooper 	extent_init();
935*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
936*63d1fd59SEnji Cooper 
937*63d1fd59SEnji Cooper 	/* We have total memory of 1MB */
938*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(PAGE_COUNT_1M, uvmexp.npages);
939*63d1fd59SEnji Cooper 
940*63d1fd59SEnji Cooper 	upm =uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
941*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
942*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
943*63d1fd59SEnji Cooper 
944*63d1fd59SEnji Cooper 	/* We added another 1MB so PAGE_COUNT_1M + PAGE_COUNT_1M */
945*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(PAGE_COUNT_1M + PAGE_COUNT_1M, uvmexp.npages);
946*63d1fd59SEnji Cooper 
947*63d1fd59SEnji Cooper }
948*63d1fd59SEnji Cooper #endif
949*63d1fd59SEnji Cooper 
950*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_start);
ATF_TC_HEAD(uvm_physseg_get_start,tc)951*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_start, tc)
952*63d1fd59SEnji Cooper {
953*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the start PFN is returned \
954*63d1fd59SEnji Cooper 	    correctly from a segment created via uvm_page_physload().");
955*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_start,tc)956*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_start, tc)
957*63d1fd59SEnji Cooper {
958*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
959*63d1fd59SEnji Cooper 
960*63d1fd59SEnji Cooper 	/* Fake early boot */
961*63d1fd59SEnji Cooper 	setup();
962*63d1fd59SEnji Cooper 
963*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
964*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
965*63d1fd59SEnji Cooper 
966*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
967*63d1fd59SEnji Cooper 
968*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
969*63d1fd59SEnji Cooper 
970*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm));
971*63d1fd59SEnji Cooper 
972*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
973*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
974*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
975*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
976*63d1fd59SEnji Cooper 
977*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
978*63d1fd59SEnji Cooper 
979*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
980*63d1fd59SEnji Cooper 
981*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm));
982*63d1fd59SEnji Cooper #endif
983*63d1fd59SEnji Cooper }
984*63d1fd59SEnji Cooper 
985*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_start_invalid);
ATF_TC_HEAD(uvm_physseg_get_start_invalid,tc)986*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_start_invalid, tc)
987*63d1fd59SEnji Cooper {
988*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \
989*63d1fd59SEnji Cooper 	    correctly when uvm_physseg_get_start() is called with invalid \
990*63d1fd59SEnji Cooper 	    parameter values.");
991*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_start_invalid,tc)992*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_start_invalid, tc)
993*63d1fd59SEnji Cooper {
994*63d1fd59SEnji Cooper 	/* Check for pgs == NULL */
995*63d1fd59SEnji Cooper 	setup();
996*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
997*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
998*63d1fd59SEnji Cooper 
999*63d1fd59SEnji Cooper 	/* Force other check conditions */
1000*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
1001*63d1fd59SEnji Cooper 
1002*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1003*63d1fd59SEnji Cooper 
1004*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1005*63d1fd59SEnji Cooper 
1006*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm.page_init_done);
1007*63d1fd59SEnji Cooper 
1008*63d1fd59SEnji Cooper 	/* Invalid uvm_physseg_t */
1009*63d1fd59SEnji Cooper 	ATF_CHECK_EQ((paddr_t) -1,
1010*63d1fd59SEnji Cooper 	    uvm_physseg_get_start(UVM_PHYSSEG_TYPE_INVALID));
1011*63d1fd59SEnji Cooper }
1012*63d1fd59SEnji Cooper 
1013*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_end);
ATF_TC_HEAD(uvm_physseg_get_end,tc)1014*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_end, tc)
1015*63d1fd59SEnji Cooper {
1016*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the end PFN is returned \
1017*63d1fd59SEnji Cooper 	    correctly from a segment created via uvm_page_physload().");
1018*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_end,tc)1019*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_end, tc)
1020*63d1fd59SEnji Cooper {
1021*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1022*63d1fd59SEnji Cooper 
1023*63d1fd59SEnji Cooper 	setup();
1024*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1025*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1026*63d1fd59SEnji Cooper 
1027*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1028*63d1fd59SEnji Cooper 
1029*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1030*63d1fd59SEnji Cooper 
1031*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm));
1032*63d1fd59SEnji Cooper 
1033*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1034*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1035*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1036*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1037*63d1fd59SEnji Cooper 
1038*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
1039*63d1fd59SEnji Cooper 
1040*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1041*63d1fd59SEnji Cooper 
1042*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm));
1043*63d1fd59SEnji Cooper #endif
1044*63d1fd59SEnji Cooper }
1045*63d1fd59SEnji Cooper 
1046*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_end_invalid);
ATF_TC_HEAD(uvm_physseg_get_end_invalid,tc)1047*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_end_invalid, tc)
1048*63d1fd59SEnji Cooper {
1049*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \
1050*63d1fd59SEnji Cooper 	    correctly when uvm_physseg_get_end() is called with invalid \
1051*63d1fd59SEnji Cooper 	    parameter values.");
1052*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_end_invalid,tc)1053*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_end_invalid, tc)
1054*63d1fd59SEnji Cooper {
1055*63d1fd59SEnji Cooper 	/* Check for pgs == NULL */
1056*63d1fd59SEnji Cooper 	setup();
1057*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1058*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1059*63d1fd59SEnji Cooper 
1060*63d1fd59SEnji Cooper 	/* Force other check conditions */
1061*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
1062*63d1fd59SEnji Cooper 
1063*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1064*63d1fd59SEnji Cooper 
1065*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1066*63d1fd59SEnji Cooper 
1067*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm.page_init_done);
1068*63d1fd59SEnji Cooper 
1069*63d1fd59SEnji Cooper 	/* Invalid uvm_physseg_t */
1070*63d1fd59SEnji Cooper 	ATF_CHECK_EQ((paddr_t) -1,
1071*63d1fd59SEnji Cooper 	    uvm_physseg_get_end(UVM_PHYSSEG_TYPE_INVALID));
1072*63d1fd59SEnji Cooper }
1073*63d1fd59SEnji Cooper 
1074*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_avail_start);
ATF_TC_HEAD(uvm_physseg_get_avail_start,tc)1075*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_avail_start, tc)
1076*63d1fd59SEnji Cooper {
1077*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the avail_start PFN is \
1078*63d1fd59SEnji Cooper 	    returned correctly from a segment created via uvm_page_physload().");
1079*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_avail_start,tc)1080*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_avail_start, tc)
1081*63d1fd59SEnji Cooper {
1082*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1083*63d1fd59SEnji Cooper 
1084*63d1fd59SEnji Cooper 	setup();
1085*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1086*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1087*63d1fd59SEnji Cooper 
1088*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1089*63d1fd59SEnji Cooper 
1090*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1091*63d1fd59SEnji Cooper 
1092*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_1, uvm_physseg_get_avail_start(upm));
1093*63d1fd59SEnji Cooper 
1094*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1095*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1096*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1097*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1098*63d1fd59SEnji Cooper 
1099*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1100*63d1fd59SEnji Cooper 
1101*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
1102*63d1fd59SEnji Cooper 
1103*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm));
1104*63d1fd59SEnji Cooper #endif
1105*63d1fd59SEnji Cooper }
1106*63d1fd59SEnji Cooper 
1107*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_avail_start_invalid);
ATF_TC_HEAD(uvm_physseg_get_avail_start_invalid,tc)1108*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_avail_start_invalid, tc)
1109*63d1fd59SEnji Cooper {
1110*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \
1111*63d1fd59SEnji Cooper 	    correctly when uvm_physseg_get_avail_start() is called with invalid\
1112*63d1fd59SEnji Cooper 	    parameter values.");
1113*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_avail_start_invalid,tc)1114*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_avail_start_invalid, tc)
1115*63d1fd59SEnji Cooper {
1116*63d1fd59SEnji Cooper 	/* Check for pgs == NULL */
1117*63d1fd59SEnji Cooper 	setup();
1118*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1119*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1120*63d1fd59SEnji Cooper 
1121*63d1fd59SEnji Cooper 	/* Force other check conditions */
1122*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
1123*63d1fd59SEnji Cooper 
1124*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1125*63d1fd59SEnji Cooper 
1126*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1127*63d1fd59SEnji Cooper 
1128*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm.page_init_done);
1129*63d1fd59SEnji Cooper 
1130*63d1fd59SEnji Cooper 	/* Invalid uvm_physseg_t */
1131*63d1fd59SEnji Cooper 	ATF_CHECK_EQ((paddr_t) -1,
1132*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_start(UVM_PHYSSEG_TYPE_INVALID));
1133*63d1fd59SEnji Cooper }
1134*63d1fd59SEnji Cooper 
1135*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_avail_end);
ATF_TC_HEAD(uvm_physseg_get_avail_end,tc)1136*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_avail_end, tc)
1137*63d1fd59SEnji Cooper {
1138*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the avail_end PFN is \
1139*63d1fd59SEnji Cooper 	    returned correctly from a segment created via uvm_page_physload().");
1140*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_avail_end,tc)1141*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_avail_end, tc)
1142*63d1fd59SEnji Cooper {
1143*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1144*63d1fd59SEnji Cooper 
1145*63d1fd59SEnji Cooper 	setup();
1146*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1147*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1148*63d1fd59SEnji Cooper 
1149*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1150*63d1fd59SEnji Cooper 
1151*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1152*63d1fd59SEnji Cooper 
1153*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1, uvm_physseg_get_avail_end(upm));
1154*63d1fd59SEnji Cooper 
1155*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1156*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1157*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1158*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1159*63d1fd59SEnji Cooper 
1160*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
1161*63d1fd59SEnji Cooper 
1162*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1163*63d1fd59SEnji Cooper 
1164*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm));
1165*63d1fd59SEnji Cooper #endif
1166*63d1fd59SEnji Cooper }
1167*63d1fd59SEnji Cooper 
1168*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_avail_end_invalid);
ATF_TC_HEAD(uvm_physseg_get_avail_end_invalid,tc)1169*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_avail_end_invalid, tc)
1170*63d1fd59SEnji Cooper {
1171*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \
1172*63d1fd59SEnji Cooper 	    correctly when uvm_physseg_get_avail_end() is called with invalid\
1173*63d1fd59SEnji Cooper 	    parameter values.");
1174*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_avail_end_invalid,tc)1175*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_avail_end_invalid, tc)
1176*63d1fd59SEnji Cooper {
1177*63d1fd59SEnji Cooper 	/* Check for pgs == NULL */
1178*63d1fd59SEnji Cooper 	setup();
1179*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1180*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1181*63d1fd59SEnji Cooper 
1182*63d1fd59SEnji Cooper 	/* Force other check conditions */
1183*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
1184*63d1fd59SEnji Cooper 
1185*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1186*63d1fd59SEnji Cooper 
1187*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1188*63d1fd59SEnji Cooper 
1189*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm.page_init_done);
1190*63d1fd59SEnji Cooper 
1191*63d1fd59SEnji Cooper 	/* Invalid uvm_physseg_t */
1192*63d1fd59SEnji Cooper 	ATF_CHECK_EQ((paddr_t) -1,
1193*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_end(UVM_PHYSSEG_TYPE_INVALID));
1194*63d1fd59SEnji Cooper }
1195*63d1fd59SEnji Cooper 
1196*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_next);
ATF_TC_HEAD(uvm_physseg_get_next,tc)1197*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_next, tc)
1198*63d1fd59SEnji Cooper {
1199*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the pointer values for next \
1200*63d1fd59SEnji Cooper 	    segment using the uvm_physseg_get_next() call.");
1201*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_next,tc)1202*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_next, tc)
1203*63d1fd59SEnji Cooper {
1204*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1205*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1206*63d1fd59SEnji Cooper 	uvm_physseg_t upm_next;
1207*63d1fd59SEnji Cooper #endif
1208*63d1fd59SEnji Cooper 
1209*63d1fd59SEnji Cooper 	/* We insert the segments in ascending order */
1210*63d1fd59SEnji Cooper 
1211*63d1fd59SEnji Cooper 	setup();
1212*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1213*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1214*63d1fd59SEnji Cooper 
1215*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1216*63d1fd59SEnji Cooper 
1217*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1218*63d1fd59SEnji Cooper 
1219*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID_OVERFLOW,
1220*63d1fd59SEnji Cooper 	    uvm_physseg_get_next(upm));
1221*63d1fd59SEnji Cooper 
1222*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1223*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1224*63d1fd59SEnji Cooper 	upm_next = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1225*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1226*63d1fd59SEnji Cooper 
1227*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1228*63d1fd59SEnji Cooper 
1229*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
1230*63d1fd59SEnji Cooper 
1231*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_next(upm); /* Fetch Next */
1232*63d1fd59SEnji Cooper 
1233*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_next, upm);
1234*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm));
1235*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm));
1236*63d1fd59SEnji Cooper #endif
1237*63d1fd59SEnji Cooper 
1238*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 3 or more segments. */
1239*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
1240*63d1fd59SEnji Cooper 	upm_next = uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3,
1241*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT);
1242*63d1fd59SEnji Cooper 
1243*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1244*63d1fd59SEnji Cooper 
1245*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(3, uvm_physseg_get_entries());
1246*63d1fd59SEnji Cooper 
1247*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_next(upm); /* Fetch Next */
1248*63d1fd59SEnji Cooper 
1249*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_next, upm);
1250*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_3, uvm_physseg_get_start(upm));
1251*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_3, uvm_physseg_get_end(upm));
1252*63d1fd59SEnji Cooper #endif
1253*63d1fd59SEnji Cooper }
1254*63d1fd59SEnji Cooper 
1255*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_next_invalid);
ATF_TC_HEAD(uvm_physseg_get_next_invalid,tc)1256*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_next_invalid, tc)
1257*63d1fd59SEnji Cooper {
1258*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \
1259*63d1fd59SEnji Cooper 	    correctly when uvm_physseg_get_next() is called with invalid \
1260*63d1fd59SEnji Cooper 	    parameter values.");
1261*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_next_invalid,tc)1262*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_next_invalid, tc)
1263*63d1fd59SEnji Cooper {
1264*63d1fd59SEnji Cooper 	uvm_physseg_t upm = UVM_PHYSSEG_TYPE_INVALID;
1265*63d1fd59SEnji Cooper 
1266*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID, uvm_physseg_get_next(upm));
1267*63d1fd59SEnji Cooper }
1268*63d1fd59SEnji Cooper 
1269*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_prev);
ATF_TC_HEAD(uvm_physseg_get_prev,tc)1270*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_prev, tc)
1271*63d1fd59SEnji Cooper {
1272*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the pointer values for previous \
1273*63d1fd59SEnji Cooper 	    segment using the uvm_physseg_get_prev() call.");
1274*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_prev,tc)1275*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_prev, tc)
1276*63d1fd59SEnji Cooper {
1277*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1278*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1279*63d1fd59SEnji Cooper #endif
1280*63d1fd59SEnji Cooper 	uvm_physseg_t upm_prev;
1281*63d1fd59SEnji Cooper 
1282*63d1fd59SEnji Cooper 
1283*63d1fd59SEnji Cooper 	setup();
1284*63d1fd59SEnji Cooper 	upm_prev = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1285*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1286*63d1fd59SEnji Cooper 
1287*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1288*63d1fd59SEnji Cooper 
1289*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1290*63d1fd59SEnji Cooper 
1291*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID_EMPTY,
1292*63d1fd59SEnji Cooper 	    uvm_physseg_get_prev(upm_prev));
1293*63d1fd59SEnji Cooper 
1294*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1295*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1296*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1297*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1298*63d1fd59SEnji Cooper 
1299*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1300*63d1fd59SEnji Cooper 
1301*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
1302*63d1fd59SEnji Cooper 
1303*63d1fd59SEnji Cooper 	/* Fetch Previous, we inserted a lower value */
1304*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_prev(upm);
1305*63d1fd59SEnji Cooper 
1306*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_prev, upm);
1307*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm));
1308*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm));
1309*63d1fd59SEnji Cooper #endif
1310*63d1fd59SEnji Cooper 
1311*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 3 or more segments. */
1312*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
1313*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3,
1314*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT);
1315*63d1fd59SEnji Cooper 
1316*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1317*63d1fd59SEnji Cooper 
1318*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(3, uvm_physseg_get_entries());
1319*63d1fd59SEnji Cooper 
1320*63d1fd59SEnji Cooper 	/*
1321*63d1fd59SEnji Cooper 	 * This will return a UVM_PHYSSEG_TYPE_INVALID_EMPTY we are at the
1322*63d1fd59SEnji Cooper 	 * lowest
1323*63d1fd59SEnji Cooper 	 */
1324*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_prev(upm);
1325*63d1fd59SEnji Cooper 
1326*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID_EMPTY, upm);
1327*63d1fd59SEnji Cooper #endif
1328*63d1fd59SEnji Cooper }
1329*63d1fd59SEnji Cooper 
1330*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_prev_invalid);
ATF_TC_HEAD(uvm_physseg_get_prev_invalid,tc)1331*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_prev_invalid, tc)
1332*63d1fd59SEnji Cooper {
1333*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \
1334*63d1fd59SEnji Cooper 	    correctly when uvm_physseg_get_prev() is called with invalid \
1335*63d1fd59SEnji Cooper 	    parameter values.");
1336*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_prev_invalid,tc)1337*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_prev_invalid, tc)
1338*63d1fd59SEnji Cooper {
1339*63d1fd59SEnji Cooper 	uvm_physseg_t upm = UVM_PHYSSEG_TYPE_INVALID;
1340*63d1fd59SEnji Cooper 
1341*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID, uvm_physseg_get_prev(upm));
1342*63d1fd59SEnji Cooper }
1343*63d1fd59SEnji Cooper 
1344*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_first);
ATF_TC_HEAD(uvm_physseg_get_first,tc)1345*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_first, tc)
1346*63d1fd59SEnji Cooper {
1347*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the pointer values for first \
1348*63d1fd59SEnji Cooper 	    segment (lowest node) using the uvm_physseg_get_first() call.");
1349*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_first,tc)1350*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_first, tc)
1351*63d1fd59SEnji Cooper {
1352*63d1fd59SEnji Cooper 	uvm_physseg_t upm = UVM_PHYSSEG_TYPE_INVALID_EMPTY;
1353*63d1fd59SEnji Cooper 	uvm_physseg_t upm_first;
1354*63d1fd59SEnji Cooper 
1355*63d1fd59SEnji Cooper 	/* Fake early boot */
1356*63d1fd59SEnji Cooper 	setup();
1357*63d1fd59SEnji Cooper 
1358*63d1fd59SEnji Cooper 	/* No nodes exist */
1359*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm, uvm_physseg_get_first());
1360*63d1fd59SEnji Cooper 
1361*63d1fd59SEnji Cooper 	upm_first = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1362*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1363*63d1fd59SEnji Cooper 
1364*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1365*63d1fd59SEnji Cooper 
1366*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1367*63d1fd59SEnji Cooper 
1368*63d1fd59SEnji Cooper 	/* Pointer to first should be the least valued node */
1369*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_first();
1370*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_first, upm);
1371*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm));
1372*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm));
1373*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm));
1374*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm));
1375*63d1fd59SEnji Cooper 
1376*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1377*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1378*63d1fd59SEnji Cooper 	/* Insert a node of lesser value */
1379*63d1fd59SEnji Cooper 	upm_first = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1380*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1381*63d1fd59SEnji Cooper 
1382*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(0, uvmexp.npages);
1383*63d1fd59SEnji Cooper 
1384*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
1385*63d1fd59SEnji Cooper 
1386*63d1fd59SEnji Cooper 	/* Pointer to first should be the least valued node */
1387*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_first();
1388*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_first, upm);
1389*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm));
1390*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm));
1391*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_1, uvm_physseg_get_avail_start(upm));
1392*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1, uvm_physseg_get_avail_end(upm));
1393*63d1fd59SEnji Cooper #endif
1394*63d1fd59SEnji Cooper 
1395*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 3 or more segments. */
1396*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
1397*63d1fd59SEnji Cooper 	/* Insert a node of higher value */
1398*63d1fd59SEnji Cooper 	upm_first =uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3,
1399*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT);
1400*63d1fd59SEnji Cooper 
1401*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(0, uvmexp.npages);
1402*63d1fd59SEnji Cooper 
1403*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(3, uvm_physseg_get_entries());
1404*63d1fd59SEnji Cooper 
1405*63d1fd59SEnji Cooper 	/* Pointer to first should be the least valued node */
1406*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_first();
1407*63d1fd59SEnji Cooper 	ATF_CHECK(upm_first != upm);
1408*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm));
1409*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm));
1410*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_1, uvm_physseg_get_avail_start(upm));
1411*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1, uvm_physseg_get_avail_end(upm));
1412*63d1fd59SEnji Cooper #endif
1413*63d1fd59SEnji Cooper }
1414*63d1fd59SEnji Cooper 
1415*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_last);
ATF_TC_HEAD(uvm_physseg_get_last,tc)1416*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_last, tc)
1417*63d1fd59SEnji Cooper {
1418*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the pointer values for last \
1419*63d1fd59SEnji Cooper 	    segment using the uvm_physseg_get_last() call.");
1420*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_last,tc)1421*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_last, tc)
1422*63d1fd59SEnji Cooper {
1423*63d1fd59SEnji Cooper 	uvm_physseg_t upm = UVM_PHYSSEG_TYPE_INVALID_EMPTY;
1424*63d1fd59SEnji Cooper 	uvm_physseg_t upm_last;
1425*63d1fd59SEnji Cooper 
1426*63d1fd59SEnji Cooper 	setup();
1427*63d1fd59SEnji Cooper 
1428*63d1fd59SEnji Cooper 	/* No nodes exist */
1429*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm, uvm_physseg_get_last());
1430*63d1fd59SEnji Cooper 
1431*63d1fd59SEnji Cooper 	upm_last = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1432*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1433*63d1fd59SEnji Cooper 
1434*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1435*63d1fd59SEnji Cooper 
1436*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1437*63d1fd59SEnji Cooper 
1438*63d1fd59SEnji Cooper 	/* Pointer to last should be the most valued node */
1439*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_last();
1440*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_last, upm);
1441*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm));
1442*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm));
1443*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_1, uvm_physseg_get_avail_start(upm));
1444*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1, uvm_physseg_get_avail_end(upm));
1445*63d1fd59SEnji Cooper 
1446*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1447*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1448*63d1fd59SEnji Cooper 	/* Insert node of greater value */
1449*63d1fd59SEnji Cooper 	upm_last = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1450*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1451*63d1fd59SEnji Cooper 
1452*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1453*63d1fd59SEnji Cooper 
1454*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
1455*63d1fd59SEnji Cooper 
1456*63d1fd59SEnji Cooper 	/* Pointer to last should be the most valued node */
1457*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_last();
1458*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_last, upm);
1459*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm));
1460*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm));
1461*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm));
1462*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm));
1463*63d1fd59SEnji Cooper #endif
1464*63d1fd59SEnji Cooper 
1465*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 3 or more segments. */
1466*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
1467*63d1fd59SEnji Cooper 	/* Insert node of greater value */
1468*63d1fd59SEnji Cooper 	upm_last = uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3,
1469*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT);
1470*63d1fd59SEnji Cooper 
1471*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1472*63d1fd59SEnji Cooper 
1473*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(3, uvm_physseg_get_entries());
1474*63d1fd59SEnji Cooper 
1475*63d1fd59SEnji Cooper 	/* Pointer to last should be the most valued node */
1476*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_last();
1477*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_last, upm);
1478*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_3, uvm_physseg_get_start(upm));
1479*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_3, uvm_physseg_get_end(upm));
1480*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_3, uvm_physseg_get_avail_start(upm));
1481*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_3, uvm_physseg_get_avail_end(upm));
1482*63d1fd59SEnji Cooper #endif
1483*63d1fd59SEnji Cooper }
1484*63d1fd59SEnji Cooper 
1485*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_valid);
ATF_TC_HEAD(uvm_physseg_valid,tc)1486*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_valid, tc)
1487*63d1fd59SEnji Cooper {
1488*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the pointer value for current \
1489*63d1fd59SEnji Cooper 	    segment is valid using the uvm_physseg_valid_p() call.");
1490*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_valid,tc)1491*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_valid, tc)
1492*63d1fd59SEnji Cooper {
1493*63d1fd59SEnji Cooper 	psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1);
1494*63d1fd59SEnji Cooper 
1495*63d1fd59SEnji Cooper 	struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages);
1496*63d1fd59SEnji Cooper 
1497*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1498*63d1fd59SEnji Cooper 
1499*63d1fd59SEnji Cooper 	setup();
1500*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1501*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1502*63d1fd59SEnji Cooper 
1503*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1504*63d1fd59SEnji Cooper 
1505*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1506*63d1fd59SEnji Cooper 
1507*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(upm, pgs);
1508*63d1fd59SEnji Cooper 
1509*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(PAGE_COUNT_1M, uvmexp.npages);
1510*63d1fd59SEnji Cooper 
1511*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(true, uvm_physseg_valid_p(upm));
1512*63d1fd59SEnji Cooper }
1513*63d1fd59SEnji Cooper 
1514*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_valid_invalid);
ATF_TC_HEAD(uvm_physseg_valid_invalid,tc)1515*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_valid_invalid, tc)
1516*63d1fd59SEnji Cooper {
1517*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests the pointer value for current \
1518*63d1fd59SEnji Cooper 	    segment is invalid using the uvm_physseg_valid_p() call.");
1519*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_valid_invalid,tc)1520*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_valid_invalid, tc)
1521*63d1fd59SEnji Cooper {
1522*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1523*63d1fd59SEnji Cooper 
1524*63d1fd59SEnji Cooper 	setup();
1525*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1526*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1527*63d1fd59SEnji Cooper 
1528*63d1fd59SEnji Cooper 	/* Force other check conditions */
1529*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
1530*63d1fd59SEnji Cooper 
1531*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm.page_init_done);
1532*63d1fd59SEnji Cooper 
1533*63d1fd59SEnji Cooper 	/* Invalid uvm_physseg_t */
1534*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(false, uvm_physseg_valid_p(UVM_PHYSSEG_TYPE_INVALID));
1535*63d1fd59SEnji Cooper 
1536*63d1fd59SEnji Cooper 	/*
1537*63d1fd59SEnji Cooper 	 * Without any pages initialized for segment, it is considered
1538*63d1fd59SEnji Cooper 	 * invalid
1539*63d1fd59SEnji Cooper 	 */
1540*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(false, uvm_physseg_valid_p(upm));
1541*63d1fd59SEnji Cooper }
1542*63d1fd59SEnji Cooper 
1543*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_highest);
ATF_TC_HEAD(uvm_physseg_get_highest,tc)1544*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_highest, tc)
1545*63d1fd59SEnji Cooper {
1546*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned PFN matches  \
1547*63d1fd59SEnji Cooper 	    the highest PFN in use by the system.");
1548*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_highest,tc)1549*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_highest, tc)
1550*63d1fd59SEnji Cooper {
1551*63d1fd59SEnji Cooper 	setup();
1552*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1553*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1554*63d1fd59SEnji Cooper 
1555*63d1fd59SEnji Cooper 	/* Only one segment so highest is the current */
1556*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1 - 1, uvm_physseg_get_highest_frame());
1557*63d1fd59SEnji Cooper 
1558*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1559*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1560*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3,
1561*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT);
1562*63d1fd59SEnji Cooper 
1563*63d1fd59SEnji Cooper 	/* PFN_3 > PFN_1 */
1564*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_3 - 1, uvm_physseg_get_highest_frame());
1565*63d1fd59SEnji Cooper #endif
1566*63d1fd59SEnji Cooper 
1567*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 3 or more segments. */
1568*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
1569*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1570*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1571*63d1fd59SEnji Cooper 
1572*63d1fd59SEnji Cooper 	/* PFN_3 > PFN_2 */
1573*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_3 - 1, uvm_physseg_get_highest_frame());
1574*63d1fd59SEnji Cooper #endif
1575*63d1fd59SEnji Cooper }
1576*63d1fd59SEnji Cooper 
1577*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_free_list);
ATF_TC_HEAD(uvm_physseg_get_free_list,tc)1578*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_free_list, tc)
1579*63d1fd59SEnji Cooper {
1580*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned Free List type \
1581*63d1fd59SEnji Cooper 	    of a segment matches the one returned from \
1582*63d1fd59SEnji Cooper 	    uvm_physseg_get_free_list() call.");
1583*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_free_list,tc)1584*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_free_list, tc)
1585*63d1fd59SEnji Cooper {
1586*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1587*63d1fd59SEnji Cooper 
1588*63d1fd59SEnji Cooper 	/* Fake early boot */
1589*63d1fd59SEnji Cooper 	setup();
1590*63d1fd59SEnji Cooper 
1591*63d1fd59SEnji Cooper 	/* Insertions are made in ascending order */
1592*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1593*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1594*63d1fd59SEnji Cooper 
1595*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VM_FREELIST_DEFAULT, uvm_physseg_get_free_list(upm));
1596*63d1fd59SEnji Cooper 
1597*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1598*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1599*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1600*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_FIRST16);
1601*63d1fd59SEnji Cooper 
1602*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VM_FREELIST_FIRST16, uvm_physseg_get_free_list(upm));
1603*63d1fd59SEnji Cooper #endif
1604*63d1fd59SEnji Cooper 
1605*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 3 or more segments. */
1606*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 2
1607*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3,
1608*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_FIRST1G);
1609*63d1fd59SEnji Cooper 
1610*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VM_FREELIST_FIRST1G, uvm_physseg_get_free_list(upm));
1611*63d1fd59SEnji Cooper #endif
1612*63d1fd59SEnji Cooper }
1613*63d1fd59SEnji Cooper 
1614*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_start_hint);
ATF_TC_HEAD(uvm_physseg_get_start_hint,tc)1615*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_start_hint, tc)
1616*63d1fd59SEnji Cooper {
1617*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned start_hint value \
1618*63d1fd59SEnji Cooper 	    of a segment matches the one returned from \
1619*63d1fd59SEnji Cooper 	    uvm_physseg_get_start_hint() call.");
1620*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_start_hint,tc)1621*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_start_hint, tc)
1622*63d1fd59SEnji Cooper {
1623*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1624*63d1fd59SEnji Cooper 
1625*63d1fd59SEnji Cooper 	setup();
1626*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1627*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1628*63d1fd59SEnji Cooper 
1629*63d1fd59SEnji Cooper 	/* Will be Zero since no specific value is set during init */
1630*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(0, uvm_physseg_get_start_hint(upm));
1631*63d1fd59SEnji Cooper }
1632*63d1fd59SEnji Cooper 
1633*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_set_start_hint);
ATF_TC_HEAD(uvm_physseg_set_start_hint,tc)1634*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_set_start_hint, tc)
1635*63d1fd59SEnji Cooper {
1636*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned start_hint value \
1637*63d1fd59SEnji Cooper 	    of a segment matches the one set by the \
1638*63d1fd59SEnji Cooper 	    uvm_physseg_set_start_hint() call.");
1639*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_set_start_hint,tc)1640*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_set_start_hint, tc)
1641*63d1fd59SEnji Cooper {
1642*63d1fd59SEnji Cooper 	psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1);
1643*63d1fd59SEnji Cooper 
1644*63d1fd59SEnji Cooper 	struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages);
1645*63d1fd59SEnji Cooper 
1646*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1647*63d1fd59SEnji Cooper 
1648*63d1fd59SEnji Cooper 	setup();
1649*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1650*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1651*63d1fd59SEnji Cooper 
1652*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(upm, pgs);
1653*63d1fd59SEnji Cooper 
1654*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(true, uvm_physseg_set_start_hint(upm, atop(128)));
1655*63d1fd59SEnji Cooper 
1656*63d1fd59SEnji Cooper 	/* Will be atop(128) since no specific value is set above */
1657*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(atop(128), uvm_physseg_get_start_hint(upm));
1658*63d1fd59SEnji Cooper }
1659*63d1fd59SEnji Cooper 
1660*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_set_start_hint_invalid);
ATF_TC_HEAD(uvm_physseg_set_start_hint_invalid,tc)1661*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_set_start_hint_invalid, tc)
1662*63d1fd59SEnji Cooper {
1663*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned value is false \
1664*63d1fd59SEnji Cooper 	    when an invalid segment matches the one trying to set by the \
1665*63d1fd59SEnji Cooper 	    uvm_physseg_set_start_hint() call.");
1666*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_set_start_hint_invalid,tc)1667*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_set_start_hint_invalid, tc)
1668*63d1fd59SEnji Cooper {
1669*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1670*63d1fd59SEnji Cooper 
1671*63d1fd59SEnji Cooper 	setup();
1672*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1673*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1674*63d1fd59SEnji Cooper 
1675*63d1fd59SEnji Cooper 	/* Force other check conditions */
1676*63d1fd59SEnji Cooper 	uvm.page_init_done = true;
1677*63d1fd59SEnji Cooper 
1678*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, uvm.page_init_done);
1679*63d1fd59SEnji Cooper 
1680*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(false, uvm_physseg_set_start_hint(upm, atop(128)));
1681*63d1fd59SEnji Cooper 
1682*63d1fd59SEnji Cooper 	/*
1683*63d1fd59SEnji Cooper 	 * Will be Zero since no specific value is set after the init
1684*63d1fd59SEnji Cooper 	 * due to failure
1685*63d1fd59SEnji Cooper 	 */
1686*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT, "invalid uvm_physseg_t handle");
1687*63d1fd59SEnji Cooper 
1688*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(0, uvm_physseg_get_start_hint(upm));
1689*63d1fd59SEnji Cooper }
1690*63d1fd59SEnji Cooper 
1691*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_pg);
ATF_TC_HEAD(uvm_physseg_get_pg,tc)1692*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_pg, tc)
1693*63d1fd59SEnji Cooper {
1694*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned vm_page struct \
1695*63d1fd59SEnji Cooper 	    is correct when fetched by uvm_physseg_get_pg() call.");
1696*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_pg,tc)1697*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_pg, tc)
1698*63d1fd59SEnji Cooper {
1699*63d1fd59SEnji Cooper 	psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1);
1700*63d1fd59SEnji Cooper 
1701*63d1fd59SEnji Cooper 	struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages);
1702*63d1fd59SEnji Cooper 
1703*63d1fd59SEnji Cooper 	struct vm_page *extracted_pg = NULL;
1704*63d1fd59SEnji Cooper 
1705*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1706*63d1fd59SEnji Cooper 
1707*63d1fd59SEnji Cooper 	setup();
1708*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1709*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1710*63d1fd59SEnji Cooper 
1711*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1712*63d1fd59SEnji Cooper 
1713*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1714*63d1fd59SEnji Cooper 
1715*63d1fd59SEnji Cooper 	/* Now we initialize the segment */
1716*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(upm, pgs);
1717*63d1fd59SEnji Cooper 
1718*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(PAGE_COUNT_1M, uvmexp.npages);
1719*63d1fd59SEnji Cooper 
1720*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(NULL, extracted_pg);
1721*63d1fd59SEnji Cooper 
1722*63d1fd59SEnji Cooper 	/* Try fetching the 5th Page in the Segment */
1723*63d1fd59SEnji Cooper 	extracted_pg = uvm_physseg_get_pg(upm, 5);
1724*63d1fd59SEnji Cooper 
1725*63d1fd59SEnji Cooper 	/* Values of phys_addr is n * PAGE_SIZE where n is the page number */
1726*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(5 * PAGE_SIZE, extracted_pg->phys_addr);
1727*63d1fd59SEnji Cooper 
1728*63d1fd59SEnji Cooper 	/* Try fetching the 113th Page in the Segment */
1729*63d1fd59SEnji Cooper 	extracted_pg = uvm_physseg_get_pg(upm, 113);
1730*63d1fd59SEnji Cooper 
1731*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(113 * PAGE_SIZE, extracted_pg->phys_addr);
1732*63d1fd59SEnji Cooper }
1733*63d1fd59SEnji Cooper 
1734*63d1fd59SEnji Cooper #ifdef __HAVE_PMAP_PHYSSEG
1735*63d1fd59SEnji Cooper ATF_TC(uvm_physseg_get_pmseg);
ATF_TC_HEAD(uvm_physseg_get_pmseg,tc)1736*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_physseg_get_pmseg, tc)
1737*63d1fd59SEnji Cooper {
1738*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned pmap_physseg \
1739*63d1fd59SEnji Cooper 	    struct is correct when fetched by uvm_physseg_get_pmseg() call.");
1740*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_physseg_get_pmseg,tc)1741*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_physseg_get_pmseg, tc)
1742*63d1fd59SEnji Cooper {
1743*63d1fd59SEnji Cooper 	psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1);
1744*63d1fd59SEnji Cooper 
1745*63d1fd59SEnji Cooper 	struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages);
1746*63d1fd59SEnji Cooper 
1747*63d1fd59SEnji Cooper 	struct pmap_physseg pmseg = { true };
1748*63d1fd59SEnji Cooper 
1749*63d1fd59SEnji Cooper 	struct pmap_physseg *extracted_pmseg = NULL;
1750*63d1fd59SEnji Cooper 
1751*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1752*63d1fd59SEnji Cooper 
1753*63d1fd59SEnji Cooper 	setup();
1754*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1755*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1756*63d1fd59SEnji Cooper 
1757*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1758*63d1fd59SEnji Cooper 
1759*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1760*63d1fd59SEnji Cooper 
1761*63d1fd59SEnji Cooper 	/* Now we initialize the segment */
1762*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(upm, pgs);
1763*63d1fd59SEnji Cooper 
1764*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(PAGE_COUNT_1M, uvmexp.npages);
1765*63d1fd59SEnji Cooper 
1766*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(NULL, extracted_pmseg);
1767*63d1fd59SEnji Cooper 
1768*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(true, pmseg.dummy_variable);
1769*63d1fd59SEnji Cooper 
1770*63d1fd59SEnji Cooper 	/* Extract the current pmseg */
1771*63d1fd59SEnji Cooper 	extracted_pmseg = uvm_physseg_get_pmseg(upm);
1772*63d1fd59SEnji Cooper 
1773*63d1fd59SEnji Cooper 	/*
1774*63d1fd59SEnji Cooper 	 * We can only check if it is not NULL
1775*63d1fd59SEnji Cooper 	 * We do not know the value it contains
1776*63d1fd59SEnji Cooper 	 */
1777*63d1fd59SEnji Cooper 	ATF_CHECK(NULL != extracted_pmseg);
1778*63d1fd59SEnji Cooper 
1779*63d1fd59SEnji Cooper 	extracted_pmseg->dummy_variable = pmseg.dummy_variable;
1780*63d1fd59SEnji Cooper 
1781*63d1fd59SEnji Cooper 	/* Invert value to ensure test integrity */
1782*63d1fd59SEnji Cooper 	pmseg.dummy_variable = false;
1783*63d1fd59SEnji Cooper 
1784*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(false, pmseg.dummy_variable);
1785*63d1fd59SEnji Cooper 
1786*63d1fd59SEnji Cooper 	extracted_pmseg = uvm_physseg_get_pmseg(upm);
1787*63d1fd59SEnji Cooper 
1788*63d1fd59SEnji Cooper 	ATF_CHECK(NULL != extracted_pmseg);
1789*63d1fd59SEnji Cooper 
1790*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(true, extracted_pmseg->dummy_variable);
1791*63d1fd59SEnji Cooper }
1792*63d1fd59SEnji Cooper #endif
1793*63d1fd59SEnji Cooper 
1794*63d1fd59SEnji Cooper ATF_TC(vm_physseg_find);
ATF_TC_HEAD(vm_physseg_find,tc)1795*63d1fd59SEnji Cooper ATF_TC_HEAD(vm_physseg_find, tc)
1796*63d1fd59SEnji Cooper {
1797*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned segment number \
1798*63d1fd59SEnji Cooper 	    is correct when an PFN is passed into uvm_physseg_find() call. \
1799*63d1fd59SEnji Cooper 	    In addition	to this the offset of the PFN from the start of \
1800*63d1fd59SEnji Cooper 	    segment is also set if the parameter is passed in as not NULL.");
1801*63d1fd59SEnji Cooper }
ATF_TC_BODY(vm_physseg_find,tc)1802*63d1fd59SEnji Cooper ATF_TC_BODY(vm_physseg_find, tc)
1803*63d1fd59SEnji Cooper {
1804*63d1fd59SEnji Cooper 	psize_t offset = (psize_t) -1;
1805*63d1fd59SEnji Cooper 
1806*63d1fd59SEnji Cooper 	uvm_physseg_t upm_first, result;
1807*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1808*63d1fd59SEnji Cooper 	uvm_physseg_t upm_second;
1809*63d1fd59SEnji Cooper #endif
1810*63d1fd59SEnji Cooper 
1811*63d1fd59SEnji Cooper 	setup();
1812*63d1fd59SEnji Cooper 
1813*63d1fd59SEnji Cooper 	upm_first = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1814*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1815*63d1fd59SEnji Cooper 
1816*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1817*63d1fd59SEnji Cooper 
1818*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1819*63d1fd59SEnji Cooper 
1820*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1821*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1822*63d1fd59SEnji Cooper 	upm_second = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1823*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1824*63d1fd59SEnji Cooper 
1825*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
1826*63d1fd59SEnji Cooper 
1827*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1828*63d1fd59SEnji Cooper #endif
1829*63d1fd59SEnji Cooper 
1830*63d1fd59SEnji Cooper 	/* Under ONE_MEGABYTE is segment upm_first */
1831*63d1fd59SEnji Cooper 	result = uvm_physseg_find(atop(ONE_MEGABYTE - 1024), NULL);
1832*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_first, result);
1833*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_start(upm_first),
1834*63d1fd59SEnji Cooper 	    uvm_physseg_get_start(result));
1835*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_end(upm_first),
1836*63d1fd59SEnji Cooper 	    uvm_physseg_get_end(result));
1837*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_avail_start(upm_first),
1838*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_start(result));
1839*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_avail_end(upm_first),
1840*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_end(result));
1841*63d1fd59SEnji Cooper 
1842*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ((psize_t) -1, offset);
1843*63d1fd59SEnji Cooper 
1844*63d1fd59SEnji Cooper 	/* This test will be triggered only if there are 2 or more segments. */
1845*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
1846*63d1fd59SEnji Cooper 	/* Over ONE_MEGABYTE is segment upm_second */
1847*63d1fd59SEnji Cooper 	result = uvm_physseg_find(atop(ONE_MEGABYTE + 8192), &offset);
1848*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_second, result);
1849*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_start(upm_second),
1850*63d1fd59SEnji Cooper 	    uvm_physseg_get_start(result));
1851*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_end(upm_second),
1852*63d1fd59SEnji Cooper 	    uvm_physseg_get_end(result));
1853*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_avail_start(upm_second),
1854*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_start(result));
1855*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_avail_end(upm_second),
1856*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_end(result));
1857*63d1fd59SEnji Cooper 
1858*63d1fd59SEnji Cooper 	/* Offset is calculated based on PAGE_SIZE */
1859*63d1fd59SEnji Cooper 	/* atop(ONE_MEGABYTE + (2 * PAGE_SIZE)) - VALID_START_PFN1  = 2 */
1860*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(2, offset);
1861*63d1fd59SEnji Cooper #else
1862*63d1fd59SEnji Cooper 	/* Under ONE_MEGABYTE is segment upm_first */
1863*63d1fd59SEnji Cooper 	result = uvm_physseg_find(atop(ONE_MEGABYTE - 12288), &offset);
1864*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(upm_first, result);
1865*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_start(upm_first),
1866*63d1fd59SEnji Cooper 	    uvm_physseg_get_start(result));
1867*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_end(upm_first),
1868*63d1fd59SEnji Cooper 	    uvm_physseg_get_end(result));
1869*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_avail_start(upm_first),
1870*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_start(result));
1871*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(uvm_physseg_get_avail_end(upm_first),
1872*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_end(result));
1873*63d1fd59SEnji Cooper 
1874*63d1fd59SEnji Cooper 	/* Offset is calculated based on PAGE_SIZE */
1875*63d1fd59SEnji Cooper 	/* atop(ONE_MEGABYTE - (3 * PAGE_SIZE)) - VALID_START_PFN1  = 253 */
1876*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(253, offset);
1877*63d1fd59SEnji Cooper #endif
1878*63d1fd59SEnji Cooper }
1879*63d1fd59SEnji Cooper 
1880*63d1fd59SEnji Cooper ATF_TC(vm_physseg_find_invalid);
ATF_TC_HEAD(vm_physseg_find_invalid,tc)1881*63d1fd59SEnji Cooper ATF_TC_HEAD(vm_physseg_find_invalid, tc)
1882*63d1fd59SEnji Cooper {
1883*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the returned segment number \
1884*63d1fd59SEnji Cooper 	    is (paddr_t) -1  when a non existant PFN is passed into \
1885*63d1fd59SEnji Cooper 	    uvm_physseg_find() call.");
1886*63d1fd59SEnji Cooper }
ATF_TC_BODY(vm_physseg_find_invalid,tc)1887*63d1fd59SEnji Cooper ATF_TC_BODY(vm_physseg_find_invalid, tc)
1888*63d1fd59SEnji Cooper {
1889*63d1fd59SEnji Cooper 	psize_t offset = (psize_t) -1;
1890*63d1fd59SEnji Cooper 
1891*63d1fd59SEnji Cooper 	setup();
1892*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
1893*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
1894*63d1fd59SEnji Cooper 
1895*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1896*63d1fd59SEnji Cooper 
1897*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1898*63d1fd59SEnji Cooper 
1899*63d1fd59SEnji Cooper 	/* No segments over 3 MB exists at the moment */
1900*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID,
1901*63d1fd59SEnji Cooper 	    uvm_physseg_find(atop(ONE_MEGABYTE * 3), NULL));
1902*63d1fd59SEnji Cooper 
1903*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ((psize_t) -1, offset);
1904*63d1fd59SEnji Cooper 
1905*63d1fd59SEnji Cooper 	/* No segments over 3 MB exists at the moment */
1906*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID,
1907*63d1fd59SEnji Cooper 	    uvm_physseg_find(atop(ONE_MEGABYTE * 3), &offset));
1908*63d1fd59SEnji Cooper 
1909*63d1fd59SEnji Cooper 	ATF_CHECK_EQ((psize_t) -1, offset);
1910*63d1fd59SEnji Cooper }
1911*63d1fd59SEnji Cooper 
1912*63d1fd59SEnji Cooper ATF_TC(uvm_page_physunload_start);
ATF_TC_HEAD(uvm_page_physunload_start,tc)1913*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physunload_start, tc)
1914*63d1fd59SEnji Cooper {
1915*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physunload()\
1916*63d1fd59SEnji Cooper 	    call works without a panic(). Unloads from Start of the segment.");
1917*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physunload_start,tc)1918*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physunload_start, tc)
1919*63d1fd59SEnji Cooper {
1920*63d1fd59SEnji Cooper 	/*
1921*63d1fd59SEnji Cooper 	 * Would uvmexp.npages reduce everytime an uvm_page_physunload is called?
1922*63d1fd59SEnji Cooper 	 */
1923*63d1fd59SEnji Cooper 	psize_t npages = (VALID_END_PFN_2 - VALID_START_PFN_2);
1924*63d1fd59SEnji Cooper 
1925*63d1fd59SEnji Cooper 	struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages);
1926*63d1fd59SEnji Cooper 
1927*63d1fd59SEnji Cooper 	paddr_t p = 0;
1928*63d1fd59SEnji Cooper 
1929*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1930*63d1fd59SEnji Cooper 
1931*63d1fd59SEnji Cooper 	setup();
1932*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1933*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
1934*63d1fd59SEnji Cooper 
1935*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1936*63d1fd59SEnji Cooper 
1937*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1938*63d1fd59SEnji Cooper 
1939*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(upm, pgs);
1940*63d1fd59SEnji Cooper 
1941*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p));
1942*63d1fd59SEnji Cooper 
1943*63d1fd59SEnji Cooper 	/*
1944*63d1fd59SEnji Cooper 	 * When called for first time, uvm_page_physload() removes the first PFN
1945*63d1fd59SEnji Cooper 	 *
1946*63d1fd59SEnji Cooper 	 * New avail start will be VALID_AVAIL_START_PFN_2 + 1
1947*63d1fd59SEnji Cooper 	 */
1948*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, atop(p));
1949*63d1fd59SEnji Cooper 
1950*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2 + 1,
1951*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_start(upm));
1952*63d1fd59SEnji Cooper 
1953*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2 + 1, uvm_physseg_get_start(upm));
1954*63d1fd59SEnji Cooper 
1955*63d1fd59SEnji Cooper 	/* Rest of the stuff should remain the same */
1956*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm));
1957*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm));
1958*63d1fd59SEnji Cooper }
1959*63d1fd59SEnji Cooper 
1960*63d1fd59SEnji Cooper ATF_TC(uvm_page_physunload_end);
ATF_TC_HEAD(uvm_page_physunload_end,tc)1961*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physunload_end, tc)
1962*63d1fd59SEnji Cooper {
1963*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physunload()\
1964*63d1fd59SEnji Cooper 	    call works without a panic(). Unloads from End of the segment.");
1965*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physunload_end,tc)1966*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physunload_end, tc)
1967*63d1fd59SEnji Cooper {
1968*63d1fd59SEnji Cooper 	/*
1969*63d1fd59SEnji Cooper 	 * Would uvmexp.npages reduce everytime an uvm_page_physunload is called?
1970*63d1fd59SEnji Cooper 	 */
1971*63d1fd59SEnji Cooper 	paddr_t p = 0;
1972*63d1fd59SEnji Cooper 
1973*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
1974*63d1fd59SEnji Cooper 
1975*63d1fd59SEnji Cooper 	setup();
1976*63d1fd59SEnji Cooper 	/* Note: start != avail_start to remove from end. */
1977*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
1978*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2 + 1, VALID_AVAIL_END_PFN_2,
1979*63d1fd59SEnji Cooper 	    VM_FREELIST_DEFAULT);
1980*63d1fd59SEnji Cooper 
1981*63d1fd59SEnji Cooper 	p = 0;
1982*63d1fd59SEnji Cooper 
1983*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
1984*63d1fd59SEnji Cooper 
1985*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
1986*63d1fd59SEnji Cooper 
1987*63d1fd59SEnji Cooper 	ATF_REQUIRE(
1988*63d1fd59SEnji Cooper 		uvm_physseg_get_avail_start(upm) != uvm_physseg_get_start(upm));
1989*63d1fd59SEnji Cooper 
1990*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p));
1991*63d1fd59SEnji Cooper 
1992*63d1fd59SEnji Cooper 	/*
1993*63d1fd59SEnji Cooper 	 * Remember if X is the upper limit the actual valid pointer is X - 1
1994*63d1fd59SEnji Cooper 	 *
1995*63d1fd59SEnji Cooper 	 * For example if 256 is the upper limit for 1MB memory, last valid
1996*63d1fd59SEnji Cooper 	 * pointer is 256 - 1 = 255
1997*63d1fd59SEnji Cooper 	 */
1998*63d1fd59SEnji Cooper 
1999*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2 - 1, atop(p));
2000*63d1fd59SEnji Cooper 
2001*63d1fd59SEnji Cooper 	/*
2002*63d1fd59SEnji Cooper 	 * When called for second time, uvm_page_physload() removes the last PFN
2003*63d1fd59SEnji Cooper 	 *
2004*63d1fd59SEnji Cooper 	 * New avail end will be VALID_AVAIL_END_PFN_2 - 1
2005*63d1fd59SEnji Cooper 	 * New end will be VALID_AVAIL_PFN_2 - 1
2006*63d1fd59SEnji Cooper 	 */
2007*63d1fd59SEnji Cooper 
2008*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2 - 1, uvm_physseg_get_avail_end(upm));
2009*63d1fd59SEnji Cooper 
2010*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2 - 1, uvm_physseg_get_end(upm));
2011*63d1fd59SEnji Cooper 
2012*63d1fd59SEnji Cooper 	/* Rest of the stuff should remain the same */
2013*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2 + 1,
2014*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_start(upm));
2015*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm));
2016*63d1fd59SEnji Cooper }
2017*63d1fd59SEnji Cooper 
2018*63d1fd59SEnji Cooper ATF_TC(uvm_page_physunload_none);
ATF_TC_HEAD(uvm_page_physunload_none,tc)2019*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physunload_none, tc)
2020*63d1fd59SEnji Cooper {
2021*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physunload()\
2022*63d1fd59SEnji Cooper 	    call works without a panic(). Does not unload from start or end \
2023*63d1fd59SEnji Cooper 	    because of non-aligned start / avail_start and end / avail_end \
2024*63d1fd59SEnji Cooper 	    respectively.");
2025*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physunload_none,tc)2026*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physunload_none, tc)
2027*63d1fd59SEnji Cooper {
2028*63d1fd59SEnji Cooper 	psize_t npages = (VALID_END_PFN_2 - VALID_START_PFN_2);
2029*63d1fd59SEnji Cooper 
2030*63d1fd59SEnji Cooper 	struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages);
2031*63d1fd59SEnji Cooper 
2032*63d1fd59SEnji Cooper 	paddr_t p = 0;
2033*63d1fd59SEnji Cooper 
2034*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
2035*63d1fd59SEnji Cooper 
2036*63d1fd59SEnji Cooper 	setup();
2037*63d1fd59SEnji Cooper 	/*
2038*63d1fd59SEnji Cooper 	 * Note: start != avail_start and end != avail_end.
2039*63d1fd59SEnji Cooper 	 *
2040*63d1fd59SEnji Cooper 	 * This prevents any unload from occuring.
2041*63d1fd59SEnji Cooper 	 */
2042*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
2043*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2 + 1, VALID_AVAIL_END_PFN_2 - 1,
2044*63d1fd59SEnji Cooper 	    VM_FREELIST_DEFAULT);
2045*63d1fd59SEnji Cooper 
2046*63d1fd59SEnji Cooper 	p = 0;
2047*63d1fd59SEnji Cooper 
2048*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
2049*63d1fd59SEnji Cooper 
2050*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
2051*63d1fd59SEnji Cooper 
2052*63d1fd59SEnji Cooper 	ATF_REQUIRE(
2053*63d1fd59SEnji Cooper 		uvm_physseg_get_avail_start(upm) != uvm_physseg_get_start(upm));
2054*63d1fd59SEnji Cooper 
2055*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(upm, pgs);
2056*63d1fd59SEnji Cooper 
2057*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(false, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p));
2058*63d1fd59SEnji Cooper 
2059*63d1fd59SEnji Cooper 	/* uvm_page_physload() will no longer unload memory */
2060*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(0, p);
2061*63d1fd59SEnji Cooper 
2062*63d1fd59SEnji Cooper 	/* Rest of the stuff should remain the same */
2063*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2 + 1,
2064*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_start(upm));
2065*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2 - 1,
2066*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_end(upm));
2067*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm));
2068*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm));
2069*63d1fd59SEnji Cooper }
2070*63d1fd59SEnji Cooper 
2071*63d1fd59SEnji Cooper ATF_TC(uvm_page_physunload_delete_start);
ATF_TC_HEAD(uvm_page_physunload_delete_start,tc)2072*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physunload_delete_start, tc)
2073*63d1fd59SEnji Cooper {
2074*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the  uvm_page_physunload() \
2075*63d1fd59SEnji Cooper 	    works when the segment gets small enough to be deleted scenario. \
2076*63d1fd59SEnji Cooper 	    NOTE: This one works deletes from start.");
2077*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physunload_delete_start,tc)2078*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physunload_delete_start, tc)
2079*63d1fd59SEnji Cooper {
2080*63d1fd59SEnji Cooper 	/*
2081*63d1fd59SEnji Cooper 	 * Would uvmexp.npages reduce everytime an uvm_page_physunload is called?
2082*63d1fd59SEnji Cooper 	 */
2083*63d1fd59SEnji Cooper 	paddr_t p = 0;
2084*63d1fd59SEnji Cooper 
2085*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
2086*63d1fd59SEnji Cooper 
2087*63d1fd59SEnji Cooper 	setup();
2088*63d1fd59SEnji Cooper 
2089*63d1fd59SEnji Cooper 	/*
2090*63d1fd59SEnji Cooper 	 * Setup the Nuke from Starting point
2091*63d1fd59SEnji Cooper 	 */
2092*63d1fd59SEnji Cooper 
2093*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_END_PFN_1 - 1, VALID_END_PFN_1,
2094*63d1fd59SEnji Cooper 	    VALID_AVAIL_END_PFN_1 - 1, VALID_AVAIL_END_PFN_1,
2095*63d1fd59SEnji Cooper 	    VM_FREELIST_DEFAULT);
2096*63d1fd59SEnji Cooper 
2097*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
2098*63d1fd59SEnji Cooper 
2099*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
2100*63d1fd59SEnji Cooper 
2101*63d1fd59SEnji Cooper 	/* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */
2102*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
2103*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
2104*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
2105*63d1fd59SEnji Cooper 
2106*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
2107*63d1fd59SEnji Cooper #endif
2108*63d1fd59SEnji Cooper 
2109*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX == 1
2110*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT,
2111*63d1fd59SEnji Cooper 	    "cannot uvm_page_physunload() the last segment");
2112*63d1fd59SEnji Cooper #endif
2113*63d1fd59SEnji Cooper 
2114*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p));
2115*63d1fd59SEnji Cooper 
2116*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_1 - 1, atop(p));
2117*63d1fd59SEnji Cooper 
2118*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(1, uvm_physseg_get_entries());
2119*63d1fd59SEnji Cooper 
2120*63d1fd59SEnji Cooper 	/* The only node now is the one we inserted second. */
2121*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_first();
2122*63d1fd59SEnji Cooper 
2123*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm));
2124*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm));
2125*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm));
2126*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm));
2127*63d1fd59SEnji Cooper }
2128*63d1fd59SEnji Cooper 
2129*63d1fd59SEnji Cooper ATF_TC(uvm_page_physunload_delete_end);
ATF_TC_HEAD(uvm_page_physunload_delete_end,tc)2130*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physunload_delete_end, tc)
2131*63d1fd59SEnji Cooper {
2132*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the  uvm_page_physunload() \
2133*63d1fd59SEnji Cooper 	    works when the segment gets small enough to be deleted scenario. \
2134*63d1fd59SEnji Cooper 	    NOTE: This one works deletes from end.");
2135*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physunload_delete_end,tc)2136*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physunload_delete_end, tc)
2137*63d1fd59SEnji Cooper {
2138*63d1fd59SEnji Cooper 	/*
2139*63d1fd59SEnji Cooper 	 * Would uvmexp.npages reduce everytime an uvm_page_physunload is called?
2140*63d1fd59SEnji Cooper 	 */
2141*63d1fd59SEnji Cooper 
2142*63d1fd59SEnji Cooper 	paddr_t p = 0;
2143*63d1fd59SEnji Cooper 
2144*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
2145*63d1fd59SEnji Cooper 
2146*63d1fd59SEnji Cooper 	setup();
2147*63d1fd59SEnji Cooper 
2148*63d1fd59SEnji Cooper 	/*
2149*63d1fd59SEnji Cooper 	 * Setup the Nuke from Ending point
2150*63d1fd59SEnji Cooper 	 */
2151*63d1fd59SEnji Cooper 
2152*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_START_PFN_1 + 2,
2153*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1 + 1, VALID_AVAIL_START_PFN_1 + 2,
2154*63d1fd59SEnji Cooper 	    VM_FREELIST_DEFAULT);
2155*63d1fd59SEnji Cooper 
2156*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
2157*63d1fd59SEnji Cooper 
2158*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
2159*63d1fd59SEnji Cooper 
2160*63d1fd59SEnji Cooper 	/* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */
2161*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
2162*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
2163*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
2164*63d1fd59SEnji Cooper 
2165*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
2166*63d1fd59SEnji Cooper #endif
2167*63d1fd59SEnji Cooper 
2168*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX == 1
2169*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT,
2170*63d1fd59SEnji Cooper 	    "cannot uvm_page_physunload() the last segment");
2171*63d1fd59SEnji Cooper #endif
2172*63d1fd59SEnji Cooper 
2173*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p));
2174*63d1fd59SEnji Cooper 
2175*63d1fd59SEnji Cooper 	p = 0;
2176*63d1fd59SEnji Cooper 
2177*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p));
2178*63d1fd59SEnji Cooper 
2179*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_1 + 2, atop(p));
2180*63d1fd59SEnji Cooper 
2181*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(1, uvm_physseg_get_entries());
2182*63d1fd59SEnji Cooper 
2183*63d1fd59SEnji Cooper 	/* The only node now is the one we inserted second. */
2184*63d1fd59SEnji Cooper 	upm = uvm_physseg_get_first();
2185*63d1fd59SEnji Cooper 
2186*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm));
2187*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm));
2188*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm));
2189*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm));
2190*63d1fd59SEnji Cooper }
2191*63d1fd59SEnji Cooper 
2192*63d1fd59SEnji Cooper ATF_TC(uvm_page_physunload_invalid);
ATF_TC_HEAD(uvm_page_physunload_invalid,tc)2193*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physunload_invalid, tc)
2194*63d1fd59SEnji Cooper {
2195*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the  uvm_page_physunload() \
2196*63d1fd59SEnji Cooper 	    fails when then Free list does not match.");
2197*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physunload_invalid,tc)2198*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physunload_invalid, tc)
2199*63d1fd59SEnji Cooper {
2200*63d1fd59SEnji Cooper 	psize_t npages = (VALID_END_PFN_2 - VALID_START_PFN_2);
2201*63d1fd59SEnji Cooper 
2202*63d1fd59SEnji Cooper 	struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages);
2203*63d1fd59SEnji Cooper 
2204*63d1fd59SEnji Cooper 	paddr_t p = 0;
2205*63d1fd59SEnji Cooper 
2206*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
2207*63d1fd59SEnji Cooper 
2208*63d1fd59SEnji Cooper 	setup();
2209*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
2210*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
2211*63d1fd59SEnji Cooper 
2212*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
2213*63d1fd59SEnji Cooper 
2214*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
2215*63d1fd59SEnji Cooper 
2216*63d1fd59SEnji Cooper 	uvm_physseg_init_seg(upm, pgs);
2217*63d1fd59SEnji Cooper 
2218*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(false, uvm_page_physunload(upm, VM_FREELIST_FIRST4G, &p));
2219*63d1fd59SEnji Cooper }
2220*63d1fd59SEnji Cooper 
2221*63d1fd59SEnji Cooper ATF_TC(uvm_page_physunload_force);
ATF_TC_HEAD(uvm_page_physunload_force,tc)2222*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physunload_force, tc)
2223*63d1fd59SEnji Cooper {
2224*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the basic \
2225*63d1fd59SEnji Cooper 	    uvm_page_physunload_force() including delete works without.");
2226*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physunload_force,tc)2227*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physunload_force, tc)
2228*63d1fd59SEnji Cooper {
2229*63d1fd59SEnji Cooper 	/*
2230*63d1fd59SEnji Cooper 	 * Would uvmexp.npages reduce everytime an uvm_page_physunload is called?
2231*63d1fd59SEnji Cooper 	 */
2232*63d1fd59SEnji Cooper 	paddr_t p = 0;
2233*63d1fd59SEnji Cooper 
2234*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
2235*63d1fd59SEnji Cooper 
2236*63d1fd59SEnji Cooper 	setup();
2237*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1,
2238*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT);
2239*63d1fd59SEnji Cooper 
2240*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
2241*63d1fd59SEnji Cooper 
2242*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
2243*63d1fd59SEnji Cooper 
2244*63d1fd59SEnji Cooper 	/* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */
2245*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
2246*63d1fd59SEnji Cooper 	/*
2247*63d1fd59SEnji Cooper 	 * We have couple of physloads done this is bacause of the fact that if
2248*63d1fd59SEnji Cooper 	 * we physunload all the PFs from a given range and we have only one
2249*63d1fd59SEnji Cooper 	 * segment in total a panic() is called
2250*63d1fd59SEnji Cooper 	 */
2251*63d1fd59SEnji Cooper 	uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2,
2252*63d1fd59SEnji Cooper 	    VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT);
2253*63d1fd59SEnji Cooper 
2254*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(2, uvm_physseg_get_entries());
2255*63d1fd59SEnji Cooper #endif
2256*63d1fd59SEnji Cooper 
2257*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX == 1
2258*63d1fd59SEnji Cooper 	atf_tc_expect_signal(SIGABRT,
2259*63d1fd59SEnji Cooper 	    "cannot uvm_page_physunload() the last segment");
2260*63d1fd59SEnji Cooper #endif
2261*63d1fd59SEnji Cooper 
2262*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(VALID_AVAIL_START_PFN_1,
2263*63d1fd59SEnji Cooper 	    uvm_physseg_get_avail_start(upm));
2264*63d1fd59SEnji Cooper 
2265*63d1fd59SEnji Cooper 	for(paddr_t i = VALID_AVAIL_START_PFN_1;
2266*63d1fd59SEnji Cooper 	    i < VALID_AVAIL_END_PFN_1; i++) {
2267*63d1fd59SEnji Cooper 		ATF_CHECK_EQ(true,
2268*63d1fd59SEnji Cooper 		    uvm_page_physunload_force(upm, VM_FREELIST_DEFAULT, &p));
2269*63d1fd59SEnji Cooper 		ATF_CHECK_EQ(i, atop(p));
2270*63d1fd59SEnji Cooper 
2271*63d1fd59SEnji Cooper 		if(i + 1 < VALID_AVAIL_END_PFN_1)
2272*63d1fd59SEnji Cooper 			ATF_CHECK_EQ(i + 1, uvm_physseg_get_avail_start(upm));
2273*63d1fd59SEnji Cooper 	}
2274*63d1fd59SEnji Cooper 
2275*63d1fd59SEnji Cooper 	/*
2276*63d1fd59SEnji Cooper 	 * Now we try to retrieve the segment, which has been removed
2277*63d1fd59SEnji Cooper 	 * from the system through force unloading all the pages inside it.
2278*63d1fd59SEnji Cooper 	 */
2279*63d1fd59SEnji Cooper 	upm = uvm_physseg_find(VALID_AVAIL_END_PFN_1 - 1, NULL);
2280*63d1fd59SEnji Cooper 
2281*63d1fd59SEnji Cooper 	/* It should no longer exist */
2282*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(NULL, upm);
2283*63d1fd59SEnji Cooper 
2284*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(1, uvm_physseg_get_entries());
2285*63d1fd59SEnji Cooper }
2286*63d1fd59SEnji Cooper 
2287*63d1fd59SEnji Cooper ATF_TC(uvm_page_physunload_force_invalid);
ATF_TC_HEAD(uvm_page_physunload_force_invalid,tc)2288*63d1fd59SEnji Cooper ATF_TC_HEAD(uvm_page_physunload_force_invalid, tc)
2289*63d1fd59SEnji Cooper {
2290*63d1fd59SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests if the invalid conditions for \
2291*63d1fd59SEnji Cooper 	    uvm_page_physunload_force_invalid().");
2292*63d1fd59SEnji Cooper }
ATF_TC_BODY(uvm_page_physunload_force_invalid,tc)2293*63d1fd59SEnji Cooper ATF_TC_BODY(uvm_page_physunload_force_invalid, tc)
2294*63d1fd59SEnji Cooper {
2295*63d1fd59SEnji Cooper 	paddr_t p = 0;
2296*63d1fd59SEnji Cooper 
2297*63d1fd59SEnji Cooper 	uvm_physseg_t upm;
2298*63d1fd59SEnji Cooper 
2299*63d1fd59SEnji Cooper 	setup();
2300*63d1fd59SEnji Cooper 	upm = uvm_page_physload(VALID_START_PFN_2, VALID_START_PFN_2+ 1,
2301*63d1fd59SEnji Cooper 	    VALID_START_PFN_2, VALID_START_PFN_2, VM_FREELIST_DEFAULT);
2302*63d1fd59SEnji Cooper 
2303*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(1, uvm_physseg_get_entries());
2304*63d1fd59SEnji Cooper 
2305*63d1fd59SEnji Cooper 	ATF_REQUIRE_EQ(0, uvmexp.npages);
2306*63d1fd59SEnji Cooper 
2307*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(false,
2308*63d1fd59SEnji Cooper 	    uvm_page_physunload_force(upm, VM_FREELIST_DEFAULT, &p));
2309*63d1fd59SEnji Cooper 
2310*63d1fd59SEnji Cooper 	ATF_CHECK_EQ(0, p);
2311*63d1fd59SEnji Cooper }
2312*63d1fd59SEnji Cooper 
ATF_TP_ADD_TCS(tp)2313*63d1fd59SEnji Cooper ATF_TP_ADD_TCS(tp)
2314*63d1fd59SEnji Cooper {
2315*63d1fd59SEnji Cooper #if defined(UVM_HOTPLUG)
2316*63d1fd59SEnji Cooper 	/* Internal */
2317*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_alloc_atboot_mismatch);
2318*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_alloc_atboot_overrun);
2319*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_alloc_sanity);
2320*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_free_atboot_mismatch);
2321*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_free_sanity);
2322*63d1fd59SEnji Cooper #if VM_PHYSSEG_MAX > 1
2323*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_atboot_free_leak);
2324*63d1fd59SEnji Cooper #endif
2325*63d1fd59SEnji Cooper #endif /* UVM_HOTPLUG */
2326*63d1fd59SEnji Cooper 
2327*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_plug);
2328*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_unplug);
2329*63d1fd59SEnji Cooper 
2330*63d1fd59SEnji Cooper 	/* Exported */
2331*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_init);
2332*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physload_preload);
2333*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physload_postboot);
2334*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_handle_immutable);
2335*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_seg_chomp_slab);
2336*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_alloc_from_slab);
2337*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_init_seg);
2338*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_start);
2339*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_start_invalid);
2340*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_end);
2341*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_end_invalid);
2342*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_avail_start);
2343*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_avail_start_invalid);
2344*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_avail_end);
2345*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_avail_end_invalid);
2346*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_next);
2347*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_next_invalid);
2348*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_prev);
2349*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_prev_invalid);
2350*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_first);
2351*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_last);
2352*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_valid);
2353*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_valid_invalid);
2354*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_highest);
2355*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_free_list);
2356*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_start_hint);
2357*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_set_start_hint);
2358*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_set_start_hint_invalid);
2359*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_pg);
2360*63d1fd59SEnji Cooper 
2361*63d1fd59SEnji Cooper #ifdef __HAVE_PMAP_PHYSSEG
2362*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_physseg_get_pmseg);
2363*63d1fd59SEnji Cooper #endif
2364*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, vm_physseg_find);
2365*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, vm_physseg_find_invalid);
2366*63d1fd59SEnji Cooper 
2367*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physunload_start);
2368*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physunload_end);
2369*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physunload_none);
2370*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physunload_delete_start);
2371*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physunload_delete_end);
2372*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physunload_invalid);
2373*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physunload_force);
2374*63d1fd59SEnji Cooper 	ATF_TP_ADD_TC(tp, uvm_page_physunload_force_invalid);
2375*63d1fd59SEnji Cooper 
2376*63d1fd59SEnji Cooper 	return atf_no_error();
2377*63d1fd59SEnji Cooper }
2378