The branch main has been updated by mhorne:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=1b5ec2e466ee100161017ae2618f91829310f1d6

commit 1b5ec2e466ee100161017ae2618f91829310f1d6
Author:     Mitchell Horne <[email protected]>
AuthorDate: 2026-07-13 19:49:32 +0000
Commit:     Mitchell Horne <[email protected]>
CommitDate: 2026-07-13 19:49:32 +0000

    subr_physmem_test: add tests for two edge-cases
    
    Help validate my assertion that "physmem will never report empty
    ranges". Part of this is covered by the existing tests, which check the
    merging of adjacent/overlapping regions. The other part is to ensure
    that addition of zero-sized ranges is ignored.
    
    The physmem implementation also includes logic to ignore the first
    physical page of memory (physical addresses 0 to PAGE_SIZE-1). Add a
    second test case for this.
    
    Reviewed by:    markj
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D45914
---
 tests/sys/kern/subr_physmem_test.c | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/tests/sys/kern/subr_physmem_test.c 
b/tests/sys/kern/subr_physmem_test.c
index 31bd30447e3b..96e608a36d72 100644
--- a/tests/sys/kern/subr_physmem_test.c
+++ b/tests/sys/kern/subr_physmem_test.c
@@ -160,11 +160,54 @@ ATF_TC_BODY(hwregion_unordered, tc)
        ATF_CHECK_EQ(avail[1], 3 * PAGE_SIZE);
 }
 
+ATF_TC_WITHOUT_HEAD(hwregion_ignore_empty);
+ATF_TC_BODY(hwregion_ignore_empty, tc)
+{
+       vm_paddr_t avail[4];
+       size_t len;
+
+       /* Add a region. */
+       physmem_hardware_region(PAGE_SIZE, 2 * PAGE_SIZE);
+
+       /* Add full zero range (ignored) */
+       physmem_hardware_region(0, 0);
+
+       /* Add a zero-sized range (ignored) */
+       physmem_hardware_region(4 * PAGE_SIZE, 0);
+
+       len = physmem_avail(avail, nitems(avail));
+       ATF_CHECK_EQ(len, 2);
+       ATF_CHECK_EQ(avail[0], PAGE_SIZE);
+       ATF_CHECK_EQ(avail[1], 3 * PAGE_SIZE);
+}
+
+ATF_TC_WITHOUT_HEAD(hwregion_ignore_page0);
+ATF_TC_BODY(hwregion_ignore_page0, tc)
+{
+       vm_paddr_t avail[4];
+       size_t len;
+
+       /*
+        * Physical addresses [0, PAGE_SIZE) are unusable in the VM layer.
+        *
+        * physmem will truncate this from the beginning of an otherwise valid
+        * memory range; test that this is the case.
+        */
+       physmem_hardware_region(0, 2 * PAGE_SIZE);
+
+       len = physmem_avail(avail, 4);
+       ATF_CHECK_EQ(len, 2);
+       ATF_CHECK_EQ(avail[0], PAGE_SIZE);
+       ATF_CHECK_EQ(avail[1], 2 * PAGE_SIZE);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
        ATF_TP_ADD_TC(tp, hwregion);
        ATF_TP_ADD_TC(tp, hwregion_exclude);
        ATF_TP_ADD_TC(tp, hwregion_unordered);
+       ATF_TP_ADD_TC(tp, hwregion_ignore_empty);
+       ATF_TP_ADD_TC(tp, hwregion_ignore_page0);
        return (atf_no_error());
 }

Reply via email to