@ -23,9 +23,13 @@
# include "qapi/qapi-visit-sockets.h"
# include "qapi/qobject-input-visitor.h"
# include "qapi/qobject-output-visitor.h"
# include "crypto/tlscredspsk.h"
# include "migration-helpers.h"
# include "tests/migration/migration-test.h"
# ifdef CONFIG_GNUTLS
# include "tests / unit / crypto-tls-psk-helpers.h"
# endif /* CONFIG_GNUTLS */
/* For dirty ring test; so far only x86_64 is supported */
# if defined(__linux__) && defined(HOST_X86_64)
@ -640,6 +644,100 @@ static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
cleanup ( " dest_serial " ) ;
}
# ifdef CONFIG_GNUTLS
struct TestMigrateTLSPSKData {
char * workdir ;
char * workdiralt ;
char * pskfile ;
char * pskfilealt ;
} ;
static void *
test_migrate_tls_psk_start_common ( QTestState * from ,
QTestState * to ,
bool mismatch )
{
struct TestMigrateTLSPSKData * data =
g_new0 ( struct TestMigrateTLSPSKData , 1 ) ;
QDict * rsp ;
data - > workdir = g_strdup_printf ( " %s/tlscredspsk0 " , tmpfs ) ;
data - > pskfile = g_strdup_printf ( " %s/%s " , data - > workdir ,
QCRYPTO_TLS_CREDS_PSKFILE ) ;
mkdir ( data - > workdir , 0700 ) ;
test_tls_psk_init ( data - > pskfile ) ;
if ( mismatch ) {
data - > workdiralt = g_strdup_printf ( " %s/tlscredspskalt0 " , tmpfs ) ;
data - > pskfilealt = g_strdup_printf ( " %s/%s " , data - > workdiralt ,
QCRYPTO_TLS_CREDS_PSKFILE ) ;
mkdir ( data - > workdiralt , 0700 ) ;
test_tls_psk_init_alt ( data - > pskfilealt ) ;
}
rsp = wait_command ( from ,
" { 'execute': 'object-add', "
" 'arguments': { 'qom-type': 'tls-creds-psk', "
" 'id': 'tlscredspsk0', "
" 'endpoint': 'client', "
" 'dir': %s, "
" 'username': 'qemu'} } " ,
data - > workdir ) ;
qobject_unref ( rsp ) ;
rsp = wait_command ( to ,
" { 'execute': 'object-add', "
" 'arguments': { 'qom-type': 'tls-creds-psk', "
" 'id': 'tlscredspsk0', "
" 'endpoint': 'server', "
" 'dir': %s } } " ,
mismatch ? data - > workdiralt : data - > workdir ) ;
qobject_unref ( rsp ) ;
migrate_set_parameter_str ( from , " tls-creds " , " tlscredspsk0 " ) ;
migrate_set_parameter_str ( to , " tls-creds " , " tlscredspsk0 " ) ;
return data ;
}
static void *
test_migrate_tls_psk_start_match ( QTestState * from ,
QTestState * to )
{
return test_migrate_tls_psk_start_common ( from , to , false ) ;
}
static void *
test_migrate_tls_psk_start_mismatch ( QTestState * from ,
QTestState * to )
{
return test_migrate_tls_psk_start_common ( from , to , true ) ;
}
static void
test_migrate_tls_psk_finish ( QTestState * from ,
QTestState * to ,
void * opaque )
{
struct TestMigrateTLSPSKData * data = opaque ;
test_tls_psk_cleanup ( data - > pskfile ) ;
if ( data - > pskfilealt ) {
test_tls_psk_cleanup ( data - > pskfilealt ) ;
}
rmdir ( data - > workdir ) ;
if ( data - > workdiralt ) {
rmdir ( data - > workdiralt ) ;
}
g_free ( data - > workdiralt ) ;
g_free ( data - > pskfilealt ) ;
g_free ( data - > workdir ) ;
g_free ( data - > pskfile ) ;
g_free ( data ) ;
}
# endif /* CONFIG_GNUTLS */
static int migrate_postcopy_prepare ( QTestState * * from_ptr ,
QTestState * * to_ptr ,
MigrateStart * args )
@ -911,7 +1009,7 @@ static void test_precopy_common(MigrateCommon *args)
test_migrate_end ( from , to , args - > result = = MIG_TEST_SUCCEED ) ;
}
static void test_precopy_unix ( void )
static void test_precopy_unix_plain ( void )
{
g_autofree char * uri = g_strdup_printf ( " unix:%s/migsocket " , tmpfs ) ;
MigrateCommon args = {
@ -922,6 +1020,21 @@ static void test_precopy_unix(void)
test_precopy_common ( & args ) ;
}
# ifdef CONFIG_GNUTLS
static void test_precopy_unix_tls_psk ( void )
{
g_autofree char * uri = g_strdup_printf ( " unix:%s/migsocket " , tmpfs ) ;
MigrateCommon args = {
. connect_uri = uri ,
. listen_uri = uri ,
. start_hook = test_migrate_tls_psk_start_match ,
. finish_hook = test_migrate_tls_psk_finish ,
} ;
test_precopy_common ( & args ) ;
}
# endif
static void test_precopy_unix_dirty_ring ( void )
{
g_autofree char * uri = g_strdup_printf ( " unix:%s/migsocket " , tmpfs ) ;
@ -1026,7 +1139,7 @@ static void test_xbzrle_unix(void)
test_xbzrle ( uri ) ;
}
static void test_precopy_tcp ( void )
static void test_precopy_tcp_plain ( void )
{
MigrateCommon args = {
. listen_uri = " tcp:127.0.0.1:0 " ,
@ -1035,6 +1148,34 @@ static void test_precopy_tcp(void)
test_precopy_common ( & args ) ;
}
# ifdef CONFIG_GNUTLS
static void test_precopy_tcp_tls_psk_match ( void )
{
MigrateCommon args = {
. listen_uri = " tcp:127.0.0.1:0 " ,
. start_hook = test_migrate_tls_psk_start_match ,
. finish_hook = test_migrate_tls_psk_finish ,
} ;
test_precopy_common ( & args ) ;
}
static void test_precopy_tcp_tls_psk_mismatch ( void )
{
MigrateCommon args = {
. start = {
. hide_stderr = true ,
} ,
. listen_uri = " tcp:127.0.0.1:0 " ,
. start_hook = test_migrate_tls_psk_start_mismatch ,
. finish_hook = test_migrate_tls_psk_finish ,
. result = MIG_TEST_FAIL ,
} ;
test_precopy_common ( & args ) ;
}
# endif /* CONFIG_GNUTLS */
static void * test_migrate_fd_start_hook ( QTestState * from ,
QTestState * to )
{
@ -1497,8 +1638,20 @@ int main(int argc, char **argv)
qtest_add_func ( " /migration/postcopy/unix " , test_postcopy ) ;
qtest_add_func ( " /migration/postcopy/recovery " , test_postcopy_recovery ) ;
qtest_add_func ( " /migration/bad_dest " , test_baddest ) ;
qtest_add_func ( " /migration/precopy/unix " , test_precopy_unix ) ;
qtest_add_func ( " /migration/precopy/tcp " , test_precopy_tcp ) ;
qtest_add_func ( " /migration/precopy/unix/plain " , test_precopy_unix_plain ) ;
# ifdef CONFIG_GNUTLS
qtest_add_func ( " /migration/precopy/unix/tls/psk " ,
test_precopy_unix_tls_psk ) ;
# endif /* CONFIG_GNUTLS */
qtest_add_func ( " /migration/precopy/tcp/plain " , test_precopy_tcp_plain ) ;
# ifdef CONFIG_GNUTLS
qtest_add_func ( " /migration/precopy/tcp/tls/psk/match " ,
test_precopy_tcp_tls_psk_match ) ;
qtest_add_func ( " /migration/precopy/tcp/tls/psk/mismatch " ,
test_precopy_tcp_tls_psk_mismatch ) ;
# endif /* CONFIG_GNUTLS */
/* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
qtest_add_func ( " /migration/xbzrle/unix " , test_xbzrle_unix ) ;
qtest_add_func ( " /migration/fd_proto " , test_migrate_fd_proto ) ;