Skip to content

Commit

Permalink
tests: add module loading test
Browse files Browse the repository at this point in the history
This test will simply check that modules can be loaded, and no symbols
are missing.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
elmarco authored and bonzini committed Aug 21, 2019
1 parent 81d8ccb commit eb062cf
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
9 changes: 9 additions & 0 deletions qtest.c
Expand Up @@ -661,6 +661,15 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
qtest_send_prefix(chr);
qtest_sendf(chr, "OK %"PRIi64"\n",
(int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
} else if (strcmp(words[0], "module_load") == 0) {
g_assert(words[1] && words[2]);

qtest_send_prefix(chr);
if (module_load_one(words[1], words[2])) {
qtest_sendf(chr, "OK\n");
} else {
qtest_sendf(chr, "FAIL\n");
}
} else if (qtest_enabled() && strcmp(words[0], "clock_set") == 0) {
int64_t ns;
int ret;
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.include
Expand Up @@ -149,6 +149,7 @@ check-block-$(call land,$(CONFIG_POSIX),$(CONFIG_SOFTMMU)) += tests/check-block.

check-qtest-generic-y += tests/qmp-test$(EXESUF)
check-qtest-generic-y += tests/qmp-cmd-test$(EXESUF)
check-qtest-generic-$(CONFIG_MODULES) += tests/modules-test$(EXESUF)

check-qtest-generic-y += tests/device-introspect-test$(EXESUF)
check-qtest-generic-y += tests/cdrom-test$(EXESUF)
Expand Down
6 changes: 6 additions & 0 deletions tests/libqtest.c
Expand Up @@ -811,6 +811,12 @@ bool qtest_get_irq(QTestState *s, int num)
return s->irq_level[num];
}

void qtest_module_load(QTestState *s, const char *prefix, const char *libname)
{
qtest_sendf(s, "module_load %s %s\n", prefix, libname);
qtest_rsp(s, 0);
}

static int64_t qtest_clock_rsp(QTestState *s)
{
gchar **words;
Expand Down
2 changes: 2 additions & 0 deletions tests/libqtest.h
Expand Up @@ -262,6 +262,8 @@ char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
GCC_FMT_ATTR(2, 0);

void qtest_module_load(QTestState *s, const char *prefix, const char *libname);

/**
* qtest_get_irq:
* @s: #QTestState instance to operate on.
Expand Down
71 changes: 71 additions & 0 deletions tests/modules-test.c
@@ -0,0 +1,71 @@
#include "qemu/osdep.h"
#include "libqtest.h"

static void test_modules_load(const void *data)
{
QTestState *qts;
const char **args = data;

qts = qtest_init(NULL);
qtest_module_load(qts, args[0], args[1]);
qtest_quit(qts);
}

int main(int argc, char *argv[])
{
const char *modules[] = {
#ifdef CONFIG_CURL
"block-", "curl",
#endif
#ifdef CONFIG_GLUSTERFS
"block-", "gluster",
#endif
#ifdef CONFIG_LIBISCSI
"block-", "iscsi",
#endif
#ifdef CONFIG_LIBNFS
"block-", "nfs",
#endif
#ifdef CONFIG_LIBSSH
"block-", "ssh",
#endif
#ifdef CONFIG_RBD
"block-", "rbd",
#endif
#ifdef CONFIG_AUDIO_ALSA
"audio-", "alsa",
#endif
#ifdef CONFIG_AUDIO_OSS
"audio-", "oss",
#endif
#ifdef CONFIG_AUDIO_PA
"audio-", "pa",
#endif
#ifdef CONFIG_AUDIO_SDL
"audio-", "sdl",
#endif
#ifdef CONFIG_CURSES
"ui-", "curses",
#endif
#if defined(CONFIG_GTK) && defined(CONFIG_VTE)
"ui-", "gtk",
#endif
#ifdef CONFIG_SDL
"ui-", "sdl",
#endif
#if defined(CONFIG_SPICE) && defined(CONFIG_GIO)
"ui-", "spice-app",
#endif
};
int i;

g_test_init(&argc, &argv, NULL);

for (i = 0; i < G_N_ELEMENTS(modules); i += 2) {
char *testname = g_strdup_printf("/module/load/%s", modules[i + 1]);
qtest_add_data_func(testname, modules + i, test_modules_load);
g_free(testname);
}

return g_test_run();
}

0 comments on commit eb062cf

Please sign in to comment.