From nobody Sat Feb 7 20:40:31 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 255201B0421 for ; Sat, 8 Mar 2025 09:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426518; cv=none; b=Gmacbv/jpNQdkXvdDM4dBFO0kroIsy/jhIG+af+VaREvdMFFcsd7JnKhNY1KTNty3Pz8AWYYN6d6f01TDfsDKiWLtLS9jQliYHFwExYyyu3auEOW0D77lfL6PSZhcYYbcjw4IkaGmLNmD2LxM2c3t0WRp6cuDWTYgqUlLhypo1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426518; c=relaxed/simple; bh=gJT8KFm2BDhcFxPIXv4x/VUO8cwfBB/jJoOBt6gPwRs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kyuhKDg4XX5fOW4tf0xRXS6ZUvy4QbE0rKA0MMHUF6X8iIzXhCu1n/DndcM1AEiM4HUe8uyqSb30SDHyD6gjBI6odVL5scYAz4v5ak7VKbuxguy+LAUrXUkB2341FYwf3sQ+KBiBCGjaKQKkNdKjc8Ww7iSNNy4iGndp3LrS05M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XjNw2D2V; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XjNw2D2V" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43bc48ff815so15777435e9.0 for ; Sat, 08 Mar 2025 01:35:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741426514; x=1742031314; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iS0WSD5gKp5cnAuszIjnCYCd0M0+1iOtyBELh+t/oUk=; b=XjNw2D2V14XDu3HK3OJGDX7UFUzk/le/UmCRTcKUWHxkXup/OHWIgm2zfTDjZVTs4B ASpn8KjcsxwSumlieg/SLzChlmCbgkkVQReH8Z9Hj1pU+zjmjtIF7wHnFGCVEepvR2fK dcRu+Yv0m8S9sLx9dH9mzmw+PxJQQLYG57ayunqCFrz1dMNKflsarcsL1bbFu8HFR7zR 0qaqYv+6GgCy1RhEzJ8IUG/VJJQpsh40KJhrEoSfDDRPjEdQsXDJCOw/n1QAagDLbRoX fUSlW7t5MsOMGUNlPGOZ3rPDeqbtB3R+uhs2gwlJtUPL2nrhta9klNv94eK70CyPwhn6 t6EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741426514; x=1742031314; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iS0WSD5gKp5cnAuszIjnCYCd0M0+1iOtyBELh+t/oUk=; b=GD7uQU7TrA93u01f2tCpJGNNAN0zYlh3lEL3FSlsb6rDd9ZDOKLJiC8FovAK+4hi3e abHVeCYfmsCl1cNiataZmIN2GaFW+ltL2VIb3h88ERMbcqKi20p6i6M60RNKDmgLRBmC JL0A2IHLuTrGzuauITr/+K8SLyF7TYMaS9RqavUGPstP1z+E3so1+IlaAzObMpSvhN4q iAoaU9Bj0u7gfqGss0udZvcAAvM8GNnjDDzEk1z45JzXM1Z9ACrXK8NFXFB5itDfwFwM wBMZ1xnU4SaUNs9zUm9JEOgv9meCoexCFQEn1PUXhKKdBEI4kUBvN9SffkTq6Jzn1Y4r TweA== X-Gm-Message-State: AOJu0YwDHyyBng9zsFujsk4jDJ5+gxywGD2fPLXbzqRvWdMKwXuS1h9I 8w7yY/wfk04sZj8i9OkpbvtOuS7Kb/dcRKimjpGxltfal8lgu8Rc/0KLrw== X-Gm-Gg: ASbGncuZ83wKY2P/EYfTDQYRaNQsjzbRnbosoId6Bf0OQpjo9mFh3owIemzrRGFthQl UGRYckmP6h4XZGRaKUPA7mVMQLdTxCPy0G00nYKEPooKQ6CTYdctbcPrtO+qwWYbN8U+57QUd5L xUsXyYjipXQu2NRNLtcK1ffnH31ELtd4Zzg6iSIZxy1wuWERcx5/hWjoYR9VgTaQG4lLey30ocY iIXphshttehTe7Aonj7DP5AMt7pPJhb+e9AoNgS6LnMTmggOVY599lOZX0pLnUoah7oFik/2AaR bmXSjmwfM+ynqZ6DQAI6Pm52doNtFeNfHmzlar3aPFTmF4lHFetYWC5p7hWblCo5KaM6eBP3pwg GWOMZ0IK+DhOxAhFSXNQhohoMAA== X-Google-Smtp-Source: AGHT+IH4O6vzDrZ1HR1AZ4KCRONlOv/LizsBVk9kFV6Vz/TriUtHWtb84lTI8Cs29KXJfWVOcPFxwg== X-Received: by 2002:a05:600c:54f1:b0:43b:c638:3433 with SMTP id 5b1f17b1804b1-43ce4af10f3mr13048525e9.12.1741426514063; Sat, 08 Mar 2025 01:35:14 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ce3f573f6sm15663895e9.0.2025.03.08.01.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Mar 2025 01:35:13 -0800 (PST) From: David Laight To: linux-kernel@vger.kernel.org, Andrew Morton Cc: David Laight , Arnd Bergmann , Linus Torvalds , Christophe Leroy , Andy Shevchenko , Rasmus Villemoes , nnac123@linux.ibm.com, horms@kernel.org Subject: [PATCH next 1/8] test_hexdump: Change rowsize and groupsize to size_t Date: Sat, 8 Mar 2025 09:34:45 +0000 Message-Id: <20250308093452.3742-2-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250308093452.3742-1-david.laight.linux@gmail.com> References: <20250308093452.3742-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Both refer to positive values, size_t matches the other parameters. Signed-off-by: David Laight --- lib/test_hexdump.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 751645645988..502768e56e4e 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -64,14 +64,14 @@ static const char * const test_data_8_be[] __initconst = =3D { static unsigned total_tests __initdata; static unsigned failed_tests __initdata; =20 -static void __init test_hexdump_prepare_test(size_t len, int rowsize, - int groupsize, char *test, +static void __init test_hexdump_prepare_test(size_t len, size_t rowsize, + size_t groupsize, char *test, size_t testlen, bool ascii) { char *p; const char * const *result; size_t l =3D len; - int gs =3D groupsize, rs =3D rowsize; + size_t gs =3D groupsize, rs =3D rowsize; unsigned int i; const bool is_be =3D IS_ENABLED(CONFIG_CPU_BIG_ENDIAN); =20 @@ -122,7 +122,7 @@ static void __init test_hexdump_prepare_test(size_t len= , int rowsize, =20 #define TEST_HEXDUMP_BUF_SIZE (32 * 3 + 2 + 32 + 1) =20 -static void __init test_hexdump(size_t len, int rowsize, int groupsize, +static void __init test_hexdump(size_t len, size_t rowsize, size_t groupsi= ze, bool ascii) { char test[TEST_HEXDUMP_BUF_SIZE]; @@ -139,16 +139,16 @@ static void __init test_hexdump(size_t len, int rowsi= ze, int groupsize, ascii); =20 if (memcmp(test, real, TEST_HEXDUMP_BUF_SIZE)) { - pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize); + pr_err("Len: %zu row: %zu group: %zu\n", len, rowsize, groupsize); pr_err("Result: '%s'\n", real); pr_err("Expect: '%s'\n", test); failed_tests++; } } =20 -static void __init test_hexdump_set(int rowsize, bool ascii) +static void __init test_hexdump_set(size_t rowsize, bool ascii) { - size_t d =3D min_t(size_t, sizeof(data_b), rowsize); + size_t d =3D min(sizeof(data_b), rowsize); size_t len =3D get_random_u32_inclusive(1, d); =20 test_hexdump(len, rowsize, 4, ascii); @@ -158,13 +158,13 @@ static void __init test_hexdump_set(int rowsize, bool= ascii) } =20 static void __init test_hexdump_overflow(size_t buflen, size_t len, - int rowsize, int groupsize, + size_t rowsize, size_t groupsize, bool ascii) { char test[TEST_HEXDUMP_BUF_SIZE]; char buf[TEST_HEXDUMP_BUF_SIZE]; - int rs =3D rowsize, gs =3D groupsize; - int ae, he, e, f, r; + size_t rs =3D rowsize, gs =3D groupsize; + size_t ae, he, e, f, r; bool a; =20 total_tests++; @@ -185,7 +185,7 @@ static void __init test_hexdump_overflow(size_t buflen,= size_t len, else e =3D he; =20 - f =3D min_t(int, e + 1, buflen); + f =3D min(e + 1, buflen); if (buflen) { test_hexdump_prepare_test(len, rs, gs, test, sizeof(test), ascii); test[f - 1] =3D '\0'; @@ -199,8 +199,8 @@ static void __init test_hexdump_overflow(size_t buflen,= size_t len, if (!a) { pr_err("Len: %zu buflen: %zu strlen: %zu\n", len, buflen, strnlen(buf, sizeof(buf))); - pr_err("Result: %d '%s'\n", r, buf); - pr_err("Expect: %d '%s'\n", e, test); + pr_err("Result: %zu '%s'\n", r, buf); + pr_err("Expect: %zu '%s'\n", e, test); failed_tests++; } } @@ -208,10 +208,10 @@ static void __init test_hexdump_overflow(size_t bufle= n, size_t len, static void __init test_hexdump_overflow_set(size_t buflen, bool ascii) { unsigned int i =3D 0; - int rs =3D get_random_u32_inclusive(1, 2) * 16; + size_t rs =3D get_random_u32_inclusive(1, 2) * 16; =20 do { - int gs =3D 1 << i; + size_t gs =3D 1 << i; size_t len =3D get_random_u32_below(rs) + gs; =20 test_hexdump_overflow(buflen, rounddown(len, gs), rs, gs, ascii); @@ -221,7 +221,7 @@ static void __init test_hexdump_overflow_set(size_t buf= len, bool ascii) static int __init test_hexdump_init(void) { unsigned int i; - int rowsize; + size_t rowsize; =20 rowsize =3D get_random_u32_inclusive(1, 2) * 16; for (i =3D 0; i < 16; i++) --=20 2.39.5 From nobody Sat Feb 7 20:40:31 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D59F01AF0C5 for ; Sat, 8 Mar 2025 09:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426518; cv=none; b=QXaskojrrbxpnB9rz9UlsSfl9JPsdpCoi2wNWG6XdqAN1RhF7PqnqMXsVEp8GE8c+lPBQG010GCJTz6FTeB3wjzeFHZK/AFPR8krC4ZWGASlD/8uUt/smForz8aygZldSXmGrSSQGelHy8fvEGrge+0Am6fJSd+DU172JIsAqHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426518; c=relaxed/simple; bh=CkYsnKRXNatWif3xICg+QL4M1DMIPG6ytqPYguDtjdU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ca5oktAKhEiZSFFju7EX4OFlWSDMS2tu9DRB+GeRaB7p7YsH6XJ7CM7lrdlfgaH7CLwAOfDf5s8/jqGTwNa+2wAb1MSQa5hs/RmlbkSEXD8Gd2OIRLNpCmSXVEEdfjzRtoAYWU/eua8fOcL1MAUANJCZG6xKzacyLwQAYXGyURA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gVJjbcL8; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gVJjbcL8" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4394036c0efso14859595e9.2 for ; Sat, 08 Mar 2025 01:35:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741426515; x=1742031315; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RcOCVzvPBtsIxHK6RsctkJ4kjVqT46IPYI0eIByXjGs=; b=gVJjbcL8RgQCwTxd0bMkrutMMXnWQndROAfmjup6ENkxyqonOynnobqRE3SI2S0gnU VC+NhH6FxUNQZDQWp4UvKC3tcANUJpmfSqwO3qZ2rsI6w3Q1BhBTfnOI7SakDLBxosyf dP+tZbUIuPg3le8Xw1+Mux2P96KkYI5CULOO+PphoqXh8pjhWtKZWmaNMDnlmalhEX/i Q/aFm7cRboyFEmdwPlqwwMqtydwTBLgUx8NIEEeG3/vrCyH5AN6/NrIaU2SqP/Pm+jfR x3VL17s9O7640Qg8WeGBupbFAl+bB7q+ju8QDIEaqcsHxekBK5+DPbt/CR9ONtYvn13K l8/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741426515; x=1742031315; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RcOCVzvPBtsIxHK6RsctkJ4kjVqT46IPYI0eIByXjGs=; b=c5+8D+Qts0nf2gBdt+56LLVHtHcazIhfbKUvXIoeffwYf0+jkDbql9Ruf67cE/6jvb xIChzszmJbvY/pt+1ew2KFRfK334aoq/Ua3xiix1tO2HIvaR+jYfA97OLF1vl5yIXElM H6cSF6/7uuOM1V6aucXi1DAw10xhVIo31iRiEWmsJ/owSWaeEzMZFVtd12LhCIlMZ512 iOdvkk2nfkZPocRWTq7JZld8F1jMXCGE5MSCZ6Rr2W9Bt/P6VIfPdkgqNS+HI0AonQTH VYAyUJWaS+k1blskRcKUchu+jCnyBCIWc4zhj2W+QJVZzlLc0PQ9TPC3HmuMGQ2IzHwW WpPQ== X-Gm-Message-State: AOJu0YwurjbSf55Xyd3QnifMsIPzEpndu5ZfBbWFFulTB6BhMGLlmmG0 VsFbsXCH4MZesHKUOf8lm3YK/6v5xGBBjgHnJclVMlf+kLbQshoyZAB12w== X-Gm-Gg: ASbGncvN1jy6BkGPacms96RaORJwM6QS1b1gNbcqPjNoSBow0B0x9YEHb44lTFlW+L1 g4cBK4dK81sLzhTEw8MnUAUfrixh31G8xgK0vih15nY85+0BNVfi3wg2CwX17KECjAWrMAjFXIt FIJ1umOr0cQG6txPueaVwLA92MjfrC/d+9ARttcRDvE3TEBoGZr66noUpgcRHSa0G2HzAi6Goke aDtzlzip4+7s3ZK2By1qSeYFL0WgM8m1MDHNbMqNneRvgZMx73k5yHQOfQ/HHkEqkouRBEJyUZj abOeGXWAzeIcj6Y1T8cBg/RpCCsDDAGUo/l+Dw1xaEb35cRUYGXWIQKSkqpjEbF77rEBqYEZnnq z/izI1jGq5vkQQzOVEuYsr/l39w== X-Google-Smtp-Source: AGHT+IF7zQ7HAhUUObeZ6zTf1to4CejJUYxSdhRm7Z8XHD0R1guQv5sMhA0F5l3onw+eK+2Zvj5lLQ== X-Received: by 2002:a7b:ca4c:0:b0:43c:eb00:50eb with SMTP id 5b1f17b1804b1-43ceb0054a9mr7366065e9.5.1741426514786; Sat, 08 Mar 2025 01:35:14 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ce3f573f6sm15663895e9.0.2025.03.08.01.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Mar 2025 01:35:14 -0800 (PST) From: David Laight To: linux-kernel@vger.kernel.org, Andrew Morton Cc: David Laight , Arnd Bergmann , Linus Torvalds , Christophe Leroy , Andy Shevchenko , Rasmus Villemoes , nnac123@linux.ibm.com, horms@kernel.org Subject: [PATCH next 2/8] test_hexdump: Create test output data from the binary input data buffer Date: Sat, 8 Mar 2025 09:34:46 +0000 Message-Id: <20250308093452.3742-3-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250308093452.3742-1-david.laight.linux@gmail.com> References: <20250308093452.3742-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Using the same data that is passed to hex_dump_to_buffer() lets the tests be expanded to test different input data bytes. Signed-off-by: David Laight --- lib/test_hexdump.c | 80 +++++++++------------------------------------- 1 file changed, 15 insertions(+), 65 deletions(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 502768e56e4e..e142b11c36c6 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -3,6 +3,7 @@ */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include #include @@ -16,49 +17,6 @@ static const unsigned char data_b[] =3D { '\x4c', '\xd1', '\x19', '\x99', '\x43', '\xb1', '\xaf', '\x0c', /* 18 - 1= f */ }; =20 -static const unsigned char data_a[] =3D ".2.{....p..$}.4...1.....L...C..."; - -static const char * const test_data_1[] __initconst =3D { - "be", "32", "db", "7b", "0a", "18", "93", "b2", - "70", "ba", "c4", "24", "7d", "83", "34", "9b", - "a6", "9c", "31", "ad", "9c", "0f", "ac", "e9", - "4c", "d1", "19", "99", "43", "b1", "af", "0c", -}; - -static const char * const test_data_2_le[] __initconst =3D { - "32be", "7bdb", "180a", "b293", - "ba70", "24c4", "837d", "9b34", - "9ca6", "ad31", "0f9c", "e9ac", - "d14c", "9919", "b143", "0caf", -}; - -static const char * const test_data_2_be[] __initconst =3D { - "be32", "db7b", "0a18", "93b2", - "70ba", "c424", "7d83", "349b", - "a69c", "31ad", "9c0f", "ace9", - "4cd1", "1999", "43b1", "af0c", -}; - -static const char * const test_data_4_le[] __initconst =3D { - "7bdb32be", "b293180a", "24c4ba70", "9b34837d", - "ad319ca6", "e9ac0f9c", "9919d14c", "0cafb143", -}; - -static const char * const test_data_4_be[] __initconst =3D { - "be32db7b", "0a1893b2", "70bac424", "7d83349b", - "a69c31ad", "9c0face9", "4cd11999", "43b1af0c", -}; - -static const char * const test_data_8_le[] __initconst =3D { - "b293180a7bdb32be", "9b34837d24c4ba70", - "e9ac0f9cad319ca6", "0cafb1439919d14c", -}; - -static const char * const test_data_8_be[] __initconst =3D { - "be32db7b0a1893b2", "70bac4247d83349b", - "a69c31ad9c0face9", "4cd1199943b1af0c", -}; - #define FILL_CHAR '#' =20 static unsigned total_tests __initdata; @@ -69,11 +27,9 @@ static void __init test_hexdump_prepare_test(size_t len,= size_t rowsize, size_t testlen, bool ascii) { char *p; - const char * const *result; size_t l =3D len; size_t gs =3D groupsize, rs =3D rowsize; - unsigned int i; - const bool is_be =3D IS_ENABLED(CONFIG_CPU_BIG_ENDIAN); + size_t bs, i, j; =20 if (rs !=3D 16 && rs !=3D 32) rs =3D 16; @@ -83,26 +39,18 @@ static void __init test_hexdump_prepare_test(size_t len= , size_t rowsize, =20 if (!is_power_of_2(gs) || gs > 8 || (len % gs !=3D 0)) gs =3D 1; - - if (gs =3D=3D 8) - result =3D is_be ? test_data_8_be : test_data_8_le; - else if (gs =3D=3D 4) - result =3D is_be ? test_data_4_be : test_data_4_le; - else if (gs =3D=3D 2) - result =3D is_be ? test_data_2_be : test_data_2_le; - else - result =3D test_data_1; + bs =3D IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) ? 0 : gs - 1; =20 /* hex dump */ p =3D test; - for (i =3D 0; i < l / gs; i++) { - const char *q =3D *result++; - size_t amount =3D strlen(q); - - memcpy(p, q, amount); - p +=3D amount; - - *p++ =3D ' '; + for (i =3D 0, j =3D 0; i < l; i++) { + unsigned char b =3D data_b[i ^ bs]; + *p++ =3D "0123456789abcdef"[b >> 4]; + *p++ =3D "0123456789abcdef"[b & 15]; + if (++j =3D=3D gs) { + j =3D 0; + *p++ =3D ' '; + } } if (i) p--; @@ -113,8 +61,10 @@ static void __init test_hexdump_prepare_test(size_t len= , size_t rowsize, *p++ =3D ' '; } while (p < test + rs * 2 + rs / gs + 1); =20 - memcpy(p, data_a, l); - p +=3D l; + for (i =3D 0; i < l; i++) { + unsigned char b =3D data_b[i]; + *p++ =3D (isascii(b) && isprint(b)) ? b : '.'; + } } =20 *p =3D '\0'; --=20 2.39.5 From nobody Sat Feb 7 20:40:31 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8849B1B041C for ; Sat, 8 Mar 2025 09:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426519; cv=none; b=DMo0nsZboayQqSglA+i7iF/+eG3LxajsTlExm1nc0/1Rr53LFbFL6Q84MgffeIxWklkOPVQR9AFlCRvCxKcWRCdBtpX+euch1AjWnE7V0NVy/Y2UH0hU62EhyaerNsv1/pAytq/J2MoORH+SEVQvIAI0YNWHXkdrrLQYz3+6bbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426519; c=relaxed/simple; bh=MyZk6fSEEAU1j5j19Vgbj0IZIpCkG7MCb8+Wkev9LZ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TTia1o8etxEpau/udnN0pG1ObSybZAJhL4V8ULWTaffk9V7ugd6dHTUB5P8+IH1cJnIKF58di+CsAm9iyll7QlD9OLahZ/4jPEr/OLJBkbJDHGXdmxBSW5yf/AlHnG7Er+DDcurjvCnMvxBKrj4JZd9uTsEbxkRNsWMTE4HRwTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gr0ZmOmV; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gr0ZmOmV" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-43bd45e4d91so15697755e9.1 for ; Sat, 08 Mar 2025 01:35:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741426516; x=1742031316; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XTYbCZgZ62mscw+fPR883v5qEHUvINwlZxHSBDC1Mqs=; b=gr0ZmOmVvhOwNzFGwzlWr7Ppw7azhfhZC+1cDrDWrJfc/N6G1vztel0jJSPUH3zB/9 k0BP05luLld9QaYhqAXpNsVXszJWSSQ67k6Bj4XSRjhI/Vjj+4RsqawfDMhWOzvKh8qo yOM4qUjXzb4w8CEPmYNBKVS9N4VymM703Z7RnyqewpLLZPJ2DfqcNfXj1isM9Qdc4YrF 4wa3jeGuopwZcP2HqP5b36sg57/FTyvwN4D+uGmdwYMlJMOMgGQuucK32bkRqStnOpDj lQzMQyTLsNrA9uM7rv5CmkKQ05BQeLaBIxgOzGwPPObqZLYOkzLhZtcSjdtcPeF8eZbL xxZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741426516; x=1742031316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XTYbCZgZ62mscw+fPR883v5qEHUvINwlZxHSBDC1Mqs=; b=pj4AeUH9RPRLFWUzShrP1Xe3CJfgKS66ocPrnpeH7qQEXXTdnDSeTrw7khhL5Bvhz4 e2fBHidQd2Frzi/AQ7DJ/aOspM1gf4r1rcxT19icDv/AZE6Bh09qaQ628hbgXW4YKLUg p4V0fm3Tcwq1+eJxn+IWri0ZCFq9bmgngCBL0I96bf5hY3v94OZAt+iq6NCdN4HTst5r G+MNGd43kkbMEZT910vLwO9eg46hf+C5WXORSfKO1jXZA91vM1lAe2+2Urlc0DvHOyRj MAS4JoNJS1jbFH5m/+xp2GvmsRZ3h4nxgRJenY++hpdXqsrku5LFqjnF34e4qfh6Utfx Bb8Q== X-Gm-Message-State: AOJu0YyF+17xsmLmg7/UzraLEqs69Jj3+9gcK3lIVPCnEKdVv6vM4POh ITw2nm7vJ63vUzI0kr5KUYPqgAXM07zRB7FdWQiqKMTbYmIaUlcnQhiTVA== X-Gm-Gg: ASbGnctXTQ5sn/2vCeZPKTkdqwpZNT5BxhAt3Sjzp1GPIFmIRrLl2cA3IB0Ag+Pyfyl rRFHHRkSRjdNELviWvpOUNbONHe2KFmEFOGF/SVUw5BVB07nPmCOr3/lV1qobO8pY/S4W2BjxXs eYJecw1HzUKYwULfcoWYA//u+GZwk2984yB6iXIfhPflG9fn1B/XpA8UIwHcYF6vSM5zvIWhzbO lV+WblIj2Ar4E3V6+o3KS4Bof5v03o5BfTXYTKbkhJTPGkkbgLaNaozlPs6NSFice37KOuX4eWv qma5uCdVRXcmt4g8pdGSI3036zn8LtcQddpmtAyjMfx8B+Fa+1iFe7pDlZGllMbrQR2N42RuKXc yStOB0/jtTop8Aj45XuprUHIYBQ== X-Google-Smtp-Source: AGHT+IHnB88p51a4UgLfQucwZzVz+7NxSdJc6jJsqBJrTOvWbxTsKy0T37alVMRdleosV9iswqBCgg== X-Received: by 2002:a05:600c:a47:b0:439:9434:4f3b with SMTP id 5b1f17b1804b1-43ce4ad68a2mr14792855e9.8.1741426515603; Sat, 08 Mar 2025 01:35:15 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ce3f573f6sm15663895e9.0.2025.03.08.01.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Mar 2025 01:35:15 -0800 (PST) From: David Laight To: linux-kernel@vger.kernel.org, Andrew Morton Cc: David Laight , Arnd Bergmann , Linus Torvalds , Christophe Leroy , Andy Shevchenko , Rasmus Villemoes , nnac123@linux.ibm.com, horms@kernel.org Subject: [PATCH next 3/8] test_hexdump: Use longer variable names Date: Sat, 8 Mar 2025 09:34:47 +0000 Message-Id: <20250308093452.3742-4-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250308093452.3742-1-david.laight.linux@gmail.com> References: <20250308093452.3742-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We're not so short of memory space for the compiler symbol table that variable names have to be limited to 2 characters. Use groupsize and rowsize (not gs and rs). There is also no need to copy the function parameters to locals. Change test_hexdump_prepare_test() (the function that gernerate the sample output) to return the length - saves calculating it separately. Test reports 'all 1184 tests passed'. Signed-off-by: David Laight --- lib/test_hexdump.c | 81 +++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index e142b11c36c6..743ea5c78f9e 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -22,32 +22,30 @@ static const unsigned char data_b[] =3D { static unsigned total_tests __initdata; static unsigned failed_tests __initdata; =20 -static void __init test_hexdump_prepare_test(size_t len, size_t rowsize, - size_t groupsize, char *test, - size_t testlen, bool ascii) +static size_t __init test_hexdump_prepare_test(size_t len, size_t rowsize, + size_t groupsize, char *test, + size_t testlen, bool ascii) { char *p; - size_t l =3D len; - size_t gs =3D groupsize, rs =3D rowsize; - size_t bs, i, j; + size_t byteswap, i, j; =20 - if (rs !=3D 16 && rs !=3D 32) - rs =3D 16; + if (rowsize !=3D 16 && rowsize !=3D 32) + rowsize =3D 16; =20 - if (l > rs) - l =3D rs; + if (len > rowsize) + len =3D rowsize; =20 - if (!is_power_of_2(gs) || gs > 8 || (len % gs !=3D 0)) - gs =3D 1; - bs =3D IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) ? 0 : gs - 1; + if (!is_power_of_2(groupsize) || groupsize > 8 || (len % groupsize !=3D 0= )) + groupsize =3D 1; + byteswap =3D IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) ? 0 : groupsize - 1; =20 /* hex dump */ p =3D test; - for (i =3D 0, j =3D 0; i < l; i++) { - unsigned char b =3D data_b[i ^ bs]; + for (i =3D 0, j =3D 0; i < len; i++) { + unsigned char b =3D data_b[i ^ byteswap]; *p++ =3D "0123456789abcdef"[b >> 4]; *p++ =3D "0123456789abcdef"[b & 15]; - if (++j =3D=3D gs) { + if (++j =3D=3D groupsize) { j =3D 0; *p++ =3D ' '; } @@ -59,15 +57,16 @@ static void __init test_hexdump_prepare_test(size_t len= , size_t rowsize, if (ascii) { do { *p++ =3D ' '; - } while (p < test + rs * 2 + rs / gs + 1); + } while (p < test + rowsize * 2 + rowsize / groupsize + 1); =20 - for (i =3D 0; i < l; i++) { + for (i =3D 0; i < len; i++) { unsigned char b =3D data_b[i]; *p++ =3D (isascii(b) && isprint(b)) ? b : '.'; } } =20 *p =3D '\0'; + return p - test; } =20 #define TEST_HEXDUMP_BUF_SIZE (32 * 3 + 2 + 32 + 1) @@ -113,44 +112,35 @@ static void __init test_hexdump_overflow(size_t bufle= n, size_t len, { char test[TEST_HEXDUMP_BUF_SIZE]; char buf[TEST_HEXDUMP_BUF_SIZE]; - size_t rs =3D rowsize, gs =3D groupsize; - size_t ae, he, e, f, r; - bool a; + size_t expected; + size_t f, result; + bool ok; =20 total_tests++; =20 memset(buf, FILL_CHAR, sizeof(buf)); =20 - r =3D hex_dump_to_buffer(data_b, len, rs, gs, buf, buflen, ascii); + result =3D hex_dump_to_buffer(data_b, len, rowsize, groupsize, buf, + buflen, ascii); =20 - /* - * Caller must provide the data length multiple of groupsize. The - * calculations below are made with that assumption in mind. - */ - ae =3D rs * 2 /* hex */ + rs / gs /* spaces */ + 1 /* space */ + len /* a= scii */; - he =3D (gs * 2 /* hex */ + 1 /* space */) * len / gs - 1 /* no trailing s= pace */; + /* Test output is generated into a 'long enough' buffer */ + expected =3D test_hexdump_prepare_test(len, rowsize, groupsize, test, + sizeof(test), ascii); =20 - if (ascii) - e =3D ae; - else - e =3D he; - - f =3D min(e + 1, buflen); - if (buflen) { - test_hexdump_prepare_test(len, rs, gs, test, sizeof(test), ascii); + f =3D min(expected + 1, buflen); + if (f) test[f - 1] =3D '\0'; - } memset(test + f, FILL_CHAR, sizeof(test) - f); =20 - a =3D r =3D=3D e && !memcmp(test, buf, TEST_HEXDUMP_BUF_SIZE); + ok =3D result =3D=3D expected && !memcmp(test, buf, TEST_HEXDUMP_BUF_SIZE= ); =20 buf[sizeof(buf) - 1] =3D '\0'; =20 - if (!a) { + if (!ok) { pr_err("Len: %zu buflen: %zu strlen: %zu\n", len, buflen, strnlen(buf, sizeof(buf))); - pr_err("Result: %zu '%s'\n", r, buf); - pr_err("Expect: %zu '%s'\n", e, test); + pr_err("Result: %zu '%s'\n", result, buf); + pr_err("Expect: %zu '%s'\n", expected, test); failed_tests++; } } @@ -158,13 +148,14 @@ static void __init test_hexdump_overflow(size_t bufle= n, size_t len, static void __init test_hexdump_overflow_set(size_t buflen, bool ascii) { unsigned int i =3D 0; - size_t rs =3D get_random_u32_inclusive(1, 2) * 16; + size_t rowsize =3D get_random_u32_inclusive(1, 2) * 16; =20 do { - size_t gs =3D 1 << i; - size_t len =3D get_random_u32_below(rs) + gs; + size_t groupsize =3D 1 << i; + size_t len =3D get_random_u32_below(rowsize) + groupsize; =20 - test_hexdump_overflow(buflen, rounddown(len, gs), rs, gs, ascii); + test_hexdump_overflow(buflen, rounddown(len, groupsize), + rowsize, groupsize, ascii); } while (i++ < 3); } =20 --=20 2.39.5 From nobody Sat Feb 7 20:40:31 2026 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 556501B042C for ; Sat, 8 Mar 2025 09:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426520; cv=none; b=ay9HAon3bzU626hXYezI9yqs1Ngb2nb0o8hI/8kWvXZGIQhSyF8focJmwT9llTgfiNMdhshXvGMVBr+AaaMQji5xD+MXS5pLpmj17oufZuu8u2Web+Ul/g/6tcEmw/iDbiW4jUQJVsui6eWwgs27vuw7KhICYhTeZZFIirg11Qs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426520; c=relaxed/simple; bh=Na5QZnzZVT+yDAfsuNqlRZjHxAdQgXYY3JM2ct9y3rY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SCxA/BzoPqxcnRQL49fgS4oPNIwES0cjr+knB5AWABjcHUicvDMaDf+BuIU6KZWed08PNye6iI6ptY4iQEeHKO1llw/Rcv8xMqbr1p/NcHaXzvCnxSq3uRryvawirCJ13xBEclRIn/J1fHySzGelFKQ40hIAY4V7P7kYJZZPS/w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EQumPoEA; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EQumPoEA" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3913cf69784so321128f8f.1 for ; Sat, 08 Mar 2025 01:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741426516; x=1742031316; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IcclpSrczhYCUkaASfB4VlFx0+UuGDBAbCCoNJpvREs=; b=EQumPoEAorNYFDyTVpkeFw6NixWK0paRObthSgC3xE/az44Yq9qabbwyS0TkGouaTS Cozs27wVr6Cm6RgPNtuCG04lcOxtjq6iPkxeHXwR8Bq517BmhrXIXpQmo2jgJltACy7L TfO0t8K1ZU4sm6zvVSE6GJsws+pEf8BC3DDcjrM7bNFNnD17wGYERNKiizfE1834XLcc ZQ3Ef0d+TiCSKXLI7wPgidMJDvOSHN+3KPQ9i+504HyfwNw9b7f1nIaB5ePqrKaxvWLB suaocpt5bmFxv+mFPQa4XKU7F1drKTCUTIYoWwiRzwtymdNcW4GizIHG0ks8dN2VtXsX ErSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741426516; x=1742031316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IcclpSrczhYCUkaASfB4VlFx0+UuGDBAbCCoNJpvREs=; b=XQGEAbohhz+wdz7U4KWrcYO/inj5dgY0i9TVqIjPbKp0UAFF46XaYO3wz1kVqU2oCO O8fGRD4YRdHuvBB7BGUtcRR6SkwjuhIdS8vEGDYTWXi14PyQdLiMO0f/cyi/pURa3Ywj 9ZT2D7F52u+vYUh5HuwMgL19/3o5qq4xVfrPa2BaM/KjWL6e81+UeTFBCT58Xr4RUpSY /bd8NGnitGX1ml7ZBch3iJ7mA5qqfBwccbzhvl/MFen3+oF6pXCFfc/ninGeVAltD2wA vq6foq9BTW8jysoD5t4DUxt2R6iiUWZJ7YbsOJlazdgeQ4kEL//6VE93iD9AqwQXU6Ic YzWg== X-Gm-Message-State: AOJu0Yw7ivK6SrWBFX2v4QHELV6GZ8O6jZYb6Murgn3HeCQXcQzBaIQJ 6CaQRZKkSVqC6dbtdM8vI/DrboCvUl00MpKtuh8JemsX6AkR5ZmgWI6CrA== X-Gm-Gg: ASbGncvNaRuvcmnzvfUz0220rtrng10xv25njdoe7y/3kDignGbNI/+efGsAo5zXtGX wg5AVgeAneZPA6OxF9hxVz5L3GOb8JQaKAl97GQNlYRHrNkfnfM5PNLVePdPd7QwhCi1pE5Fp3P /9GhE35IxvsfxRRy5gVj/eeIjUzH7OxRN2hT33eOJPtosg9S3KM0rd098KtrlqNSI0KQlKMB7PG zr6anL+CeJePBFXY+3djVgGZux7czITv97gDt2GxQzj2y/WafyUqQ59Ncb3pDfiA0zbaCAEzbh9 Xiy+mqmM3RyqcFFJYEw+SRXOrMR1ggA+Ac6MzBxzBcIeDALVHUCqaHan1NHDjMo9cpINNVVw9aH E6aY6JV0L/5NavbdV9sjja/HN8w== X-Google-Smtp-Source: AGHT+IHS4j9ICyntbrA/BcR/VMofdv33fdKuwLaq8j3TbpKch7Ews0lvzB0+RnXZFglw24Avy0rteg== X-Received: by 2002:a05:6000:1fa9:b0:391:212:459a with SMTP id ffacd0b85a97d-39132d3b46fmr6507270f8f.22.1741426516381; Sat, 08 Mar 2025 01:35:16 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ce3f573f6sm15663895e9.0.2025.03.08.01.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Mar 2025 01:35:15 -0800 (PST) From: David Laight To: linux-kernel@vger.kernel.org, Andrew Morton Cc: David Laight , Arnd Bergmann , Linus Torvalds , Christophe Leroy , Andy Shevchenko , Rasmus Villemoes , nnac123@linux.ibm.com, horms@kernel.org Subject: [PATCH next 4/8] test_hexdump: Check for buffer overrun of sample output buffer Date: Sat, 8 Mar 2025 09:34:48 +0000 Message-Id: <20250308093452.3742-5-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250308093452.3742-1-david.laight.linux@gmail.com> References: <20250308093452.3742-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" While the output generated by test_hexdump_prepare_test() shouldn't be longer than the size of the buffer passed, for safety verify that the buffer is long enough. If too short fill the buffer with an error message - output on test failure. Signed-off-by: David Laight --- lib/test_hexdump.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 743ea5c78f9e..ed6f0b0a1bb3 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -39,6 +39,14 @@ static size_t __init test_hexdump_prepare_test(size_t le= n, size_t rowsize, groupsize =3D 1; byteswap =3D IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) ? 0 : groupsize - 1; =20 + /* Check test passed a big enough output buffer */ + if (ascii) + i =3D rowsize * 2 + rowsize / groupsize + 1 + len + 1; + else + i =3D len * 2 + len / groupsize - 1 + 1; + if (i > testlen) + return scnprintf(test, testlen, "buffer too short %zu < %zu", testlen, i= ); + /* hex dump */ p =3D test; for (i =3D 0, j =3D 0; i < len; i++) { --=20 2.39.5 From nobody Sat Feb 7 20:40:31 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F30981B0435 for ; Sat, 8 Mar 2025 09:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426520; cv=none; b=Wg5gcntFF2ytpGgn25IpdYLYGU1HxGxGWlLYyPlucZDOPnPiqczCMdg9mBmYpGiKQTJHHSQXYcO56WtgMn4zulso+N4WsWj/G50onsIul1RVai9BcQdlyGbzS50SU1wDfQ2yF2YRTVW5lPIVMEDrl/3N1EAewYRki3wfqd5tEKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426520; c=relaxed/simple; bh=4TWWcOGt87pDlGMnt8USRTVtLWmp/L0eOPEnxcJOKNE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DUl2iBh9ot+Lf2qoDv/zFKJS4F1HLH08bNJivLmZi+dXWkvAU6ZGbTq/IAHW1neRo6RnhPm+HGf98CZF9PFDAaxKoAWuvYiDBJwxJV7j2RTgBWMuZkoTEJCp0mJSOX2Rh2qm/2NNmSwf6SFsbhdm1d9VYXfVxq2kcHY7SzDrSX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P5m9xadJ; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P5m9xadJ" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43bccfa7b89so22328125e9.2 for ; Sat, 08 Mar 2025 01:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741426517; x=1742031317; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=egKKaEVuZCvmZpPyEYq1kxS3wPxzdvw1j9Mda8j6VvA=; b=P5m9xadJ8DaXvzYdtRXVqh3DFHppQcVaihmPVOTY2149v7raDRFyNl3wW0EtG/dVbb oaKQ+4WVPVzFw5RuPgMV7uUzVLcV/RFUpIPbovlzCTs8wJtzQtaQWGbrtcAyjvRTKxJJ xJ1bqmAAELg8VP6x2DYHIvKAkxVwFT9axSp3mbkUx8tyjai02bcJASA5UGi/HM3FYcKw R9nBhWzUJT6Qb5W201Io7Vgja8oiODP4bUEeZmJ7LjnTbAyrOEdIhiJNGszJ/o9NAhtl buq3BsOLcl7yUcpIHcod06adHl68fnD9AK/K364p3mXuBpSYL6s3U2VkUbOFavjRcnYC 7FRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741426517; x=1742031317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=egKKaEVuZCvmZpPyEYq1kxS3wPxzdvw1j9Mda8j6VvA=; b=DlbiX41w7GgF1mqAY19/XowJPShEswikC9TcwbOFhCImWwvgQbr/VqI0BuYm16GHZ+ dI1zo+xipkDU58ognlqKvQHVq90edhrJiNrKFnsgskZtNo5KBZ0pcBfcMJEyynqSKDHX xK0W5fKkoBbg2VzDlIFSquaYSyrgNPEOdrOKNLL7qbQNNWriBP4VhkV1YbYMNHzn83GD 5QQ7H49kOLUWCh/XUQhyWDxgH/jdwBRnIBP0he51+CrButcgy3RVbI45nFYt+mvLfJCQ Iz7KYV+C8hUiVLpniTr+7BgcNVGwiMzqLCSY1SwKu7ztmpgdsjVeodXUoXK5NmU0jwUv hNnQ== X-Gm-Message-State: AOJu0Yy/j7mI72QVRuZoxbSAbEP/SsloP4asX4WMwlfANJTqpdFrG6VF EqqtxI3ZKcQ8ecEkbLqBkb388u79m2NI5xWpvh4/DyfsQF8gzvAVREKugQ== X-Gm-Gg: ASbGnctMH6VXEDZBTuPy0szYaAxxHclNWfkQDDF+DFwcEWToij3V1j3+C/FwSu2FOcX Nv1QNEIa2yXNlMzBlpwmpl48u7fe88eQThFbjC/Aqpja0DkDWiTWPBr4l2Iv74x/oR3GMqhYbcg G5fhxCro+T1GL750BwoF+X4m4Mqle+1I3NtQdMtsC034lC7kMxhMuh+oGCOaFUf9kaY4AQxpPGF WpSvHN0nAew1ghc1oxbQOKpOS4WBMSlNsIMr4Wqvxw+lrRQV0MQlMRdym6NfJKgCUTcU/ubh7n8 TghYOacAQxwCg5jDynPlotLmfDgbh49lN20V9Ad0OECqxyaWbpczmjaUKKM1CFlrRtPWaHkYrK6 7i4MvTJiVupRrVaofeM9VIK6C1w== X-Google-Smtp-Source: AGHT+IFdwfFvnAY318GElxbu6iJWO7wLPbhjDXVMUjbWTm33nvlc3UO4LXAbbtCyiNTBBEYfWr+Wkg== X-Received: by 2002:a05:6000:144d:b0:385:faaa:9d1d with SMTP id ffacd0b85a97d-39132d98bc3mr5135942f8f.35.1741426517172; Sat, 08 Mar 2025 01:35:17 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ce3f573f6sm15663895e9.0.2025.03.08.01.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Mar 2025 01:35:16 -0800 (PST) From: David Laight To: linux-kernel@vger.kernel.org, Andrew Morton Cc: David Laight , Arnd Bergmann , Linus Torvalds , Christophe Leroy , Andy Shevchenko , Rasmus Villemoes , nnac123@linux.ibm.com, horms@kernel.org Subject: [PATCH next 5/8] test_hexdump: Fix sample output if zero bytes requested Date: Sat, 8 Mar 2025 09:34:49 +0000 Message-Id: <20250308093452.3742-6-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250308093452.3742-1-david.laight.linux@gmail.com> References: <20250308093452.3742-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If 'len' is zero the expected output is an empty string even if 'ascii' is requested. Signed-off-by: David Laight --- lib/test_hexdump.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index ed6f0b0a1bb3..07a8cc7e9088 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -29,6 +29,11 @@ static size_t __init test_hexdump_prepare_test(size_t le= n, size_t rowsize, char *p; size_t byteswap, i, j; =20 + if (!len) { + test[0] =3D 0; + return 0; + } + if (rowsize !=3D 16 && rowsize !=3D 32) rowsize =3D 16; =20 @@ -58,8 +63,7 @@ static size_t __init test_hexdump_prepare_test(size_t len= , size_t rowsize, *p++ =3D ' '; } } - if (i) - p--; + p--; =20 /* ASCII part */ if (ascii) { --=20 2.39.5 From nobody Sat Feb 7 20:40:31 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D49CD1B0F34 for ; Sat, 8 Mar 2025 09:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426521; cv=none; b=bXqu1rXfhdF2+PMXrvOnX3r3zjZmG+wsue2mdHHHYVT8xxmoekfZCnmPU81iHUBVZNb0oYLFyPDuxLg/DCtYN2rtC4VaA7tTvROzuScRyGX3eq1QPPtChL15akSdc97GW4vKJBdxXVXVqavkSBE9yu2DnLkwj4xUyNwBrwTyidc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426521; c=relaxed/simple; bh=rXSaBXfcbQJqt0BgGEAbtlgiusEoJFPxi/+hJvLdrpM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DXmk3lI7eEAJiXTx6RRhfuCL17W+JiGv9rvsaz0sT8HL9RYzW/G/Ow/pqIGnEz3fp9C6EQDgiKOC+bOF/rF4hsqh3VV+1NxOFMwZyRd1Laq/FudzomDJ9Ral57uepBzSdyRZUinar1RMSD5GM5R2A+9gTAexDeI2ZbkO5+7d0Eg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=U69HOax7; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U69HOax7" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-43bc63876f1so22564575e9.3 for ; Sat, 08 Mar 2025 01:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741426518; x=1742031318; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/dBEWPyN2Xgq5pJleu9O7q2U3augDpu+DFH6QigHgwU=; b=U69HOax7O7tgliUTBLPRdkS1Kwhf58XmoxlpZLBU39S8hjuiSeUJN7yRBOnjOnqwJL BA/xQQa3PXiBuwBL4ZSxbg5MpT1lEzHY668Aw2PMMgGfcQqyU0M6BnakPFYfyUy4syGj CFpDyuPFFbnovhA9suKTuhQYbqesGk16OMO66geRA3bBvXfBWO0ObVjEnYTyt528nVCP t/2/dYfLOqoEQO53GPR4JP80Wh37om2eXGkTtb+R3BLoI2f684qqD/sCb95RsCfPQRus 1iIxgz0XvR8EkFGTr8rC0XLgnAqWHsePkIx0wSAIG4iLjKAcebpVA4agrovl+oO614Ug BY5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741426518; x=1742031318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/dBEWPyN2Xgq5pJleu9O7q2U3augDpu+DFH6QigHgwU=; b=SX30sZkFfSHpW9fNY0FuaOY2IOqB75KG2DxFti/R6r81AOUDTuUZLBzVDmnoPUm2UK wbKqARSazIT9uzayp48xuhMMcIZDJX2LnAQIV8TkpqEZLp72zTBNXwB+XpnA6qRQZR8e G2qSKvQ72WVU0EmWUAU43OlbSJd5bCQuBssUkDs6g+q2LAVfYKLNsBBi0J7yVwsVgZY6 JOojADvzSE8hOM6vMm/VS/alMO/b/5IUwij4+rMrUa5OLe7Z1ONUTOwamGBVHOlc7VI0 EScM/Ckg1vCJpgl1rvJB4WLLh3LlhIr6w8vcVdHiPYSqC91UIHmSFVt2rbYotZuXNxpp oCmQ== X-Gm-Message-State: AOJu0YyDPFcU67HdI4tw/MX/kFMwUR/ljHELteGrOZ5AhR80d80hfywP SZi6UH0J52jdc/X6NR0sq6kuiOgwIGeCwsvPT++QKXvBqet+OgqrNv5K+w== X-Gm-Gg: ASbGncusSM4LLsvCnFGgIW254ANqkuoTfvV8ea44kpQgBCOPyr1KOun2k9J9NmkGzqB 5J7r9Ys3bAcsUAAKOmsW2NbErpF6LubA7ebKU+TgZczI9gGO6jjZq1SrL6FG2LMwEDyrFXurPw9 xQvrqVj+hPdhIM9mbfMCoPSExDPXR2BdKDdxkREBablGsO2r+Dy7Iz4mqUsTf/pJ5nJ7r3sSx5x 8zUW4QLtKi5q9fUvbxC33iXLRQHjL8KKPhPVp5QzdqTSYmcw72/IA7RgdIRU1arST9F3tDXKgDO Az8yh9xqeGUnK7AairwaDMdeQcCpj58FC9vVDCHFwdVuKApuuJG70L8dJFmYRVCdQEqzBAmsjM+ 8ci0W0OclrJDMt4CsvpUZpkqrmA== X-Google-Smtp-Source: AGHT+IGDKj9fyryLAzHMCbNhcW2J4OZGRgKyhPcEXWP1tdnrhn1453rxJtqLSLot6YFXQkrk/6KtGQ== X-Received: by 2002:a05:600c:3791:b0:43c:ec28:d303 with SMTP id 5b1f17b1804b1-43cec28d49fmr5086675e9.5.1741426517965; Sat, 08 Mar 2025 01:35:17 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ce3f573f6sm15663895e9.0.2025.03.08.01.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Mar 2025 01:35:17 -0800 (PST) From: David Laight To: linux-kernel@vger.kernel.org, Andrew Morton Cc: David Laight , Arnd Bergmann , Linus Torvalds , Christophe Leroy , Andy Shevchenko , Rasmus Villemoes , nnac123@linux.ibm.com, horms@kernel.org Subject: [PATCH next 6/8] test_hexdump: If a test fails print all the parameters Date: Sat, 8 Mar 2025 09:34:50 +0000 Message-Id: <20250308093452.3742-7-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250308093452.3742-1-david.laight.linux@gmail.com> References: <20250308093452.3742-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Print the returned lengths as signed integers. While they shouldn't be negative, -1 is better than 18446744073709551615. The string outputs were also incorrectly truncated. Signed-off-by: David Laight --- lib/test_hexdump.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 07a8cc7e9088..56c0dfbd075b 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -146,13 +146,12 @@ static void __init test_hexdump_overflow(size_t bufle= n, size_t len, =20 ok =3D result =3D=3D expected && !memcmp(test, buf, TEST_HEXDUMP_BUF_SIZE= ); =20 - buf[sizeof(buf) - 1] =3D '\0'; - if (!ok) { - pr_err("Len: %zu buflen: %zu strlen: %zu\n", + pr_err("Rowsize %zu, groupsize %zu, ascii %s, len %zu, buflen %zu, strle= n %zu\n", + rowsize, groupsize, ascii ? "yes" : "no", len, buflen, strnlen(buf, sizeof(buf))); - pr_err("Result: %zu '%s'\n", result, buf); - pr_err("Expect: %zu '%s'\n", expected, test); + pr_err("Result: %zd '%.*s'\n", result, TEST_HEXDUMP_BUF_SIZE, buf); + pr_err("Expect: %zd '%.*s'\n", expected, TEST_HEXDUMP_BUF_SIZE, test); failed_tests++; } } --=20 2.39.5 From nobody Sat Feb 7 20:40:31 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 871EA1B3952 for ; Sat, 8 Mar 2025 09:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426522; cv=none; b=GOiNBeEagDC0J26iK8UTqu0eg0+bRVyffis/QwSyqgkJMnWSIGpndXRvWFOcoszPJOAktVwiVMj15Kd5VqOWdAUh/axKF3oa4jESpwFlzssYVxKA9A71MhiY+waAN4GYQh9aHve2Suw0j3Qyqrhf0itJIFXeLRggXB8p9qN0PCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426522; c=relaxed/simple; bh=/rrpX0Jd7AO0pLzNN/4r3XJG+AwFTV8rMFZQlcAimDg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RKbh0nYpLTfvSO0XMIBuSqsfXZEt+PfxLRjp4ly26EN01I9gg4GlvWZBCUWBRZy4UBPpxg6Rk0YO6EZb0odTE4kK54ce/i0rP57x02MVnzhfsaXDxR5DN2NOO7MGgkHoiw4cL7fpjbcDiJ2Fq2LO6m0PoR8UJX4XKLzI0aWqrRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XxWUJv1Y; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XxWUJv1Y" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43bd45e4d91so15698005e9.1 for ; Sat, 08 Mar 2025 01:35:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741426519; x=1742031319; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=615WbshJLbjls5U3jeu6OdaXqEtsj7lJRi/IOdHuV80=; b=XxWUJv1YEB3P4n7nG0lX0CQenaGtutw41dXWwZTeYTLlQjRn5xubz0WTHWwCvoB2Aw dbmJc1Dqf5nI0kugydp8WxIsQc5qFM2gbINaUC0jBK1eNMIZKpZ94l0mC4srqmG8lgGP hnaXxZr3Y9QOlu2fi8a+U8RPE1b3cjgcsVad/q61b+Lzjw75fC/Y+TTtYwqlunzTxVse KADb6KJAvDc9VzOVNuD0BLj/LRVtQHZJFk/wRTyJDONIn3co8FqrbKM//D9aHa4TPj1g KTLL2kHSUVLcz7vFleDOzva0aDqcto/Wz8GjVdnM5N8KRptFFMLxahhdsvA4JnVCzFuu eJhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741426519; x=1742031319; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=615WbshJLbjls5U3jeu6OdaXqEtsj7lJRi/IOdHuV80=; b=CHuExnnMOGucugzuKqEMDQQmDc/4N9c3eDzhHduZmzK6YP2NUTBl1dUW3ZgqQ251GK 3OzeHvbMJrcgGqZzcfEB5WBbdMxT30s+AgsyHbKASZUvCxHEqayRj5u55LuAixjkk7nc KjxOyvgUMcwRbI6maWa1xin0ElamCEQItrWlEkpl7+z0lbjeQTEC8R1EXaUIQaKTzHLQ 2GM87qDx9jP0w3zng4DdCdY6zCBhRPgOe3isoxNDrYyRGsv8Wc8KjCJkctDviXGAaruB 58r29VEaSeQisIolC9rApRM9mkeI8auVxYIFYl2uKh/ZnUbDJXhkjFpDHydCKVyaJwqr exXw== X-Gm-Message-State: AOJu0Yw9g5CsXIJq3CSgXDBsVByQDrjV6sntTfPDi3tuhe9a5pAyjNvU LbWO85G2byzWcN0FKYyiwEl01fQQK7YPC2GlQgCLhXeCyNP46VvzyOkpJw== X-Gm-Gg: ASbGnctgdwf6/8P2ys5Jyw06oTUgHdkKNUttRCiuG1HNgxzSB8wFsquyvwUrbmR4of9 gcbcZP19/XueSIWThaZEsG+mgc+OSprxxm6wS804cy1dWmBqZsUAjUsZ7nY7XqTf+iB0U9khebs TxDhY1D4BhXxgFYgLlHjvmYwnbn7/l8CClTgs6SHIBPe+PHHM+u+/kyUH0Vw0F/HTGDYov6IvFl WXwkODGVIphY2xHIsOWwoVr9Sl2v1ZDx+4rvw/HCV0ywQgZau1e//izHB5EimHGbUK49W+qPMXf qcBfpI9JIyaQWujnZDG1nsjYdHYqnWUDUOdJDbI9+fgpkgP4JTtt051ruD2cXES5evDobWjtlbZ D0UGHZANdlTX4RluJAQ7miaNvHQ== X-Google-Smtp-Source: AGHT+IEIZS3vD8An/PeadukaTEKOvMV1HWmz7oRSz92Axe7UFQ9wmzlVQ7eX55TWhfAM5hWZlyZegw== X-Received: by 2002:a05:600c:354b:b0:439:4b23:9e8e with SMTP id 5b1f17b1804b1-43ce4ab02eamr16863985e9.3.1741426518799; Sat, 08 Mar 2025 01:35:18 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ce3f573f6sm15663895e9.0.2025.03.08.01.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Mar 2025 01:35:18 -0800 (PST) From: David Laight To: linux-kernel@vger.kernel.org, Andrew Morton Cc: David Laight , Arnd Bergmann , Linus Torvalds , Christophe Leroy , Andy Shevchenko , Rasmus Villemoes , nnac123@linux.ibm.com, horms@kernel.org Subject: [PATCH next 7/8] test_hexdump: Run fixed not random tests Date: Sat, 8 Mar 2025 09:34:51 +0000 Message-Id: <20250308093452.3742-8-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250308093452.3742-1-david.laight.linux@gmail.com> References: <20250308093452.3742-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For reproducibilty instead of running 16 random length with two random 'rowsize' picked from 16 and 32, run the tests with rowsize 16 and 32 and all the lengths from 1 to rowsize. (This still includes all the cases where groupsize gets forced to 1.) For the overflow tests increase 'len' if the data fits and 'buflen' if it doesn't. The is more tests than really needed but covers all the interesting cases without generating a very large number of tests. Signed-off-by: David Laight --- lib/test_hexdump.c | 64 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 56c0dfbd075b..877033a570d4 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -7,7 +7,6 @@ #include #include #include -#include #include =20 static const unsigned char data_b[] =3D { @@ -109,18 +108,19 @@ static void __init test_hexdump(size_t len, size_t ro= wsize, size_t groupsize, =20 static void __init test_hexdump_set(size_t rowsize, bool ascii) { - size_t d =3D min(sizeof(data_b), rowsize); - size_t len =3D get_random_u32_inclusive(1, d); + size_t len; =20 - test_hexdump(len, rowsize, 4, ascii); - test_hexdump(len, rowsize, 2, ascii); - test_hexdump(len, rowsize, 8, ascii); - test_hexdump(len, rowsize, 1, ascii); + for (len =3D 1; len <=3D rowsize; len++) { + test_hexdump(len, rowsize, 4, ascii); + test_hexdump(len, rowsize, 2, ascii); + test_hexdump(len, rowsize, 8, ascii); + test_hexdump(len, rowsize, 1, ascii); + } } =20 -static void __init test_hexdump_overflow(size_t buflen, size_t len, - size_t rowsize, size_t groupsize, - bool ascii) +static bool __init test_hexdump_overflow(size_t buflen, size_t len, + size_t rowsize, size_t groupsize, + bool ascii) { char test[TEST_HEXDUMP_BUF_SIZE]; char buf[TEST_HEXDUMP_BUF_SIZE]; @@ -154,40 +154,40 @@ static void __init test_hexdump_overflow(size_t bufle= n, size_t len, pr_err("Expect: %zd '%.*s'\n", expected, TEST_HEXDUMP_BUF_SIZE, test); failed_tests++; } + + return expected < buflen; } =20 -static void __init test_hexdump_overflow_set(size_t buflen, bool ascii) +static void __init test_hexdump_overflow_set(size_t rowsize, bool ascii) { - unsigned int i =3D 0; - size_t rowsize =3D get_random_u32_inclusive(1, 2) * 16; - - do { - size_t groupsize =3D 1 << i; - size_t len =3D get_random_u32_below(rowsize) + groupsize; - - test_hexdump_overflow(buflen, rounddown(len, groupsize), - rowsize, groupsize, ascii); - } while (i++ < 3); + size_t groupsize, len, buflen; + + for (groupsize =3D 1; groupsize <=3D 8; groupsize *=3D 2) { + len =3D 0; + buflen =3D 0; + for (; len <=3D rowsize && buflen <=3D TEST_HEXDUMP_BUF_SIZE;) { + if (test_hexdump_overflow(buflen, len, rowsize, + groupsize, ascii)) + len +=3D groupsize; + else + buflen++; + } + } } =20 static int __init test_hexdump_init(void) { - unsigned int i; size_t rowsize; =20 - rowsize =3D get_random_u32_inclusive(1, 2) * 16; - for (i =3D 0; i < 16; i++) + for (rowsize =3D 16; rowsize <=3D 32; rowsize +=3D 16) { test_hexdump_set(rowsize, false); - - rowsize =3D get_random_u32_inclusive(1, 2) * 16; - for (i =3D 0; i < 16; i++) test_hexdump_set(rowsize, true); + } =20 - for (i =3D 0; i <=3D TEST_HEXDUMP_BUF_SIZE; i++) - test_hexdump_overflow_set(i, false); - - for (i =3D 0; i <=3D TEST_HEXDUMP_BUF_SIZE; i++) - test_hexdump_overflow_set(i, true); + test_hexdump_overflow_set(16, false); + test_hexdump_overflow_set(16, true); + test_hexdump_overflow_set(32, false); + test_hexdump_overflow_set(32, true); =20 if (failed_tests =3D=3D 0) pr_info("all %u tests passed\n", total_tests); --=20 2.39.5 From nobody Sat Feb 7 20:40:31 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E9121B415F for ; Sat, 8 Mar 2025 09:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426523; cv=none; b=AZdNrgRm1zejTU3p6lEzS+IRPOchMlJW95wHB3m3niIWXUM87dlSGzrj67asd+NwK4/h/oaJD2wLia8TVIHWSWoMALiM25y9VgUwPaepWYxnkdi2/y66lpBp3iTOjv1znhtZEcTIqyobVHF61HkDWOviHtwX9FHkmFhV0grkq0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741426523; c=relaxed/simple; bh=rONEl4RfPQnnqrxuu2tf2lJ019DkcnnMas5SmS6HZrk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fCcvjyzWlwntrHysNt7jgHNqaSQLFRCCoWJ0tNlDq402z3ouCKHKGu4XCsJXvDS3R03xkU/u5gQFKlOkaXSW0QenEYN9RGpOwQFTPqg8T5PvoKdVLlw/DShc9/oG3TfzEMaRrZkpzQFE+v7KDUHRcEJGJp5e4WLWnNtRBZ+QvSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jc1YG1fZ; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jc1YG1fZ" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-43bc0b8520cso15843255e9.1 for ; Sat, 08 Mar 2025 01:35:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741426519; x=1742031319; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tkOJABZ+cpIWk2CuveFX94zFWy5fKj3p9VLpKdU0T9o=; b=jc1YG1fZnAl30r3B5zdLHOdSIrfZyTWhxoy3g+7szUniRZbWNWdiMXsAPBeQrMmBzI +Q6v4HzieeYN5LaOoJz2JzsXYcQeGPuqkz9dXiK9Q9ed1bHYZQzFr5ezW1h5T2Ruas9u MPLpHv6+9bi8HdceJaV9sAn9EbDjRRgTue9qgEFKY/ywrS2LYXcoCEL2iM/ESx4/diyG ve3H/RPBtgDkLMwwSYNP4luma6ms1JyAsF+llm07mINHdwXqkpZ9311CaqyD4A0PnMER 0cWFBrW3Vh1r06hD9vi1PurjaSM5sZp3Us6mGZzagvRsSg8vqhc36jFUBnSYhzuyhCMH KlIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741426519; x=1742031319; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tkOJABZ+cpIWk2CuveFX94zFWy5fKj3p9VLpKdU0T9o=; b=HBi/9sfNmiH//FxSvduPFdaASKwgPM5PgKaPaCuEGxJLNTE/y8mzy0naPGZamLl59L cxalSY8KdJcoHxr+s9Bi6DGFCc0UPu9arNEFTqCBlATCx/Croh6NpmgEMDMlwDkkF3nl I/K1Mj+cxmBdknxqgBcBNwZ6QhwphEdNP8fZVVqoxOrafrCFyQwWFZUweoiRLRpDKYo8 FUZ0oE7aE2Pe0d/n5Lb3cVSUlIZbDcbiwmoK1fUju1nrNNUCLwDRlVAmy2YgmKMMW7kA jjKwCy+XFeHKE7UDw+zUluu1wPwTlHLbDL7kWn466sh4j/RHMMsRXTl1KzsGreFHlwgJ AFCQ== X-Gm-Message-State: AOJu0YwF83c1c7sLwSV2H33DMyUEnVVSfCot6hBaW8PNm/uyH470DtER 6Ob85av1xw0c5N1KNwp6fN+gesA0ZpdK2yTrHaNcON8OTeLuQYYYFApJ4Q== X-Gm-Gg: ASbGncuSzldu708HCZFW/Qr/lOJG9lwJzZQVs7jAGclr4ON1p4iOnVeELl5b1sYt+if tX7b3RD/ZOM4k9U11qQRgySWPDfR+PuW8TzG59M9tegvP8FvOtbzFrbPbmFrAxo/jwMJ2TX7PCy 9h2D6F9j29CMV4Z9xs6a8BXdaioqC3RXiH2d4bJUleGVvJEHqeI4lYYFRroCV+obTRh60n6yQjP WdB+GTMyOvRE8R/LpdR/1czE1E/V1FljFoABmaxM+spBjrOJgvk1b0VxZu7yqevM/tb+Jigwh3K KnXwcVwloKOJJ8WUqHzNvJIAOnNB19+QrZpx4mG9vtKjgc3WWhv4bexQlVYyQodXpFBtPNLthLa 2UJ7tA5ipyd5YLlYHtO8ZSw1K/uBueMeYSm2U X-Google-Smtp-Source: AGHT+IFuBUzzXZb67a0ZGAawYBWfklfcHyBfOcWeCBnhkZLx72LdIH/x8ie86I6Ae/EJp/gw8DKnaw== X-Received: by 2002:a05:600c:1d03:b0:43c:eacc:9d68 with SMTP id 5b1f17b1804b1-43ceacca125mr6148745e9.20.1741426519527; Sat, 08 Mar 2025 01:35:19 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ce3f573f6sm15663895e9.0.2025.03.08.01.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Mar 2025 01:35:19 -0800 (PST) From: David Laight To: linux-kernel@vger.kernel.org, Andrew Morton Cc: David Laight , Arnd Bergmann , Linus Torvalds , Christophe Leroy , Andy Shevchenko , Rasmus Villemoes , nnac123@linux.ibm.com, horms@kernel.org Subject: [PATCH next 8/8] test_hexdump: Test all 256 byte values Date: Sat, 8 Mar 2025 09:34:52 +0000 Message-Id: <20250308093452.3742-9-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250308093452.3742-1-david.laight.linux@gmail.com> References: <20250308093452.3742-1-david.laight.linux@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass the hex data buffer as a parameter to test_hexdump_prepare_test() and test_hexdump(). Add additional tests that pass all 256 byte values requesting 'ascii'. Checks that unprintable characters are concerted to '.'. Signed-off-by: David Laight --- lib/test_hexdump.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 877033a570d4..d2ed1870f869 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -21,9 +21,9 @@ static const unsigned char data_b[] =3D { static unsigned total_tests __initdata; static unsigned failed_tests __initdata; =20 -static size_t __init test_hexdump_prepare_test(size_t len, size_t rowsize, - size_t groupsize, char *test, - size_t testlen, bool ascii) +static size_t __init test_hexdump_prepare_test(const unsigned char *buf, s= ize_t len, + size_t rowsize, size_t groupsize, + char *test, size_t testlen, bool ascii) { char *p; size_t byteswap, i, j; @@ -54,7 +54,7 @@ static size_t __init test_hexdump_prepare_test(size_t len= , size_t rowsize, /* hex dump */ p =3D test; for (i =3D 0, j =3D 0; i < len; i++) { - unsigned char b =3D data_b[i ^ byteswap]; + unsigned char b =3D buf[i ^ byteswap]; *p++ =3D "0123456789abcdef"[b >> 4]; *p++ =3D "0123456789abcdef"[b & 15]; if (++j =3D=3D groupsize) { @@ -71,7 +71,7 @@ static size_t __init test_hexdump_prepare_test(size_t len= , size_t rowsize, } while (p < test + rowsize * 2 + rowsize / groupsize + 1); =20 for (i =3D 0; i < len; i++) { - unsigned char b =3D data_b[i]; + unsigned char b =3D buf[i]; *p++ =3D (isascii(b) && isprint(b)) ? b : '.'; } } @@ -82,8 +82,8 @@ static size_t __init test_hexdump_prepare_test(size_t len= , size_t rowsize, =20 #define TEST_HEXDUMP_BUF_SIZE (32 * 3 + 2 + 32 + 1) =20 -static void __init test_hexdump(size_t len, size_t rowsize, size_t groupsi= ze, - bool ascii) +static void __init test_hexdump(const void *buf, size_t len, size_t rowsiz= e, + size_t groupsize, bool ascii) { char test[TEST_HEXDUMP_BUF_SIZE]; char real[TEST_HEXDUMP_BUF_SIZE]; @@ -91,11 +91,11 @@ static void __init test_hexdump(size_t len, size_t rows= ize, size_t groupsize, total_tests++; =20 memset(real, FILL_CHAR, sizeof(real)); - hex_dump_to_buffer(data_b, len, rowsize, groupsize, real, sizeof(real), + hex_dump_to_buffer(buf, len, rowsize, groupsize, real, sizeof(real), ascii); =20 memset(test, FILL_CHAR, sizeof(test)); - test_hexdump_prepare_test(len, rowsize, groupsize, test, sizeof(test), + test_hexdump_prepare_test(buf, len, rowsize, groupsize, test, sizeof(test= ), ascii); =20 if (memcmp(test, real, TEST_HEXDUMP_BUF_SIZE)) { @@ -111,10 +111,10 @@ static void __init test_hexdump_set(size_t rowsize, b= ool ascii) size_t len; =20 for (len =3D 1; len <=3D rowsize; len++) { - test_hexdump(len, rowsize, 4, ascii); - test_hexdump(len, rowsize, 2, ascii); - test_hexdump(len, rowsize, 8, ascii); - test_hexdump(len, rowsize, 1, ascii); + test_hexdump(data_b, len, rowsize, 4, ascii); + test_hexdump(data_b, len, rowsize, 2, ascii); + test_hexdump(data_b, len, rowsize, 8, ascii); + test_hexdump(data_b, len, rowsize, 1, ascii); } } =20 @@ -136,7 +136,7 @@ static bool __init test_hexdump_overflow(size_t buflen,= size_t len, buflen, ascii); =20 /* Test output is generated into a 'long enough' buffer */ - expected =3D test_hexdump_prepare_test(len, rowsize, groupsize, test, + expected =3D test_hexdump_prepare_test(data_b, len, rowsize, groupsize, t= est, sizeof(test), ascii); =20 f =3D min(expected + 1, buflen); @@ -175,6 +175,22 @@ static void __init test_hexdump_overflow_set(size_t ro= wsize, bool ascii) } } =20 +static void __init test_hexdump_bytes(void) +{ + unsigned char buf[16]; + size_t i, j; + + for (i =3D 0; i < 256; i +=3D 16) { + for (j =3D 0; j < 16; j++) + buf[j] =3D i + j; + test_hexdump(buf, 16, 16, 1, true); + test_hexdump(buf, 16, 16, 2, true); + test_hexdump(buf, 16, 16, 4, true); + test_hexdump(buf, 16, 16, 8, true); + } +} + + static int __init test_hexdump_init(void) { size_t rowsize; @@ -189,6 +205,8 @@ static int __init test_hexdump_init(void) test_hexdump_overflow_set(32, false); test_hexdump_overflow_set(32, true); =20 + test_hexdump_bytes(); + if (failed_tests =3D=3D 0) pr_info("all %u tests passed\n", total_tests); else --=20 2.39.5