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