diff --git a/tests/integration_tests/functional/test_balloon.py b/tests/integration_tests/functional/test_balloon.py index cd4b3d33637..de6a14b554f 100644 --- a/tests/integration_tests/functional/test_balloon.py +++ b/tests/integration_tests/functional/test_balloon.py @@ -74,10 +74,8 @@ def make_guest_dirty_memory(ssh_connection, amount_mib=32): logger.error("while running: %s", cmd) logger.error("stdout: %s", stdout) logger.error("stderr: %s", stderr) - - cmd = "cat /tmp/fillmem_output.txt" except TimeoutExpired: - # It's ok if this expires. Some times the SSH connection + # It's ok if this expires. Sometimes the SSH connection # gets killed by the OOM killer *after* the fillmem program # started. As a result, we can ignore timeouts here. pass @@ -131,6 +129,7 @@ def test_rss_memory_lower(uvm_plain_any): # Start the microvm. test_microvm.start() + test_microvm.wait_for_up() _test_rss_memory_lower(test_microvm) @@ -152,6 +151,7 @@ def test_inflate_reduces_free(uvm_plain_any): # Start the microvm test_microvm.start() + test_microvm.wait_for_up() firecracker_pid = test_microvm.firecracker_pid # Get the free memory before ballooning. @@ -303,6 +303,7 @@ def test_size_reduction(uvm_plain_any): # Start the microvm. test_microvm.start() + test_microvm.wait_for_up() firecracker_pid = test_microvm.firecracker_pid # Check memory usage. @@ -340,16 +341,28 @@ def test_stats(uvm_plain_any): # Add a memory balloon with stats enabled. test_microvm.api.balloon.put( - amount_mib=0, deflate_on_oom=True, stats_polling_interval_s=1 + amount_mib=0, + deflate_on_oom=True, + stats_polling_interval_s=STATS_POLLING_INTERVAL_S, ) # Start the microvm. test_microvm.start() + test_microvm.wait_for_up() firecracker_pid = test_microvm.firecracker_pid + # Give Firecracker enough time to poll the stats at least once post-boot + time.sleep(STATS_POLLING_INTERVAL_S * 2) + # Get an initial reading of the stats. initial_stats = test_microvm.api.balloon_stats.get().json() + # Major faults happen when a page fault has to be satisfied from disk. They are not + # triggered by our `make_guest_dirty_memory` workload, as it uses MAP_ANONYMOUS, which + # only triggers minor faults. However, during the boot process, things are read from the + # rootfs, so we should at least see a non-zero number of major faults. + assert initial_stats["major_faults"] > 0 + # Dirty 10MB of pages. make_guest_dirty_memory(test_microvm.ssh, amount_mib=10) time.sleep(1) @@ -359,7 +372,6 @@ def test_stats(uvm_plain_any): # Make sure that the stats catch the page faults. after_workload_stats = test_microvm.api.balloon_stats.get().json() assert initial_stats.get("minor_faults", 0) < after_workload_stats["minor_faults"] - assert initial_stats.get("major_faults", 0) < after_workload_stats["major_faults"] # Now inflate the balloon with 10MB of pages. test_microvm.api.balloon.patch(amount_mib=10) @@ -405,6 +417,7 @@ def test_stats_update(uvm_plain_any): # Start the microvm. test_microvm.start() + test_microvm.wait_for_up() firecracker_pid = test_microvm.firecracker_pid # Dirty 30MB of pages. @@ -456,6 +469,7 @@ def test_balloon_snapshot(microvm_factory, guest_kernel, rootfs): ) vm.start() + vm.wait_for_up() # Dirty 60MB of pages. make_guest_dirty_memory(vm.ssh, amount_mib=60) @@ -520,24 +534,6 @@ def test_balloon_snapshot(microvm_factory, guest_kernel, rootfs): assert stats_after_snap["available_memory"] > latest_stats["available_memory"] -def test_snapshot_compatibility(microvm_factory, guest_kernel, rootfs): - """ - Test that the balloon serializes correctly. - """ - vm = microvm_factory.build(guest_kernel, rootfs) - vm.spawn() - vm.basic_config( - vcpu_count=2, - mem_size_mib=256, - ) - - # Add a memory balloon with stats enabled. - vm.api.balloon.put(amount_mib=0, deflate_on_oom=True, stats_polling_interval_s=1) - - vm.start() - vm.snapshot_full() - - def test_memory_scrub(microvm_factory, guest_kernel, rootfs): """ Test that the memory is zeroed after deflate. @@ -553,6 +549,7 @@ def test_memory_scrub(microvm_factory, guest_kernel, rootfs): ) microvm.start() + microvm.wait_for_up() # Dirty 60MB of pages. make_guest_dirty_memory(microvm.ssh, amount_mib=60) diff --git a/tests/integration_tests/functional/test_cmd_line_start.py b/tests/integration_tests/functional/test_cmd_line_start.py index 82425458e89..79793c2157d 100644 --- a/tests/integration_tests/functional/test_cmd_line_start.py +++ b/tests/integration_tests/functional/test_cmd_line_start.py @@ -7,7 +7,6 @@ import platform import re import shutil -import time from pathlib import Path import pytest @@ -164,7 +163,7 @@ def test_config_start_no_api_exit(uvm_plain, vm_config_file): test_microvm.jailer.extra_args.update({"no-api": None}) test_microvm.spawn() # Start Firecracker and MicroVM - time.sleep(3) # Wait for startup + test_microvm.wait_for_up() test_microvm.ssh.run("reboot") # Exit test_microvm.mark_killed() # waits for process to terminate @@ -266,7 +265,7 @@ def test_config_start_with_limit(uvm_plain, vm_config_file): response += '{ "error": "Request payload with size 260 is larger than ' response += "the limit of 250 allowed by server.\n" response += 'All previous unanswered requests will be dropped." }' - _, stdout, _stderr = utils.check_output(cmd) + _, stdout, _ = utils.check_output(cmd) assert stdout.encode("utf-8") == response.encode("utf-8") @@ -420,8 +419,7 @@ def test_config_start_and_mmds_with_api(uvm_plain, vm_config_file): # Network namespace has already been created. test_microvm.spawn() - - assert test_microvm.state == "Running" + test_microvm.wait_for_up() data_store = { "latest": { @@ -434,7 +432,7 @@ def test_config_start_and_mmds_with_api(uvm_plain, vm_config_file): assert response.json() == {} # Populate MMDS with data. - response = test_microvm.api.mmds.put(**data_store) + test_microvm.api.mmds.put(**data_store) # Ensure the MMDS contents have been successfully updated. response = test_microvm.api.mmds.get() @@ -480,6 +478,7 @@ def test_with_config_and_metadata_no_api(uvm_plain, vm_config_file, metadata_fil _configure_network_interface(test_microvm) test_microvm.jailer.extra_args.update({"no-api": None}) test_microvm.spawn() + test_microvm.wait_for_up() # Get MMDS version and IPv4 address configured from the file. version, ipv4_address = _get_optional_fields_from_file(vm_config_file)