Skip to content

Commit 04708b2

Browse files
committed
test(snapshot): verify guest clock advances after cross-kernel restore
Sample guest time twice and assert it advanced by roughly the sleep duration. Comparing guest time to host time doesn't work here: phase1 and restore run as separate pipeline steps with elapsed time between them, and snapshot restore preserves the guest's KVM-clock from capture time. Sampling twice still catches what we care about - the clock being frozen, going backwards, or running at the wrong rate - which is how KVM-clock regressions across host kernels manifest. Signed-off-by: Jack Thomson <jackabt@amazon.com>
1 parent cdc4bd3 commit 04708b2

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/integration_tests/functional/test_snapshot_restore_cross_kernel.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import json
77
import logging
8+
import time
89
from pathlib import Path
910

1011
import pytest
@@ -27,6 +28,20 @@
2728
pytestmark = pytest.mark.nonci
2829

2930

31+
def _check_guest_clock_advances(ssh_connection, sleep_sec=1, tolerance_sec=1):
32+
# Can't compare guest time to host time here: phase1 and restore run as
33+
# separate pipeline steps with elapsed time between them, and snapshot
34+
# restore preserves the guest's KVM-clock from capture time. Instead,
35+
# sample twice and verify the clock advanced by roughly sleep_sec.
36+
_, first, _ = ssh_connection.check_output("date +%s")
37+
time.sleep(sleep_sec)
38+
_, second, _ = ssh_connection.check_output("date +%s")
39+
elapsed = int(second.strip()) - int(first.strip())
40+
assert (
41+
abs(elapsed - sleep_sec) <= tolerance_sec
42+
), f"Guest clock advanced by {elapsed}s over {sleep_sec}s sleep"
43+
44+
3045
def _test_balloon(microvm):
3146
# Check memory usage.
3247
first_reading = get_stable_rss_mem(microvm)
@@ -129,4 +144,7 @@ def test_snap_restore_from_artifacts(
129144
logger.info("Testing entropy...")
130145
check_entropy(vm.ssh)
131146

147+
logger.info("Testing guest clock advances...")
148+
_check_guest_clock_advances(vm.ssh)
149+
132150
vm.kill()

0 commit comments

Comments
 (0)