Commit a2569b00 authored by Thomas Huth's avatar Thomas Huth
Browse files

tests/test-filter: Make tests independent of global_qtest



Apart from using qmp() in the qmp_discard_response() macro, these
tests do not have any dependencies to the global_qtest variable,
so we can simply get rid of it here by replacing the qmp() with
qtest_qmp() in the macro.

Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarThomas Huth <thuth@redhat.com>
parent e6426b74
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#include "qemu/main-loop.h"

/* TODO actually test the results and get rid of this */
#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__))
#define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__))

static void test_mirror(void)
{
@@ -29,6 +29,7 @@ static void test_mirror(void)
    uint32_t size = sizeof(send_buf);
    size = htonl(size);
    const char *devstr = "e1000";
    QTestState *qts;

    if (g_str_equal(qtest_get_arch(), "s390x")) {
        devstr = "virtio-net-ccw";
@@ -40,7 +41,7 @@ static void test_mirror(void)
    ret = mkstemp(sock_path);
    g_assert_cmpint(ret, !=, -1);

    global_qtest = qtest_initf(
    qts = qtest_initf(
        "-netdev socket,id=qtest-bn0,fd=%d "
        "-device %s,netdev=qtest-bn0,id=qtest-e0 "
        "-chardev socket,id=mirror0,path=%s,server,nowait "
@@ -61,7 +62,7 @@ static void test_mirror(void)
    };

    /* send a qmp command to guarantee that 'connected' is setting to true. */
    qmp_discard_response("{ 'execute' : 'query-status'}");
    qmp_discard_response(qts, "{ 'execute' : 'query-status'}");
    ret = iov_send(send_sock[0], iov, 2, 0, sizeof(size) + sizeof(send_buf));
    g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));
    close(send_sock[0]);
@@ -78,6 +79,7 @@ static void test_mirror(void)
    g_free(recv_buf);
    close(recv_sock);
    unlink(sock_path);
    qtest_quit(qts);
}

int main(int argc, char **argv)
@@ -88,7 +90,6 @@ int main(int argc, char **argv)

    qtest_add_func("/netfilter/mirror", test_mirror);
    ret = g_test_run();
    qtest_end();

    return ret;
}
+9 −7
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@
#include "qemu/main-loop.h"

/* TODO actually test the results and get rid of this */
#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__))
#define qmp_discard_response(qs, ...) qobject_unref(qtest_qmp(qs, __VA_ARGS__))

static const char *get_devstr(void)
{
@@ -81,6 +81,7 @@ static void test_redirector_tx(void)
    char *recv_buf;
    uint32_t size = sizeof(send_buf);
    size = htonl(size);
    QTestState *qts;

    ret = socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock);
    g_assert_cmpint(ret, !=, -1);
@@ -90,7 +91,7 @@ static void test_redirector_tx(void)
    ret = mkstemp(sock_path1);
    g_assert_cmpint(ret, !=, -1);

    global_qtest = qtest_initf(
    qts = qtest_initf(
        "-netdev socket,id=qtest-bn0,fd=%d "
        "-device %s,netdev=qtest-bn0,id=qtest-e0 "
        "-chardev socket,id=redirector0,path=%s,server,nowait "
@@ -108,7 +109,7 @@ static void test_redirector_tx(void)
    g_assert_cmpint(recv_sock, !=, -1);

    /* send a qmp command to guarantee that 'connected' is setting to true. */
    qmp_discard_response("{ 'execute' : 'query-status'}");
    qmp_discard_response(qts, "{ 'execute' : 'query-status'}");

    struct iovec iov[] = {
        {
@@ -137,7 +138,7 @@ static void test_redirector_tx(void)
    close(recv_sock);
    unlink(sock_path0);
    unlink(sock_path1);
    qtest_end();
    qtest_quit(qts);
}

static void test_redirector_rx(void)
@@ -150,6 +151,7 @@ static void test_redirector_rx(void)
    char *recv_buf;
    uint32_t size = sizeof(send_buf);
    size = htonl(size);
    QTestState *qts;

    ret = socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock);
    g_assert_cmpint(ret, !=, -1);
@@ -159,7 +161,7 @@ static void test_redirector_rx(void)
    ret = mkstemp(sock_path1);
    g_assert_cmpint(ret, !=, -1);

    global_qtest = qtest_initf(
    qts = qtest_initf(
        "-netdev socket,id=qtest-bn0,fd=%d "
        "-device %s,netdev=qtest-bn0,id=qtest-e0 "
        "-chardev socket,id=redirector0,path=%s,server,nowait "
@@ -186,7 +188,7 @@ static void test_redirector_rx(void)
    send_sock = unix_connect(sock_path1, NULL);
    g_assert_cmpint(send_sock, !=, -1);
    /* send a qmp command to guarantee that 'connected' is setting to true. */
    qmp_discard_response("{ 'execute' : 'query-status'}");
    qmp_discard_response(qts, "{ 'execute' : 'query-status'}");

    ret = iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf));
    g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size));
@@ -204,7 +206,7 @@ static void test_redirector_rx(void)
    g_free(recv_buf);
    unlink(sock_path0);
    unlink(sock_path1);
    qtest_end();
    qtest_quit(qts);
}

int main(int argc, char **argv)