From nobody Fri Jul 24 21:52:34 2026 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 8365E283CB5 for ; Thu, 23 Jul 2026 07:46:09 +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=1784792770; cv=none; b=aNkxMFb0j8zMTaJb0eetA8RDIMul6Sn/Q40Yf9sFfJppPNlyrpGyiKKSw7x8oLpKw8o33TYLCAfwy6htboOTfmH9zIe3UfSq9ZtzvX+P3UnA4iK2ZLWlHaJBKOGz9RFFG7/8kvPiMGnw4QcXTxILGnYLJpZbXmUfePXiikCHb2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792770; c=relaxed/simple; bh=juRSUQH49mutSlw9dHVHjZYx+yd8pmfuE+wPZU8INnk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mDOTfYRxCHjQZbuA5/g5HMF4xxULs7jDeDjgzh1A26A7G1aHQ+JrFBgQw5HoVMnmF28q2yVkUsqq9I1FqkKnji0Anu7RgogH7U60Zjj/DAuwVolfKtFuOMXH6L65Vd9+Fv+gs/x7Y8kuBcH0XE+ER7CVnC8kSUe/MI/C1NMiOi0= 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=Di/lYrqA; 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="Di/lYrqA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xmUSuZjVzHE1hMQrcBQZVjUHguf58xO1cn06OsAaV8E=; b=Di/lYrqAb4MzLC39DHIob0g7XDICDbngfiDds00fzfXgXaRDUXCBB57VYo1rx/Vd51o1GW 27XsJXIJNVqwX3UKidcZCwo6l41sIzdmMh04c4UgMzScI0Bi4enOxHUB27e9nARYtF1XEe Cr25fBDqh2i28uLJg7z06NqwcMd4Ozs= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-1-fEeLltkAMHOq1wcVsf8P0Q-1; Thu, 23 Jul 2026 03:46:04 -0400 X-MC-Unique: fEeLltkAMHOq1wcVsf8P0Q-1 X-Mimecast-MFC-AGG-ID: fEeLltkAMHOq1wcVsf8P0Q_1784792763 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C516E182FA37; Thu, 23 Jul 2026 07:46:02 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7123A180029D; Thu, 23 Jul 2026 07:45:59 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 01/17] rv: Use generic rv_this for the rv_monitor variable in LTL Date: Thu, 23 Jul 2026 09:45:18 +0200 Message-ID: <20260723074534.43521-2-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Align the rv_monitor variable name in LTL to the generic rv_this as it is already done for DA/HA monitors. This improves consistency and eases assumptions across model classes. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/ltl_monitor.h | 5 ++--- kernel/trace/rv/monitors/pagefault/pagefault.c | 6 +++--- kernel/trace/rv/monitors/sleep/sleep.c | 6 +++--- tools/verification/rvgen/rvgen/templates/ltl2k/main.c | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/rv/ltl_monitor.h b/include/rv/ltl_monitor.h index 38e792401f76..56e83edcf0c4 100644 --- a/include/rv/ltl_monitor.h +++ b/include/rv/ltl_monitor.h @@ -16,8 +16,7 @@ #error "Please include $(MODEL_NAME).h generated by rvgen" #endif =20 -#define RV_MONITOR_NAME CONCATENATE(rv_, MONITOR_NAME) -static struct rv_monitor RV_MONITOR_NAME; +static struct rv_monitor rv_this; =20 static int ltl_monitor_slot =3D RV_PER_TASK_MONITOR_INIT; =20 @@ -85,7 +84,7 @@ static void ltl_monitor_destroy(void) static void ltl_illegal_state(struct task_struct *task, struct ltl_monitor= *mon) { CONCATENATE(trace_error_, MONITOR_NAME)(task); - rv_react(&RV_MONITOR_NAME, "rv: "__stringify(MONITOR_NAME)": %s[%d]: viol= ation detected\n", + rv_react(&rv_this, "rv: "__stringify(MONITOR_NAME)": %s[%d]: violation de= tected\n", task->comm, task->pid); } =20 diff --git a/kernel/trace/rv/monitors/pagefault/pagefault.c b/kernel/trace/= rv/monitors/pagefault/pagefault.c index 9fe6123b2200..5e1a2a606783 100644 --- a/kernel/trace/rv/monitors/pagefault/pagefault.c +++ b/kernel/trace/rv/monitors/pagefault/pagefault.c @@ -63,7 +63,7 @@ static void disable_pagefault(void) ltl_monitor_destroy(); } =20 -static struct rv_monitor rv_pagefault =3D { +static struct rv_monitor rv_this =3D { .name =3D "pagefault", .description =3D "Monitor that RT tasks do not raise page faults", .enable =3D enable_pagefault, @@ -72,12 +72,12 @@ static struct rv_monitor rv_pagefault =3D { =20 static int __init register_pagefault(void) { - return rv_register_monitor(&rv_pagefault, &rv_rtapp); + return rv_register_monitor(&rv_this, &rv_rtapp); } =20 static void __exit unregister_pagefault(void) { - rv_unregister_monitor(&rv_pagefault); + rv_unregister_monitor(&rv_this); } =20 module_init(register_pagefault); diff --git a/kernel/trace/rv/monitors/sleep/sleep.c b/kernel/trace/rv/monit= ors/sleep/sleep.c index 8dfe5ec13e19..12328ce663f5 100644 --- a/kernel/trace/rv/monitors/sleep/sleep.c +++ b/kernel/trace/rv/monitors/sleep/sleep.c @@ -224,7 +224,7 @@ static void disable_sleep(void) ltl_monitor_destroy(); } =20 -static struct rv_monitor rv_sleep =3D { +static struct rv_monitor rv_this =3D { .name =3D "sleep", .description =3D "Monitor that RT tasks do not undesirably sleep", .enable =3D enable_sleep, @@ -233,12 +233,12 @@ static struct rv_monitor rv_sleep =3D { =20 static int __init register_sleep(void) { - return rv_register_monitor(&rv_sleep, &rv_rtapp); + return rv_register_monitor(&rv_this, &rv_rtapp); } =20 static void __exit unregister_sleep(void) { - rv_unregister_monitor(&rv_sleep); + rv_unregister_monitor(&rv_this); } =20 module_init(register_sleep); diff --git a/tools/verification/rvgen/rvgen/templates/ltl2k/main.c b/tools/= verification/rvgen/rvgen/templates/ltl2k/main.c index f85d076fbf78..31258b9ea083 100644 --- a/tools/verification/rvgen/rvgen/templates/ltl2k/main.c +++ b/tools/verification/rvgen/rvgen/templates/ltl2k/main.c @@ -77,7 +77,7 @@ static void disable_%%MODEL_NAME%%(void) /* * This is the monitor register section. */ -static struct rv_monitor rv_%%MODEL_NAME%% =3D { +static struct rv_monitor rv_this =3D { .name =3D "%%MODEL_NAME%%", .description =3D "%%DESCRIPTION%%", .enable =3D enable_%%MODEL_NAME%%, @@ -86,12 +86,12 @@ static struct rv_monitor rv_%%MODEL_NAME%% =3D { =20 static int __init register_%%MODEL_NAME%%(void) { - return rv_register_monitor(&rv_%%MODEL_NAME%%, %%PARENT%%); + return rv_register_monitor(&rv_this, %%PARENT%%); } =20 static void __exit unregister_%%MODEL_NAME%%(void) { - rv_unregister_monitor(&rv_%%MODEL_NAME%%); + rv_unregister_monitor(&rv_this); } =20 module_init(register_%%MODEL_NAME%%); --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 B545C339392 for ; Thu, 23 Jul 2026 07:46:12 +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=1784792774; cv=none; b=N5qzkGgXn6rIrlEqhFl2o88zXR39JiYCnBlBRqkvawzkWaQipQ7xsgTDLpciUE1OZSz8MYkI0iRqEojsTromWRos0Pt0C3hvEqCdn/1V08V4oX9KYY2uyF16pZS1byTRpX7KXMAXcVlnniICemCivBuHMIhu2FxLGfPt11BnmfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792774; c=relaxed/simple; bh=ycYvBP9hzjR8aDm3BJY/4osWJ8vsvl8LdYfIxaFDnyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qmFwp5IdbMSDL8FLS5bQjPnYfyKQLsf74PNL9mjOGLbP4vpdjpa80ViFP1R9QRAZfEcB42q8eq1YuFtIgbW6+MefI7Lqe1wPvK7tmBNpfdNTzK1dz9IthpQ1jn8eLbVm+/QOx9t0HC4RgGKB4sjLfttwzGQ29Y217TmkES6DwZI= 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=FxZsyHSQ; 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="FxZsyHSQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792771; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZEnIH1pC1zinOd93k1MlbOMnciBp15Ri/sQHFqDz0Fw=; b=FxZsyHSQPV0t7pTE9eacupg1c/wHuPlF5nKpG6HEa5NLciht9R/qyVdPExsGX1FCMWDoPx 3pnGFQnW4mVz18z1EjUv+KlFy02UxuRjyBd4cY5m+jLc3mF/J5xnUrWzPxuAh+ceehSJqZ bSW52ndexNNAceVihisPPlFJfOcyDUs= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-OwMzS8vZNhy8BH1ciNAUjA-1; Thu, 23 Jul 2026 03:46:08 -0400 X-MC-Unique: OwMzS8vZNhy8BH1ciNAUjA-1 X-Mimecast-MFC-AGG-ID: OwMzS8vZNhy8BH1ciNAUjA_1784792767 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C4B4B1800578; Thu, 23 Jul 2026 07:46:06 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BE444180029A; Thu, 23 Jul 2026 07:46:03 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 02/17] tools/rv: Fix exit status when monitor execution fails Date: Thu, 23 Jul 2026 09:45:19 +0200 Message-ID: <20260723074534.43521-3-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" When running "rv mon" on a monitor that is already enabled, the tool fails to start but incorrectly exits with a success status (0). Fix the exit condition to ensure it returns a failure code on any execution error. Also use the standard EXIT_SUCCESS/EXIT_FAILURE macros throughout the file. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- tools/verification/rv/src/rv.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/verification/rv/src/rv.c b/tools/verification/rv/src/rv.c index b8fe24a87d97..09e0d8598619 100644 --- a/tools/verification/rv/src/rv.c +++ b/tools/verification/rv/src/rv.c @@ -50,23 +50,23 @@ static void rv_list(int argc, char **argv) " [container]: list only monitors in this container", NULL, }; - int i, print_help =3D 0, retval =3D 0; + int i, print_help =3D 0, retval =3D EXIT_SUCCESS; char *container =3D NULL; =20 if (argc =3D=3D 2) { if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { print_help =3D 1; - retval =3D 0; + retval =3D EXIT_SUCCESS; } else if (argv[1][0] =3D=3D '-') { /* assume invalid option */ print_help =3D 1; - retval =3D 1; + retval =3D EXIT_FAILURE; } else container =3D argv[1]; } else if (argc > 2) { /* more than 2 is always usage */ print_help =3D 1; - retval =3D 1; + retval =3D EXIT_FAILURE; } if (print_help) { fprintf(stderr, "rv version %s\n", VERSION); @@ -77,7 +77,7 @@ static void rv_list(int argc, char **argv) =20 ikm_list_monitors(container); =20 - exit(0); + exit(EXIT_SUCCESS); } =20 /* @@ -108,14 +108,14 @@ static void rv_mon(int argc, char **argv) =20 for (i =3D 0; usage[i]; i++) fprintf(stderr, "%s\n", usage[i]); - exit(1); + exit(EXIT_FAILURE); } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { =20 fprintf(stderr, "rv version %s\n", VERSION); =20 for (i =3D 0; usage[i]; i++) fprintf(stderr, "%s\n", usage[i]); - exit(0); + exit(EXIT_SUCCESS); } =20 monitor_name =3D argv[1]; @@ -127,7 +127,7 @@ static void rv_mon(int argc, char **argv) =20 if (!run) err_msg("rv: monitor %s does not exist\n", monitor_name); - exit(!run); + exit(run > 0 ? EXIT_SUCCESS : EXIT_FAILURE); } =20 static void usage(int exit_val, const char *fmt, ...) @@ -174,13 +174,13 @@ static void usage(int exit_val, const char *fmt, ...) int main(int argc, char **argv) { if (geteuid()) - usage(1, "%s needs root permission", argv[0]); + usage(EXIT_FAILURE, "%s needs root permission", argv[0]); =20 if (argc <=3D 1) - usage(1, "%s requires a command", argv[0]); + usage(EXIT_FAILURE, "%s requires a command", argv[0]); =20 if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) - usage(0, "help"); + usage(EXIT_SUCCESS, "help"); =20 if (!strcmp(argv[1], "list")) rv_list(--argc, &argv[1]); @@ -197,5 +197,5 @@ int main(int argc, char **argv) } =20 /* invalid sub-command */ - usage(1, "%s does not know the %s command, old version?", argv[0], argv[1= ]); + usage(EXIT_FAILURE, "%s does not know the %s command, old version?", argv= [0], argv[1]); } --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 05934470EAD for ; Thu, 23 Jul 2026 07:46:15 +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=1784792777; cv=none; b=PunCWwrFBhGIkXU9HadbkS0H5sa9iXVkGaM26raUzSlwK9303H2awiutqqszJ8HRqWRz33ki6oo3BFGYf27EuMocawHiOCNWtqb6WV86doSYam/kUtg3nzIkF4T9vVx/B7DtaRWcz6Zs0xj++6oi3XIggvdglUKTJgysPiYwcPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792777; c=relaxed/simple; bh=Cum0QqU8Sg1+ObZ8D8XOaDmDfbRlz/6RuQyxIG8Mgdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nvuXzDha3g832XQ5H3MEFQdOUMx1QJIMYGKuUi8hZbNEbqwsWdK7OfpXJbc7Y2sJDTMO3Bpy11dbJjNLVKn7iPoiEbeOxdVsRgrqKGdiKua/6HYQm6s4h9vEbEdDJqg5ZH3tk+EvdxnF7hYbezGJDUNIwf+rryAzWzJPD2nQPK0= 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=ft/vOqcq; 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="ft/vOqcq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ju7llNIicTz9FkVPfQxMT1c3/C73QaL40X9t/IZ06cI=; b=ft/vOqcquarvgxolOdca3GbsNrw9VkztU9/7hB6ux4FpFVEfDn5TDZOhtlSLHMNLZPxyQ6 5eHEWTaclxpLIbQPJFrLlu0yYvQXqWzxYI3/ehqRNSHLhwlcGn4fdt66KrHNOUEeUVLfZV QOFeF3gPlaF1IBp2UYIpJC+d9Q/+HKM= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-BITVSBFsP3SSTi2mQGxlQA-1; Thu, 23 Jul 2026 03:46:12 -0400 X-MC-Unique: BITVSBFsP3SSTi2mQGxlQA-1 X-Mimecast-MFC-AGG-ID: BITVSBFsP3SSTi2mQGxlQA_1784792771 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A6F31805F20; Thu, 23 Jul 2026 07:46:11 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BB32318002B5; Thu, 23 Jul 2026 07:46:07 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 03/17] verification/rvgen: Improve rv_dir discovery in RVGenerator Date: Thu, 23 Jul 2026 09:45:20 +0200 Message-ID: <20260723074534.43521-4-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The RVGenerator class can find the RV directory (kernel/trace/rv) in the kernel tree to do some auto patching. This works by assuming PWD is either the kernel tree or tools/verification, which isn't always the case (e.g. when running from selftests). Make discovery more robust by relying on the absolute path of the current script and traversing backwards the right number of times. This should work from any location if rvgen is in the kernel tree. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- Notes: V4: * Use pathlib's parents array to climb up directories tools/verification/rvgen/rvgen/generator.py | 29 ++++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tools/verification/rvgen/rvgen/generator.py b/tools/verificati= on/rvgen/rvgen/generator.py index 56f3bd8db850..1c20f7d1905c 100644 --- a/tools/verification/rvgen/rvgen/generator.py +++ b/tools/verification/rvgen/rvgen/generator.py @@ -7,6 +7,7 @@ =20 import platform import os +from pathlib import Path =20 =20 class RVGenerator: @@ -25,27 +26,29 @@ class RVGenerator: self.__fill_rv_kernel_dir() =20 def __fill_rv_kernel_dir(self): - - # first try if we are running in the kernel tree root - if os.path.exists(self.rv_dir): - return - - # offset if we are running inside the kernel tree from verificatio= n/dot2 - kernel_path =3D os.path.join("../..", self.rv_dir) - - if os.path.exists(kernel_path): - self.rv_dir =3D kernel_path + # find the kernel tree root relative to this file's location + resolved_path =3D Path(__file__).resolve() + if len(resolved_path.parents) > 4: + kernel_root =3D resolved_path.parents[4] + kernel_path =3D kernel_root / self.rv_dir + + if kernel_path.exists(): + self.rv_dir =3D str(kernel_path) + return + + # best effort if rvgen is installed and we are at the root of a ke= rnel tree + if Path(self.rv_dir).exists(): return =20 if platform.system() !=3D "Linux": raise OSError("I can only run on Linux.") =20 - kernel_path =3D os.path.join(f"/lib/modules/{platform.release()}/b= uild", self.rv_dir) + kernel_path =3D Path(f"/lib/modules/{platform.release()}/build") /= self.rv_dir =20 # if the current kernel is from a distro this may not be a full ke= rnel tree # verify that one of the files we are going to modify is available - if os.path.exists(os.path.join(kernel_path, "rv_trace.h")): - self.rv_dir =3D kernel_path + if (kernel_path / "rv_trace.h").exists(): + self.rv_dir =3D str(kernel_path) return =20 raise FileNotFoundError("Could not find the rv directory, do you h= ave the kernel source installed?") --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 396A43F9FB for ; Thu, 23 Jul 2026 07:46:20 +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=1784792782; cv=none; b=q49y1W3yo+lmt5C4lKpboHRg+LSnFml/M1Dn0puTQYMqVe+XQGbbHE92kG56mCThM7WKzIrZsJGmTkjK0ZCeDuUMNWnSS3/NyYtnQN0t1KADBrLS052RRrBnZ3cF4tgsUVYhQYDCvqVNQli7OfVGWN4ld6kQTHJturkxorGKeDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792782; c=relaxed/simple; bh=DGm9ZkHsAWX41PM618xr+/oZsh5ML37hVD3X1R8WMHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bQfU65w9dogMSOmzC5iL8VXDgMAkL66gmoD2xCAnlPMARkAJdzCtO+aLZ6Vxb1RgUQiiqBzU1n4rYQ1qO167Ny/h3cTKftcNRo0xt5xb16WtpnH+7SyIDAUNfIkIbIBBJk1QOEVSL0jBpceIOnDt0Kvp2BqyMsVnBg26uAldDhg= 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=gPfkRKgU; 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="gPfkRKgU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uljRcLJYDvn4XROMEV+Mu/AmUKGVI0WCPtBXywCVYgA=; b=gPfkRKgUIt1qJbVMpmcCEXEeN7mTE6f6oGl3HeKf/56yaaNX/Z4h2eflYH18vzvYkmC8zi UuKj8DxuH9ES0P+uepr6F7o+k3udBNDtUTtYefmbetYpHVf5uJbjzpUuxEQZvmkMf+nxfH QjJdqrPAm3/ML2p5C5DbLOXt3gRTNyk= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-mHRZLjQwO5mHrgXwTnpJWQ-1; Thu, 23 Jul 2026 03:46:16 -0400 X-MC-Unique: mHRZLjQwO5mHrgXwTnpJWQ-1 X-Mimecast-MFC-AGG-ID: mHRZLjQwO5mHrgXwTnpJWQ_1784792775 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1952319540DD; Thu, 23 Jul 2026 07:46:15 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0AEF418002B4; Thu, 23 Jul 2026 07:46:11 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 04/17] verification/rvgen: Use pathlib instead of os.path Date: Thu, 23 Jul 2026 09:45:21 +0200 Message-ID: <20260723074534.43521-5-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Migrate to the newer patlib library, bundled with python since 3.4 to increase readability over using os.path. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- tools/verification/rvgen/rvgen/generator.py | 22 +++++++++------------ 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/verification/rvgen/rvgen/generator.py b/tools/verificati= on/rvgen/rvgen/generator.py index 1c20f7d1905c..f1b37d34b1e9 100644 --- a/tools/verification/rvgen/rvgen/generator.py +++ b/tools/verification/rvgen/rvgen/generator.py @@ -6,7 +6,6 @@ # Abstract class for generating kernel runtime verification monitors from = specification file =20 import platform -import os from pathlib import Path =20 =20 @@ -17,7 +16,7 @@ class RVGenerator: self.name =3D extra_params.get("model_name") self.parent =3D extra_params.get("parent") self.abs_template_dir =3D \ - os.path.join(os.path.dirname(__file__), "templates", self.temp= late_dir) + Path(__file__).resolve().parent / "templates" / self.template_= dir self.main_c =3D self._read_template_file("main.c") self.kconfig =3D self._read_template_file("Kconfig") self.description =3D extra_params.get("description", self.name) or= "auto-generated" @@ -60,12 +59,12 @@ class RVGenerator: =20 def _read_template_file(self, file): try: - path =3D os.path.join(self.abs_template_dir, file) + path =3D self.abs_template_dir / file return self._read_file(path) except OSError: # Specific template file not found. Try the generic template f= ile in the template/ # directory, which is one level up - path =3D os.path.join(self.abs_template_dir, "..", file) + path =3D self.abs_template_dir.parent / file return self._read_file(path) =20 def fill_parent(self): @@ -136,7 +135,7 @@ class RVGenerator: =20 def _patch_file(self, file, marker, line): assert self.auto_patch - file_to_patch =3D os.path.join(self.rv_dir, file) + file_to_patch =3D Path(self.rv_dir) / file content =3D self._read_file(file_to_patch) content =3D content.replace(marker, line + "\n" + marker) self.__write_file(file_to_patch, content) @@ -190,22 +189,19 @@ obj-$(CONFIG_RV_MON_{name_up}) +=3D monitors/{name}/{= name}.o return f" - Move {self.name}/ to the kernel's monitor directory (= {self.rv_dir}/monitors)" =20 def __create_directory(self): - path =3D self.name + path =3D Path(self.name) if self.auto_patch: - path =3D os.path.join(self.rv_dir, "monitors", path) - try: - os.mkdir(path) - except FileExistsError: - return + path =3D Path(self.rv_dir) / "monitors" / path + path.mkdir(exist_ok=3DTrue) =20 def __write_file(self, file_name, content): with open(file_name, 'w') as file: file.write(content) =20 def _create_file(self, file_name, content): - path =3D f"{self.name}/{file_name}" + path =3D Path(self.name) / file_name if self.auto_patch: - path =3D os.path.join(self.rv_dir, "monitors", path) + path =3D Path(self.rv_dir) / "monitors" / self.name / file_name self.__write_file(path, content) =20 def print_files(self): --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 8921C2C11E4 for ; Thu, 23 Jul 2026 07:46:26 +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=1784792787; cv=none; b=KflRR/PTUI2+qpze+mshOZn+KvtAdcaWMiTRquIfZmPtHfTmEHDaOyS+K7o30UGgYH+4XLJbqRoywBZw0wn0IwpeNWKq/3LSs/nfHStagmw1dXEzbAHphYcxSQV5gGiqaqGiaCs/yhF1i6tClTOcOzjhlWU4wTOedpI6FSGTNok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792787; c=relaxed/simple; bh=UEjxAhCAsv2UuByilZ5MOahp6B941LXeH4E/4NteAqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=meQqIQa4w9Pu85pUVLxySIG3ZMxEhCkFMk/+Gv+MNW4w7fLA3CRBEp47JHPgEiRpd0vUDqxyecdu/E/fZf/iqv0tKFryL6YgFujqPOS0KikMvX3uaiofpkoBqnvPl2MCj2/aQ3a3kannOsPjdGLLdj37IRzAZ1BWc5CejkVGz5g= 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=ZQndGTuw; 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="ZQndGTuw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ITEDGHwFCgIa8U7w4Rj8ukCi468SmehxzxZTxI1lFXI=; b=ZQndGTuwggHIALn/THNzN0RCGDC2lMqeA71Ro5EbriaXYnHmsYrpjLEPqiT8JIO0dUKjNr G8DDca5/ObZCx+Y05+SV5WKvJt6buKCijJ9pZfc4ocsGNaLI4kdU/iqvmMto3G44XBOZbl VNuQMfRtID+Ro9sFv6OBFL8B5WBZSZ8= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-248-PDyuYkMuP_eGA6fn1qY10g-1; Thu, 23 Jul 2026 03:46:21 -0400 X-MC-Unique: PDyuYkMuP_eGA6fn1qY10g-1 X-Mimecast-MFC-AGG-ID: PDyuYkMuP_eGA6fn1qY10g_1784792779 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A18C11977539; Thu, 23 Jul 2026 07:46:19 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 81144180029D; Thu, 23 Jul 2026 07:46:16 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 05/17] verification/rvgen: Improve consistency in template files Date: Thu, 23 Jul 2026 09:45:22 +0200 Message-ID: <20260723074534.43521-6-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Template files for rvgen had minor inconsistencies in their placeholders for default author and default tracepoint examples. The user needs to modify those anyway but keeping consistency may help in bulk editing or checking. Change default author from "dot2k: auto-generated" (for DA/containers) or /* TODO */ (for LTL) to the general "rvgen: auto-generated". Align the sample tracepoint handler name in LTL template to handle_example_event, consistently with the rest of the file. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- tools/verification/rvgen/rvgen/ltl2k.py | 2 +- tools/verification/rvgen/rvgen/templates/container/main.c | 2 +- tools/verification/rvgen/rvgen/templates/dot2k/main.c | 2 +- tools/verification/rvgen/rvgen/templates/ltl2k/main.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/verification/rvgen/rvgen/ltl2k.py b/tools/verification/r= vgen/rvgen/ltl2k.py index 81fd1f5ea5ea..f3781a3e0856 100644 --- a/tools/verification/rvgen/rvgen/ltl2k.py +++ b/tools/verification/rvgen/rvgen/ltl2k.py @@ -222,7 +222,7 @@ class ltl2k(generator.Monitor): return f"\trv_attach_trace_probe(\"{self.name}\", /* XXX: tracepoi= nt */, handle_example_event);" =20 def fill_tracepoint_detach_helper(self): - return f"\trv_detach_trace_probe(\"{self.name}\", /* XXX: tracepoi= nt */, handle_sample_event);" + return f"\trv_detach_trace_probe(\"{self.name}\", /* XXX: tracepoi= nt */, handle_example_event);" =20 def fill_atoms_init(self): buff =3D [] diff --git a/tools/verification/rvgen/rvgen/templates/container/main.c b/to= ols/verification/rvgen/rvgen/templates/container/main.c index 5fc89b46f279..e6a20d74886c 100644 --- a/tools/verification/rvgen/rvgen/templates/container/main.c +++ b/tools/verification/rvgen/rvgen/templates/container/main.c @@ -31,5 +31,5 @@ module_init(register_%%MODEL_NAME%%); module_exit(unregister_%%MODEL_NAME%%); =20 MODULE_LICENSE("GPL"); -MODULE_AUTHOR("dot2k: auto-generated"); +MODULE_AUTHOR("rvgen: auto-generated"); MODULE_DESCRIPTION("%%MODEL_NAME%%: %%DESCRIPTION%%"); diff --git a/tools/verification/rvgen/rvgen/templates/dot2k/main.c b/tools/= verification/rvgen/rvgen/templates/dot2k/main.c index 889446760e3c..bd3e0aab9cc5 100644 --- a/tools/verification/rvgen/rvgen/templates/dot2k/main.c +++ b/tools/verification/rvgen/rvgen/templates/dot2k/main.c @@ -79,5 +79,5 @@ module_init(register_%%MODEL_NAME%%); module_exit(unregister_%%MODEL_NAME%%); =20 MODULE_LICENSE("GPL"); -MODULE_AUTHOR("dot2k: auto-generated"); +MODULE_AUTHOR("rvgen: auto-generated"); MODULE_DESCRIPTION("%%MODEL_NAME%%: %%DESCRIPTION%%"); diff --git a/tools/verification/rvgen/rvgen/templates/ltl2k/main.c b/tools/= verification/rvgen/rvgen/templates/ltl2k/main.c index 31258b9ea083..c33f21535a7a 100644 --- a/tools/verification/rvgen/rvgen/templates/ltl2k/main.c +++ b/tools/verification/rvgen/rvgen/templates/ltl2k/main.c @@ -98,5 +98,5 @@ module_init(register_%%MODEL_NAME%%); module_exit(unregister_%%MODEL_NAME%%); =20 MODULE_LICENSE("GPL"); -MODULE_AUTHOR(/* TODO */); +MODULE_AUTHOR("rvgen: auto-generated"); MODULE_DESCRIPTION("%%MODEL_NAME%%: %%DESCRIPTION%%"); --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 41B232EEE69 for ; Thu, 23 Jul 2026 07:46:30 +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=1784792792; cv=none; b=FhtOyRtzUdgn6Bo9oxRqJLb2cAWSfOnTp4v/xIKc3+JXxVU5n5qtJzr2XdFfzO5aLvXdkyqzezMYeGsL5IstShWvwJowx+UG7QzR8O1PCivgkXI7sCHM6TueGTn9p8xvt/EYoYH2zmRCEtoEpx0y2EAYY2YW3z96xrRf7QV/Rfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792792; c=relaxed/simple; bh=XEo6Lcn87SsNgKeheHvv9+LkhsVblcmjrvZtzauIzeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ntIWuoogKJ9K3f5xEzMPq5k5dVy8/CA+KsO0tNJko0U7aJlknYDNQPJOROVnueTw9VYfgMkddadJEGlRG/3uGZm3t0kA6/YPFCP++viYMgywioE3t1du6BKjSqiNHKMN9sKJ6EnEiRleAyRypq5UddQhmgI1CVoOWGhTNqOxnJ8= 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=iIXq1NJQ; 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="iIXq1NJQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z7aNTglJykimQQOXOH133gOSR7LNkwiArg7Dhg4y2F8=; b=iIXq1NJQP/lswP9dnWw/oblCPpugDuCRnE2lHenPUIfgyosllUl3zWuwQhf54ddGYbXcIi t+0q14Az6iIeFM0tO4gDfJpwt1KYZBsYBRd1sAyE1d+weAMh/gK0pHvG6zRgk1sdg+EHBG qik+WG4beFNZuuccqL/npWdoMpmE2A4= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-GP91sBfYOiq4aIsjRHYNVQ-1; Thu, 23 Jul 2026 03:46:25 -0400 X-MC-Unique: GP91sBfYOiq4aIsjRHYNVQ-1 X-Mimecast-MFC-AGG-ID: GP91sBfYOiq4aIsjRHYNVQ_1784792784 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A77D195FDF4; Thu, 23 Jul 2026 07:46:24 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 25E4F180029A; Thu, 23 Jul 2026 07:46:20 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 06/17] tools/rv: Add selftests Date: Thu, 23 Jul 2026 09:45:23 +0200 Message-ID: <20260723074534.43521-7-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The rv tool needs automated testing to catch regressions and verify correct functionality across different usage scenarios. Add selftests that validate monitor listing (including containers and nested monitors), monitor execution with different configurations (reactors, verbose output, tracing), and trace output format for both per-task and per-cpu monitors. Error handling paths are also tested. Tests use a shared engine for common patterns. Acked-by: Nam Cao Signed-off-by: Gabriele Monaco --- Notes: V4: * Retry multiple times when getting the pid to avoid races tools/verification/rv/Makefile | 5 +- tools/verification/rv/tests/rv_list.t | 48 +++++++++ tools/verification/rv/tests/rv_mon.t | 95 +++++++++++++++++ tools/verification/tests/engine.sh | 141 ++++++++++++++++++++++++++ 4 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 tools/verification/rv/tests/rv_list.t create mode 100644 tools/verification/rv/tests/rv_mon.t create mode 100644 tools/verification/tests/engine.sh diff --git a/tools/verification/rv/Makefile b/tools/verification/rv/Makefile index 5b898360ba48..8ae5fc0d1d17 100644 --- a/tools/verification/rv/Makefile +++ b/tools/verification/rv/Makefile @@ -78,4 +78,7 @@ clean: doc_clean fixdep-clean $(Q)rm -f rv rv-static fixdep FEATURE-DUMP rv-* $(Q)rm -rf feature =20 -.PHONY: FORCE clean +check: $(RV) + RV=3D$(RV) prove -o --directives -f tests/ + +.PHONY: FORCE clean check diff --git a/tools/verification/rv/tests/rv_list.t b/tools/verification/rv/= tests/rv_list.t new file mode 100644 index 000000000000..201af33a52cc --- /dev/null +++ b/tools/verification/rv/tests/rv_list.t @@ -0,0 +1,48 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source ../tests/engine.sh +test_begin + +set_timeout 30s + +RVDIR=3D/sys/kernel/tracing/rv/ + +# Help and basic tests +check "verify help page" \ + "$RV --help" 0 "usage: rv command" + +check "verify list subcommand help" \ + "$RV list --help" 0 "list all available monitors" + +all_nested=3D$(grep : $RVDIR/available_monitors | cut -d: -f2 | paste -s |= sed 's/\t/\\|/g') +all_non_nested=3D$(grep -v : $RVDIR/available_monitors | cut -d: -f2 | pas= te -s | sed 's/\t/\\|/g') +sched_monitors=3D$(grep sched: $RVDIR/available_monitors | cut -d: -f2 | p= aste -s | sed 's/\t/\\|/g') +description_state=3D"[[:space:]]\+[[:print:]]\+\[\(OFF\|ON\)\]" +line_nested=3D" - \($all_nested\)${description_state}" +line_non_nested=3D"\($all_non_nested\)${description_state}" + +# List monitors and containers +check "list all monitors" \ + "$RV list" 0 "" "" "^\($line_nested\|$line_non_nested\)$" + +check_if_exists "list container" \ + "$RV list sched" "$RVDIR/monitors/sched" \ + "" "-- No monitor found in container sched --" \ + "^\($sched_monitors\)${description_state}$" + +check_if_exists "list non-container" \ + "$RV list wwnr" "$RVDIR/monitors/wwnr" \ + "-- No monitor found in container wwnr --" \ + "^\( - \)\?[[:alnum:]]\+${description_state}$" + +check "list incomplete container name" \ + "$RV list s" 0 "-- No monitor found in container s --" + +# Error handling tests +check "no command" \ + "$RV" 1 "rv requires a command" + +check "invalid command" \ + "$RV invalid" 1 "rv does not know the invalid command" + +test_end diff --git a/tools/verification/rv/tests/rv_mon.t b/tools/verification/rv/t= ests/rv_mon.t new file mode 100644 index 000000000000..cbc346c74c71 --- /dev/null +++ b/tools/verification/rv/tests/rv_mon.t @@ -0,0 +1,95 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source ../tests/engine.sh +test_begin + +set_timeout 30s + +RVDIR=3D/sys/kernel/tracing/rv/ + +# Help and basic tests +check "verify mon subcommand help" \ + "$RV mon --help" 0 "run a monitor" + +# Error handling tests +check "mon without monitor name" \ + "$RV mon" 1 "usage: rv mon" + +check "invalid monitor name" \ + "$RV mon invalid" 1 "monitor invalid does not exist" + +if [ -d $RVDIR/monitors/wwnr ]; then + +check "invalid reactor name" \ + "$RV mon wwnr -r invalid" 1 "failed to set invalid reactor, is it availab= le?" + +check "monitor name is substring of another monitor" \ + "$RV mon nr" 1 "monitor nr does not exist" + +check "already enabled monitor returns error" \ + "echo 1 > $RVDIR/monitors/wwnr/enable; $RV mon wwnr" 1 \ + "monitor wwnr (in-kernel) is already enabled" +echo 0 > $RVDIR/monitors/wwnr/enable + +fi + +# rv mon runs until terminated +set_expected_timeout 2s + +# Run monitors with different configurations +check_if_exists "run the monitor without parameters" \ + "$RV mon wwnr" "$RVDIR/monitors/wwnr" "" "." + +check_if_exists "run the monitor as verbose" \ + "$RV mon wwnr -v" "$RVDIR/monitors/wwnr" \ + "my pid is \$pid" "\(event\|error\)" + +check_if_exists "run the monitor with a reactor" \ + "$RV mon wwnr -r printk & sleep .5 && cat $RVDIR/monitors/wwnr/reactors &= & wait" \ + "$RVDIR/monitors/wwnr/reactors" "\[printk\]" + +check_if_exists "reactor is restored after exit" \ + "cat $RVDIR/monitors/wwnr/reactors" \ + "$RVDIR/monitors/wwnr/reactors" "\[nop\]" + +check_if_exists "run a nested monitor with a reactor" \ + "$RV mon snroc -r printk & sleep .5 && cat $RVDIR/monitors/sched/snroc/re= actors && wait" \ + "$RVDIR/monitors/sched/snroc/reactors" "\[printk\]" + +check_if_exists "run an explicitly nested monitor with a reactor" \ + "$RV mon sched:sssw -r printk & sleep .5 && cat $RVDIR/monitors/sched/sss= w/reactors && wait" \ + "$RVDIR/monitors/sched/sssw/reactors" "\[printk\]" + +check_if_exists "run container monitor" \ + "$RV mon sched & sleep .5 && cat $RVDIR/monitors/sched/{sssw,sco}/enable = && wait" \ + "$RVDIR/monitors/sched" "1" "0" "^1$" + +# Regexes for the trace +header=3D"^[[:space:]]\+\(\([][A-Z_x<>-]\+\||\)[[:space:]]*\)\+$" +type=3D"\(event\|error\)[[:space:]]\+" +genpid=3D"[0-9]\+[[:space:]]\+" +selfpid=3D"\$pid[[:space:]]\+" +cpu=3D"\[[0-9]\{3\}\][[:space:]]\+" +state=3D"[a-z_]\+ " +trace_task=3D"${genpid}${cpu}${type}${genpid}${state}" +trace_task_self=3D"${genpid}${cpu}${type}${selfpid}${state}" +trace_cpu=3D"${genpid}${cpu}${type}${state}" +trace_cpu_self=3D"${selfpid}${cpu}${type}${state}" + +check_if_exists "run per-task monitor with tracing" \ + "$RV mon sssw -t" "$RVDIR/monitors/sched/sssw" \ + "$header" "$trace_task_self" "\($header\|$trace_task\)" + +check_if_exists "run per-task monitor tracing also self" \ + "$RV mon sched:sssw -t -s" "$RVDIR/monitors/sched/sssw" \ + "$trace_task_self" "" "\($header\|$trace_task\)" + +check_if_exists "run per-cpu monitor with tracing" \ + "$RV mon sched:sco -t" "$RVDIR/monitors/sched/sco" \ + "$header" "$trace_cpu_self" "\($header\|$trace_cpu\)" + +check_if_exists "run per-cpu monitor tracing also self" \ + "$RV mon sco -t -s" "$RVDIR/monitors/sched/sco" \ + "$trace_cpu_self" "" "\($header\|$trace_cpu\)" + +test_end diff --git a/tools/verification/tests/engine.sh b/tools/verification/tests/= engine.sh new file mode 100644 index 000000000000..57e16dc980b1 --- /dev/null +++ b/tools/verification/tests/engine.sh @@ -0,0 +1,141 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +test_begin() { + # Count tests to allow the test harness to double-check if all were + # included correctly. + ctr=3D0 + [ -z "$RV" ] && RV=3D"../rv/rv" + [ -n "$TEST_COUNT" ] && echo "1..$TEST_COUNT" +} + +failure() { + fail=3D1 + if [ $# -gt 0 ]; then + failbuf+=3D"$1" + failbuf+=3D$'\n' + fi +} + +report() { + local desc=3D"$1" + + if [ "$fail" -eq 0 ]; then + echo "ok $ctr - $desc" + else + # Add output and exit code as comments in case of failure + echo "not ok $ctr - $desc" + echo -n "$failbuf" + echo "$result" | col -b | while read -r line; do echo "# $line"; done + printf "#\n# exit code %s\n" "$exitcode" + fi +} + +_check() { + local command=3D$2 + local expected_exitcode=3D${3:-0} + local expected_output=3D$4 + local unexpected_output=3D$5 + local all_lines_pattern=3D$6 + local patterns=3D"$expected_output $unexpected_output $all_lines_pattern" + local bgpid pid + + eval "$TIMEOUT" "$command" &> check_output.$$ & + bgpid=3D$! + + if grep -q "\$pid" <<< "$patterns"; then + for _ in {1..30}; do + pid=3D$(pgrep -f "${command%%[|;&>]*}" | tail -n1) + [ -n "$pid" ] && break + sleep 0.1 + done + fi + + wait $bgpid + exitcode=3D$? + result=3D$(tr -d '\0' < check_output.$$) + rm -f check_output.$$ + + failbuf=3D'' + fail=3D0 + + # Suppress any other error if a needed pid is empty + if [ -z "$pid" ] && grep -q "\$pid" <<< "$patterns"; then + result=3D'' + failure "# Empty pid for $command" + return 1 + fi + + expected_output=3D"${expected_output//\$pid/$pid}" + unexpected_output=3D"${unexpected_output//\$pid/$pid}" + all_lines_pattern=3D"${all_lines_pattern//\$pid/$pid}" + + # Test if the results matches if requested + if [ -n "$expected_output" ] && ! grep -qe "$expected_output" <<< "$resul= t"; then + failure "# Output match failed: \"$expected_output\"" + fi + + if [ -n "$unexpected_output" ] && grep -qe "$unexpected_output" <<< "$res= ult"; then + failure "# Output non-match failed: \"$unexpected_output\"" + fi + + if [ -n "$all_lines_pattern" ] && grep -vqe "$all_lines_pattern" <<< "$re= sult"; then + failure "# All-lines pattern failed: \"$all_lines_pattern\"" + fi + + if [ $exitcode -ne "$expected_exitcode" ]; then + failure "# Expected exit code $expected_exitcode" + fi +} + +check() { + # Simple check: run the command with given arguments and test exit code. + # If TEST_COUNT is set, run the test. Otherwise, just count. + ctr=3D$((ctr + 1)) + if [ -n "$TEST_COUNT" ]; then + _check "$@" + report "$1" + fi +} + +check_if_exists() { + # Conditional check that skips if a file or folder doesn't exist + local desc=3D$1 + local command=3D$2 + local file=3D$3 + local expected_output=3D$4 + local unexpected_output=3D$5 + local all_lines_pattern=3D$6 + + ctr=3D$((ctr + 1)) + if [ -n "$TEST_COUNT" ]; then + if [ ! -e "$file" ]; then + echo "ok $ctr - $desc # SKIP file not found: $file" + else + _check "$desc" "$command" 0 "$expected_output" \ + "$unexpected_output" "$all_lines_pattern" + report "$desc" + fi + fi +} + +set_timeout() { + TIMEOUT=3D"timeout -v -k 30s $1" +} + +set_expected_timeout() { + TIMEOUT=3D"timeout --preserve-status -k 30s $1" +} + +unset_timeout() { + unset TIMEOUT +} + +test_end() { + # If running without TEST_COUNT, tests are not actually run, just + # counted. In that case, re-run the test with the correct count. + [ -z "$TEST_COUNT" ] && TEST_COUNT=3D$ctr exec bash "$0" || true +} + +# Avoid any environmental discrepancies +export LC_ALL=3DC +unset_timeout --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 467872EEE69 for ; Thu, 23 Jul 2026 07:46:42 +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=1784792807; cv=none; b=RW0S/lNAxl17gUd/35ad/uXY/sTpSyxriaGDuZz4djOrlv9cPM25aZlPRY5sv+U+tr0XeKXNrQIOgC+sv0Luccpkg5ZH+S+QjxYHeoJRZLHF96Mso4zmKdp89DVc4/Y6w5X/JnffpuHnCkMffhvHtNz58Ki6WkYxqwXhKMX2SSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792807; c=relaxed/simple; bh=FX4VtX1OzvPGLdN75RHp5LSGMcNzTz8t8/fPhLFzcRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oKGysuu1vuSYhf8tCms0pIZrSySlWC0xknYfgS4y3VgKZQGBuXVGXSQGxE/dvqN4FrS8UDRH6ko8O1XKnGWtP+aeEFeFPqn5UqcPH3ludWZmTFMLMLnJX/bZZ3uYIrWnPCh8XMJIJvcbAScmnKarXuMA6uMXOx8N83YBcwW3SY0= 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=g/ncFd0Q; 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="g/ncFd0Q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+SHbjP+gnKIEycLlCjXgNfNehm1gEvPVrRuekoYGGxw=; b=g/ncFd0QKLlgIM5o8DcAI6x0op/UPgEYUPBWS5P5NjiSDptWfiPfITz7Gp2QIaM7PDbXNJ xpLdsSXnY2QqFa2sV2mP/UYkmuWVnre+w54OcWLJFEESq9ahNOYHZ/0ZeOpRWGZ18UnHtY n1ioyxCnXbQoNKgpMM1keniIw6Me7Ak= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-685-KkbWvuNvOYWaHQqdzHS_8g-1; Thu, 23 Jul 2026 03:46:36 -0400 X-MC-Unique: KkbWvuNvOYWaHQqdzHS_8g-1 X-Mimecast-MFC-AGG-ID: KkbWvuNvOYWaHQqdzHS_8g_1784792795 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 32F231977517; Thu, 23 Jul 2026 07:46:35 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3B687180029A; Thu, 23 Jul 2026 07:46:30 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 07/17] verification/rvgen: Add golden and spec folders for tests Date: Thu, 23 Jul 2026 09:45:24 +0200 Message-ID: <20260723074534.43521-8-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Create reference models specifications and generated files in the golded folder. Those can be used as reference to validate rvgen still generates files as expected in automated tests. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- .../rvgen/tests/golden/da_global/Kconfig | 9 + .../rvgen/tests/golden/da_global/da_global.c | 95 +++++++ .../rvgen/tests/golden/da_global/da_global.h | 47 ++++ .../tests/golden/da_global/da_global_trace.h | 15 ++ .../tests/golden/da_perobj_parent/Kconfig | 11 + .../da_perobj_parent/da_perobj_parent.c | 110 ++++++++ .../da_perobj_parent/da_perobj_parent.h | 64 +++++ .../da_perobj_parent/da_perobj_parent_trace.h | 15 ++ .../tests/golden/da_pertask_desc/Kconfig | 9 + .../golden/da_pertask_desc/da_pertask_desc.c | 105 ++++++++ .../golden/da_pertask_desc/da_pertask_desc.h | 64 +++++ .../da_pertask_desc/da_pertask_desc_trace.h | 15 ++ .../rvgen/tests/golden/ha_percpu/Kconfig | 9 + .../rvgen/tests/golden/ha_percpu/ha_percpu.c | 244 +++++++++++++++++ .../rvgen/tests/golden/ha_percpu/ha_percpu.h | 72 +++++ .../tests/golden/ha_percpu/ha_percpu_trace.h | 19 ++ .../rvgen/tests/golden/ltl_pertask/Kconfig | 9 + .../tests/golden/ltl_pertask/ltl_pertask.c | 107 ++++++++ .../tests/golden/ltl_pertask/ltl_pertask.h | 108 ++++++++ .../golden/ltl_pertask/ltl_pertask_trace.h | 14 + .../rvgen/tests/golden/test_container/Kconfig | 5 + .../golden/test_container/test_container.c | 35 +++ .../golden/test_container/test_container.h | 3 + .../rvgen/tests/golden/test_da/Kconfig | 9 + .../rvgen/tests/golden/test_da/test_da.c | 95 +++++++ .../rvgen/tests/golden/test_da/test_da.h | 47 ++++ .../tests/golden/test_da/test_da_trace.h | 15 ++ .../rvgen/tests/golden/test_ha/Kconfig | 9 + .../rvgen/tests/golden/test_ha/test_ha.c | 247 ++++++++++++++++++ .../rvgen/tests/golden/test_ha/test_ha.h | 72 +++++ .../tests/golden/test_ha/test_ha_trace.h | 19 ++ .../rvgen/tests/golden/test_ltl/Kconfig | 11 + .../rvgen/tests/golden/test_ltl/test_ltl.c | 108 ++++++++ .../rvgen/tests/golden/test_ltl/test_ltl.h | 108 ++++++++ .../tests/golden/test_ltl/test_ltl_trace.h | 14 + .../rvgen/tests/specs/test_da.dot | 16 ++ .../rvgen/tests/specs/test_da2.dot | 19 ++ .../rvgen/tests/specs/test_ha.dot | 27 ++ .../rvgen/tests/specs/test_invalid.dot | 8 + .../rvgen/tests/specs/test_invalid.ltl | 1 + .../rvgen/tests/specs/test_invalid_ha.dot | 16 ++ .../rvgen/tests/specs/test_ltl.ltl | 1 + 42 files changed, 2026 insertions(+) create mode 100644 tools/verification/rvgen/tests/golden/da_global/Kconfig create mode 100644 tools/verification/rvgen/tests/golden/da_global/da_glob= al.c create mode 100644 tools/verification/rvgen/tests/golden/da_global/da_glob= al.h create mode 100644 tools/verification/rvgen/tests/golden/da_global/da_glob= al_trace.h create mode 100644 tools/verification/rvgen/tests/golden/da_perobj_parent/= Kconfig create mode 100644 tools/verification/rvgen/tests/golden/da_perobj_parent/= da_perobj_parent.c create mode 100644 tools/verification/rvgen/tests/golden/da_perobj_parent/= da_perobj_parent.h create mode 100644 tools/verification/rvgen/tests/golden/da_perobj_parent/= da_perobj_parent_trace.h create mode 100644 tools/verification/rvgen/tests/golden/da_pertask_desc/K= config create mode 100644 tools/verification/rvgen/tests/golden/da_pertask_desc/d= a_pertask_desc.c create mode 100644 tools/verification/rvgen/tests/golden/da_pertask_desc/d= a_pertask_desc.h create mode 100644 tools/verification/rvgen/tests/golden/da_pertask_desc/d= a_pertask_desc_trace.h create mode 100644 tools/verification/rvgen/tests/golden/ha_percpu/Kconfig create mode 100644 tools/verification/rvgen/tests/golden/ha_percpu/ha_perc= pu.c create mode 100644 tools/verification/rvgen/tests/golden/ha_percpu/ha_perc= pu.h create mode 100644 tools/verification/rvgen/tests/golden/ha_percpu/ha_perc= pu_trace.h create mode 100644 tools/verification/rvgen/tests/golden/ltl_pertask/Kconf= ig create mode 100644 tools/verification/rvgen/tests/golden/ltl_pertask/ltl_p= ertask.c create mode 100644 tools/verification/rvgen/tests/golden/ltl_pertask/ltl_p= ertask.h create mode 100644 tools/verification/rvgen/tests/golden/ltl_pertask/ltl_p= ertask_trace.h create mode 100644 tools/verification/rvgen/tests/golden/test_container/Kc= onfig create mode 100644 tools/verification/rvgen/tests/golden/test_container/te= st_container.c create mode 100644 tools/verification/rvgen/tests/golden/test_container/te= st_container.h create mode 100644 tools/verification/rvgen/tests/golden/test_da/Kconfig create mode 100644 tools/verification/rvgen/tests/golden/test_da/test_da.c create mode 100644 tools/verification/rvgen/tests/golden/test_da/test_da.h create mode 100644 tools/verification/rvgen/tests/golden/test_da/test_da_t= race.h create mode 100644 tools/verification/rvgen/tests/golden/test_ha/Kconfig create mode 100644 tools/verification/rvgen/tests/golden/test_ha/test_ha.c create mode 100644 tools/verification/rvgen/tests/golden/test_ha/test_ha.h create mode 100644 tools/verification/rvgen/tests/golden/test_ha/test_ha_t= race.h create mode 100644 tools/verification/rvgen/tests/golden/test_ltl/Kconfig create mode 100644 tools/verification/rvgen/tests/golden/test_ltl/test_ltl= .c create mode 100644 tools/verification/rvgen/tests/golden/test_ltl/test_ltl= .h create mode 100644 tools/verification/rvgen/tests/golden/test_ltl/test_ltl= _trace.h create mode 100644 tools/verification/rvgen/tests/specs/test_da.dot create mode 100644 tools/verification/rvgen/tests/specs/test_da2.dot create mode 100644 tools/verification/rvgen/tests/specs/test_ha.dot create mode 100644 tools/verification/rvgen/tests/specs/test_invalid.dot create mode 100644 tools/verification/rvgen/tests/specs/test_invalid.ltl create mode 100644 tools/verification/rvgen/tests/specs/test_invalid_ha.dot create mode 100644 tools/verification/rvgen/tests/specs/test_ltl.ltl diff --git a/tools/verification/rvgen/tests/golden/da_global/Kconfig b/tool= s/verification/rvgen/tests/golden/da_global/Kconfig new file mode 100644 index 000000000000..799fbf11c3ac --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_global/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_DA_GLOBAL + depends on RV + # XXX: add dependencies if there + select DA_MON_EVENTS_IMPLICIT + bool "da_global monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/da_global/da_global.c b/= tools/verification/rvgen/tests/golden/da_global/da_global.c new file mode 100644 index 000000000000..71b26ae2d51c --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_global/da_global.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "da_global" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#define RV_MON_TYPE RV_MON_GLOBAL +#include "da_global.h" +#include + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + * + */ +static void handle_event_1(void *data, /* XXX: fill header */) +{ + da_handle_event(event_1_da_global); +} + +static void handle_event_2(void *data, /* XXX: fill header */) +{ + /* XXX: validate that this event always leads to the initial state */ + da_handle_start_event(event_2_da_global); +} + +static int enable_da_global(void) +{ + int retval; + + retval =3D da_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("da_global", /* XXX: tracepoint */, handle_event_1); + rv_attach_trace_probe("da_global", /* XXX: tracepoint */, handle_event_2); + + return 0; +} + +static void disable_da_global(void) +{ + rv_this.enabled =3D 0; + + rv_detach_trace_probe("da_global", /* XXX: tracepoint */, handle_event_1); + rv_detach_trace_probe("da_global", /* XXX: tracepoint */, handle_event_2); + + da_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "da_global", + .description =3D "auto-generated", + .enable =3D enable_da_global, + .disable =3D disable_da_global, + .reset =3D da_monitor_reset_all, + .enabled =3D 0, +}; + +static int __init register_da_global(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_da_global(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_da_global); +module_exit(unregister_da_global); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("da_global: auto-generated"); diff --git a/tools/verification/rvgen/tests/golden/da_global/da_global.h b/= tools/verification/rvgen/tests/golden/da_global/da_global.h new file mode 100644 index 000000000000..40b1f1c0c681 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_global/da_global.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Automatically generated C representation of da_global automaton + * For further information about this format, see kernel documentation: + * Documentation/trace/rv/deterministic_automata.rst + */ + +#define MONITOR_NAME da_global + +enum states_da_global { + state_a_da_global, + state_b_da_global, + state_max_da_global, +}; + +#define INVALID_STATE state_max_da_global + +enum events_da_global { + event_1_da_global, + event_2_da_global, + event_max_da_global, +}; + +struct automaton_da_global { + char *state_names[state_max_da_global]; + char *event_names[event_max_da_global]; + unsigned char function[state_max_da_global][event_max_da_global]; + unsigned char initial_state; + bool final_states[state_max_da_global]; +}; + +static const struct automaton_da_global automaton_da_global =3D { + .state_names =3D { + "state_a", + "state_b", + }, + .event_names =3D { + "event_1", + "event_2", + }, + .function =3D { + { state_b_da_global, state_a_da_global }, + { INVALID_STATE, state_a_da_global }, + }, + .initial_state =3D state_a_da_global, + .final_states =3D { 1, 0 }, +}; diff --git a/tools/verification/rvgen/tests/golden/da_global/da_global_trac= e.h b/tools/verification/rvgen/tests/golden/da_global/da_global_trace.h new file mode 100644 index 000000000000..4d2730b71dd0 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_global/da_global_trace.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_DA_GLOBAL +DEFINE_EVENT(event_da_monitor, event_da_global, + TP_PROTO(char *state, char *event, char *next_state, bool final_stat= e), + TP_ARGS(state, event, next_state, final_state)); + +DEFINE_EVENT(error_da_monitor, error_da_global, + TP_PROTO(char *state, char *event), + TP_ARGS(state, event)); +#endif /* CONFIG_RV_MON_DA_GLOBAL */ diff --git a/tools/verification/rvgen/tests/golden/da_perobj_parent/Kconfig= b/tools/verification/rvgen/tests/golden/da_perobj_parent/Kconfig new file mode 100644 index 000000000000..249ba3aee8d7 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_perobj_parent/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_DA_PEROBJ_PARENT + depends on RV + # XXX: add dependencies if there + depends on RV_MON_PARENT_MON + default y + select DA_MON_EVENTS_ID + bool "da_perobj_parent monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/da_perobj_parent/da_pero= bj_parent.c b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_per= obj_parent.c new file mode 100644 index 000000000000..a0f8b5a216a3 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_pare= nt.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "da_perobj_parent" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#define RV_MON_TYPE RV_MON_PER_OBJ +typedef /* XXX: define the target type */ *monitor_target; +#include "da_perobj_parent.h" +#include + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + * + */ +static void handle_event_1(void *data, /* XXX: fill header */) +{ + /* XXX: validate that this event is only valid in the initial state */ + int id =3D /* XXX: how do I get the id? */; + monitor_target t =3D /* XXX: how do I get t? */; + da_handle_start_run_event(id, t, event_1_da_perobj_parent); +} + +static void handle_event_2(void *data, /* XXX: fill header */) +{ + int id =3D /* XXX: how do I get the id? */; + monitor_target t =3D /* XXX: how do I get t? */; + da_handle_event(id, t, event_2_da_perobj_parent); +} + +static void handle_event_3(void *data, /* XXX: fill header */) +{ + int id =3D /* XXX: how do I get the id? */; + monitor_target t =3D /* XXX: how do I get t? */; + da_handle_event(id, t, event_3_da_perobj_parent); +} + +static int enable_da_perobj_parent(void) +{ + int retval; + + retval =3D da_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("da_perobj_parent", /* XXX: tracepoint */, handle_e= vent_1); + rv_attach_trace_probe("da_perobj_parent", /* XXX: tracepoint */, handle_e= vent_2); + rv_attach_trace_probe("da_perobj_parent", /* XXX: tracepoint */, handle_e= vent_3); + + return 0; +} + +static void disable_da_perobj_parent(void) +{ + rv_this.enabled =3D 0; + + rv_detach_trace_probe("da_perobj_parent", /* XXX: tracepoint */, handle_e= vent_1); + rv_detach_trace_probe("da_perobj_parent", /* XXX: tracepoint */, handle_e= vent_2); + rv_detach_trace_probe("da_perobj_parent", /* XXX: tracepoint */, handle_e= vent_3); + + da_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "da_perobj_parent", + .description =3D "auto-generated", + .enable =3D enable_da_perobj_parent, + .disable =3D disable_da_perobj_parent, + .reset =3D da_monitor_reset_all, + .enabled =3D 0, +}; + +static int __init register_da_perobj_parent(void) +{ + return rv_register_monitor(&rv_this, &rv_parent_mon); +} + +static void __exit unregister_da_perobj_parent(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_da_perobj_parent); +module_exit(unregister_da_perobj_parent); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("da_perobj_parent: auto-generated"); diff --git a/tools/verification/rvgen/tests/golden/da_perobj_parent/da_pero= bj_parent.h b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_per= obj_parent.h new file mode 100644 index 000000000000..3c8dc3b22443 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_pare= nt.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Automatically generated C representation of da_perobj_parent automaton + * For further information about this format, see kernel documentation: + * Documentation/trace/rv/deterministic_automata.rst + */ + +#define MONITOR_NAME da_perobj_parent + +enum states_da_perobj_parent { + state_a_da_perobj_parent, + state_b_da_perobj_parent, + state_c_da_perobj_parent, + state_max_da_perobj_parent, +}; + +#define INVALID_STATE state_max_da_perobj_parent + +enum events_da_perobj_parent { + event_1_da_perobj_parent, + event_2_da_perobj_parent, + event_3_da_perobj_parent, + event_max_da_perobj_parent, +}; + +struct automaton_da_perobj_parent { + char *state_names[state_max_da_perobj_parent]; + char *event_names[event_max_da_perobj_parent]; + unsigned char function[state_max_da_perobj_parent][event_max_da_perobj_pa= rent]; + unsigned char initial_state; + bool final_states[state_max_da_perobj_parent]; +}; + +static const struct automaton_da_perobj_parent automaton_da_perobj_parent = =3D { + .state_names =3D { + "state_a", + "state_b", + "state_c", + }, + .event_names =3D { + "event_1", + "event_2", + "event_3", + }, + .function =3D { + { + state_b_da_perobj_parent, + state_c_da_perobj_parent, + INVALID_STATE, + }, + { + INVALID_STATE, + state_a_da_perobj_parent, + state_c_da_perobj_parent, + }, + { + INVALID_STATE, + INVALID_STATE, + INVALID_STATE, + }, + }, + .initial_state =3D state_a_da_perobj_parent, + .final_states =3D { 1, 0, 0 }, +}; diff --git a/tools/verification/rvgen/tests/golden/da_perobj_parent/da_pero= bj_parent_trace.h b/tools/verification/rvgen/tests/golden/da_perobj_parent/= da_perobj_parent_trace.h new file mode 100644 index 000000000000..59bfca8f73d2 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_perobj_parent/da_perobj_pare= nt_trace.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_DA_PEROBJ_PARENT +DEFINE_EVENT(event_da_monitor_id, event_da_perobj_parent, + TP_PROTO(int id, char *state, char *event, char *next_state, bool fi= nal_state), + TP_ARGS(id, state, event, next_state, final_state)); + +DEFINE_EVENT(error_da_monitor_id, error_da_perobj_parent, + TP_PROTO(int id, char *state, char *event), + TP_ARGS(id, state, event)); +#endif /* CONFIG_RV_MON_DA_PEROBJ_PARENT */ diff --git a/tools/verification/rvgen/tests/golden/da_pertask_desc/Kconfig = b/tools/verification/rvgen/tests/golden/da_pertask_desc/Kconfig new file mode 100644 index 000000000000..c6f350179098 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_pertask_desc/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_DA_PERTASK_DESC + depends on RV + # XXX: add dependencies if there + select DA_MON_EVENTS_ID + bool "da_pertask_desc monitor" + help + Custom description for testing diff --git a/tools/verification/rvgen/tests/golden/da_pertask_desc/da_perta= sk_desc.c b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertas= k_desc.c new file mode 100644 index 000000000000..c1ae5078c4f9 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc= .c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "da_pertask_desc" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#define RV_MON_TYPE RV_MON_PER_TASK +#include "da_pertask_desc.h" +#include + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + * + */ +static void handle_event_1(void *data, /* XXX: fill header */) +{ + /* XXX: validate that this event is only valid in the initial state */ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_start_run_event(p, event_1_da_pertask_desc); +} + +static void handle_event_2(void *data, /* XXX: fill header */) +{ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_event(p, event_2_da_pertask_desc); +} + +static void handle_event_3(void *data, /* XXX: fill header */) +{ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_event(p, event_3_da_pertask_desc); +} + +static int enable_da_pertask_desc(void) +{ + int retval; + + retval =3D da_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("da_pertask_desc", /* XXX: tracepoint */, handle_ev= ent_1); + rv_attach_trace_probe("da_pertask_desc", /* XXX: tracepoint */, handle_ev= ent_2); + rv_attach_trace_probe("da_pertask_desc", /* XXX: tracepoint */, handle_ev= ent_3); + + return 0; +} + +static void disable_da_pertask_desc(void) +{ + rv_this.enabled =3D 0; + + rv_detach_trace_probe("da_pertask_desc", /* XXX: tracepoint */, handle_ev= ent_1); + rv_detach_trace_probe("da_pertask_desc", /* XXX: tracepoint */, handle_ev= ent_2); + rv_detach_trace_probe("da_pertask_desc", /* XXX: tracepoint */, handle_ev= ent_3); + + da_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "da_pertask_desc", + .description =3D "Custom description for testing", + .enable =3D enable_da_pertask_desc, + .disable =3D disable_da_pertask_desc, + .reset =3D da_monitor_reset_all, + .enabled =3D 0, +}; + +static int __init register_da_pertask_desc(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_da_pertask_desc(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_da_pertask_desc); +module_exit(unregister_da_pertask_desc); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("da_pertask_desc: Custom description for testing"); diff --git a/tools/verification/rvgen/tests/golden/da_pertask_desc/da_perta= sk_desc.h b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertas= k_desc.h new file mode 100644 index 000000000000..837b238754b0 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc= .h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Automatically generated C representation of da_pertask_desc automaton + * For further information about this format, see kernel documentation: + * Documentation/trace/rv/deterministic_automata.rst + */ + +#define MONITOR_NAME da_pertask_desc + +enum states_da_pertask_desc { + state_a_da_pertask_desc, + state_b_da_pertask_desc, + state_c_da_pertask_desc, + state_max_da_pertask_desc, +}; + +#define INVALID_STATE state_max_da_pertask_desc + +enum events_da_pertask_desc { + event_1_da_pertask_desc, + event_2_da_pertask_desc, + event_3_da_pertask_desc, + event_max_da_pertask_desc, +}; + +struct automaton_da_pertask_desc { + char *state_names[state_max_da_pertask_desc]; + char *event_names[event_max_da_pertask_desc]; + unsigned char function[state_max_da_pertask_desc][event_max_da_pertask_de= sc]; + unsigned char initial_state; + bool final_states[state_max_da_pertask_desc]; +}; + +static const struct automaton_da_pertask_desc automaton_da_pertask_desc = =3D { + .state_names =3D { + "state_a", + "state_b", + "state_c", + }, + .event_names =3D { + "event_1", + "event_2", + "event_3", + }, + .function =3D { + { + state_b_da_pertask_desc, + state_c_da_pertask_desc, + INVALID_STATE, + }, + { + INVALID_STATE, + state_a_da_pertask_desc, + state_c_da_pertask_desc, + }, + { + INVALID_STATE, + INVALID_STATE, + INVALID_STATE, + }, + }, + .initial_state =3D state_a_da_pertask_desc, + .final_states =3D { 1, 0, 0 }, +}; diff --git a/tools/verification/rvgen/tests/golden/da_pertask_desc/da_perta= sk_desc_trace.h b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_= pertask_desc_trace.h new file mode 100644 index 000000000000..4e6086c4d86e --- /dev/null +++ b/tools/verification/rvgen/tests/golden/da_pertask_desc/da_pertask_desc= _trace.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_DA_PERTASK_DESC +DEFINE_EVENT(event_da_monitor_id, event_da_pertask_desc, + TP_PROTO(int id, char *state, char *event, char *next_state, bool fi= nal_state), + TP_ARGS(id, state, event, next_state, final_state)); + +DEFINE_EVENT(error_da_monitor_id, error_da_pertask_desc, + TP_PROTO(int id, char *state, char *event), + TP_ARGS(id, state, event)); +#endif /* CONFIG_RV_MON_DA_PERTASK_DESC */ diff --git a/tools/verification/rvgen/tests/golden/ha_percpu/Kconfig b/tool= s/verification/rvgen/tests/golden/ha_percpu/Kconfig new file mode 100644 index 000000000000..0cc185ccfddf --- /dev/null +++ b/tools/verification/rvgen/tests/golden/ha_percpu/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_HA_PERCPU + depends on RV + # XXX: add dependencies if there + select HA_MON_EVENTS_IMPLICIT + bool "ha_percpu monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.c b/= tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.c new file mode 100644 index 000000000000..f61b2eae691a --- /dev/null +++ b/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.c @@ -0,0 +1,244 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "ha_percpu" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#define RV_MON_TYPE RV_MON_PER_CPU +/* XXX: If the monitor has several instances, consider HA_TIMER_WHEEL */ +#define HA_TIMER_TYPE HA_TIMER_HRTIMER +#include "ha_percpu.h" +#include + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + * + */ +#define BAR_NS(ha_mon) /* XXX: what is BAR_NS(ha_mon)? */ + +#define FOO_NS /* XXX: what is FOO_NS? */ + +static inline u64 bar_ns(struct ha_monitor *ha_mon) +{ + return /* XXX: what is bar_ns(ha_mon)? */; +} + +static u64 foo_ns =3D /* XXX: default value */; +module_param(foo_ns, ullong, 0644); + +/* + * These functions define how to read and reset the environment variable. + * + * Common environment variables like ns-based and jiffy-based clocks have + * pre-define getters and resetters you can use. The parser can infer the = type + * of the environment variable if you supply a measure unit in the constra= int. + * If you define your own functions, make sure to add appropriate memory + * barriers if required. + * Some environment variables don't require a storage as they read a system + * state (e.g. preemption count). Those variables are never reset, so we d= on't + * define a reset function on monitors only relying on this type of variab= les. + */ +static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs_ha_percpu env, = u64 time_ns) +{ + if (env =3D=3D clk_ha_percpu) + return ha_get_clk_ns(ha_mon, env, time_ns); + else if (env =3D=3D env1_ha_percpu) + return /* XXX: how do I read env1? */ + else if (env =3D=3D env2_ha_percpu) + return /* XXX: how do I read env2? */ + return ENV_INVALID_VALUE; +} + +static void ha_reset_env(struct ha_monitor *ha_mon, enum envs_ha_percpu en= v, u64 time_ns) +{ + if (env =3D=3D clk_ha_percpu) + ha_reset_clk_ns(ha_mon, env, time_ns); +} + +/* + * These functions are used to validate state transitions. + * + * They are generated by parsing the model, there is usually no need to ch= ange them. + * If the monitor requires a timer, there are functions responsible to arm= it when + * the next state has a constraint, cancel it in any other case and to che= ck + * that it didn't expire before the callback run. Transitions to the same = state + * without a reset never affect timers. + * Due to the different representations between invariants and guards, the= re is + * a function to convert it in case invariants or guards are reachable from + * another invariant without reset. Those are not present if not required = in + * the model. This is all automatic but is worth checking because it may s= how + * errors in the model (e.g. missing resets). + */ +static inline bool ha_verify_invariants(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (curr_state =3D=3D S0_ha_percpu) + return ha_check_invariant_ns(ha_mon, clk_ha_percpu, time_ns); + else if (curr_state =3D=3D S2_ha_percpu) + return ha_check_invariant_ns(ha_mon, clk_ha_percpu, time_ns); + return true; +} + +static inline void ha_convert_inv_guard(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (curr_state =3D=3D next_state) + return; + if (curr_state =3D=3D S2_ha_percpu) + ha_inv_to_guard(ha_mon, clk_ha_percpu, BAR_NS(ha_mon), time_ns); +} + +static inline bool ha_verify_guards(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + bool res =3D true; + + if (curr_state =3D=3D S0_ha_percpu && event =3D=3D event0_ha_percpu) + ha_reset_env(ha_mon, clk_ha_percpu, time_ns); + else if (curr_state =3D=3D S0_ha_percpu && event =3D=3D event1_ha_percpu) + ha_reset_env(ha_mon, clk_ha_percpu, time_ns); + else if (curr_state =3D=3D S1_ha_percpu && event =3D=3D event0_ha_percpu) + ha_reset_env(ha_mon, clk_ha_percpu, time_ns); + else if (curr_state =3D=3D S1_ha_percpu && event =3D=3D event2_ha_percpu)= { + res =3D ha_get_env(ha_mon, env1_ha_percpu, time_ns) =3D=3D 0ull; + ha_reset_env(ha_mon, clk_ha_percpu, time_ns); + } else if (curr_state =3D=3D S2_ha_percpu && event =3D=3D event1_ha_percp= u) + res =3D ha_monitor_env_invalid(ha_mon, clk_ha_percpu) || + ha_get_env(ha_mon, clk_ha_percpu, time_ns) < foo_ns; + else if (curr_state =3D=3D S3_ha_percpu && event =3D=3D event0_ha_percpu) + res =3D ha_monitor_env_invalid(ha_mon, clk_ha_percpu) || + (ha_get_env(ha_mon, clk_ha_percpu, time_ns) < FOO_NS && + ha_get_env(ha_mon, env2_ha_percpu, time_ns) =3D=3D 0ull); + else if (curr_state =3D=3D S3_ha_percpu && event =3D=3D event1_ha_percpu)= { + res =3D ha_monitor_env_invalid(ha_mon, clk_ha_percpu) || + (ha_get_env(ha_mon, clk_ha_percpu, time_ns) < 5000ull && + ha_get_env(ha_mon, env1_ha_percpu, time_ns) =3D=3D 1ull); + ha_reset_env(ha_mon, clk_ha_percpu, time_ns); + } + return res; +} + +static inline void ha_setup_invariants(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (next_state =3D=3D curr_state && event !=3D event0_ha_percpu) + return; + if (next_state =3D=3D S0_ha_percpu) + ha_start_timer_ns(ha_mon, clk_ha_percpu, bar_ns(ha_mon), time_ns); + else if (next_state =3D=3D S2_ha_percpu) + ha_start_timer_ns(ha_mon, clk_ha_percpu, BAR_NS(ha_mon), time_ns); + else if (curr_state =3D=3D S0_ha_percpu) + ha_cancel_timer(ha_mon); + else if (curr_state =3D=3D S2_ha_percpu) + ha_cancel_timer(ha_mon); +} + +static bool ha_verify_constraint(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (!ha_verify_invariants(ha_mon, curr_state, event, next_state, time_ns)) + return false; + + ha_convert_inv_guard(ha_mon, curr_state, event, next_state, time_ns); + + if (!ha_verify_guards(ha_mon, curr_state, event, next_state, time_ns)) + return false; + + ha_setup_invariants(ha_mon, curr_state, event, next_state, time_ns); + + return true; +} + +static void handle_event0(void *data, /* XXX: fill header */) +{ + /* XXX: validate that this event always leads to the initial state */ + da_handle_start_event(event0_ha_percpu); +} + +static void handle_event1(void *data, /* XXX: fill header */) +{ + da_handle_event(event1_ha_percpu); +} + +static void handle_event2(void *data, /* XXX: fill header */) +{ + da_handle_event(event2_ha_percpu); +} + +static int enable_ha_percpu(void) +{ + int retval; + + retval =3D ha_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("ha_percpu", /* XXX: tracepoint */, handle_event0); + rv_attach_trace_probe("ha_percpu", /* XXX: tracepoint */, handle_event1); + rv_attach_trace_probe("ha_percpu", /* XXX: tracepoint */, handle_event2); + + return 0; +} + +static void disable_ha_percpu(void) +{ + rv_this.enabled =3D 0; + + rv_detach_trace_probe("ha_percpu", /* XXX: tracepoint */, handle_event0); + rv_detach_trace_probe("ha_percpu", /* XXX: tracepoint */, handle_event1); + rv_detach_trace_probe("ha_percpu", /* XXX: tracepoint */, handle_event2); + + ha_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "ha_percpu", + .description =3D "auto-generated", + .enable =3D enable_ha_percpu, + .disable =3D disable_ha_percpu, + .reset =3D da_monitor_reset_all, + .enabled =3D 0, +}; + +static int __init register_ha_percpu(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_ha_percpu(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_ha_percpu); +module_exit(unregister_ha_percpu); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("ha_percpu: auto-generated"); diff --git a/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h b/= tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h new file mode 100644 index 000000000000..2538db4f6a26 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Automatically generated C representation of ha_percpu automaton + * For further information about this format, see kernel documentation: + * Documentation/trace/rv/deterministic_automata.rst + */ + +#define MONITOR_NAME ha_percpu + +enum states_ha_percpu { + S0_ha_percpu, + S1_ha_percpu, + S2_ha_percpu, + S3_ha_percpu, + state_max_ha_percpu, +}; + +#define INVALID_STATE state_max_ha_percpu + +enum events_ha_percpu { + event0_ha_percpu, + event1_ha_percpu, + event2_ha_percpu, + event_max_ha_percpu, +}; + +enum envs_ha_percpu { + clk_ha_percpu, + env1_ha_percpu, + env2_ha_percpu, + env_max_ha_percpu, + env_max_stored_ha_percpu =3D env1_ha_percpu, +}; + +_Static_assert(env_max_stored_ha_percpu <=3D MAX_HA_ENV_LEN, "Not enough s= lots"); +#define HA_CLK_NS + +struct automaton_ha_percpu { + char *state_names[state_max_ha_percpu]; + char *event_names[event_max_ha_percpu]; + char *env_names[env_max_ha_percpu]; + unsigned char function[state_max_ha_percpu][event_max_ha_percpu]; + unsigned char initial_state; + bool final_states[state_max_ha_percpu]; +}; + +static const struct automaton_ha_percpu automaton_ha_percpu =3D { + .state_names =3D { + "S0", + "S1", + "S2", + "S3", + }, + .event_names =3D { + "event0", + "event1", + "event2", + }, + .env_names =3D { + "clk", + "env1", + "env2", + }, + .function =3D { + { S0_ha_percpu, S1_ha_percpu, INVALID_ST= ATE }, + { S0_ha_percpu, INVALID_STATE, S2_ha_per= cpu }, + { INVALID_STATE, S2_ha_percpu, S3_ha_per= cpu }, + { S0_ha_percpu, S1_ha_percpu, INVALID_ST= ATE }, + }, + .initial_state =3D S0_ha_percpu, + .final_states =3D { 1, 0, 0, 0 }, +}; diff --git a/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trac= e.h b/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trace.h new file mode 100644 index 000000000000..074ddff6a60d --- /dev/null +++ b/tools/verification/rvgen/tests/golden/ha_percpu/ha_percpu_trace.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_HA_PERCPU +DEFINE_EVENT(event_da_monitor, event_ha_percpu, + TP_PROTO(char *state, char *event, char *next_state, bool final_stat= e), + TP_ARGS(state, event, next_state, final_state)); + +DEFINE_EVENT(error_da_monitor, error_ha_percpu, + TP_PROTO(char *state, char *event), + TP_ARGS(state, event)); + +DEFINE_EVENT(error_env_da_monitor, error_env_ha_percpu, + TP_PROTO(char *state, char *event, char *env), + TP_ARGS(state, event, env)); +#endif /* CONFIG_RV_MON_HA_PERCPU */ diff --git a/tools/verification/rvgen/tests/golden/ltl_pertask/Kconfig b/to= ols/verification/rvgen/tests/golden/ltl_pertask/Kconfig new file mode 100644 index 000000000000..b37f46670bfd --- /dev/null +++ b/tools/verification/rvgen/tests/golden/ltl_pertask/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_LTL_PERTASK + depends on RV + # XXX: add dependencies if there + select LTL_MON_EVENTS_ID + bool "ltl_pertask monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask.= c b/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask.c new file mode 100644 index 000000000000..2c60b5c5b4e0 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "ltl_pertask" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#include "ltl_pertask.h" +#include + +static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *= mon) +{ + /* + * This is called everytime the Buchi automaton is triggered. + * + * This function could be used to fetch the atomic propositions which + * are expensive to trace. It is possible only if the atomic proposition + * does not need to be updated at precise time. + * + * It is recommended to use tracepoints and ltl_atom_update() instead. + */ +} + +static void ltl_atoms_init(struct task_struct *task, struct ltl_monitor *m= on, bool task_creation) +{ + /* + * This should initialize as many atomic propositions as possible. + * + * @task_creation indicates whether the task is being created. This is + * false if the task is already running before the monitor is enabled. + */ + ltl_atom_set(mon, LTL_EVENT_A, true/false); + ltl_atom_set(mon, LTL_EVENT_B, true/false); +} + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + */ +static void handle_example_event(void *data, /* XXX: fill header */) +{ + ltl_atom_update(task, LTL_EVENT_A, true/false); +} + +static int enable_ltl_pertask(void) +{ + int retval; + + retval =3D ltl_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("ltl_pertask", /* XXX: tracepoint */, handle_exampl= e_event); + + return 0; +} + +static void disable_ltl_pertask(void) +{ + rv_detach_trace_probe("ltl_pertask", /* XXX: tracepoint */, handle_exampl= e_event); + + ltl_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "ltl_pertask", + .description =3D "auto-generated", + .enable =3D enable_ltl_pertask, + .disable =3D disable_ltl_pertask, +}; + +static int __init register_ltl_pertask(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_ltl_pertask(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_ltl_pertask); +module_exit(unregister_ltl_pertask); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("ltl_pertask: auto-generated"); diff --git a/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask.= h b/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask.h new file mode 100644 index 000000000000..7e5de351b8fa --- /dev/null +++ b/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * C implementation of Buchi automaton, automatically generated by + * tools/verification/rvgen from the linear temporal logic specification. + * For further information, see kernel documentation: + * Documentation/trace/rv/linear_temporal_logic.rst + */ + +#include + +#define MONITOR_NAME ltl_pertask + +enum ltl_atom { + LTL_EVENT_A, + LTL_EVENT_B, + LTL_NUM_ATOM +}; +static_assert(LTL_NUM_ATOM <=3D RV_MAX_LTL_ATOM); + +static const char *ltl_atom_str(enum ltl_atom atom) +{ + static const char *const names[] =3D { + "ev_a", + "ev_b", + }; + + return names[atom]; +} + +enum ltl_buchi_state { + S0, + S1, + S2, + S3, + S4, + RV_NUM_BA_STATES +}; +static_assert(RV_NUM_BA_STATES <=3D RV_MAX_BA_STATES); + +static void ltl_start(struct task_struct *task, struct ltl_monitor *mon) +{ + bool event_b =3D test_bit(LTL_EVENT_B, mon->atoms); + bool event_a =3D test_bit(LTL_EVENT_A, mon->atoms); + bool val1 =3D !event_a; + + if (val1) + __set_bit(S0, mon->states); + if (true) + __set_bit(S1, mon->states); + if (event_b) + __set_bit(S4, mon->states); +} + +static void +ltl_possible_next_states(struct ltl_monitor *mon, unsigned int state, unsi= gned long *next) +{ + bool event_b =3D test_bit(LTL_EVENT_B, mon->atoms); + bool event_a =3D test_bit(LTL_EVENT_A, mon->atoms); + bool val1 =3D !event_a; + + switch (state) { + case S0: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + case S1: + if (true) + __set_bit(S1, next); + if (true && val1) + __set_bit(S2, next); + if (event_b && val1) + __set_bit(S3, next); + if (event_b) + __set_bit(S4, next); + break; + case S2: + if (true) + __set_bit(S1, next); + if (true && val1) + __set_bit(S2, next); + if (event_b && val1) + __set_bit(S3, next); + if (event_b) + __set_bit(S4, next); + break; + case S3: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + case S4: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + } +} diff --git a/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_= trace.h b/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_tra= ce.h new file mode 100644 index 000000000000..ebd53621a5b1 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/ltl_pertask/ltl_pertask_trace.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_LTL_PERTASK +DEFINE_EVENT(event_ltl_monitor_id, event_ltl_pertask, + TP_PROTO(struct task_struct *task, char *states, char *atoms, char *= next), + TP_ARGS(task, states, atoms, next)); +DEFINE_EVENT(error_ltl_monitor_id, error_ltl_pertask, + TP_PROTO(struct task_struct *task), + TP_ARGS(task)); +#endif /* CONFIG_RV_MON_LTL_PERTASK */ diff --git a/tools/verification/rvgen/tests/golden/test_container/Kconfig b= /tools/verification/rvgen/tests/golden/test_container/Kconfig new file mode 100644 index 000000000000..2becb65dddad --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_container/Kconfig @@ -0,0 +1,5 @@ +config RV_MON_TEST_CONTAINER + depends on RV + bool "test_container monitor" + help + Test container for grouping monitors diff --git a/tools/verification/rvgen/tests/golden/test_container/test_cont= ainer.c b/tools/verification/rvgen/tests/golden/test_container/test_contain= er.c new file mode 100644 index 000000000000..e7e34592c6c5 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_container/test_container.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +#define MODULE_NAME "test_container" + +#include "test_container.h" + +struct rv_monitor rv_test_container =3D { + .name =3D "test_container", + .description =3D "Test container for grouping monitors", + .enable =3D NULL, + .disable =3D NULL, + .reset =3D NULL, + .enabled =3D 0, +}; + +static int __init register_test_container(void) +{ + return rv_register_monitor(&rv_test_container, NULL); +} + +static void __exit unregister_test_container(void) +{ + rv_unregister_monitor(&rv_test_container); +} + +module_init(register_test_container); +module_exit(unregister_test_container); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("test_container: Test container for grouping monitors"); diff --git a/tools/verification/rvgen/tests/golden/test_container/test_cont= ainer.h b/tools/verification/rvgen/tests/golden/test_container/test_contain= er.h new file mode 100644 index 000000000000..83e434432650 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_container/test_container.h @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +extern struct rv_monitor rv_test_container; diff --git a/tools/verification/rvgen/tests/golden/test_da/Kconfig b/tools/= verification/rvgen/tests/golden/test_da/Kconfig new file mode 100644 index 000000000000..0143a148ef34 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_TEST_DA + depends on RV + # XXX: add dependencies if there + select DA_MON_EVENTS_IMPLICIT + bool "test_da monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/test_da/test_da.c b/tool= s/verification/rvgen/tests/golden/test_da/test_da.c new file mode 100644 index 000000000000..59b8dfabbbf1 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da/test_da.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "test_da" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#define RV_MON_TYPE RV_MON_PER_CPU +#include "test_da.h" +#include + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + * + */ +static void handle_event_1(void *data, /* XXX: fill header */) +{ + da_handle_event(event_1_test_da); +} + +static void handle_event_2(void *data, /* XXX: fill header */) +{ + /* XXX: validate that this event always leads to the initial state */ + da_handle_start_event(event_2_test_da); +} + +static int enable_test_da(void) +{ + int retval; + + retval =3D da_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("test_da", /* XXX: tracepoint */, handle_event_1); + rv_attach_trace_probe("test_da", /* XXX: tracepoint */, handle_event_2); + + return 0; +} + +static void disable_test_da(void) +{ + rv_this.enabled =3D 0; + + rv_detach_trace_probe("test_da", /* XXX: tracepoint */, handle_event_1); + rv_detach_trace_probe("test_da", /* XXX: tracepoint */, handle_event_2); + + da_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "test_da", + .description =3D "auto-generated", + .enable =3D enable_test_da, + .disable =3D disable_test_da, + .reset =3D da_monitor_reset_all, + .enabled =3D 0, +}; + +static int __init register_test_da(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_test_da(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_test_da); +module_exit(unregister_test_da); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("test_da: auto-generated"); diff --git a/tools/verification/rvgen/tests/golden/test_da/test_da.h b/tool= s/verification/rvgen/tests/golden/test_da/test_da.h new file mode 100644 index 000000000000..d55795efbb61 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da/test_da.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Automatically generated C representation of test_da automaton + * For further information about this format, see kernel documentation: + * Documentation/trace/rv/deterministic_automata.rst + */ + +#define MONITOR_NAME test_da + +enum states_test_da { + state_a_test_da, + state_b_test_da, + state_max_test_da, +}; + +#define INVALID_STATE state_max_test_da + +enum events_test_da { + event_1_test_da, + event_2_test_da, + event_max_test_da, +}; + +struct automaton_test_da { + char *state_names[state_max_test_da]; + char *event_names[event_max_test_da]; + unsigned char function[state_max_test_da][event_max_test_da]; + unsigned char initial_state; + bool final_states[state_max_test_da]; +}; + +static const struct automaton_test_da automaton_test_da =3D { + .state_names =3D { + "state_a", + "state_b", + }, + .event_names =3D { + "event_1", + "event_2", + }, + .function =3D { + { state_b_test_da, state_a_test_da }, + { INVALID_STATE, state_a_test_da }, + }, + .initial_state =3D state_a_test_da, + .final_states =3D { 1, 0 }, +}; diff --git a/tools/verification/rvgen/tests/golden/test_da/test_da_trace.h = b/tools/verification/rvgen/tests/golden/test_da/test_da_trace.h new file mode 100644 index 000000000000..8bd67115d244 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da/test_da_trace.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_TEST_DA +DEFINE_EVENT(event_da_monitor, event_test_da, + TP_PROTO(char *state, char *event, char *next_state, bool final_stat= e), + TP_ARGS(state, event, next_state, final_state)); + +DEFINE_EVENT(error_da_monitor, error_test_da, + TP_PROTO(char *state, char *event), + TP_ARGS(state, event)); +#endif /* CONFIG_RV_MON_TEST_DA */ diff --git a/tools/verification/rvgen/tests/golden/test_ha/Kconfig b/tools/= verification/rvgen/tests/golden/test_ha/Kconfig new file mode 100644 index 000000000000..f4048290c774 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_TEST_HA + depends on RV + # XXX: add dependencies if there + select HA_MON_EVENTS_ID + bool "test_ha monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/test_ha/test_ha.c b/tool= s/verification/rvgen/tests/golden/test_ha/test_ha.c new file mode 100644 index 000000000000..900370428e5f --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha/test_ha.c @@ -0,0 +1,247 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "test_ha" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#define RV_MON_TYPE RV_MON_PER_TASK +/* XXX: If the monitor has several instances, consider HA_TIMER_WHEEL */ +#define HA_TIMER_TYPE HA_TIMER_HRTIMER +#include "test_ha.h" +#include + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + * + */ +#define BAR_NS(ha_mon) /* XXX: what is BAR_NS(ha_mon)? */ + +#define FOO_NS /* XXX: what is FOO_NS? */ + +static inline u64 bar_ns(struct ha_monitor *ha_mon) +{ + return /* XXX: what is bar_ns(ha_mon)? */; +} + +static u64 foo_ns =3D /* XXX: default value */; +module_param(foo_ns, ullong, 0644); + +/* + * These functions define how to read and reset the environment variable. + * + * Common environment variables like ns-based and jiffy-based clocks have + * pre-define getters and resetters you can use. The parser can infer the = type + * of the environment variable if you supply a measure unit in the constra= int. + * If you define your own functions, make sure to add appropriate memory + * barriers if required. + * Some environment variables don't require a storage as they read a system + * state (e.g. preemption count). Those variables are never reset, so we d= on't + * define a reset function on monitors only relying on this type of variab= les. + */ +static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs_test_ha env, u6= 4 time_ns) +{ + if (env =3D=3D clk_test_ha) + return ha_get_clk_ns(ha_mon, env, time_ns); + else if (env =3D=3D env1_test_ha) + return /* XXX: how do I read env1? */ + else if (env =3D=3D env2_test_ha) + return /* XXX: how do I read env2? */ + return ENV_INVALID_VALUE; +} + +static void ha_reset_env(struct ha_monitor *ha_mon, enum envs_test_ha env,= u64 time_ns) +{ + if (env =3D=3D clk_test_ha) + ha_reset_clk_ns(ha_mon, env, time_ns); +} + +/* + * These functions are used to validate state transitions. + * + * They are generated by parsing the model, there is usually no need to ch= ange them. + * If the monitor requires a timer, there are functions responsible to arm= it when + * the next state has a constraint, cancel it in any other case and to che= ck + * that it didn't expire before the callback run. Transitions to the same = state + * without a reset never affect timers. + * Due to the different representations between invariants and guards, the= re is + * a function to convert it in case invariants or guards are reachable from + * another invariant without reset. Those are not present if not required = in + * the model. This is all automatic but is worth checking because it may s= how + * errors in the model (e.g. missing resets). + */ +static inline bool ha_verify_invariants(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (curr_state =3D=3D S0_test_ha) + return ha_check_invariant_ns(ha_mon, clk_test_ha, time_ns); + else if (curr_state =3D=3D S2_test_ha) + return ha_check_invariant_ns(ha_mon, clk_test_ha, time_ns); + return true; +} + +static inline void ha_convert_inv_guard(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (curr_state =3D=3D next_state) + return; + if (curr_state =3D=3D S2_test_ha) + ha_inv_to_guard(ha_mon, clk_test_ha, BAR_NS(ha_mon), time_ns); +} + +static inline bool ha_verify_guards(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + bool res =3D true; + + if (curr_state =3D=3D S0_test_ha && event =3D=3D event0_test_ha) + ha_reset_env(ha_mon, clk_test_ha, time_ns); + else if (curr_state =3D=3D S0_test_ha && event =3D=3D event1_test_ha) + ha_reset_env(ha_mon, clk_test_ha, time_ns); + else if (curr_state =3D=3D S1_test_ha && event =3D=3D event0_test_ha) + ha_reset_env(ha_mon, clk_test_ha, time_ns); + else if (curr_state =3D=3D S1_test_ha && event =3D=3D event2_test_ha) { + res =3D ha_get_env(ha_mon, env1_test_ha, time_ns) =3D=3D 0ull; + ha_reset_env(ha_mon, clk_test_ha, time_ns); + } else if (curr_state =3D=3D S2_test_ha && event =3D=3D event1_test_ha) + res =3D ha_monitor_env_invalid(ha_mon, clk_test_ha) || + ha_get_env(ha_mon, clk_test_ha, time_ns) < foo_ns; + else if (curr_state =3D=3D S3_test_ha && event =3D=3D event0_test_ha) + res =3D ha_monitor_env_invalid(ha_mon, clk_test_ha) || + (ha_get_env(ha_mon, clk_test_ha, time_ns) < FOO_NS && + ha_get_env(ha_mon, env2_test_ha, time_ns) =3D=3D 0ull); + else if (curr_state =3D=3D S3_test_ha && event =3D=3D event1_test_ha) { + res =3D ha_monitor_env_invalid(ha_mon, clk_test_ha) || + (ha_get_env(ha_mon, clk_test_ha, time_ns) < 5000ull && + ha_get_env(ha_mon, env1_test_ha, time_ns) =3D=3D 1ull); + ha_reset_env(ha_mon, clk_test_ha, time_ns); + } + return res; +} + +static inline void ha_setup_invariants(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (next_state =3D=3D curr_state && event !=3D event0_test_ha) + return; + if (next_state =3D=3D S0_test_ha) + ha_start_timer_ns(ha_mon, clk_test_ha, bar_ns(ha_mon), time_ns); + else if (next_state =3D=3D S2_test_ha) + ha_start_timer_ns(ha_mon, clk_test_ha, BAR_NS(ha_mon), time_ns); + else if (curr_state =3D=3D S0_test_ha) + ha_cancel_timer(ha_mon); + else if (curr_state =3D=3D S2_test_ha) + ha_cancel_timer(ha_mon); +} + +static bool ha_verify_constraint(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (!ha_verify_invariants(ha_mon, curr_state, event, next_state, time_ns)) + return false; + + ha_convert_inv_guard(ha_mon, curr_state, event, next_state, time_ns); + + if (!ha_verify_guards(ha_mon, curr_state, event, next_state, time_ns)) + return false; + + ha_setup_invariants(ha_mon, curr_state, event, next_state, time_ns); + + return true; +} + +static void handle_event0(void *data, /* XXX: fill header */) +{ + /* XXX: validate that this event always leads to the initial state */ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_start_event(p, event0_test_ha); +} + +static void handle_event1(void *data, /* XXX: fill header */) +{ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_event(p, event1_test_ha); +} + +static void handle_event2(void *data, /* XXX: fill header */) +{ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_event(p, event2_test_ha); +} + +static int enable_test_ha(void) +{ + int retval; + + retval =3D ha_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("test_ha", /* XXX: tracepoint */, handle_event0); + rv_attach_trace_probe("test_ha", /* XXX: tracepoint */, handle_event1); + rv_attach_trace_probe("test_ha", /* XXX: tracepoint */, handle_event2); + + return 0; +} + +static void disable_test_ha(void) +{ + rv_this.enabled =3D 0; + + rv_detach_trace_probe("test_ha", /* XXX: tracepoint */, handle_event0); + rv_detach_trace_probe("test_ha", /* XXX: tracepoint */, handle_event1); + rv_detach_trace_probe("test_ha", /* XXX: tracepoint */, handle_event2); + + ha_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "test_ha", + .description =3D "auto-generated", + .enable =3D enable_test_ha, + .disable =3D disable_test_ha, + .reset =3D da_monitor_reset_all, + .enabled =3D 0, +}; + +static int __init register_test_ha(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_test_ha(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_test_ha); +module_exit(unregister_test_ha); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("test_ha: auto-generated"); diff --git a/tools/verification/rvgen/tests/golden/test_ha/test_ha.h b/tool= s/verification/rvgen/tests/golden/test_ha/test_ha.h new file mode 100644 index 000000000000..949fa4453403 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha/test_ha.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Automatically generated C representation of test_ha automaton + * For further information about this format, see kernel documentation: + * Documentation/trace/rv/deterministic_automata.rst + */ + +#define MONITOR_NAME test_ha + +enum states_test_ha { + S0_test_ha, + S1_test_ha, + S2_test_ha, + S3_test_ha, + state_max_test_ha, +}; + +#define INVALID_STATE state_max_test_ha + +enum events_test_ha { + event0_test_ha, + event1_test_ha, + event2_test_ha, + event_max_test_ha, +}; + +enum envs_test_ha { + clk_test_ha, + env1_test_ha, + env2_test_ha, + env_max_test_ha, + env_max_stored_test_ha =3D env1_test_ha, +}; + +_Static_assert(env_max_stored_test_ha <=3D MAX_HA_ENV_LEN, "Not enough slo= ts"); +#define HA_CLK_NS + +struct automaton_test_ha { + char *state_names[state_max_test_ha]; + char *event_names[event_max_test_ha]; + char *env_names[env_max_test_ha]; + unsigned char function[state_max_test_ha][event_max_test_ha]; + unsigned char initial_state; + bool final_states[state_max_test_ha]; +}; + +static const struct automaton_test_ha automaton_test_ha =3D { + .state_names =3D { + "S0", + "S1", + "S2", + "S3", + }, + .event_names =3D { + "event0", + "event1", + "event2", + }, + .env_names =3D { + "clk", + "env1", + "env2", + }, + .function =3D { + { S0_test_ha, S1_test_ha, INVALID_STATE }, + { S0_test_ha, INVALID_STATE, S2_test_ha }, + { INVALID_STATE, S2_test_ha, S3_test_ha }, + { S0_test_ha, S1_test_ha, INVALID_STATE }, + }, + .initial_state =3D S0_test_ha, + .final_states =3D { 1, 0, 0, 0 }, +}; diff --git a/tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h = b/tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h new file mode 100644 index 000000000000..381bafcb3322 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha/test_ha_trace.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_TEST_HA +DEFINE_EVENT(event_da_monitor_id, event_test_ha, + TP_PROTO(int id, char *state, char *event, char *next_state, bool fi= nal_state), + TP_ARGS(id, state, event, next_state, final_state)); + +DEFINE_EVENT(error_da_monitor_id, error_test_ha, + TP_PROTO(int id, char *state, char *event), + TP_ARGS(id, state, event)); + +DEFINE_EVENT(error_env_da_monitor_id, error_env_test_ha, + TP_PROTO(int id, char *state, char *event, char *env), + TP_ARGS(id, state, event, env)); +#endif /* CONFIG_RV_MON_TEST_HA */ diff --git a/tools/verification/rvgen/tests/golden/test_ltl/Kconfig b/tools= /verification/rvgen/tests/golden/test_ltl/Kconfig new file mode 100644 index 000000000000..e2d0e721f180 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_TEST_LTL + depends on RV + # XXX: add dependencies if there + depends on RV_MON_LTL_PARENT + default y + select LTL_MON_EVENTS_ID + bool "test_ltl monitor" + help + Simple description diff --git a/tools/verification/rvgen/tests/golden/test_ltl/test_ltl.c b/to= ols/verification/rvgen/tests/golden/test_ltl/test_ltl.c new file mode 100644 index 000000000000..dd961c5dc8ad --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl/test_ltl.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "test_ltl" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include +#include + + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#include "test_ltl.h" +#include + +static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *= mon) +{ + /* + * This is called everytime the Buchi automaton is triggered. + * + * This function could be used to fetch the atomic propositions which + * are expensive to trace. It is possible only if the atomic proposition + * does not need to be updated at precise time. + * + * It is recommended to use tracepoints and ltl_atom_update() instead. + */ +} + +static void ltl_atoms_init(struct task_struct *task, struct ltl_monitor *m= on, bool task_creation) +{ + /* + * This should initialize as many atomic propositions as possible. + * + * @task_creation indicates whether the task is being created. This is + * false if the task is already running before the monitor is enabled. + */ + ltl_atom_set(mon, LTL_EVENT_A, true/false); + ltl_atom_set(mon, LTL_EVENT_B, true/false); +} + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + */ +static void handle_example_event(void *data, /* XXX: fill header */) +{ + ltl_atom_update(task, LTL_EVENT_A, true/false); +} + +static int enable_test_ltl(void) +{ + int retval; + + retval =3D ltl_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("test_ltl", /* XXX: tracepoint */, handle_example_e= vent); + + return 0; +} + +static void disable_test_ltl(void) +{ + rv_detach_trace_probe("test_ltl", /* XXX: tracepoint */, handle_example_e= vent); + + ltl_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "test_ltl", + .description =3D "Simple description", + .enable =3D enable_test_ltl, + .disable =3D disable_test_ltl, +}; + +static int __init register_test_ltl(void) +{ + return rv_register_monitor(&rv_this, &rv_ltl_parent); +} + +static void __exit unregister_test_ltl(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_test_ltl); +module_exit(unregister_test_ltl); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("test_ltl: Simple description"); diff --git a/tools/verification/rvgen/tests/golden/test_ltl/test_ltl.h b/to= ols/verification/rvgen/tests/golden/test_ltl/test_ltl.h new file mode 100644 index 000000000000..7895f2e233e8 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl/test_ltl.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * C implementation of Buchi automaton, automatically generated by + * tools/verification/rvgen from the linear temporal logic specification. + * For further information, see kernel documentation: + * Documentation/trace/rv/linear_temporal_logic.rst + */ + +#include + +#define MONITOR_NAME test_ltl + +enum ltl_atom { + LTL_EVENT_A, + LTL_EVENT_B, + LTL_NUM_ATOM +}; +static_assert(LTL_NUM_ATOM <=3D RV_MAX_LTL_ATOM); + +static const char *ltl_atom_str(enum ltl_atom atom) +{ + static const char *const names[] =3D { + "ev_a", + "ev_b", + }; + + return names[atom]; +} + +enum ltl_buchi_state { + S0, + S1, + S2, + S3, + S4, + RV_NUM_BA_STATES +}; +static_assert(RV_NUM_BA_STATES <=3D RV_MAX_BA_STATES); + +static void ltl_start(struct task_struct *task, struct ltl_monitor *mon) +{ + bool event_b =3D test_bit(LTL_EVENT_B, mon->atoms); + bool event_a =3D test_bit(LTL_EVENT_A, mon->atoms); + bool val1 =3D !event_a; + + if (val1) + __set_bit(S0, mon->states); + if (true) + __set_bit(S1, mon->states); + if (event_b) + __set_bit(S4, mon->states); +} + +static void +ltl_possible_next_states(struct ltl_monitor *mon, unsigned int state, unsi= gned long *next) +{ + bool event_b =3D test_bit(LTL_EVENT_B, mon->atoms); + bool event_a =3D test_bit(LTL_EVENT_A, mon->atoms); + bool val1 =3D !event_a; + + switch (state) { + case S0: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + case S1: + if (true) + __set_bit(S1, next); + if (true && val1) + __set_bit(S2, next); + if (event_b && val1) + __set_bit(S3, next); + if (event_b) + __set_bit(S4, next); + break; + case S2: + if (true) + __set_bit(S1, next); + if (true && val1) + __set_bit(S2, next); + if (event_b && val1) + __set_bit(S3, next); + if (event_b) + __set_bit(S4, next); + break; + case S3: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + case S4: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + } +} diff --git a/tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.= h b/tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.h new file mode 100644 index 000000000000..3571b004c114 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl/test_ltl_trace.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_TEST_LTL +DEFINE_EVENT(event_ltl_monitor_id, event_test_ltl, + TP_PROTO(struct task_struct *task, char *states, char *atoms, char *= next), + TP_ARGS(task, states, atoms, next)); +DEFINE_EVENT(error_ltl_monitor_id, error_test_ltl, + TP_PROTO(struct task_struct *task), + TP_ARGS(task)); +#endif /* CONFIG_RV_MON_TEST_LTL */ diff --git a/tools/verification/rvgen/tests/specs/test_da.dot b/tools/verif= ication/rvgen/tests/specs/test_da.dot new file mode 100644 index 000000000000..e555c239b221 --- /dev/null +++ b/tools/verification/rvgen/tests/specs/test_da.dot @@ -0,0 +1,16 @@ +digraph state_automaton { + {node [shape =3D circle] "state_b"}; + {node [shape =3D plaintext, style=3Dinvis, label=3D""] "__init_state_a"}; + {node [shape =3D doublecircle] "state_a"}; + {node [shape =3D circle] "state_a"}; + "__init_state_a" -> "state_a"; + "state_a" [label =3D "state_a"]; + "state_a" -> "state_a" [ label =3D "event_2" ]; + "state_a" -> "state_b" [ label =3D "event_1" ]; + "state_b" [label =3D "state_b"]; + "state_b" -> "state_a" [ label =3D "event_2" ]; + { rank =3D min ; + "__init_state_a"; + "state_a"; + } +} diff --git a/tools/verification/rvgen/tests/specs/test_da2.dot b/tools/veri= fication/rvgen/tests/specs/test_da2.dot new file mode 100644 index 000000000000..cdd4192f58ae --- /dev/null +++ b/tools/verification/rvgen/tests/specs/test_da2.dot @@ -0,0 +1,19 @@ +digraph state_automaton { + {node [shape =3D circle] "state_b"}; + {node [shape =3D circle] "state_c"}; + {node [shape =3D plaintext, style=3Dinvis, label=3D""] "__init_state_a"}; + {node [shape =3D doublecircle] "state_a"}; + {node [shape =3D circle] "state_a"}; + "__init_state_a" -> "state_a"; + "state_a" [label =3D "state_a"]; + "state_a" -> "state_b" [ label =3D "event_1" ]; + "state_a" -> "state_c" [ label =3D "event_2" ]; + "state_b" [label =3D "state_b"]; + "state_b" -> "state_a" [ label =3D "event_2" ]; + "state_b" -> "state_c" [ label =3D "event_3" ]; + "state_c" [label =3D "state_c"]; + { rank =3D min ; + "__init_state_a"; + "state_a"; + } +} diff --git a/tools/verification/rvgen/tests/specs/test_ha.dot b/tools/verif= ication/rvgen/tests/specs/test_ha.dot new file mode 100644 index 000000000000..af18ad7389ec --- /dev/null +++ b/tools/verification/rvgen/tests/specs/test_ha.dot @@ -0,0 +1,27 @@ +digraph state_automaton { + center =3D true; + size =3D "7,11"; + {node [shape =3D circle] "S1"}; + {node [shape =3D plaintext, style=3Dinvis, label=3D""] "__init_S0"}; + {node [shape =3D doublecircle] "S0"}; + {node [shape =3D circle] "S0"}; + {node [shape =3D circle] "S2"}; + {node [shape =3D circle] "S3"}; + "__init_S0" -> "S0"; + "S0" [label =3D "S0\nclk < bar_ns()", color =3D green3]; + "S1" [label =3D "S1"]; + "S2" [label =3D "S2\nclk < BAR_NS()"]; + "S3" [label =3D "S3"]; + "S1" -> "S0" [ label =3D "event0;reset(clk)" ]; + "S0" -> "S1" [ label =3D "event1;reset(clk)" ]; + "S0" -> "S0" [ label =3D "event0;reset(clk)" ]; + "S1" -> "S2" [ label =3D "event2;env1 =3D=3D 0;reset(clk)" ]; + "S2" -> "S3" [ label =3D "event2" ]; + "S2" -> "S2" [ label =3D "event1;clk < foo_ns" ]; + "S3" -> "S0" [ label =3D "event0;clk < FOO_NS && env2 =3D=3D 0" ]; + "S3" -> "S1" [ label =3D "event1;clk < 5us && env1 =3D=3D 1;reset(clk)" ]; + { rank =3D min ; + "__init_S0"; + "S0"; + } +} diff --git a/tools/verification/rvgen/tests/specs/test_invalid.dot b/tools/= verification/rvgen/tests/specs/test_invalid.dot new file mode 100644 index 000000000000..17c63fc57f17 --- /dev/null +++ b/tools/verification/rvgen/tests/specs/test_invalid.dot @@ -0,0 +1,8 @@ +digraph invalid { + {node [shape =3D circle] "init"}; + {node [shape =3D circle] "state1"}; + "init" [label =3D "init"]; + "init" -> "state1" [ label =3D "event_a" ]; + "state1" [label =3D "state1"]; + "state1" -> "init" [ label =3D "event_b" ]; +} diff --git a/tools/verification/rvgen/tests/specs/test_invalid.ltl b/tools/= verification/rvgen/tests/specs/test_invalid.ltl new file mode 100644 index 000000000000..cf36307e003c --- /dev/null +++ b/tools/verification/rvgen/tests/specs/test_invalid.ltl @@ -0,0 +1 @@ +RULE =3D A invalid B diff --git a/tools/verification/rvgen/tests/specs/test_invalid_ha.dot b/too= ls/verification/rvgen/tests/specs/test_invalid_ha.dot new file mode 100644 index 000000000000..06de6aa8709f --- /dev/null +++ b/tools/verification/rvgen/tests/specs/test_invalid_ha.dot @@ -0,0 +1,16 @@ +digraph state_automaton { + {node [shape =3D circle] "state_b"}; + {node [shape =3D plaintext, style=3Dinvis, label=3D""] "__init_state_a"}; + {node [shape =3D doublecircle] "state_a"}; + {node [shape =3D circle] "state_a"}; + "__init_state_a" -> "state_a"; + "state_a" [label =3D "state_a;clk < 1"]; + "state_a" -> "state_a" [ label =3D "event_2;reset(clk)" ]; + "state_a" -> "state_b" [ label =3D "event_1;wrong_constraint" ]; + "state_b" [label =3D "state_b"]; + "state_b" -> "state_a" [ label =3D "event_2" ]; + { rank =3D min ; + "__init_state_a"; + "state_a"; + } +} diff --git a/tools/verification/rvgen/tests/specs/test_ltl.ltl b/tools/veri= fication/rvgen/tests/specs/test_ltl.ltl new file mode 100644 index 000000000000..5ed658abd69c --- /dev/null +++ b/tools/verification/rvgen/tests/specs/test_ltl.ltl @@ -0,0 +1 @@ +RULE =3D always (EVENT_A imply eventually EVENT_B) --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 5A9C42C11E4 for ; Thu, 23 Jul 2026 07:46:48 +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=1784792810; cv=none; b=ZZk1yk4PAGl7gy7Q/uVTl9NjtEQMfAfXn30mQET1L4JCoyre3YBfJfGzQHqCQ5dCFxFYkJb4pBlo20hsaElUCL3kDrcft3X79h3p8j3TybambKYzkGHbVZc1/O3Wg+hLJs7UB7xjQN/33QBX5SEUlA3SGaCVKF7GF1m/yDgXYpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792810; c=relaxed/simple; bh=9sPLdkum2kWCCtOLzcn0klZI0PoIJRU8ohLPxFOoEbc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EaJCIt5E8xo0dCXJAHhBcwDo/QWhNo/SgtpRIUEn2L6Nr0SxgYUITKWhC51fzpKqDdnDxzlvtsRmqu7eu4z6w6vkJ56ACupyO8IPmPCYX6MSbaRxuSsU9fUjx5gOS4r0l46Qq6e7i5EPh0sFk9FWKHsPJG6nz5KJxY3mTirrd00= 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=Nk1A1OMe; 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="Nk1A1OMe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ICw0LxmziCf43DdT2yVS8sQfUszLZeUuGlgWCzPqF6U=; b=Nk1A1OMe/4veyd8Df2g5gLoUBlionT5V9VbtvFJtm42yUBNlsu1zM3ewKKRYyDwisM7kAi jPuHRt/+eHa2EBrZPo/dkskxcsDMpwFEAhXR/i1eytcTKRts66pbEmohp/h40iK+u0DtPv 5mVWsgOn12rKmP4+x98dam6fwrEdM+g= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-ELwuCGnEOOWvHUO1SxRvMA-1; Thu, 23 Jul 2026 03:46:41 -0400 X-MC-Unique: ELwuCGnEOOWvHUO1SxRvMA-1 X-Mimecast-MFC-AGG-ID: ELwuCGnEOOWvHUO1SxRvMA_1784792799 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B408119540CE; Thu, 23 Jul 2026 07:46:39 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AB761180029D; Thu, 23 Jul 2026 07:46:36 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Wen Yang , Thomas Weissschuh , Tomas Glozar , John Kacur Subject: [PATCH v5 08/17] verification/rvgen: Add selftests Date: Thu, 23 Jul 2026 09:45:25 +0200 Message-ID: <20260723074534.43521-9-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The rvgen code generator needs validation to ensure it produces correct monitor implementations from input specifications. Add selftests with golden reference outputs covering all monitor classes (DA, HA, LTL) and types (global, per_cpu, per_task, per_obj), including optional features like descriptions and parent monitors. Container generation and error handling (missing files, invalid specifications, missing arguments) are also validated against expected output. Acked-by: Nam Cao Reviewed-by: Wen Yang Signed-off-by: Gabriele Monaco --- tools/verification/rvgen/Makefile | 4 + .../rvgen/tests/rvgen_container.t | 20 +++++ .../verification/rvgen/tests/rvgen_monitor.t | 87 +++++++++++++++++++ tools/verification/tests/engine.sh | 34 ++++++++ 4 files changed, 145 insertions(+) create mode 100644 tools/verification/rvgen/tests/rvgen_container.t create mode 100644 tools/verification/rvgen/tests/rvgen_monitor.t diff --git a/tools/verification/rvgen/Makefile b/tools/verification/rvgen/M= akefile index cfc4056c1e87..2a2b9e64ea42 100644 --- a/tools/verification/rvgen/Makefile +++ b/tools/verification/rvgen/Makefile @@ -13,6 +13,10 @@ all: .PHONY: clean clean: =20 +.PHONY: check +check: + prove -o --directives -f tests/ + .PHONY: install install: $(INSTALL) rvgen/automata.py -D -m 644 $(DESTDIR)$(PYLIB)/rvgen/automata.= py diff --git a/tools/verification/rvgen/tests/rvgen_container.t b/tools/verif= ication/rvgen/tests/rvgen_container.t new file mode 100644 index 000000000000..fa4fb3db8288 --- /dev/null +++ b/tools/verification/rvgen/tests/rvgen_container.t @@ -0,0 +1,20 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source ../tests/engine.sh +test_begin + +set_timeout 30s + +# Help tests +check "verify container subcommand help" \ + "$RVGEN container -h" 0 "model_name" "class" + +check_and_compare_folder "container with description" \ + "$RVGEN container -n test_container -D 'Test container for grouping monit= ors'" \ + "test_container" "Writing the monitor into the directory test_container" + +# Error handling tests +check "missing required model_name" \ + "$RVGEN container" 2 "the following arguments are required: -n/--model_na= me" + +test_end diff --git a/tools/verification/rvgen/tests/rvgen_monitor.t b/tools/verific= ation/rvgen/tests/rvgen_monitor.t new file mode 100644 index 000000000000..261476504eee --- /dev/null +++ b/tools/verification/rvgen/tests/rvgen_monitor.t @@ -0,0 +1,87 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source ../tests/engine.sh +test_begin + +set_timeout 30s + +# Help and basic tests +check "verify help page" \ + "$RVGEN --help" 0 "Generate kernel rv monitor" + +check "verify monitor subcommand help" \ + "$RVGEN monitor --help" 0 "Monitor class" + +# DA monitor tests - test all monitor types +check_and_compare_folder "DA per_cpu (default name)" \ + "$RVGEN monitor -c da -s tests/specs/test_da.dot -t per_cpu" \ + "test_da" "obj-\$(CONFIG_RV_MON_TEST_DA) +=3D monitors/test_da/test_da.o" + +check_and_compare_folder "DA global type" \ + "$RVGEN monitor -c da -s tests/specs/test_da.dot -t global -n da_global" \ + "da_global" "DA_MON_EVENTS_IMPLICIT" + +check_and_compare_folder "DA per_task with description" \ + "$RVGEN monitor -c da -s tests/specs/test_da2.dot -t per_task -n da_perta= sk_desc -D 'Custom description for testing'" \ + "da_pertask_desc" "#include " + +check_and_compare_folder "DA per_obj with parent" \ + "$RVGEN monitor -c da -s tests/specs/test_da2.dot -t per_obj -n da_perobj= _parent -p parent_mon" \ + "da_perobj_parent" "DA_MON_EVENTS_ID" + +# HA monitor tests +check_and_compare_folder "HA per_task (default name)" \ + "$RVGEN monitor -c ha -s tests/specs/test_ha.dot -t per_task" \ + "test_ha" "HA_MON_EVENTS_ID" + +check_and_compare_folder "HA per_cpu type" \ + "$RVGEN monitor -c ha -s tests/specs/test_ha.dot -t per_cpu -n ha_percpu"= \ + "ha_percpu" "HA_MON_EVENTS_IMPLICIT" + +# LTL monitor test +check_and_compare_folder "LTL per_task" \ + "$RVGEN monitor -c ltl -s tests/specs/test_ltl.ltl -t per_task -n ltl_per= task" \ + "ltl_pertask" "source \"kernel/trace/rv/monitors/ltl_pertask/Kconfig\"" + +check_and_compare_folder "LTL per_task with parent and description (defaul= t name)" \ + "$RVGEN monitor -c ltl -s tests/specs/test_ltl.ltl -t per_task -p ltl_par= ent -D 'Simple description'" \ + "test_ltl" "LTL_MON_EVENTS_ID" + +# Error handling tests +check "missing required spec argument" \ + "$RVGEN monitor -c da -t per_cpu" 2 \ + "the following arguments are required: -s/--spec" "Traceback (most recent= call last)" + +check "missing required monitor type" \ + "$RVGEN monitor -c da -s tests/specs/test_da.dot" 2 \ + "the following arguments are required: -t/--monitor_type" "Traceback (mos= t recent call last)" + +check "missing required monitor class" \ + "$RVGEN monitor -s tests/specs/test_da.dot -t per_cpu" 2 \ + "the following arguments are required: -c/--class" "Traceback (most recen= t call last)" + +check "invalid monitor class" \ + "$RVGEN monitor -c invalid -s tests/specs/test_da.dot -t per_cpu" 1 \ + "Unknown monitor class" "Traceback (most recent call last)" + +check "missing dot file" \ + "$RVGEN monitor -c da -s tests/specs/nonexistent.dot -t per_cpu" 1 \ + "No such file or directory" "Traceback (most recent call last)" + +check "missing ltl file" \ + "$RVGEN monitor -c ltl -s tests/specs/nonexistent.ltl -t per_task" 1 \ + "No such file or directory" "Traceback (most recent call last)" + +check "invalid dot file syntax" \ + "$RVGEN monitor -c da -s tests/specs/test_invalid.dot -t per_cpu" 1 \ + "Not a valid .dot format" "Traceback (most recent call last)" + +check "invalid ha file syntax" \ + "$RVGEN monitor -c ha -s tests/specs/test_invalid_ha.dot -t per_obj" 1 \ + "Unrecognised event constraint" "Traceback (most recent call last)" + +check "invalid ltl file syntax" \ + "$RVGEN monitor -c ltl -s tests/specs/test_invalid.ltl -t per_task" 1 \ + "Illegal character 'i'" "Traceback (most recent call last)" + +test_end diff --git a/tools/verification/tests/engine.sh b/tools/verification/tests/= engine.sh index 57e16dc980b1..cfdf2180aad8 100644 --- a/tools/verification/tests/engine.sh +++ b/tools/verification/tests/engine.sh @@ -5,6 +5,8 @@ test_begin() { # included correctly. ctr=3D0 [ -z "$RV" ] && RV=3D"../rv/rv" + [ -z "$RVGEN" ] && RVGEN=3D"python3 ../rvgen" + [ -z "$GOLDEN_DIR" ] && GOLDEN_DIR=3D"tests/golden" [ -n "$TEST_COUNT" ] && echo "1..$TEST_COUNT" } =20 @@ -118,6 +120,38 @@ check_if_exists() { fi } =20 +check_and_compare_folder() { + # Run command, compare generated folder to golden, and cleanup + local desc=3D$1 + local command=3D$2 + local generated_dir=3D$3 + local expected_output=3D$4 + local unexpected_output=3D$5 + local golden_dir=3D"$GOLDEN_DIR/$generated_dir" + + ctr=3D$((ctr + 1)) + if [ -n "$TEST_COUNT" ]; then + rm -rf "$generated_dir" + _check "$desc" "$command" 0 "$expected_output" "$unexpected_output" + + if [ "$fail" -eq 0 ] && [ ! -d "$generated_dir" ]; then + failure "# Generated directory not found: $generated_dir" + fi + + if [ "$fail" -ne 0 ]; then + : + elif ! diff -r "$generated_dir" "$golden_dir" &> /dev/null; then + failure "# Directories differ:" + failbuf+=3D$(diff -r "$generated_dir" "$golden_dir" 2>&1 | sed 's/^/# = /') + failbuf+=3D$'\n' + fi + + report "$1" + + rm -rf "$generated_dir" + fi +} + set_timeout() { TIMEOUT=3D"timeout -v -k 30s $1" } --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 1321F35CB6A for ; Thu, 23 Jul 2026 07:46:50 +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=1784792812; cv=none; b=dKTULkQfHQsB2QoVGJRCXxlJNzaWLcCoO7bBzZwh5QnI5CBS2iZ+LywTc3M6isILBRsUMQ6saoBSOgEAKkOhC64c1glWlrMk14LZMuQ+O3fHjY0d2DDL68EUnAAITaXe8qzg0eKNQktcsxVfdOBVNK9uyBX8RWEk/H6rVcratcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792812; c=relaxed/simple; bh=A3xPmuJB8NnKzkkoKYweeWUvXQqDW7w8pYyKaeXY3L4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a+ATvr8ngje0GvcR9KS781lp+odwxGGH+Ve+74/4wi7xtlt4eJ3cpHPPjCWZxm+ffBCYCzqfkB2kivMWCLe7rEO/xbmGYdLCj1ZjAtQ8FlktHGb8QlkfYpbi5Ned8Ce+AgoxA5JZKTaJF5ERf95VGKMCbuu8Yl5yiSdyZVnW23k= 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=WPaWmUSU; 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="WPaWmUSU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GONDOah0g59wCvAm9TUKSXzD9ZNPiF5wKvAACqnf3JQ=; b=WPaWmUSUShl032R0XwhhxyEBLCza9B6i6yzHbVyKMNx926R04oXfhE70t/Sea7diQalKHs Jc5DzXpffqc7UKF9jW/xz2Xl4JKa+Dovmzx1KjnUsxSNCrbVWYarPcdRTR0VdIHIYensCU tJYVwhWC64fvcIzICfXHtYvfwfpOzxI= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-470-G3HbajlEOHO5xUk79OCtWg-1; Thu, 23 Jul 2026 03:46:45 -0400 X-MC-Unique: G3HbajlEOHO5xUk79OCtWg-1 X-Mimecast-MFC-AGG-ID: G3HbajlEOHO5xUk79OCtWg_1784792804 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 787D7197753D; Thu, 23 Jul 2026 07:46:44 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5739A180029A; Thu, 23 Jul 2026 07:46:41 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 09/17] verification/rvgen: Add the rvgen kunit subcommand Date: Thu, 23 Jul 2026 09:45:26 +0200 Message-ID: <20260723074534.43521-10-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Add the rvgen kunit subcommand to patch an already generated monitor for kunit support. It parses the handlers and create the necessary structs and initialisations. The only remaining manual steps are importing the test in the runner and writing the test itself. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- Notes: V4: * Use pathlib instead of os.path * Rename files to backup instead of writing to backup tools/verification/rvgen/Makefile | 1 + tools/verification/rvgen/__main__.py | 15 +- tools/verification/rvgen/rvgen/generator.py | 4 +- tools/verification/rvgen/rvgen/kunit.py | 194 ++++++++++++++++++ .../rvgen/rvgen/templates/kunit.c | 33 +++ 5 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 tools/verification/rvgen/rvgen/kunit.py create mode 100644 tools/verification/rvgen/rvgen/templates/kunit.c diff --git a/tools/verification/rvgen/Makefile b/tools/verification/rvgen/M= akefile index 2a2b9e64ea42..48d0376a5cc4 100644 --- a/tools/verification/rvgen/Makefile +++ b/tools/verification/rvgen/Makefile @@ -23,6 +23,7 @@ install: $(INSTALL) rvgen/dot2c.py -D -m 644 $(DESTDIR)$(PYLIB)/rvgen/dot2c.py $(INSTALL) dot2c -D -m 755 $(DESTDIR)$(bindir)/ $(INSTALL) rvgen/dot2k.py -D -m 644 $(DESTDIR)$(PYLIB)/rvgen/dot2k.py + $(INSTALL) rvgen/kunit.py -D -m 644 $(DESTDIR)$(PYLIB)/rvgen/kunit.py $(INSTALL) rvgen/container.py -D -m 644 $(DESTDIR)$(PYLIB)/rvgen/containe= r.py $(INSTALL) rvgen/generator.py -D -m 644 $(DESTDIR)$(PYLIB)/rvgen/generato= r.py $(INSTALL) rvgen/ltl2ba.py -D -m 644 $(DESTDIR)$(PYLIB)/rvgen/ltl2ba.py diff --git a/tools/verification/rvgen/__main__.py b/tools/verification/rvge= n/__main__.py index 5c923dc10d0f..e0ac562fbddd 100644 --- a/tools/verification/rvgen/__main__.py +++ b/tools/verification/rvgen/__main__.py @@ -13,6 +13,7 @@ if __name__ =3D=3D '__main__': from rvgen.generator import Monitor from rvgen.container import Container from rvgen.ltl2k import ltl2k + from rvgen.kunit import KUnit, KUnitError from rvgen.automata import AutomataError import argparse import sys @@ -41,6 +42,11 @@ if __name__ =3D=3D '__main__': container_parser =3D subparsers.add_parser("container", parents=3D[par= ent_parser]) container_parser.add_argument('-n', "--model_name", dest=3D"model_name= ", required=3DTrue) =20 + kunit_parser =3D subparsers.add_parser("kunit", parents=3D[parent_pars= er]) + kunit_parser.add_argument('-n', "--model_name", dest=3D"model_name", r= equired=3DTrue) + kunit_parser.add_argument('-l', "--local", dest=3D"local", action=3D"s= tore_true", required=3DFalse, + help=3D"Force looking for the monitor in th= e current directory only") + params =3D parser.parse_args() =20 try: @@ -55,11 +61,18 @@ if __name__ =3D=3D '__main__': else: print("Unknown monitor class:", params.monitor_class) sys.exit(1) - else: + elif params.subcmd =3D=3D "container": monitor =3D Container(vars(params)) + elif params.subcmd =3D=3D "kunit": + monitor =3D KUnit(vars(params)) + monitor.print_files() + sys.exit(0) except AutomataError as e: print(f"There was an error processing {params.spec}: {e}", file=3D= sys.stderr) sys.exit(1) + except KUnitError as e: + print(f"There was an error generating KUnit files: {e}", file=3Dsy= s.stderr) + sys.exit(1) =20 print(f"Writing the monitor into the directory {monitor.name}") monitor.print_files() diff --git a/tools/verification/rvgen/rvgen/generator.py b/tools/verificati= on/rvgen/rvgen/generator.py index f1b37d34b1e9..45e2bab26cb5 100644 --- a/tools/verification/rvgen/rvgen/generator.py +++ b/tools/verification/rvgen/rvgen/generator.py @@ -22,9 +22,9 @@ class RVGenerator: self.description =3D extra_params.get("description", self.name) or= "auto-generated" self.auto_patch =3D extra_params.get("auto_patch") if self.auto_patch: - self.__fill_rv_kernel_dir() + self._fill_rv_kernel_dir() =20 - def __fill_rv_kernel_dir(self): + def _fill_rv_kernel_dir(self): # find the kernel tree root relative to this file's location resolved_path =3D Path(__file__).resolve() if len(resolved_path.parents) > 4: diff --git a/tools/verification/rvgen/rvgen/kunit.py b/tools/verification/r= vgen/rvgen/kunit.py new file mode 100644 index 000000000000..ed2082d7d3bc --- /dev/null +++ b/tools/verification/rvgen/rvgen/kunit.py @@ -0,0 +1,194 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2026-2029 Red Hat, Inc. Gabriele Monaco +# +# Generator for runtime verification kunit files + +import re +from pathlib import Path +from . import generator + + +class KUnitError(Exception): + """Exception raised for errors in KUnit generation and file handling."= "" + + +class KUnit(generator.RVGenerator): + template_dir =3D "" + + def __init__(self, extra_params=3D{}): + super().__init__(extra_params) + self.local =3D extra_params.get("local", False) + self.kunit_c =3D self._read_template_file("kunit.c") + if not self.local: + self._fill_rv_kernel_dir() + try: + self.monitor_path =3D self.__find_monitor_c_file() + with open(self.monitor_path, 'r') as f: + self.content =3D f.read() + except OSError as e: + raise KUnitError(e) from e + self.monitor_class =3D self.__detect_monitor_class() + + def _read_template_file(self, file): + if file in ("main.c", "Kconfig"): + return "" + return super()._read_template_file(file) + + def __find_monitor_c_file(self) -> str: + """Look for the monitor file in the kernel tree or in the current = folder.""" + if not self.local: + path =3D Path(self.rv_dir) / "monitors" / self.name / f"{self.= name}.c" + if path.exists(): + return str(path) + + path =3D Path(self.name) / f"{self.name}.c" + if path.exists(): + return str(path) + + raise FileNotFoundError(f"Could not find monitor C file for '{self= .name}'") + + def __extract_function_args(self, handler_name: str) -> str: + pattern =3D re.compile( + r'^\s*(.*?)\b' + re.escape(handler_name) + r'\(([^)]*)\)', + re.MULTILINE | re.DOTALL + ) + match =3D pattern.search(self.content) + if not match: + return "/* XXX: fill handlers argument. */" + + return match.group(2).strip() + + def __parse_attach_handlers(self) -> list[str]: + """Find handlers by parsing when they are attached to tracepoints.= """ + probe_pattern =3D re.compile( + r'rv_attach_trace_probe\(.*, ([a-zA-Z0-9_]+)\)' + ) + handlers =3D [] + for match in probe_pattern.finditer(self.content): + handler =3D match.group(1) + if handler not in handlers: + handlers.append(handler) + return handlers + + def __detect_monitor_class(self) -> str: + for c in ("da", "ha", "ltl"): + if f"{c}_monitor.h" in self.content: + return c + return "da" + + def __fill_kunit_c(self, struct_name: str) -> str: + kunit_c =3D self.kunit_c + kunit_c =3D kunit_c.replace("%%MODEL_NAME%%", self.name) + kunit_c =3D kunit_c.replace("%%MODEL_NAME_UP%%", self.name.upper()) + kunit_c =3D kunit_c.replace("%%MONITOR_CLASS%%", self.monitor_clas= s) + kunit_c =3D kunit_c.replace("%%STRUCT_NAME%%", struct_name) + return kunit_c + + def __fill_kunit_h(self, struct_name, prototypes) -> str: + return f"""/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __{self.name.upper()}_KUNIT_H +#define __{self.name.upper()}_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct {struct_name} {{ +\tstruct rv_kunit_mon mon; +\t{"\n\t".join(prototypes)} +}} {struct_name}; +#endif + +#endif /* __{self.name.upper()}_KUNIT_H */ +""" + + def __fill_monitor_handlers(self, struct_name, assignments): + struct_definition =3D f"""#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_= TEST) +#include +#include "{self.name}_kunit.h" + +const struct {struct_name} {struct_name} =3D {{ +\t.mon =3D RV_MON_OPS_INIT(), +\t{"\n\t".join(assignments)} +}}; +EXPORT_SYMBOL_IF_KUNIT({struct_name}); +#endif""" + + if self.auto_patch: + try: + with open(self.monitor_path, 'w') as f: + f.write(f"{self.content}\n{struct_definition}\n") + except OSError as e: + raise KUnitError(f"Error patching monitor file {self.monit= or_path}: {e}") from e + else: + print(f"Append the following to {self.name}.c:\n") + print(struct_definition) + print("Now complete the test and add it to rv_monitors_test.c") + + def print_files(self): + + handlers =3D self.__parse_attach_handlers() + + if not handlers: + raise KUnitError(f"No handlers found in {self.monitor_path}") + + prototypes =3D [] + assignments =3D [] + for handler in handlers: + arguments =3D self.__extract_function_args(handler) + + prototypes.append(f"void (*{handler})({arguments});") + assignments.append(f".{handler} =3D {handler},") + + struct_name =3D f"rv_{self.name}_ops" + + self.__fill_monitor_handlers(struct_name, assignments) + + dir_path =3D Path(self.monitor_path).parent + + header_file_path =3D dir_path / f"{self.name}_kunit.h" + kunit_c_file_path =3D dir_path / f"{self.name}_kunit.c" + + use_backup =3D True + if header_file_path.exists() or kunit_c_file_path.exists(): + try: + response =3D input("KUnit file(s) already exist. Backup? [= Y/n] ") + if response.strip().lower() in ("n", "no"): + use_backup =3D False + except EOFError: + print("Non-interactive session detected, backing up existi= ng files.") + else: + use_backup =3D False + + if use_backup: + for path in (header_file_path, kunit_c_file_path): + if path.exists(): + try: + path.rename(path.with_suffix(path.suffix + ".bak")) + except OSError as e: + raise KUnitError(f"Error backing up file {path}: {= e}") from e + + header_content =3D self.__fill_kunit_h(struct_name, prototypes) + try: + with open(header_file_path, 'w') as f: + f.write(header_content) + print(f"Successfully created KUnit header file: {header_file_p= ath}") + except OSError as e: + raise KUnitError(f"Error writing to file {header_file_path}: {= e}") from e + + kunit_c_content =3D self.__fill_kunit_c(struct_name) + try: + with open(kunit_c_file_path, 'w') as f: + f.write(kunit_c_content) + print(f"Successfully created KUnit C file: {kunit_c_file_path}= ") + except OSError as e: + raise KUnitError(f"Error writing to file {kunit_c_file_path}: = {e}") from e diff --git a/tools/verification/rvgen/rvgen/templates/kunit.c b/tools/verif= ication/rvgen/rvgen/templates/kunit.c new file mode 100644 index 000000000000..62092b5cc6d4 --- /dev/null +++ b/tools/verification/rvgen/rvgen/templates/kunit.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +/* + * XXX: include required headers, e.g., + * #include + */ +#include "%%MODEL_NAME%%_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_%%MODEL_NAME_UP%%) + +static void rv_test_%%MODEL_NAME%%(struct kunit *test) +{ + struct rv_kunit_ctx *ctx =3D test->priv; + /* + * If you need to create task_structs with rv_kunit_alloc_mock_task() + * do it BEFORE preparing the test. + */ + + prepare_test(test, &%%STRUCT_NAME%%.mon); + + /* + * XXX: write the test here + * e.g. + * RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + * %%STRUCT_NAME%%.handle_event(args); + */ +} + +#else +#define rv_test_%%MODEL_NAME%% rv_test_stub +#endif --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 E37BB3655CE for ; Thu, 23 Jul 2026 07:46:58 +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=1784792822; cv=none; b=QYtT3CVn386MevCqRrZ5dihppELIHNtwLYbaZSGCGU254U0T1d5s1nJbLBZQFusnAqO6c/vnJhHSPtiV0TYMBj/rv+zFfd+X9ZmRPp2xvoQnaGlpuPCcX2TYhfSQJ23VEi310D+ezj2jlbSsQv+NrtTjLfyRbuJfVU+6EeUvofI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792822; c=relaxed/simple; bh=EkAZBKVjM0rVKvFJfv+GdsOmFpt+62Ep19z3l8rqSYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nv9NHWNKi66Y51Rd8am87Z4oQril5UbWlqLS1cGmB4DgK53foZR1jdIwOw6SCMP1KK642aUWl5rjtJ4UXjU5rJXmLZYkfQM3qwfPEOsR4X/wupypbO5BPE13WFrZyhS/LulI8k/UaBRn3M5u1KPVeZpdtc8QXj1we2LWLfZ4lFI= 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=HP0XKAEq; 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="HP0XKAEq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n4A+8a+zwG0RjWsF3ZIC6cJyxaF2HyVUIJCQQicrCvA=; b=HP0XKAEqE8F/9Zy5eDy8YsKcP0Sbe2KgR14A/2QecpW8HpaXcG+QWM9hEqxgDIR19ItzXC kd2GC1pCUTMjE0yxqKOJDxiXTHAKle17CHYA5rfRgu2VEiiLTnaeZkK2vOKjn5zqCicE4V 1t904DZv2+P1eK4gYNW9nq2sQEvJspU= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-300-HiEc4tvTO9e87ZzuLLY05w-1; Thu, 23 Jul 2026 03:46:53 -0400 X-MC-Unique: HiEc4tvTO9e87ZzuLLY05w-1 X-Mimecast-MFC-AGG-ID: HiEc4tvTO9e87ZzuLLY05w_1784792812 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 503EE182E6A6; Thu, 23 Jul 2026 07:46:52 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2BD0718002B5; Thu, 23 Jul 2026 07:46:48 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 10/17] verification/rvgen: Add selftests for rvgen kunit Date: Thu, 23 Jul 2026 09:45:27 +0200 Message-ID: <20260723074534.43521-11-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The rvgen kunit command patches monitor files and adds necessary definitions for kunit tests. Add a test case validating its behaviour on dummy generated files and comparing it against reference files, like it's done for rvgen monitor. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- .../rvgen/tests/golden/test_bak_kunit/Kconfig | 9 + .../golden/test_bak_kunit/test_bak_kunit.c | 107 +++++++ .../golden/test_bak_kunit/test_bak_kunit.h | 108 ++++++++ .../test_bak_kunit/test_bak_kunit_kunit.c | 33 +++ .../test_bak_kunit/test_bak_kunit_kunit.c.bak | 1 + .../test_bak_kunit/test_bak_kunit_kunit.h | 22 ++ .../test_bak_kunit/test_bak_kunit_trace.h | 14 + .../rvgen/tests/golden/test_da_kunit/Kconfig | 9 + .../golden/test_da_kunit/test_da_kunit.c | 107 +++++++ .../golden/test_da_kunit/test_da_kunit.h | 47 ++++ .../test_da_kunit/test_da_kunit_kunit.c | 33 +++ .../test_da_kunit/test_da_kunit_kunit.h | 23 ++ .../test_da_kunit/test_da_kunit_trace.h | 15 + .../rvgen/tests/golden/test_ha_kunit/Kconfig | 9 + .../golden/test_ha_kunit/test_ha_kunit.c | 260 ++++++++++++++++++ .../golden/test_ha_kunit/test_ha_kunit.h | 88 ++++++ .../test_ha_kunit/test_ha_kunit_kunit.c | 33 +++ .../test_ha_kunit/test_ha_kunit_kunit.h | 24 ++ .../test_ha_kunit/test_ha_kunit_trace.h | 19 ++ .../rvgen/tests/golden/test_ltl_kunit/Kconfig | 9 + .../golden/test_ltl_kunit/test_ltl_kunit.c | 107 +++++++ .../golden/test_ltl_kunit/test_ltl_kunit.h | 108 ++++++++ .../test_ltl_kunit/test_ltl_kunit_kunit.c | 33 +++ .../test_ltl_kunit/test_ltl_kunit_kunit.h | 22 ++ .../test_ltl_kunit/test_ltl_kunit_trace.h | 14 + tools/verification/rvgen/tests/rvgen_kunit.t | 41 +++ 26 files changed, 1295 insertions(+) create mode 100644 tools/verification/rvgen/tests/golden/test_bak_kunit/Kc= onfig create mode 100644 tools/verification/rvgen/tests/golden/test_bak_kunit/te= st_bak_kunit.c create mode 100644 tools/verification/rvgen/tests/golden/test_bak_kunit/te= st_bak_kunit.h create mode 100644 tools/verification/rvgen/tests/golden/test_bak_kunit/te= st_bak_kunit_kunit.c create mode 100644 tools/verification/rvgen/tests/golden/test_bak_kunit/te= st_bak_kunit_kunit.c.bak create mode 100644 tools/verification/rvgen/tests/golden/test_bak_kunit/te= st_bak_kunit_kunit.h create mode 100644 tools/verification/rvgen/tests/golden/test_bak_kunit/te= st_bak_kunit_trace.h create mode 100644 tools/verification/rvgen/tests/golden/test_da_kunit/Kco= nfig create mode 100644 tools/verification/rvgen/tests/golden/test_da_kunit/tes= t_da_kunit.c create mode 100644 tools/verification/rvgen/tests/golden/test_da_kunit/tes= t_da_kunit.h create mode 100644 tools/verification/rvgen/tests/golden/test_da_kunit/tes= t_da_kunit_kunit.c create mode 100644 tools/verification/rvgen/tests/golden/test_da_kunit/tes= t_da_kunit_kunit.h create mode 100644 tools/verification/rvgen/tests/golden/test_da_kunit/tes= t_da_kunit_trace.h create mode 100644 tools/verification/rvgen/tests/golden/test_ha_kunit/Kco= nfig create mode 100644 tools/verification/rvgen/tests/golden/test_ha_kunit/tes= t_ha_kunit.c create mode 100644 tools/verification/rvgen/tests/golden/test_ha_kunit/tes= t_ha_kunit.h create mode 100644 tools/verification/rvgen/tests/golden/test_ha_kunit/tes= t_ha_kunit_kunit.c create mode 100644 tools/verification/rvgen/tests/golden/test_ha_kunit/tes= t_ha_kunit_kunit.h create mode 100644 tools/verification/rvgen/tests/golden/test_ha_kunit/tes= t_ha_kunit_trace.h create mode 100644 tools/verification/rvgen/tests/golden/test_ltl_kunit/Kc= onfig create mode 100644 tools/verification/rvgen/tests/golden/test_ltl_kunit/te= st_ltl_kunit.c create mode 100644 tools/verification/rvgen/tests/golden/test_ltl_kunit/te= st_ltl_kunit.h create mode 100644 tools/verification/rvgen/tests/golden/test_ltl_kunit/te= st_ltl_kunit_kunit.c create mode 100644 tools/verification/rvgen/tests/golden/test_ltl_kunit/te= st_ltl_kunit_kunit.h create mode 100644 tools/verification/rvgen/tests/golden/test_ltl_kunit/te= st_ltl_kunit_trace.h create mode 100644 tools/verification/rvgen/tests/rvgen_kunit.t diff --git a/tools/verification/rvgen/tests/golden/test_bak_kunit/Kconfig b= /tools/verification/rvgen/tests/golden/test_bak_kunit/Kconfig new file mode 100644 index 000000000000..175a416f8b18 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_bak_kunit/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_TEST_BAK_KUNIT + depends on RV + # XXX: add dependencies if there + select LTL_MON_EVENTS_ID + bool "test_bak_kunit monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_= kunit.c b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kun= it.c new file mode 100644 index 000000000000..16579c1c6910 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "test_bak_kunit" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#include "test_bak_kunit.h" +#include + +static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *= mon) +{ + /* + * This is called everytime the Buchi automaton is triggered. + * + * This function could be used to fetch the atomic propositions which + * are expensive to trace. It is possible only if the atomic proposition + * does not need to be updated at precise time. + * + * It is recommended to use tracepoints and ltl_atom_update() instead. + */ +} + +static void ltl_atoms_init(struct task_struct *task, struct ltl_monitor *m= on, bool task_creation) +{ + /* + * This should initialize as many atomic propositions as possible. + * + * @task_creation indicates whether the task is being created. This is + * false if the task is already running before the monitor is enabled. + */ + ltl_atom_set(mon, LTL_EVENT_A, true/false); + ltl_atom_set(mon, LTL_EVENT_B, true/false); +} + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + */ +static void handle_example_event(void *data, /* XXX: fill header */) +{ + ltl_atom_update(task, LTL_EVENT_A, true/false); +} + +static int enable_test_bak_kunit(void) +{ + int retval; + + retval =3D ltl_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("test_bak_kunit", /* XXX: tracepoint */, handle_exa= mple_event); + + return 0; +} + +static void disable_test_bak_kunit(void) +{ + rv_detach_trace_probe("test_bak_kunit", /* XXX: tracepoint */, handle_exa= mple_event); + + ltl_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "test_bak_kunit", + .description =3D "auto-generated", + .enable =3D enable_test_bak_kunit, + .disable =3D disable_test_bak_kunit, +}; + +static int __init register_test_bak_kunit(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_test_bak_kunit(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_test_bak_kunit); +module_exit(unregister_test_bak_kunit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("test_bak_kunit: auto-generated"); diff --git a/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_= kunit.h b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kun= it.h new file mode 100644 index 000000000000..2bfe4e37cea7 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * C implementation of Buchi automaton, automatically generated by + * tools/verification/rvgen from the linear temporal logic specification. + * For further information, see kernel documentation: + * Documentation/trace/rv/linear_temporal_logic.rst + */ + +#include + +#define MONITOR_NAME test_bak_kunit + +enum ltl_atom { + LTL_EVENT_A, + LTL_EVENT_B, + LTL_NUM_ATOM +}; +static_assert(LTL_NUM_ATOM <=3D RV_MAX_LTL_ATOM); + +static const char *ltl_atom_str(enum ltl_atom atom) +{ + static const char *const names[] =3D { + "ev_a", + "ev_b", + }; + + return names[atom]; +} + +enum ltl_buchi_state { + S0, + S1, + S2, + S3, + S4, + RV_NUM_BA_STATES +}; +static_assert(RV_NUM_BA_STATES <=3D RV_MAX_BA_STATES); + +static void ltl_start(struct task_struct *task, struct ltl_monitor *mon) +{ + bool event_b =3D test_bit(LTL_EVENT_B, mon->atoms); + bool event_a =3D test_bit(LTL_EVENT_A, mon->atoms); + bool val1 =3D !event_a; + + if (val1) + __set_bit(S0, mon->states); + if (true) + __set_bit(S1, mon->states); + if (event_b) + __set_bit(S4, mon->states); +} + +static void +ltl_possible_next_states(struct ltl_monitor *mon, unsigned int state, unsi= gned long *next) +{ + bool event_b =3D test_bit(LTL_EVENT_B, mon->atoms); + bool event_a =3D test_bit(LTL_EVENT_A, mon->atoms); + bool val1 =3D !event_a; + + switch (state) { + case S0: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + case S1: + if (true) + __set_bit(S1, next); + if (true && val1) + __set_bit(S2, next); + if (event_b && val1) + __set_bit(S3, next); + if (event_b) + __set_bit(S4, next); + break; + case S2: + if (true) + __set_bit(S1, next); + if (true && val1) + __set_bit(S2, next); + if (event_b && val1) + __set_bit(S3, next); + if (event_b) + __set_bit(S4, next); + break; + case S3: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + case S4: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + } +} diff --git a/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_= kunit_kunit.c b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_b= ak_kunit_kunit.c new file mode 100644 index 000000000000..e2b9354034cc --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_k= unit.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +/* + * XXX: include required headers, e.g., + * #include + */ +#include "test_bak_kunit_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_TEST_BAK_KUNIT) + +static void rv_test_test_bak_kunit(struct kunit *test) +{ + struct rv_kunit_ctx *ctx =3D test->priv; + /* + * If you need to create task_structs with rv_kunit_alloc_mock_task() + * do it BEFORE preparing the test. + */ + + prepare_test(test, &rv_test_bak_kunit_ops.mon); + + /* + * XXX: write the test here + * e.g. + * RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + * rv_test_bak_kunit_ops.handle_event(args); + */ +} + +#else +#define rv_test_test_bak_kunit rv_test_stub +#endif diff --git a/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_= kunit_kunit.c.bak b/tools/verification/rvgen/tests/golden/test_bak_kunit/te= st_bak_kunit_kunit.c.bak new file mode 100644 index 000000000000..f747925bf542 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_k= unit.c.bak @@ -0,0 +1 @@ +DUMMY diff --git a/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_= kunit_kunit.h b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_b= ak_kunit_kunit.h new file mode 100644 index 000000000000..585c4803be23 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_k= unit.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __TEST_BAK_KUNIT_KUNIT_H +#define __TEST_BAK_KUNIT_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_test_bak_kunit_ops { + struct rv_kunit_mon mon; + void (*handle_example_event)(void *data, /* XXX: fill header */); +} rv_test_bak_kunit_ops; +#endif + +#endif /* __TEST_BAK_KUNIT_KUNIT_H */ diff --git a/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_= kunit_trace.h b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_b= ak_kunit_trace.h new file mode 100644 index 000000000000..b984208838c4 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_bak_kunit/test_bak_kunit_t= race.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_TEST_BAK_KUNIT +DEFINE_EVENT(event_ltl_monitor_id, event_test_bak_kunit, + TP_PROTO(struct task_struct *task, char *states, char *atoms, char *= next), + TP_ARGS(task, states, atoms, next)); +DEFINE_EVENT(error_ltl_monitor_id, error_test_bak_kunit, + TP_PROTO(struct task_struct *task), + TP_ARGS(task)); +#endif /* CONFIG_RV_MON_TEST_BAK_KUNIT */ diff --git a/tools/verification/rvgen/tests/golden/test_da_kunit/Kconfig b/= tools/verification/rvgen/tests/golden/test_da_kunit/Kconfig new file mode 100644 index 000000000000..6d664ba5624d --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da_kunit/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_TEST_DA_KUNIT + depends on RV + # XXX: add dependencies if there + select DA_MON_EVENTS_IMPLICIT + bool "test_da_kunit monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_ku= nit.c b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.c new file mode 100644 index 000000000000..effd26548b07 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "test_da_kunit" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#define RV_MON_TYPE RV_MON_PER_CPU +#include "test_da_kunit.h" +#include + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + * + */ +static void handle_event_1(void *data, /* XXX: fill header */) +{ + da_handle_event(event_1_test_da_kunit); +} + +static void handle_event_2(void *data, /* XXX: fill header */) +{ + /* XXX: validate that this event always leads to the initial state */ + da_handle_start_event(event_2_test_da_kunit); +} + +static int enable_test_da_kunit(void) +{ + int retval; + + retval =3D da_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("test_da_kunit", /* XXX: tracepoint */, handle_even= t_1); + rv_attach_trace_probe("test_da_kunit", /* XXX: tracepoint */, handle_even= t_2); + + return 0; +} + +static void disable_test_da_kunit(void) +{ + rv_this.enabled =3D 0; + + rv_detach_trace_probe("test_da_kunit", /* XXX: tracepoint */, handle_even= t_1); + rv_detach_trace_probe("test_da_kunit", /* XXX: tracepoint */, handle_even= t_2); + + da_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "test_da_kunit", + .description =3D "auto-generated", + .enable =3D enable_test_da_kunit, + .disable =3D disable_test_da_kunit, + .reset =3D da_monitor_reset_all, + .enabled =3D 0, +}; + +static int __init register_test_da_kunit(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_test_da_kunit(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_test_da_kunit); +module_exit(unregister_test_da_kunit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("test_da_kunit: auto-generated"); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "test_da_kunit_kunit.h" + +const struct rv_test_da_kunit_ops rv_test_da_kunit_ops =3D { + .mon =3D RV_MON_OPS_INIT(), + .handle_event_1 =3D handle_event_1, + .handle_event_2 =3D handle_event_2, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_test_da_kunit_ops); +#endif diff --git a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_ku= nit.h b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.h new file mode 100644 index 000000000000..290a9454caa4 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Automatically generated C representation of test_da_kunit automaton + * For further information about this format, see kernel documentation: + * Documentation/trace/rv/deterministic_automata.rst + */ + +#define MONITOR_NAME test_da_kunit + +enum states_test_da_kunit { + state_a_test_da_kunit, + state_b_test_da_kunit, + state_max_test_da_kunit, +}; + +#define INVALID_STATE state_max_test_da_kunit + +enum events_test_da_kunit { + event_1_test_da_kunit, + event_2_test_da_kunit, + event_max_test_da_kunit, +}; + +struct automaton_test_da_kunit { + char *state_names[state_max_test_da_kunit]; + char *event_names[event_max_test_da_kunit]; + unsigned char function[state_max_test_da_kunit][event_max_test_da_kunit]; + unsigned char initial_state; + bool final_states[state_max_test_da_kunit]; +}; + +static const struct automaton_test_da_kunit automaton_test_da_kunit =3D { + .state_names =3D { + "state_a", + "state_b", + }, + .event_names =3D { + "event_1", + "event_2", + }, + .function =3D { + { state_b_test_da_kunit, state_a_test_da_kunit }, + { INVALID_STATE, state_a_test_da_kunit }, + }, + .initial_state =3D state_a_test_da_kunit, + .final_states =3D { 1, 0 }, +}; diff --git a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_ku= nit_kunit.c b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_k= unit_kunit.c new file mode 100644 index 000000000000..17826a5c47c8 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit_kun= it.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +/* + * XXX: include required headers, e.g., + * #include + */ +#include "test_da_kunit_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_TEST_DA_KUNIT) + +static void rv_test_test_da_kunit(struct kunit *test) +{ + struct rv_kunit_ctx *ctx =3D test->priv; + /* + * If you need to create task_structs with rv_kunit_alloc_mock_task() + * do it BEFORE preparing the test. + */ + + prepare_test(test, &rv_test_da_kunit_ops.mon); + + /* + * XXX: write the test here + * e.g. + * RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + * rv_test_da_kunit_ops.handle_event(args); + */ +} + +#else +#define rv_test_test_da_kunit rv_test_stub +#endif diff --git a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_ku= nit_kunit.h b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_k= unit_kunit.h new file mode 100644 index 000000000000..0094215ff4fb --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit_kun= it.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __TEST_DA_KUNIT_KUNIT_H +#define __TEST_DA_KUNIT_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_test_da_kunit_ops { + struct rv_kunit_mon mon; + void (*handle_event_1)(void *data, /* XXX: fill header */); + void (*handle_event_2)(void *data, /* XXX: fill header */); +} rv_test_da_kunit_ops; +#endif + +#endif /* __TEST_DA_KUNIT_KUNIT_H */ diff --git a/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_ku= nit_trace.h b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_k= unit_trace.h new file mode 100644 index 000000000000..16804a79e834 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_da_kunit/test_da_kunit_tra= ce.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_TEST_DA_KUNIT +DEFINE_EVENT(event_da_monitor, event_test_da_kunit, + TP_PROTO(char *state, char *event, char *next_state, bool final_stat= e), + TP_ARGS(state, event, next_state, final_state)); + +DEFINE_EVENT(error_da_monitor, error_test_da_kunit, + TP_PROTO(char *state, char *event), + TP_ARGS(state, event)); +#endif /* CONFIG_RV_MON_TEST_DA_KUNIT */ diff --git a/tools/verification/rvgen/tests/golden/test_ha_kunit/Kconfig b/= tools/verification/rvgen/tests/golden/test_ha_kunit/Kconfig new file mode 100644 index 000000000000..6c48770ace1a --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha_kunit/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_TEST_HA_KUNIT + depends on RV + # XXX: add dependencies if there + select HA_MON_EVENTS_ID + bool "test_ha_kunit monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_ku= nit.c b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.c new file mode 100644 index 000000000000..99d6244c2539 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.c @@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "test_ha_kunit" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#define RV_MON_TYPE RV_MON_PER_TASK +/* XXX: If the monitor has several instances, consider HA_TIMER_WHEEL */ +#define HA_TIMER_TYPE HA_TIMER_HRTIMER +#include "test_ha_kunit.h" +#include + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + * + */ +#define BAR_NS(ha_mon) /* XXX: what is BAR_NS(ha_mon)? */ + +#define FOO_NS /* XXX: what is FOO_NS? */ + +static inline u64 bar_ns(struct ha_monitor *ha_mon) +{ + return /* XXX: what is bar_ns(ha_mon)? */; +} + +static u64 foo_ns =3D /* XXX: default value */; +module_param(foo_ns, ullong, 0644); + +/* + * These functions define how to read and reset the environment variable. + * + * Common environment variables like ns-based and jiffy-based clocks have + * pre-define getters and resetters you can use. The parser can infer the = type + * of the environment variable if you supply a measure unit in the constra= int. + * If you define your own functions, make sure to add appropriate memory + * barriers if required. + * Some environment variables don't require a storage as they read a system + * state (e.g. preemption count). Those variables are never reset, so we d= on't + * define a reset function on monitors only relying on this type of variab= les. + */ +static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs_test_ha_kunit e= nv, u64 time_ns) +{ + if (env =3D=3D clk_test_ha_kunit) + return ha_get_clk_ns(ha_mon, env, time_ns); + else if (env =3D=3D env1_test_ha_kunit) + return /* XXX: how do I read env1? */ + else if (env =3D=3D env2_test_ha_kunit) + return /* XXX: how do I read env2? */ + return ENV_INVALID_VALUE; +} + +static void ha_reset_env(struct ha_monitor *ha_mon, enum envs_test_ha_kuni= t env, u64 time_ns) +{ + if (env =3D=3D clk_test_ha_kunit) + ha_reset_clk_ns(ha_mon, env, time_ns); +} + +/* + * These functions are used to validate state transitions. + * + * They are generated by parsing the model, there is usually no need to ch= ange them. + * If the monitor requires a timer, there are functions responsible to arm= it when + * the next state has a constraint, cancel it in any other case and to che= ck + * that it didn't expire before the callback run. Transitions to the same = state + * without a reset never affect timers. + * Due to the different representations between invariants and guards, the= re is + * a function to convert it in case invariants or guards are reachable from + * another invariant without reset. Those are not present if not required = in + * the model. This is all automatic but is worth checking because it may s= how + * errors in the model (e.g. missing resets). + */ +static inline bool ha_verify_invariants(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (curr_state =3D=3D S0_test_ha_kunit) + return ha_check_invariant_ns(ha_mon, clk_test_ha_kunit, time_ns); + else if (curr_state =3D=3D S2_test_ha_kunit) + return ha_check_invariant_ns(ha_mon, clk_test_ha_kunit, time_ns); + return true; +} + +static inline void ha_convert_inv_guard(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (curr_state =3D=3D next_state) + return; + if (curr_state =3D=3D S2_test_ha_kunit) + ha_inv_to_guard(ha_mon, clk_test_ha_kunit, BAR_NS(ha_mon), time_ns); +} + +static inline bool ha_verify_guards(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + bool res =3D true; + + if (curr_state =3D=3D S0_test_ha_kunit && event =3D=3D event0_test_ha_kun= it) + ha_reset_env(ha_mon, clk_test_ha_kunit, time_ns); + else if (curr_state =3D=3D S0_test_ha_kunit && event =3D=3D event1_test_h= a_kunit) + ha_reset_env(ha_mon, clk_test_ha_kunit, time_ns); + else if (curr_state =3D=3D S1_test_ha_kunit && event =3D=3D event0_test_h= a_kunit) + ha_reset_env(ha_mon, clk_test_ha_kunit, time_ns); + else if (curr_state =3D=3D S1_test_ha_kunit && event =3D=3D event2_test_h= a_kunit) { + res =3D ha_get_env(ha_mon, env1_test_ha_kunit, time_ns) =3D=3D 0ull; + ha_reset_env(ha_mon, clk_test_ha_kunit, time_ns); + } else if (curr_state =3D=3D S2_test_ha_kunit && event =3D=3D event1_test= _ha_kunit) + res =3D ha_monitor_env_invalid(ha_mon, clk_test_ha_kunit) || + ha_get_env(ha_mon, clk_test_ha_kunit, time_ns) < foo_ns; + else if (curr_state =3D=3D S3_test_ha_kunit && event =3D=3D event0_test_h= a_kunit) + res =3D ha_monitor_env_invalid(ha_mon, clk_test_ha_kunit) || + (ha_get_env(ha_mon, clk_test_ha_kunit, time_ns) < FOO_NS && + ha_get_env(ha_mon, env2_test_ha_kunit, time_ns) =3D=3D 0ull); + else if (curr_state =3D=3D S3_test_ha_kunit && event =3D=3D event1_test_h= a_kunit) { + res =3D ha_monitor_env_invalid(ha_mon, clk_test_ha_kunit) || + (ha_get_env(ha_mon, clk_test_ha_kunit, time_ns) < 5000ull && + ha_get_env(ha_mon, env1_test_ha_kunit, time_ns) =3D=3D 1ull); + ha_reset_env(ha_mon, clk_test_ha_kunit, time_ns); + } + return res; +} + +static inline void ha_setup_invariants(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (next_state =3D=3D curr_state && event !=3D event0_test_ha_kunit) + return; + if (next_state =3D=3D S0_test_ha_kunit) + ha_start_timer_ns(ha_mon, clk_test_ha_kunit, bar_ns(ha_mon), time_ns); + else if (next_state =3D=3D S2_test_ha_kunit) + ha_start_timer_ns(ha_mon, clk_test_ha_kunit, BAR_NS(ha_mon), time_ns); + else if (curr_state =3D=3D S0_test_ha_kunit) + ha_cancel_timer(ha_mon); + else if (curr_state =3D=3D S2_test_ha_kunit) + ha_cancel_timer(ha_mon); +} + +static bool ha_verify_constraint(struct ha_monitor *ha_mon, + enum states curr_state, enum events event, + enum states next_state, u64 time_ns) +{ + if (!ha_verify_invariants(ha_mon, curr_state, event, next_state, time_ns)) + return false; + + ha_convert_inv_guard(ha_mon, curr_state, event, next_state, time_ns); + + if (!ha_verify_guards(ha_mon, curr_state, event, next_state, time_ns)) + return false; + + ha_setup_invariants(ha_mon, curr_state, event, next_state, time_ns); + + return true; +} + +static void handle_event0(void *data, /* XXX: fill header */) +{ + /* XXX: validate that this event always leads to the initial state */ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_start_event(p, event0_test_ha_kunit); +} + +static void handle_event1(void *data, /* XXX: fill header */) +{ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_event(p, event1_test_ha_kunit); +} + +static void handle_event2(void *data, /* XXX: fill header */) +{ + struct task_struct *p =3D /* XXX: how do I get p? */; + da_handle_event(p, event2_test_ha_kunit); +} + +static int enable_test_ha_kunit(void) +{ + int retval; + + retval =3D ha_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("test_ha_kunit", /* XXX: tracepoint */, handle_even= t0); + rv_attach_trace_probe("test_ha_kunit", /* XXX: tracepoint */, handle_even= t1); + rv_attach_trace_probe("test_ha_kunit", /* XXX: tracepoint */, handle_even= t2); + + return 0; +} + +static void disable_test_ha_kunit(void) +{ + rv_this.enabled =3D 0; + + rv_detach_trace_probe("test_ha_kunit", /* XXX: tracepoint */, handle_even= t0); + rv_detach_trace_probe("test_ha_kunit", /* XXX: tracepoint */, handle_even= t1); + rv_detach_trace_probe("test_ha_kunit", /* XXX: tracepoint */, handle_even= t2); + + ha_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "test_ha_kunit", + .description =3D "auto-generated", + .enable =3D enable_test_ha_kunit, + .disable =3D disable_test_ha_kunit, + .reset =3D da_monitor_reset_all, + .enabled =3D 0, +}; + +static int __init register_test_ha_kunit(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_test_ha_kunit(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_test_ha_kunit); +module_exit(unregister_test_ha_kunit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("test_ha_kunit: auto-generated"); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "test_ha_kunit_kunit.h" + +const struct rv_test_ha_kunit_ops rv_test_ha_kunit_ops =3D { + .mon =3D RV_MON_OPS_INIT(), + .handle_event0 =3D handle_event0, + .handle_event1 =3D handle_event1, + .handle_event2 =3D handle_event2, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_test_ha_kunit_ops); +#endif diff --git a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_ku= nit.h b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.h new file mode 100644 index 000000000000..5c428f818bdf --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit.h @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Automatically generated C representation of test_ha_kunit automaton + * For further information about this format, see kernel documentation: + * Documentation/trace/rv/deterministic_automata.rst + */ + +#define MONITOR_NAME test_ha_kunit + +enum states_test_ha_kunit { + S0_test_ha_kunit, + S1_test_ha_kunit, + S2_test_ha_kunit, + S3_test_ha_kunit, + state_max_test_ha_kunit, +}; + +#define INVALID_STATE state_max_test_ha_kunit + +enum events_test_ha_kunit { + event0_test_ha_kunit, + event1_test_ha_kunit, + event2_test_ha_kunit, + event_max_test_ha_kunit, +}; + +enum envs_test_ha_kunit { + clk_test_ha_kunit, + env1_test_ha_kunit, + env2_test_ha_kunit, + env_max_test_ha_kunit, + env_max_stored_test_ha_kunit =3D env1_test_ha_kunit, +}; + +_Static_assert(env_max_stored_test_ha_kunit <=3D MAX_HA_ENV_LEN, "Not enou= gh slots"); +#define HA_CLK_NS + +struct automaton_test_ha_kunit { + char *state_names[state_max_test_ha_kunit]; + char *event_names[event_max_test_ha_kunit]; + char *env_names[env_max_test_ha_kunit]; + unsigned char function[state_max_test_ha_kunit][event_max_test_ha_kunit]; + unsigned char initial_state; + bool final_states[state_max_test_ha_kunit]; +}; + +static const struct automaton_test_ha_kunit automaton_test_ha_kunit =3D { + .state_names =3D { + "S0", + "S1", + "S2", + "S3", + }, + .event_names =3D { + "event0", + "event1", + "event2", + }, + .env_names =3D { + "clk", + "env1", + "env2", + }, + .function =3D { + { + S0_test_ha_kunit, + S1_test_ha_kunit, + INVALID_STATE, + }, + { + S0_test_ha_kunit, + INVALID_STATE, + S2_test_ha_kunit, + }, + { + INVALID_STATE, + S2_test_ha_kunit, + S3_test_ha_kunit, + }, + { + S0_test_ha_kunit, + S1_test_ha_kunit, + INVALID_STATE, + }, + }, + .initial_state =3D S0_test_ha_kunit, + .final_states =3D { 1, 0, 0, 0 }, +}; diff --git a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_ku= nit_kunit.c b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_k= unit_kunit.c new file mode 100644 index 000000000000..6214a4aa6d25 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit_kun= it.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +/* + * XXX: include required headers, e.g., + * #include + */ +#include "test_ha_kunit_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_TEST_HA_KUNIT) + +static void rv_test_test_ha_kunit(struct kunit *test) +{ + struct rv_kunit_ctx *ctx =3D test->priv; + /* + * If you need to create task_structs with rv_kunit_alloc_mock_task() + * do it BEFORE preparing the test. + */ + + prepare_test(test, &rv_test_ha_kunit_ops.mon); + + /* + * XXX: write the test here + * e.g. + * RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + * rv_test_ha_kunit_ops.handle_event(args); + */ +} + +#else +#define rv_test_test_ha_kunit rv_test_stub +#endif diff --git a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_ku= nit_kunit.h b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_k= unit_kunit.h new file mode 100644 index 000000000000..0b2030cb644a --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit_kun= it.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __TEST_HA_KUNIT_KUNIT_H +#define __TEST_HA_KUNIT_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_test_ha_kunit_ops { + struct rv_kunit_mon mon; + void (*handle_event0)(void *data, /* XXX: fill header */); + void (*handle_event1)(void *data, /* XXX: fill header */); + void (*handle_event2)(void *data, /* XXX: fill header */); +} rv_test_ha_kunit_ops; +#endif + +#endif /* __TEST_HA_KUNIT_KUNIT_H */ diff --git a/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_ku= nit_trace.h b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_k= unit_trace.h new file mode 100644 index 000000000000..6c13ee0068d3 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ha_kunit/test_ha_kunit_tra= ce.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_TEST_HA_KUNIT +DEFINE_EVENT(event_da_monitor_id, event_test_ha_kunit, + TP_PROTO(int id, char *state, char *event, char *next_state, bool fi= nal_state), + TP_ARGS(id, state, event, next_state, final_state)); + +DEFINE_EVENT(error_da_monitor_id, error_test_ha_kunit, + TP_PROTO(int id, char *state, char *event), + TP_ARGS(id, state, event)); + +DEFINE_EVENT(error_env_da_monitor_id, error_env_test_ha_kunit, + TP_PROTO(int id, char *state, char *event, char *env), + TP_ARGS(id, state, event, env)); +#endif /* CONFIG_RV_MON_TEST_HA_KUNIT */ diff --git a/tools/verification/rvgen/tests/golden/test_ltl_kunit/Kconfig b= /tools/verification/rvgen/tests/golden/test_ltl_kunit/Kconfig new file mode 100644 index 000000000000..3e334c344261 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl_kunit/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +config RV_MON_TEST_LTL_KUNIT + depends on RV + # XXX: add dependencies if there + select LTL_MON_EVENTS_ID + bool "test_ltl_kunit monitor" + help + auto-generated diff --git a/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_= kunit.c b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kun= it.c new file mode 100644 index 000000000000..c1d58ce435a8 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include + +#define MODULE_NAME "test_ltl_kunit" + +/* + * XXX: include required tracepoint headers, e.g., + * #include + */ +#include + + +/* + * This is the self-generated part of the monitor. Generally, there is no = need + * to touch this section. + */ +#include "test_ltl_kunit.h" +#include + +static void ltl_atoms_fetch(struct task_struct *task, struct ltl_monitor *= mon) +{ + /* + * This is called everytime the Buchi automaton is triggered. + * + * This function could be used to fetch the atomic propositions which + * are expensive to trace. It is possible only if the atomic proposition + * does not need to be updated at precise time. + * + * It is recommended to use tracepoints and ltl_atom_update() instead. + */ +} + +static void ltl_atoms_init(struct task_struct *task, struct ltl_monitor *m= on, bool task_creation) +{ + /* + * This should initialize as many atomic propositions as possible. + * + * @task_creation indicates whether the task is being created. This is + * false if the task is already running before the monitor is enabled. + */ + ltl_atom_set(mon, LTL_EVENT_A, true/false); + ltl_atom_set(mon, LTL_EVENT_B, true/false); +} + +/* + * This is the instrumentation part of the monitor. + * + * This is the section where manual work is required. Here the kernel even= ts + * are translated into model's event. + */ +static void handle_example_event(void *data, /* XXX: fill header */) +{ + ltl_atom_update(task, LTL_EVENT_A, true/false); +} + +static int enable_test_ltl_kunit(void) +{ + int retval; + + retval =3D ltl_monitor_init(); + if (retval) + return retval; + + rv_attach_trace_probe("test_ltl_kunit", /* XXX: tracepoint */, handle_exa= mple_event); + + return 0; +} + +static void disable_test_ltl_kunit(void) +{ + rv_detach_trace_probe("test_ltl_kunit", /* XXX: tracepoint */, handle_exa= mple_event); + + ltl_monitor_destroy(); +} + +/* + * This is the monitor register section. + */ +static struct rv_monitor rv_this =3D { + .name =3D "test_ltl_kunit", + .description =3D "auto-generated", + .enable =3D enable_test_ltl_kunit, + .disable =3D disable_test_ltl_kunit, +}; + +static int __init register_test_ltl_kunit(void) +{ + return rv_register_monitor(&rv_this, NULL); +} + +static void __exit unregister_test_ltl_kunit(void) +{ + rv_unregister_monitor(&rv_this); +} + +module_init(register_test_ltl_kunit); +module_exit(unregister_test_ltl_kunit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("rvgen: auto-generated"); +MODULE_DESCRIPTION("test_ltl_kunit: auto-generated"); diff --git a/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_= kunit.h b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kun= it.h new file mode 100644 index 000000000000..acc503b56e87 --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * C implementation of Buchi automaton, automatically generated by + * tools/verification/rvgen from the linear temporal logic specification. + * For further information, see kernel documentation: + * Documentation/trace/rv/linear_temporal_logic.rst + */ + +#include + +#define MONITOR_NAME test_ltl_kunit + +enum ltl_atom { + LTL_EVENT_A, + LTL_EVENT_B, + LTL_NUM_ATOM +}; +static_assert(LTL_NUM_ATOM <=3D RV_MAX_LTL_ATOM); + +static const char *ltl_atom_str(enum ltl_atom atom) +{ + static const char *const names[] =3D { + "ev_a", + "ev_b", + }; + + return names[atom]; +} + +enum ltl_buchi_state { + S0, + S1, + S2, + S3, + S4, + RV_NUM_BA_STATES +}; +static_assert(RV_NUM_BA_STATES <=3D RV_MAX_BA_STATES); + +static void ltl_start(struct task_struct *task, struct ltl_monitor *mon) +{ + bool event_b =3D test_bit(LTL_EVENT_B, mon->atoms); + bool event_a =3D test_bit(LTL_EVENT_A, mon->atoms); + bool val1 =3D !event_a; + + if (val1) + __set_bit(S0, mon->states); + if (true) + __set_bit(S1, mon->states); + if (event_b) + __set_bit(S4, mon->states); +} + +static void +ltl_possible_next_states(struct ltl_monitor *mon, unsigned int state, unsi= gned long *next) +{ + bool event_b =3D test_bit(LTL_EVENT_B, mon->atoms); + bool event_a =3D test_bit(LTL_EVENT_A, mon->atoms); + bool val1 =3D !event_a; + + switch (state) { + case S0: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + case S1: + if (true) + __set_bit(S1, next); + if (true && val1) + __set_bit(S2, next); + if (event_b && val1) + __set_bit(S3, next); + if (event_b) + __set_bit(S4, next); + break; + case S2: + if (true) + __set_bit(S1, next); + if (true && val1) + __set_bit(S2, next); + if (event_b && val1) + __set_bit(S3, next); + if (event_b) + __set_bit(S4, next); + break; + case S3: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + case S4: + if (val1) + __set_bit(S0, next); + if (true) + __set_bit(S1, next); + if (event_b) + __set_bit(S4, next); + break; + } +} diff --git a/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_= kunit_kunit.c b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_l= tl_kunit_kunit.c new file mode 100644 index 000000000000..37dab5dfdebc --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit_k= unit.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +/* + * XXX: include required headers, e.g., + * #include + */ +#include "test_ltl_kunit_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_TEST_LTL_KUNIT) + +static void rv_test_test_ltl_kunit(struct kunit *test) +{ + struct rv_kunit_ctx *ctx =3D test->priv; + /* + * If you need to create task_structs with rv_kunit_alloc_mock_task() + * do it BEFORE preparing the test. + */ + + prepare_test(test, &rv_test_ltl_kunit_ops.mon); + + /* + * XXX: write the test here + * e.g. + * RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + * rv_test_ltl_kunit_ops.handle_event(args); + */ +} + +#else +#define rv_test_test_ltl_kunit rv_test_stub +#endif diff --git a/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_= kunit_kunit.h b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_l= tl_kunit_kunit.h new file mode 100644 index 000000000000..b2ca34be327f --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit_k= unit.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __TEST_LTL_KUNIT_KUNIT_H +#define __TEST_LTL_KUNIT_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_test_ltl_kunit_ops { + struct rv_kunit_mon mon; + void (*handle_example_event)(void *data, /* XXX: fill header */); +} rv_test_ltl_kunit_ops; +#endif + +#endif /* __TEST_LTL_KUNIT_KUNIT_H */ diff --git a/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_= kunit_trace.h b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_l= tl_kunit_trace.h new file mode 100644 index 000000000000..a054d5b2c0ea --- /dev/null +++ b/tools/verification/rvgen/tests/golden/test_ltl_kunit/test_ltl_kunit_t= race.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Snippet to be included in rv_trace.h + */ + +#ifdef CONFIG_RV_MON_TEST_LTL_KUNIT +DEFINE_EVENT(event_ltl_monitor_id, event_test_ltl_kunit, + TP_PROTO(struct task_struct *task, char *states, char *atoms, char *= next), + TP_ARGS(task, states, atoms, next)); +DEFINE_EVENT(error_ltl_monitor_id, error_test_ltl_kunit, + TP_PROTO(struct task_struct *task), + TP_ARGS(task)); +#endif /* CONFIG_RV_MON_TEST_LTL_KUNIT */ diff --git a/tools/verification/rvgen/tests/rvgen_kunit.t b/tools/verificat= ion/rvgen/tests/rvgen_kunit.t new file mode 100644 index 000000000000..d27d9175f562 --- /dev/null +++ b/tools/verification/rvgen/tests/rvgen_kunit.t @@ -0,0 +1,41 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +source ../tests/engine.sh +test_begin + +set_timeout 30s + +# Help tests +check "verify kunit subcommand help" \ + "$RVGEN kunit -h" 0 "model_name" "spec" + +check_and_compare_folder "KUnit generation with local lookup and test_da_k= unit" \ + "$RVGEN monitor -c da -s tests/specs/test_da.dot -t per_cpu -n test_da_ku= nit && $RVGEN kunit -a -l -n test_da_kunit" \ + "test_da_kunit" "Now complete the test and add it to rv_monitors_test.c" = "RV_MON_OPS_INIT" + +check_and_compare_folder "KUnit generation with local lookup and test_ha_k= unit" \ + "$RVGEN monitor -c ha -s tests/specs/test_ha.dot -t per_task -n test_ha_k= unit && $RVGEN kunit -a -l -n test_ha_kunit" \ + "test_ha_kunit" "Successfully created KUnit" "Append the following to" + +check_and_compare_folder "KUnit generation with local lookup and test_ltl_= kunit" \ + "$RVGEN monitor -c ltl -s tests/specs/test_ltl.ltl -t per_task -n test_lt= l_kunit && $RVGEN kunit -l -n test_ltl_kunit" \ + "test_ltl_kunit" "RV_MON_OPS_INIT" + +check_and_compare_folder "KUnit generation with backup file" \ + "$RVGEN monitor -c ltl -s tests/specs/test_ltl.ltl -t per_task -n test_ba= k_kunit && echo DUMMY > test_bak_kunit/test_bak_kunit_kunit.c && $RVGEN kun= it -l -n test_bak_kunit" \ + "test_bak_kunit" "KUnit file(s) already exist.*backing up existing files" + +# Error handling tests +check "missing required model_name" \ + "$RVGEN kunit" 2 "the following arguments are required: -n/--model_name" + +check "non-existent model_name with auto_patch" \ + "$RVGEN kunit -a -n nonexistent" 1 \ + "Could not find monitor C file" "Traceback (most recent call last)" + +check "monitor without handlers" \ + "mkdir -p nohandler ; echo DUMMY > nohandler/nohandler.c ; $RVGEN kunit -= l -n nohandler" 1 \ + "No handlers found" "Traceback (most recent call last)" +rm -rf nohandler + +test_end --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 DB8DB233938 for ; Thu, 23 Jul 2026 07:47:02 +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=1784792824; cv=none; b=eJ1qINmD1SKSpaPMcCGl3BYel3u5UxkSvA+fXtXuBaCkbbGzU6sccBawSQnjX2Fh0n+FCVFpmYZMfcl6r7TIHkLjV0w/KIV9Yg08N6wO+Ylz3pEL7cbOqJ0n+4ZHGzjSgKcjp+jnbJ9ieChlBCIAhKwIJ5ptqj9PmLqDIQddJdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792824; c=relaxed/simple; bh=xXaIarO6met28YkseyNHcQizFWioTZjYEayWFFiF7no=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NrUFJ0UijjHM/QfowuOAT60WJSDJgUehVhdjVj1xQNyXdJn8QkzhwDisHllvvYuWgZswkHnkxCKLzuUOacur0wvK9qOC8FWjEFsKCgpu3mCiqJ8snDLAHhtz82DR/WbUZ2yxk//oBbN4q+m078/d5oC9jqh9tBgzhnVpXf42+m0= 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=Lw8aQIfT; 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="Lw8aQIfT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0rg8/odVrC6K+/oPHjo8skQzS2Qub6L3Pd7Jhfnd+C8=; b=Lw8aQIfTsnmCJE6eUv9CyZByBRHsOj3IWIo+ntXxdeq19+dnUAq5vSeizHbE2J5Ey1hOGL x08T1dpOzGRVn8xQa7coh2RnACr02I8lHWPTQjtr2ZTg4KBOABGuQVMLjxgMIJgWI0Htce WLbmESV2vFW5TIZj075aejcTSmN1llI= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-O-v-SyrYP4yyO5ZFSP0wog-1; Thu, 23 Jul 2026 03:46:58 -0400 X-MC-Unique: O-v-SyrYP4yyO5ZFSP0wog-1 X-Mimecast-MFC-AGG-ID: O-v-SyrYP4yyO5ZFSP0wog_1784792816 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84CFD197753D; Thu, 23 Jul 2026 07:46:56 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 60D76180029D; Thu, 23 Jul 2026 07:46:53 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 11/17] rv: Export task monitor slot and react symbols Date: Thu, 23 Jul 2026 09:45:28 +0200 Message-ID: <20260723074534.43521-12-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Export rv_get_task_monitor_slot, rv_put_task_monitor_slot, and rv_react to GPL modules so they can be accessed by KUnit and future monitors built as kernel modules. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- kernel/trace/rv/rv.c | 2 ++ kernel/trace/rv/rv_reactors.c | 1 + 2 files changed, 3 insertions(+) diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c index ee4e68102f17..9d58c730821d 100644 --- a/kernel/trace/rv/rv.c +++ b/kernel/trace/rv/rv.c @@ -189,6 +189,7 @@ int rv_get_task_monitor_slot(void) =20 return -EINVAL; } +EXPORT_SYMBOL_GPL(rv_get_task_monitor_slot); =20 void rv_put_task_monitor_slot(int slot) { @@ -205,6 +206,7 @@ void rv_put_task_monitor_slot(int slot) task_monitor_count--; task_monitor_slots[slot] =3D false; } +EXPORT_SYMBOL_GPL(rv_put_task_monitor_slot); =20 /* * Monitors with a parent are nested, diff --git a/kernel/trace/rv/rv_reactors.c b/kernel/trace/rv/rv_reactors.c index 460af07f7aba..2f5fc8d18dea 100644 --- a/kernel/trace/rv/rv_reactors.c +++ b/kernel/trace/rv/rv_reactors.c @@ -479,3 +479,4 @@ void rv_react(struct rv_monitor *monitor, const char *m= sg, ...) =20 va_end(args); } +EXPORT_SYMBOL_GPL(rv_react); --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 311AD470E86 for ; Thu, 23 Jul 2026 07:47:10 +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=1784792832; cv=none; b=MJp5qviEXXjIfWx5wzWpQX2PI2FytlJFHHF4OV5RkwuOkXA/L5CLV4pMKTN6/uN0wudsTwPGE/PzC9Dnz02toM5E2Pu0XBLWuv3Ov3qgoi6/UmmRPH5pTkpogNbq5unautJEgHi95wG49W54vEbMWh1sE5Smo6kwYifn87cJsq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792832; c=relaxed/simple; bh=het5xn/ccCltKo7lubxEO+gA/ivfr9S8+2tR8xNpYoM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z2UuMIpfrJBOCDXeg+VJNtPH6whfq76oAys2wKEIQeBXjVSne9uB/hsF+NIoDxGvzimx5SSIXzHEBXsvm1dlf5xRVpQeilgwtb9IjpMTaFMIeHhBmAR0Bdw9sauA0ZvlPhihwmRMxkHYqwF6Xts4lqc9DirSOUx8Je3VYWx7P1I= 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=V9ReKZxZ; 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="V9ReKZxZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P5YIR0cYKjPT5tgtYwcUfB4Jy/tmniJh+cOJaUSWcCk=; b=V9ReKZxZs7k6/YdXxLsf/Xhe7DjNd2v0JMj9qub5IZfoWU7+ba1PkObM9y57vqgPNrK95H c3dMGzciDq1uN8drE4m/e91gQVNv44upSJyvnGuPSUOvdoDe4EgXknh6WblzUMCjK5U+vr SnBPwMXzKvd5S8X+2rt0MNsulGNPWzg= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-314-6ZCb8fR4MfG5Z9bpCzyIxg-1; Thu, 23 Jul 2026 03:47:05 -0400 X-MC-Unique: 6ZCb8fR4MfG5Z9bpCzyIxg-1 X-Mimecast-MFC-AGG-ID: 6ZCb8fR4MfG5Z9bpCzyIxg_1784792824 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DE6361954128; Thu, 23 Jul 2026 07:47:03 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AAD65180029D; Thu, 23 Jul 2026 07:47:00 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 12/17] rv: Add KUnit tests for some DA/HA monitors Date: Thu, 23 Jul 2026 09:45:29 +0200 Message-ID: <20260723074534.43521-13-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Validate the functionality of DA monitors by injecting events in a controlled environment (KUnit) and expecting reactions. Events handlers are exported directly from the monitor source files without using system events and with dummy arguments (e.g. no real tasks). If the provided sequence of events incurs a violation, the test expects the stub version of rv_react() to be called. This testing method can validate the entire monitor implementation since it sits between the monitor and the system (in place of the tracepoints). All sorts of system and timing events can be emulated without affecting the running kernel. Handlers and monitor functions are exported as part of a struct to simplify the process of running KUnit tests from kernel modules. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- Notes: V4: * Use deadline_thresh in nomiss KUnit test * Special init/destroy for per-task monitors to avoid touching real tasks and starting tracepoints * Add dummy test to check reactions work as expected * Use actual reactor instead of stub to support timer reactions include/rv/da_monitor.h | 22 +++ include/rv/ha_monitor.h | 21 +++ include/rv/kunit.h | 61 ++++++ kernel/trace/rv/Kconfig | 11 ++ kernel/trace/rv/Makefile | 1 + kernel/trace/rv/monitors/nomiss/nomiss.c | 18 ++ .../trace/rv/monitors/nomiss/nomiss_kunit.c | 38 ++++ .../trace/rv/monitors/nomiss/nomiss_kunit.h | 35 ++++ kernel/trace/rv/monitors/opid/opid.c | 12 ++ kernel/trace/rv/monitors/opid/opid_kunit.c | 33 ++++ kernel/trace/rv/monitors/opid/opid_kunit.h | 23 +++ kernel/trace/rv/monitors/sco/sco.c | 13 ++ kernel/trace/rv/monitors/sco/sco_kunit.c | 29 +++ kernel/trace/rv/monitors/sco/sco_kunit.h | 24 +++ kernel/trace/rv/monitors/sssw/sssw.c | 14 ++ kernel/trace/rv/monitors/sssw/sssw_kunit.c | 33 ++++ kernel/trace/rv/monitors/sssw/sssw_kunit.h | 30 +++ kernel/trace/rv/monitors/sts/sts.c | 19 ++ kernel/trace/rv/monitors/sts/sts_kunit.c | 39 ++++ kernel/trace/rv/monitors/sts/sts_kunit.h | 33 ++++ kernel/trace/rv/rv.c | 40 ++++ kernel/trace/rv/rv_monitors_test.c | 174 ++++++++++++++++++ 22 files changed, 723 insertions(+) create mode 100644 include/rv/kunit.h create mode 100644 kernel/trace/rv/monitors/nomiss/nomiss_kunit.c create mode 100644 kernel/trace/rv/monitors/nomiss/nomiss_kunit.h create mode 100644 kernel/trace/rv/monitors/opid/opid_kunit.c create mode 100644 kernel/trace/rv/monitors/opid/opid_kunit.h create mode 100644 kernel/trace/rv/monitors/sco/sco_kunit.c create mode 100644 kernel/trace/rv/monitors/sco/sco_kunit.h create mode 100644 kernel/trace/rv/monitors/sssw/sssw_kunit.c create mode 100644 kernel/trace/rv/monitors/sssw/sssw_kunit.h create mode 100644 kernel/trace/rv/monitors/sts/sts_kunit.c create mode 100644 kernel/trace/rv/monitors/sts/sts_kunit.h create mode 100644 kernel/trace/rv/rv_monitors_test.c diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 34b8fba9ecd4..773564720ba1 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -311,6 +311,11 @@ static inline struct da_monitor *da_get_monitor(struct= task_struct *tsk) return &tsk->rv[task_mon_slot].da_mon; } =20 +static inline void da_reset(struct task_struct *tsk) +{ + da_monitor_reset(da_get_monitor(tsk)); +} + /* * da_get_target - return the task associated to the monitor */ @@ -908,4 +913,21 @@ static inline void da_reset(da_id_type id, monitor_tar= get target) } #endif /* RV_MON_TYPE */ =20 +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#if RV_MON_TYPE =3D=3D RV_MON_PER_TASK +#define RV_MON_OPS_INIT() { \ + .rv_this =3D &rv_this, \ + .is_per_task =3D true, \ + .task_slot =3D &task_mon_slot, \ + .task_reset =3D da_reset, \ +} +#else +#define RV_MON_OPS_INIT() { \ + .rv_this =3D &rv_this, \ + .monitor_init =3D da_monitor_init, \ + .monitor_destroy =3D da_monitor_destroy, \ +} +#endif /* RV_MON_TYPE */ +#endif /* CONFIG_RV_MONITORS_KUNIT_TEST */ + #endif diff --git a/include/rv/ha_monitor.h b/include/rv/ha_monitor.h index 28d3c74cabfc..d4a490bf2726 100644 --- a/include/rv/ha_monitor.h +++ b/include/rv/ha_monitor.h @@ -558,4 +558,25 @@ static inline bool ha_cancel_timer(struct ha_monitor *= ha_mon) static inline void ha_cancel_timer_sync(struct ha_monitor *ha_mon) { } #endif =20 +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#ifdef RV_MON_OPS_INIT +#undef RV_MON_OPS_INIT +#endif + +#if RV_MON_TYPE =3D=3D RV_MON_PER_TASK +#define RV_MON_OPS_INIT() { \ + .rv_this =3D &rv_this, \ + .is_per_task =3D true, \ + .task_slot =3D &task_mon_slot, \ + .task_reset =3D da_reset, \ +} +#else +#define RV_MON_OPS_INIT() { \ + .rv_this =3D &rv_this, \ + .monitor_init =3D ha_monitor_init, \ + .monitor_destroy =3D ha_monitor_destroy, \ +} +#endif /* RV_MON_TYPE */ +#endif /* CONFIG_RV_MONITORS_KUNIT_TEST */ + #endif diff --git a/include/rv/kunit.h b/include/rv/kunit.h new file mode 100644 index 000000000000..ff98b5137285 --- /dev/null +++ b/include/rv/kunit.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2026-2029 Red Hat, Inc. Gabriele Monaco + * + * Declaration of utilities to run KUnit tests. + */ + +#ifndef _RV_KUNIT_H +#define _RV_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include +#include + +int rv_set_testing(struct kunit_suite *suite); +void rv_clear_testing(struct kunit_suite *suite); + +#define RV_KUNIT_MAX_MOCK_TASKS 8 + +struct rv_kunit_ctx { + int reactions, expected; + int mock_task_count; + struct task_struct *mock_tasks[RV_KUNIT_MAX_MOCK_TASKS]; +}; + +#define RV_KUNIT_EXPECT_REACTION(test, ctx) \ + do { \ + KUNIT_EXPECT_EQ(test, ctx->reactions, ++ctx->expected); \ + if (ctx->reactions !=3D ctx->expected) \ + ctx->expected =3D ctx->reactions; \ + } while (0) + +#define RV_KUNIT_EXPECT_NO_REACTION(test, ctx) \ + do { \ + KUNIT_EXPECT_EQ(test, ctx->reactions, ctx->expected); \ + if (ctx->reactions !=3D ctx->expected) \ + ctx->expected =3D ctx->reactions; \ + } while (0) + +#define RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) = \ + for (int __done =3D ({ RV_KUNIT_EXPECT_NO_REACTION(test, ctx); 0; }); \ + !__done; \ + __done =3D ({ RV_KUNIT_EXPECT_REACTION(test, ctx); 1; })) + +struct rv_kunit_mon { + struct rv_monitor *rv_this; + int (*monitor_init)(void); + void (*monitor_destroy)(void); + bool is_per_task; + int *task_slot; + void (*task_reset)(struct task_struct *task); +}; + +void prepare_test(struct kunit *test, const struct rv_kunit_mon *mon); +void teardown_test(void *arg); +struct task_struct *rv_kunit_alloc_mock_task(struct kunit *test); + +#endif /* CONFIG_RV_MONITORS_KUNIT_TEST */ +#endif /* _RV_KUNIT_H */ diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig index 3884b14df375..34c1feb35a9b 100644 --- a/kernel/trace/rv/Kconfig +++ b/kernel/trace/rv/Kconfig @@ -111,3 +111,14 @@ config RV_REACT_PANIC help Enables the panic reactor. The panic reactor emits a printk() message if an exception is found and panic()s the system. + +config RV_MONITORS_KUNIT_TEST + tristate "KUnit tests for RV monitors" if !KUNIT_ALL_TESTS + depends on KUNIT && RV && RV_REACTORS + default KUNIT_ALL_TESTS + help + Enable KUnit tests for the RV (Runtime Verification) monitors. + These tests verify that monitors correctly detect violations by + triggering fake events and validating the expected reactions. + + If unsure, say N. diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile index 94498da35b37..a3502b7fe7f2 100644 --- a/kernel/trace/rv/Makefile +++ b/kernel/trace/rv/Makefile @@ -24,3 +24,4 @@ obj-$(CONFIG_RV_MON_NOMISS) +=3D monitors/nomiss/nomiss.o obj-$(CONFIG_RV_REACTORS) +=3D rv_reactors.o obj-$(CONFIG_RV_REACT_PRINTK) +=3D reactor_printk.o obj-$(CONFIG_RV_REACT_PANIC) +=3D reactor_panic.o +obj-$(CONFIG_RV_MONITORS_KUNIT_TEST) +=3D rv_monitors_test.o diff --git a/kernel/trace/rv/monitors/nomiss/nomiss.c b/kernel/trace/rv/mon= itors/nomiss/nomiss.c index 8ead8783c29f..beb75965dc8d 100644 --- a/kernel/trace/rv/monitors/nomiss/nomiss.c +++ b/kernel/trace/rv/monitors/nomiss/nomiss.c @@ -291,3 +291,21 @@ module_exit(unregister_nomiss); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Gabriele Monaco "); MODULE_DESCRIPTION("nomiss: dl entities run to completion before their dea= dline."); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "nomiss_kunit.h" + +const struct rv_nomiss_ops rv_nomiss_ops =3D { + .mon =3D RV_MON_OPS_INIT(), + .deadline_thresh =3D &deadline_thresh, + .handle_dl_replenish =3D handle_dl_replenish, + .handle_dl_throttle =3D handle_dl_throttle, + .handle_dl_server_stop =3D handle_dl_server_stop, + .handle_sched_switch =3D handle_sched_switch, + .handle_sched_wakeup =3D handle_sched_wakeup, + .handle_sys_enter =3D handle_sys_enter, + .handle_newtask =3D handle_newtask, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_nomiss_ops); +#endif diff --git a/kernel/trace/rv/monitors/nomiss/nomiss_kunit.c b/kernel/trace/= rv/monitors/nomiss/nomiss_kunit.c new file mode 100644 index 000000000000..1f64249dfcce --- /dev/null +++ b/kernel/trace/rv/monitors/nomiss/nomiss_kunit.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "nomiss_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_NOMISS) + +static void rv_test_nomiss(struct kunit *test) +{ + struct task_struct *target =3D rv_kunit_alloc_mock_task(test); + struct task_struct *other =3D rv_kunit_alloc_mock_task(test); + struct rv_kunit_ctx *ctx =3D test->priv; + + prepare_test(test, &rv_nomiss_ops.mon); + + target->pid =3D 99; + target->policy =3D SCHED_DEADLINE; + target->dl.runtime =3D 10000; + target->dl.dl_deadline =3D 20000; + + rv_nomiss_ops.handle_newtask(NULL, target, 0); + + /* Task gets preempted and can't terminate before deadline */ + rv_nomiss_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING); + rv_nomiss_ops.handle_dl_replenish(NULL, &target->dl, 0, DL_TASK); + udelay(10); + rv_nomiss_ops.handle_sched_switch(NULL, 0, target, other, TASK_RUNNING); + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) { + udelay(15 + *rv_nomiss_ops.deadline_thresh / 1000); + rv_nomiss_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING); + } +} + +#else +#define rv_test_nomiss rv_test_stub +#endif diff --git a/kernel/trace/rv/monitors/nomiss/nomiss_kunit.h b/kernel/trace/= rv/monitors/nomiss/nomiss_kunit.h new file mode 100644 index 000000000000..2be779c5dbaa --- /dev/null +++ b/kernel/trace/rv/monitors/nomiss/nomiss_kunit.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __NOMISS_KUNIT_H +#define __NOMISS_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_nomiss_ops { + struct rv_kunit_mon mon; + const u64 *deadline_thresh; + void (*handle_dl_replenish)(void *data, struct sched_dl_entity *dl_se, + int cpu, u8 type); + void (*handle_dl_throttle)(void *data, struct sched_dl_entity *dl_se, + int cpu, u8 type); + void (*handle_dl_server_stop)(void *data, struct sched_dl_entity *dl_se, + int cpu, u8 type); + void (*handle_sched_switch)(void *data, bool preempt, + struct task_struct *prev, + struct task_struct *next, + unsigned int prev_state); + void (*handle_sched_wakeup)(void *data, struct task_struct *tsk); + void (*handle_sys_enter)(void *data, struct pt_regs *regs, long id); + void (*handle_newtask)(void *data, struct task_struct *task, u64 flags); +} rv_nomiss_ops; +#endif + +#endif /* __NOMISS_KUNIT_H */ diff --git a/kernel/trace/rv/monitors/opid/opid.c b/kernel/trace/rv/monitor= s/opid/opid.c index 3b6a85e815b8..9ae619f176fa 100644 --- a/kernel/trace/rv/monitors/opid/opid.c +++ b/kernel/trace/rv/monitors/opid/opid.c @@ -115,3 +115,15 @@ module_exit(unregister_opid); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Gabriele Monaco "); MODULE_DESCRIPTION("opid: operations with preemption and irq disabled."); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "opid_kunit.h" + +const struct rv_opid_ops rv_opid_ops =3D { + .mon =3D RV_MON_OPS_INIT(), + .handle_sched_need_resched =3D handle_sched_need_resched, + .handle_sched_waking =3D handle_sched_waking, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_opid_ops); +#endif diff --git a/kernel/trace/rv/monitors/opid/opid_kunit.c b/kernel/trace/rv/m= onitors/opid/opid_kunit.c new file mode 100644 index 000000000000..3cb087a74241 --- /dev/null +++ b/kernel/trace/rv/monitors/opid/opid_kunit.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "opid_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_OPID) + +static void rv_test_opid(struct kunit *test) +{ + struct rv_kunit_ctx *ctx =3D test->priv; + + prepare_test(test, &rv_opid_ops.mon); + + /* Ensure we keep the same per-cpu monitor */ + guard(migrate)(); + KUNIT_EXPECT_TRUE(test, preemptible()); + + /* Wakeup with preemption and interrupts enabled */ + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_opid_ops.handle_sched_waking(NULL, NULL); + + /* Need resched with interrupts enabled */ + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) { + scoped_guard(preempt) + rv_opid_ops.handle_sched_need_resched(NULL, NULL, 0, TIF_NEED_RESCHED); + } +} + +#else +#define rv_test_opid rv_test_stub +#endif diff --git a/kernel/trace/rv/monitors/opid/opid_kunit.h b/kernel/trace/rv/m= onitors/opid/opid_kunit.h new file mode 100644 index 000000000000..4969c6175957 --- /dev/null +++ b/kernel/trace/rv/monitors/opid/opid_kunit.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __OPID_KUNIT_H +#define __OPID_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_opid_ops { + struct rv_kunit_mon mon; + void (*handle_sched_need_resched)(void *data, struct task_struct *tsk, in= t cpu, int tif); + void (*handle_sched_waking)(void *data, struct task_struct *p); +} rv_opid_ops; +#endif + +#endif /* __OPID_KUNIT_H */ diff --git a/kernel/trace/rv/monitors/sco/sco.c b/kernel/trace/rv/monitors/= sco/sco.c index 5a3bd5e16e62..1ef1b96e859d 100644 --- a/kernel/trace/rv/monitors/sco/sco.c +++ b/kernel/trace/rv/monitors/sco/sco.c @@ -83,3 +83,16 @@ module_exit(unregister_sco); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Gabriele Monaco "); MODULE_DESCRIPTION("sco: scheduling context operations."); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "sco_kunit.h" + +const struct rv_sco_ops rv_sco_ops =3D { + .mon =3D RV_MON_OPS_INIT(), + .handle_sched_set_state =3D handle_sched_set_state, + .handle_schedule_entry =3D handle_schedule_entry, + .handle_schedule_exit =3D handle_schedule_exit, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_sco_ops); +#endif diff --git a/kernel/trace/rv/monitors/sco/sco_kunit.c b/kernel/trace/rv/mon= itors/sco/sco_kunit.c new file mode 100644 index 000000000000..5e59bcbfcf0b --- /dev/null +++ b/kernel/trace/rv/monitors/sco/sco_kunit.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "sco_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_SCO) + +static void rv_test_sco(struct kunit *test) +{ + struct task_struct *target =3D rv_kunit_alloc_mock_task(test); + struct rv_kunit_ctx *ctx =3D test->priv; + + prepare_test(test, &rv_sco_ops.mon); + + /* Ensure we keep the same per-cpu monitor */ + guard(migrate)(); + + /* Set state while scheduling */ + rv_sco_ops.handle_sched_set_state(NULL, target, TASK_INTERRUPTIBLE); + rv_sco_ops.handle_schedule_entry(NULL, false); + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_sco_ops.handle_sched_set_state(NULL, target, TASK_INTERRUPTIBLE); +} + +#else +#define rv_test_sco rv_test_stub +#endif diff --git a/kernel/trace/rv/monitors/sco/sco_kunit.h b/kernel/trace/rv/mon= itors/sco/sco_kunit.h new file mode 100644 index 000000000000..567757df6b1d --- /dev/null +++ b/kernel/trace/rv/monitors/sco/sco_kunit.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __SCO_KUNIT_H +#define __SCO_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_sco_ops { + struct rv_kunit_mon mon; + void (*handle_sched_set_state)(void *data, struct task_struct *tsk, int s= tate); + void (*handle_schedule_entry)(void *data, bool preempt); + void (*handle_schedule_exit)(void *data, bool is_switch); +} rv_sco_ops; +#endif + +#endif /* __SCO_KUNIT_H */ diff --git a/kernel/trace/rv/monitors/sssw/sssw.c b/kernel/trace/rv/monitor= s/sssw/sssw.c index a91321c890cd..fbfde32dc136 100644 --- a/kernel/trace/rv/monitors/sssw/sssw.c +++ b/kernel/trace/rv/monitors/sssw/sssw.c @@ -112,3 +112,17 @@ module_exit(unregister_sssw); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Gabriele Monaco "); MODULE_DESCRIPTION("sssw: set state sleep and wakeup."); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "sssw_kunit.h" + +const struct rv_sssw_ops rv_sssw_ops =3D { + .mon =3D RV_MON_OPS_INIT(), + .handle_sched_set_state =3D handle_sched_set_state, + .handle_sched_switch =3D handle_sched_switch, + .handle_sched_wakeup =3D handle_sched_wakeup, + .handle_signal_deliver =3D handle_signal_deliver, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_sssw_ops); +#endif diff --git a/kernel/trace/rv/monitors/sssw/sssw_kunit.c b/kernel/trace/rv/m= onitors/sssw/sssw_kunit.c new file mode 100644 index 000000000000..a95faf859c60 --- /dev/null +++ b/kernel/trace/rv/monitors/sssw/sssw_kunit.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "sssw_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_SSSW) + +static void rv_test_sssw(struct kunit *test) +{ + struct task_struct *target =3D rv_kunit_alloc_mock_task(test); + struct task_struct *other =3D rv_kunit_alloc_mock_task(test); + struct rv_kunit_ctx *ctx =3D test->priv; + + prepare_test(test, &rv_sssw_ops.mon); + + /* Suspend without setting to sleepable */ + rv_sssw_ops.handle_sched_set_state(NULL, target, TASK_RUNNING); + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_sssw_ops.handle_sched_switch(NULL, 0, target, other, TASK_INTERRUPTIB= LE); + + /* Switch in after suspension without wakeup */ + rv_sssw_ops.handle_sched_wakeup(NULL, target); + rv_sssw_ops.handle_sched_set_state(NULL, target, TASK_INTERRUPTIBLE); + rv_sssw_ops.handle_sched_switch(NULL, 0, target, other, TASK_INTERRUPTIBL= E); + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_sssw_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING); +} + +#else +#define rv_test_sssw rv_test_stub +#endif diff --git a/kernel/trace/rv/monitors/sssw/sssw_kunit.h b/kernel/trace/rv/m= onitors/sssw/sssw_kunit.h new file mode 100644 index 000000000000..6513daa7afba --- /dev/null +++ b/kernel/trace/rv/monitors/sssw/sssw_kunit.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __SSSW_KUNIT_H +#define __SSSW_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_sssw_ops { + struct rv_kunit_mon mon; + void (*handle_sched_set_state)(void *data, struct task_struct *tsk, int s= tate); + void (*handle_sched_switch)(void *data, bool preempt, + struct task_struct *prev, + struct task_struct *next, + unsigned int prev_state); + void (*handle_sched_wakeup)(void *data, struct task_struct *p); + void (*handle_signal_deliver)(void *data, int sig, + struct kernel_siginfo *info, + struct k_sigaction *ka); +} rv_sssw_ops; +#endif + +#endif /* __SSSW_KUNIT_H */ diff --git a/kernel/trace/rv/monitors/sts/sts.c b/kernel/trace/rv/monitors/= sts/sts.c index ce031cbf202a..2a044cf925b1 100644 --- a/kernel/trace/rv/monitors/sts/sts.c +++ b/kernel/trace/rv/monitors/sts/sts.c @@ -152,3 +152,22 @@ module_exit(unregister_sts); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Gabriele Monaco "); MODULE_DESCRIPTION("sts: schedule implies task switch."); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "sts_kunit.h" + +const struct rv_sts_ops rv_sts_ops =3D { + .mon =3D RV_MON_OPS_INIT(), +#ifdef CONFIG_X86_LOCAL_APIC + .handle_vector_irq_entry =3D handle_vector_irq_entry, +#endif + .handle_irq_disable =3D handle_irq_disable, + .handle_irq_enable =3D handle_irq_enable, + .handle_irq_entry =3D handle_irq_entry, + .handle_sched_switch =3D handle_sched_switch, + .handle_schedule_entry =3D handle_schedule_entry, + .handle_schedule_exit =3D handle_schedule_exit, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_sts_ops); +#endif diff --git a/kernel/trace/rv/monitors/sts/sts_kunit.c b/kernel/trace/rv/mon= itors/sts/sts_kunit.c new file mode 100644 index 000000000000..a07316fff091 --- /dev/null +++ b/kernel/trace/rv/monitors/sts/sts_kunit.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "sts_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_STS) + +static void rv_test_sts(struct kunit *test) +{ + struct task_struct *target =3D rv_kunit_alloc_mock_task(test); + struct task_struct *other =3D rv_kunit_alloc_mock_task(test); + struct rv_kunit_ctx *ctx =3D test->priv; + + prepare_test(test, &rv_sts_ops.mon); + /* Per-CPU monitor, make sure we don't change CPU mid-test */ + guard(migrate)(); + + /* Switch without disabling interrupts */ + rv_sts_ops.handle_schedule_exit(NULL, false); + rv_sts_ops.handle_schedule_entry(NULL, false); + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_sts_ops.handle_sched_switch(NULL, 0, target, other, TASK_RUNNING); + + rv_sts_ops.handle_schedule_exit(NULL, false); + + /* Schedule from interrupt context */ + rv_sts_ops.handle_schedule_entry(NULL, false); + rv_sts_ops.handle_irq_disable(NULL, 0, 0); + rv_sts_ops.handle_irq_entry(NULL, 0, NULL); + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_sts_ops.handle_sched_switch(NULL, 0, target, other, TASK_RUNNING); + rv_sts_ops.handle_irq_enable(NULL, 0, 0); +} + +#else +#define rv_test_sts rv_test_stub +#endif diff --git a/kernel/trace/rv/monitors/sts/sts_kunit.h b/kernel/trace/rv/mon= itors/sts/sts_kunit.h new file mode 100644 index 000000000000..dede4e098c1f --- /dev/null +++ b/kernel/trace/rv/monitors/sts/sts_kunit.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __STS_KUNIT_H +#define __STS_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_sts_ops { + struct rv_kunit_mon mon; +#ifdef CONFIG_X86_LOCAL_APIC + void (*handle_vector_irq_entry)(void *data, int vector); +#endif + void (*handle_irq_disable)(void *data, unsigned long ip, unsigned long pa= rent_ip); + void (*handle_irq_enable)(void *data, unsigned long ip, unsigned long par= ent_ip); + void (*handle_irq_entry)(void *data, int irq, struct irqaction *action); + void (*handle_sched_switch)(void *data, bool preempt, + struct task_struct *prev, + struct task_struct *next, + unsigned int prev_state); + void (*handle_schedule_entry)(void *data, bool preempt); + void (*handle_schedule_exit)(void *data, bool is_switch); +} rv_sts_ops; +#endif + +#endif /* __STS_KUNIT_H */ diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c index 9d58c730821d..cfe950fef3b4 100644 --- a/kernel/trace/rv/rv.c +++ b/kernel/trace/rv/rv.c @@ -854,3 +854,43 @@ int __init rv_init_interface(void) =20 return 0; } + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include + +/* + * rv_set_testing - ensure mutual exclusion between KUnit tests and real m= onitors + * + * KUnit tests for RV monitors rely on stubs that are incompatible with + * the execution of real monitors. Ensure mutual exclusion by acquiring + * the rv_interface_lock for the duration of the suite. + * + * Returns 0 on success, -EBUSY if any real monitor is already enabled. + */ +int rv_set_testing(struct kunit_suite *suite) +{ + struct rv_monitor *mon; + + mutex_lock(&rv_interface_lock); + + list_for_each_entry(mon, &rv_monitors_list, list) { + if (mon->enabled) { + mutex_unlock(&rv_interface_lock); + return -EBUSY; + } + } + + return 0; +} +EXPORT_SYMBOL_IF_KUNIT(rv_set_testing); + +/* + * rv_clear_testing - allow real monitors to run again after KUnit tests + */ +void rv_clear_testing(struct kunit_suite *suite) +{ + mutex_unlock(&rv_interface_lock); +} +EXPORT_SYMBOL_IF_KUNIT(rv_clear_testing); +#endif diff --git a/kernel/trace/rv/rv_monitors_test.c b/kernel/trace/rv/rv_monito= rs_test.c new file mode 100644 index 000000000000..82c798f1875a --- /dev/null +++ b/kernel/trace/rv/rv_monitors_test.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2026-2029 Red Hat, Inc. Gabriele Monaco + * + * RV monitor kunit tests: + * Tests the RV monitors by triggering fake events to verify monitor + * behavior and reactions. Tests start from the first defined event and + * trigger events in order to verify error detection. + */ +#include +#include +#include +#include +#include "rv.h" + +/* + * An easy way to pass the context is to use kunit_get_current_test()->pri= v, + * but this doesn't always work (e.g. a reactor running from another conte= xt + * like softirq). Store the current value here whenever a test is running. + */ +static struct rv_kunit_ctx *active_ctx; + +__printf(1, 0) +static void rv_kunit_mock_react(const char *msg, va_list args) +{ + if (active_ctx) + ++active_ctx->reactions; +} + +/* + * teardown_test - Disable the monitor for a kunit test + * + * Since per-task monitors are special, make sure we reset all the ones we + * started manually here, if required. + */ +void teardown_test(void *arg) +{ + const struct rv_kunit_mon *mon =3D arg; + struct kunit *test =3D kunit_get_current_test(); + + if (test) { + struct rv_kunit_ctx *ctx =3D test->priv; + + RV_KUNIT_EXPECT_NO_REACTION(test, ctx); + + if (mon->is_per_task && mon->task_reset) { + for (int i =3D 0; i < ctx->mock_task_count; i++) + mon->task_reset(ctx->mock_tasks[i]); + synchronize_rcu(); + } + } + + mon->rv_this->enabled =3D 0; + + mon->rv_this->react =3D NULL; + active_ctx =3D NULL; + + if (mon->is_per_task) + *mon->task_slot =3D RV_PER_TASK_MONITOR_INIT; + else + mon->monitor_destroy(); +} + +/* + * prepare_test - Enable the monitor for a kunit test + * + * Do the bare minimum to set up the monitor, per-task monitors are specia= l as + * "real" initialisation/destruction iterates over real tasks, and may reg= ister + * handlers. All we need is to select the right slot in the task_struct. + */ +void prepare_test(struct kunit *test, const struct rv_kunit_mon *mon) +{ + KUNIT_ASSERT_FALSE(test, mon->rv_this->enabled); + + active_ctx =3D test->priv; + mon->rv_this->react =3D rv_kunit_mock_react; + + if (mon->is_per_task) + *mon->task_slot =3D 0; + else + KUNIT_ASSERT_EQ(test, mon->monitor_init(), 0); + + mon->rv_this->enabled =3D 1; + + KUNIT_ASSERT_EQ(test, 0, + kunit_add_action_or_reset(test, teardown_test, (void *)mon)); +} + +struct task_struct *rv_kunit_alloc_mock_task(struct kunit *test) +{ + struct rv_kunit_ctx *ctx =3D test->priv; + struct task_struct *tsk; + + KUNIT_ASSERT_LT(test, ctx->mock_task_count, RV_KUNIT_MAX_MOCK_TASKS); + + tsk =3D kunit_kzalloc(test, sizeof(struct task_struct), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, tsk); + + if (!IS_ENABLED(CONFIG_THREAD_INFO_IN_TASK)) { + tsk->stack =3D kunit_kzalloc(test, sizeof(struct thread_info), GFP_KERNE= L); + KUNIT_ASSERT_NOT_NULL(test, tsk->stack); + } + + ctx->mock_tasks[ctx->mock_task_count++] =3D tsk; + return tsk; +} + +static int rv_mon_test_init(struct kunit *test) +{ + struct rv_kunit_ctx *ctx; + + ctx =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); + + test->priv =3D ctx; + + return 0; +} + +static void __maybe_unused rv_test_stub(struct kunit *test) +{ + kunit_skip(test, "Monitor not enabled\n"); +} + +/* + * rv_test_dummy - test reactions work as expected + */ +static void rv_test_dummy(struct kunit *test) +{ + struct rv_kunit_ctx *ctx =3D test->priv; + static struct rv_monitor dummy_monitor =3D { + .name =3D "dummy", + .react =3D rv_kunit_mock_react, + }; + + active_ctx =3D ctx; + + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_react(&dummy_monitor, "dummy"); + RV_KUNIT_EXPECT_NO_REACTION(test, ctx); + + active_ctx =3D NULL; +} + +#include "monitors/sco/sco_kunit.c" +#include "monitors/sssw/sssw_kunit.c" +#include "monitors/sts/sts_kunit.c" +#include "monitors/opid/opid_kunit.c" +#include "monitors/nomiss/nomiss_kunit.c" + +static struct kunit_case rv_mon_test_cases[] =3D { + KUNIT_CASE(rv_test_dummy), + KUNIT_CASE(rv_test_sco), + KUNIT_CASE(rv_test_sssw), + KUNIT_CASE(rv_test_sts), + KUNIT_CASE(rv_test_opid), + KUNIT_CASE(rv_test_nomiss), + {} +}; + +static struct kunit_suite rv_mon_test_suite =3D { + .name =3D "rv_mon", + .suite_init =3D rv_set_testing, + .suite_exit =3D rv_clear_testing, + .init =3D rv_mon_test_init, + .test_cases =3D rv_mon_test_cases, +}; + +kunit_test_suites(&rv_mon_test_suite); + +MODULE_AUTHOR("Gabriele Monaco "); +MODULE_DESCRIPTION("RV monitor kunit tests: test monitors by triggering re= actions"); +MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 0C59B3D25AD for ; Thu, 23 Jul 2026 07:47:14 +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=1784792836; cv=none; b=h++KapY0zjSxBHq8KztmEaqiicMNwJquk0uawgyhg+6XF6t70ZHHophrp8jmKNj+7AM/xj1w7MYw5LHPqEGw2rn6vc5pIqd7TAJz1yLWj/LNSKhl0HkupEQqn4QJYXEOreSW7uY+8IUNZglVLaqxFMHJX4ISbN/jBx/xIUZj76s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792836; c=relaxed/simple; bh=sZaVGVoaak3SY11DAF18v5rPr/ILFVTmE2a+Nvx+8KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B/bFZp4AqFhUC8RjKI4eeq7YJkWyU276M610jfK60mJ9xEsQ93YIoia4O1A2jm50k5wQeKa8oHpx7rHBZ8X2SJg09iF+pay4eGB6J3Yfxp4TIEFRlM8a8p81BUx2cy3Bp1rcQnCbeUJg0+ijppOQAMw3p5eEV0TpTlGU2UvTKB4= 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=a0sXDvkP; 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="a0sXDvkP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792834; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bX8YYyIiRMvDviiUwbiVIwWWBLrKFvd9CXuo6ymghQ0=; b=a0sXDvkP+aKcAPvAVs8z308ah1nCaKdg3097iWd6m5WUqa7Lo2GttqS7IvDKJryUBsVd+7 BCFB6yqJ1gUKdM7gJMsFaqy3bOHGJ8zEUKSEO8nBGLZKsE/uUieIb0ycvb31999am2Ew0f xitmPl3PvaeZ6o2jR7S69T0Sm3WWVl4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-183-LdunC3J-M6Oqomjxe5c1jw-1; Thu, 23 Jul 2026 03:47:10 -0400 X-MC-Unique: LdunC3J-M6Oqomjxe5c1jw-1 X-Mimecast-MFC-AGG-ID: LdunC3J-M6Oqomjxe5c1jw_1784792829 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E33EB1954124; Thu, 23 Jul 2026 07:47:08 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C7E54180029D; Thu, 23 Jul 2026 07:47:05 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 13/17] rv: Add KUnit mock for current Date: Thu, 23 Jul 2026 09:45:30 +0200 Message-ID: <20260723074534.43521-14-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Some monitors do not only rely on tracepoint arguments but also on the currently executing task. This makes it more challenging to mock events in KUnit. Define wrapper functions around current, the functionality is mocked only during KUnit, an additional function call is avoided using a static branch unless any (even unrelated) KUnit test is running. Rely on a global mock_current variable that is set only by the RV KUnit tests and cleared on teardown. Unrelated KUnit tests that happen to trigger RV handlers would see it null and use current. Signed-off-by: Gabriele Monaco --- Notes: V5: * Drop static stub from current to avoid issues with unrelated KUnit te= sts include/rv/da_monitor.h | 1 + include/rv/kunit.h | 14 +++++++++- include/rv/ltl_monitor.h | 1 + kernel/trace/rv/Kconfig | 3 +++ .../trace/rv/monitors/pagefault/pagefault.c | 2 +- kernel/trace/rv/monitors/sleep/sleep.c | 24 ++++++++--------- kernel/trace/rv/rv.c | 26 +++++++++++++++++++ kernel/trace/rv/rv_monitors_test.c | 1 + 8 files changed, 58 insertions(+), 14 deletions(-) diff --git a/include/rv/da_monitor.h b/include/rv/da_monitor.h index 773564720ba1..9f7ba443d777 100644 --- a/include/rv/da_monitor.h +++ b/include/rv/da_monitor.h @@ -16,6 +16,7 @@ =20 #include #include +#include #include #include #include diff --git a/include/rv/kunit.h b/include/rv/kunit.h index ff98b5137285..31e0b93c40ea 100644 --- a/include/rv/kunit.h +++ b/include/rv/kunit.h @@ -2,7 +2,10 @@ /* * Copyright (C) 2026-2029 Red Hat, Inc. Gabriele Monaco * - * Declaration of utilities to run KUnit tests. + * Declaration of wrappers to allow mocking core functionality, like curre= nt, + * and other testing utilities. + * Necessary only when mocking may be needed. If the RV KUnit test is + * enabled, the wrappers incur an additional function call overhead. */ =20 #ifndef _RV_KUNIT_H @@ -57,5 +60,14 @@ void prepare_test(struct kunit *test, const struct rv_ku= nit_mon *mon); void teardown_test(void *arg); struct task_struct *rv_kunit_alloc_mock_task(struct kunit *test); =20 +void rv_mock_current(struct task_struct *tsk); +struct task_struct *rv_get_mock_current(void); + +#define rv_get_current() (unlikely(kunit_get_current_test()) ? rv_get_mock= _current() : current) + +#else /* !CONFIG_RV_MONITORS_KUNIT_TEST */ + +#define rv_get_current() current + #endif /* CONFIG_RV_MONITORS_KUNIT_TEST */ #endif /* _RV_KUNIT_H */ diff --git a/include/rv/ltl_monitor.h b/include/rv/ltl_monitor.h index 56e83edcf0c4..d7dc01db4dd9 100644 --- a/include/rv/ltl_monitor.h +++ b/include/rv/ltl_monitor.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include =20 diff --git a/kernel/trace/rv/Kconfig b/kernel/trace/rv/Kconfig index 34c1feb35a9b..da905de6c4e8 100644 --- a/kernel/trace/rv/Kconfig +++ b/kernel/trace/rv/Kconfig @@ -121,4 +121,7 @@ config RV_MONITORS_KUNIT_TEST These tests verify that monitors correctly detect violations by triggering fake events and validating the expected reactions. =20 + Enabling this may slightly increase overhead of some monitors if any + unrelated KUnit test is running. + If unsure, say N. diff --git a/kernel/trace/rv/monitors/pagefault/pagefault.c b/kernel/trace/= rv/monitors/pagefault/pagefault.c index 5e1a2a606783..e52500fd2de0 100644 --- a/kernel/trace/rv/monitors/pagefault/pagefault.c +++ b/kernel/trace/rv/monitors/pagefault/pagefault.c @@ -38,7 +38,7 @@ static void ltl_atoms_init(struct task_struct *task, stru= ct ltl_monitor *mon, bo static void handle_page_fault(void *data, unsigned long address, struct pt= _regs *regs, unsigned long error_code) { - ltl_atom_pulse(current, LTL_PAGEFAULT, true); + ltl_atom_pulse(rv_get_current(), LTL_PAGEFAULT, true); } =20 static int enable_pagefault(void) diff --git a/kernel/trace/rv/monitors/sleep/sleep.c b/kernel/trace/rv/monit= ors/sleep/sleep.c index 12328ce663f5..71d2005ce520 100644 --- a/kernel/trace/rv/monitors/sleep/sleep.c +++ b/kernel/trace/rv/monitors/sleep/sleep.c @@ -102,7 +102,7 @@ static void handle_sched_waking(void *data, struct task= _struct *task) if (this_cpu_read(hardirq_context)) { ltl_atom_pulse(task, LTL_WOKEN_BY_HARDIRQ, true); } else if (in_task()) { - if (current->prio <=3D task->prio) + if (rv_get_current()->prio <=3D task->prio) ltl_atom_pulse(task, LTL_WOKEN_BY_EQUAL_OR_HIGHER_PRIO, true); } else if (in_nmi()) { ltl_atom_pulse(task, LTL_WOKEN_BY_NMI, true); @@ -112,12 +112,12 @@ static void handle_sched_waking(void *data, struct ta= sk_struct *task) static void handle_contention_begin(void *data, void *lock, unsigned int f= lags) { if (flags & LCB_F_RT) - ltl_atom_update(current, LTL_BLOCK_ON_RT_MUTEX, true); + ltl_atom_update(rv_get_current(), LTL_BLOCK_ON_RT_MUTEX, true); } =20 static void handle_contention_end(void *data, void *lock, int ret) { - ltl_atom_update(current, LTL_BLOCK_ON_RT_MUTEX, false); + ltl_atom_update(rv_get_current(), LTL_BLOCK_ON_RT_MUTEX, false); } =20 static void handle_sys_enter(void *data, struct pt_regs *regs, long id) @@ -126,7 +126,7 @@ static void handle_sys_enter(void *data, struct pt_regs= *regs, long id) unsigned long args[6]; int op, cmd; =20 - mon =3D ltl_get_monitor(current); + mon =3D ltl_get_monitor(rv_get_current()); =20 switch (id) { #ifdef __NR_clock_nanosleep @@ -135,11 +135,11 @@ static void handle_sys_enter(void *data, struct pt_re= gs *regs, long id) #ifdef __NR_clock_nanosleep_time64 case __NR_clock_nanosleep_time64: #endif - syscall_get_arguments(current, regs, args); + syscall_get_arguments(rv_get_current(), regs, args); ltl_atom_set(mon, LTL_NANOSLEEP_CLOCK_MONOTONIC, args[0] =3D=3D CLOCK_MO= NOTONIC); ltl_atom_set(mon, LTL_NANOSLEEP_CLOCK_TAI, args[0] =3D=3D CLOCK_TAI); ltl_atom_set(mon, LTL_NANOSLEEP_TIMER_ABSTIME, args[1] =3D=3D TIMER_ABST= IME); - ltl_atom_update(current, LTL_CLOCK_NANOSLEEP, true); + ltl_atom_update(rv_get_current(), LTL_CLOCK_NANOSLEEP, true); break; =20 #ifdef __NR_futex @@ -148,25 +148,25 @@ static void handle_sys_enter(void *data, struct pt_re= gs *regs, long id) #ifdef __NR_futex_time64 case __NR_futex_time64: #endif - syscall_get_arguments(current, regs, args); + syscall_get_arguments(rv_get_current(), regs, args); op =3D args[1]; cmd =3D op & FUTEX_CMD_MASK; =20 switch (cmd) { case FUTEX_LOCK_PI: case FUTEX_LOCK_PI2: - ltl_atom_update(current, LTL_FUTEX_LOCK_PI, true); + ltl_atom_update(rv_get_current(), LTL_FUTEX_LOCK_PI, true); break; case FUTEX_WAIT: case FUTEX_WAIT_BITSET: case FUTEX_WAIT_REQUEUE_PI: - ltl_atom_update(current, LTL_FUTEX_WAIT, true); + ltl_atom_update(rv_get_current(), LTL_FUTEX_WAIT, true); break; } break; #ifdef __NR_epoll_wait case __NR_epoll_wait: - ltl_atom_update(current, LTL_EPOLL_WAIT, true); + ltl_atom_update(rv_get_current(), LTL_EPOLL_WAIT, true); break; #endif } @@ -174,7 +174,7 @@ static void handle_sys_enter(void *data, struct pt_regs= *regs, long id) =20 static void handle_sys_exit(void *data, struct pt_regs *regs, long ret) { - struct ltl_monitor *mon =3D ltl_get_monitor(current); + struct ltl_monitor *mon =3D ltl_get_monitor(rv_get_current()); =20 ltl_atom_set(mon, LTL_FUTEX_LOCK_PI, false); ltl_atom_set(mon, LTL_FUTEX_WAIT, false); @@ -182,7 +182,7 @@ static void handle_sys_exit(void *data, struct pt_regs = *regs, long ret) ltl_atom_set(mon, LTL_NANOSLEEP_CLOCK_TAI, false); ltl_atom_set(mon, LTL_NANOSLEEP_TIMER_ABSTIME, false); ltl_atom_set(mon, LTL_EPOLL_WAIT, false); - ltl_atom_update(current, LTL_CLOCK_NANOSLEEP, false); + ltl_atom_update(rv_get_current(), LTL_CLOCK_NANOSLEEP, false); } =20 static void handle_kthread_stop(void *data, struct task_struct *task) diff --git a/kernel/trace/rv/rv.c b/kernel/trace/rv/rv.c index cfe950fef3b4..4c7143961e6e 100644 --- a/kernel/trace/rv/rv.c +++ b/kernel/trace/rv/rv.c @@ -893,4 +893,30 @@ void rv_clear_testing(struct kunit_suite *suite) mutex_unlock(&rv_interface_lock); } EXPORT_SYMBOL_IF_KUNIT(rv_clear_testing); + +/* + * rv_get_mock_current() is called only if we are running from a KUnit tes= t. + * This can occur from a legitimate RV test or any unrelated test running = when + * a real RV monitor is active and triggering events. + * We assume the former case is the only one where mock_current is not NUL= L and + * can occur only sequentially (KUnit doesn't run tests in parallel). + * We cannot rely on the test's context because there is no way to safely + * understand from which test we are running and KUnit utilities require + * locking, which is unsafe from NMI or scheduling context. + * Note that it is not possible for a real RV monitor to run when the RV K= Unit + * tests are running (see rv_set_testing()). + */ +static struct task_struct *mock_current; + +void rv_mock_current(struct task_struct *tsk) +{ + mock_current =3D tsk; +} +EXPORT_SYMBOL_IF_KUNIT(rv_mock_current); + +struct task_struct *rv_get_mock_current(void) +{ + return mock_current ?: current; +} +EXPORT_SYMBOL_GPL(rv_get_mock_current); #endif diff --git a/kernel/trace/rv/rv_monitors_test.c b/kernel/trace/rv/rv_monito= rs_test.c index 82c798f1875a..8026176eee90 100644 --- a/kernel/trace/rv/rv_monitors_test.c +++ b/kernel/trace/rv/rv_monitors_test.c @@ -54,6 +54,7 @@ void teardown_test(void *arg) =20 mon->rv_this->react =3D NULL; active_ctx =3D NULL; + rv_mock_current(NULL); =20 if (mon->is_per_task) *mon->task_slot =3D RV_PER_TASK_MONITOR_INIT; --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 3894D3E0C4D for ; Thu, 23 Jul 2026 07:47:20 +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=1784792842; cv=none; b=o7LrCvTo26gusIKBDqDTXK+8F6w3I2Jla68eMDdlNewsnFLCR53EYZAvcSwbza2NmjGi0ayjC0tNSk6rDFWtj0idbBNhF6BSFc4+c8U9QzOkF9Nq18bIbP8aX9lpfiUjKvVH6EShfpyOnQvYJ4X045TQ6XCxkYzG1zPH1puq034= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792842; c=relaxed/simple; bh=dk3ZYiMgykV9ONANh6OImGVani0ym6CK+J+ka2HUmpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wilf5PxV4AeduxPLZjwl5XmV/C2yae2ra63UC9QLUU1jeMwDPu1hnn3sxGSkraKEtD942svDC0x+RVKIPVHipLaZXVwe7GkNNZqb+AT4JjCYiskvcYQc8UaHq1Cm+uSyC+0P7RRbcYQ3VDYh3VONYvAn6cEQh+kbav5gCs6TDjE= 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=G5FNPvfr; 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="G5FNPvfr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cHqtuG2IRtNlsLWQ7zqYw9TT0URRJyqxcRNG2zcBo6g=; b=G5FNPvfr91Z44xfPgoVwvI5W6ZEyRx6Ihog0xqxnuvD1/xkqHtEggZu/GPM911lekz3XmI OZ+acAmlfoM/Oes0kjQgn1Vq2WlW2A/0xxpFddD4k1AixouCujNij2/TzLmctvD89fbFox 43MKjY7A8yV9TdfC/RQ4BBlXtPoj+H8= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-IosriG_-OOuy8VQJJ4EnCg-1; Thu, 23 Jul 2026 03:47:15 -0400 X-MC-Unique: IosriG_-OOuy8VQJJ4EnCg-1 X-Mimecast-MFC-AGG-ID: IosriG_-OOuy8VQJJ4EnCg_1784792834 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 65A41182F546; Thu, 23 Jul 2026 07:47:14 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 11ADE180029D; Thu, 23 Jul 2026 07:47:10 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Masami Hiramatsu Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 14/17] rv: Add KUnit tests for some LTL monitors Date: Thu, 23 Jul 2026 09:45:31 +0200 Message-ID: <20260723074534.43521-15-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Validate the functionality of LTL monitors by injecting events in a controlled environment (KUnit) and expecting reactions, just like it is done in DA monitors. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- include/rv/ltl_monitor.h | 8 +++ .../trace/rv/monitors/pagefault/pagefault.c | 12 ++++ .../rv/monitors/pagefault/pagefault_kunit.c | 34 +++++++++++ .../rv/monitors/pagefault/pagefault_kunit.h | 24 ++++++++ kernel/trace/rv/monitors/sleep/sleep.c | 19 ++++++ kernel/trace/rv/monitors/sleep/sleep_kunit.c | 58 +++++++++++++++++++ kernel/trace/rv/monitors/sleep/sleep_kunit.h | 30 ++++++++++ kernel/trace/rv/rv_monitors_test.c | 4 ++ 8 files changed, 189 insertions(+) create mode 100644 kernel/trace/rv/monitors/pagefault/pagefault_kunit.c create mode 100644 kernel/trace/rv/monitors/pagefault/pagefault_kunit.h create mode 100644 kernel/trace/rv/monitors/sleep/sleep_kunit.c create mode 100644 kernel/trace/rv/monitors/sleep/sleep_kunit.h diff --git a/include/rv/ltl_monitor.h b/include/rv/ltl_monitor.h index d7dc01db4dd9..e9fd8265a3da 100644 --- a/include/rv/ltl_monitor.h +++ b/include/rv/ltl_monitor.h @@ -172,3 +172,11 @@ static void __maybe_unused ltl_atom_pulse(struct task_= struct *task, enum ltl_ato ltl_atom_set(mon, atom, !value); ltl_validate(task, mon); } + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#define RV_MON_OPS_INIT() { \ + .rv_this =3D &rv_this, \ + .is_per_task =3D true, \ + .task_slot =3D <l_monitor_slot, \ +} +#endif /* CONFIG_RV_MONITORS_KUNIT_TEST */ diff --git a/kernel/trace/rv/monitors/pagefault/pagefault.c b/kernel/trace/= rv/monitors/pagefault/pagefault.c index e52500fd2de0..c599fc19fc88 100644 --- a/kernel/trace/rv/monitors/pagefault/pagefault.c +++ b/kernel/trace/rv/monitors/pagefault/pagefault.c @@ -86,3 +86,15 @@ module_exit(unregister_pagefault); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Nam Cao "); MODULE_DESCRIPTION("pagefault: Monitor that RT tasks do not raise page fau= lts"); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "pagefault_kunit.h" + +const struct rv_pagefault_ops rv_pagefault_ops =3D { + .mon =3D RV_MON_OPS_INIT(), + .handle_page_fault =3D handle_page_fault, + .handle_task_newtask =3D handle_task_newtask, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_pagefault_ops); +#endif diff --git a/kernel/trace/rv/monitors/pagefault/pagefault_kunit.c b/kernel/= trace/rv/monitors/pagefault/pagefault_kunit.c new file mode 100644 index 000000000000..06369960b008 --- /dev/null +++ b/kernel/trace/rv/monitors/pagefault/pagefault_kunit.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include "pagefault_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_PAGEFAULT) + +static void rv_test_pagefault(struct kunit *test) +{ + struct task_struct *target =3D rv_kunit_alloc_mock_task(test); + struct rv_kunit_ctx *ctx =3D test->priv; + + prepare_test(test, &rv_pagefault_ops.mon); + + /* Initial pagefault when non-RT to start the model without failure */ + target->policy =3D SCHED_NORMAL; + target->prio =3D MAX_RT_PRIO + 20; + rv_pagefault_ops.handle_task_newtask(NULL, target, 0); + rv_mock_current(target); + rv_pagefault_ops.handle_page_fault(NULL, 0, NULL, 0); + + /* RT task has a page fault */ + target->policy =3D SCHED_FIFO; + target->prio =3D MAX_RT_PRIO - 1; + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_pagefault_ops.handle_page_fault(NULL, 0, NULL, 0); +} + +#else +#define rv_test_pagefault rv_test_stub +#endif diff --git a/kernel/trace/rv/monitors/pagefault/pagefault_kunit.h b/kernel/= trace/rv/monitors/pagefault/pagefault_kunit.h new file mode 100644 index 000000000000..2f9652f08b3f --- /dev/null +++ b/kernel/trace/rv/monitors/pagefault/pagefault_kunit.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __PAGEFAULT_KUNIT_H +#define __PAGEFAULT_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_pagefault_ops { + struct rv_kunit_mon mon; + void (*handle_page_fault)(void *data, unsigned long address, struct pt_re= gs *regs, + unsigned long error_code); + void (*handle_task_newtask)(void *data, struct task_struct *task, u64 fla= gs); +} rv_pagefault_ops; +#endif + +#endif /* __PAGEFAULT_KUNIT_H */ diff --git a/kernel/trace/rv/monitors/sleep/sleep.c b/kernel/trace/rv/monit= ors/sleep/sleep.c index 71d2005ce520..f84a61a21825 100644 --- a/kernel/trace/rv/monitors/sleep/sleep.c +++ b/kernel/trace/rv/monitors/sleep/sleep.c @@ -247,3 +247,22 @@ module_exit(unregister_sleep); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Nam Cao "); MODULE_DESCRIPTION("sleep: Monitor that RT tasks do not undesirably sleep"= ); + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) +#include +#include "sleep_kunit.h" + +const struct rv_sleep_ops rv_sleep_ops =3D { + .mon =3D RV_MON_OPS_INIT(), + .handle_sched_waking =3D handle_sched_waking, + .handle_sched_wakeup =3D handle_sched_wakeup, + .handle_sched_set_state =3D handle_sched_set_state, + .handle_contention_begin =3D handle_contention_begin, + .handle_contention_end =3D handle_contention_end, + .handle_kthread_stop =3D handle_kthread_stop, + .handle_sys_enter =3D handle_sys_enter, + .handle_sys_exit =3D handle_sys_exit, + .handle_task_newtask =3D handle_task_newtask, +}; +EXPORT_SYMBOL_IF_KUNIT(rv_sleep_ops); +#endif diff --git a/kernel/trace/rv/monitors/sleep/sleep_kunit.c b/kernel/trace/rv= /monitors/sleep/sleep_kunit.c new file mode 100644 index 000000000000..ccbb3d188528 --- /dev/null +++ b/kernel/trace/rv/monitors/sleep/sleep_kunit.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include "sleep_kunit.h" + +#if IS_REACHABLE(CONFIG_RV_MON_SLEEP) + +static void rv_test_sleep(struct kunit *test) +{ + struct task_struct *target =3D rv_kunit_alloc_mock_task(test); + struct task_struct *other =3D rv_kunit_alloc_mock_task(test); + struct rv_kunit_ctx *ctx =3D test->priv; + unsigned long args[6] =3D {0}; + struct pt_regs regs =3D {0}; + + prepare_test(test, &rv_sleep_ops.mon); + target->policy =3D SCHED_FIFO; + target->prio =3D MAX_RT_PRIO - 2; + other->policy =3D SCHED_FIFO; + other->prio =3D MAX_RT_PRIO - 1; + rv_sleep_ops.handle_task_newtask(NULL, target, 0); + + /* RT task sleeps on a non RT-friendly nanosleep */ + rv_mock_current(target); + args[0] =3D CLOCK_REALTIME; + syscall_set_arguments(target, ®s, args); +#ifdef __NR_clock_nanosleep + rv_sleep_ops.handle_sys_enter(NULL, ®s, __NR_clock_nanosleep); +#elif defined(__NR_clock_nanosleep_time64) + rv_sleep_ops.handle_sys_enter(NULL, ®s, __NR_clock_nanosleep_time64); +#endif + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_sleep_ops.handle_sched_set_state(NULL, target, TASK_INTERRUPTIBLE); + rv_sleep_ops.handle_sys_exit(NULL, NULL, 0); + + /* RT task woken up by lower priority task */ + args[1] =3D FUTEX_WAIT; + syscall_set_arguments(target, ®s, args); + rv_mock_current(target); +#ifdef __NR_futex + rv_sleep_ops.handle_sys_enter(NULL, ®s, __NR_futex); +#elif defined(__NR_futex_time64) + rv_sleep_ops.handle_sys_enter(NULL, ®s, __NR_futex_time64); +#endif + rv_sleep_ops.handle_sched_set_state(NULL, target, TASK_INTERRUPTIBLE); + rv_mock_current(other); + rv_sleep_ops.handle_sched_waking(NULL, target); + RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) + rv_sleep_ops.handle_sched_wakeup(NULL, target); +} + +#else +#define rv_test_sleep rv_test_stub +#endif diff --git a/kernel/trace/rv/monitors/sleep/sleep_kunit.h b/kernel/trace/rv= /monitors/sleep/sleep_kunit.h new file mode 100644 index 000000000000..2cd61e31a6af --- /dev/null +++ b/kernel/trace/rv/monitors/sleep/sleep_kunit.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Automatically generated by rvgen kunit. + * May need manual intervention for function prototypes that couldn't be + * found (e.g. are in another file) or variables to be exported. + */ + +#ifndef __SLEEP_KUNIT_H +#define __SLEEP_KUNIT_H + +#if IS_ENABLED(CONFIG_RV_MONITORS_KUNIT_TEST) + +#include +#include + +extern const struct rv_sleep_ops { + struct rv_kunit_mon mon; + void (*handle_sched_waking)(void *data, struct task_struct *task); + void (*handle_sched_wakeup)(void *data, struct task_struct *task); + void (*handle_sched_set_state)(void *data, struct task_struct *task, int = state); + void (*handle_contention_begin)(void *data, void *lock, unsigned int flag= s); + void (*handle_contention_end)(void *data, void *lock, int ret); + void (*handle_kthread_stop)(void *data, struct task_struct *task); + void (*handle_sys_enter)(void *data, struct pt_regs *regs, long id); + void (*handle_sys_exit)(void *data, struct pt_regs *regs, long ret); + void (*handle_task_newtask)(void *data, struct task_struct *task, u64 fla= gs); +} rv_sleep_ops; +#endif + +#endif /* __SLEEP_KUNIT_H */ diff --git a/kernel/trace/rv/rv_monitors_test.c b/kernel/trace/rv/rv_monito= rs_test.c index 8026176eee90..bbbf7d120ec0 100644 --- a/kernel/trace/rv/rv_monitors_test.c +++ b/kernel/trace/rv/rv_monitors_test.c @@ -148,6 +148,8 @@ static void rv_test_dummy(struct kunit *test) #include "monitors/sts/sts_kunit.c" #include "monitors/opid/opid_kunit.c" #include "monitors/nomiss/nomiss_kunit.c" +#include "monitors/pagefault/pagefault_kunit.c" +#include "monitors/sleep/sleep_kunit.c" =20 static struct kunit_case rv_mon_test_cases[] =3D { KUNIT_CASE(rv_test_dummy), @@ -156,6 +158,8 @@ static struct kunit_case rv_mon_test_cases[] =3D { KUNIT_CASE(rv_test_sts), KUNIT_CASE(rv_test_opid), KUNIT_CASE(rv_test_nomiss), + KUNIT_CASE(rv_test_pagefault), + KUNIT_CASE(rv_test_sleep), {} }; =20 --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 F210D3DC4D7 for ; Thu, 23 Jul 2026 07:47:26 +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=1784792848; cv=none; b=sIawzAyZfvAEQhVX6KQagMieCNpbaJiBsgmDrNZRqiDrwa8nMmuYk0InuQ8yZs9X3MJooFbodWgYq/Mmd4Wh/cF4wtZUo7APi4fBqW+6jsbQRbN69AqmdyNLKED3LOR5ISELuSiNPngCsXlEgo56cUOX0l+OpXe8dEBJEDahJ3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792848; c=relaxed/simple; bh=oHrzS7c2fdMxPD+EoUgQkE+zbdNYCbx8okcllqp9KYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jakrQ9Uo4TItmrHSU+72QCIByAPPM6ywU4v/UZ9+QTAwtSVa7RZW4CkgnsFAMFyJMHxxEgP6q+PPRKv/WpIod2OXdCH945GmIjvvXg0GrfeiZ9xWzjk5J5UtrHHnzDmBENIUHA+GinUxGmmQISdPiuBtMOK5gHsURRtUOlKC5Ws= 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=cH1Cxc6V; 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="cH1Cxc6V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792846; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rU+JQSn24qoe+8/7ChMxhPzRjJgh1VjUQ1PsYPpKZ7A=; b=cH1Cxc6VReIc/BfVkJWW7OhU+WudD8R91gc5Kxku6Xs98raE70wN0iRNdPphpJzgOxHLth hAW4XyrRBKW1A92mbKWgQYcU7D83yDza+cpdMYfElGYD/0vY+0Bf1PQwLv75BQ3cm9dbG2 aAXxk6ZaBGgPztzh1+iUv1xiJ/l+HJ4= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-OIFZQ_uGMim6Wy1GXEkM8A-1; Thu, 23 Jul 2026 03:47:20 -0400 X-MC-Unique: OIFZQ_uGMim6Wy1GXEkM8A-1 X-Mimecast-MFC-AGG-ID: OIFZQ_uGMim6Wy1GXEkM8A_1784792839 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F2FA1182FA23; Thu, 23 Jul 2026 07:47:18 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7F0EB180029D; Thu, 23 Jul 2026 07:47:15 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Shuah Khan , linux-kselftest@vger.kernel.org Cc: Wen Yang , Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur Subject: [PATCH v5 15/17] selftests/verification: Fix wrong errexit assumption Date: Thu, 23 Jul 2026 09:45:32 +0200 Message-ID: <20260723074534.43521-16-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" RV selftest rely on bash errexit (set -e) to terminate with error, when a step is expected to return false, the following syntax is used: ! cmd This however prevents the test from exiting when cmd is false (desired) but doesn't exit if cmd is true, since commands prefixed with ! are explicitly excluded from errexit. Use the syntax ! cmd || false Which ends up checking the exit value of ! cmd and supplies a false command for errexit to evaluate. Reviewed-by: Wen Yang Acked-by: Nam Cao Signed-off-by: Gabriele Monaco --- .../verification/test.d/rv_monitor_enable_disable.tc | 10 +++++----- .../verification/test.d/rv_monitor_reactor.tc | 4 ++-- .../selftests/verification/test.d/rv_wwnr_printk.tc | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/verification/test.d/rv_monitor_enable_= disable.tc b/tools/testing/selftests/verification/test.d/rv_monitor_enable_= disable.tc index f29236defb5a..61e2c8b54d9a 100644 --- a/tools/testing/selftests/verification/test.d/rv_monitor_enable_disable= .tc +++ b/tools/testing/selftests/verification/test.d/rv_monitor_enable_disable= .tc @@ -10,7 +10,7 @@ test_simple_monitor() { grep -q "$monitor$" enabled_monitors =20 echo 0 > "monitors/$prefix$monitor/enable" - ! grep -q "$monitor$" enabled_monitors + ! grep -q "$monitor$" enabled_monitors || false =20 echo "$monitor" >> enabled_monitors grep -q 1 "monitors/$prefix$monitor/enable" @@ -34,12 +34,12 @@ test_container_monitor() { test -n "$nested" =20 echo 0 > "monitors/$monitor/enable" - ! grep -q "^$monitor$" enabled_monitors + ! grep -q "^$monitor$" enabled_monitors || false =20 for nested_dir in "monitors/$monitor"/*; do [ -d "$nested_dir" ] || continue nested=3D$(basename "$nested_dir") - ! grep -q "^$monitor:$nested$" enabled_monitors + ! grep -q "^$monitor:$nested$" enabled_monitors || false done =20 echo "$monitor" >> enabled_monitors @@ -71,5 +71,5 @@ for monitor_dir in monitors/*; do fi done =20 -! echo non_existent_monitor > enabled_monitors -! grep -q "^non_existent_monitor$" enabled_monitors +! echo non_existent_monitor > enabled_monitors || false +! grep -q "^non_existent_monitor$" enabled_monitors || false diff --git a/tools/testing/selftests/verification/test.d/rv_monitor_reactor= .tc b/tools/testing/selftests/verification/test.d/rv_monitor_reactor.tc index 2958bf849338..516a20971390 100644 --- a/tools/testing/selftests/verification/test.d/rv_monitor_reactor.tc +++ b/tools/testing/selftests/verification/test.d/rv_monitor_reactor.tc @@ -64,5 +64,5 @@ done =20 monitor=3D$(ls /sys/kernel/tracing/rv/monitors -1 | head -n 1) test -f "monitors/$monitor/reactors" -! echo non_existent_reactor > "monitors/$monitor/reactors" -! grep -q "\\[non_existent_reactor\\]" "monitors/$monitor/reactors" +! echo non_existent_reactor > "monitors/$monitor/reactors" || false +! grep -q "\\[non_existent_reactor\\]" "monitors/$monitor/reactors" || fal= se diff --git a/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc = b/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc index 5a59432b1d93..96de95edb530 100644 --- a/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc +++ b/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc @@ -17,13 +17,13 @@ echo printk > monitors/wwnr/reactors load =20 echo 0 > monitoring_on -! load +! load || false echo 1 > monitoring_on =20 load =20 echo 0 > reacting_on -! load +! load || false echo 1 > reacting_on =20 echo nop > monitors/wwnr/reactors --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 340943E0750 for ; Thu, 23 Jul 2026 07:47:29 +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=1784792850; cv=none; b=AVU2wFJEg+JIbCx+hyBQQuTeKw1CUEtNchlu60N2ZZ//+SfYRPvSAa93HrS7/9UtOuKsND/gr0W1hmov6rVZxVdh3XRwyLO1Pa4AYcRwdYGBUkXRHQt4qbRO+b/Fe1I5K9gRut7sNNiclLEP1FiRustJkOXm1J2ythEmg0UNCjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792850; c=relaxed/simple; bh=wdoYB9ksSQhCXncTt4fxSxJ3Mz7TvFITOT54NotPTXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FS95Av7g6M9a+6/3aloJjEHIpPb+hINF0wgUkmQtxH6AvsWOU9zm1PquH2xScSbsX+t7T8vw8736rJVGE8RNXDQsQ7MFp7X0bGT/FiJ2Cp7piGbwKEXHSxt4dsFiWat/hxBsqKwT2hsqvA0cF07SQX5LwPk51O8nX8h6zOLebTw= 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=a4pvFet3; 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="a4pvFet3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NS4LZld37qPIOcoXEkiVMtyQomhnvEW3v8Emy4S5hTY=; b=a4pvFet3tgJYNthVtVKuagCJ5es2b1IfLgr1UfFlYtwo2UrdC0CcAhPUn5vtEbPZXcPP7g gACuHE6wZVNgPo3f4ZGo6fG+Oz5xyXZXPpo2bEAvG0MVzSSEQTeFGOOKjMTUm3jaJ1uvmP DaJki3RgZdU3GHoXdjZdN496YJtgoQM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-407--7MBmvfoPSCataVvgTb57Q-1; Thu, 23 Jul 2026 03:47:24 -0400 X-MC-Unique: -7MBmvfoPSCataVvgTb57Q-1 X-Mimecast-MFC-AGG-ID: -7MBmvfoPSCataVvgTb57Q_1784792843 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 543C5182FA23; Thu, 23 Jul 2026 07:47:23 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EBA37180029A; Thu, 23 Jul 2026 07:47:19 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Shuah Khan , linux-kselftest@vger.kernel.org Cc: Wen Yang , Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur Subject: [PATCH v5 16/17] selftests/verification: Rearrange the wwnr_printk test Date: Thu, 23 Jul 2026 09:45:33 +0200 Message-ID: <20260723074534.43521-17-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" The wwnr_printk test expects no reactions in some situations, after fixing the bash assertion, the test is failing because expecting no reaction after a previous step had reactions is flaky without making sure all buffers are flushed. Wait for reactions to be over when expected by polling dmesg for an interval without any rv message. Also simplify the load function to stop loads as soon as a reaction occurs, this limits the number of lines to flush and makes tests overall faster and more stable. Reviewed-by: Wen Yang Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- Notes: V5: * Move wait for flush to avoid wwnr/printk selftest to hang V4: * Wait for dmesg to flush all messages after reactions .../verification/test.d/rv_wwnr_printk.tc | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc = b/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc index 96de95edb530..17e1edfb3902 100644 --- a/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc +++ b/tools/testing/selftests/verification/test.d/rv_wwnr_printk.tc @@ -4,11 +4,29 @@ # requires: available_reactors wwnr:monitor printk:reactor stress-ng:progr= am =20 load() { # returns true if there was a reaction - local lines_before num + local lines_before num load_pid ret num=3D$((($(nproc) + 1) / 2)) lines_before=3D$(dmesg | wc -l) - stress-ng --cpu-sched "$num" --timer "$num" -t 5 -q - dmesg | tail -n $((lines_before + 1)) | grep -q "rv: monitor wwnr does no= t allow event" + stress-ng --cpu-sched "$num" --timer "$num" -t 5 -q & + load_pid=3D$! + timeout 5 dmesg -w | tail -n +$((lines_before + 1)) | \ + grep -m 1 -q "rv: monitor wwnr does not allow event" + ret=3D$? + kill "$load_pid" || true + wait "$load_pid" || true + return $ret +} + +# loads may flood the ringbuffer, wait for all pending printks (timeout at= 2 minutes) +wait_dmesg_flush() { + local last_before last_after + for _ in $(seq 400); do + last_before=3D$last_after + last_after=3D$(dmesg | grep "rv:" | tail -n 1 || true) + [ "$last_before" =3D "$last_after" ] && return 0 + sleep .3 + done + return 1 } =20 echo 1 > monitors/wwnr/enable @@ -17,12 +35,16 @@ echo printk > monitors/wwnr/reactors load =20 echo 0 > monitoring_on +wait_dmesg_flush + ! load || false echo 1 > monitoring_on =20 load =20 echo 0 > reacting_on +wait_dmesg_flush + ! load || false echo 1 > reacting_on =20 --=20 2.55.0 From nobody Fri Jul 24 21:52:34 2026 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 A5ABF3B27E3 for ; Thu, 23 Jul 2026 07:47:34 +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=1784792857; cv=none; b=oJnxMdXyBnIMBdJdZvu7LguBdI5NDf5f6n/tu1hYFw/xUzKOqxr4nV5Jw8dF8VfGexDbI6YC/zjYgbabcUcAMMCayPeKUvqbimHz+HFMB7Fgc+r8Y0KTH9803czLUcZL3recw0VTzxm1K0tFqnIgjy+Yv3tc/aE2QXAPNpwprGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784792857; c=relaxed/simple; bh=T2lbyT/yM7x1H71zHyiVIbknJvhnpix0X4z2hlwzwLI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gvT+Dg16uyq3hfEaMfeDDNZyxpLQErSdNRmqgEQbKFkv/2qxcUQdL1BI6XChIr/qioxNUXi7SCzGEncqd22BABSC7XF+BAfuytZYUohJOajeZ/rEWhnbNyb0B7igxhQAck0fs1VlztYFOgdfKbSXuFHVCiMvpBV8c1cU9OPVeIw= 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=HjVtDvmu; 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="HjVtDvmu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784792853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=izA3D0CqoZEPLiW5dd3Cu7GNT4gzd8+KLF5CAaXCB1E=; b=HjVtDvmujSTA9bQXbBvoD37REk6ygYCPwLEUUVy6+TlE7PkP+8NJ57ExLqEtdz/ouFy7q7 cFLha0oa0LLpcQ4jkpPztN9f+T71OwH6o8D7dc36b32IvvpewuzBf4QmgqEvJaA7Jj8H2w 1dpx7a9ICj0jtHlACmrJ7Am4xaF0QP4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-43-NFarALcyPWOja-sJBvn8tQ-1; Thu, 23 Jul 2026 03:47:29 -0400 X-MC-Unique: NFarALcyPWOja-sJBvn8tQ-1 X-Mimecast-MFC-AGG-ID: NFarALcyPWOja-sJBvn8tQ_1784792848 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2656F197753F; Thu, 23 Jul 2026 07:47:28 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.local (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 84600180029A; Thu, 23 Jul 2026 07:47:24 +0000 (UTC) From: Gabriele Monaco To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Gabriele Monaco , Shuah Khan , linux-kselftest@vger.kernel.org Cc: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur , Wen Yang Subject: [PATCH v5 17/17] selftests/verification: Add selftests for deadline and stall monitors Date: Thu, 23 Jul 2026 09:45:34 +0200 Message-ID: <20260723074534.43521-18-gmonaco@redhat.com> In-Reply-To: <20260723074534.43521-1-gmonaco@redhat.com> References: <20260723074534.43521-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Add selftests to verify deadline monitors don't fail under expected conditions and the stall monitor report violations only when expected. Reviewed-by: Nam Cao Signed-off-by: Gabriele Monaco --- Notes: V4: * Restore original stall threshold after selftest .../verification/test.d/rv_deadline.tc | 23 +++++++++++++ .../selftests/verification/test.d/rv_stall.tc | 33 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tools/testing/selftests/verification/test.d/rv_deadline= .tc create mode 100644 tools/testing/selftests/verification/test.d/rv_stall.tc diff --git a/tools/testing/selftests/verification/test.d/rv_deadline.tc b/t= ools/testing/selftests/verification/test.d/rv_deadline.tc new file mode 100644 index 000000000000..fc95267dbb82 --- /dev/null +++ b/tools/testing/selftests/verification/test.d/rv_deadline.tc @@ -0,0 +1,23 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# description: Test deadline monitors trigger no reaction +# requires: available_reactors deadline:monitor printk:reactor stress-ng:p= rogram + +load() { # returns true if there was a reaction + local lines_before + lines_before=3D$(dmesg | wc -l) + stress-ng --cpu 2 --sched deadline --sched-period 100000000 \ + --sched-deadline 100000000 --sched-runtime 20000000 -t 5 & + stress-ng --cpu 2 --sched rr --sched-prio 50 --cyclic 1 \ + --cyclic-policy rr --cyclic-prio 50 -t 5 & + wait + dmesg | tail -n +$((lines_before + 1)) | grep -q "rv: monitor [a-z]\+ doe= s not allow event" +} + +echo 1 > monitors/deadline/enable +echo printk > monitors/deadline/reactors + +! load || false + +echo nop > monitors/deadline/reactors +echo 0 > monitors/deadline/enable diff --git a/tools/testing/selftests/verification/test.d/rv_stall.tc b/tool= s/testing/selftests/verification/test.d/rv_stall.tc new file mode 100644 index 000000000000..515a10263ca1 --- /dev/null +++ b/tools/testing/selftests/verification/test.d/rv_stall.tc @@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# description: Test stall monitor +# requires: available_reactors stall:monitor printk:reactor stress-ng:prog= ram + +THRESHOLD=3D/sys/module/stall/parameters/threshold_jiffies +ORIG_THRESHOLD=3D$(cat $THRESHOLD) +trap 'echo $ORIG_THRESHOLD > $THRESHOLD' EXIT + +load() { # returns true if there was a reaction + local lines_before cpu + cpu=3D$(($(nproc) - 1)) + lines_before=3D$(dmesg | wc -l) + stress-ng --cpu 1 --taskset "$cpu" --sched rr --sched-prio 1 -t 3 & + stress-ng --cpu 5 --taskset "$cpu" -t 3 & + wait + dmesg | tail -n +$((lines_before + 1)) | grep -q "rv: monitor stall does = not allow event" +} + +echo 5000 > $THRESHOLD +echo 1 > monitors/stall/enable +echo printk > monitors/stall/reactors + +! load || false + +echo 0 > monitors/stall/enable +echo 70 > $THRESHOLD +echo 1 > monitors/stall/enable + +load + +echo nop > monitors/stall/reactors +echo 0 > monitors/stall/enable --=20 2.55.0