Received: from eggs.gnu.org ([2001:4830:134:3::10]:40347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnYaI-0000mb-Id for qemu-devel@nongnu.org; Fri, 23 Sep 2016 18:04:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnYaH-0003gv-Ba for qemu-devel@nongnu.org; Fri, 23 Sep 2016 18:04:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnYaH-0003go-2a for qemu-devel@nongnu.org; Fri, 23 Sep 2016 18:04:41 -0400 Date: Sat, 24 Sep 2016 01:04:39 +0300 From: "Michael S. Tsirkin" Message-ID: <1474668213-15643-4-git-send-email-mst@redhat.com> References: <1474668213-15643-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1474668213-15643-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL v2 03/19] tests: add /vhost-user/flags-mismatch test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Paolo Bonzini , Eric Blake From: Marc-Andr=E9 Lureau Check that qemu disconnects the backend that doesn't have the previously acked features. Signed-off-by: Marc-Andr=E9 Lureau Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/vhost-user-test.c | 60 +++++++++++++++++++++++++++++++++++++++++++= +++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index ffdd398..a39846e 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -130,6 +130,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; @@ -143,6 +150,7 @@ typedef struct TestServer { int log_fd; uint64_t rings; bool test_fail; + int test_flags; int queues; } TestServer; =20 @@ -292,6 +300,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; @@ -299,6 +311,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: @@ -424,6 +440,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; @@ -432,7 +458,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) @@ -774,6 +801,34 @@ 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); + + init_virtio_dev(s); + 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) @@ -908,6 +963,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 MST