Skip to content

Commit fa4fe9d

Browse files
committed
test(balloon): enable secret_free on all balloon tests
Add the secret_free fixture parameter to all balloon functional tests, so they run with both SF_OFF and SF_ON variants. This exercises the fallocate(PUNCH_HOLE) discard path for guest_memfd-backed memory during balloon inflate/deflate. Signed-off-by: Jack Thomson <jackabt@amazon.com>
1 parent 160e374 commit fa4fe9d

1 file changed

Lines changed: 25 additions & 33 deletions

File tree

tests/integration_tests/functional/test_balloon.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ def _test_rss_memory_lower(test_microvm):
9393

9494

9595
# pylint: disable=C0103
96-
def test_rss_memory_lower(uvm_plain_any):
96+
def test_rss_memory_lower(uvm_plain_any, secret_free):
9797
"""
9898
Test that inflating the balloon makes guest use less rss memory.
9999
"""
100100
test_microvm = uvm_plain_any
101101
test_microvm.spawn()
102-
test_microvm.basic_config()
102+
test_microvm.basic_config(secret_free=secret_free)
103103
test_microvm.add_net_iface()
104104

105105
# Add a memory balloon.
@@ -114,13 +114,13 @@ def test_rss_memory_lower(uvm_plain_any):
114114

115115

116116
# pylint: disable=C0103
117-
def test_inflate_reduces_free(uvm_plain_any):
117+
def test_inflate_reduces_free(uvm_plain_any, secret_free):
118118
"""
119119
Check that the output of free in guest changes with inflate.
120120
"""
121121
test_microvm = uvm_plain_any
122122
test_microvm.spawn()
123-
test_microvm.basic_config()
123+
test_microvm.basic_config(secret_free=secret_free)
124124
test_microvm.add_net_iface()
125125

126126
# Install deflated balloon.
@@ -150,7 +150,7 @@ def test_inflate_reduces_free(uvm_plain_any):
150150

151151
# pylint: disable=C0103
152152
@pytest.mark.parametrize("deflate_on_oom", [True, False])
153-
def test_deflate_on_oom(uvm_plain_any, deflate_on_oom):
153+
def test_deflate_on_oom(uvm_plain_any, secret_free, deflate_on_oom):
154154
"""
155155
Verify that setting the `deflate_on_oom` option works correctly.
156156
@@ -167,7 +167,7 @@ def test_deflate_on_oom(uvm_plain_any, deflate_on_oom):
167167

168168
test_microvm = uvm_plain_any
169169
test_microvm.spawn()
170-
test_microvm.basic_config()
170+
test_microvm.basic_config(secret_free=secret_free)
171171
test_microvm.add_net_iface()
172172

173173
# Add a deflated memory balloon.
@@ -215,13 +215,13 @@ def test_deflate_on_oom(uvm_plain_any, deflate_on_oom):
215215

216216

217217
# pylint: disable=C0103
218-
def test_reinflate_balloon(uvm_plain_any):
218+
def test_reinflate_balloon(uvm_plain_any, secret_free):
219219
"""
220220
Verify that repeatedly inflating and deflating the balloon works.
221221
"""
222222
test_microvm = uvm_plain_any
223223
test_microvm.spawn()
224-
test_microvm.basic_config()
224+
test_microvm.basic_config(secret_free=secret_free)
225225
test_microvm.add_net_iface()
226226

227227
# Add a deflated memory balloon.
@@ -280,13 +280,13 @@ def test_reinflate_balloon(uvm_plain_any):
280280

281281

282282
# pylint: disable=C0103
283-
def test_stats(uvm_plain_any):
283+
def test_stats(uvm_plain_any, secret_free):
284284
"""
285285
Verify that balloon stats work as expected.
286286
"""
287287
test_microvm = uvm_plain_any
288288
test_microvm.spawn()
289-
test_microvm.basic_config()
289+
test_microvm.basic_config(secret_free=secret_free)
290290
test_microvm.add_net_iface()
291291

292292
# Add a memory balloon with stats enabled.
@@ -351,13 +351,13 @@ def test_stats(uvm_plain_any):
351351
check_guest_dmesg_for_stalls(test_microvm.ssh)
352352

353353

354-
def test_stats_update(uvm_plain_any):
354+
def test_stats_update(uvm_plain_any, secret_free):
355355
"""
356356
Verify that balloon stats update correctly.
357357
"""
358358
test_microvm = uvm_plain_any
359359
test_microvm.spawn()
360-
test_microvm.basic_config()
360+
test_microvm.basic_config(secret_free=secret_free)
361361
test_microvm.add_net_iface()
362362

363363
# Add a memory balloon with stats enabled.
@@ -403,7 +403,7 @@ def test_stats_update(uvm_plain_any):
403403
check_guest_dmesg_for_stalls(test_microvm.ssh)
404404

405405

406-
def test_balloon_snapshot(uvm_plain_any, microvm_factory):
406+
def test_balloon_snapshot(uvm_plain_any, secret_free, microvm_factory):
407407
"""
408408
Test that the balloon works after pause/resume.
409409
"""
@@ -415,6 +415,7 @@ def test_balloon_snapshot(uvm_plain_any, microvm_factory):
415415
vm.basic_config(
416416
vcpu_count=2,
417417
mem_size_mib=256,
418+
secret_free=secret_free,
418419
)
419420
vm.add_net_iface()
420421

@@ -437,11 +438,8 @@ def test_balloon_snapshot(uvm_plain_any, microvm_factory):
437438
# Now inflate the balloon with 20MB of pages.
438439
vm.api.balloon.patch(amount_mib=20)
439440

440-
# Check memory usage again.
441+
# Check memory usage again — should decrease (balloon reclaimed pages).
441442
second_reading = get_stable_rss_mem(vm)
442-
443-
# There should be a reduction in RSS, but it's inconsistent.
444-
# We only test that the reduction happens.
445443
assert first_reading > second_reading
446444

447445
snapshot = vm.snapshot_full()
@@ -461,18 +459,15 @@ def test_balloon_snapshot(uvm_plain_any, microvm_factory):
461459
# Dirty 60MB of pages.
462460
make_guest_dirty_memory(microvm.ssh, amount_mib=60)
463461

464-
# Check memory usage.
462+
# Check memory usage — should increase (guest used more memory).
465463
fourth_reading = get_stable_rss_mem(microvm)
466-
467464
assert fourth_reading > third_reading
468465

469466
# Inflate the balloon with another 20MB of pages.
470467
microvm.api.balloon.patch(amount_mib=40)
471468

469+
# Should decrease again (balloon reclaimed pages).
472470
fifth_reading = get_stable_rss_mem(microvm)
473-
474-
# There should be a reduction in RSS, but it's inconsistent.
475-
# We only test that the reduction happens.
476471
assert fourth_reading > fifth_reading
477472

478473
# Get the stats after we take a snapshot and dirty some memory,
@@ -488,7 +483,9 @@ def test_balloon_snapshot(uvm_plain_any, microvm_factory):
488483

489484

490485
@pytest.mark.parametrize("method", ["reporting", "hinting"])
491-
def test_hinting_reporting_snapshot(uvm_plain_any, microvm_factory, method):
486+
def test_hinting_reporting_snapshot(
487+
uvm_plain_any, secret_free, microvm_factory, method
488+
):
492489
"""
493490
Test that the balloon hinting and reporting works after pause/resume.
494491
"""
@@ -500,6 +497,7 @@ def test_hinting_reporting_snapshot(uvm_plain_any, microvm_factory, method):
500497
vm.basic_config(
501498
vcpu_count=2,
502499
mem_size_mib=256,
500+
secret_free=secret_free,
503501
)
504502
vm.add_net_iface()
505503

@@ -534,11 +532,8 @@ def test_hinting_reporting_snapshot(uvm_plain_any, microvm_factory, method):
534532
if free_page_hinting:
535533
vm.api.balloon_hinting_start.patch()
536534

537-
# Check memory usage again.
535+
# Check memory usage again — should decrease (pages freed + hinted/reported).
538536
second_reading = get_stable_rss_mem(vm)
539-
540-
# There should be a reduction in RSS, but it's inconsistent.
541-
# We only test that the reduction happens.
542537
assert first_reading > second_reading
543538

544539
snapshot = vm.snapshot_full()
@@ -565,23 +560,20 @@ def test_hinting_reporting_snapshot(uvm_plain_any, microvm_factory, method):
565560
if free_page_hinting:
566561
microvm.api.balloon_hinting_start.patch()
567562

568-
# Check memory usage again.
563+
# Check memory usage again — should decrease.
569564
fourth_reading = get_stable_rss_mem(microvm)
570-
571-
# There should be a reduction in RSS, but it's inconsistent.
572-
# We only test that the reduction happens.
573565
assert third_reading > fourth_reading
574566
check_guest_dmesg_for_stalls(microvm.ssh)
575567

576568

577569
@pytest.mark.parametrize("method", ["traditional", "hinting", "reporting"])
578-
def test_memory_scrub(uvm_plain_any, method):
570+
def test_memory_scrub(uvm_plain_any, secret_free, method):
579571
"""
580572
Test that the memory is zeroed after deflate.
581573
"""
582574
microvm = uvm_plain_any
583575
microvm.spawn()
584-
microvm.basic_config(vcpu_count=2, mem_size_mib=256)
576+
microvm.basic_config(vcpu_count=2, mem_size_mib=256, secret_free=secret_free)
585577
microvm.add_net_iface()
586578

587579
free_page_reporting = method == "reporting"

0 commit comments

Comments
 (0)