1 /* 2 * QTest testcases for migration compression 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 #include "qemu/module.h" 19 20 21 static char *tmpfs; 22 23 #ifdef CONFIG_ZSTD 24 static void * 25 migrate_hook_start_precopy_tcp_multifd_zstd(QTestState *from, 26 QTestState *to) 27 { 28 migrate_set_parameter_int(from, "multifd-zstd-level", 2); 29 migrate_set_parameter_int(to, "multifd-zstd-level", 2); 30 31 return migrate_hook_start_precopy_tcp_multifd_common(from, to, "zstd"); 32 } 33 34 static void test_multifd_tcp_zstd(void) 35 { 36 MigrateCommon args = { 37 .listen_uri = "defer", 38 .start = { 39 .caps[MIGRATION_CAPABILITY_MULTIFD] = true, 40 }, 41 .start_hook = migrate_hook_start_precopy_tcp_multifd_zstd, 42 }; 43 test_precopy_common(&args); 44 } 45 46 static void test_multifd_postcopy_tcp_zstd(void) 47 { 48 MigrateCommon args = { 49 .listen_uri = "defer", 50 .start = { 51 .caps[MIGRATION_CAPABILITY_MULTIFD] = true, 52 .caps[MIGRATION_CAPABILITY_POSTCOPY_RAM] = true, 53 }, 54 .start_hook = migrate_hook_start_precopy_tcp_multifd_zstd, 55 }; 56 57 test_precopy_common(&args); 58 } 59 #endif /* CONFIG_ZSTD */ 60 61 #ifdef CONFIG_QATZIP 62 static void * 63 migrate_hook_start_precopy_tcp_multifd_qatzip(QTestState *from, 64 QTestState *to) 65 { 66 migrate_set_parameter_int(from, "multifd-qatzip-level", 2); 67 migrate_set_parameter_int(to, "multifd-qatzip-level", 2); 68 69 return migrate_hook_start_precopy_tcp_multifd_common(from, to, "qatzip"); 70 } 71 72 static void test_multifd_tcp_qatzip(void) 73 { 74 MigrateCommon args = { 75 .listen_uri = "defer", 76 .start = { 77 .caps[MIGRATION_CAPABILITY_MULTIFD] = true, 78 }, 79 .start_hook = migrate_hook_start_precopy_tcp_multifd_qatzip, 80 }; 81 test_precopy_common(&args); 82 } 83 #endif 84 85 #ifdef CONFIG_QPL 86 static void * 87 migrate_hook_start_precopy_tcp_multifd_qpl(QTestState *from, 88 QTestState *to) 89 { 90 return migrate_hook_start_precopy_tcp_multifd_common(from, to, "qpl"); 91 } 92 93 static void test_multifd_tcp_qpl(void) 94 { 95 MigrateCommon args = { 96 .listen_uri = "defer", 97 .start = { 98 .caps[MIGRATION_CAPABILITY_MULTIFD] = true, 99 }, 100 .start_hook = migrate_hook_start_precopy_tcp_multifd_qpl, 101 }; 102 test_precopy_common(&args); 103 } 104 #endif /* CONFIG_QPL */ 105 106 #ifdef CONFIG_UADK 107 static void * 108 migrate_hook_start_precopy_tcp_multifd_uadk(QTestState *from, 109 QTestState *to) 110 { 111 return migrate_hook_start_precopy_tcp_multifd_common(from, to, "uadk"); 112 } 113 114 static void test_multifd_tcp_uadk(void) 115 { 116 MigrateCommon args = { 117 .listen_uri = "defer", 118 .start = { 119 .caps[MIGRATION_CAPABILITY_MULTIFD] = true, 120 }, 121 .start_hook = migrate_hook_start_precopy_tcp_multifd_uadk, 122 }; 123 test_precopy_common(&args); 124 } 125 #endif /* CONFIG_UADK */ 126 127 static void * 128 migrate_hook_start_xbzrle(QTestState *from, 129 QTestState *to) 130 { 131 migrate_set_parameter_int(from, "xbzrle-cache-size", 33554432); 132 return NULL; 133 } 134 135 static void test_precopy_unix_xbzrle(void) 136 { 137 g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); 138 MigrateCommon args = { 139 .connect_uri = uri, 140 .listen_uri = uri, 141 .start_hook = migrate_hook_start_xbzrle, 142 .iterations = 2, 143 .start = { 144 .caps[MIGRATION_CAPABILITY_XBZRLE] = true, 145 }, 146 /* 147 * XBZRLE needs pages to be modified when doing the 2nd+ round 148 * iteration to have real data pushed to the stream. 149 */ 150 .live = true, 151 }; 152 153 test_precopy_common(&args); 154 } 155 156 static void * 157 migrate_hook_start_precopy_tcp_multifd_zlib(QTestState *from, 158 QTestState *to) 159 { 160 /* 161 * Overloading this test to also check that set_parameter does not error. 162 * This is also done in the tests for the other compression methods. 163 */ 164 migrate_set_parameter_int(from, "multifd-zlib-level", 2); 165 migrate_set_parameter_int(to, "multifd-zlib-level", 2); 166 167 return migrate_hook_start_precopy_tcp_multifd_common(from, to, "zlib"); 168 } 169 170 static void test_multifd_tcp_zlib(void) 171 { 172 MigrateCommon args = { 173 .listen_uri = "defer", 174 .start = { 175 .caps[MIGRATION_CAPABILITY_MULTIFD] = true, 176 }, 177 .start_hook = migrate_hook_start_precopy_tcp_multifd_zlib, 178 }; 179 test_precopy_common(&args); 180 } 181 182 static void migration_test_add_compression_smoke(MigrationTestEnv *env) 183 { 184 migration_test_add("/migration/multifd/tcp/plain/zlib", 185 test_multifd_tcp_zlib); 186 } 187 188 void migration_test_add_compression(MigrationTestEnv *env) 189 { 190 tmpfs = env->tmpfs; 191 192 migration_test_add_compression_smoke(env); 193 194 if (!env->full_set) { 195 return; 196 } 197 198 #ifdef CONFIG_ZSTD 199 migration_test_add("/migration/multifd/tcp/plain/zstd", 200 test_multifd_tcp_zstd); 201 if (env->has_uffd) { 202 migration_test_add("/migration/multifd+postcopy/tcp/plain/zstd", 203 test_multifd_postcopy_tcp_zstd); 204 } 205 #endif 206 207 #ifdef CONFIG_QATZIP 208 migration_test_add("/migration/multifd/tcp/plain/qatzip", 209 test_multifd_tcp_qatzip); 210 #endif 211 212 #ifdef CONFIG_QPL 213 migration_test_add("/migration/multifd/tcp/plain/qpl", 214 test_multifd_tcp_qpl); 215 #endif 216 217 #ifdef CONFIG_UADK 218 migration_test_add("/migration/multifd/tcp/plain/uadk", 219 test_multifd_tcp_uadk); 220 #endif 221 222 if (g_test_slow()) { 223 migration_test_add("/migration/precopy/unix/xbzrle", 224 test_precopy_unix_xbzrle); 225 } 226 } 227