Received: from eggs.gnu.org ([2001:4830:134:3::10]:60416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS9jJ-0003cm-9g for qemu-devel@nongnu.org; Tue, 26 Jul 2016 17:17:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bS9jF-0002Vx-95 for qemu-devel@nongnu.org; Tue, 26 Jul 2016 17:17:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS9jF-0002Vn-0f for qemu-devel@nongnu.org; Tue, 26 Jul 2016 17:17:29 -0400 From: marcandre.lureau@redhat.com Date: Wed, 27 Jul 2016 01:15:26 +0400 Message-Id: <20160726211527.28510-33-marcandre.lureau@redhat.com> In-Reply-To: <20160726211527.28510-1-marcandre.lureau@redhat.com> References: <20160726211527.28510-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v6 32/33] vhost-user-test: add flags mismatch test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mukawa@igel.co.jp, yuanhan.liu@linux.intel.com, victork@redhat.com, jonshin@cisco.com, mst@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-Andr=C3=A9 Lureau Check that qemu disconnects the backend that doesn't have the previously acked features. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/vhost-user-test.c | 59 +++++++++++++++++++++++++++++++++++++++++++= +++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 9c1438d..8e2b63c 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -126,6 +126,13 @@ static VhostUserMsg m __attribute__ ((unused)); #define VHOST_USER_VERSION (0x1) /***********************************************************************= ******/ =20 +enum { + TEST_FLAGS_OK, + TEST_FLAGS_DISCONNECT, + TEST_FLAGS_BAD, + TEST_FLAGS_END, +}; + typedef struct TestServer { gchar *socket_path; gchar *mig_path; @@ -139,6 +146,7 @@ typedef struct TestServer { int log_fd; uint64_t rings; bool test_fail; + int test_flags; int queues; } TestServer; =20 @@ -264,6 +272,10 @@ static void chr_read(void *opaque, const uint8_t *bu= f, int size) if (s->queues > 1) { msg.payload.u64 |=3D 0x1ULL << VIRTIO_NET_F_MQ; } + if (s->test_flags >=3D TEST_FLAGS_BAD) { + msg.payload.u64 =3D 0; + s->test_flags =3D TEST_FLAGS_END; + } p =3D (uint8_t *) &msg; qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); break; @@ -271,6 +283,10 @@ static void chr_read(void *opaque, const uint8_t *bu= f, int size) case VHOST_USER_SET_FEATURES: g_assert_cmpint(msg.payload.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL_FEAT= URES), !=3D, 0ULL); + if (s->test_flags =3D=3D TEST_FLAGS_DISCONNECT) { + qemu_chr_disconnect(chr); + s->test_flags =3D TEST_FLAGS_BAD; + } break; =20 case VHOST_USER_GET_PROTOCOL_FEATURES: @@ -396,6 +412,16 @@ static TestServer *test_server_new(const gchar *name= ) return server; } =20 +static void chr_event(void *opaque, int event) +{ + TestServer *s =3D opaque; + + if (s->test_flags =3D=3D TEST_FLAGS_END && + event =3D=3D CHR_EVENT_CLOSED) { + s->test_flags =3D TEST_FLAGS_OK; + } +} + static void test_server_create_chr(TestServer *server, const gchar *opt) { gchar *chr_path; @@ -404,7 +430,8 @@ static void test_server_create_chr(TestServer *server= , const gchar *opt) server->chr =3D qemu_chr_new(server->chr_name, chr_path, NULL); g_free(chr_path); =20 - qemu_chr_add_handlers(server->chr, chr_can_read, chr_read, NULL, ser= ver); + qemu_chr_add_handlers(server->chr, chr_can_read, chr_read, + chr_event, server); } =20 static void test_server_listen(TestServer *server) @@ -743,6 +770,33 @@ static void test_connect_fail(void) g_free(path); } =20 +static void test_flags_mismatch_subprocess(void) +{ + TestServer *s =3D test_server_new("flags-mismatch"); + char *cmd; + + s->test_flags =3D TEST_FLAGS_DISCONNECT; + g_thread_new("connect", connect_thread, s); + cmd =3D GET_QEMU_CMDE(s, 2, ",server", ""); + qtest_start(cmd); + g_free(cmd); + + wait_for_fds(s); + wait_for_rings_started(s, 2); + + qtest_end(); + test_server_free(s); +} + +static void test_flags_mismatch(void) +{ + gchar *path =3D g_strdup_printf("/%s/vhost-user/flags-mismatch/subpr= ocess", + qtest_get_arch()); + g_test_trap_subprocess(path, 0, 0); + g_test_trap_assert_passed(); + g_free(path); +} + #endif =20 static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot) @@ -877,6 +931,9 @@ int main(int argc, char **argv) qtest_add_func("/vhost-user/connect-fail/subprocess", test_connect_fail_subprocess); qtest_add_func("/vhost-user/connect-fail", test_connect_fail); + qtest_add_func("/vhost-user/flags-mismatch/subprocess", + test_flags_mismatch_subprocess); + qtest_add_func("/vhost-user/flags-mismatch", test_flags_mismatch); #endif =20 ret =3D g_test_run(); --=20 2.9.0