qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: peterx@redhat.com
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: peterx@redhat.com, Fabiano Rosas <farosas@suse.de>
Subject: [PULL 07/20] tests/qtest/migration: Add a wrapper to print test names
Date: Tue, 16 Jan 2024 11:19:34 +0800	[thread overview]
Message-ID: <20240116031947.69017-8-peterx@redhat.com> (raw)
In-Reply-To: <20240116031947.69017-1-peterx@redhat.com>

From: Fabiano Rosas <farosas@suse.de>

Our usage of gtest results in us losing the very basic functionality
of "knowing which test failed". The issue is that gtest only prints
test names ("paths" in gtest parlance) once the test has finished, but
we use asserts in the tests and crash gtest itself before it can print
anything. We also use a final abort when the result of g_test_run is
not 0.

Depending on how the test failed/broke we can see the function that
trigged the abort, which may be representative of the test, but it
could also just be some generic function.

We have been relying on the primitive method of looking at the name of
the previous successful test and then looking at the code to figure
out which test should have come next.

Add a wrapper to the test registration that does the job of printing
the test name before running.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Peter Xu <peterx@redhat.com>
Link: https://lore.kernel.org/r/20240104142144.9680-7-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 tests/qtest/migration-helpers.h |  1 +
 tests/qtest/migration-helpers.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index b478549096..3bf7ded1b9 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -52,4 +52,5 @@ char *find_common_machine_version(const char *mtype, const char *var1,
                                   const char *var2);
 char *resolve_machine_version(const char *alias, const char *var1,
                               const char *var2);
+void migration_test_add(const char *path, void (*fn)(void));
 #endif /* MIGRATION_HELPERS_H */
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index 19384e3fa6..e451dbdbed 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -291,3 +291,35 @@ char *resolve_machine_version(const char *alias, const char *var1,
 
     return find_common_machine_version(machine_name, var1, var2);
 }
+
+typedef struct {
+    char *name;
+    void (*func)(void);
+} MigrationTest;
+
+static void migration_test_destroy(gpointer data)
+{
+    MigrationTest *test = (MigrationTest *)data;
+
+    g_free(test->name);
+    g_free(test);
+}
+
+static void migration_test_wrapper(const void *data)
+{
+    MigrationTest *test = (MigrationTest *)data;
+
+    g_test_message("Running /%s%s", qtest_get_arch(), test->name);
+    test->func();
+}
+
+void migration_test_add(const char *path, void (*fn)(void))
+{
+    MigrationTest *test = g_new0(MigrationTest, 1);
+
+    test->func = fn;
+    test->name = g_strdup(path);
+
+    qtest_add_data_func_full(path, test, migration_test_wrapper,
+                             migration_test_destroy);
+}
-- 
2.43.0



  parent reply	other threads:[~2024-01-16  3:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16  3:19 [PULL 00/20] Migration 20240116 patches peterx
2024-01-16  3:19 ` [PULL 01/20] migration: Simplify initial conditionals in migration for better readability peterx
2024-01-16  3:19 ` [PULL 02/20] migration/multifd: Remove MultiFDPages_t::packet_num peterx
2024-01-16  3:19 ` [PULL 03/20] migration/multifd: Remove QEMUFile from where it is not needed peterx
2024-01-16  3:19 ` [PULL 04/20] migration/multifd: Change multifd_pages_init argument peterx
2024-01-16  3:19 ` [PULL 05/20] migration: Report error in incoming migration peterx
2024-01-16  3:19 ` [PULL 06/20] tests/qtest/migration: Print migration incoming errors peterx
2024-01-16  3:19 ` peterx [this message]
2024-01-16  3:19 ` [PULL 08/20] tests/qtest/migration: Use the new migration_test_add peterx
2024-01-16  3:19 ` [PULL 09/20] tests/qtest: Re-enable multifd cancel test peterx
2024-01-16  3:19 ` [PULL 10/20] docs/migration: Create migration/ directory peterx
2024-01-16  3:19 ` [PULL 11/20] docs/migration: Create index page peterx
2024-01-16  3:19 ` [PULL 12/20] docs/migration: Convert virtio.txt into rST peterx
2024-01-16  3:19 ` [PULL 13/20] docs/migration: Split "Backwards compatibility" separately peterx
2024-01-16  3:19 ` [PULL 14/20] docs/migration: Split "Debugging" and "Firmware" peterx
2024-01-16  3:19 ` [PULL 15/20] docs/migration: Split "Postcopy" peterx
2024-01-16  3:19 ` [PULL 16/20] docs/migration: Split "dirty limit" peterx
2024-01-16  3:19 ` [PULL 17/20] docs/migration: Organize "Postcopy" page peterx
2024-01-16  3:19 ` [PULL 18/20] docs/migration: Further move vfio to be feature of migration peterx
2024-01-16  3:19 ` [PULL 19/20] docs/migration: Further move virtio " peterx
2024-01-16  3:19 ` [PULL 20/20] migration/rdma: define htonll/ntohll only if not predefined peterx
2024-01-16 16:33 ` [PULL 00/20] Migration 20240116 patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116031947.69017-8-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=farosas@suse.de \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).