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