From nobody Sun Oct 5 19:12:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504289485635895.5251402151994; Fri, 1 Sep 2017 11:11:25 -0700 (PDT) Received: from localhost ([::1]:53121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnqPb-0005y1-UH for importer@patchew.org; Fri, 01 Sep 2017 14:11:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnqIS-00077m-Ro for qemu-devel@nongnu.org; Fri, 01 Sep 2017 14:04:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnqIR-0001aU-8B for qemu-devel@nongnu.org; Fri, 01 Sep 2017 14:04:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnqIQ-0001a8-Vy for qemu-devel@nongnu.org; Fri, 01 Sep 2017 14:03:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F96B404321 for ; Fri, 1 Sep 2017 18:03:58 +0000 (UTC) Received: from red.redhat.com (ovpn-121-149.rdu2.redhat.com [10.10.121.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F10A62929; Fri, 1 Sep 2017 18:03:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0F96B404321 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:03:21 -0500 Message-Id: <20170901180340.30009-11-eblake@redhat.com> In-Reply-To: <20170901180340.30009-1-eblake@redhat.com> References: <20170901180340.30009-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 01 Sep 2017 18:03:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 10/29] libqtest: Topologically sort functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Put static functions prior to public ones, in part so that improvements to qtest_start() can benefit from the static helpers without needing forward references. Code motion, with no semantic change. Signed-off-by: Eric Blake --- tests/libqtest.c | 263 +++++++++++++++++++++++++++------------------------= ---- 1 file changed, 131 insertions(+), 132 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 438a22678d..5d16351e24 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -49,7 +49,6 @@ static struct sigaction sigact_old; g_assert_cmpint(ret, !=3D, -1); \ } while (0) -static int qtest_query_target_endianness(QTestState *s); static int init_socket(const char *socket_path) { @@ -128,6 +127,137 @@ static void setup_sigabrt_handler(void) sigaction(SIGABRT, &sigact, &sigact_old); } +static void socket_send(int fd, const char *buf, ssize_t size) +{ + size_t offset; + + if (size < 0) { + size =3D strlen(buf); + } + offset =3D 0; + while (offset < size) { + ssize_t len; + + len =3D write(fd, buf + offset, size - offset); + if (len =3D=3D -1 && errno =3D=3D EINTR) { + continue; + } + + g_assert_no_errno(len); + g_assert_cmpint(len, >, 0); + + offset +=3D len; + } +} + +static void socket_sendf(int fd, const char *fmt, va_list ap) +{ + gchar *str =3D g_strdup_vprintf(fmt, ap); + + socket_send(fd, str, -1); + g_free(str); +} + +static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt,= ...) +{ + va_list ap; + + va_start(ap, fmt); + socket_sendf(s->fd, fmt, ap); + va_end(ap); +} + +static GString *qtest_recv_line(QTestState *s) +{ + GString *line; + size_t offset; + char *eol; + + while ((eol =3D strchr(s->rx->str, '\n')) =3D=3D NULL) { + ssize_t len; + char buffer[1024]; + + len =3D read(s->fd, buffer, sizeof(buffer)); + if (len =3D=3D -1 && errno =3D=3D EINTR) { + continue; + } + + if (len =3D=3D -1 || len =3D=3D 0) { + fprintf(stderr, "Broken pipe\n"); + exit(1); + } + + g_string_append_len(s->rx, buffer, len); + } + + offset =3D eol - s->rx->str; + line =3D g_string_new_len(s->rx->str, offset); + g_string_erase(s->rx, 0, offset + 1); + + return line; +} + +static gchar **qtest_rsp(QTestState *s, int expected_args) +{ + GString *line; + gchar **words; + int i; + +redo: + line =3D qtest_recv_line(s); + words =3D g_strsplit(line->str, " ", 0); + g_string_free(line, TRUE); + + if (strcmp(words[0], "IRQ") =3D=3D 0) { + long irq; + int ret; + + g_assert(words[1] !=3D NULL); + g_assert(words[2] !=3D NULL); + + ret =3D qemu_strtol(words[2], NULL, 0, &irq); + g_assert(!ret); + g_assert_cmpint(irq, >=3D, 0); + g_assert_cmpint(irq, <, MAX_IRQ); + + if (strcmp(words[1], "raise") =3D=3D 0) { + s->irq_level[irq] =3D true; + } else { + s->irq_level[irq] =3D false; + } + + g_strfreev(words); + goto redo; + } + + g_assert(words[0] !=3D NULL); + g_assert_cmpstr(words[0], =3D=3D, "OK"); + + if (expected_args) { + for (i =3D 0; i < expected_args; i++) { + g_assert(words[i] !=3D NULL); + } + } else { + g_strfreev(words); + } + + return words; +} + +static int qtest_query_target_endianness(QTestState *s) +{ + gchar **args; + int big_endian; + + qtest_sendf(s, "endianness\n"); + args =3D qtest_rsp(s, 1); + g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little") = =3D=3D 0); + big_endian =3D strcmp(args[1], "big") =3D=3D 0; + g_strfreev(args); + + return big_endian; +} + static void cleanup_sigabrt_handler(void) { sigaction(SIGABRT, &sigact_old, NULL); @@ -252,137 +382,6 @@ void qtest_quit(QTestState *s) g_free(s); } -static void socket_send(int fd, const char *buf, ssize_t size) -{ - size_t offset; - - if (size < 0) { - size =3D strlen(buf); - } - offset =3D 0; - while (offset < size) { - ssize_t len; - - len =3D write(fd, buf + offset, size - offset); - if (len =3D=3D -1 && errno =3D=3D EINTR) { - continue; - } - - g_assert_no_errno(len); - g_assert_cmpint(len, >, 0); - - offset +=3D len; - } -} - -static void socket_sendf(int fd, const char *fmt, va_list ap) -{ - gchar *str =3D g_strdup_vprintf(fmt, ap); - - socket_send(fd, str, -1); - g_free(str); -} - -static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt,= ...) -{ - va_list ap; - - va_start(ap, fmt); - socket_sendf(s->fd, fmt, ap); - va_end(ap); -} - -static GString *qtest_recv_line(QTestState *s) -{ - GString *line; - size_t offset; - char *eol; - - while ((eol =3D strchr(s->rx->str, '\n')) =3D=3D NULL) { - ssize_t len; - char buffer[1024]; - - len =3D read(s->fd, buffer, sizeof(buffer)); - if (len =3D=3D -1 && errno =3D=3D EINTR) { - continue; - } - - if (len =3D=3D -1 || len =3D=3D 0) { - fprintf(stderr, "Broken pipe\n"); - exit(1); - } - - g_string_append_len(s->rx, buffer, len); - } - - offset =3D eol - s->rx->str; - line =3D g_string_new_len(s->rx->str, offset); - g_string_erase(s->rx, 0, offset + 1); - - return line; -} - -static gchar **qtest_rsp(QTestState *s, int expected_args) -{ - GString *line; - gchar **words; - int i; - -redo: - line =3D qtest_recv_line(s); - words =3D g_strsplit(line->str, " ", 0); - g_string_free(line, TRUE); - - if (strcmp(words[0], "IRQ") =3D=3D 0) { - long irq; - int ret; - - g_assert(words[1] !=3D NULL); - g_assert(words[2] !=3D NULL); - - ret =3D qemu_strtol(words[2], NULL, 0, &irq); - g_assert(!ret); - g_assert_cmpint(irq, >=3D, 0); - g_assert_cmpint(irq, <, MAX_IRQ); - - if (strcmp(words[1], "raise") =3D=3D 0) { - s->irq_level[irq] =3D true; - } else { - s->irq_level[irq] =3D false; - } - - g_strfreev(words); - goto redo; - } - - g_assert(words[0] !=3D NULL); - g_assert_cmpstr(words[0], =3D=3D, "OK"); - - if (expected_args) { - for (i =3D 0; i < expected_args; i++) { - g_assert(words[i] !=3D NULL); - } - } else { - g_strfreev(words); - } - - return words; -} - -static int qtest_query_target_endianness(QTestState *s) -{ - gchar **args; - int big_endian; - - qtest_sendf(s, "endianness\n"); - args =3D qtest_rsp(s, 1); - g_assert(strcmp(args[1], "big") =3D=3D 0 || strcmp(args[1], "little") = =3D=3D 0); - big_endian =3D strcmp(args[1], "big") =3D=3D 0; - g_strfreev(args); - - return big_endian; -} - typedef struct { JSONMessageParser parser; QDict *response; --=20 2.13.5