From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45BA541167C for ; Mon, 3 Aug 2026 12:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785761354; cv=none; b=uwexb2Ws0yP2JgqNAZnjsnei64/SKdymr6Y03lAs15Hq7HQwK3jfyR4spGyUQZ0pw/OXNVry+J4JBOxF47unvyqY3Q3F426EbBtW6Qkd39YJVUGTm68JlCzTo+rNj5O3tYeXLVaZxeJ0z2OkOMUSoFFtt59HAA7Nuvg+MpehDJM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785761354; c=relaxed/simple; bh=Dw8kCj+0e5z09X/AiHYAmo/jw4KDYBX4KTNHnQa03oI=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=bcXtZLfXdgboQkbt4QbDIUlcudltMEf39Atsefg6sTnHRRvRMtn3E/RUOiOMDbt7Pruo6FYnna/cy9FepD2etfcMpGUbwejtCoDEvWB7L4r3nyTsvDVEHhVWLO/3Rkr2HRjCx/bFH9Q+M+cDbdj7WlHahFyz1OfAXuFnorMjYQY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NeF4+OxI; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=LV+oSDE9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NeF4+OxI"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="LV+oSDE9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785761352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Wy0Vs4Ln8sXF3zFU/v51FDbJv/h2bqSlAWl9ZiAyaTI=; b=NeF4+OxIJE7OgpuLZYQlUf/WZqXv4FN6TDMcf492tnTZpjIUc7SSKhGOya03PEr2fad9yT EaAfgXeq6odlSMDNIeJSOOo14tm3/CJamPOQlLma8USH9nhobvFVPv4mKRTmtU18rMHDvh HBF+CV5Yfrmq498LmxUJMV8A7JPteSk= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-qtwm_O0iNsq-WOSp_jqtJw-1; Mon, 03 Aug 2026 08:49:11 -0400 X-MC-Unique: qtwm_O0iNsq-WOSp_jqtJw-1 X-Mimecast-MFC-AGG-ID: qtwm_O0iNsq-WOSp_jqtJw_1785761350 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-49545071724so21754695e9.0 for ; Mon, 03 Aug 2026 05:49:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1785761350; x=1786366150; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=Wy0Vs4Ln8sXF3zFU/v51FDbJv/h2bqSlAWl9ZiAyaTI=; b=LV+oSDE9lR4BrXexrBDsOdRaD8m+1lVVZCVt+AIFF8LxLaAAtNC4vbdR5OBwhk0qFI ZDtLBgLSSTLQPkG6hFDtTTGW/rWqufVmQaDLRB4LwOmVraKvlIcu9dmjlV0nb/P42HIs 4R3Yl0QCh7ZqEpDEDrrGQ8TtatujbR6eCsC3yu31oaQzAlEEuM5CikLcuN9YkrQKmXUS mwBXrWnID/OhLHsuBVrWCCPfpLvGtlG713pIxDxkYwYVrAcObAfLYsqrGGjroCdZeLpM jkbcmpCAPMjSyINYhFGg58eNZd0w2zRZW2Cv70XzwBrsOw9P13ThmaG65pPDGP+Ikcrz e1uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785761350; x=1786366150; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=Wy0Vs4Ln8sXF3zFU/v51FDbJv/h2bqSlAWl9ZiAyaTI=; b=FggZAHkqHBLSAlwe6HnhDAL+yR/xuJEHTmtXcQbzGxUaivTmRBjDUo6pgQGUghuZ5m vXWtfTt7oL0AxiuPbfezudRPfXI/m3I+3NOD6vEBHfwLcRtzzU0X6eP1MpyhkIZWp2zM Ov8x4g7n0nOTAXj4ilDKJXcY4fCEnKH6wkOorCYI+71QXiOnMgzae9+efvRJ1QO6MOjO xjXXO/MNIZy1KgPl059y0vqKBP2vqO4dsn7Ny60zqFeGTaiC8rWC+GhtOyU5VxZR4UHm jyJH85NnjJ9am49Cv5iHijVFOeD1XWNRqfnK8JXf/MsFIL9kNaA7PgRpPSeRZUOZROHX Iamg== X-Forwarded-Encrypted: i=1; AHgh+Rq/bDmusDz7rpry9IJbfMM0uVzbVtpd4f7wCoG0FkTVfGPo+6WFWR7qnT8vRONTvP0NrrjeleFFE+9LMm4=@vger.kernel.org X-Gm-Message-State: AOJu0YwlT5MXr1wWoGxaGQ8ZfTYru2t/+VOc99292DjGUfMPqj+Jchxs 1cUciB+hIqLvZONog/Qt9jsZP2tBz2e1bUETeL4LtN4z2Vji/uTjq7WWd2KhzegqzlTX9+IEjGe pJQnVnj/k5hv7/UIOjFPkA91bLt859ElMrpPcgukaLmNhqUJTqfToE6skJklPoRSNhg== X-Gm-Gg: AR+sD102UIeKdav6pjPuvEKMXqY9JdEeouzrYaTxqrMCxi0rAAwRJ1pWGh146+D1e+a yjzi6VsbzPQiANYTyS6nhfXaRlS5OM9sh+K5aD/c7A2eM9P4tPWVB9A7wE37IaIJ40YxG4CzKli trTBR6wbbwCQdnBKAYx97kxQP63No5OKEQuvgxR6xzdFmd+5U8NOd6na7cHFXcfu+1BFoqso0oB qfoc8WByGHVDXIROvo0yijqCXteu+s/zas8YrJwprs7sMIvJ9oPlKysWfvH+IhoF/J2h5vqlhmC p2XzTS1qtMJLU+X+5WzlT/CitRNK11ptnXG/VfhxbYPlZGu7+OoqLdO36b1MHD7cwulyTuKs98N 3QN5w2LEXuUNzsFy7sqPRRk8gEaid X-Received: by 2002:a05:600c:c490:b0:495:7538:d4ea with SMTP id 5b1f17b1804b1-4980c5fd773mr194744835e9.0.1785761349677; Mon, 03 Aug 2026 05:49:09 -0700 (PDT) X-Received: by 2002:a05:600c:c490:b0:495:7538:d4ea with SMTP id 5b1f17b1804b1-4980c5fd773mr194743855e9.0.1785761349018; Mon, 03 Aug 2026 05:49:09 -0700 (PDT) Received: from gmonaco-thinkpadt14gen3.rmtit.csb ([185.168.96.228]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49808191ef9sm254878215e9.1.2026.08.03.05.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 05:49:08 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2 4/4] rv/reactors: add KUnit tests for reactor registration and dispatch From: Gabriele Monaco To: wen.yang@linux.dev Cc: Nam Cao , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 03 Aug 2026 14:49:07 +0200 In-Reply-To: <55a167aacaf1497fafbbe9fd578ffe14cbee368f.1785695669.git.wen.yang@linux.dev> References: <55a167aacaf1497fafbbe9fd578ffe14cbee368f.1785695669.git.wen.yang@linux.dev> Autocrypt: addr=gmonaco@redhat.com; prefer-encrypt=mutual; keydata=mDMEZuK5YxYJKwYBBAHaRw8BAQdAmJ3dM9Sz6/Hodu33Qrf8QH2bNeNbOikqYtxWFLVm0 1a0JEdhYnJpZWxlIE1vbmFjbyA8Z21vbmFjb0BrZXJuZWwub3JnPoiZBBMWCgBBFiEEysoR+AuB3R Zwp6j270psSVh4TfIFAmjKX2MCGwMFCQWjmoAFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgk Q70psSVh4TfIQuAD+JulczTN6l7oJjyroySU55Fbjdvo52xiYYlMjPG7dCTsBAMFI7dSL5zg98I+8 cXY1J7kyNsY6/dcipqBM4RMaxXsOtCRHYWJyaWVsZSBNb25hY28gPGdtb25hY29AcmVkaGF0LmNvb T6InAQTFgoARAIbAwUJBaOagAULCQgHAgIiAgYVCgkICwIEFgIDAQIeBwIXgBYhBMrKEfgLgd0WcK eo9u9KbElYeE3yBQJoymCyAhkBAAoJEO9KbElYeE3yjX4BAJ/ETNnlHn8OjZPT77xGmal9kbT1bC1 7DfrYVISWV2Y1AP9HdAMhWNAvtCtN2S1beYjNybuK6IzWYcFfeOV+OBWRDQ== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.2 (3.60.2-1.fc44) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2026-08-03 at 02:43 +0800, wen.yang@linux.dev wrote: > From: Wen Yang >=20 > Add KUnit tests covering the reactor register/unregister lifecycle > (including duplicate and name-length rejection) and rv_react() dispatch > (a no-op without a callback, exactly one invocation with one; the mdelay > callback keeps the CPU busy so a timer interrupt exercises the LD_WAIT_SP= IN > lockdep context).=C2=A0 The Kconfig entry is tristate so the tests can be= built > as a module when CONFIG_KUNIT=3Dm; only RV_REACTORS is required. >=20 > Signed-off-by: Wen Yang > --- > =C2=A0kernel/trace/rv/Kconfig=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 12 +++ > =C2=A0kernel/trace/rv/Makefile=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 1 + > =C2=A0kernel/trace/rv/rv_reactors_kunit.c | 143 +++++++++++++++++++++++++= +++ > =C2=A03 files changed, 156 insertions(+) > =C2=A0create mode 100644 kernel/trace/rv/rv_reactors_kunit.c >=20 > diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig > index efa930f94ea4..9bfd429ffdea 100644 > --- a/kernel/trace/rv/Kconfig > +++ b/kernel/trace/rv/Kconfig > @@ -113,6 +113,18 @@ config RV_REACT_PANIC > =C2=A0 =C2=A0 Enables the panic reactor. The panic reactor emits a printk= () > =C2=A0 =C2=A0 message if an exception is found and panic()s the system. > =C2=A0 > +config RV_REACTORS_KUNIT > + tristate "KUnit tests for RV reactors" if !KUNIT_ALL_TESTS > + depends on KUNIT > + depends on RV_REACTORS > + default KUNIT_ALL_TESTS > + help > + =C2=A0 Enable KUnit tests for RV reactor registration and dispatch. > + =C2=A0 These tests verify the register/unregister lifecycle, duplicate > + =C2=A0 rejection, and that rv_react() correctly invokes callbacks. > + > + =C2=A0 If unsure, say N. > + > =C2=A0config RV_MONITORS_KUNIT_TEST > =C2=A0 tristate "KUnit tests for RV monitors" if !KUNIT_ALL_TESTS > =C2=A0 depends on KUNIT && RV && RV_REACTORS > diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile > index cdbf68c84f5a..c895d81dfdad 100644 > --- a/kernel/trace/rv/Makefile > +++ b/kernel/trace/rv/Makefile > @@ -25,4 +25,5 @@ obj-$(CONFIG_RV_MON_WAKEUP) +=3D monitors/wakeup/wakeup= .o > =C2=A0obj-$(CONFIG_RV_REACTORS) +=3D rv_reactors.o > =C2=A0obj-$(CONFIG_RV_REACT_PRINTK) +=3D reactor_printk.o > =C2=A0obj-$(CONFIG_RV_REACT_PANIC) +=3D reactor_panic.o > +obj-$(CONFIG_RV_REACTORS_KUNIT) +=3D rv_reactors_kunit.o > =C2=A0obj-$(CONFIG_RV_MONITORS_KUNIT_TEST) +=3D rv_monitors_test.o > diff --git a/kernel/trace/rv/rv_reactors_kunit.c > b/kernel/trace/rv/rv_reactors_kunit.c > new file mode 100644 > index 000000000000..32c25dcf0cb6 > --- /dev/null > +++ b/kernel/trace/rv/rv_reactors_kunit.c > @@ -0,0 +1,143 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * KUnit tests for RV reactor registration and dispatch. > + */ > + > +#include > +#include > +#include > +#include > +#include "rv.h" > + > +static struct rv_reactor test_reactor =3D { > + .name =3D "kunit_test_reactor", > + .description =3D "KUnit test reactor", > +}; > + > +/* > + * rv_unregister_reactor() on a reactor that was never registered would > + * list_del() an uninitialized list_head, so track registration and only > + * unregister in the teardown if it is still on the list. > + */ > +static bool test_reactor_registered; I'm not too fond of adding more logic than necessary in the test, but if yo= u really want to keep the dynamic teardown cannot this variable stay somehow = in test-specific memory (test->priv)? That feels to me a bit cleaner, although the reactor and obviously the reac= tors list are still static, so we probably wouldn't gain a huge deal. What do you think? > + > +static int unregister_test_reactor(void) > +{ > + int ret =3D 0; > + > + if (test_reactor_registered) { > + ret =3D rv_unregister_reactor(&test_reactor); > + test_reactor_registered =3D false; rv_unregister_reactor() cannot fail and probably never will (I'm not quite = sure it should return int). But setting test_reactor_registered to false here is assuming it didn't fai= l while the rest of the test doesn't make this assumption. Maybe let's make it void and stop tracking a result that can never change (= and that real reactors already have to ignore). If we do that you may even stop unregistering manually and rely only on the teardown, and perhaps get rid of test_reactor_registered. Even test_register_unregister() would be mostly already covered by the next one. Just throwing in the idea. > + } > + > + return ret; > +} > + > +/* > + * The teardown action guarantees the reactor is unregistered even if a > + * test fails mid-way, so a leftover entry cannot corrupt later tests. > + */ > +static void reactor_teardown(void *arg) > +{ > + unregister_test_reactor(); > +} > + > +static void register_test_reactor(struct kunit *test) > +{ > + KUNIT_ASSERT_EQ(test, rv_register_reactor(&test_reactor), 0); > + test_reactor_registered =3D true; > + KUNIT_ASSERT_EQ(test, > + kunit_add_action_or_reset(test, reactor_teardown, > NULL), 0); > +} > + > +static void test_register_unregister(struct kunit *test) > +{ > + register_test_reactor(test); > + > + KUNIT_EXPECT_EQ(test, unregister_test_reactor(), 0); > +} > + > +static void test_double_register(struct kunit *test) > +{ > + register_test_reactor(test); > + > + KUNIT_EXPECT_EQ(test, rv_register_reactor(&test_reactor), -EINVAL); > + > + KUNIT_EXPECT_EQ(test, unregister_test_reactor(), 0); > +} > + > +static void test_name_too_long(struct kunit *test) > +{ > + /* Name length of MAX_RV_REACTOR_NAME_SIZE (32) must be rejected. */ > + static struct rv_reactor long_reactor =3D { > + .name =3D "kunit_reactor_name_too_long_xxx_", > + }; > + > + KUNIT_ASSERT_EQ(test, (int)strlen(long_reactor.name), > + MAX_RV_REACTOR_NAME_SIZE); You probably want KUNIT_ASSERT_GE, or even better _Static_assert(sizeof(long_name) - 1 >=3D MAX_RV_REACTOR_NAME_SIZE) (you'd need to save the name to a static array first for sizeof() to work a= s expected) > + KUNIT_EXPECT_EQ(test, rv_register_reactor(&long_reactor), -EINVAL); > +} > + > +static struct kunit_case rv_reactor_registration_cases[] =3D { > + KUNIT_CASE(test_register_unregister), > + KUNIT_CASE(test_double_register), > + KUNIT_CASE(test_name_too_long), > + {} > +}; > + > +static struct kunit_suite rv_reactor_registration_suite =3D { > + .name =3D "rv_reactor_registration", > + .test_cases =3D rv_reactor_registration_cases, > +}; > + > +static atomic_t react_call_count; > + > +__printf(1, 0) static void mock_react(const char *msg, va_list args) > +{ > + atomic_inc(&react_call_count); > + /* > + * Hold the CPU for 5 ms so a timer interrupt is likely to fire > + * inside rv_react()'s lockdep context, exercising the LD_WAIT_SPIN > + * constraint.=C2=A0 mdelay() is a calibrated busy-wait with no schedul= er > + * interaction. > + */ > + mdelay(5); > +} > + > +static void test_react_no_callback(struct kunit *test) > +{ > + struct rv_monitor monitor =3D { > + .name =3D "kunit_null_react", > + }; > + > + /* rv_react() must silently return when monitor->react is NULL. */ > + rv_react(&monitor, "no callback"); So what are we testing here? That the kernel doesn't panic? It's fair to ex= pect a silent return, but we cannot really validate that. If that's your intent, maybe specify it better, since, in fact, KUnit canno= t validate this. Something like: "The only possible failure in this test case is a kernel panic" Thanks, Gabriele > +} > + > +static void test_react_callback_invoked(struct kunit *test) > +{ > + struct rv_monitor monitor =3D { > + .name =3D "kunit_dispatch_monitor", > + .react =3D mock_react, > + }; > + > + atomic_set(&react_call_count, 0); > + rv_react(&monitor, "callback invocation test"); > + KUNIT_EXPECT_EQ(test, atomic_read(&react_call_count), 1); > +} > + > +static struct kunit_case rv_react_dispatch_cases[] =3D { > + KUNIT_CASE(test_react_no_callback), > + KUNIT_CASE(test_react_callback_invoked), > + {} > +}; > + > +static struct kunit_suite rv_react_dispatch_suite =3D { > + .name =3D "rv_react_dispatch", > + .test_cases =3D rv_react_dispatch_cases, > +}; > + > +kunit_test_suites(&rv_reactor_registration_suite, &rv_react_dispatch_sui= te); > + > +MODULE_LICENSE("GPL"); > +MODULE_DESCRIPTION("KUnit tests for RV reactor registration and dispatch= ");