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