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 B1EBD3C3C07 for ; Mon, 17 Aug 2026 11:05:16 +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=1786964718; cv=none; b=EVgTEURl+LNpQo2r7Rtxv7s3FpROb1v2ZvlJXq2rppqTeIdm/Of7L5Sj0GZqM8/eKi9VfQOwuTAkbHhvrRRtr/bTK+1RbfifqHpOMucxCQfiE0FHuLaBk2EHwce4huqT+Eyl7lYTUoRNNkYnlVO/9eanmsXtICKQg2FICS1IzI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786964718; c=relaxed/simple; bh=yeunoKxhrqQwRKRlxVOcQjJLiJuCO79tS5E54W+eypE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=t+r0vhq/W9oRe9EUAGpNokWPUbZDizxRu3lWfh/q60/mIOU4VR9KS6AaiNiyjZSbIGuXxb6sLtR/7orZER+Yc+2/1M3BC12HfZjPUFWrUyKHIk7O/jv8sR75jK5lUShAaJ0yxxc4l+Lt9wMwW5SOAS6t1W/8ZmgHFkJGt0Kwz5s= 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=DHfWRHBr; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=l23Sjv19; 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="DHfWRHBr"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="l23Sjv19" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786964715; 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=bFJHtQEQTjEN89h+WkE0r6/DImgMIWSTd0t59oRhvCU=; b=DHfWRHBrHxZ+FVf4Aun6JkLLCQfAaMiS7u4c6bHKn/dCAG/fUPWIJs8Tuwr0wtQYtU3zh/ vUC3d+s/GOCAtg9j2WLVjgQ/fpPQ+GZLMNLBKjOjCdTGa5CvCJ2zLu34ZhY1OmDEpRHld4 lXcIl+asX3zte3lT+uYM5gmxUifHEb4= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-470-pgL8z9hMMQe97PQHDNKaEg-1; Mon, 17 Aug 2026 07:05:14 -0400 X-MC-Unique: pgL8z9hMMQe97PQHDNKaEg-1 X-Mimecast-MFC-AGG-ID: pgL8z9hMMQe97PQHDNKaEg_1786964713 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-47f6e8b5996so3008535f8f.2 for ; Mon, 17 Aug 2026 04:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1786964713; x=1787569513; 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=bFJHtQEQTjEN89h+WkE0r6/DImgMIWSTd0t59oRhvCU=; b=l23Sjv19QF+vOJfzUgNDXD5RZcicDt+ohlr5pDOH4EkqDSQITnGvsBHk9HgCrsBckE Wpp1FbwdnS7LbJgQBiBd6U1sP47jJMFui/d+neLLoYE7sp38mSnLxiCaI1UZ+c/HCdGP XeU1//UOPTh1by2ROXRZ26tACsCzt1kch29Q6bAnKtTwhIVuUeHQzZjeZs1r47Ro/bdK XRYHYLfCCVx7/bNevTYczcGZXg1uL/+eCpn+AcI87BlsBMqEDEaZHsHyXkKavKSC7t0S YpVclbap4ZR6cTU+CIHLAdoAl+A3u3pzsVNNlZLz8X/FcbWhafRjI6cxMtfDkiNByhCB Rl9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786964713; x=1787569513; 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=bFJHtQEQTjEN89h+WkE0r6/DImgMIWSTd0t59oRhvCU=; b=YaRFGxWYpAd6Vbxw1ZtWClLjDVvP3Xdt5enPGnJn0mBugTefftHslQhBanVhwR8MAY yDFQWupktl5oo2TPGvCLW+wV8TIy6pDkzhzyajRImf0r4c4SEx6/iGtc4LQOr+5Taj5o Tvk0Nu2up9sAZyxrfuO34hugv/409yHvFH1bnkkWueL18mNWztt9yDdSHLA5K9HUshbf KfaRhi6eiE4xs6uOQCt0CV2Fwf7K7NTjh2zTH0qwY/tUx86DXsbmKIonzJLpaUtyujR2 C1R222khJ5gFSuwmvWeWtkFgY+nNaTHp/MyeF9g72PnxN2TFQl/uZZIb+WSuwR6gnUBF DvOA== X-Forwarded-Encrypted: i=1; AHgh+Rr8sC7CCvq6Tw03CWGszpuLftlq4EpmylBSZjrMDzLMaE5yROspa/+YMZ8dmoQJN3pvcDnzS9os7NPjbkY=@vger.kernel.org X-Gm-Message-State: AOJu0YyxJqOKyF/2oVQmlfIRggpXFUxmRa9Aj7YJq0BtJmC8XT3VTQMn 6m2dMKrnM1nFwDGsP2Sy6RI82hNkkYpxSEbqKNomSCRW2kI0xvDSEu/uwaZpnvVjj2GJ6PaYLAc Jd6PiWHxJ6QaPlFBuzctb1Dk0SqtOSc02RODyPIfeLNh+h7oB3pso+VBf38VJuFlIsrfW7bYUs/ tgnCg= X-Gm-Gg: AR+sD10GhKyT/X2F2FmGi7o/indo7kKpebl8ku+9A6W9tXWGdAvJuFayVJK24iomAkh +jPIPh0pGadZ8tE/2f2RoH5i6dp15aN1E5MA40YcPYGspu7PZc1InV14/jr+jSsRQt+Pbp8i1jW yxEDAoPdrf0S9sNiPyKGbzL3X7AFYpIZnGiH8WPtLwqy3GzhBIVo02wGYn6hIix3I5rmOnZfrL8 6aeXzCXusXHvq974HnIOyIdHvbq5XBg2o44gFiyArXrGu1HDMXS6ID7sUf4HywJQ3lpwC42DjyA RVCbyoorsyRfLiZJiAJwg5jSPkFIBK1IXtOgC9xLIp4dUh9ua2Mcl/gEmDPTSJlH9i1Vwb3b2Eb QtQndq6bBSxDJRDro6/rXGDoRcvRGZM07gCrFaPruPGbCfaTc8nPorCbPiJJj0RSN18+D8w== X-Received: by 2002:a05:600c:3151:b0:499:51f0:a9b2 with SMTP id 5b1f17b1804b1-499880b4335mr339156405e9.1.1786964713032; Mon, 17 Aug 2026 04:05:13 -0700 (PDT) X-Received: by 2002:a05:600c:3151:b0:499:51f0:a9b2 with SMTP id 5b1f17b1804b1-499880b4335mr339155485e9.1.1786964712658; Mon, 17 Aug 2026 04:05:12 -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 ffacd0b85a97d-482a5a3b51asm3138914f8f.11.2026.08.17.04.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2026 04:05:12 -0700 (PDT) Message-ID: <0e0641cfd06ee56488305ffdb410ab27706f202b.camel@redhat.com> Subject: Re: [PATCH v3 4/4] rv/reactors: add KUnit tests for reactor registration and dispatch From: Gabriele Monaco To: Nam Cao , wen.yang@linux.dev Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 17 Aug 2026 13:05:10 +0200 In-Reply-To: <87wltpnhne.fsf@yellow.woof> References: <2b91af9f6d045f7fdb8620ef5c66c3b3e189833b.1786294920.git.wen.yang@linux.dev> <87wltpnhne.fsf@yellow.woof> 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-17 at 12:52 +0200, Nam Cao wrote: > wen.yang@linux.dev=C2=A0writes: > > +/* > > + * Use a fixed-size array so sizeof() gives the exact byte count at > > + * compile time. > > + */ >=20 > There is no need for a comment. This is obvious from the code itself. >=20 > > +static const char long_reactor_name[] =3D "kunit_reactor_name_too_long= _xxx_"; > > +_Static_assert(sizeof(long_reactor_name) - 1 >=3D MAX_RV_REACTOR_NAME_= SIZE, > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "long_reactor_name must be at le= ast MAX_RV_REACTOR_NAME_SIZE > > chars"); > > + > > +static void test_name_too_long(struct kunit *test) > > +{ > > + static struct rv_reactor long_reactor =3D { > > + .name =3D long_reactor_name, > > + }; > > + > > + KUNIT_EXPECT_EQ(test, rv_register_reactor(&long_reactor), -EINVAL); > > +} > > + > > +static struct kunit_case rv_reactor_registration_cases[] =3D { > > + KUNIT_CASE(test_double_register), > > + KUNIT_CASE(test_name_too_long), > > + {} > > +}; >=20 > I am not sure about the usefulness of these test cases. > rv_register_reactor() is not an user API that we have to prepare > for corner case usage. We can expect its users to be sane since the > users are us. >=20 > But well, if Gabriele wants to keep them.. >=20 That's right, it can be a bit of an overkill, but I'm thinking one day reac= tors could come from (out-of-tree) kernel modules, it wouldn't hurt to have this= path tested, especially if it doesn't require much effort. > > + > > +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; >=20 > Do we really need atomic_t? Does int work? Missed that, yes, it should work just fine since KUnit runs in a single thr= ead. >=20 > > + > > +__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 > > scheduler > > + * interaction. > > + */ >=20 > The comment above mdelay()'s definition already explains what it does. >=20 > > + mdelay(5); > > +} > > + > > +static void test_react_no_callback(struct kunit *test) > > +{ > > + struct rv_monitor monitor =3D { > > + .name =3D "kunit_null_react", > > + }; > > + > > + atomic_set(&react_call_count, 0); > > + rv_react(&monitor, "no callback"); > > + > > + /* > > + * The only possible failure in this test case is a kernel panic. > > + * NULL react guard: callback must NOT have been invoked > > + */ >=20 > Obvious comment. >=20 > > + KUNIT_EXPECT_EQ(test, atomic_read(&react_call_count), 0); > > +} > > + > > +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); > > +} >=20 > So the test calls rv_react(), and validates that the reactor is called? > Honestly I am not sure how useful that is. Especially since Gabriele > already made the selftest which validates that the reactor is invoked. >From what I understood, the value in this test suite isn't really about the assertions (especially in test_react_no_callback). It triggers cases that s= hould not produce a splat (panic/lockdep) and a pass should consider that too. This makes them not quite pure KUnit, but again, I think it doesn't hurt to= have this kind of test since KUnit output is in dmesg anyway, so a splat would h= ardly slip. What do you think? Gabriele