From nobody Mon Feb 9 11:44:23 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=1768929565; cv=none; d=zohomail.com; s=zohoarc; b=JdYlBZvHJ3Y4eG/dgolndAipFxW1j7ARF0vulJGQyn7R4OMjgMORXuhlKqEeN9G/MmRvSvgEt03C9E0QEAzyY81OUs3XkR2/lY7wMOjnsf5W9dxGNmkmPPcEPUsFeU2dkr9qGxWvV1RD6+TPlftIkpo262sFhhZx8LAw2adWvpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768929565; 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=FgmTzjUx0O002hfQqB5c16tgZWRdJZZOlIeUGwUgOXE=; b=aQOPxXAetUhtVyuq+w61zuxG1GV4IN8I5kBf3CUUq6MR6mxK90rEN4vLyfFSRe7lgjxHlNXMw+iAMOPrJHw+3w5pHpx73trU6PJfrWJBFOmoUxKZiiiGGAFpRWrVqRir0k9iocDh9zm9HyxSU+U0e76ynD88nfSHvhMNoiG9jzs= 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 1768929564286465.36469420537014; Tue, 20 Jan 2026 09:19:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1viFNc-0006tC-2K; Tue, 20 Jan 2026 12:19:00 -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 1viFNZ-0006sR-PN for qemu-devel@nongnu.org; Tue, 20 Jan 2026 12:18:58 -0500 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1viFNX-0001l4-Kq for qemu-devel@nongnu.org; Tue, 20 Jan 2026 12:18:57 -0500 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c24:fa2:0:640:41ee:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 679E480773; Tue, 20 Jan 2026 20:18:52 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:b20::1:6]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id pIe1J02A4uQ0-fnreXwAj; Tue, 20 Jan 2026 20:18:51 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1768929531; bh=FgmTzjUx0O002hfQqB5c16tgZWRdJZZOlIeUGwUgOXE=; h=Message-ID:Date:Cc:Subject:To:From; b=k1C50AuR0EoQp3Ma2wh6goOzGRdj3rd1501YO5gjqNQ8Ty+OLq0bQgHr1/+PmwVJT 4g4YSz/VRnLF+VsktXgXxqq3mV7prT/JDicYVxcatyxrqsowgtmWjWhFw8dkEOJTTT R564NxBOksQ4x81jkRBWfHZUK2F72h61TnFB8Rto= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.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 v4] tests/unit: add unit test for qemu_hexdump() Date: Tue, 20 Jan 2026 20:18:48 +0300 Message-ID: <20260120171848.455742-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=178.154.239.136; 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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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: 1768929568503158500 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 | 51 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/unit/test-cutils.c b/tests/unit/test-cutils.c index 75fae29003..5f22b83564 100644 --- a/tests/unit/test-cutils.c +++ b/tests/unit/test-cutils.c @@ -3626,6 +3626,52 @@ 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 fread(output, 1, size, f); + 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 +4041,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