From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796115635; b=tteqvhUmbYi02SyB+Ygb37buX6P3XEVAxRjmTDlE3i5lCqwIGX9iGYXCrfrsKtWtyF2V ZFwUU8dgvCIhBCnp+k2//oVSeQ7bx9KDiYSOM6Hxqac8HEzXzoRJELLw9Z3e4VEbllKUA fU+H/5WyZDTwFJ57eQk1DqbmZvKsnGpjlffHsg5o0E8dcuyQVZPMZ+TTFkEsLrQq8bnVl 8MUcGODEWfhDqN9Xz2XuPpvryXmsBuz6bm9VXDlUSO/lbfYTR3ARZypwbsnlDFccxX1PT XHiNmzMXNiiv7RSUz66JWD5sobzkHbKJ6/qXD4AuQBJ0XBJku4xqh58il2DWP4sizKw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796115635; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=Kpf1k9LFw9GSTBLFXc/X6neMJQzoFkucyYUTmW+b7BM=; b=YSOD++DJP0nCyvhha9nIN4Dom1TSj93OoWlWckuP4t+i4lxhJIDoZeop6E/3VmkVmDkU oawFlTNZi5qSNz0eWCg1Abq4wWobJfBm5+ncwsTyKxR/LEY/ygHc0FHwFodu6iQB30UxK jsKS2l4Vzyfvxw87wwkj4p35JesL6LM9g+jYvh/woPshzk2GTbXRNffo2Z5S55dsOJwh1 Rt2715NZCOvtKXZh9S0lWIZt8w4i39NW66IX8kIOdvJDVjAXGpxs3UOkPbirJYlpzVohD m73v9k2pnLdMcaxc0TBN5e1r6NRL1KsTj+Lx/5FlsO8TtsZoPRDNPsKpWnr2O/vqLMw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GScrXPMO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64963606A332; Tue, 1 Dec 2026 09:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GScrXPMO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 596621F000C1; Tue, 1 Dec 2026 09:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796115634; bh=Kpf1k9LFw9GSTBLFXc/X6neMJQzoFkucyYUTmW+b7BM=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=GScrXPMO/Th0D1+a1NV6Y/rhffxli4TlLf0hvV+2ydoRdKSU2EmV6/oNSH9sRFaFK ylTCuYFre1QWCKnomov3dgUi4MR78bQuw6nn8BopomxvtkUA3reoacFBF3SD9iubOh I3eM77YdX1kgqtSWfuf1wKK4jZp0E8Soxrsop7TCsU7c2fA7Js9MjoZDO21Tt1GpVI 62O8+mPZUBuVZY7EvNGCR5s0NJ/RsdEFRqZcd13wRhTu2yGQKbVbK3DiEm6eoP1NAF 6aJE+onEcUYHqCwBwFU0xgtULU319ELiI+JEHMavb5QDb/mBdYw2ABWxQbrkwG0STP yfzMbPf6KFNkA== Message-ID: Date: Tue, 1 Dec 2026 10:00:31 +0100 X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 4/4] media: zoran: add KUnit tests for capture format negotiation To: Minseo Park , clabbe@baylibre.com, mchehab@kernel.org, hverkuil@kernel.org, linux-media@vger.kernel.org Cc: mjpeg-users@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20261125070548.28989-1-hiyoukou@gmail.com> <20261125070548.28989-5-hiyoukou@gmail.com> From: Hans Verkuil Content-Language: en-US, nl In-Reply-To: <20261125070548.28989-5-hiyoukou@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Minseo, On 25/11/2026 08:05, Minseo Park wrote: > Check that zoran_v4l_set_format() leaves zr->buffer_size and > zr->v4l_settings describing the last accepted format when a format is > rejected, and that an accepted format leaves the two consistent with > each other. > > zr_vb2_queue_setup() sizes the capture buffers from zr->buffer_size > while zr36057_set_memgrab() and zr_set_buf() program the chip from > zr->v4l_settings, so a disagreement between them makes the chip DMA a > frame that does not fit the buffers it was given. > > The tests are included into zoran_driver.c because the function under > test is static. I'm taking patches 1-3, but will drop this one. It is overkill to add a KUnit test for such an old driver. Regards, Hans > > Signed-off-by: Minseo Park > --- > drivers/media/pci/zoran/Kconfig | 14 +++ > drivers/media/pci/zoran/zoran_driver.c | 4 + > drivers/media/pci/zoran/zoran_driver_test.c | 123 ++++++++++++++++++++ > 3 files changed, 141 insertions(+) > create mode 100644 drivers/media/pci/zoran/zoran_driver_test.c > > diff --git a/drivers/media/pci/zoran/Kconfig b/drivers/media/pci/zoran/Kconfig > index 3fb3e27e04a8..fd3d3c2e5ff5 100644 > --- a/drivers/media/pci/zoran/Kconfig > +++ b/drivers/media/pci/zoran/Kconfig > @@ -24,6 +24,20 @@ config VIDEO_ZORAN > To compile this driver as a module, choose M here: the > module will be called zr36067. > > +config VIDEO_ZORAN_KUNIT_TEST > + bool "KUnit tests for the Zoran driver" if !KUNIT_ALL_TESTS > + depends on VIDEO_ZORAN && KUNIT > + default KUNIT_ALL_TESTS > + help > + Enable the KUnit tests for the Zoran capture format negotiation. > + They check that a format which fails validation leaves the buffer > + size and the capture geometry describing the previously accepted > + format. > + > + For more information on KUnit see Documentation/dev-tools/kunit. > + > + If you are unsure, say N. > + > config VIDEO_ZORAN_DC30 > bool "Pinnacle/Miro DC30(+) support" > depends on VIDEO_ZORAN > diff --git a/drivers/media/pci/zoran/zoran_driver.c b/drivers/media/pci/zoran/zoran_driver.c > index ec8ed5601f50..894653a97fb0 100644 > --- a/drivers/media/pci/zoran/zoran_driver.c > +++ b/drivers/media/pci/zoran/zoran_driver.c > @@ -976,3 +976,7 @@ void zoran_queue_exit(struct zoran *zr) > { > vb2_queue_release(zr->video_dev->queue); > } > + > +#if IS_ENABLED(CONFIG_VIDEO_ZORAN_KUNIT_TEST) > +#include "zoran_driver_test.c" > +#endif > diff --git a/drivers/media/pci/zoran/zoran_driver_test.c b/drivers/media/pci/zoran/zoran_driver_test.c > new file mode 100644 > index 000000000000..424b2fd065c8 > --- /dev/null > +++ b/drivers/media/pci/zoran/zoran_driver_test.c > @@ -0,0 +1,123 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * KUnit tests for the Zoran capture format negotiation. > + * > + * This file is included at the end of zoran_driver.c so that the tests can > + * reach zoran_v4l_set_format(), which is static. > + */ > + > +#include > + > +/* zoran_card.c: PAL square pixel timings, the largest supported geometry. */ > +static const struct tvnorm zoran_test_pal = { 944, 768, 83, 880, 625, 576, 16 }; > + > +static const struct zoran_format *zoran_test_format(u32 fourcc) > +{ > + unsigned int i; > + > + for (i = 0; i < NUM_FORMATS; i++) > + if (zoran_formats[i].fourcc == fourcc) > + return &zoran_formats[i]; > + > + return NULL; > +} > + > +static struct zoran *zoran_test_alloc(struct kunit *test) > +{ > + struct zoran *zr; > + > + zr = kunit_kzalloc(test, sizeof(*zr), GFP_KERNEL); > + KUNIT_ASSERT_NOT_NULL(test, zr); > + > + /* > + * zoran_v4l_set_format() only reads zr->timing and only reports > + * through pci_dbg(), so a zeroed struct pci_dev is enough. > + */ > + zr->pci_dev = kunit_kzalloc(test, sizeof(*zr->pci_dev), GFP_KERNEL); > + KUNIT_ASSERT_NOT_NULL(test, zr->pci_dev); > + zr->timing = &zoran_test_pal; > + > + return zr; > +} > + > +/* > + * A format that fails validation must leave the device state describing the > + * last format that was accepted. zr_vb2_queue_setup() sizes the capture > + * buffers from zr->buffer_size while zr36057_set_memgrab() and zr_set_buf() > + * program the chip from zr->v4l_settings, so the two must never disagree. > + */ > +static void zoran_set_format_rejected_keeps_state(struct kunit *test) > +{ > + const struct zoran_format *bgr32, *rgb555, *bgr24; > + struct zoran *zr = zoran_test_alloc(test); > + > + bgr32 = zoran_test_format(V4L2_PIX_FMT_BGR32); > + rgb555 = zoran_test_format(V4L2_PIX_FMT_RGB555); > + bgr24 = zoran_test_format(V4L2_PIX_FMT_BGR24); > + KUNIT_ASSERT_NOT_NULL(test, bgr32); > + KUNIT_ASSERT_NOT_NULL(test, rgb555); > + KUNIT_ASSERT_NOT_NULL(test, bgr24); > + > + /* 4 bytes per pixel, so the line alignment check cannot trigger. */ > + KUNIT_ASSERT_EQ(test, 0, zoran_v4l_set_format(zr, 768, 576, bgr32)); > + KUNIT_EXPECT_EQ(test, 768u * 576 * 4, zr->buffer_size); > + KUNIT_EXPECT_EQ(test, 768, zr->v4l_settings.width); > + KUNIT_EXPECT_EQ(test, 576, zr->v4l_settings.height); > + KUNIT_EXPECT_EQ(test, 768 * 4, zr->v4l_settings.bytesperline); > + > + /* 2 bytes per pixel and an odd width: rejected by the alignment check. */ > + KUNIT_EXPECT_EQ(test, -EINVAL, zoran_v4l_set_format(zr, 33, 24, rgb555)); > + KUNIT_EXPECT_EQ(test, 768u * 576 * 4, zr->buffer_size); > + KUNIT_EXPECT_EQ(test, 768, zr->v4l_settings.width); > + KUNIT_EXPECT_EQ(test, 576, zr->v4l_settings.height); > + KUNIT_EXPECT_EQ(test, 768 * 4, zr->v4l_settings.bytesperline); > + > + /* 3 bytes per pixel and a width that is not a multiple of four. */ > + KUNIT_EXPECT_EQ(test, -EINVAL, zoran_v4l_set_format(zr, 33, 24, bgr24)); > + KUNIT_EXPECT_EQ(test, 768u * 576 * 4, zr->buffer_size); > + KUNIT_EXPECT_EQ(test, 768 * 4, zr->v4l_settings.bytesperline); > +} > + > +/* An accepted format must describe the same frame through both fields. */ > +static void zoran_set_format_accepted_is_consistent(struct kunit *test) > +{ > + const struct zoran_format *fmt = zoran_test_format(V4L2_PIX_FMT_YUYV); > + struct zoran *zr = zoran_test_alloc(test); > + > + KUNIT_ASSERT_NOT_NULL(test, fmt); > + > + KUNIT_ASSERT_EQ(test, 0, zoran_v4l_set_format(zr, 704, 576, fmt)); > + KUNIT_EXPECT_EQ(test, (unsigned int)(zr->v4l_settings.bytesperline * > + zr->v4l_settings.height), > + zr->buffer_size); > +} > + > +/* Geometry outside the active area is rejected before anything is stored. */ > +static void zoran_set_format_out_of_range(struct kunit *test) > +{ > + const struct zoran_format *fmt = zoran_test_format(V4L2_PIX_FMT_BGR32); > + struct zoran *zr = zoran_test_alloc(test); > + > + KUNIT_ASSERT_NOT_NULL(test, fmt); > + > + KUNIT_EXPECT_EQ(test, -EINVAL, zoran_v4l_set_format(zr, 769, 576, fmt)); > + KUNIT_EXPECT_EQ(test, 0u, zr->buffer_size); > + KUNIT_EXPECT_EQ(test, -EINVAL, zoran_v4l_set_format(zr, 768, 577, fmt)); > + KUNIT_EXPECT_EQ(test, 0u, zr->buffer_size); > + KUNIT_EXPECT_EQ(test, -EINVAL, zoran_v4l_set_format(zr, 31, 24, fmt)); > + KUNIT_EXPECT_EQ(test, 0u, zr->buffer_size); > +} > + > +static struct kunit_case zoran_test_cases[] = { > + KUNIT_CASE(zoran_set_format_rejected_keeps_state), > + KUNIT_CASE(zoran_set_format_accepted_is_consistent), > + KUNIT_CASE(zoran_set_format_out_of_range), > + {} > +}; > + > +static struct kunit_suite zoran_test_suite = { > + .name = "zoran", > + .test_cases = zoran_test_cases, > +}; > + > +kunit_test_suite(zoran_test_suite);