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 8CBF43655C4 for ; Wed, 22 Jul 2026 14:42:39 +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=1784731362; cv=none; b=tM2Ca6vV/rNerziz8IT4ZsXUYJ6q9N6bwlnTTBUfV+nHT2yojHEI29gAXf2XDT8esbiyRk2EpkZlyo8qqTKoKmVs5Y7xKKqV3t7He/XQ65mi71prgEQbzGJJlh/1umB1PtRGYW+GgAu2c4KAi1aOztZDtMFFQO8zi1mf4OzN/AE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784731362; c=relaxed/simple; bh=SwFR71ZbSXUfh/XNxVdjfzcKQN1PvoTgWdIat/qBmws=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=I8yWdI2NH/+7+ZU7FD+rOsTwxAg/aV8x+Qg/7QrGBTpXk6dXg8Cj5AM5r562talTBLmZq7cEyN9MhAnjOtwyIPA3jDqw++BcqrBHUuyTaoFAzBvotlLn+F7P5VhpiM2uqGJcmd+2u+AwjD+U3ya6k24ySdJc78tsbMJCIT6pXVI= 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=Wgv6F46e; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Jf8pceui; 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="Wgv6F46e"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Jf8pceui" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784731358; 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=fv7S9xnzeNkgckKPxKGiukDkgSkYwdABYq3Cxat9xRM=; b=Wgv6F46e0M3hIPRLPSbQF+cMN68XDjtm1oSzIipfrJycz1cgqF50o/gIUDltMnQZEUNnxv m85NNAxO2rcYMdJb8tT1A7D4wb6xhCGyL3/LYg6uCVWpPwxi0rV1R+isP5M4JBDOFiRSrE LBTkbQKMJjMD7VqNBT4mzOIsZzOLvCI= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-qvoQ16cqMleklP9fTAUenA-1; Wed, 22 Jul 2026 10:42:37 -0400 X-MC-Unique: qvoQ16cqMleklP9fTAUenA-1 X-Mimecast-MFC-AGG-ID: qvoQ16cqMleklP9fTAUenA_1784731356 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-c15e57a7f8cso1269048066b.1 for ; Wed, 22 Jul 2026 07:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784731356; x=1785336156; 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=fv7S9xnzeNkgckKPxKGiukDkgSkYwdABYq3Cxat9xRM=; b=Jf8pceuiwIC4lOX4JjQZ/sqYN6Tbtk0ol/dEZGxB6jbh9QbLJSd560S2jY1lGakFQ5 M6d9Z5ZlISAymcQ5GYCzf2nJyL/D/YLIg6fieLlOVFSA/iS/T4PxVbtB8w0DuoifPN7G +NllNu8+iabgxqHKGIWkarFA0S9lFeD8ALdyc/pzyzukq15QjAd8eAKyBswE9XTDKcGc +41b/H3GHvgrsfRrrpbEclRq+1Pu27YgBPBB+8ftgVM/a+tAZ6Gf3TXx1Lu4qqvcKwUI CuvIzuznBRFPohnEbJvdSBo0jMhbFnvpcU189zop+kNFDiWQzqscqFVIWVoeKFY1Z3N4 t9eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784731356; x=1785336156; 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=fv7S9xnzeNkgckKPxKGiukDkgSkYwdABYq3Cxat9xRM=; b=S9qStYCB3Ewdx7/tUFWsRc9pAcr3xvL3BvkQHsPK6t+vsOZWepXiSQuPYo7FIyz5Tg isVWQg8/Rbv/fFBNMzp3DPtvaBmacIZcolAOk5Fl66Kw/VUlbzzyjwY1rAXcBivRgbbX Ak69YmmqLQXXJ85AwQxp4loDfOkKHN4592FR1cJTncra6iZP9Ac+10TwIvt7W3dP1fMG 53EpjzQkfQLZl6fCZJSLEsLZdZnSjWsJWSmg/pqBShJ6PSXoF22NQWbIlB1n0mZBowOo HPonGG+qdt2thDgl1GSZo3ZIfhrBZ5LpcEEe9PusUvBjHNF1OjySK6tJz8hAvL89HxHE vLDQ== X-Forwarded-Encrypted: i=1; AHgh+RpqowHCHO5RO/j4s0atO1SNoPvYFCSb0FV0zJbOaysJGByP+TFRHrnoWkg+kx4mI1y/XCJiyUgq04lj6iQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxFvQaOheQAeXOSNNvjpaD7qgsL3RrDGMr/7xhb5DR2MTrvXJgK Khc/HFGS3ejbq1hzVzPugGJAFua3Pn+QXRym/Fg74mndLggjsjyD8tyV2+B4bOiKAEt+x8ehWHx wFz0el56e5l8jo2HLwOdaGc+Z2HYGPC5r0AUd6TzuS4Yi/1hkh/TCJgDl86V8SyknoA== X-Gm-Gg: AR+sD11TiBOuOTZvYYe7Wh6Lit08tV246ITZ1ed/WpFc0uEW9nuzo/7qQsKNaTjtaJu VzcEKvxihtPRSxTuBw9umzDA2jGY8vdCknR1rVV5fFBRQqwDzaMnCqCM9LW59MVGAr8vnKhSIy5 XF9Q1oWCCe/1pIIbbZaKJwnfRAV3DXtUFPxYkbeiCoJbFAwrXWbTtPMonjQaEhJ/xA0RrXeEKqp hBJYEDAhfOJco0N4WquNPQXRqBCvUALEovH89GDVC10iFhXuFVDa4Dn3b0joCeIyx2uTWv0L3Ei PzWS++jbIX+VoQX4Ofrg0ZS6eJwo6xeyml5OEtqGB0WhrKiMr6ZH5VZHNOskUBUoGj9F1LywdDh oYLsZp9OSeW2opn/2AgMBMvI49oeh2g8cEM7xWmkKYA5dh8SO32cT1nzRBtqcuUhU53LNUA== X-Received: by 2002:a17:907:c0b:b0:c16:e54:9cbb with SMTP id a640c23a62f3a-c16b46fda3bmr1113247166b.25.1784731355871; Wed, 22 Jul 2026 07:42:35 -0700 (PDT) X-Received: by 2002:a17:907:c0b:b0:c16:e54:9cbb with SMTP id a640c23a62f3a-c16b46fda3bmr1113245266b.25.1784731355431; Wed, 22 Jul 2026 07:42:35 -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 a640c23a62f3a-c1c32ac936dsm122446266b.22.2026.07.22.07.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 07:42:35 -0700 (PDT) Message-ID: <7dbb7caf3364c3efe29264d51b208097df10c327.camel@redhat.com> Subject: Re: [PATCH v4 7/8] rv/tlob: add KUnit tests for the tlob monitor From: Gabriele Monaco To: wen.yang@linux.dev Cc: Nam Cao , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 22 Jul 2026 16:42:33 +0200 In-Reply-To: <18ab97e8a248e55dfeef5daa49daa407bf58dc56.1783524627.git.wen.yang@linux.dev> References: <18ab97e8a248e55dfeef5daa49daa407bf58dc56.1783524627.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 Wed, 2026-07-08 at 23:38 +0800, wen.yang@linux.dev wrote: > From: Wen Yang > ... > +++ b/kernel/trace/rv/monitors/tlob/.kunitconfig > @@ -0,0 +1,8 @@ > +CONFIG_FTRACE=3Dy > +CONFIG_HIGH_RES_TIMERS=3Dy > +CONFIG_KUNIT=3Dy > +CONFIG_MODULES=3Dy > +CONFIG_RV=3Dy > +CONFIG_RV_MON_TLOB=3Dy > +CONFIG_TLOB_KUNIT_TEST=3Dy > +CONFIG_UPROBES=3Dy Let's perhaps drop here what isn't a (mostly) direct dependency and make it slimmer? Others are requirements of those anyway (and if they stop being so, they aren't required for the test either). CONFIG_KUNIT=3Dy CONFIG_UPROBES=3Dy CONFIG_RV=3Dy CONFIG_RV_MON_TLOB=3Dy CONFIG_TLOB_KUNIT_TEST=3Dy > diff --git a/kernel/trace/rv/monitors/tlob/Kconfig > b/kernel/trace/rv/monitors/tlob/Kconfig > index aa43382073d2..402ef2e5c076 100644 > --- a/kernel/trace/rv/monitors/tlob/Kconfig > +++ b/kernel/trace/rv/monitors/tlob/Kconfig > @@ -10,3 +10,10 @@ config RV_MON_TLOB > =C2=A0 =C2=A0 monitor.=C2=A0 tlob tracks per-task elapsed wall-clock time= across a > =C2=A0 =C2=A0 user-delimited code section and emits error_env_tlob when t= he > =C2=A0 =C2=A0 elapsed time exceeds a configurable per-invocation budget. > + > +config TLOB_KUNIT_TEST > + tristate "KUnit tests for tlob monitor" if !KUNIT_ALL_TESTS > + depends on RV_MON_TLOB && KUNIT > + default KUNIT_ALL_TESTS > + help > + =C2=A0 Enable KUnit unit tests for the tlob RV monitor. > diff --git a/kernel/trace/rv/monitors/tlob/tlob.c > b/kernel/trace/rv/monitors/tlob/tlob.c > index b45e84195131..a6f9c371646c 100644 > --- a/kernel/trace/rv/monitors/tlob/tlob.c > +++ b/kernel/trace/rv/monitors/tlob/tlob.c > @@ -708,7 +708,7 @@ static ssize_t tlob_monitor_read(struct file *file, > =C2=A0 * PATH may contain ':'; the last ':' separates path from offset. > =C2=A0 * Returns 0, -EINVAL, or -ERANGE. > =C2=A0 */ > -static int tlob_parse_uprobe_line(char *buf, u64 *thr_out, > +VISIBLE_IF_KUNIT int tlob_parse_uprobe_line(char *buf, u64 *thr_out, > =C2=A0 =C2=A0 char **path_out, > =C2=A0 =C2=A0 loff_t *start_out, loff_t *stop_out) > =C2=A0{ > @@ -782,6 +782,7 @@ static int tlob_parse_uprobe_line(char *buf, u64 *thr= _out, > =C2=A0 *stop_out=C2=A0 =3D (loff_t)stop_val; > =C2=A0 return 0; > =C2=A0} > +EXPORT_SYMBOL_IF_KUNIT(tlob_parse_uprobe_line); > =C2=A0 > =C2=A0/* > =C2=A0 * Parse "-PATH:OFFSET_START" (ftrace uprobe_events removal convent= ion). > @@ -810,8 +811,9 @@ VISIBLE_IF_KUNIT int tlob_parse_remove_line(char *buf= , > char **path_out, > =C2=A0 *start_out =3D (loff_t)off; > =C2=A0 return 0; > =C2=A0} > +EXPORT_SYMBOL_IF_KUNIT(tlob_parse_remove_line); > =C2=A0 > -VISIBLE_IF_KUNIT int tlob_create_or_delete_uprobe(char *buf) > +static int tlob_create_or_delete_uprobe(char *buf) That's a nit, but probably all the VISIBLE_IF_KUNIT / EXPORT_SYMBOL_IF_KUNIT should be added by this patch alone. And definitely tlob_create_or_delete_uprobe shouldn't have it in the earlier patch just for it to be removed here. > =C2=A0{ > =C2=A0 loff_t offset_start, offset_stop; > =C2=A0 u64 threshold_ns; > @@ -836,7 +838,6 @@ VISIBLE_IF_KUNIT int tlob_create_or_delete_uprobe(cha= r > *buf) > =C2=A0 mutex_unlock(&tlob_uprobe_mutex); > =C2=A0 return ret; > =C2=A0} > -EXPORT_SYMBOL_IF_KUNIT(tlob_create_or_delete_uprobe); > =C2=A0 > =C2=A0static ssize_t tlob_monitor_write(struct file *file, > =C2=A0 =C2=A0 const char __user *ubuf, > diff --git a/kernel/trace/rv/monitors/tlob/tlob.h > b/kernel/trace/rv/monitors/tlob/tlob.h > index fceeba748c85..15bdf3b7fade 100644 > --- a/kernel/trace/rv/monitors/tlob/tlob.h > +++ b/kernel/trace/rv/monitors/tlob/tlob.h > @@ -145,7 +145,9 @@ int tlob_start_task(struct task_struct *task, u64 > threshold_ns); > =C2=A0int tlob_stop_task(struct task_struct *task); > =C2=A0 > =C2=A0#if IS_ENABLED(CONFIG_KUNIT) Any reason not to use IS_ENABLED(CONFIG_TLOB_KUNIT_TEST) ? > -int tlob_create_or_delete_uprobe(char *buf); > +int tlob_parse_uprobe_line(char *buf, u64 *thr_out, char **path_out, > + =C2=A0=C2=A0 loff_t *start_out, loff_t *stop_out); > +int tlob_parse_remove_line(char *buf, char **path_out, loff_t *start_out= ); Same here, those can all be exported in this patch, no need to mention any KUNIT stuff earlier. > =C2=A0#endif /* CONFIG_KUNIT */ > =C2=A0 > =C2=A0#endif /* _RV_TLOB_H */ > diff --git a/kernel/trace/rv/monitors/tlob/tlob_kunit.c > b/kernel/trace/rv/monitors/tlob/tlob_kunit.c > new file mode 100644 > index 000000000000..7448f3fab959 > --- /dev/null > +++ b/kernel/trace/rv/monitors/tlob/tlob_kunit.c > @@ -0,0 +1,139 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * KUnit tests for the tlob RV monitor. > + * > + */ Besides the minor nits above, tests look good. Thanks, Gabriele > +#include > + > +#include "tlob.h" > + > +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); > + > +/* Valid "p PATH:START STOP threshold=3DNS" lines. */ > +static const char * const tlob_parse_valid[] =3D { > + "p /usr/bin/myapp:4768 4848 threshold=3D5000000", > + "p /usr/bin/myapp:0x12a0 0x12f0 threshold=3D10000000", > + "p /opt/my:app/bin:0x100 0x200 threshold=3D1000000", > +}; > + > +/* Malformed "p ..." lines that must be rejected with -EINVAL. */ > +static const char * const tlob_parse_invalid[] =3D { > + "p :0x100 0x200 threshold=3D5000", > + "p /usr/bin/myapp:0x100 threshold=3D5000", > + "p /usr/bin/myapp:-1 0x200 threshold=3D5000", > + "p /usr/bin/myapp:0x100 -1 threshold=3D5000000", /* negative stop > offset */ > + "p /usr/bin/myapp:0x100 0x200", > + "p /usr/bin/myapp:0x100 0x100 threshold=3D5000", > +}; > + > +/* threshold_ns out of valid range =3D> -ERANGE. */ > +static const char * const tlob_parse_out_of_range[] =3D { > + "p /usr/bin/myapp:0x100 0x200 threshold=3D0", > + "p /usr/bin/myapp:0x100 0x200 threshold=3D999", > + "p /usr/bin/myapp:0x100 0x200 threshold=3D3600000000001", > +}; > + > +/* Valid "-PATH:OFFSET_START" remove lines. */ > +static const char * const tlob_remove_valid[] =3D { > + "-/usr/bin/myapp:0x100", > + "-/opt/my:app/bin:0x200", > +}; > + > +/* Malformed remove lines that must be rejected with -EINVAL. */ > +static const char * const tlob_remove_invalid[] =3D { > + "-usr/bin/myapp:0x100", > + "-/usr/bin/myapp", > + "-/:0x100", > + "-/usr/bin/myapp:-1", /* negative offset */ > + "-/usr/bin/myapp:abc", > +}; > + > +static void tlob_parse_valid_accepted(struct kunit *test) > +{ > + u64 thr; > + char *path; > + loff_t start, stop; > + char buf[128]; > + int i; > + > + for (i =3D 0; i < ARRAY_SIZE(tlob_parse_valid); i++) { > + strscpy(buf, tlob_parse_valid[i], sizeof(buf)); > + KUNIT_EXPECT_EQ(test, tlob_parse_uprobe_line(buf, &thr, > &path, > + =C2=A0=C2=A0=C2=A0=C2=A0 &start, &stop), > 0); > + } > +} > + > +static void tlob_parse_invalid_rejected(struct kunit *test) > +{ > + u64 thr; > + char *path; > + loff_t start, stop; > + char buf[128]; > + int i; > + > + for (i =3D 0; i < ARRAY_SIZE(tlob_parse_invalid); i++) { > + strscpy(buf, tlob_parse_invalid[i], sizeof(buf)); > + KUNIT_EXPECT_EQ(test, tlob_parse_uprobe_line(buf, &thr, > &path, > + =C2=A0=C2=A0=C2=A0=C2=A0 &start, &stop), > -EINVAL); > + } > +} > + > +static void tlob_parse_out_of_range_rejected(struct kunit *test) > +{ > + u64 thr; > + char *path; > + loff_t start, stop; > + char buf[128]; > + int i; > + > + for (i =3D 0; i < ARRAY_SIZE(tlob_parse_out_of_range); i++) { > + strscpy(buf, tlob_parse_out_of_range[i], sizeof(buf)); > + KUNIT_EXPECT_EQ(test, tlob_parse_uprobe_line(buf, &thr, > &path, > + =C2=A0=C2=A0=C2=A0=C2=A0 &start, &stop), > -ERANGE); > + } > +} > + > +static void tlob_remove_valid_accepted(struct kunit *test) > +{ > + char *path; > + loff_t start; > + char buf[128]; > + int i; > + > + for (i =3D 0; i < ARRAY_SIZE(tlob_remove_valid); i++) { > + strscpy(buf, tlob_remove_valid[i], sizeof(buf)); > + KUNIT_EXPECT_EQ(test, tlob_parse_remove_line(buf, &path, > &start), 0); > + } > +} > + > +static void tlob_remove_invalid_rejected(struct kunit *test) > +{ > + char *path; > + loff_t start; > + char buf[128]; > + int i; > + > + for (i =3D 0; i < ARRAY_SIZE(tlob_remove_invalid); i++) { > + strscpy(buf, tlob_remove_invalid[i], sizeof(buf)); > + KUNIT_EXPECT_EQ(test, tlob_parse_remove_line(buf, &path, > &start), -EINVAL); > + } > +} > + > +static struct kunit_case tlob_parse_cases[] =3D { > + KUNIT_CASE(tlob_parse_valid_accepted), > + KUNIT_CASE(tlob_parse_invalid_rejected), > + KUNIT_CASE(tlob_parse_out_of_range_rejected), > + KUNIT_CASE(tlob_remove_valid_accepted), > + KUNIT_CASE(tlob_remove_invalid_rejected), > + {} > +}; > + > +static struct kunit_suite tlob_parse_suite =3D { > + .name=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D "tlob_parse", > + .test_cases =3D tlob_parse_cases, > +}; > + > +kunit_test_suite(tlob_parse_suite); > + > +MODULE_DESCRIPTION("KUnit tests for the tlob RV monitor"); > +MODULE_LICENSE("GPL");