@@ -284,3 +284,56 @@ fn test_store_word(has_ownership: bool, a: Word, b: Word, c: Imm12) -> SimpleRes
284284
285285 Ok ( ( ) )
286286}
287+
288+ macro_rules! generate_test__memory_instance__grow_heap_by_after_reset__does_not_retain_dirty_memory_size {
289+ ( $size: expr) => {
290+ paste:: paste! {
291+ #[ test]
292+ fn [ <memory_instance__grow_heap_by_after_reset__does_not_retain_dirty_memory_size_ $size>] ( ) -> SimpleResult <( ) > {
293+ // given: a pre-initialized memory instance with $size bytes of heap memory
294+ let mut memory_instance = MemoryInstance :: new( ) ;
295+ let sp = Reg :: new( & 10 ) ;
296+ let mut hp = VM_MAX_RAM ;
297+ const SIZE : usize = $size;
298+
299+ memory_instance. grow_heap_by( sp, RegMut :: new( & mut hp) , SIZE . try_into( ) . unwrap( ) ) ?;
300+ memory_instance. write_bytes_noownerchecks(
301+ memory_instance. hp,
302+ [ 1u8 ; SIZE ] ,
303+ ) ?;
304+
305+ // when: we reset and grow the heap again, triggering the reallocation
306+ // after we grow the heap again, it should not have any memory left over from before
307+ // the reset
308+ memory_instance. reset( ) ;
309+ let mut hp = VM_MAX_RAM ;
310+ const NEW_SIZE : usize = SIZE * 3 ;
311+ memory_instance. grow_heap_by(
312+ sp,
313+ RegMut :: new( & mut hp) ,
314+ NEW_SIZE . try_into( ) . unwrap( ) ,
315+ ) ?;
316+ let heap = memory_instance. heap_raw( ) ;
317+ let heap_len = heap. len( ) ;
318+
319+ // then: we check that the heap is all zeroed out
320+ assert_eq!( heap, vec![ 0u8 ; heap_len] ) ;
321+
322+ Ok ( ( ) )
323+ }
324+ }
325+ } ;
326+ }
327+
328+ // Generate tests with different sizes
329+ macro_rules! generate_tests__memory_instance__grow_heap_by_after_reset__does_not_retain_dirty_memory_size {
330+ ( $( $size: expr) ,* ) => {
331+ $(
332+ generate_test__memory_instance__grow_heap_by_after_reset__does_not_retain_dirty_memory_size!( $size) ;
333+ ) *
334+ } ;
335+ }
336+
337+ generate_tests__memory_instance__grow_heap_by_after_reset__does_not_retain_dirty_memory_size ! (
338+ 0 , 1 , 16 , 32 , 64 , 128 , 256 , 512 , 1024 , 2048 , 4096 , 8192 , 16384 , 32768 , 65536 , 131072
339+ ) ;
0 commit comments