From nobody Tue Feb 10 18:58:51 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651740000; cv=none; d=zohomail.com; s=zohoarc; b=AbzUg+KxS3jwVeJTdMs0NNj6TTqgIge2RzbrQjsfnShz19JMohpJ63f4gAV5wVxX2jEYE3NgC9b+AlfGSNoai9UWXVCCMq5fOuo5u6H1aTO5q8mY/1efUc8Rn0/n+k/GQSfdLSNiM9Y9FsAqEWJUcdOLOUaF4BkYs27qPZNLap8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651740000; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=P2DQcg2f7d6Ls9Ryi5RaJ5AgskrjL/TQo/dulXyKwCY=; b=GQKZhSrzJ4SBAeAZ8OyIzqiSYWI0Ovz4CNn/SdMk+Ukccqd/nX+3H3eXSjEJv6mVg2rVjve2eBj1N2z6207Vlbjg5YHExZo7iIjl/tx92Nm1wTE0tIVsQh8FfFWkkxNkmXrH4D8NQ6zKxAg6QawzF06MgyEyJud2WIIOxkZFcYc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651740000806158.64847108541187; Thu, 5 May 2022 01:40:00 -0700 (PDT) Received: from localhost ([::1]:34626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmX1j-0006EB-0N for importer@patchew.org; Thu, 05 May 2022 04:39:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmWfB-0007c2-KM for qemu-devel@nongnu.org; Thu, 05 May 2022 04:16:42 -0400 Received: from us-smtp-delivery-74.mimecast.com ([170.10.133.74]:43407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmWf9-00081L-Aq for qemu-devel@nongnu.org; Thu, 05 May 2022 04:16:41 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-230-dEQNTk1bNeWmkkIaNdW6GQ-1; Thu, 05 May 2022 04:16:35 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A882B8339C1; Thu, 5 May 2022 08:16:34 +0000 (UTC) Received: from localhost (unknown [10.39.208.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9927C2813A; Thu, 5 May 2022 08:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651738598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P2DQcg2f7d6Ls9Ryi5RaJ5AgskrjL/TQo/dulXyKwCY=; b=F4HXvkaRVkRjqxw84prhoeoAwXT6rTa3JUeHOTPr4MBG23DxCl0YjRCoOugBsJqlZLdFLs 7wURSrE9Oal9zEBm7pLP9WlNPpXIV2ARonmpkSk3NOc0zH0dK9T0DqqZDkvZw0Ew1vfBZ6 7zU22cTV6UTDyvV0OVWV2QNHd71pURk= X-MC-Unique: dEQNTk1bNeWmkkIaNdW6GQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Alexander Bulekov , Bandan Das , Thomas Huth , Hanna Reitz , Markus Armbruster , Konstantin Kostiuk , Stefan Weil , Kevin Wolf , Darren Kenny , Laurent Vivier , Michael Roth , Paolo Bonzini , Qiuhao Li , Stefan Hajnoczi , qemu-block@nongnu.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 15/15] test/qga: use g_auto wherever sensible Date: Thu, 5 May 2022 12:14:31 +0400 Message-Id: <20220505081431.934739-16-marcandre.lureau@redhat.com> In-Reply-To: <20220505081431.934739-1-marcandre.lureau@redhat.com> References: <20220505081431.934739-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.74; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-74.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651740001958100001 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/unit/test-qga.c | 125 +++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 80 deletions(-) diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index ab0b12a2dd16..53cefc2c2649 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -51,8 +51,11 @@ static void fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp) { const gchar *extra_arg =3D data; - GError *error =3D NULL; - gchar *cwd, *path, *cmd, **argv =3D NULL; + g_autoptr(GError) error =3D NULL; + g_autofree char *cwd =3D NULL; + g_autofree char *path =3D NULL; + g_autofree char *cmd =3D NULL; + g_auto(GStrv) argv =3D NULL; =20 fixture->loop =3D g_main_loop_new(NULL, FALSE); =20 @@ -78,17 +81,12 @@ fixture_setup(TestFixture *fixture, gconstpointer data,= gchar **envp) =20 fixture->fd =3D connect_qga(path); g_assert_cmpint(fixture->fd, !=3D, -1); - - g_strfreev(argv); - g_free(cmd); - g_free(cwd); - g_free(path); } =20 static void fixture_tear_down(TestFixture *fixture, gconstpointer data) { - gchar *tmp; + g_autofree char *tmp =3D NULL; =20 kill(fixture->pid, SIGTERM); =20 @@ -107,7 +105,6 @@ fixture_tear_down(TestFixture *fixture, gconstpointer d= ata) =20 tmp =3D g_build_filename(fixture->test_dir, "sock", NULL); g_unlink(tmp); - g_free(tmp); =20 g_rmdir(fixture->test_dir); g_free(fixture->test_dir); @@ -122,7 +119,7 @@ static void qmp_assertion_message_error(const char = *domain, QDict *dict) { const char *class, *desc; - char *s; + g_autofree char *s =3D NULL; QDict *error; =20 error =3D qdict_get_qdict(dict, "error"); @@ -131,7 +128,6 @@ static void qmp_assertion_message_error(const char = *domain, =20 s =3D g_strdup_printf("assertion failed %s: %s %s", expr, class, desc); g_assertion_message(domain, file, line, func, s); - g_free(s); } =20 #define qmp_assert_no_error(err) do { \ @@ -146,7 +142,7 @@ static void test_qga_sync_delimited(gconstpointer fix) const TestFixture *fixture =3D fix; guint32 v, r =3D g_test_rand_int(); unsigned char c; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; =20 qmp_fd_send_raw(fixture->fd, "\xff"); qmp_fd_send(fixture->fd, @@ -180,15 +176,13 @@ static void test_qga_sync_delimited(gconstpointer fix) =20 v =3D qdict_get_int(ret, "return"); g_assert_cmpint(r, =3D=3D, v); - - qobject_unref(ret); } =20 static void test_qga_sync(gconstpointer fix) { const TestFixture *fixture =3D fix; guint32 v, r =3D g_test_rand_int(); - QDict *ret; + g_autoptr(QDict) ret =3D NULL; =20 /* * TODO guest-sync is inherently limited: we cannot distinguish @@ -210,33 +204,27 @@ static void test_qga_sync(gconstpointer fix) =20 v =3D qdict_get_int(ret, "return"); g_assert_cmpint(r, =3D=3D, v); - - qobject_unref(ret); } =20 static void test_qga_ping(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping'}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); - - qobject_unref(ret); } =20 static void test_qga_id(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); g_assert_cmpint(qdict_get_int(ret, "id"), =3D=3D, 1); - - qobject_unref(ret); } =20 static void test_qga_invalid_oob(gconstpointer fix) @@ -253,7 +241,8 @@ static void test_qga_invalid_oob(gconstpointer fix) static void test_qga_invalid_args(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *error; + g_autoptr(QDict) ret =3D NULL; + QDict *error; const gchar *class, *desc; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping', " @@ -266,14 +255,13 @@ static void test_qga_invalid_args(gconstpointer fix) =20 g_assert_cmpstr(class, =3D=3D, "GenericError"); g_assert_cmpstr(desc, =3D=3D, "Parameter 'foo' is unexpected"); - - qobject_unref(ret); } =20 static void test_qga_invalid_cmd(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *error; + g_autoptr(QDict) ret =3D NULL; + QDict *error; const gchar *class, *desc; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-invalid-cmd'}"); @@ -285,14 +273,13 @@ static void test_qga_invalid_cmd(gconstpointer fix) =20 g_assert_cmpstr(class, =3D=3D, "CommandNotFound"); g_assert_cmpint(strlen(desc), >, 0); - - qobject_unref(ret); } =20 static void test_qga_info(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *val; + g_autoptr(QDict) ret =3D NULL; + QDict *val; const gchar *version; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-info'}"); @@ -302,14 +289,12 @@ static void test_qga_info(gconstpointer fix) val =3D qdict_get_qdict(ret, "return"); version =3D qdict_get_try_str(val, "version"); g_assert_cmpstr(version, =3D=3D, QEMU_VERSION); - - qobject_unref(ret); } =20 static void test_qga_get_vcpus(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; QList *list; const QListEntry *entry; =20 @@ -322,14 +307,12 @@ static void test_qga_get_vcpus(gconstpointer fix) entry =3D qlist_first(list); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "logical-id")); - - qobject_unref(ret); } =20 static void test_qga_get_fsinfo(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; QList *list; const QListEntry *entry; =20 @@ -346,14 +329,13 @@ static void test_qga_get_fsinfo(gconstpointer fix) g_assert(qdict_haskey(qobject_to(QDict, entry->value), "type")); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "disk")); } - - qobject_unref(ret); } =20 static void test_qga_get_memory_block_info(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *val; + g_autoptr(QDict) ret =3D NULL; + QDict *val; int64_t size; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-block-info'= }"); @@ -366,14 +348,12 @@ static void test_qga_get_memory_block_info(gconstpoin= ter fix) size =3D qdict_get_int(val, "size"); g_assert_cmpint(size, >, 0); } - - qobject_unref(ret); } =20 static void test_qga_get_memory_blocks(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; QList *list; const QListEntry *entry; =20 @@ -391,14 +371,12 @@ static void test_qga_get_memory_blocks(gconstpointer = fix) g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online= ")); } } - - qobject_unref(ret); } =20 static void test_qga_network_get_interfaces(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; QList *list; const QListEntry *entry; =20 @@ -410,8 +388,6 @@ static void test_qga_network_get_interfaces(gconstpoint= er fix) list =3D qdict_get_qlist(ret, "return"); entry =3D qlist_first(list); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name")); - - qobject_unref(ret); } =20 static void test_qga_file_ops(gconstpointer fix) @@ -642,7 +618,7 @@ static void test_qga_file_write_read(gconstpointer fix) static void test_qga_get_time(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; int64_t time; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); @@ -651,8 +627,6 @@ static void test_qga_get_time(gconstpointer fix) =20 time =3D qdict_get_int(ret, "return"); g_assert_cmpint(time, >, 0); - - qobject_unref(ret); } =20 static void test_qga_blacklist(gconstpointer data) @@ -692,19 +666,23 @@ static void test_qga_blacklist(gconstpointer data) =20 static void test_qga_config(gconstpointer data) { - GError *error =3D NULL; - char *cwd, *cmd, *out, *err, *str, **strv, **argv =3D NULL; + g_autoptr(GError) error =3D NULL; + g_autofree char *out =3D NULL; + g_autofree char *err =3D NULL; + g_autofree char *cwd =3D NULL; + g_autofree char *cmd =3D NULL; + g_auto(GStrv) argv =3D NULL; + g_auto(GStrv) strv =3D NULL; + g_autoptr(GKeyFile) kf =3D NULL; + char *str; char *env[2]; int status; gsize n; - GKeyFile *kf; =20 cwd =3D g_get_current_dir(); cmd =3D g_strdup_printf("%s%cqga%cqemu-ga -D", cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR); - g_free(cwd); g_shell_parse_argv(cmd, NULL, &argv, &error); - g_free(cmd); g_assert_no_error(error); =20 env[0] =3D g_strdup_printf("QGA_CONF=3Dtests%cdata%ctest-qga-config", @@ -712,7 +690,6 @@ static void test_qga_config(gconstpointer data) env[1] =3D NULL; g_spawn_sync(NULL, argv, env, 0, NULL, NULL, &out, &err, &status, &error); - g_strfreev(argv); =20 g_assert_no_error(error); g_assert_cmpstr(err, =3D=3D, ""); @@ -759,18 +736,14 @@ static void test_qga_config(gconstpointer data) g_assert_true(g_strv_contains((const char * const *)strv, "guest-get-time")); g_assert_no_error(error); - g_strfreev(strv); =20 - g_free(out); - g_free(err); g_free(env[0]); - g_key_file_free(kf); } =20 static void test_qga_fsfreeze_status(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; const gchar *status; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}"); @@ -779,16 +752,15 @@ static void test_qga_fsfreeze_status(gconstpointer fi= x) =20 status =3D qdict_get_try_str(ret, "return"); g_assert_cmpstr(status, =3D=3D, "thawed"); - - qobject_unref(ret); } =20 static void test_qga_guest_exec(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *val; + g_autoptr(QDict) ret =3D NULL; + QDict *val; const gchar *out; - guchar *decoded; + g_autofree guchar *decoded =3D NULL; int64_t pid, now, exitcode; gsize len; bool exited; @@ -827,14 +799,13 @@ static void test_qga_guest_exec(gconstpointer fix) decoded =3D g_base64_decode(out, &len); g_assert_cmpint(len, =3D=3D, 12); g_assert_cmpstr((char *)decoded, =3D=3D, "\" test_str \""); - g_free(decoded); - qobject_unref(ret); } =20 static void test_qga_guest_exec_invalid(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *error; + g_autoptr(QDict) ret =3D NULL; + QDict *error; const gchar *class, *desc; =20 /* invalid command */ @@ -859,13 +830,13 @@ static void test_qga_guest_exec_invalid(gconstpointer= fix) desc =3D qdict_get_str(error, "desc"); g_assert_cmpstr(class, =3D=3D, "GenericError"); g_assert_cmpint(strlen(desc), >, 0); - qobject_unref(ret); } =20 static void test_qga_guest_get_host_name(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *val; + g_autoptr(QDict) ret =3D NULL; + QDict *val; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-host-name'}"); g_assert_nonnull(ret); @@ -873,14 +844,13 @@ static void test_qga_guest_get_host_name(gconstpointe= r fix) =20 val =3D qdict_get_qdict(ret, "return"); g_assert(qdict_haskey(val, "host-name")); - - qobject_unref(ret); } =20 static void test_qga_guest_get_timezone(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret, *val; + g_autoptr(QDict) ret =3D NULL; + QDict *val; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-timezone'}"); g_assert_nonnull(ret); @@ -889,14 +859,12 @@ static void test_qga_guest_get_timezone(gconstpointer= fix) /* Make sure there's at least offset */ val =3D qdict_get_qdict(ret, "return"); g_assert(qdict_haskey(val, "offset")); - - qobject_unref(ret); } =20 static void test_qga_guest_get_users(gconstpointer fix) { const TestFixture *fixture =3D fix; - QDict *ret; + g_autoptr(QDict) ret =3D NULL; QList *val; =20 ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-users'}"); @@ -906,15 +874,13 @@ static void test_qga_guest_get_users(gconstpointer fi= x) /* There is not much to test here */ val =3D qdict_get_qlist(ret, "return"); g_assert_nonnull(val); - - qobject_unref(ret); } =20 static void test_qga_guest_get_osinfo(gconstpointer data) { TestFixture fixture; const gchar *str; - QDict *ret =3D NULL; + g_autoptr(QDict) ret =3D NULL; char *env[2]; QDict *val; =20 @@ -958,7 +924,6 @@ static void test_qga_guest_get_osinfo(gconstpointer dat= a) g_assert_nonnull(str); g_assert_cmpstr(str, =3D=3D, "unit-test"); =20 - qobject_unref(ret); g_free(env[0]); fixture_tear_down(&fixture, NULL); } --=20 2.36.0.44.g0f828332d5ac