From nobody Wed Nov 27 10:39:34 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 935E220A5CD for ; Fri, 11 Oct 2024 07:31:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631863; cv=none; b=QmZKhYkreWsayg8j/3Lzo6zuMKfeeU7M2WB7/oKUk7DxjsL/6wp3455oYog66xr791s8Ey6ViGJ0Hl48ZEoqSZsdgoBdfeoAeYFMiLbVN9lkiBAF41e6qEhZV//HrPv8UMFgaHm2k0otvjrp5WGfV45ifyirBrgL+WWykREX0P8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631863; c=relaxed/simple; bh=MLKVj5mIGtKe2lmA8uZuUkbaKPXRlkwhLj+qZGlP1IQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IdghIAnUe+zZTE8VuOLqHY9V5aEjVTAplAVmu4TTkOdJwBwMFLRkFrODnQLCzRFDizNQzc4/KAFb7Qlay4wdQu2ak/MQMzdyVSJxE0MBBCc4QMNLkp82NLNsNAqp5v7YBb+Ji6UQRhK2r+ynvVFP3G4gC03Ow8H/MmM3URvSMk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hhO2J50V; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hhO2J50V" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e28ef71f0d8so2730515276.0 for ; Fri, 11 Oct 2024 00:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728631860; x=1729236660; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=p2/wWiYYGPs+6qkE7fTq8up8gyUggtyfyady5a+MRp8=; b=hhO2J50VTlW8leXquLYKk+Xj4RfCyEwrnRMQyLSPCKVdDee6QcUxKhkixjjmb9nYJU xH8f3ihX/pBKsgp7cEGfA3LnltViHaMzwSTweJPi54oB6c1ygwPPEOi969euL2v0KfhV H8eq/6LShz9cCJn+CGROsEyBKqW5eYpB0iYObcpd2DNTXPsMkNhKXUWjdcb5Q9pso+83 p4YO34XVgLzI4FIA/dO8air7r7yqXObI8f2EHpZCjtUoyquJy02htW1bMYFAvN6t22w1 LCizaKtYgWQOgN5pmEmA32IGmykRqx22pyM0Kvml4Q8R0VA64INU1cCcpTgGTZ6ohLJJ UdGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631860; x=1729236660; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=p2/wWiYYGPs+6qkE7fTq8up8gyUggtyfyady5a+MRp8=; b=BE9OEgIGJ2Zc+m3z6virtOMqJYahsVWaD8jSu9H+rH7E9P2ivBLnfrWk/v7V9uj0vG AzhpNHWTcgADiPwMLPFGwmBR10JrQQ9DLWvj+Ix4Ca0kHu+GWKK82gJFnsUWCWjndm3r x24o0F5MJdO4k25CfZPyv6VFGE3ytcIE9xmCGnmabnZBzduYCCIJ2b9KzGlPMpRt7ypk uTUA7V4xt/fJ0S16YFDIksGe1I9YEs+IiYyh0lviUbNqTEkwCwPMD8OjgmkJ1GBqeAe4 +9w1D+i/6as3AKcWqWO8AQbnWwBK1kgvfzFUgyk04xWeQWEh4wumpHpl2pOYt3ErhFll oJ1A== X-Forwarded-Encrypted: i=1; AJvYcCUcjyfiRUhZ1BfMNKjJ/i/ExLTJfbk5gcnDX/DCx8KbNI/swWz0A156/9FSqIMv6mDgQAP+1+JtAZKsoKA=@vger.kernel.org X-Gm-Message-State: AOJu0YzVKdQnMeQpdwmm6Zj+0CQ0JB2F3bU95w8zeAQYHAjwC0pQxxwc WQvK2BGVU4UPIrffn3VdpGj5UfLVuGBrNDt6ujAKdYSRKpzSvbbgPiLShDGWk+JTGeYrCaO6gSp nbAGTXwYgNA== X-Google-Smtp-Source: AGHT+IGg8zwYdpqTc4hwks/F2yxEDRYUPiypRoSyjyZWBgBdCoyywn0K+Zem/S5QXprlyw+K62or1As/8fQ1Rg== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:b1:7045:ac11:6237]) (user=davidgow job=sendgmr) by 2002:a25:d084:0:b0:e25:cea9:b0e with SMTP id 3f1490d57ef6-e2919fe8406mr1099276.9.1728631860588; Fri, 11 Oct 2024 00:31:00 -0700 (PDT) Date: Fri, 11 Oct 2024 15:25:05 +0800 In-Reply-To: <20241011072509.3068328-2-davidgow@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241011072509.3068328-2-davidgow@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241011072509.3068328-3-davidgow@google.com> Subject: [PATCH 1/6] lib: math: Move kunit tests into tests/ subdir From: David Gow To: Andrew Morton , Shuah Khan , Brendan Higgins , Rae Moar , Kees Cook Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Stephen Rothwell , Luis Felipe Hernandez , quic_jjohnson@quicinc.com, macro@orcam.me.uk, tpiepho@gmail.com, ricardo@marliere.net, linux-kernel-mentees@lists.linuxfoundation.org, Nicolas Pitre , David Gow Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Luis Felipe Hernandez This patch is a follow-up task from a discussion stemming from point 3 in a recent patch introducing the int_pow kunit test [1] and documentation regarding kunit test style and nomenclature [2]. Colocate all kunit test suites in lib/math/tests/ and follow recommended naming convention for files _kunit.c and kconfig entries CONFIG__KUNIT_TEST. Link: https://lore.kernel.org/all/CABVgOS=3D-vh5TqHFCq_jo=3Dffq8v_nGgr6JsPn= OZag3e6+19ysxQ@mail.gmail.com/ [1] Link: https://docs.kernel.org/dev-tools/kunit/style.html [2] Signed-off-by: Luis Felipe Hernandez Acked-by: Nicolas Pitre [Rebased on top of mm-nonmm-unstable.] Signed-off-by: David Gow Acked-by: Shuah Khan --- arch/m68k/configs/amiga_defconfig | 2 +- arch/m68k/configs/apollo_defconfig | 2 +- arch/m68k/configs/atari_defconfig | 2 +- arch/m68k/configs/bvme6000_defconfig | 2 +- arch/m68k/configs/hp300_defconfig | 2 +- arch/m68k/configs/mac_defconfig | 2 +- arch/m68k/configs/multi_defconfig | 2 +- arch/m68k/configs/mvme147_defconfig | 2 +- arch/m68k/configs/mvme16x_defconfig | 2 +- arch/m68k/configs/q40_defconfig | 2 +- arch/m68k/configs/sun3_defconfig | 2 +- arch/m68k/configs/sun3x_defconfig | 2 +- arch/powerpc/configs/ppc64_defconfig | 2 +- lib/Kconfig.debug | 6 +++--- lib/math/Makefile | 5 +---- lib/math/tests/Makefile | 5 ++++- lib/math/{test_div64.c =3D> tests/div64_kunit.c} | 0 .../mul_u64_u64_div_u64_kunit.c} | 2 +- lib/math/{rational-test.c =3D> tests/rational_kunit.c} | 0 19 files changed, 22 insertions(+), 22 deletions(-) rename lib/math/{test_div64.c =3D> tests/div64_kunit.c} (100%) rename lib/math/{test_mul_u64_u64_div_u64.c =3D> tests/mul_u64_u64_div_u64= _kunit.c} (98%) rename lib/math/{rational-test.c =3D> tests/rational_kunit.c} (100%) diff --git a/arch/m68k/configs/amiga_defconfig b/arch/m68k/configs/amiga_de= fconfig index d01dc47d52ea..7ba9311c084c 100644 --- a/arch/m68k/configs/amiga_defconfig +++ b/arch/m68k/configs/amiga_defconfig @@ -619,7 +619,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/apollo_defconfig b/arch/m68k/configs/apollo_= defconfig index 46808e581d7b..273fe4032b85 100644 --- a/arch/m68k/configs/apollo_defconfig +++ b/arch/m68k/configs/apollo_defconfig @@ -576,7 +576,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/atari_defconfig b/arch/m68k/configs/atari_de= fconfig index 4469a7839c9d..9976cda99fc1 100644 --- a/arch/m68k/configs/atari_defconfig +++ b/arch/m68k/configs/atari_defconfig @@ -596,7 +596,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/bvme6000_defconfig b/arch/m68k/configs/bvme6= 000_defconfig index c0719322c028..f59082c8fe06 100644 --- a/arch/m68k/configs/bvme6000_defconfig +++ b/arch/m68k/configs/bvme6000_defconfig @@ -568,7 +568,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/hp300_defconfig b/arch/m68k/configs/hp300_de= fconfig index 8d429e63f8f2..6db3556da9ac 100644 --- a/arch/m68k/configs/hp300_defconfig +++ b/arch/m68k/configs/hp300_defconfig @@ -578,7 +578,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/mac_defconfig b/arch/m68k/configs/mac_defcon= fig index bafd33da27c1..25c06b5c83ee 100644 --- a/arch/m68k/configs/mac_defconfig +++ b/arch/m68k/configs/mac_defconfig @@ -595,7 +595,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/multi_defconfig b/arch/m68k/configs/multi_de= fconfig index 6f5ca3f85ea1..35e57e0ee139 100644 --- a/arch/m68k/configs/multi_defconfig +++ b/arch/m68k/configs/multi_defconfig @@ -681,7 +681,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/mvme147_defconfig b/arch/m68k/configs/mvme14= 7_defconfig index d16b328c7136..d253b686119a 100644 --- a/arch/m68k/configs/mvme147_defconfig +++ b/arch/m68k/configs/mvme147_defconfig @@ -567,7 +567,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/mvme16x_defconfig b/arch/m68k/configs/mvme16= x_defconfig index 80f6c15a5ed5..62bc6ad63783 100644 --- a/arch/m68k/configs/mvme16x_defconfig +++ b/arch/m68k/configs/mvme16x_defconfig @@ -568,7 +568,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/q40_defconfig b/arch/m68k/configs/q40_defcon= fig index 0e81589f0ee2..caba39c61bac 100644 --- a/arch/m68k/configs/q40_defconfig +++ b/arch/m68k/configs/q40_defconfig @@ -585,7 +585,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/sun3_defconfig b/arch/m68k/configs/sun3_defc= onfig index 8cd785290339..a348f645ed55 100644 --- a/arch/m68k/configs/sun3_defconfig +++ b/arch/m68k/configs/sun3_defconfig @@ -565,7 +565,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/m68k/configs/sun3x_defconfig b/arch/m68k/configs/sun3x_de= fconfig index 78035369f60f..f8b3cfc3275b 100644 --- a/arch/m68k/configs/sun3x_defconfig +++ b/arch/m68k/configs/sun3x_defconfig @@ -566,7 +566,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_REED_SOLOMON_TEST=3Dm CONFIG_ATOMIC64_SELFTEST=3Dm CONFIG_ASYNC_RAID6_TEST=3Dm diff --git a/arch/powerpc/configs/ppc64_defconfig b/arch/powerpc/configs/pp= c64_defconfig index a5e3e7f97f4d..f1f21765c0c1 100644 --- a/arch/powerpc/configs/ppc64_defconfig +++ b/arch/powerpc/configs/ppc64_defconfig @@ -435,7 +435,7 @@ CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_LKDTM=3Dm CONFIG_TEST_MIN_HEAP=3Dm -CONFIG_TEST_DIV64=3Dm +CONFIG_DIV64_KUNIT_TEST=3Dm CONFIG_BACKTRACE_SELF_TEST=3Dm CONFIG_TEST_REF_TRACKER=3Dm CONFIG_RBTREE_TEST=3Dm diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 856bc9f9c069..3ed6cf950f04 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2296,7 +2296,7 @@ config TEST_SORT =20 If unsure, say N. =20 -config TEST_DIV64 +config DIV64_KUNIT_TEST tristate "64bit/32bit division and modulo test" depends on DEBUG_KERNEL || m help @@ -2306,7 +2306,7 @@ config TEST_DIV64 =20 If unsure, say N. =20 -config TEST_MULDIV64 +config MULDIV64_KUNIT_TEST tristate "mul_u64_u64_div_u64() test" depends on DEBUG_KERNEL || m help @@ -2993,7 +2993,7 @@ config TEST_OBJPOOL =20 If unsure, say N. =20 -config INT_POW_TEST +config INT_POW_KUNIT_TEST tristate "Integer exponentiation (int_pow) test" if !KUNIT_ALL_TESTS depends on KUNIT default KUNIT_ALL_TESTS diff --git a/lib/math/Makefile b/lib/math/Makefile index 3ef11305f8d2..1c489501ff57 100644 --- a/lib/math/Makefile +++ b/lib/math/Makefile @@ -5,7 +5,4 @@ obj-$(CONFIG_CORDIC) +=3D cordic.o obj-$(CONFIG_PRIME_NUMBERS) +=3D prime_numbers.o obj-$(CONFIG_RATIONAL) +=3D rational.o =20 -obj-$(CONFIG_INT_POW_TEST) +=3D tests/int_pow_kunit.o -obj-$(CONFIG_TEST_DIV64) +=3D test_div64.o -obj-$(CONFIG_TEST_MULDIV64) +=3D test_mul_u64_u64_div_u64.o -obj-$(CONFIG_RATIONAL_KUNIT_TEST) +=3D rational-test.o +obj-y +=3D tests/ diff --git a/lib/math/tests/Makefile b/lib/math/tests/Makefile index 6a169123320a..f9a0a0e6b73a 100644 --- a/lib/math/tests/Makefile +++ b/lib/math/tests/Makefile @@ -1,3 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only =20 -obj-$(CONFIG_INT_POW_TEST) +=3D int_pow_kunit.o +obj-$(CONFIG_DIV64_KUNIT_TEST) +=3D div64_kunit.o +obj-$(CONFIG_INT_POW_KUNIT_TEST) +=3D int_pow_kunit.o +obj-$(CONFIG_MULDIV64_KUNIT_TEST) +=3D mul_u64_u64_div_u64_kunit.o +obj-$(CONFIG_RATIONAL_KUNIT_TEST) +=3D rational_kunit.o diff --git a/lib/math/test_div64.c b/lib/math/tests/div64_kunit.c similarity index 100% rename from lib/math/test_div64.c rename to lib/math/tests/div64_kunit.c diff --git a/lib/math/test_mul_u64_u64_div_u64.c b/lib/math/tests/mul_u64_u= 64_div_u64_kunit.c similarity index 98% rename from lib/math/test_mul_u64_u64_div_u64.c rename to lib/math/tests/mul_u64_u64_div_u64_kunit.c index 58d058de4e73..f61f571a0a2e 100644 --- a/lib/math/test_mul_u64_u64_div_u64.c +++ b/lib/math/tests/mul_u64_u64_div_u64_kunit.c @@ -49,7 +49,7 @@ static test_params test_values[] =3D { * * #!/bin/sh * sed -ne 's/^{ \+\(.*\), \+\(.*\), \+\(.*\), \+\(.*\) },$/\1 \2 \3 \4/p'= \ - * lib/math/test_mul_u64_u64_div_u64.c | + * lib/math/tests/mul_u64_u64_div_u64_kunit.c | * while read a b c r; do * expected=3D$( printf "obase=3D16; ibase=3D16; %X * %X / %X\n" $a $b $= c | bc ) * given=3D$( printf "%X\n" $r ) diff --git a/lib/math/rational-test.c b/lib/math/tests/rational_kunit.c similarity index 100% rename from lib/math/rational-test.c rename to lib/math/tests/rational_kunit.c --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 10:39:34 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 CA09120A5E4 for ; Fri, 11 Oct 2024 07:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631867; cv=none; b=FGYfOIixdvPjyAYQrcS3OUDkpX4bcEyW6IpVIg9uchj+oxfpi15MOX9Mo7xCzqvi/ewcyr6O3qFoXu5JNUiAgshk0dhGnPM1O3KYH7l1AlRiVnZfOpZZ3sexEcyksOVuMmDSLRDB/Qe6nFwiV8nBN8bEK4EeVURlZY4Xymn5jv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631867; c=relaxed/simple; bh=4UNA/bzgNeQKZNn+GTcFYWje5KcHYL5lIgLuvQk+bVg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u2eZnDQe6qslo49Npx7Iz5tH5IUOAx2I2CV6dBLOdzb6WpDd1rMiEajlpByxS72mZj6Q1TPwfz8rETMWY+YVw2IWePNRvMB0Vvnq8ZhSLUYLNLFwEp4FXHbWaA1i3GqiIfcE8zWKoF5fgDYgvqTctYNgMTFW1LKyQBcXa8dOuZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MmdFR+wS; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MmdFR+wS" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e24a31ad88aso2115547276.1 for ; Fri, 11 Oct 2024 00:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728631865; x=1729236665; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=hyJ4dk3YkG68rGowxEN01juZ4Qxhn4HXMW65oX2xFoY=; b=MmdFR+wS7HQcaNGwTgXJZmgqQkWg44FK1z72l+XtzfdsLsKk2j+hPEhPICa0Z13W1X /PX9hJGm/av57iTIFO/o8emHKOC4PuXLTva5kcabz8CKKLKIR4SIztYdNGy4s4qjI0AD zWiKCJaJsZELx/T7IIQ4zW9XD/Zdc4sIRs//9sU0YGl+eY1ayB8zTSimwBS/M1/IyVUK Z2xdMcDLQEZlJSKHMoEtfrVQyYMRP5g59FaOrlRJDbmh5q/2xZWEg+0ndlm1grTwz2qb gVbNF2nHQdCp1/sso0cV1woK37JM08m1DHRDQZhpjTBsVhNPgzCg8/Y4Nssz9sonxTxd 0OqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631865; x=1729236665; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=hyJ4dk3YkG68rGowxEN01juZ4Qxhn4HXMW65oX2xFoY=; b=Tl9CVIXd79L+auxL+SAVEj0G1hXgxAHpNseBLXCm5kAbweEwcTXQrKe52KnS3AhtBO ot7xmvBGzY21RZ6QG2y3e4NEz8A4dwv7Z4MGr38dkWHK2zqdgDUaqT1BMGIEus4ve7MP 5/GiOtocXPXsxprK+EgjTQOnleLfnaFc9nH28Hps3pGuKiXsj88djDdpRnvS22YyUho2 3tCZT3HfAe79Y9YRv1FX6xS801BcQaVBSXICAfc3fH4f4cVZ/RM0uhPNWPsBaFRv2ODr oop/wBN66v9MVlrADA6l6QSaPCU7AL+UhNTALVSBjLSbkTC8WJKgUzWO+NCjJwobH/0K D0og== X-Forwarded-Encrypted: i=1; AJvYcCVhrLYzhFW+vF7gatG8aa8wOgiI/I9bpweKpzuKeqKkMW1d5S44Q1/XbMY5gwniWg5mbjjrD2JNNodeH0w=@vger.kernel.org X-Gm-Message-State: AOJu0YyrAdGb6mPXyRaoQ4TbmETai/b4fXGt/fulv+5egWEsFIyRU7bS 5kC+qasIeMYoQEZmawNztsPe0xMaEQnNw6lcY6XUNl2Guk1bWkD9ATiW1S16SAV55p4SvNBOBv7 zIxI/Ei+i3Q== X-Google-Smtp-Source: AGHT+IEnt/DrbeHagqIrCVFokOqS9C4siCZ3tDEnNfDLr/bUT6Lkv6eaQ6re5XPXQMlsOouyNX83PB9KAt1ZSw== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:b1:7045:ac11:6237]) (user=davidgow job=sendgmr) by 2002:a25:844c:0:b0:e27:3e6a:345 with SMTP id 3f1490d57ef6-e2919ff8519mr1303276.10.1728631864951; Fri, 11 Oct 2024 00:31:04 -0700 (PDT) Date: Fri, 11 Oct 2024 15:25:06 +0800 In-Reply-To: <20241011072509.3068328-2-davidgow@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241011072509.3068328-2-davidgow@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241011072509.3068328-4-davidgow@google.com> Subject: [PATCH 2/6] lib/math: Add int_log test suite From: David Gow To: Andrew Morton , Shuah Khan , Brendan Higgins , Rae Moar , Kees Cook Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Stephen Rothwell , "=?UTF-8?q?Bruno=20Sobreira=20Fran=C3=A7a?=" , linux-kernel-mentees@lists.linuxfoundation.org, David Gow Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bruno Sobreira Fran=C3=A7a This commit introduces KUnit tests for the intlog2 and intlog10 functions, which compute logarithms in base 2 and base 10, respectively. The tests cover a range of inputs to ensure the correctness of these functions across common and edge cases. Signed-off-by: Bruno Sobreira Fran=C3=A7a Reviewed-by: David Gow [Rebased on top of mm-nonmm-unstable] Signed-off-by: David Gow Acked-by: Shuah Khan --- lib/Kconfig.debug | 11 +++++ lib/math/tests/Makefile | 1 + lib/math/tests/int_log_kunit.c | 75 ++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 lib/math/tests/int_log_kunit.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 3ed6cf950f04..6571243ac232 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -3009,6 +3009,17 @@ config INT_POW_KUNIT_TEST =20 If unsure, say N =20 +config INT_LOG_KUNIT_TEST + tristate "Integer log (int_log) test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + This option enables the KUnit test suite for the int_log library= , which + provides two functions to compute the integer logarithm in base = 2 and + base 10, called respectively as intlog2 and intlog10. + + If unsure, say N + endif # RUNTIME_TESTING_MENU =20 config ARCH_USE_MEMTEST diff --git a/lib/math/tests/Makefile b/lib/math/tests/Makefile index f9a0a0e6b73a..89a266241e98 100644 --- a/lib/math/tests/Makefile +++ b/lib/math/tests/Makefile @@ -2,5 +2,6 @@ =20 obj-$(CONFIG_DIV64_KUNIT_TEST) +=3D div64_kunit.o obj-$(CONFIG_INT_POW_KUNIT_TEST) +=3D int_pow_kunit.o +obj-$(CONFIG_INT_LOG_KUNIT_TEST) +=3D int_log_kunit.o obj-$(CONFIG_MULDIV64_KUNIT_TEST) +=3D mul_u64_u64_div_u64_kunit.o obj-$(CONFIG_RATIONAL_KUNIT_TEST) +=3D rational_kunit.o diff --git a/lib/math/tests/int_log_kunit.c b/lib/math/tests/int_log_kunit.c new file mode 100644 index 000000000000..d750a1df37c1 --- /dev/null +++ b/lib/math/tests/int_log_kunit.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include +#include + +struct test_case_params { + u32 value; + unsigned int expected_result; + const char *name; +}; + + +/* The expected result takes into account the log error */ +static const struct test_case_params intlog2_params[] =3D { + {0, 0, "Log base 2 of 0"}, + {1, 0, "Log base 2 of 1"}, + {2, 16777216, "Log base 2 of 2"}, + {3, 26591232, "Log base 2 of 3"}, + {4, 33554432, "Log base 2 of 4"}, + {8, 50331648, "Log base 2 of 8"}, + {16, 67108864, "Log base 2 of 16"}, + {32, 83886080, "Log base 2 of 32"}, + {U32_MAX, 536870911, "Log base 2 of MAX"}, +}; + +static const struct test_case_params intlog10_params[] =3D { + {0, 0, "Log base 10 of 0"}, + {1, 0, "Log base 10 of 1"}, + {6, 13055203, "Log base 10 of 6"}, + {10, 16777225, "Log base 10 of 10"}, + {100, 33554450, "Log base 10 of 100"}, + {1000, 50331675, "Log base 10 of 1000"}, + {10000, 67108862, "Log base 10 of 10000"}, + {U32_MAX, 161614247, "Log base 10 of MAX"} +}; + +static void get_desc(const struct test_case_params *tc, char *desc) +{ + strscpy(desc, tc->name, KUNIT_PARAM_DESC_SIZE); +} + + +KUNIT_ARRAY_PARAM(intlog2, intlog2_params, get_desc); + +static void intlog2_test(struct kunit *test) +{ + const struct test_case_params *tc =3D (const struct test_case_params *)te= st->param_value; + + KUNIT_EXPECT_EQ(test, tc->expected_result, intlog2(tc->value)); +} + +KUNIT_ARRAY_PARAM(intlog10, intlog10_params, get_desc); + +static void intlog10_test(struct kunit *test) +{ + const struct test_case_params *tc =3D (const struct test_case_params *)te= st->param_value; + + KUNIT_EXPECT_EQ(test, tc->expected_result, intlog10(tc->value)); +} + +static struct kunit_case math_int_log_test_cases[] =3D { + KUNIT_CASE_PARAM(intlog2_test, intlog2_gen_params), + KUNIT_CASE_PARAM(intlog10_test, intlog10_gen_params), + {} +}; + +static struct kunit_suite int_log_test_suite =3D { + .name =3D "math-int_log", + .test_cases =3D math_int_log_test_cases, +}; + +kunit_test_suites(&int_log_test_suite); + +MODULE_DESCRIPTION("math.int_log KUnit test suite"); +MODULE_LICENSE("GPL"); + --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 10:39:34 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 764ED20ADD5 for ; Fri, 11 Oct 2024 07:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631875; cv=none; b=twX54LND8nCgi2ecV90KY8wB/mQOROMWwg47w2qgILZq3wNNoNznYkIVV0rVBqLkfRjZbG42kYu8SeUGl4nM4D6vySE5gOJlath2oKcriC9huTxbn9WUPpuk3PfRagrddbSs/npFHGLRPl8vYCWA+h6L664cldQT7D7CDyfUWcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631875; c=relaxed/simple; bh=YW58ht6CyiuZkFliYx0qFm95AAGfQIn/SYFw2I/6ruc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JPJ7Cm84qaDCemEjQlLjf8pl9UxEhtTOASS/zT7TVN1lrljX9VUQHRssIsdFkQYFm3Q9omXDm6XapO/aFcWWj1dN8HIl/mhh/G4EwGK3bsy3AHzqAYGM227Y6BjofrGZ2zVn/xqfxc2s6GjlMrcyrOP2Ts4H78F9lQlovCQPodA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4c/2QQMX; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4c/2QQMX" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e2acec0109so30564477b3.3 for ; Fri, 11 Oct 2024 00:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728631869; x=1729236669; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oEo/RIpbwWM3TDrwxpV43z65/ZOiBhGZMKP7K+QyLzo=; b=4c/2QQMXtLvBuk0UBIAnCy5Gz7bd5BjB7MelCG8k7P04+4VZFqV0DgeGTchsfjLYEg c2hmI6yA8QaoEEKGApBN5UbTTYAzwFZTT0YN9tzzzm558ppyT3jCUbLK9PSRwOZKcHJ5 /TRLfzEFqgLQGDI/DN6fdVDSSfn867IcPMEokwAP6Ykem7jb1yW6ucN7t4z47P6QB8nL Y86phDXLB4skaHK0gBKMokzPBGlICnECHc/7elADmyZJBiDr5WqiuCC/jLFh/zYDno8z 7ViRI2I8qPKHR8SCjrLFuOfckJeTyurVzVx1cHpzgJZ0E08xNejeO+slj4cF399INebY 91Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631869; x=1729236669; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oEo/RIpbwWM3TDrwxpV43z65/ZOiBhGZMKP7K+QyLzo=; b=TEVPLeRWpKhkwIJDRad8Jzbu3+HShkE1Rye86jtIWdJ0zOZ+Yror9j+YTB8LBjui8o AV4DQGrHwoQmv20EgbrKdW6byrsCKfoemqwY/zc4S6gx0NXfrigDkff/kZbeCr4Vnmtt 2VxpQTvtO53M8vyd/sOMWOR89i+NiVi2CLaDfoSjGoqeoVvAEk6SyyJqFWQQ4Ufuf0y4 e5icAIuAcLv+lDRkbIw9QVKER/4xOF9uJoqokgk955AVjwr1VlQuX3dO3A+m0JC63dzW VoE+APiT15KfW8njF0ySa/xOWmUYd9LadSVWOad/3zhi+IfAyf0coXxikehRAlUzjrJ4 g5nQ== X-Forwarded-Encrypted: i=1; AJvYcCWoYL2XcveGouG302POENKwbDpndqPVyWBfvvdbvx7sRXnqSrsTLrw1MWcgsx0NbhoQak6C/BDGlz6+Ie4=@vger.kernel.org X-Gm-Message-State: AOJu0Ywoi/7jusW/54CU1hzKBJesPXEUJsxOWDwLq2Gz90FniSy0C3Nq O29d1XEDkMsTximyKkHequB4o8dHV7oVoLPfH+rmeZk3u9/woyluyRo1l99kFAU/s/yzgFXrQrl Qx5bDwKhwqw== X-Google-Smtp-Source: AGHT+IGdqFCzf4VfBt+kJ7UuT23EboG4g5C752yNmlJ+lOYyUe/sQDWFfgg9Cath79/UvjftuMEFz9qfNUfSHQ== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:b1:7045:ac11:6237]) (user=davidgow job=sendgmr) by 2002:a05:690c:dc2:b0:6e3:39e5:f0e8 with SMTP id 00721157ae682-6e347c4e59fmr218467b3.6.1728631869517; Fri, 11 Oct 2024 00:31:09 -0700 (PDT) Date: Fri, 11 Oct 2024 15:25:07 +0800 In-Reply-To: <20241011072509.3068328-2-davidgow@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241011072509.3068328-2-davidgow@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241011072509.3068328-5-davidgow@google.com> Subject: [PATCH 3/6] lib: Move KUnit tests into tests/ subdirectory From: David Gow To: Andrew Morton , Shuah Khan , Brendan Higgins , Rae Moar , Kees Cook Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Stephen Rothwell , Yury Norov , Rasmus Villemoes , "Jason A . Donenfeld" , Andy Shevchenko , "Naveen N . Rao" , Anil S Keshavamurthy , "David S . Miller" , Masami Hiramatsu , Mark Brown , linux-hardening@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Palmer Dabbelt , Christophe Leroy , Charlie Jenkins , Simon Horman , Jakub Kicinski , Arnd Bergmann , Daniel Latypov , Guenter Roeck , David Howells , "=?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?=" , Marco Elver , Mark Rutland , "Gustavo A. R. Silva" , Vlastimil Babka , Geert Uytterhoeven , Nathan Chancellor , Fangrui Song , "Steven Rostedt (Google)" , David Gow Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kees Cook Following from the recent KUnit file naming discussion[1], move all KUnit tests in lib/ into lib/tests/. Link: https://lore.kernel.org/lkml/20240720165441.it.320-kees@kernel.org/ [= 1] Signed-off-by: Kees Cook Acked-by: "Steven Rostedt (Google)" Acked-by: Jakub Kicinski Acked-by: "Masami Hiramatsu (Google)" Reviewed-by: David Gow [Rebased onto mm-nonmm-unstable, moved usercopy_kunit] Signed-off-by: David Gow Acked-by: Shuah Khan Acked-by: Vlastimil Babka #slab --- MAINTAINERS | 19 +++++++------ lib/Makefile | 36 +----------------------- lib/tests/Makefile | 38 ++++++++++++++++++++++++++ lib/{ =3D> tests}/bitfield_kunit.c | 0 lib/{ =3D> tests}/checksum_kunit.c | 0 lib/{ =3D> tests}/cmdline_kunit.c | 0 lib/{ =3D> tests}/cpumask_kunit.c | 0 lib/{ =3D> tests}/fortify_kunit.c | 0 lib/{ =3D> tests}/hashtable_test.c | 0 lib/{ =3D> tests}/is_signed_type_kunit.c | 0 lib/{ =3D> tests}/kunit_iov_iter.c | 0 lib/{ =3D> tests}/list-test.c | 0 lib/{ =3D> tests}/memcpy_kunit.c | 0 lib/{ =3D> tests}/overflow_kunit.c | 0 lib/{ =3D> tests}/siphash_kunit.c | 0 lib/{ =3D> tests}/slub_kunit.c | 0 lib/{ =3D> tests}/stackinit_kunit.c | 0 lib/{ =3D> tests}/string_helpers_kunit.c | 0 lib/{ =3D> tests}/string_kunit.c | 0 lib/{ =3D> tests}/test_bits.c | 0 lib/{ =3D> tests}/test_fprobe.c | 0 lib/{ =3D> tests}/test_hash.c | 0 lib/{ =3D> tests}/test_kprobes.c | 0 lib/{ =3D> tests}/test_linear_ranges.c | 0 lib/{ =3D> tests}/test_list_sort.c | 0 lib/{ =3D> tests}/test_sort.c | 0 lib/{ =3D> tests}/usercopy_kunit.c | 0 27 files changed, 49 insertions(+), 44 deletions(-) create mode 100644 lib/tests/Makefile rename lib/{ =3D> tests}/bitfield_kunit.c (100%) rename lib/{ =3D> tests}/checksum_kunit.c (100%) rename lib/{ =3D> tests}/cmdline_kunit.c (100%) rename lib/{ =3D> tests}/cpumask_kunit.c (100%) rename lib/{ =3D> tests}/fortify_kunit.c (100%) rename lib/{ =3D> tests}/hashtable_test.c (100%) rename lib/{ =3D> tests}/is_signed_type_kunit.c (100%) rename lib/{ =3D> tests}/kunit_iov_iter.c (100%) rename lib/{ =3D> tests}/list-test.c (100%) rename lib/{ =3D> tests}/memcpy_kunit.c (100%) rename lib/{ =3D> tests}/overflow_kunit.c (100%) rename lib/{ =3D> tests}/siphash_kunit.c (100%) rename lib/{ =3D> tests}/slub_kunit.c (100%) rename lib/{ =3D> tests}/stackinit_kunit.c (100%) rename lib/{ =3D> tests}/string_helpers_kunit.c (100%) rename lib/{ =3D> tests}/string_kunit.c (100%) rename lib/{ =3D> tests}/test_bits.c (100%) rename lib/{ =3D> tests}/test_fprobe.c (100%) rename lib/{ =3D> tests}/test_hash.c (100%) rename lib/{ =3D> tests}/test_kprobes.c (100%) rename lib/{ =3D> tests}/test_linear_ranges.c (100%) rename lib/{ =3D> tests}/test_list_sort.c (100%) rename lib/{ =3D> tests}/test_sort.c (100%) rename lib/{ =3D> tests}/usercopy_kunit.c (100%) diff --git a/MAINTAINERS b/MAINTAINERS index f1e1cd652699..bbba5c760533 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3929,10 +3929,10 @@ F: include/vdso/bits.h F: lib/bitmap-str.c F: lib/bitmap.c F: lib/cpumask.c -F: lib/cpumask_kunit.c F: lib/find_bit.c F: lib/find_bit_benchmark.c F: lib/test_bitmap.c +F: lib/tests/cpumask_kunit.c F: tools/include/linux/bitfield.h F: tools/include/linux/bitmap.h F: tools/include/linux/bits.h @@ -8911,9 +8911,10 @@ L: linux-hardening@vger.kernel.org S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-ne= xt/hardening F: include/linux/fortify-string.h -F: lib/fortify_kunit.c -F: lib/memcpy_kunit.c F: lib/test_fortify/* +F: lib/tests/fortify_kunit.c +F: lib/tests/memcpy_kunit.c +F: scripts/test_fortify.sh K: \bunsafe_memcpy\b K: \b__NO_FORTIFY\b =20 @@ -9578,9 +9579,9 @@ F: include/linux/string.h F: include/linux/string_choices.h F: include/linux/string_helpers.h F: lib/string.c -F: lib/string_kunit.c F: lib/string_helpers.c -F: lib/string_helpers_kunit.c +F: lib/tests/string_helpers_kunit.c +F: lib/tests/string_kunit.c F: scripts/coccinelle/api/string_choices.cocci =20 GENERIC UIO DRIVER FOR PCI DEVICES @@ -12741,7 +12742,7 @@ F: Documentation/trace/kprobes.rst F: include/asm-generic/kprobes.h F: include/linux/kprobes.h F: kernel/kprobes.c -F: lib/test_kprobes.c +F: lib/tests/test_kprobes.c F: samples/kprobes =20 KS0108 LCD CONTROLLER DRIVER @@ -13091,7 +13092,7 @@ M: Mark Brown R: Matti Vaittinen F: include/linux/linear_range.h F: lib/linear_ranges.c -F: lib/test_linear_ranges.c +F: lib/tests/test_linear_ranges.c =20 LINUX FOR POWER MACINTOSH L: linuxppc-dev@lists.ozlabs.org @@ -13219,7 +13220,7 @@ M: David Gow L: linux-kselftest@vger.kernel.org L: kunit-dev@googlegroups.com S: Maintained -F: lib/list-test.c +F: lib/tests/list-test.c =20 LITEX PLATFORM M: Karol Gugala @@ -21199,7 +21200,7 @@ M: Jason A. Donenfeld S: Maintained F: include/linux/siphash.h F: lib/siphash.c -F: lib/siphash_kunit.c +F: lib/tests/siphash_kunit.c =20 SIS 190 ETHERNET DRIVER M: Francois Romieu diff --git a/lib/Makefile b/lib/Makefile index 53f82de7cbe2..7f2ddbf03fe9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -51,9 +51,7 @@ obj-y +=3D bcd.o sort.o parser.o debug_locks.o random32.o= \ percpu-refcount.o rhashtable.o base64.o \ once.o refcount.o rcuref.o usercopy.o errseq.o bucket_locks.o \ generic-radix-tree.o bitmap-str.o -obj-$(CONFIG_STRING_KUNIT_TEST) +=3D string_kunit.o obj-y +=3D string_helpers.o -obj-$(CONFIG_STRING_HELPERS_KUNIT_TEST) +=3D string_helpers_kunit.o obj-y +=3D hexdump.o obj-$(CONFIG_TEST_HEXDUMP) +=3D test_hexdump.o obj-y +=3D kstrtox.o @@ -64,22 +62,17 @@ obj-$(CONFIG_TEST_DHRY) +=3D test_dhry.o obj-$(CONFIG_TEST_FIRMWARE) +=3D test_firmware.o obj-$(CONFIG_TEST_BITOPS) +=3D test_bitops.o CFLAGS_test_bitops.o +=3D -Werror -obj-$(CONFIG_CPUMASK_KUNIT_TEST) +=3D cpumask_kunit.o obj-$(CONFIG_TEST_SYSCTL) +=3D test_sysctl.o -obj-$(CONFIG_TEST_IOV_ITER) +=3D kunit_iov_iter.o -obj-$(CONFIG_HASH_KUNIT_TEST) +=3D test_hash.o obj-$(CONFIG_TEST_IDA) +=3D test_ida.o obj-$(CONFIG_TEST_UBSAN) +=3D test_ubsan.o CFLAGS_test_ubsan.o +=3D $(call cc-disable-warning, vla) CFLAGS_test_ubsan.o +=3D $(call cc-disable-warning, unused-but-set-variabl= e) UBSAN_SANITIZE_test_ubsan.o :=3D y obj-$(CONFIG_TEST_KSTRTOX) +=3D test-kstrtox.o -obj-$(CONFIG_TEST_LIST_SORT) +=3D test_list_sort.o obj-$(CONFIG_TEST_MIN_HEAP) +=3D test_min_heap.o obj-$(CONFIG_TEST_LKM) +=3D test_module.o obj-$(CONFIG_TEST_VMALLOC) +=3D test_vmalloc.o obj-$(CONFIG_TEST_RHASHTABLE) +=3D test_rhashtable.o -obj-$(CONFIG_TEST_SORT) +=3D test_sort.o obj-$(CONFIG_TEST_STATIC_KEYS) +=3D test_static_keys.o obj-$(CONFIG_TEST_STATIC_KEYS) +=3D test_static_key_base.o obj-$(CONFIG_TEST_DYNAMIC_DEBUG) +=3D test_dynamic_debug.o @@ -105,10 +98,7 @@ obj-$(CONFIG_TEST_MEMINIT) +=3D test_meminit.o obj-$(CONFIG_TEST_LOCKUP) +=3D test_lockup.o obj-$(CONFIG_TEST_HMM) +=3D test_hmm.o obj-$(CONFIG_TEST_FREE_PAGES) +=3D test_free_pages.o -obj-$(CONFIG_KPROBES_SANITY_TEST) +=3D test_kprobes.o obj-$(CONFIG_TEST_REF_TRACKER) +=3D test_ref_tracker.o -CFLAGS_test_fprobe.o +=3D $(CC_FLAGS_FTRACE) -obj-$(CONFIG_FPROBE_SANITY_TEST) +=3D test_fprobe.o obj-$(CONFIG_TEST_OBJPOOL) +=3D test_objpool.o =20 obj-$(CONFIG_TEST_FPU) +=3D test_fpu.o @@ -130,7 +120,7 @@ endif obj-$(CONFIG_DEBUG_INFO_REDUCED) +=3D debug_info.o CFLAGS_debug_info.o +=3D $(call cc-option, -femit-struct-debug-detailed=3D= any) =20 -obj-y +=3D math/ crypto/ +obj-y +=3D math/ crypto/ tests/ =20 obj-$(CONFIG_GENERIC_IOMAP) +=3D iomap.o obj-$(CONFIG_HAS_IOMEM) +=3D iomap_copy.o devres.o @@ -367,30 +357,6 @@ obj-$(CONFIG_OBJAGG) +=3D objagg.o # pldmfw library obj-$(CONFIG_PLDMFW) +=3D pldmfw/ =20 -# KUnit tests -CFLAGS_bitfield_kunit.o :=3D $(DISABLE_STRUCTLEAK_PLUGIN) -obj-$(CONFIG_BITFIELD_KUNIT) +=3D bitfield_kunit.o -obj-$(CONFIG_CHECKSUM_KUNIT) +=3D checksum_kunit.o -obj-$(CONFIG_LIST_KUNIT_TEST) +=3D list-test.o -obj-$(CONFIG_HASHTABLE_KUNIT_TEST) +=3D hashtable_test.o -obj-$(CONFIG_LINEAR_RANGES_TEST) +=3D test_linear_ranges.o -obj-$(CONFIG_BITS_TEST) +=3D test_bits.o -obj-$(CONFIG_CMDLINE_KUNIT_TEST) +=3D cmdline_kunit.o -obj-$(CONFIG_SLUB_KUNIT_TEST) +=3D slub_kunit.o -obj-$(CONFIG_MEMCPY_KUNIT_TEST) +=3D memcpy_kunit.o -obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) +=3D is_signed_type_kunit.o -CFLAGS_overflow_kunit.o =3D $(call cc-disable-warning, tautological-consta= nt-out-of-range-compare) -obj-$(CONFIG_OVERFLOW_KUNIT_TEST) +=3D overflow_kunit.o -CFLAGS_stackinit_kunit.o +=3D $(call cc-disable-warning, switch-unreachabl= e) -obj-$(CONFIG_STACKINIT_KUNIT_TEST) +=3D stackinit_kunit.o -CFLAGS_fortify_kunit.o +=3D $(call cc-disable-warning, unsequenced) -CFLAGS_fortify_kunit.o +=3D $(call cc-disable-warning, stringop-overread) -CFLAGS_fortify_kunit.o +=3D $(call cc-disable-warning, stringop-truncation) -CFLAGS_fortify_kunit.o +=3D $(DISABLE_STRUCTLEAK_PLUGIN) -obj-$(CONFIG_FORTIFY_KUNIT_TEST) +=3D fortify_kunit.o -obj-$(CONFIG_SIPHASH_KUNIT_TEST) +=3D siphash_kunit.o -obj-$(CONFIG_USERCOPY_KUNIT_TEST) +=3D usercopy_kunit.o - obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) +=3D devmem_is_allowed.o =20 obj-$(CONFIG_FIRMWARE_TABLE) +=3D fw_table.o diff --git a/lib/tests/Makefile b/lib/tests/Makefile new file mode 100644 index 000000000000..41689f0b7c97 --- /dev/null +++ b/lib/tests/Makefile @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for tests of kernel library functions. + +# KUnit tests +CFLAGS_bitfield_kunit.o :=3D $(DISABLE_STRUCTLEAK_PLUGIN) +obj-$(CONFIG_BITFIELD_KUNIT) +=3D bitfield_kunit.o +obj-$(CONFIG_BITS_TEST) +=3D test_bits.o +obj-$(CONFIG_CHECKSUM_KUNIT) +=3D checksum_kunit.o +obj-$(CONFIG_CMDLINE_KUNIT_TEST) +=3D cmdline_kunit.o +obj-$(CONFIG_CPUMASK_KUNIT_TEST) +=3D cpumask_kunit.o +CFLAGS_fortify_kunit.o +=3D $(call cc-disable-warning, unsequenced) +CFLAGS_fortify_kunit.o +=3D $(call cc-disable-warning, stringop-overread) +CFLAGS_fortify_kunit.o +=3D $(call cc-disable-warning, stringop-truncation) +CFLAGS_fortify_kunit.o +=3D $(DISABLE_STRUCTLEAK_PLUGIN) +obj-$(CONFIG_FORTIFY_KUNIT_TEST) +=3D fortify_kunit.o +CFLAGS_test_fprobe.o +=3D $(CC_FLAGS_FTRACE) +obj-$(CONFIG_FPROBE_SANITY_TEST) +=3D test_fprobe.o +obj-$(CONFIG_HASHTABLE_KUNIT_TEST) +=3D hashtable_test.o +obj-$(CONFIG_HASH_KUNIT_TEST) +=3D test_hash.o +obj-$(CONFIG_TEST_IOV_ITER) +=3D kunit_iov_iter.o +obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) +=3D is_signed_type_kunit.o +obj-$(CONFIG_KPROBES_SANITY_TEST) +=3D test_kprobes.o +obj-$(CONFIG_LIST_KUNIT_TEST) +=3D list-test.o +obj-$(CONFIG_TEST_LIST_SORT) +=3D test_list_sort.o +obj-$(CONFIG_LINEAR_RANGES_TEST) +=3D test_linear_ranges.o +obj-$(CONFIG_MEMCPY_KUNIT_TEST) +=3D memcpy_kunit.o +CFLAGS_overflow_kunit.o =3D $(call cc-disable-warning, tautological-consta= nt-out-of-range-compare) +obj-$(CONFIG_OVERFLOW_KUNIT_TEST) +=3D overflow_kunit.o +obj-$(CONFIG_SIPHASH_KUNIT_TEST) +=3D siphash_kunit.o +obj-$(CONFIG_SLUB_KUNIT_TEST) +=3D slub_kunit.o +obj-$(CONFIG_TEST_SORT) +=3D test_sort.o +CFLAGS_stackinit_kunit.o +=3D $(call cc-disable-warning, switch-unreachabl= e) +obj-$(CONFIG_STACKINIT_KUNIT_TEST) +=3D stackinit_kunit.o +obj-$(CONFIG_STRING_KUNIT_TEST) +=3D string_kunit.o +obj-$(CONFIG_STRING_HELPERS_KUNIT_TEST) +=3D string_helpers_kunit.o +obj-$(CONFIG_USERCOPY_KUNIT_TEST) +=3D usercopy_kunit.o + diff --git a/lib/bitfield_kunit.c b/lib/tests/bitfield_kunit.c similarity index 100% rename from lib/bitfield_kunit.c rename to lib/tests/bitfield_kunit.c diff --git a/lib/checksum_kunit.c b/lib/tests/checksum_kunit.c similarity index 100% rename from lib/checksum_kunit.c rename to lib/tests/checksum_kunit.c diff --git a/lib/cmdline_kunit.c b/lib/tests/cmdline_kunit.c similarity index 100% rename from lib/cmdline_kunit.c rename to lib/tests/cmdline_kunit.c diff --git a/lib/cpumask_kunit.c b/lib/tests/cpumask_kunit.c similarity index 100% rename from lib/cpumask_kunit.c rename to lib/tests/cpumask_kunit.c diff --git a/lib/fortify_kunit.c b/lib/tests/fortify_kunit.c similarity index 100% rename from lib/fortify_kunit.c rename to lib/tests/fortify_kunit.c diff --git a/lib/hashtable_test.c b/lib/tests/hashtable_test.c similarity index 100% rename from lib/hashtable_test.c rename to lib/tests/hashtable_test.c diff --git a/lib/is_signed_type_kunit.c b/lib/tests/is_signed_type_kunit.c similarity index 100% rename from lib/is_signed_type_kunit.c rename to lib/tests/is_signed_type_kunit.c diff --git a/lib/kunit_iov_iter.c b/lib/tests/kunit_iov_iter.c similarity index 100% rename from lib/kunit_iov_iter.c rename to lib/tests/kunit_iov_iter.c diff --git a/lib/list-test.c b/lib/tests/list-test.c similarity index 100% rename from lib/list-test.c rename to lib/tests/list-test.c diff --git a/lib/memcpy_kunit.c b/lib/tests/memcpy_kunit.c similarity index 100% rename from lib/memcpy_kunit.c rename to lib/tests/memcpy_kunit.c diff --git a/lib/overflow_kunit.c b/lib/tests/overflow_kunit.c similarity index 100% rename from lib/overflow_kunit.c rename to lib/tests/overflow_kunit.c diff --git a/lib/siphash_kunit.c b/lib/tests/siphash_kunit.c similarity index 100% rename from lib/siphash_kunit.c rename to lib/tests/siphash_kunit.c diff --git a/lib/slub_kunit.c b/lib/tests/slub_kunit.c similarity index 100% rename from lib/slub_kunit.c rename to lib/tests/slub_kunit.c diff --git a/lib/stackinit_kunit.c b/lib/tests/stackinit_kunit.c similarity index 100% rename from lib/stackinit_kunit.c rename to lib/tests/stackinit_kunit.c diff --git a/lib/string_helpers_kunit.c b/lib/tests/string_helpers_kunit.c similarity index 100% rename from lib/string_helpers_kunit.c rename to lib/tests/string_helpers_kunit.c diff --git a/lib/string_kunit.c b/lib/tests/string_kunit.c similarity index 100% rename from lib/string_kunit.c rename to lib/tests/string_kunit.c diff --git a/lib/test_bits.c b/lib/tests/test_bits.c similarity index 100% rename from lib/test_bits.c rename to lib/tests/test_bits.c diff --git a/lib/test_fprobe.c b/lib/tests/test_fprobe.c similarity index 100% rename from lib/test_fprobe.c rename to lib/tests/test_fprobe.c diff --git a/lib/test_hash.c b/lib/tests/test_hash.c similarity index 100% rename from lib/test_hash.c rename to lib/tests/test_hash.c diff --git a/lib/test_kprobes.c b/lib/tests/test_kprobes.c similarity index 100% rename from lib/test_kprobes.c rename to lib/tests/test_kprobes.c diff --git a/lib/test_linear_ranges.c b/lib/tests/test_linear_ranges.c similarity index 100% rename from lib/test_linear_ranges.c rename to lib/tests/test_linear_ranges.c diff --git a/lib/test_list_sort.c b/lib/tests/test_list_sort.c similarity index 100% rename from lib/test_list_sort.c rename to lib/tests/test_list_sort.c diff --git a/lib/test_sort.c b/lib/tests/test_sort.c similarity index 100% rename from lib/test_sort.c rename to lib/tests/test_sort.c diff --git a/lib/usercopy_kunit.c b/lib/tests/usercopy_kunit.c similarity index 100% rename from lib/usercopy_kunit.c rename to lib/tests/usercopy_kunit.c --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 10:39:34 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 1663F20ADD2 for ; Fri, 11 Oct 2024 07:31:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631876; cv=none; b=aYGOBKeL93cT1ltnyjZbuDCdIZNa0lCZaptV30ikbR/Jn+lZnrr5cPzLjXbWo4p98N0HenqyMuLqoeXKhnobjUAGU0xo6b9oiaOvIaW/2LLo6aTPSHN07sE1BtqgKwxTBP1/jAJ9IapBYrnfjloRMRtDtmYnp5nkU22dFT6c5MM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631876; c=relaxed/simple; bh=AMKPesFIZMPLoBoJ2Y9rfxvp8CFrXBUwHZyl9514h2o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ITeIBgsPVrlQg7s77pj+OcF8G29YSMAS+oHJVJJfn7Tkq8211aJbj2+gp/I+brfu2C0Hov14t1bdu9w/dxd530tgLtqYLgxChyHNl6Nk7Bc3AlBgwoTRIZ1WmhigueHAWLBCUGEoEST10yOMakbAZInvXCN74Ws8JavNOJ4GUeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QsnATIqX; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QsnATIqX" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e23ee3110fso30014187b3.1 for ; Fri, 11 Oct 2024 00:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728631874; x=1729236674; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GvbTps7fc2dpRlFJse2FWm6+mRA3DQF4bPdus0fKmQU=; b=QsnATIqXhrMxY1awV+ChHAHXwIiBzIesNUkMu9tQCNLBzVVmEbBR27af6bCCjEX5pr DoUgIsKXGgGetRyRqLzw+t0tVzc55p0LS9EsmTVvEScG53euM/8qa7nzoDufZ+pLH0rZ lILyrtDe8nPRMSpAy09lYCsjMWxeOYnX+MI3g4Qvgj2sugRpDbqTzs/S7tmBQh762d3p mSNEdtGDndJGHjkJFy2HzCYj831qCH94DCZcS3WKcruvqYOhQxOGJ5InPuWzs+ynLTtb BVDSLy8NvuWLCvgPZYoo1OXtVl5AsMxRFNfBT9vPkYMyGnQL4vgvKb/JLolvkF8IIado vwBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631874; x=1729236674; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GvbTps7fc2dpRlFJse2FWm6+mRA3DQF4bPdus0fKmQU=; b=t7xK4vc72/OoIzBtBuui8r4zSN+L3fZ3LAhl0/w7jNlz5LoCBv5j58rpLpTfDPB3oS peSMdg52Q7yqM9Oe2nqfpIo9T6Wyc+voS2A5AwVip+4gW1/WGMCbePAmuRyiw8jLOiON fntyQnTeBXLjnTQk+EBZerUp4Pkk8f4ZNXQuzVS3LWyBzxafDc9MBE5OgkNQPo24A5d5 s8qJY1ClHbAKnCDIOpjAxQxkgwgRJPUbF3WUde8X5PGD9800/AwNDPRtOMlYPtl2MdVt cYmwFdk98K/t9cGwJ0VzcqXWOV4W76HihSziwlfUmy9CyIC11wADe9u8fojQYk3rHKWA DRGA== X-Forwarded-Encrypted: i=1; AJvYcCUh9QzoQ7hPv01l9N+7lzbURJJ8TQcoBGfVnf+uWH8yuD2bqp9xfRexWvqAuXUD9u9M9hJxrxJ6bgoHcNY=@vger.kernel.org X-Gm-Message-State: AOJu0YwaXY+qe5DgGSdltpnvUQZ9+u9lqyrIPLNHjMyqOAO5y5Fw98FZ ClBMiis4yDzgIJ/WILChCMgwLKkzlisvM70C0oxAYjE5wDHkRJ1v3xCnnN72Zv/OzBvu/zqw0Z1 gkyFv/fnIwA== X-Google-Smtp-Source: AGHT+IEXk/1kjI7Z2ejSaYEgxJDFzQUqoGeA/WOYww6aXEhdrGdjP6eIkIiYr6/dpFky7gRGsWAdeqvl5ZW4MQ== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:b1:7045:ac11:6237]) (user=davidgow job=sendgmr) by 2002:a05:690c:4505:b0:6db:d257:b98 with SMTP id 00721157ae682-6e347b30d7dmr269647b3.3.1728631874169; Fri, 11 Oct 2024 00:31:14 -0700 (PDT) Date: Fri, 11 Oct 2024 15:25:08 +0800 In-Reply-To: <20241011072509.3068328-2-davidgow@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241011072509.3068328-2-davidgow@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241011072509.3068328-6-davidgow@google.com> Subject: [PATCH 4/6] lib/tests/kfifo_kunit.c: add tests for the kfifo structure From: David Gow To: Andrew Morton , Shuah Khan , Brendan Higgins , Rae Moar , Kees Cook Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Stephen Rothwell , Diego Vieira , n@nfraprado.net, andrealmeid@riseup.net, vinicius@nukelet.com, David Gow Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Diego Vieira Add KUnit tests for the kfifo data structure. They test the vast majority of macros defined in the kfifo header (include/linux/kfifo.h). These are inspired by the existing tests for the doubly linked list in lib/tests/list-test.c (previously at lib/list-test.c) [1]. Note that this patch depends on the patch that moves the KUnit tests on lib/ into lib/tests/ [2]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree= /lib/list-test.c?h=3Dv6.11-rc6 [2] https://lore.kernel.org/all/20240720181025.work.002-kees@kernel.org/ Signed-off-by: Diego Vieira Reviewed-by: David Gow Signed-off-by: David Gow Acked-by: Shuah Khan --- lib/Kconfig.debug | 14 +++ lib/tests/Makefile | 1 + lib/tests/kfifo_kunit.c | 224 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+) create mode 100644 lib/tests/kfifo_kunit.c diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 6571243ac232..134d077562a9 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2673,6 +2673,20 @@ config SYSCTL_KUNIT_TEST =20 If unsure, say N. =20 +config KFIFO_KUNIT_TEST + tristate "KUnit Test for the generic kernel FIFO implementation" if !KUNI= T_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + This builds the generic FIFO implementation KUnit test suite. + It tests that the API and basic functionality of the kfifo type + and associated macros. + + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + config LIST_KUNIT_TEST tristate "KUnit Test for Kernel Linked-list structures" if !KUNIT_ALL_TES= TS depends on KUNIT diff --git a/lib/tests/Makefile b/lib/tests/Makefile index 41689f0b7c97..380f95b003fc 100644 --- a/lib/tests/Makefile +++ b/lib/tests/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_TEST_IOV_ITER) +=3D kunit_iov_iter.o obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) +=3D is_signed_type_kunit.o obj-$(CONFIG_KPROBES_SANITY_TEST) +=3D test_kprobes.o obj-$(CONFIG_LIST_KUNIT_TEST) +=3D list-test.o +obj-$(CONFIG_KFIFO_KUNIT_TEST) +=3D kfifo_kunit.o obj-$(CONFIG_TEST_LIST_SORT) +=3D test_list_sort.o obj-$(CONFIG_LINEAR_RANGES_TEST) +=3D test_linear_ranges.o obj-$(CONFIG_MEMCPY_KUNIT_TEST) +=3D memcpy_kunit.o diff --git a/lib/tests/kfifo_kunit.c b/lib/tests/kfifo_kunit.c new file mode 100644 index 000000000000..a85eedc3195a --- /dev/null +++ b/lib/tests/kfifo_kunit.c @@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit test for the generic kernel FIFO implementation. + * + * Copyright (C) 2024 Diego Vieira + */ +#include + +#include + +#define KFIFO_SIZE 32 +#define N_ELEMENTS 5 + +static void kfifo_test_reset_should_clear_the_fifo(struct kunit *test) +{ + DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); + + kfifo_put(&my_fifo, 1); + kfifo_put(&my_fifo, 2); + kfifo_put(&my_fifo, 3); + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 3); + + kfifo_reset(&my_fifo); + + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 0); + KUNIT_EXPECT_TRUE(test, kfifo_is_empty(&my_fifo)); +} + +static void kfifo_test_define_should_define_an_empty_fifo(struct kunit *te= st) +{ + DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); + + KUNIT_EXPECT_TRUE(test, kfifo_initialized(&my_fifo)); + KUNIT_EXPECT_TRUE(test, kfifo_is_empty(&my_fifo)); + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 0); +} + +static void kfifo_test_len_should_ret_n_of_stored_elements(struct kunit *t= est) +{ + u8 buffer1[N_ELEMENTS]; + + for (int i =3D 0; i < N_ELEMENTS; i++) + buffer1[i] =3D i + 1; + + DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); + + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 0); + + kfifo_in(&my_fifo, buffer1, N_ELEMENTS); + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), N_ELEMENTS); + + kfifo_in(&my_fifo, buffer1, N_ELEMENTS); + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), N_ELEMENTS * 2); + + kfifo_reset(&my_fifo); + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 0); +} + +static void kfifo_test_put_should_insert_and_get_should_pop(struct kunit *= test) +{ + u8 out_data =3D 0; + int processed_elements; + u8 elements[] =3D { 3, 5, 11 }; + + DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); + + // If the fifo is empty, get returns 0 + processed_elements =3D kfifo_get(&my_fifo, &out_data); + KUNIT_EXPECT_EQ(test, processed_elements, 0); + KUNIT_EXPECT_EQ(test, out_data, 0); + + for (int i =3D 0; i < 3; i++) + kfifo_put(&my_fifo, elements[i]); + + for (int i =3D 0; i < 3; i++) { + processed_elements =3D kfifo_get(&my_fifo, &out_data); + KUNIT_EXPECT_EQ(test, processed_elements, 1); + KUNIT_EXPECT_EQ(test, out_data, elements[i]); + } +} + +static void kfifo_test_in_should_insert_multiple_elements(struct kunit *te= st) +{ + u8 in_buffer[] =3D { 11, 25, 65 }; + u8 out_data; + int processed_elements; + + DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); + + kfifo_in(&my_fifo, in_buffer, 3); + + for (int i =3D 0; i < 3; i++) { + processed_elements =3D kfifo_get(&my_fifo, &out_data); + KUNIT_EXPECT_EQ(test, processed_elements, 1); + KUNIT_EXPECT_EQ(test, out_data, in_buffer[i]); + } +} + +static void kfifo_test_out_should_pop_multiple_elements(struct kunit *test) +{ + u8 in_buffer[] =3D { 11, 25, 65 }; + u8 out_buffer[3]; + int copied_elements; + + DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); + + for (int i =3D 0; i < 3; i++) + kfifo_put(&my_fifo, in_buffer[i]); + + copied_elements =3D kfifo_out(&my_fifo, out_buffer, 3); + KUNIT_EXPECT_EQ(test, copied_elements, 3); + + for (int i =3D 0; i < 3; i++) + KUNIT_EXPECT_EQ(test, out_buffer[i], in_buffer[i]); + KUNIT_EXPECT_TRUE(test, kfifo_is_empty(&my_fifo)); +} + +static void kfifo_test_dec_init_should_define_an_empty_fifo(struct kunit *= test) +{ + DECLARE_KFIFO(my_fifo, u8, KFIFO_SIZE); + + INIT_KFIFO(my_fifo); + + // my_fifo is a struct with an inplace buffer + KUNIT_EXPECT_FALSE(test, __is_kfifo_ptr(&my_fifo)); + + KUNIT_EXPECT_TRUE(test, kfifo_initialized(&my_fifo)); +} + +static void kfifo_test_define_should_equal_declare_init(struct kunit *test) +{ + // declare a variable my_fifo of type struct kfifo of u8 + DECLARE_KFIFO(my_fifo1, u8, KFIFO_SIZE); + // initialize the my_fifo variable + INIT_KFIFO(my_fifo1); + + // DEFINE_KFIFO declares the variable with the initial value + // essentially the same as calling DECLARE_KFIFO and INIT_KFIFO + DEFINE_KFIFO(my_fifo2, u8, KFIFO_SIZE); + + // my_fifo1 and my_fifo2 have the same size + KUNIT_EXPECT_EQ(test, sizeof(my_fifo1), sizeof(my_fifo2)); + KUNIT_EXPECT_EQ(test, kfifo_initialized(&my_fifo1), + kfifo_initialized(&my_fifo2)); + KUNIT_EXPECT_EQ(test, kfifo_is_empty(&my_fifo1), + kfifo_is_empty(&my_fifo2)); +} + +static void kfifo_test_alloc_should_initiliaze_a_ptr_fifo(struct kunit *te= st) +{ + int ret; + DECLARE_KFIFO_PTR(my_fifo, u8); + + INIT_KFIFO(my_fifo); + + // kfifo_initialized returns false signaling the buffer pointer is NULL + KUNIT_EXPECT_FALSE(test, kfifo_initialized(&my_fifo)); + + // kfifo_alloc allocates the buffer + ret =3D kfifo_alloc(&my_fifo, KFIFO_SIZE, GFP_KERNEL); + KUNIT_EXPECT_EQ_MSG(test, ret, 0, "Memory allocation should succeed"); + KUNIT_EXPECT_TRUE(test, kfifo_initialized(&my_fifo)); + + // kfifo_free frees the buffer + kfifo_free(&my_fifo); +} + +static void kfifo_test_peek_should_not_remove_elements(struct kunit *test) +{ + u8 out_data; + int processed_elements; + + DEFINE_KFIFO(my_fifo, u8, KFIFO_SIZE); + + // If the fifo is empty, peek returns 0 + processed_elements =3D kfifo_peek(&my_fifo, &out_data); + KUNIT_EXPECT_EQ(test, processed_elements, 0); + + kfifo_put(&my_fifo, 3); + kfifo_put(&my_fifo, 5); + kfifo_put(&my_fifo, 11); + + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 3); + + processed_elements =3D kfifo_peek(&my_fifo, &out_data); + KUNIT_EXPECT_EQ(test, processed_elements, 1); + KUNIT_EXPECT_EQ(test, out_data, 3); + + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 3); + + // Using peek doesn't remove the element + // so the read element and the fifo length + // remains the same + processed_elements =3D kfifo_peek(&my_fifo, &out_data); + KUNIT_EXPECT_EQ(test, processed_elements, 1); + KUNIT_EXPECT_EQ(test, out_data, 3); + + KUNIT_EXPECT_EQ(test, kfifo_len(&my_fifo), 3); +} + +static struct kunit_case kfifo_test_cases[] =3D { + KUNIT_CASE(kfifo_test_reset_should_clear_the_fifo), + KUNIT_CASE(kfifo_test_define_should_define_an_empty_fifo), + KUNIT_CASE(kfifo_test_len_should_ret_n_of_stored_elements), + KUNIT_CASE(kfifo_test_put_should_insert_and_get_should_pop), + KUNIT_CASE(kfifo_test_in_should_insert_multiple_elements), + KUNIT_CASE(kfifo_test_out_should_pop_multiple_elements), + KUNIT_CASE(kfifo_test_dec_init_should_define_an_empty_fifo), + KUNIT_CASE(kfifo_test_define_should_equal_declare_init), + KUNIT_CASE(kfifo_test_alloc_should_initiliaze_a_ptr_fifo), + KUNIT_CASE(kfifo_test_peek_should_not_remove_elements), + {}, +}; + +static struct kunit_suite kfifo_test_module =3D { + .name =3D "kfifo", + .test_cases =3D kfifo_test_cases, +}; + +kunit_test_suites(&kfifo_test_module); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Diego Vieira "); +MODULE_DESCRIPTION("KUnit test for the kernel FIFO"); --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 10:39:34 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 90FBA20ADFA for ; Fri, 11 Oct 2024 07:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631881; cv=none; b=g/grc8xTEDPOQaIknApbTt6FD/FoJ8B3WsiNooU1rEcpI5R4BD84w9DT4tr7iR12TkKN5iDjOazsdmj8i9TGC0g4JPN/kPRLuiuJXkUfGAoihIhjdAPABzhky8twm2QSptmKU9g1XFpnpQ8zGBXtM8RyyUHuN3CkUq2PzVX81Io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631881; c=relaxed/simple; bh=n7fq3kimOIuPR5kgHeEkIUesgQhbCxpjKXHlj8fkyJg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fQb4oKGM3Eidyb5o2lu4KAA4OOQfQacTDwMBRTZsAibq/q6Hoj/RU/RFzOOsGnB4Uvc8+WNp6ndXP3oarP7k2CzOEk0poi1guPXpM6Ap5GLlYvjW9ZQ0bRWmiaD7eOyP/Ybz5AkQJFGgx4gX8TlG2euezEV0LGOgEg4o8n+/jeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ptFMuFuP; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ptFMuFuP" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e29142c79d6so1379818276.3 for ; Fri, 11 Oct 2024 00:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728631878; x=1729236678; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TWiZJfTPLapUUxzEa+muD72ENnNjkYol+7nJvT/EgXk=; b=ptFMuFuPx0entnLjS80zmgW3elzKEm/Aj4gm5OLBbVUhAVy8vlPByO12bnzUCgvMjl 8Mvsu7w9Djj9Qa6vrmHvGP0YWZ2YytOpUc59ujeJiW1SYfQcyCAGD30PypCJPDpYN8Zf KAEm6tvUy2OAO+zmGz/q7aN4tF14zLr2cWkgX2xr4AQ4LSKxkF5aHJae5x3GbQhSN8sw b4rQccJVEWPRILeu/0ELeHd72058ILZRPH6hQqJV0eSuA/ceP13bzB17mY2E/VC9LLs2 QKSPy9WHOcXLvi/LjAJhAoLOvwoXwKD7hBrf5sf6nuxJvAt3wc12vjjM/Qt+cEFvEDTE L+2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631878; x=1729236678; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TWiZJfTPLapUUxzEa+muD72ENnNjkYol+7nJvT/EgXk=; b=L5+JOAcAQGvpNUmvLXbvjk86rmrZF3hDtqid7xfw2V7JQ9Bxmt/h+8FaTxpHmkBYQZ qmjcHK38D9St7MuU4SGhxnR7gJZvxDglpljK64mB/cu8k7DlVwqiERVetcIoys2CCrLY OyJnJ8L31hJNm3W65OnWFjQb/zYtuS7fYIOyzsegR5Z8OI9gcpV8GbuDc0iKDy9sxpiv UDM2HbF503d2JvwauBGeMg7t5tmH1xtr1WSSi42efEedWCkeGvOoo5rYNr1MuK1mLDri KK40Wq7DccnxlCQMw3VHBcNRPdaMmUnntsN4OL0ZUIyeQ/qleOPpeAj9XZC86Q/xy+mr Y43Q== X-Forwarded-Encrypted: i=1; AJvYcCUSHXZQ8LIKHuzVp8bZNcOi6IYK5EpqhNYCWMCvdANZkm5pRAHmde43iKmAueSk3VYM63JysbPUcBb3OKg=@vger.kernel.org X-Gm-Message-State: AOJu0YyOAwIhY+m7q/vzZg1HW3UguKHahcY5k1p9bhmaXBYnh3RcxjYI gM2r1F4XEXj+k1tLYvgJqek50l3MgRZXdczCYWkvCpqJE6Ed1eMWdwwfSdt+2QLa5TbmxOu+44S 53MWB4s0PMA== X-Google-Smtp-Source: AGHT+IH88HRjWKEFRlFPrvRyWi6CNyAHWoiq3tZI0/D5MKQO6NSt41vdU9SedDRQU8sIxKWgIVCsJXFxbUnIVQ== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:b1:7045:ac11:6237]) (user=davidgow job=sendgmr) by 2002:a25:86d0:0:b0:e28:f485:e000 with SMTP id 3f1490d57ef6-e2919d5faf9mr1106276.1.1728631878484; Fri, 11 Oct 2024 00:31:18 -0700 (PDT) Date: Fri, 11 Oct 2024 15:25:09 +0800 In-Reply-To: <20241011072509.3068328-2-davidgow@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241011072509.3068328-2-davidgow@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241011072509.3068328-7-davidgow@google.com> Subject: [PATCH 5/6] unicode: kunit: refactor selftest to kunit tests From: David Gow To: Andrew Morton , Shuah Khan , Brendan Higgins , Rae Moar , Kees Cook Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Stephen Rothwell , Gabriela Bittencourt , linux-fsdevel@vger.kernel.org, ~lkcamp/patches@lists.sr.ht, Pedro Orlando , Danilo Pereira , Gabriel Krisman Bertazi , David Gow Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Gabriela Bittencourt Refactoring 'test' functions into kunit tests, to test utf-8 support in unicode subsystem. This allows the utf8 tests to be run alongside the KUnit test suite using kunit-tool, quickly compiling and running all desired tests as part of the KUnit test suite, instead of compiling the selftest module and loading it. The refactoring kept the original testing logic intact, while adopting a testing pattern across different kernel modules and leveraging KUnit's benefits. Co-developed-by: Pedro Orlando Signed-off-by: Pedro Orlando Co-developed-by: Danilo Pereira Signed-off-by: Danilo Pereira Signed-off-by: Gabriela Bittencourt Reviewed-by: David Gow Signed-off-by: David Gow Acked-by: Gabriel Krisman Bertazi Acked-by: Shuah Khan --- fs/unicode/.kunitconfig | 3 + fs/unicode/Kconfig | 5 +- fs/unicode/Makefile | 2 +- fs/unicode/utf8-norm.c | 2 +- fs/unicode/utf8-selftest.c | 149 +++++++++++++++++-------------------- 5 files changed, 77 insertions(+), 84 deletions(-) create mode 100644 fs/unicode/.kunitconfig diff --git a/fs/unicode/.kunitconfig b/fs/unicode/.kunitconfig new file mode 100644 index 000000000000..62dd5c171f9c --- /dev/null +++ b/fs/unicode/.kunitconfig @@ -0,0 +1,3 @@ +CONFIG_KUNIT=3Dy +CONFIG_UNICODE=3Dy +CONFIG_UNICODE_NORMALIZATION_KUNIT_TEST=3Dy diff --git a/fs/unicode/Kconfig b/fs/unicode/Kconfig index da786a687fdc..4ad2c36550f1 100644 --- a/fs/unicode/Kconfig +++ b/fs/unicode/Kconfig @@ -10,6 +10,7 @@ config UNICODE be a separate loadable module that gets requested only when a file system actually use it. =20 -config UNICODE_NORMALIZATION_SELFTEST +config UNICODE_NORMALIZATION_KUNIT_TEST tristate "Test UTF-8 normalization support" - depends on UNICODE + depends on UNICODE && KUNIT + default KUNIT_ALL_TESTS diff --git a/fs/unicode/Makefile b/fs/unicode/Makefile index e309afe2b2bb..37bbcbc628a1 100644 --- a/fs/unicode/Makefile +++ b/fs/unicode/Makefile @@ -4,7 +4,7 @@ ifneq ($(CONFIG_UNICODE),) obj-y +=3D unicode.o endif obj-$(CONFIG_UNICODE) +=3D utf8data.o -obj-$(CONFIG_UNICODE_NORMALIZATION_SELFTEST) +=3D utf8-selftest.o +obj-$(CONFIG_UNICODE_NORMALIZATION_KUNIT_TEST) +=3D utf8-selftest.o =20 unicode-y :=3D utf8-norm.o utf8-core.o =20 diff --git a/fs/unicode/utf8-norm.c b/fs/unicode/utf8-norm.c index 768f8ab448b8..7b998c99c88d 100644 --- a/fs/unicode/utf8-norm.c +++ b/fs/unicode/utf8-norm.c @@ -586,7 +586,7 @@ int utf8byte(struct utf8cursor *u8c) } } =20 -#ifdef CONFIG_UNICODE_NORMALIZATION_SELFTEST_MODULE +#if IS_MODULE(CONFIG_UNICODE_NORMALIZATION_KUNIT_TEST) EXPORT_SYMBOL_GPL(utf8version_is_supported); EXPORT_SYMBOL_GPL(utf8nlen); EXPORT_SYMBOL_GPL(utf8ncursor); diff --git a/fs/unicode/utf8-selftest.c b/fs/unicode/utf8-selftest.c index 600e15efe9ed..52ab68ef2bbc 100644 --- a/fs/unicode/utf8-selftest.c +++ b/fs/unicode/utf8-selftest.c @@ -1,38 +1,18 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Kernel module for testing utf-8 support. + * KUnit tests for utf-8 support. * * Copyright 2017 Collabora Ltd. */ =20 -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include #include -#include +#include =20 #include "utf8n.h" =20 -static unsigned int failed_tests; -static unsigned int total_tests; - /* Tests will be based on this version. */ #define UTF8_LATEST UNICODE_AGE(12, 1, 0) =20 -#define _test(cond, func, line, fmt, ...) do { \ - total_tests++; \ - if (!cond) { \ - failed_tests++; \ - pr_err("test %s:%d Failed: %s%s", \ - func, line, #cond, (fmt?":":".")); \ - if (fmt) \ - pr_err(fmt, ##__VA_ARGS__); \ - } \ - } while (0) -#define test_f(cond, fmt, ...) _test(cond, __func__, __LINE__, fmt, ##__VA= _ARGS__) -#define test(cond) _test(cond, __func__, __LINE__, "") - static const struct { /* UTF-8 strings in this vector _must_ be NULL-terminated. */ unsigned char str[10]; @@ -170,69 +150,74 @@ static int utf8cursor(struct utf8cursor *u8c, const s= truct unicode_map *um, return utf8ncursor(u8c, um, n, s, (unsigned int)-1); } =20 -static void check_utf8_nfdi(struct unicode_map *um) +static void check_utf8_nfdi(struct kunit *test) { int i; struct utf8cursor u8c; + struct unicode_map *um =3D test->priv; =20 for (i =3D 0; i < ARRAY_SIZE(nfdi_test_data); i++) { int len =3D strlen(nfdi_test_data[i].str); int nlen =3D strlen(nfdi_test_data[i].dec); int j =3D 0; unsigned char c; + int ret; =20 - test((utf8len(um, UTF8_NFDI, nfdi_test_data[i].str) =3D=3D nlen)); - test((utf8nlen(um, UTF8_NFDI, nfdi_test_data[i].str, len) =3D=3D - nlen)); + KUNIT_EXPECT_EQ(test, utf8len(um, UTF8_NFDI, nfdi_test_data[i].str), nle= n); + KUNIT_EXPECT_EQ(test, utf8nlen(um, UTF8_NFDI, nfdi_test_data[i].str, len= ), + nlen); =20 - if (utf8cursor(&u8c, um, UTF8_NFDI, nfdi_test_data[i].str) < 0) - pr_err("can't create cursor\n"); + + ret =3D utf8cursor(&u8c, um, UTF8_NFDI, nfdi_test_data[i].str); + KUNIT_EXPECT_TRUE_MSG(test, ret >=3D 0, "Can't create cursor\n"); =20 while ((c =3D utf8byte(&u8c)) > 0) { - test_f((c =3D=3D nfdi_test_data[i].dec[j]), - "Unexpected byte 0x%x should be 0x%x\n", - c, nfdi_test_data[i].dec[j]); + KUNIT_EXPECT_EQ_MSG(test, c, nfdi_test_data[i].dec[j], + "Unexpected byte 0x%x should be 0x%x\n", + c, nfdi_test_data[i].dec[j]); j++; } =20 - test((j =3D=3D nlen)); + KUNIT_EXPECT_EQ(test, j, nlen); } } =20 -static void check_utf8_nfdicf(struct unicode_map *um) +static void check_utf8_nfdicf(struct kunit *test) { int i; struct utf8cursor u8c; + struct unicode_map *um =3D test->priv; =20 for (i =3D 0; i < ARRAY_SIZE(nfdicf_test_data); i++) { int len =3D strlen(nfdicf_test_data[i].str); int nlen =3D strlen(nfdicf_test_data[i].ncf); int j =3D 0; + int ret; unsigned char c; =20 - test((utf8len(um, UTF8_NFDICF, nfdicf_test_data[i].str) =3D=3D - nlen)); - test((utf8nlen(um, UTF8_NFDICF, nfdicf_test_data[i].str, len) =3D=3D - nlen)); + KUNIT_EXPECT_EQ(test, utf8len(um, UTF8_NFDICF, nfdicf_test_data[i].str), + nlen); + KUNIT_EXPECT_EQ(test, utf8nlen(um, UTF8_NFDICF, nfdicf_test_data[i].str,= len), + nlen); =20 - if (utf8cursor(&u8c, um, UTF8_NFDICF, - nfdicf_test_data[i].str) < 0) - pr_err("can't create cursor\n"); + ret =3D utf8cursor(&u8c, um, UTF8_NFDICF, nfdicf_test_data[i].str); + KUNIT_EXPECT_TRUE_MSG(test, ret >=3D 0, "Can't create cursor\n"); =20 while ((c =3D utf8byte(&u8c)) > 0) { - test_f((c =3D=3D nfdicf_test_data[i].ncf[j]), - "Unexpected byte 0x%x should be 0x%x\n", - c, nfdicf_test_data[i].ncf[j]); + KUNIT_EXPECT_EQ_MSG(test, c, nfdicf_test_data[i].ncf[j], + "Unexpected byte 0x%x should be 0x%x\n", + c, nfdicf_test_data[i].ncf[j]); j++; } =20 - test((j =3D=3D nlen)); + KUNIT_EXPECT_EQ(test, j, nlen); } } =20 -static void check_utf8_comparisons(struct unicode_map *table) +static void check_utf8_comparisons(struct kunit *test) { int i; + struct unicode_map *um =3D test->priv; =20 for (i =3D 0; i < ARRAY_SIZE(nfdi_test_data); i++) { const struct qstr s1 =3D {.name =3D nfdi_test_data[i].str, @@ -240,8 +225,9 @@ static void check_utf8_comparisons(struct unicode_map *= table) const struct qstr s2 =3D {.name =3D nfdi_test_data[i].dec, .len =3D sizeof(nfdi_test_data[i].dec)}; =20 - test_f(!utf8_strncmp(table, &s1, &s2), - "%s %s comparison mismatch\n", s1.name, s2.name); + /* strncmp returns 0 when strings are equal */ + KUNIT_EXPECT_TRUE_MSG(test, utf8_strncmp(um, &s1, &s2) =3D=3D 0, + "%s %s comparison mismatch\n", s1.name, s2.name); } =20 for (i =3D 0; i < ARRAY_SIZE(nfdicf_test_data); i++) { @@ -250,62 +236,65 @@ static void check_utf8_comparisons(struct unicode_map= *table) const struct qstr s2 =3D {.name =3D nfdicf_test_data[i].ncf, .len =3D sizeof(nfdicf_test_data[i].ncf)}; =20 - test_f(!utf8_strncasecmp(table, &s1, &s2), - "%s %s comparison mismatch\n", s1.name, s2.name); + /* strncasecmp returns 0 when strings are equal */ + KUNIT_EXPECT_TRUE_MSG(test, utf8_strncasecmp(um, &s1, &s2) =3D=3D 0, + "%s %s comparison mismatch\n", s1.name, s2.name); } } =20 -static void check_supported_versions(struct unicode_map *um) +static void check_supported_versions(struct kunit *test) { + struct unicode_map *um =3D test->priv; /* Unicode 7.0.0 should be supported. */ - test(utf8version_is_supported(um, UNICODE_AGE(7, 0, 0))); + KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UNICODE_AGE(7, 0, 0)= )); =20 /* Unicode 9.0.0 should be supported. */ - test(utf8version_is_supported(um, UNICODE_AGE(9, 0, 0))); + KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UNICODE_AGE(9, 0, 0)= )); =20 /* Unicode 1x.0.0 (the latest version) should be supported. */ - test(utf8version_is_supported(um, UTF8_LATEST)); + KUNIT_EXPECT_TRUE(test, utf8version_is_supported(um, UTF8_LATEST)); =20 /* Next versions don't exist. */ - test(!utf8version_is_supported(um, UNICODE_AGE(13, 0, 0))); - test(!utf8version_is_supported(um, UNICODE_AGE(0, 0, 0))); - test(!utf8version_is_supported(um, UNICODE_AGE(-1, -1, -1))); + KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(13, 0, = 0))); + KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(0, 0, 0= ))); + KUNIT_EXPECT_FALSE(test, utf8version_is_supported(um, UNICODE_AGE(-1, -1,= -1))); } =20 -static int __init init_test_ucd(void) +static struct kunit_case unicode_normalization_test_cases[] =3D { + KUNIT_CASE(check_supported_versions), + KUNIT_CASE(check_utf8_comparisons), + KUNIT_CASE(check_utf8_nfdicf), + KUNIT_CASE(check_utf8_nfdi), + {} +}; + +static int init_test_ucd(struct kunit *test) { - struct unicode_map *um; + struct unicode_map *um =3D utf8_load(UTF8_LATEST); =20 - failed_tests =3D 0; - total_tests =3D 0; + test->priv =3D um; =20 - um =3D utf8_load(UTF8_LATEST); - if (IS_ERR(um)) { - pr_err("%s: Unable to load utf8 table.\n", __func__); - return PTR_ERR(um); - } + KUNIT_EXPECT_EQ_MSG(test, IS_ERR(um), 0, + "%s: Unable to load utf8 table.\n", __func__); =20 - check_supported_versions(um); - check_utf8_nfdi(um); - check_utf8_nfdicf(um); - check_utf8_comparisons(um); - - if (!failed_tests) - pr_info("All %u tests passed\n", total_tests); - else - pr_err("%u out of %u tests failed\n", failed_tests, - total_tests); - utf8_unload(um); return 0; } =20 -static void __exit exit_test_ucd(void) +static void exit_test_ucd(struct kunit *test) { + utf8_unload(test->priv); } =20 -module_init(init_test_ucd); -module_exit(exit_test_ucd); +static struct kunit_suite unicode_normalization_test_suite =3D { + .name =3D "unicode_normalization", + .test_cases =3D unicode_normalization_test_cases, + .init =3D init_test_ucd, + .exit =3D exit_test_ucd, +}; + +kunit_test_suite(unicode_normalization_test_suite); + =20 MODULE_AUTHOR("Gabriel Krisman Bertazi "); -MODULE_DESCRIPTION("Kernel module for testing utf-8 support"); +MODULE_DESCRIPTION("KUnit tests for utf-8 support."); MODULE_LICENSE("GPL"); --=20 2.47.0.rc1.288.g06298d1525-goog From nobody Wed Nov 27 10:39:34 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 1412720B1E9 for ; Fri, 11 Oct 2024 07:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631885; cv=none; b=JVu0lJWaXd5172UJRO+9L1H/zapZsKZqDvxGFl1y+qGIeZ9sk49D8lFPatFv3S+HpRRZehsfiTK7fuFTud4REeuAT8+QqN5fQPIzgpKhIR2teF98GLH2TY9inCD5qepi1hgTgCJod/ADTcr6mhEstfF30YL0wN1zwVDOMYBUKiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728631885; c=relaxed/simple; bh=Xe26Bp8gHEAiwGIs7RHL/NO77RSdideardrkLGG2ZOU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oiZckYI9lKayUT09CS3k6/K4XBtWoLboEmrz9mL6Zhfxw//PbVUb1fPQ/XZPbWTUAwh8EoRNDzEuAKQ6KYJeNaQDCDtII2imqtJmbcT5H1A+suBI13BWtBKVhScGqoNG6fZWrg38qQXobs/0IqmiG/oNKBdq27/vKTsLmC1Xz2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GRz2EOxE; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--davidgow.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GRz2EOxE" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e32b43e053so24732647b3.1 for ; Fri, 11 Oct 2024 00:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728631883; x=1729236683; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ieo7ZHNuo7RJzAqC+Thl/FRfm1f3ThfajYdgqPFwDO8=; b=GRz2EOxEwwOLL1Y1HI114e+YWm2alx8yV0E3cGt3h4aI4B9Y4w+B7Y5aUA4Nr6k2nu N4hR1pGTuSmBQFZmhGwPcU4MwrzvGB781AvH+XS9dsvSZaSm8wTyGOgmwpHDDS4BH6jc tL5VNhdmoDGDoUR23/FTaqufwVt2bfYWixB+EuLSy5RW/kHeceDIpxoIpbVqOYK+qL3I yao9DNm3uh5GsY9YPSFgbJH4TKbhg3uC9+6OHHXLyYc45jWKD/sNlNGxBxjjRqoKYxCp u83XZGrv0qhG5W4NOjs1OGKyEumVBQoh366++MaV6DtqPl+/xgxiVa1v6ws4jSo2Z2gC UDIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728631883; x=1729236683; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ieo7ZHNuo7RJzAqC+Thl/FRfm1f3ThfajYdgqPFwDO8=; b=Yk4YCLLDhE+i0OFpVpHvmtLgrJZt87HtpR8LbsUgAFgtRbfaXxDnN4YP+8e3i/CktM arWiNuI9VY3si2jT6C6JifJOrml2KL4r1BSasPVebZOd6/xewTDfHnaraj7pWSIQqkn1 vbAXzVRzcJJch7sawj9Al8G2vHJSYyyrarkExAW+EQnGXPNtmnCuyFntsYKS2UAeTZFq /4rB9GUJ5u6br9riJzs2CLmUE/MSntGTp31xOv/e5Qh/HadqJyzelj1A3tQgClIa1pAH 9OVPx5MH1lxG9Uz2X71QNoK8fOmqPhquSpXTgykp5sOdChVcaXEOeHvQcrYibET5SPvv zBNw== X-Forwarded-Encrypted: i=1; AJvYcCU//YnQjrleB3ruVAIM+ISMlFJpIr9OPX0t2FW+GpNglSENrZvlqmVJNXgUQvOmHHIpcU67FtxI8O4f9t4=@vger.kernel.org X-Gm-Message-State: AOJu0YyfAwkSbV5CIewfOC87Q4EOfa99Egvmnno3jglGxt2VhRPLyI59 /3IWscfBUQ+nENOg3r+H7x2R69nZ201OEJ0ll6M2RMz4Eterdd9SDCcBhDbvBHoYbvnsxfqkoBM v4/2AKZejAA== X-Google-Smtp-Source: AGHT+IGG0g8IxhAAOBToCYFjY2+/Nqb4qOh7xXJ3HzDIkyIPWZmvA5SROzdPJywLrzQPXDDBI1zKCIOhPFL/Kg== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:b1:7045:ac11:6237]) (user=davidgow job=sendgmr) by 2002:a05:690c:c09:b0:6e3:1702:b3e6 with SMTP id 00721157ae682-6e347b368d2mr364247b3.4.1728631883040; Fri, 11 Oct 2024 00:31:23 -0700 (PDT) Date: Fri, 11 Oct 2024 15:25:10 +0800 In-Reply-To: <20241011072509.3068328-2-davidgow@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241011072509.3068328-2-davidgow@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241011072509.3068328-8-davidgow@google.com> Subject: [PATCH 6/6] unicode: kunit: change tests filename and path From: David Gow To: Andrew Morton , Shuah Khan , Brendan Higgins , Rae Moar , Kees Cook Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Stephen Rothwell , Gabriela Bittencourt , linux-fsdevel@vger.kernel.org, ~lkcamp/patches@lists.sr.ht, Pedro Orlando , Danilo Pereira , Gabriel Krisman Bertazi , David Gow Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Gabriela Bittencourt Change utf8 kunit test filename and path to follow the style convention on Documentation/dev-tools/kunit/style.rst Co-developed-by: Pedro Orlando Signed-off-by: Pedro Orlando Co-developed-by: Danilo Pereira Signed-off-by: Danilo Pereira Signed-off-by: Gabriela Bittencourt Reviewed-by: David Gow [Rebased, fixed module build (Gabriel Krisman Bertazi)] Signed-off-by: David Gow Acked-by: Gabriel Krisman Bertazi Acked-by: Shuah Khan --- fs/unicode/Makefile | 2 +- fs/unicode/{ =3D> tests}/.kunitconfig | 0 fs/unicode/{utf8-selftest.c =3D> tests/utf8_kunit.c} | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename fs/unicode/{ =3D> tests}/.kunitconfig (100%) rename fs/unicode/{utf8-selftest.c =3D> tests/utf8_kunit.c} (100%) diff --git a/fs/unicode/Makefile b/fs/unicode/Makefile index 37bbcbc628a1..d95be7fb9f6b 100644 --- a/fs/unicode/Makefile +++ b/fs/unicode/Makefile @@ -4,7 +4,7 @@ ifneq ($(CONFIG_UNICODE),) obj-y +=3D unicode.o endif obj-$(CONFIG_UNICODE) +=3D utf8data.o -obj-$(CONFIG_UNICODE_NORMALIZATION_KUNIT_TEST) +=3D utf8-selftest.o +obj-$(CONFIG_UNICODE_NORMALIZATION_KUNIT_TEST) +=3D tests/utf8_kunit.o =20 unicode-y :=3D utf8-norm.o utf8-core.o =20 diff --git a/fs/unicode/.kunitconfig b/fs/unicode/tests/.kunitconfig similarity index 100% rename from fs/unicode/.kunitconfig rename to fs/unicode/tests/.kunitconfig diff --git a/fs/unicode/utf8-selftest.c b/fs/unicode/tests/utf8_kunit.c similarity index 100% rename from fs/unicode/utf8-selftest.c rename to fs/unicode/tests/utf8_kunit.c --=20 2.47.0.rc1.288.g06298d1525-goog