From eb19eff19b51f0792eb98dd89f3ecd85c6bea69b Mon Sep 17 00:00:00 2001 From: Sameeh Jubran Date: Wed, 29 Jul 2026 14:19:54 +0300 Subject: [PATCH] test: cover the DMA allow list upper boundary An allow list entry covers the half-open range [addr, addr + size), so _checkAddrAgainstAllowList accepts a request when endAddr is less than or equal to allowListEndAddr. A request that fills an entry exactly is therefore legal. No test sent such a request. The basic test used a 0x1000 request against a 0x10000 entry, and the overflow tests stop at the earlier wrap guard. A change of <= to < at that comparison broke no test, but it would make the server reject every client that maps one full allowed region. Add two cases to the basic allow list test in both test suites. A request that fills the entry exactly must return WH_ERROR_OK. A request of one more byte must return WH_ERROR_ACCESS. The pair pins both sides of the upper bound. Signed-off-by: Sameeh Jubran --- test-refactor/misc/wh_test_dma.c | 11 +++++++++++ test/wh_test_dma.c | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/test-refactor/misc/wh_test_dma.c b/test-refactor/misc/wh_test_dma.c index 15e666522..919357a73 100644 --- a/test-refactor/misc/wh_test_dma.c +++ b/test-refactor/misc/wh_test_dma.c @@ -56,6 +56,17 @@ static int _whTest_DmaAllowListBasic(void) (void*)((uintptr_t)0x10000), 0x1000); WH_TEST_ASSERT_RETURN(rc == WH_ERROR_OK); + /* [addr, addr+size): exact fit is allowed, one more byte is not */ + rc = wh_Dma_CheckMemOperAgainstAllowList( + &allowList, WH_DMA_OPER_CLIENT_READ_PRE, + (void*)((uintptr_t)0x10000), 0x10000); + WH_TEST_ASSERT_RETURN(rc == WH_ERROR_OK); + + rc = wh_Dma_CheckMemOperAgainstAllowList( + &allowList, WH_DMA_OPER_CLIENT_READ_PRE, + (void*)((uintptr_t)0x10000), 0x10001); + WH_TEST_ASSERT_RETURN(rc == WH_ERROR_ACCESS); + rc = wh_Dma_CheckMemOperAgainstAllowList( &allowList, WH_DMA_OPER_CLIENT_READ_PRE, (void*)((uintptr_t)0x30000), 0x1000); diff --git a/test/wh_test_dma.c b/test/wh_test_dma.c index 88bd3db46..554ebd731 100644 --- a/test/wh_test_dma.c +++ b/test/wh_test_dma.c @@ -277,6 +277,20 @@ static int whTest_DmaAllowListBasic(void) (void*)((uintptr_t)0x10000), 0x1000); WH_TEST_ASSERT_RETURN(rc == WH_ERROR_OK); + /* An allow list entry covers [addr, addr + size). A request that fills the + * entry exactly is therefore allowed, and one more byte is not. */ + WH_TEST_PRINT(" Testing exact-fit allow list acceptance...\n"); + rc = wh_Dma_CheckMemOperAgainstAllowList( + &allowList, WH_DMA_OPER_CLIENT_READ_PRE, + (void*)((uintptr_t)0x10000), 0x10000); + WH_TEST_ASSERT_RETURN(rc == WH_ERROR_OK); + + WH_TEST_PRINT(" Testing one-byte overrun rejection...\n"); + rc = wh_Dma_CheckMemOperAgainstAllowList( + &allowList, WH_DMA_OPER_CLIENT_READ_PRE, + (void*)((uintptr_t)0x10000), 0x10001); + WH_TEST_ASSERT_RETURN(rc == WH_ERROR_ACCESS); + WH_TEST_PRINT(" Testing basic allow list rejection...\n"); rc = wh_Dma_CheckMemOperAgainstAllowList( &allowList, WH_DMA_OPER_CLIENT_READ_PRE,