From nobody Mon Feb 9 09:46:24 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1768980802; cv=none; d=zohomail.com; s=zohoarc; b=VXMA7JieHzvm6HtPT3nqRHWkIjCBS6nLf5+C0878CMS3sIWQoOHuuKjPmoDu1ieilFmeaRAOomCxeM/+jSM2RjTKZK1UaUpMdoqhAA+PHf05L7gb7xaqLS5ZdzjBOXA3vq/wIDupWD9pYHWBxA0OkiKyFlsUJ3bmE2omCnGS0dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768980802; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KIUuEn6ZVkM4bTlt096vnTPnvoNCfAocDoEblqa+K2k=; b=jIeYoMLBr+mjP7PkOhoH9+WId5i9gBu9cu0hUqpL6/PADLNtaX3Wl1EPFYz+J5DS7nOg+Jqvdo2d7jPx9CqpfDzWOR6c9pk2SM4T11lsmyIX7tHWPY+iQfiHMm7bJEFySpI+KpSwyTATNhxMtWX8uutWqP+UFQV5EwFtAmwL2xM= 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 1768980801769118.71469075805146; Tue, 20 Jan 2026 23:33:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1viSht-0000GZ-2l; Wed, 21 Jan 2026 02:32:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1viShr-0000Fr-8O for qemu-devel@nongnu.org; Wed, 21 Jan 2026 02:32:47 -0500 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1viShp-0001ia-3b for qemu-devel@nongnu.org; Wed, 21 Jan 2026 02:32:47 -0500 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:5a81:0:640:624e:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id EE20680872; Wed, 21 Jan 2026 10:32:41 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:96e::1:11]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id eWVUFB1CBSw0-Wgr7PPNr; Wed, 21 Jan 2026 10:32:41 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1768980761; bh=KIUuEn6ZVkM4bTlt096vnTPnvoNCfAocDoEblqa+K2k=; h=Message-ID:Date:Cc:Subject:To:From; b=OOhtSbO8GwmAOJOA30GQTaAJMK849VwUYTQ2O/rQpJOEpJoqxeGFDwkbt2osP2XJi QLRu7lVXk2C8MwORNIalmBCni32b+G9MKy6cYGXZteYqoQJ/uH6wwKSPR4s8+9nV9d oNtbn9ZahD5dQWJL5LbGakuc0lg2D9otluDbDQ84= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: philmd@linaro.org Cc: berrange@redhat.com, qemu-devel@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH v5] tests/unit: add unit test for qemu_hexdump() Date: Wed, 21 Jan 2026 10:32:36 +0300 Message-ID: <20260121073236.81353-1-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 (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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1768980806052154100 Content-Type: text/plain; charset="utf-8" Test, that fix in previous commit make sense. To not break compilation when we build without 'block', move hexdump.c out of "if have_block" in meson.build. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/unit/test-cutils.c | 58 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/tests/unit/test-cutils.c b/tests/unit/test-cutils.c index 75fae29003..857396fab0 100644 --- a/tests/unit/test-cutils.c +++ b/tests/unit/test-cutils.c @@ -3626,6 +3626,59 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), =3D=3D, "E"); } =20 +static void test_qemu_hexdump_alignment(void) +{ + /* + * Test that ASCII part is properly aligned for incomplete lines. + * This test catches the bug that was fixed in previous commit + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". + * + * We use data that is not aligned to 16 bytes, so last line + * is incomplete. + */ + const uint8_t data[] =3D { + /* First line: 16 bytes */ + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "Hello Wo" */ + 0x72, 0x6c, 0x64, 0x21, 0x20, 0x54, 0x68, 0x69, /* "rld! Thi" */ + /* Second line: 5 bytes (incomplete) */ + 0x73, 0x20, 0x69, 0x73, 0x20 /* "s is " */ + }; + g_autofree char *output =3D NULL; + size_t size, bytes_read; + +#define TEST_FILE "test-qemu-hexdump-alignment.txt" + FILE *f =3D fopen(TEST_FILE, "w+"); + + g_assert_nonnull(f); + + qemu_hexdump(f, "test", data, sizeof(data)); + + size =3D ftell(f); + fseek(f, 0, SEEK_SET); + + output =3D g_malloc(size + 1); + bytes_read =3D 0; + while (bytes_read < size) { + size_t chunk =3D fread(output + bytes_read, 1, size - bytes_read, = f); + if (chunk =3D=3D 0) { + break; + } + bytes_read +=3D chunk; + } + g_assert_cmpuint(bytes_read, =3D=3D, size); + output[size] =3D '\0'; + + fclose(f); + unlink(TEST_FILE); + + /* We expect proper alignment of "s is" part on the second line */ + const char *expected =3D + "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 = Hello World! Thi\n" + "test: 0010: 73 20 69 73 20 = s is \n"; + + g_assert_cmpstr(output, =3D=3D, expected); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -3995,5 +4048,10 @@ int main(int argc, char **argv) test_iec_binary_prefix); g_test_add_func("/cutils/si_prefix", test_si_prefix); + + /* qemu_hexdump() test */ + g_test_add_func("/cutils/qemu_hexdump/alignment", + test_qemu_hexdump_alignment); + return g_test_run(); } diff --git a/util/meson.build b/util/meson.build index 59e835a8d3..1804399da0 100644 --- a/util/meson.build +++ b/util/meson.build @@ -33,6 +33,7 @@ endif util_ss.add(files('defer-call.c')) util_ss.add(files('envlist.c', 'path.c', 'module.c')) util_ss.add(files('event.c')) +util_ss.add(files('hexdump.c')) util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) util_ss.add(files('fifo8.c')) @@ -92,7 +93,6 @@ if have_block util_ss.add(files('buffer.c')) util_ss.add(files('bufferiszero.c')) util_ss.add(files('hbitmap.c')) - util_ss.add(files('hexdump.c')) util_ss.add(files('iova-tree.c')) util_ss.add(files('iov.c')) util_ss.add(files('nvdimm-utils.c')) --=20 2.52.0