@@ -347,6 +347,59 @@ def test_snapshot_restore_persistence(uvm_plain_6_1, microvm_factory, snapshot_t
347347 validate_metrics (restored_vm )
348348
349349
350+ def test_snapshot_restore_incremental (uvm_plain_6_1 , microvm_factory ):
351+ """
352+ Check that hptplugged memory is persisted across snapshot/restore.
353+ """
354+ if not uvm_plain_6_1 .pci_enabled :
355+ pytest .skip (
356+ "Skip tests on MMIO transport to save time as we don't expect any difference."
357+ )
358+
359+ uvm = uvm_booted_memhp (
360+ uvm_plain_6_1 , None , microvm_factory , False , DEFAULT_CONFIG , None , None , None
361+ )
362+
363+ snapshot = uvm .snapshot_full ()
364+
365+ hotplug_count = 16
366+ hp_mem_mib_per_cycle = 1024 // hotplug_count
367+ checksums = []
368+ for i , uvm in enumerate (
369+ microvm_factory .build_n_from_snapshot (
370+ snapshot ,
371+ hotplug_count + 1 ,
372+ incremental = True ,
373+ use_snapshot_editor = True ,
374+ )
375+ ):
376+ # check checksums of previous cycles
377+ for j in range (i ):
378+ _ , checksum , _ = uvm .ssh .check_output (f"sha256sum /dev/shm/mem_hp_test_{ j } " )
379+ assert checksum == checksums [j ], f"Checksums didn't match for i={ i } j={ j } "
380+
381+ # we run hotplug_count+1 uvms to check all the checksums at the end
382+ if i >= hotplug_count :
383+ continue
384+
385+ total_hp_mem_mib = hp_mem_mib_per_cycle * (i + 1 )
386+ uvm .hotplug_memory (total_hp_mem_mib )
387+
388+ # Increase /dev/shm size as it defaults to half of the boot memory
389+ uvm .ssh .check_output (
390+ f"mount -o remount,size={ total_hp_mem_mib } M -t tmpfs tmpfs /dev/shm"
391+ )
392+
393+ uvm .ssh .check_output (
394+ f"dd if=/dev/urandom of=/dev/shm/mem_hp_test_{ i } bs=1M count={ hp_mem_mib_per_cycle } "
395+ )
396+
397+ _ , checksum , _ = uvm .ssh .check_output (f"sha256sum /dev/shm/mem_hp_test_{ i } " )
398+ checksums .append (checksum )
399+
400+ validate_metrics (uvm )
401+
402+
350403def timed_memory_hotplug (uvm , size , metrics , metric_prefix , fc_metric_name ):
351404 """Wait for all memory hotplug events to be processed"""
352405
0 commit comments