YAY!! finally I get to meet with the project. so basically this is the problem statement

The current uvm implementation in NetBSD is unaware of changes to (increase or
decrease) physical memory size. This is due to the way the memory pages are
statically allocated during the kernel boot time and a list of free pages are
maintained in a static array along with a set of properties (tags).

The Static Array implementation of vm_physseg which gets initializated during
boot time has the definition sitting in uvm_page.c

/*
 * physical memory config is stored in vm_physmem.
 */

struct vm_physseg vm_physmem[VM_PHYSSEG_MAX];   /* XXXCDC: uvm.physmem */
int vm_nphysseg = 0;                            /* XXXCDC: uvm.nphysseg */
#define vm_nphysmem     vm_nphysseg

This implementation prevents any additional run-time modification either by
expanding or collapse this array. Cherry (cherry@) has been trying to
implement a wrapper API over this which would encapsulate this data structure
and give it a more clean and neat API calls which would eventually replace the
current static array implementation.

My job in this specific project would be to assist him in testing the new
API. This meant writing test cases via ATF to assess the API usability and
explose and fix flaws that occur during the development.

Parts the code which contained the ATF test cases.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
diff -r 0b3902dbe274 -r cb1739927d33 tests/sys/uvm/t_uvm_physseg.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sys/uvm/t_uvm_physseg.c	Mon Apr 25 21:38:49 2016 +0900
@@ -0,0 +1,429 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2015, 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Cherry G. Mathew
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD$");
+
+/* Testing API - assumes userland */
+/* Provide Kernel API equivalents */
+#include <assert.h>
+#include <stdbool.h>
+#include <string.h> /* memset(3) et. al */
+#include <stdio.h> /* printf(3) */
+#include <stdlib.h> /* malloc(3) */
+#include <stdarg.h>
+
+#define	KASSERT(a)		assert(a)
+
+#define VM_PHYSSEG_MAX 1 /* machine/vmparam.h */
+#define VM_FREELIST_DEFAULT ((struct uvm_physseg_prop) { UVM_PHYS_PROP_GROUP_DMA, { UVM_PHYSSEG_DMA_CAT1 } })
+#define	VM_PHYSMEM_PTR(i)	(&vm_physmem[i])
+
+#define kmem_alloc(size, flags) malloc(size)
+#define kmem_free(p, size) do { } while (0) /* free(p) XXX: pgs management needs more thought */
+
+static void
+panic(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+	printf("\n");
+	va_end(ap);
+
+	/*NOTREACHED*/
+}
+
+/* end - Provide Kernel API equivalents */
+
+/* "MD" definitions:
+ *  For kernel builds, this is defined in MD headers
+ *  $arch/include/uvm_physseg.h
+ */
+
+
+enum uvm_physseg_dma {
+	UVM_PHYSSEG_DMA_CAT1, /* Arbitrary category #1 */
+	UVM_PHYSSEG_DMA_CAT2, /* Arbitrary category #2 */
+};
+
+enum uvm_physseg_cpu {
+	UVM_PHYSSEG_CPU_XXX,
+	/* XXX: */
+};
+enum uvm_physseg_contig {
+	UVM_PHYSSEG_CONTIG_XXX,
+	/* XXX: */
+};
+enum uvm_physseg_persist {
+	UVM_PHYSSEG_PERSIST_XXX,
+	/* XXX: */
+};
+
+typedef enum uvm_physseg_dma uvm_physseg_dma_t;
+typedef enum uvm_physseg_cpu uvm_physseg_cpu_t;
+typedef enum uvm_physseg_contig uvm_physseg_contig_t;
+typedef enum uvm_physseg_persist uvm_physseg_persist_t;
+
+#include <uvm/uvm_physseg.h>
+
+
+#include "uvm/uvm_physseg.c"
+
+#include <atf-c.h>
+
+ATF_TC(uvm_physseg_plug);
+ATF_TC_HEAD(uvm_physseg_plug, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for usable and valid struct vm_physseg");
+}
+ATF_TC_BODY(uvm_physseg_plug, tc)
+{
+
+	struct uvm_physseg *seg;
+	sfn_t start, end, avail_start, avail_end;
+
+	/* props[] check - single item */
+	struct uvm_physseg_prop props[UVM_PHYSSEG_TYPE_COUNT] = {
+		{
+			UVM_PHYSSEG_DMA,
+			{
+				UVM_PHYSSEG_DMA_CAT1
+			}
+		}
+	};
+
+	start = avail_start = 0;
+	end = avail_end = (sfn_t) -1;
+	seg = uvm_physseg_plug(start, end,
+	    avail_start, avail_end, props);
+
+	ATF_CHECK(seg != NULL);
+
+	uvm_physseg_unplug(seg); /* Hopefully DTRT */
+
+
+	/* props[] check - duplicate */
+	struct uvm_physseg_prop dupprops[UVM_PHYSSEG_TYPE_COUNT] = {
+		{
+			UVM_PHYSSEG_DMA,
+			{
+				UVM_PHYSSEG_DMA_CAT1
+			}
+		},
+		/* Duplicate */
+		{
+			UVM_PHYSSEG_DMA,
+			{
+				UVM_PHYSSEG_DMA_CAT1
+			}
+		}
+
+	};
+
+	seg = uvm_physseg_plug(start, end,
+	    avail_start, avail_end, dupprops);
+
+	ATF_CHECK(seg == NULL);
+
+	uvm_physseg_unplug(seg); /* Hopefully DTRT */
+
+	/* props[] check - non-duplicate multi param */
+	struct uvm_physseg_prop nondupprops[UVM_PHYSSEG_TYPE_COUNT] = {
+		{
+			UVM_PHYSSEG_DMA,
+			{
+				UVM_PHYSSEG_DMA_CAT1
+			}
+		},
+		/* non-duplicate, property #2 */
+		{
+			UVM_PHYSSEG_CONTIG,
+			{
+				UVM_PHYSSEG_DMA_CAT1
+			}
+		},
+
+		/* non-duplicate, property #3  - order inverted. */
+		{
+			UVM_PHYSSEG_CPU,
+			{
+				UVM_PHYSSEG_DMA_CAT1
+			}
+		}
+
+	};
+
+	seg = uvm_physseg_plug(start, end,
+	    avail_start, avail_end, nondupprops);
+
+	ATF_CHECK(seg != NULL);
+
+	uvm_physseg_unplug(seg); /* Hopefully DTRT */
+
+
+	/* Case #0: seg->prop[] sanity. */
+
+	/* Case #1: backing seg->pgs are all allocated. */
+	/* Case #2: valid seg->lastpg */
+	/* Case #3: start, end, avail_start >= start, avail_end <=end */
+
+}
+
+ATF_TC(uvm_physseg_unplug);
+ATF_TC_HEAD(uvm_physseg_unplug, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for teardown of usable and valid struct vm_physseg");
+}
+ATF_TC_BODY(uvm_physseg_unplug, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_insert);
+ATF_TC_HEAD(uvm_physseg_insert, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for proper insertion of a segment");
+}
+ATF_TC_BODY(uvm_physseg_insert, tc)
+{
+	/* Case #1b: insert discontiguous - test fragments */
+	/* Case #1d: insert contiguous and coalesce - test no fragments */
+	/* XXX */
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_valid);
+ATF_TC_HEAD(uvm_physseg_valid, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for checking the validity of an inserted or initialised segment");
+}
+
+ATF_TC_BODY(uvm_physseg_valid, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_delete);
+ATF_TC_HEAD(uvm_physseg_delete, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for proper deletion of a segment");
+	/* Case #1c: delete discontiguous - test no fragments */
+	/* Case #1e: delete contiguous and fragment - test fragments */
+}
+
+ATF_TC_BODY(uvm_physseg_delete, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_start);
+ATF_TC_HEAD(uvm_physseg_start, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for checking the start address of a valid segment");
+}
+ATF_TC_BODY(uvm_physseg_start, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_size);
+ATF_TC_HEAD(uvm_physseg_size, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for checking the size of a valid segment");
+
+}
+ATF_TC_BODY(uvm_physseg_size, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_avail_start);
+ATF_TC_HEAD(uvm_physseg_avail_start, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for checking the \"available\" start address of a valid segment");
+}
+ATF_TC_BODY(uvm_physseg_avail_start, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_avail_size);
+ATF_TC_HEAD(uvm_physseg_avail_size, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for checking the \"available\" size of a valid segment");
+}
+ATF_TC_BODY(uvm_physseg_avail_size, tc)
+{
+	struct uvm_physseg *seg;
+	sfn_t start, end, avail_start, avail_end;
+
+	/* props[] check - single item */
+	struct uvm_physseg_prop props[UVM_PHYSSEG_TYPE_COUNT] = {
+		{
+			UVM_PHYSSEG_DMA,
+			{
+				UVM_PHYSSEG_DMA_CAT1
+			}
+		}
+	};
+
+	start = avail_start = 0;
+	end = avail_end = (sfn_t) -1;
+	seg = uvm_physseg_plug(start, end,
+	    avail_start, avail_end, props);
+
+	KASSERT(uvm_physseg_avail_start(seg) == avail_start);
+
+	/* XXX: math that changes avail_start */
+}
+
+ATF_TC(uvm_physseg_first);
+ATF_TC_HEAD(uvm_physseg_first, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for fetching the first segment");
+}
+ATF_TC_BODY(uvm_physseg_first, tc)
+{
+	struct uvm_physseg *seg1, *seg2;
+	sfn_t start, end, avail_start, avail_end;
+
+	/* props[] check - single item */
+	struct uvm_physseg_prop props[UVM_PHYSSEG_TYPE_COUNT] = {
+		{
+			UVM_PHYSSEG_DMA,
+			{
+				UVM_PHYSSEG_DMA_CAT1
+			}
+		}
+	};
+
+	start = avail_start = 0;
+	end = avail_end = (sfn_t) -1 / 2;
+	seg1 = uvm_physseg_plug(start, end,
+	    avail_start, avail_end, props);
+
+	(void) seg1; /* Keep the compiler happy */
+
+	/* Vet it */
+	uvm_physseg_t firstseg;
+	firstseg = uvm_physseg_first();
+
+	/* Must be valid */
+	KASSERT(uvm_physseg_valid(firstseg));
+
+	/* Must match seg1 */
+	KASSERT(uvm_physseg_start(firstseg) == start);
+	KASSERT(uvm_physseg_avail_start(firstseg) == avail_start);
+	KASSERT(uvm_physseg_end(firstseg) == end);
+	KASSERT(uvm_physseg_avail_end(firstseg) == avail_end);
+
+	start = avail_start = (sfn_t) -1 / 2 + 1;
+	end = avail_end = (sfn_t) -1 / 2;
+	seg2 = uvm_physseg_plug(start, end,
+	    avail_start, avail_end, props);
+
+	(void) seg2; /* Keep the compiler happy */
+
+	/* Vet it again */
+	firstseg = uvm_physseg_first();
+
+	/* Must be valid */
+	KASSERT(uvm_physseg_valid(firstseg));
+
+	/* Must match seg1 */
+	KASSERT(uvm_physseg_start(firstseg) == start);
+	KASSERT(uvm_physseg_avail_start(firstseg) == avail_start);
+	KASSERT(uvm_physseg_end(firstseg) == end);
+	KASSERT(uvm_physseg_avail_end(firstseg) == avail_end);
+
+}
+
+ATF_TC(uvm_physseg_last);
+ATF_TC_HEAD(uvm_physseg_last, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for fetching the last segment");
+}
+ATF_TC_BODY(uvm_physseg_last, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_next);
+ATF_TC_HEAD(uvm_physseg_next, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for fetching the next segment");
+}
+ATF_TC_BODY(uvm_physseg_next, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_prev);
+ATF_TC_HEAD(uvm_physseg_prev, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for fetching the previous segment");
+}
+ATF_TC_BODY(uvm_physseg_prev, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TC(uvm_physseg_find);
+ATF_TC_HEAD(uvm_physseg_find, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "test for finding a segment");
+}
+ATF_TC_BODY(uvm_physseg_find, tc)
+{
+	KASSERT(!"Not Implemented");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, uvm_physseg_plug);
+	ATF_TP_ADD_TC(tp, uvm_physseg_unplug);
+	ATF_TP_ADD_TC(tp, uvm_physseg_insert);
+	ATF_TP_ADD_TC(tp, uvm_physseg_valid);
+	ATF_TP_ADD_TC(tp, uvm_physseg_delete);
+	ATF_TP_ADD_TC(tp, uvm_physseg_start);
+	ATF_TP_ADD_TC(tp, uvm_physseg_size);
+	ATF_TP_ADD_TC(tp, uvm_physseg_avail_start);
+	ATF_TP_ADD_TC(tp, uvm_physseg_avail_size);
+	ATF_TP_ADD_TC(tp, uvm_physseg_first);
+	ATF_TP_ADD_TC(tp, uvm_physseg_last);
+	ATF_TP_ADD_TC(tp, uvm_physseg_next);
+	ATF_TP_ADD_TC(tp, uvm_physseg_prev);
+	ATF_TP_ADD_TC(tp, uvm_physseg_find);
+
+	return atf_no_error();
+}

Cherry shared with me a skeleton ATF test case which I would use to build my
test cases upon. He also exported the uvm_physseg.c API into user space by
stubbing the various Kernel API calls so that I could test the existing API
without worry too much about how the various calls work.

This also meant I need to dig deep into ATF to learn how testing goes about in
the world of NetBSD.