Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6321389rdb; Thu, 14 Dec 2023 15:06:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCfZ5dLbwgIqUTqcvW17poStac7qdo3Yi/4uZH3tpfI/p80NjMgOkWGNmC/W++wYDG9v0J X-Received: by 2002:a05:6e02:20c1:b0:35d:6227:4f03 with SMTP id 1-20020a056e0220c100b0035d62274f03mr14816703ilq.7.1702595208798; Thu, 14 Dec 2023 15:06:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702595208; cv=none; d=google.com; s=arc-20160816; b=jYA7Hv3QbWBg77lA1UBDvzEcnKOVg8ZC9zt+SHNMxI1PUMZzBDvSO68MnaLVBfAklD riEDVrkHnL/eVZDLrQ07cZd2Sv0moocvAI09XCuwEMdh06dey4boZkaFaM6tMpLi6RhY rWoFhWuFS8On9VhspRPqfYusZGl8Tse+RKK8ekJ6BYn4ftPVZOIjOBI7DqOP+sCYlDre ewq5ovhaDD9DHUSWRPSlHHqzBq3jA1COF/VRRLYJ/zovhccPcWa+kNNObc6u0q7rtGb6 ADGeMELtDwsN9+Fy0S7dNnZu3TQ7PZZz+oIBtiaubrE77VB+TP7oR1lA50W1rKqKckEJ JVwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:feedback-id:dkim-signature:dkim-signature; bh=L/0CxpH+ItkIN3jpcTP0mXpLYvcBH1FSKHM4RQL+UFM=; fh=hj0UBKVp01kEiC02FrnhWQdSORjR11W+sfuTgpArQjU=; b=wbllg2UPsyFFNAgY9LLFqN7oBm9Ln0jV51ccFgUX2jZq53Jz5W6Jo5LA5+Wm8Xatgd dZTNB9wYkLn0aWbEASlglDmRIiG4FW7Py8LvumHMBERZJ6XulRGUF9KIWlSlqZCqWWi+ ZGXQvZRu/vFYRrzopbRbhIYEUnm7EOUu0q5gzqKHpUAkHf4zSDRWM5jnk4lZMoHWQyHw 3Gay2KJKgtnmiNOg0nZWk0CULtCN9L0DY4ecTaVmYrLIJ6qqJd1wfuv54c7yvXTQC/1o zlQmEtdSpWenrUlQoL/uV9a0RH9QLRt/frepxo4iUOlEjvSBkaJOpFeyMQWqmP9SgMSp qJcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=Ylob5p1y; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Z8QNha96; spf=pass (google.com: domain of linux-kernel+bounces-221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-221-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u2-20020a63df02000000b005c6bc10835fsi11865264pgg.84.2023.12.14.15.06.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 15:06:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=Ylob5p1y; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=Z8QNha96; spf=pass (google.com: domain of linux-kernel+bounces-221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-221-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D007FB20BAA for ; Thu, 14 Dec 2023 23:06:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0946266ACE; Thu, 14 Dec 2023 23:06:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="Ylob5p1y"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z8QNha96" X-Original-To: linux-kernel@vger.kernel.org Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (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 7749266AA4; Thu, 14 Dec 2023 23:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 3FEE73200B6C; Thu, 14 Dec 2023 17:56:50 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 14 Dec 2023 17:56:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1702594609; x= 1702681009; bh=L/0CxpH+ItkIN3jpcTP0mXpLYvcBH1FSKHM4RQL+UFM=; b=Y lob5p1y1K4j5mjBFalFycAkqaKaqz1FROzRP7NWkpEROFzy1e6SUuDGfMro/YXW7 FhjzgdFCa70PDXuds5aDqFaw53gjddDbSraAF+MhTKm+OBFDkEqWZYP1r6c891Eu FJWJVU5C7/K2myRzOSiegHkravmvJMcDxiaXJ6CkUOmpjIBvUWg+7vPkUaNfMEKM FuKCwOHLdM13dBAyjrwKm8RnC2fZ1umgcmm8JCbTaVGb3pocHmib/cVoNatQ+/Vz vXFOKXun5v8LjJFAJfq/UncZ12je4stK9I/h1Nmdxj7tnM88vWM/U1eLll66IDan 9utJ5oH21kB+ke8oFAjbQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1702594609; x= 1702681009; bh=L/0CxpH+ItkIN3jpcTP0mXpLYvcBH1FSKHM4RQL+UFM=; b=Z 8QNha96yOnxWRQSSo1nDSWCFHxIJmkn9MYYFdco3NpHSKLe7MimAxTTHpGymneOn 6MLJI4IF8TJ8zEAsdWP2cfpFR/ZM0Ylfphy0HLodutXTIGujX395+upYWsL81wjN x4X1XBmlD06f2OGrC8XYdP/an6b2s7OxfZT2O0Tb4tc+slGTmn1JDgj3YXKCMSes MmZy09onNnLpBo7i0Ymd/NPcL3o/jfSlfa/sSXXYhk5lntMpOwlYrHqd/HDTcvj2 dfV8Vt2frgzhmGOpTJc64fq1jV/Yfp5O90iOOTlcLZKNa3ErJgfCC8YgNbjUJNea G6x1YfFa1llnZqwqWOQ9g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvddttddgtdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgepudenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Dec 2023 17:56:48 -0500 (EST) From: Daniel Xu To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, shuah@kernel.org, memxor@gmail.com Cc: mykolal@fb.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 3/3] bpf: selftests: Test bpf_assert_if() and bpf_assert_with_if() Date: Thu, 14 Dec 2023 15:56:27 -0700 Message-ID: X-Mailer: git-send-email 2.42.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add some positive and negative test cases that exercise the "callback" semantics. Signed-off-by: Daniel Xu --- .../selftests/bpf/prog_tests/exceptions.c | 5 ++ .../testing/selftests/bpf/progs/exceptions.c | 61 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/exceptions.c b/tools/testing/selftests/bpf/prog_tests/exceptions.c index 516f4a13013c..a41113d72d0d 100644 --- a/tools/testing/selftests/bpf/prog_tests/exceptions.c +++ b/tools/testing/selftests/bpf/prog_tests/exceptions.c @@ -83,6 +83,11 @@ static void test_exceptions_success(void) RUN_SUCCESS(exception_assert_range_with, 1); RUN_SUCCESS(exception_bad_assert_range, 0); RUN_SUCCESS(exception_bad_assert_range_with, 10); + RUN_SUCCESS(exception_assert_if_body_not_executed, 2); + RUN_SUCCESS(exception_bad_assert_if_body_executed, 1); + RUN_SUCCESS(exception_bad_assert_if_throws, 0); + RUN_SUCCESS(exception_assert_with_if_body_not_executed, 3); + RUN_SUCCESS(exception_bad_assert_with_if_body_executed, 2); #define RUN_EXT(load_ret, attach_err, expr, msg, after_link) \ { \ diff --git a/tools/testing/selftests/bpf/progs/exceptions.c b/tools/testing/selftests/bpf/progs/exceptions.c index 2811ee842b01..e61cb794a305 100644 --- a/tools/testing/selftests/bpf/progs/exceptions.c +++ b/tools/testing/selftests/bpf/progs/exceptions.c @@ -365,4 +365,65 @@ int exception_bad_assert_range_with(struct __sk_buff *ctx) return 1; } +SEC("tc") +int exception_assert_if_body_not_executed(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + + bpf_assert_if(time != 0) { + return 1; + } + + return 2; +} + +SEC("tc") +int exception_bad_assert_if_body_executed(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + + bpf_assert_if(time == 0) { + return 1; + } + + return 2; +} + +SEC("tc") +int exception_bad_assert_if_throws(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + + bpf_assert_if(time == 0) { + } + + return 2; +} + +SEC("tc") +int exception_assert_with_if_body_not_executed(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + int ret = 1; + + bpf_assert_with_if(time != 0, ret) { + ret = 2; + } + + return 3; +} + +SEC("tc") +int exception_bad_assert_with_if_body_executed(struct __sk_buff *ctx) +{ + u64 time = bpf_ktime_get_ns(); + int ret = 1; + + bpf_assert_with_if(time == 0, ret) { + ret = 2; + } + + return 3; +} + char _license[] SEC("license") = "GPL"; -- 2.42.1