diff mbox series

[RESEND,1/2] qtest/migration-test.c: Add test with compress enabled

Message ID af76761aa6978071c5b8e9b872b697db465a5520.1680457631.git.lukasstraub2@web.de
State New
Headers show
Series [RESEND,1/2] qtest/migration-test.c: Add test with compress enabled | expand

Commit Message

Lukas Straub April 2, 2023, 5:47 p.m. UTC
There has never been a test for migration with compress enabled.

Add a suitable test, testing with compress-wait-thread = false
too.

iterations = 2 is intentional, so it also tests that no invalid
thread state is left over from the previous iteration.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
---
 tests/qtest/migration-test.c | 67 ++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

Comments

Peter Xu April 3, 2023, 9:17 p.m. UTC | #1
On Sun, Apr 02, 2023 at 05:47:45PM +0000, Lukas Straub wrote:
> There has never been a test for migration with compress enabled.
> 
> Add a suitable test, testing with compress-wait-thread = false
> too.
> 
> iterations = 2 is intentional, so it also tests that no invalid
> thread state is left over from the previous iteration.
> 
> Signed-off-by: Lukas Straub <lukasstraub2@web.de>

Overall looks good to me:

Reviewed-by: Peter Xu <peterx@redhat.com>

A few nitpicks below.

> ---
>  tests/qtest/migration-test.c | 67 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 67 insertions(+)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 3b615b0da9..dbcab2e8ae 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -406,6 +406,41 @@ static void migrate_set_parameter_str(QTestState *who, const char *parameter,
>      migrate_check_parameter_str(who, parameter, value);
>  }
>  
> +static long long migrate_get_parameter_bool(QTestState *who,
> +                                           const char *parameter)
> +{
> +    QDict *rsp;
> +    int result;
> +
> +    rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }");
> +    result = qdict_get_bool(rsp, parameter);
> +    qobject_unref(rsp);
> +    return !!result;
> +}
> +
> +static void migrate_check_parameter_bool(QTestState *who, const char *parameter,
> +                                        int value)
> +{
> +    int result;
> +
> +    result = migrate_get_parameter_bool(who, parameter);
> +    g_assert_cmpint(result, ==, value);
> +}
> +
> +static void migrate_set_parameter_bool(QTestState *who, const char *parameter,
> +                                      int value)
> +{
> +    QDict *rsp;
> +
> +    rsp = qtest_qmp(who,
> +                    "{ 'execute': 'migrate-set-parameters',"
> +                    "'arguments': { %s: %i } }",
> +                    parameter, value);
> +    g_assert(qdict_haskey(rsp, "return"));
> +    qobject_unref(rsp);
> +    migrate_check_parameter_bool(who, parameter, value);
> +}
> +
>  static void migrate_ensure_non_converge(QTestState *who)
>  {
>      /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */
> @@ -1524,6 +1559,36 @@ static void test_precopy_unix_xbzrle(void)
>      test_precopy_common(&args);
>  }
>  
> +static void *
> +test_migrate_compress_start(QTestState *from,
> +                          QTestState *to)
> +{
> +    migrate_set_parameter_int(from, "compress-level", 9);
> +    migrate_set_parameter_int(from, "compress-threads", 1);
> +    migrate_set_parameter_bool(from, "compress-wait-thread", false);

May worth trying both true/false (can split into two tests)?

> +    migrate_set_parameter_int(to, "decompress-threads", 1);

Why not set both compress/decompress threads to something >1 to check arace
conditions between the threads?

> +
> +    migrate_set_capability(from, "compress", true);
> +    migrate_set_capability(to, "compress", true);
> +
> +    return NULL;
> +}
> +
> +static void test_precopy_unix_compress(void)
> +{
> +    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
> +    MigrateCommon args = {
> +        .connect_uri = uri,
> +        .listen_uri = uri,
> +

Empty line.

> +        .start_hook = test_migrate_compress_start,
> +

Empty line.

> +        .iterations = 2,

Maybe move the comment in commit message over here?

> +    };
> +
> +    test_precopy_common(&args);
> +}
> +
>  static void test_precopy_tcp_plain(void)
>  {
>      MigrateCommon args = {
> @@ -2515,6 +2580,8 @@ int main(int argc, char **argv)
>      qtest_add_func("/migration/bad_dest", test_baddest);
>      qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain);
>      qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle);
> +    qtest_add_func("/migration/precopy/unix/compress",
> +                   test_precopy_unix_compress);
>  #ifdef CONFIG_GNUTLS
>      qtest_add_func("/migration/precopy/unix/tls/psk",
>                     test_precopy_unix_tls_psk);
> -- 
> 2.30.2
>
Lukas Straub April 4, 2023, 7:40 a.m. UTC | #2
On Mon, 3 Apr 2023 17:17:52 -0400
Peter Xu <peterx@redhat.com> wrote:

> On Sun, Apr 02, 2023 at 05:47:45PM +0000, Lukas Straub wrote:
> > There has never been a test for migration with compress enabled.
> > 
> > Add a suitable test, testing with compress-wait-thread = false
> > too.
> > 
> > iterations = 2 is intentional, so it also tests that no invalid
> > thread state is left over from the previous iteration.
> > 
> > Signed-off-by: Lukas Straub <lukasstraub2@web.de>  
> 
> Overall looks good to me:
> 
> Reviewed-by: Peter Xu <peterx@redhat.com>
> 
> A few nitpicks below.
> 
> > ---
> >  tests/qtest/migration-test.c | 67 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 67 insertions(+)
> > 
> > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> > index 3b615b0da9..dbcab2e8ae 100644
> > --- a/tests/qtest/migration-test.c
> > +++ b/tests/qtest/migration-test.c
> >
> > [...]
> >
> >  static void migrate_ensure_non_converge(QTestState *who)
> >  {
> >      /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */
> > @@ -1524,6 +1559,36 @@ static void test_precopy_unix_xbzrle(void)
> >      test_precopy_common(&args);
> >  }
> >  
> > +static void *
> > +test_migrate_compress_start(QTestState *from,
> > +                          QTestState *to)
> > +{
> > +    migrate_set_parameter_int(from, "compress-level", 9);
> > +    migrate_set_parameter_int(from, "compress-threads", 1);
> > +    migrate_set_parameter_bool(from, "compress-wait-thread", false);  
> 
> May worth trying both true/false (can split into two tests)?

Maybe, I just wasn't sure with your CI resources being tight, whether
I should add more tests. I think this test gives the most "bang for the
buck".

> > +    migrate_set_parameter_int(to, "decompress-threads", 1);  
> 
> Why not set both compress/decompress threads to something >1 to check arace
> conditions between the threads?

I just wanted to make sure that it won't get too fast so it really
sends some pages uncompressed. But I guess this can be fixed when
splitting it into 2 tests.

> > +
> > +    migrate_set_capability(from, "compress", true);
> > +    migrate_set_capability(to, "compress", true);
> > +
> > +    return NULL;
> > +}
> > +
> > +static void test_precopy_unix_compress(void)
> > +{
> > +    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
> > +    MigrateCommon args = {
> > +        .connect_uri = uri,
> > +        .listen_uri = uri,
> > +  
> 
> Empty line.
> 
> > +        .start_hook = test_migrate_compress_start,
> > +  
> 
> Empty line.
> 
> > +        .iterations = 2,  
> 
> Maybe move the comment in commit message over here?

Good idea, will fix in the next version.

Regards,
Lukas Straub

> > +    };
> > +
> > +    test_precopy_common(&args);
> > +}
> > +
> >  static void test_precopy_tcp_plain(void)
> >  {
> >      MigrateCommon args = {
> > @@ -2515,6 +2580,8 @@ int main(int argc, char **argv)
> >      qtest_add_func("/migration/bad_dest", test_baddest);
> >      qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain);
> >      qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle);
> > +    qtest_add_func("/migration/precopy/unix/compress",
> > +                   test_precopy_unix_compress);
> >  #ifdef CONFIG_GNUTLS
> >      qtest_add_func("/migration/precopy/unix/tls/psk",
> >                     test_precopy_unix_tls_psk);
> > -- 
> > 2.30.2
> >   
> 
> 
> 



--
diff mbox series

Patch

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 3b615b0da9..dbcab2e8ae 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -406,6 +406,41 @@  static void migrate_set_parameter_str(QTestState *who, const char *parameter,
     migrate_check_parameter_str(who, parameter, value);
 }
 
+static long long migrate_get_parameter_bool(QTestState *who,
+                                           const char *parameter)
+{
+    QDict *rsp;
+    int result;
+
+    rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }");
+    result = qdict_get_bool(rsp, parameter);
+    qobject_unref(rsp);
+    return !!result;
+}
+
+static void migrate_check_parameter_bool(QTestState *who, const char *parameter,
+                                        int value)
+{
+    int result;
+
+    result = migrate_get_parameter_bool(who, parameter);
+    g_assert_cmpint(result, ==, value);
+}
+
+static void migrate_set_parameter_bool(QTestState *who, const char *parameter,
+                                      int value)
+{
+    QDict *rsp;
+
+    rsp = qtest_qmp(who,
+                    "{ 'execute': 'migrate-set-parameters',"
+                    "'arguments': { %s: %i } }",
+                    parameter, value);
+    g_assert(qdict_haskey(rsp, "return"));
+    qobject_unref(rsp);
+    migrate_check_parameter_bool(who, parameter, value);
+}
+
 static void migrate_ensure_non_converge(QTestState *who)
 {
     /* Can't converge with 1ms downtime + 3 mbs bandwidth limit */
@@ -1524,6 +1559,36 @@  static void test_precopy_unix_xbzrle(void)
     test_precopy_common(&args);
 }
 
+static void *
+test_migrate_compress_start(QTestState *from,
+                          QTestState *to)
+{
+    migrate_set_parameter_int(from, "compress-level", 9);
+    migrate_set_parameter_int(from, "compress-threads", 1);
+    migrate_set_parameter_bool(from, "compress-wait-thread", false);
+    migrate_set_parameter_int(to, "decompress-threads", 1);
+
+    migrate_set_capability(from, "compress", true);
+    migrate_set_capability(to, "compress", true);
+
+    return NULL;
+}
+
+static void test_precopy_unix_compress(void)
+{
+    g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
+    MigrateCommon args = {
+        .connect_uri = uri,
+        .listen_uri = uri,
+
+        .start_hook = test_migrate_compress_start,
+
+        .iterations = 2,
+    };
+
+    test_precopy_common(&args);
+}
+
 static void test_precopy_tcp_plain(void)
 {
     MigrateCommon args = {
@@ -2515,6 +2580,8 @@  int main(int argc, char **argv)
     qtest_add_func("/migration/bad_dest", test_baddest);
     qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain);
     qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle);
+    qtest_add_func("/migration/precopy/unix/compress",
+                   test_precopy_unix_compress);
 #ifdef CONFIG_GNUTLS
     qtest_add_func("/migration/precopy/unix/tls/psk",
                    test_precopy_unix_tls_psk);