From patchwork Fri Aug 11 02:58:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 134300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp837133vqi; Thu, 10 Aug 2023 20:49:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFFnDxlCcK2bIZDHWjLtXcwJnP2JPfrGrWBqK90S/nfh+HdMfqoGnMelbA7xt7NbH/F87hc X-Received: by 2002:a05:620a:a4d:b0:765:9c48:a930 with SMTP id j13-20020a05620a0a4d00b007659c48a930mr721888qka.67.1691725785556; Thu, 10 Aug 2023 20:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691725785; cv=none; d=google.com; s=arc-20160816; b=XWsi9d0isr5mdzcL3l9/mwScxlSKFwVUGthH3ViPKEnrWSAHAaRuw5Gf8mfNdTL+qF q351VH/3oNqitV2Ro6QhRS6c2E4EuAhZ035l9kJFnNln4jw8TEnNUc2arZIR8O/cmO4G kpM4uG7IFipBx7ARIXRWn2bTBngcQKhK4aZnFPgsYpfR6BJosDzjNl/LRWFkTmzpE+U0 H/hAKLDAdySzBy5oa92uEEEGT/WZWpeCsMM5T4sDTHARsvUfUCakAORM68OYqtUTjtKB P9Jhlx+bCXqivNH6HrkIhDycX0aX49Hroo304cn65rQdY8xEvv7vAHqwUF7qX4ip6CKm 3vGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=Fpn1N1ZB0KetpAmPQkAbgnFDVJSzxAlzA4W3TfJjTiA=; fh=5ShMoexo/KWBTyBLrW6UihX0v08J+iCKJpYxH65iw9k=; b=ykqWhhipcXYeVHICjX6FVzQzpzkLK77k8LgQh+x5qlyfVxZ0VWNBCVNgFxFZEVgpMO tDCUlO0LNVaXBiNK5QD1VgYkwnS+tSm5RdhCxZb7Qo9rwtTmQvTf+vjySIg1zxF6KNRC TUvzcvyayOANV61+UTgnmpTuct8pb6xysoGT9fAttoPMcARv8tbvsB9HB0SUxmraGQXp EOuNJX6DDkCPhwZzKig+0qoUB3jzylCiOISn53XcMbeDc9Aj3zrISNxakkQ2Tpq+opxq RONKgnAf40cVQKlPPj8gTzDDluWqvqfKJO/LPXkkLvX9JKgl86bxoLvjhMmCOw5QqyvW /Osg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Cx4FUrEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k29-20020a635a5d000000b0055bef93b8fbsi2677070pgm.75.2023.08.10.20.49.32; Thu, 10 Aug 2023 20:49:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Cx4FUrEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230172AbjHKC6a (ORCPT + 99 others); Thu, 10 Aug 2023 22:58:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbjHKC63 (ORCPT ); Thu, 10 Aug 2023 22:58:29 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05EFDEA; Thu, 10 Aug 2023 19:58:28 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1bc83a96067so11763815ad.0; Thu, 10 Aug 2023 19:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691722707; x=1692327507; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=Fpn1N1ZB0KetpAmPQkAbgnFDVJSzxAlzA4W3TfJjTiA=; b=Cx4FUrEk1nD38+jb31BkywBQvWaqk4i2dYX9OOyMbyfUsUv8KA+cNNGvfQiR73t6AM uUKiwV+bSXkg7ffmX87KSJsd5+PHcdPMMi11mkby4fHjBr3B3KN2gR1xwwoXi4Dc44HW ag7CUWMiTgD9Tt6rLOFcNVF7oQrS7/gXhCGFA1IrLl8+AipoLRWbJj53eDL+u9yy/78E ywo8ehQHIu2i5dDfUNZ2kFTHHWepHREz6SvA5H1fgOJlFCF774nxXdD7Sb7hKtg3MzaP RbmzrVPoq1blGdJi6bj6gQebheVCEz1gADPRLgrmBAgX76TD8yXGuTJe3cFt6teSCANq sgDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691722707; x=1692327507; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Fpn1N1ZB0KetpAmPQkAbgnFDVJSzxAlzA4W3TfJjTiA=; b=UE6eHmUz4hwblKTVrK7xJ9D54bRvVnhBgROzjr2g6UVXKrdtkN2OejkYd9vV37mn34 lMEMuzCBVUWKV9fpvh8gIddJt1OhYYGtBkam6qwmU0UczBXYazkjbXBbl4t+ueiptbQa 06IFLsFrz1CAm+mVCG69FodkXkHiC5N5Om4s0mrTADm8RGVvqqUSmN3Py+aB3pJ+7tNI gLIn1LAruWx5ITHiaIyzunXpMvVMR//0Ttw1WRlcrzuqAcvvVS5NY4AZsaV083zqZ8nJ cKUQQMmWDLZtX41dTmWdQMS+1+iAKMlVRWBRJXnHbHmXZ2BzIEjOLm+K9GJ99QLg1CQO 4aBg== X-Gm-Message-State: AOJu0YwaplAHSwQpS3crTkkaBMNzYAwGUBZWkDbJdvQDUVc3UzbjQYkO 1RvSrkaUBb12sVS7tfe9zuTO4tv04/Y= X-Received: by 2002:a17:902:dacc:b0:1b9:cc6b:408c with SMTP id q12-20020a170902dacc00b001b9cc6b408cmr579146plx.38.1691722707364; Thu, 10 Aug 2023 19:58:27 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2a3:200:2328:6915:cbeb:39d4]) by smtp.gmail.com with ESMTPSA id b23-20020a170902b61700b001b9be3b94d3sm2526592pls.140.2023.08.10.19.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 19:58:26 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 1/2] perf bpf-filter: Fix sample flag check with || Date: Thu, 10 Aug 2023 19:58:21 -0700 Message-ID: <20230811025822.3859771-1-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773903057026435996 X-GMAIL-MSGID: 1773903057026435996 For logical OR operator, the actual sample_flags are in the 'groups' list so it needs to check entries in the list instead. Otherwise it would show the following error message. $ sudo perf record -a -e cycles:p --filter 'period > 100 || weight > 0' sleep 1 Error: cycles:p event does not have sample flags 0 failed to set filter "BPF" on event cycles:p with 2 (No such file or directory) Actually it should warn on 'weight' is used without WEIGHT flag. Error: cycles:p event does not have PERF_SAMPLE_WEIGHT Hint: please add -W option to perf record failed to set filter "BPF" on event cycles:p with 2 (No such file or directory) Fixes: 4310551b76e0 ("perf bpf filter: Show warning for missing sample flags") Signed-off-by: Namhyung Kim --- tools/perf/util/bpf-filter.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c index 47f01df658d9..b51544996046 100644 --- a/tools/perf/util/bpf-filter.c +++ b/tools/perf/util/bpf-filter.c @@ -62,6 +62,16 @@ static int check_sample_flags(struct evsel *evsel, struct perf_bpf_filter_expr * if (evsel->core.attr.sample_type & expr->sample_flags) return 0; + if (expr->op == PBF_OP_GROUP_BEGIN) { + struct perf_bpf_filter_expr *group; + + list_for_each_entry(group, &expr->groups, list) { + if (check_sample_flags(evsel, group) < 0) + return -1; + } + return 0; + } + info = get_sample_info(expr->sample_flags); if (info == NULL) { pr_err("Error: %s event does not have sample flags %lx\n", From patchwork Fri Aug 11 02:58:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 134313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp856987vqi; Thu, 10 Aug 2023 21:52:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExAQMFX5+ZjMcVBmPcL8a/E55usP7XP1JpoCnn6fzpJU8TbItkMHCanXF79Dv19fjpGdkG X-Received: by 2002:a05:6a00:1496:b0:67b:8602:aa1e with SMTP id v22-20020a056a00149600b0067b8602aa1emr1078825pfu.28.1691729541552; Thu, 10 Aug 2023 21:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691729541; cv=none; d=google.com; s=arc-20160816; b=cPCjNoxWeDl2cOjly/8QfLfhDaWHVyeuTm5Y3UABbxcsZ/F8EBwiUkjJNVds8KHEY0 fu0xPjcrQzSvlHy1REFNH+fZVo5UQ/hs1m6l6zPAcbiIHsGt2G/TUhuBMu9ZDJxNL0fT lao7gB6/8g0TPxSRTSzlI/BNH0ko+nEvyxgEQjrA6EVlAbc38N2azGbsK/cd3S9GApZ+ dnlDMi8r3vVrgt3vdU+XEqpEDQo0Ez0tbm30zkLmaHUxpGpq5HVg3m25oiuCXmfgMbmj ZrTfAuilB//XwABvluJEGy5V7ZX2hpCJEMLmMoHYLyW3qFww+dbsAZWjcg0SCY7OJYXv iFjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=p3HQQCbZUQgMGtswL7NtUKKa35Z1CAMIgNgpjGVzPks=; fh=EbSlobM2m9l3rzJ0owM7iR55r2EsmTePs2hunuiAKDA=; b=rKcyXtYwKc/3ayjUS3gIhFeRw/J/++whjImBP3FeTIULE0wxyF1EwD21Vu2jQSvWD8 1ETAwDB66aN8ogkhoDKo1hezY1pnJpOZL9S2KoEloUgpuSQHgyMfUu6mEeqbt6BucDie 3F8q53mIXzZGHv0fd4whOe9T325EdzC6kRJQfEm8SiB/WB8zqj4ddZSr2x/6wypbBzvE WWQfz/J4qFfFcOPZjM4mZNDwnUsYxmawx6MZ3PXcmHsMPmzZ4vwGFGjjgiI0IuO/tmgV EPAf5eh5VuTLKeKVPGza1NIK9ILoJDV6y0cMfiwLibOC2ucJkKcmUoLlH8Be7KsSXX9c HBjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=U7Xg0vUC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g192-20020a636bc9000000b0054f9f9b333csi2775737pgc.686.2023.08.10.21.52.08; Thu, 10 Aug 2023 21:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=U7Xg0vUC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbjHKC6c (ORCPT + 99 others); Thu, 10 Aug 2023 22:58:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbjHKC6a (ORCPT ); Thu, 10 Aug 2023 22:58:30 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB9CC10D; Thu, 10 Aug 2023 19:58:29 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-56546b45f30so1240684a12.3; Thu, 10 Aug 2023 19:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691722709; x=1692327509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=p3HQQCbZUQgMGtswL7NtUKKa35Z1CAMIgNgpjGVzPks=; b=U7Xg0vUCJn2dGjJvtFxShAyxZLabTC6A855FIb4VVng+t+Y0CInQo0q4KFdA+tcl9O 3qd3+KwDns4jY+p1cceG9q+ZYWt21k9p9AzKnss6WTlhmb93JZUqcOe44b2oPFyyDzaL DgPBNix/z1JACyrEjb/4mcadFAKq6xcgF+EMHuRz/eQlpAwXqw8Qc21O8bzgcAcOSpe8 UlVCrcKyr6Bk0q/XPM0MSxote2JiaWfBAAmHkvKklxLVXuCRwVkFC6hiRYgj9mEIf0wf txgYQVY99OciCLunnSfKv1tJrGRl6p46pBTPDsgA6ew/ebLOblujAnGiLCSrbDh7fzjh pJkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691722709; x=1692327509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=p3HQQCbZUQgMGtswL7NtUKKa35Z1CAMIgNgpjGVzPks=; b=QMiUboyNqZ++1dqLZFZftl65KmMXJjGf/meNpW8hdL5Fc0Rt1Dib1XashoTa5VSlhT FmZC0p3gYhRHAOUyw7xMNIvUZFRjWf10H5Aidtl577DcdBc/c2h0KaMQFboOsT1qP42y Q2N9aIXBkExHcE1XA57FFT2kenz2Ug846jWwCSIP9DDY8dSmGCqtXYH3bU2g77BAQGG0 7K0NB5zAhNch91yrVYxYEBHuUEkxQBKxE5kXz7dDLRaNTyBsvI2psM8Ert0v6lyiesDp 50+2MxuVCIqUqGwo99MrBTUF3QXuYdm3lRIOVmCT6Ps54wQU/30vdY8vPjItCzsRecfB TzeA== X-Gm-Message-State: AOJu0YwGA9XeivQC3Zrs2mteuQMUk205Oc90U1iAoolhpOAv1aAm+Zxu ko3ToHm9Rz/IVmvzKG3IP+o= X-Received: by 2002:a17:903:11c9:b0:1bb:ce4a:5893 with SMTP id q9-20020a17090311c900b001bbce4a5893mr842388plh.30.1691722708974; Thu, 10 Aug 2023 19:58:28 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2a3:200:2328:6915:cbeb:39d4]) by smtp.gmail.com with ESMTPSA id b23-20020a170902b61700b001b9be3b94d3sm2526592pls.140.2023.08.10.19.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 19:58:28 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 2/2] perf test: Add perf record sample filtering test Date: Thu, 10 Aug 2023 19:58:22 -0700 Message-ID: <20230811025822.3859771-2-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811025822.3859771-1-namhyung@kernel.org> References: <20230811025822.3859771-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773906995426380047 X-GMAIL-MSGID: 1773906995426380047 $ sudo ./perf test 'sample filter' -v 94: perf record sample filtering (by BPF) tests : --- start --- test child forked, pid 3817527 Checking BPF-filter privilege Basic bpf-filter test Basic bpf-filter test [Success] Failing bpf-filter test Error: task-clock event does not have PERF_SAMPLE_CPU Failing bpf-filter test [Success] Group bpf-filter test Error: task-clock event does not have PERF_SAMPLE_CPU Error: task-clock event does not have PERF_SAMPLE_CODE_PAGE_SIZE Group bpf-filter test [Success] test child finished with 0 ---- end ---- perf record sample filtering (by BPF) tests: Ok Cc: Athira Rajeev Signed-off-by: Namhyung Kim --- tools/perf/tests/shell/record_bpf_filter.sh | 128 ++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100755 tools/perf/tests/shell/record_bpf_filter.sh diff --git a/tools/perf/tests/shell/record_bpf_filter.sh b/tools/perf/tests/shell/record_bpf_filter.sh new file mode 100755 index 000000000000..e76ea861b92c --- /dev/null +++ b/tools/perf/tests/shell/record_bpf_filter.sh @@ -0,0 +1,128 @@ +#!/bin/sh +# perf record sample filtering (by BPF) tests +# SPDX-License-Identifier: GPL-2.0 + +set -e + +err=0 +perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) + +cleanup() { + rm -f "${perfdata}" + rm -f "${perfdata}".old + trap - EXIT TERM INT +} + +trap_cleanup() { + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +test_bpf_filter_priv() { + echo "Checking BPF-filter privilege" + + if [ "$(id -u)" != 0 ] + then + echo "bpf-filter test [Skipped permission]" + err=2 + return + fi + if ! perf record -e task-clock --filter 'period > 1' \ + -o /dev/null --quiet true 2>&1 + then + echo "bpf-filter test [Skipped missing BPF support]" + err=2 + return + fi +} + +test_bpf_filter_basic() { + echo "Basic bpf-filter test" + + if ! perf record -e task-clock -c 10000 --filter 'ip < 0xffffffff00000000' \ + -o "${perfdata}" true 2> /dev/null + then + echo "Basic bpf-filter test [Failed record]" + err=1 + return + fi + if perf script -i "${perfdata}" -F ip | grep 'ffffffff[0-9a-f]*' + then + echo "Basic bpf-filter test [Failed invalid output]" + err=1 + return + fi + echo "Basic bpf-filter test [Success]" +} + +test_bpf_filter_fail() { + echo "Failing bpf-filter test" + + # 'cpu' requires PERF_SAMPLE_CPU flag + if ! perf record -e task-clock --filter 'cpu > 0' \ + -o /dev/null true 2>&1 | grep PERF_SAMPLE_CPU + then + echo "Failing bpf-filter test [Failed forbidden CPU]" + err=1 + return + fi + + if ! perf record --sample-cpu -e task-clock --filter 'cpu > 0' \ + -o /dev/null true 2>/dev/null + then + echo "Failing bpf-filter test [Failed should succeed]" + err=1 + return + fi + + echo "Failing bpf-filter test [Success]" +} + +test_bpf_filter_group() { + echo "Group bpf-filter test" + + if ! perf record -e task-clock --filter 'period > 1000 || ip > 0' \ + -o /dev/null true 2>/dev/null + then + echo "Group bpf-filter test [Failed should succeed]" + err=1 + return + fi + + if ! perf record -e task-clock --filter 'cpu > 0 || ip > 0' \ + -o /dev/null true 2>&1 | grep PERF_SAMPLE_CPU + then + echo "Group bpf-filter test [Failed forbidden CPU]" + err=1 + return + fi + + if ! perf record -e task-clock --filter 'period > 0 || code_pgsz > 4096' \ + -o /dev/null true 2>&1 | grep PERF_SAMPLE_CODE_PAGE_SIZE + then + echo "Group bpf-filter test [Failed forbidden CODE_PAGE_SIZE]" + err=1 + return + fi + + echo "Group bpf-filter test [Success]" +} + + +test_bpf_filter_priv + +if [ $err = 0 ]; then + test_bpf_filter_basic +fi + +if [ $err = 0 ]; then + test_bpf_filter_fail +fi + +if [ $err = 0 ]; then + test_bpf_filter_group +fi + +cleanup +exit $err