Add a cpr-reboot qtest that enables x-ignore-shared and asserts the amount
of RAM transferred stays far below the guest RAM size.

This covers the shared RAM behavior: device state is saved while shared
RAM is preserved in place.

Signed-off-by: Li Chen <[email protected]>
---
 tests/qtest/migration/cpr-tests.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tests/qtest/migration/cpr-tests.c 
b/tests/qtest/migration/cpr-tests.c
index 5eafc4d678..6fa09b54ee 100644
--- a/tests/qtest/migration/cpr-tests.c
+++ b/tests/qtest/migration/cpr-tests.c
@@ -52,6 +52,23 @@ static void test_mem_backend_file_fdset(void)
 }
 #endif
 
+static void test_ignore_shared_end(QTestState *from, QTestState *to,
+                                   void *opaque)
+{
+    int64_t transferred;
+    int64_t total;
+    int64_t limit;
+
+    transferred = read_ram_property_int(from, "transferred");
+    total = read_ram_property_int(from, "total");
+    limit = total / 32;
+    limit = MIN(limit, 8 * 1024 * 1024);
+    limit = MAX(limit, 2 * 1024 * 1024);
+    g_test_message("ram.transferred=%" PRId64 " ram.total=%" PRId64
+                   " limit=%" PRId64, transferred, total, limit);
+    g_assert_cmpint(transferred, <, limit);
+}
+
 static void *migrate_hook_start_mode_reboot(QTestState *from, QTestState *to)
 {
     migrate_set_parameter_str(from, "mode", "cpr-reboot");
@@ -69,6 +86,7 @@ static void test_mode_reboot(void)
         .connect_uri = uri,
         .listen_uri = "defer",
         .start_hook = migrate_hook_start_mode_reboot,
+        .end_hook = test_ignore_shared_end,
         .start = {
             .caps[MIGRATION_CAPABILITY_X_IGNORE_SHARED] = true,
         },
-- 
2.52.0


Reply via email to