@@ -301,6 +301,47 @@ int whTest_Flash(const whFlashCb* fcb, void* fctx, const void* cfg)
301301 17 * WHFU_BYTES_PER_UNIT , 8 , read_bytes ));
302302 WH_TEST_RETURN_ON_FAIL (memcmp (write_bytes , read_bytes , 8 ));
303303
304+ /* Test unaligned ReadBytes (exercises the offset_rem != 0 path) */
305+ {
306+ uint8_t pattern [WHFU_BYTES_PER_UNIT * 4 ];
307+ uint8_t readback [WHFU_BYTES_PER_UNIT * 4 ];
308+ uint32_t base_unit = 20 ;
309+ uint32_t i ;
310+
311+ for (i = 0 ; i < sizeof (pattern ); i ++ ) {
312+ pattern [i ] = (uint8_t )(0x10 + i );
313+ }
314+
315+ /* Program 4 full units at base_unit */
316+ WH_TEST_RETURN_ON_FAIL (wh_FlashUnit_ProgramBytes (fcb , fctx ,
317+ base_unit * WHFU_BYTES_PER_UNIT , sizeof (pattern ), pattern ));
318+
319+ /* offset_rem = 3: should read pattern[3..7] */
320+ memset (readback , 0 , sizeof (readback ));
321+ WH_TEST_RETURN_ON_FAIL (wh_FlashUnit_ReadBytes (fcb , fctx ,
322+ base_unit * WHFU_BYTES_PER_UNIT + 3 , 5 , readback ));
323+ WH_TEST_ASSERT_RETURN (0 == memcmp (readback , & pattern [3 ], 5 ));
324+
325+ /* offset_rem = 1: should read pattern[1..10] */
326+ memset (readback , 0 , sizeof (readback ));
327+ WH_TEST_RETURN_ON_FAIL (wh_FlashUnit_ReadBytes (fcb , fctx ,
328+ base_unit * WHFU_BYTES_PER_UNIT + 1 , 10 , readback ));
329+ WH_TEST_ASSERT_RETURN (0 == memcmp (readback , & pattern [1 ], 10 ));
330+
331+ /* offset_rem = 5: should read pattern[5..7] */
332+ memset (readback , 0 , sizeof (readback ));
333+ WH_TEST_RETURN_ON_FAIL (wh_FlashUnit_ReadBytes (fcb , fctx ,
334+ base_unit * WHFU_BYTES_PER_UNIT + 5 , 3 , readback ));
335+ WH_TEST_ASSERT_RETURN (0 == memcmp (readback , & pattern [5 ], 3 ));
336+
337+ /* Full 3-phase read: leading partial + aligned middle + trailing
338+ * offset_rem = 2, len = 21: 6 leading + 8 aligned + 7 trailing */
339+ memset (readback , 0 , sizeof (readback ));
340+ WH_TEST_RETURN_ON_FAIL (wh_FlashUnit_ReadBytes (fcb , fctx ,
341+ base_unit * WHFU_BYTES_PER_UNIT + 2 , 21 , readback ));
342+ WH_TEST_ASSERT_RETURN (0 == memcmp (readback , & pattern [2 ], 21 ));
343+ }
344+
304345 /* Erase the first partition */
305346 WH_TEST_RETURN_ON_FAIL (wh_FlashUnit_Erase (fcb , fctx ,
306347 0 , partition_units ));
0 commit comments