1 /* 2 * QTest testcases for CPR 3 * 4 * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates 5 * based on the vhost-user-test.c that is: 6 * Copyright (c) 2014 Virtual Open Systems Sarl. 7 * 8 * This work is licensed under the terms of the GNU GPL, version 2 or later. 9 * See the COPYING file in the top-level directory. 10 * 11 */ 12 13 #include "qemu/osdep.h" 14 #include "libqtest.h" 15 #include "migration/framework.h" 16 #include "migration/migration-qmp.h" 17 #include "migration/migration-util.h" 18 19 20 static char *tmpfs; 21 22 static void *migrate_hook_start_mode_reboot(QTestState *from, QTestState *to) 23 { 24 migrate_set_parameter_str(from, "mode", "cpr-reboot"); 25 migrate_set_parameter_str(to, "mode", "cpr-reboot"); 26 27 migrate_set_capability(from, "x-ignore-shared", true); 28 migrate_set_capability(to, "x-ignore-shared", true); 29 30 return NULL; 31 } 32 33 static void test_mode_reboot(void) 34 { 35 g_autofree char *uri = g_strdup_printf("file:%s/%s", tmpfs, 36 FILE_TEST_FILENAME); 37 MigrateCommon args = { 38 .start.use_shmem = true, 39 .connect_uri = uri, 40 .listen_uri = "defer", 41 .start_hook = migrate_hook_start_mode_reboot, 42 }; 43 44 test_file_common(&args, true); 45 } 46 47 static void *test_mode_transfer_start(QTestState *from, QTestState *to) 48 { 49 migrate_set_parameter_str(from, "mode", "cpr-transfer"); 50 return NULL; 51 } 52 53 /* 54 * cpr-transfer mode cannot use the target monitor prior to starting the 55 * migration, and cannot connect synchronously to the monitor, so defer 56 * the target connection. 57 */ 58 static void test_mode_transfer_common(bool incoming_defer) 59 { 60 g_autofree char *cpr_path = g_strdup_printf("%s/cpr.sock", tmpfs); 61 g_autofree char *mig_path = g_strdup_printf("%s/migsocket", tmpfs); 62 g_autofree char *uri = g_strdup_printf("unix:%s", mig_path); 63 64 const char *opts = "-machine aux-ram-share=on -nodefaults"; 65 g_autofree const char *cpr_channel = g_strdup_printf( 66 "cpr,addr.transport=socket,addr.type=unix,addr.path=%s", 67 cpr_path); 68 g_autofree char *opts_target = g_strdup_printf("-incoming %s %s", 69 cpr_channel, opts); 70 71 g_autofree char *connect_channels = g_strdup_printf( 72 "[ { 'channel-type': 'main'," 73 " 'addr': { 'transport': 'socket'," 74 " 'type': 'unix'," 75 " 'path': '%s' } } ]", 76 mig_path); 77 78 MigrateCommon args = { 79 .start.opts_source = opts, 80 .start.opts_target = opts_target, 81 .start.defer_target_connect = true, 82 .start.memory_backend = "-object memory-backend-memfd,id=pc.ram,size=%s" 83 " -machine memory-backend=pc.ram", 84 .listen_uri = incoming_defer ? "defer" : uri, 85 .connect_channels = connect_channels, 86 .cpr_channel = cpr_channel, 87 .start_hook = test_mode_transfer_start, 88 }; 89 90 test_precopy_common(&args); 91 } 92 93 static void test_mode_transfer(void) 94 { 95 test_mode_transfer_common(NULL); 96 } 97 98 static void test_mode_transfer_defer(void) 99 { 100 test_mode_transfer_common(true); 101 } 102 103 void migration_test_add_cpr(MigrationTestEnv *env) 104 { 105 tmpfs = env->tmpfs; 106 107 /* no tests in the smoke set for now */ 108 109 if (!env->full_set) { 110 return; 111 } 112 113 /* 114 * Our CI system has problems with shared memory. 115 * Don't run this test until we find a workaround. 116 */ 117 if (getenv("QEMU_TEST_FLAKY_TESTS")) { 118 migration_test_add("/migration/mode/reboot", test_mode_reboot); 119 } 120 121 if (env->has_kvm) { 122 migration_test_add("/migration/mode/transfer", test_mode_transfer); 123 migration_test_add("/migration/mode/transfer/defer", 124 test_mode_transfer_defer); 125 } 126 } 127