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.129.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 67F1C39AD51 for ; Mon, 6 Jul 2026 14:48:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783349341; cv=none; b=l97UGStPg+oMlqq/r9xp1HsTwAFm1yP6NCpqly4Fb0osU/1GLMZv5kOnaTJQjn6ICznaL1N7KbhGotWaGKoW3/1ijfPlaCwE8K1kcZfbzOlkSAMtsFUf7MLuz5GJDKFn0GAa+BqSfjgK2pSetBdgu1cxcR9E6qL7QWf7C0bsgTw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783349341; c=relaxed/simple; bh=TP6HYbGbQXZhPvemQ5UCDwcGzv7Lts5WVPH94vZo3Ho=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=HZb1XLKRmM+/QgM7fD68Rbf+BNSZoo7gREMIUV+S19iScalgtk210KKUl9/W7s/PpnCGuTNBPwvBjdsrF3XRof9VHwnC1pamCFf/UVjvDfeclVSaj0FaxmpIv3vDFLiywBHz39LlF6xtPPwPy0eJ8GranDaV7FgrZ7PA+DmB+no= 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=b2xz+Nem; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=nVGuoJP/; arc=none smtp.client-ip=170.10.129.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="b2xz+Nem"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="nVGuoJP/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783349338; 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=QOMnvqGP4lOoTQG9VISXpd6zj1FzYhNYSBHInVki2Z8=; b=b2xz+NemSLW+4ForJnnLsqq+HgKhgh5s3dDqMrH3TQfo1YaHEijdesacchoTUPiRxIWmyd izMZW0E/VBgKkK8Y/fI8ZZadAImMV0DDYkMdxCOHQ7eo94VjMA++Y54BF8WRSy3PMFKIv3 nT12Fiu48RM5wgpUDTIiFNJtweaZ3mU= 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-125-aEIMT2pqO9G9tuK6jrY1ew-1; Mon, 06 Jul 2026 10:48:56 -0400 X-MC-Unique: aEIMT2pqO9G9tuK6jrY1ew-1 X-Mimecast-MFC-AGG-ID: aEIMT2pqO9G9tuK6jrY1ew_1783349335 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-492488f8583so32838265e9.2 for ; Mon, 06 Jul 2026 07:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1783349335; x=1783954135; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to; bh=QOMnvqGP4lOoTQG9VISXpd6zj1FzYhNYSBHInVki2Z8=; b=nVGuoJP/GOkRENU8aGGFqmNckFJIrE1OxtXJeHd2iG2H9CpcF7W9r5imHzgVMObAG9 +ZQmnAvxqcAJXPS+ip6Fpmhi0mu+eDfKgYFK72uF5V/4VQ9ZG8G7B50ax3DqlZ3vxJ8o xQgPbwDR2i9AUtz1Rx3AzYiMEvoIZ67avVYkGNcbMM/VR/H/BqXfz+qmhO4N8pjAANrR CDjsFwNecWhDm8GfatrW83NmBqiVAzJtvXRmfpvvvMRoPJ3V3kALyPRoyMZVdROgS6T1 ks0LXx1qxiYgU4qppa+xNcg1GzAyBNpH8nXr8AJkSUhUevHRBNNvXq/YzCl0hh0wMuv0 NeMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783349335; x=1783954135; h=mime-version:user-agent:content-transfer-encoding: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; bh=QOMnvqGP4lOoTQG9VISXpd6zj1FzYhNYSBHInVki2Z8=; b=Jk4MsrwdX/1nDGjuBUhYi/fuY1vB9t1jK3tgXjPDLV1WHaaV0YAmBs5H8JDOmjIQWp VSvvcOQayCPmabnrDWxagsQzyb53zTy81ekaFQCWb0gleTHCMnjy1ulj2z/XXqXH3jHt LmaqwZExXnWsxXR0DmtlKyOUzwvHZU6yKr+ZwSQHNRd3r7ErAgRE1aYNVeHPG3d2jVIF jaeU0FBRG3tZ2mYA1DpiG7NkWbWLGba3Hc0SjRmMcQgtEUG/VKqt3vp57pPynj5ZvV6p ZECch69g3EqXYB1sbCZ+Hlxe4m3Yppry5av4dMTu/yuBZ1sNvmq3mfE3V5ZFsK2av4VL LRbA== X-Forwarded-Encrypted: i=1; AHgh+Rq0W3+0aaCBgaf8mxUnmaVM7iZKGc0vK9ovcim1jvMukSUEKyoIH8HqV7K3wa115hgh7DJq4/WL/EY1LVg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/BFMG/C2YyWPjzta261Sm42E1pPB314j4LwWeOoaOTNtNjBif /4CTGxuHJwkJujoEbkXvqyTusXhUKLDm1V1KiV+B9yGbb5iu/A01yhrRfq1MbXowrxllA46ySG9 VNfE4+dTWKD1ChUHkQ+2NiOsUDWDOBQYFB+gfA5p/Kqs4adytQLvHXIkCauUe5U0JwQ== X-Gm-Gg: AfdE7clKtRJYtjhdLGHEBZSrbeMtwvFfpcmZopCK+oKmskD63aRlOgqvW/nkWoMi7US md/1Y7TsTVF2fCRXPP9h5J6A+iE7SFiClQ/9FsGABLciXnX32CPaS8CfsjkKmqiRPwSHr5za6OU UIaiwdYuYwLQTJjHgA0fKgKUh+1t44uVx9BCA5hsgl1KcfiCuqm8qIgJCmbNYF3GA6u3ph1wgyz l9vAnndEJkEzQjk/H5L2b9dvGlj7pzjru8kJYQk4+Toxk4iksuLkNzZ5A4ex4inKg37L9atl5K2 oJE1mRTZNT68JRtMmNXvlAbxwabJvmqYpExf8iFfp+u7vTpF1LR6r1GbcdRFLD7qRHGHqULwSmr 5/N2B0NaAZSb5aKraM4Cq4WISbJI2jWa0M1GyxXtlr/Rmz/w1CwBkeUr9Jpf7PDbRykMOYFlN57 FpZ2Qe X-Received: by 2002:a05:600c:6286:b0:493:c3e4:c9c0 with SMTP id 5b1f17b1804b1-493df092ad0mr10095495e9.24.1783349334707; Mon, 06 Jul 2026 07:48:54 -0700 (PDT) X-Received: by 2002:a05:600c:6286:b0:493:c3e4:c9c0 with SMTP id 5b1f17b1804b1-493df092ad0mr10095145e9.24.1783349334213; Mon, 06 Jul 2026 07:48:54 -0700 (PDT) Received: from gmonaco-thinkpadt14gen3.rmtit.csb (212-8-243-115.hosted-by-worldstream.net. [212.8.243.115]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493c637bc21sm673339825e9.7.2026.07.06.07.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 07:48:53 -0700 (PDT) Message-ID: <0575d651270c6ee2d10571c2e7ecb537398885e5.camel@redhat.com> Subject: Re: [PATCH 3/3] rv/reactors: add KUnit tests for reactor_panic From: Gabriele Monaco To: wen.yang@linux.dev Cc: Nam Cao , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 06 Jul 2026 16:48:52 +0200 In-Reply-To: <810f587d63c84b64067f990299be02b88f5d8106.1781541556.git.wen.yang@linux.dev> References: <810f587d63c84b64067f990299be02b88f5d8106.1781541556.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 Tue, 2026-06-16 at 00:44 +0800, wen.yang@linux.dev wrote: > From: Wen Yang >=20 > Add KUnit tests for the panic reactor covering: > - Reactor registration and unregistration lifecycle > - Panic notifier chain reachability >=20 > The real rv_panic_reaction() calls vpanic(), which is __noreturn and > halts the system. KUnit cannot test across that boundary. Instead, the > test drives atomic_notifier_call_chain(&panic_notifier_list, ...) directl= y > with a high-priority mock notifier that returns NOTIFY_STOP, verifying > that the panic notification propagates without triggering real handlers > (kdump, watchdog, reboot). >=20 > The mock notifier busy-waits to simulate real handler execution time > (e.g., crash_save_vmcoreinfo, emergency_restart preamble) under the > panic context constraints. >=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=C2=A0 |=C2=A0 10 +++ > =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 |=C2=A0=C2=A0 1 + > =C2=A0kernel/trace/rv/reactor_panic_kunit.c | 106 +++++++++++++++++++++++= +++ > =C2=A03 files changed, 117 insertions(+) > =C2=A0create mode 100644 kernel/trace/rv/reactor_panic_kunit.c >=20 > diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig > index ff47895c897f..6c6c43c5f86c 100644 > --- a/kernel/trace/rv/Kconfig > +++ b/kernel/trace/rv/Kconfig > @@ -121,3 +121,13 @@ config RV_REACT_PANIC > =C2=A0 help > =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. > + > +config RV_REACT_PANIC_KUNIT > + bool "KUnit tests for reactor_panic" if !KUNIT_ALL_TESTS > + depends on RV_REACT_PANIC && KUNIT > + default KUNIT_ALL_TESTS > + help > + =C2=A0 This builds KUnit tests for the panic reactor. These are only > + =C2=A0 for development and testing, not for regular kernel use cases. > + > + =C2=A0 If unsure, say N. > diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile > index ef0a2dcb927c..2ebfe5e5068c 100644 > --- a/kernel/trace/rv/Makefile > +++ b/kernel/trace/rv/Makefile > @@ -25,3 +25,4 @@ obj-$(CONFIG_RV_REACTORS) +=3D rv_reactors.o > =C2=A0obj-$(CONFIG_RV_REACT_PRINTK) +=3D reactor_printk.o > =C2=A0obj-$(CONFIG_RV_REACT_PRINTK_KUNIT) +=3D reactor_printk_kunit.o > =C2=A0obj-$(CONFIG_RV_REACT_PANIC) +=3D reactor_panic.o > +obj-$(CONFIG_RV_REACT_PANIC_KUNIT) +=3D reactor_panic_kunit.o > diff --git a/kernel/trace/rv/reactor_panic_kunit.c > b/kernel/trace/rv/reactor_panic_kunit.c > new file mode 100644 > index 000000000000..f9a09ae7aaad > --- /dev/null > +++ b/kernel/trace/rv/reactor_panic_kunit.c > @@ -0,0 +1,106 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * KUnit tests for reactor_panic > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* Simulated execution time for mock panic notifier (nanoseconds). */ > +#define RV_PANIC_NOTIFIER_EXEC_NS 2000000ULL > + > +/* Test state */ > +static struct { > + bool notifier_called; > +} panic_test_state; A struct isn't really needed I guess, but good to have a way to test there = was a call. > + > +/* > + * Mock panic notifier callback. > + * > + * Runs at INT_MAX priority and returns NOTIFY_STOP to prevent real pani= c > + * handlers (kdump, watchdog) from executing during the test.=C2=A0 Busy= -waits > + * RV_PANIC_NOTIFIER_EXEC_NS to simulate a real handler's execution time= . > + */ > +static int mock_panic_notifier_fn(struct notifier_block *nb, > + =C2=A0 unsigned long action, void *data) > +{ > + char *msg =3D data; > + u64 start =3D sched_clock(); > + > + panic_test_state.notifier_called =3D true; > + pr_emerg("KUnit: reactor_panic test intercepted panic notifier: > %s\n", > + msg ? msg : "(no message)"); Since we cannot panic(), do we really need to test yet another mock reactor= ? What if you put the notifier_called in the other test and drop this test altogether? We can simulate what panic() does right now, but it isn't too representativ= e if this ever changes. Also it's good to make this reactor test buildable as a module. Currently s= ome functions aren't exported, feel free to just EXPORT_SYMBOL_GPL() them. Ther= e is no need not to have modular reactors, just nobody did it before. Thanks, Gabriele > + > + while (sched_clock() - start < RV_PANIC_NOTIFIER_EXEC_NS) > + cpu_relax(); > + > + return NOTIFY_STOP; > +} > + > +static struct notifier_block mock_panic_nb =3D { > + .notifier_call =3D mock_panic_notifier_fn, > + .priority =3D INT_MAX, > +}; > + > +static struct rv_reactor mock_panic_reactor =3D { > + .name =3D "test_panic", > + .description =3D "test panic reactor", > +}; > + > +static int reactor_panic_kunit_init(struct kunit *test) > +{ > + panic_test_state.notifier_called =3D false; > + return 0; > +} > + > +/* Test 1: register and unregister reactor */ > +static void test_panic_register_unregister(struct kunit *test) > +{ > + int ret; > + > + ret =3D rv_register_reactor(&mock_panic_reactor); > + KUNIT_EXPECT_EQ(test, ret, 0); > + KUNIT_EXPECT_STREQ(test, mock_panic_reactor.name, "test_panic"); > + > + rv_unregister_reactor(&mock_panic_reactor); > +} > + > +/* > + * Test 2: panic notifier chain is reachable. > + * > + * vpanic() calls atomic_notifier_call_chain(&panic_notifier_list, ...). > + * Drive the chain directly to verify panic notifiers receive the > notification =E2=80=94 > + * the observable side-effect of reactor_panic without halting the syste= m. > + */ > +static void test_panic_notifier_called(struct kunit *test) > +{ > + atomic_notifier_chain_register(&panic_notifier_list, &mock_panic_nb); > + atomic_notifier_call_chain(&panic_notifier_list, 0, > + =C2=A0=C2=A0 "panic violation message"); > + atomic_notifier_chain_unregister(&panic_notifier_list, > &mock_panic_nb); > + > + KUNIT_EXPECT_TRUE(test, panic_test_state.notifier_called); > +} > + > +static struct kunit_case reactor_panic_kunit_cases[] =3D { > + KUNIT_CASE(test_panic_register_unregister), > + KUNIT_CASE(test_panic_notifier_called), > + {} > +}; > + > +static struct kunit_suite reactor_panic_kunit_suite =3D { > + .name =3D "rv_reactor_panic", > + .init =3D reactor_panic_kunit_init, > + .test_cases =3D reactor_panic_kunit_cases, > +}; > + > +kunit_test_suite(reactor_panic_kunit_suite); > + > +MODULE_LICENSE("GPL"); > +MODULE_DESCRIPTION("KUnit tests for reactor_panic");