Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp950443ybm; Wed, 22 May 2019 14:31:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqysP4wq7HZ58B33BJggrfdo4+8gO+8queNnLGOUqpKdW+8zwSsFM7Mph4yMmsM8ToqCt6nB X-Received: by 2002:a62:14d6:: with SMTP id 205mr98568652pfu.4.1558560693339; Wed, 22 May 2019 14:31:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558560693; cv=none; d=google.com; s=arc-20160816; b=pBHxB8ziChqsWZ1JctRx2y5hgTL7KwcGuojGIaq/jYIGR9ycoDH9JShN/KTEM21N0Q eIrl8oEwXrYsyADUNX7BB0p2pmoMT8uE2MZuo+qKZxc3nK1KyL+oOof3CJUi9eyg03T3 lyF5upPrb/sT4HgeLeiKSpebV+VXIwWt9l2j+OuNErd72vk2IZcm4TiJL5uZ5r2iV30y IGqGIY8MOnO/BxRJAcr+2QwJqdG4BUgUA5nbUPBFrTAQS3+tdXdCT3WuLGQp2vequEiM ql28oOHb/lJIwzxwoHFE/qPlufYD/lTjdvQCnPDMOVPFQE+ubdTRI9JyGteD/j3rOLrp o55w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix:dkim-signature; bh=4TamBFhMxI7eVZDyeQik75QRP7s+XDIcj/PxFC9FCqI=; b=aM7lTdwtNtS9o/ujnzqyiAYXZE5Zei2Z2aMUjSRIcEp17iyZ4qGQ8ePtfEFHeUzu2s tm/OpgaGpKEzoIGKYjKHRmX6MN295td+4W13h2Z4R0ayZrHoHMf0+myMXTPfa9xap26g qgW6sZ79KxnlRbrcboaGi89s3RYEpKlS3eI1QDQvVqG6hnaFzXzc/L+85y74vFCmD1Qw i6EiXA1hcE3325Vl+imc1roWRxVu7APTxEI5RmNyp0+xKt+EGi5oiRLMp6sVXtrzX5TJ umFdp33QraZtY8BkksSi/2HRvjME3M7B6CKzJDL6+SkrZWIYh+VlZeo80uYN3YKD8BB0 /65Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=hrSfMQXl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si25972203pgo.168.2019.05.22.14.31.17; Wed, 22 May 2019 14:31:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=hrSfMQXl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730230AbfEVV3n (ORCPT + 99 others); Wed, 22 May 2019 17:29:43 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:58184 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729771AbfEVV3m (ORCPT ); Wed, 22 May 2019 17:29:42 -0400 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x4MLLIJa026005 for ; Wed, 22 May 2019 14:29:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=4TamBFhMxI7eVZDyeQik75QRP7s+XDIcj/PxFC9FCqI=; b=hrSfMQXlWX3e2ugBLp6dlDBdgmdVT07HzTNOYTllL0bU9jxXQgDXIUrNOGahC4qMUO9R /Xxb10Z6dqPx3F4O71Mb0VipIGl19fwl2YeDXI1v2ujVe7sbP43vcIOaguoPGVg+o//D eADmCL4L+FuFQGehqldAcP/bg8mv0Qu9q+w= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2sn7jusrtq-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 22 May 2019 14:29:41 -0700 Received: from mx-out.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 22 May 2019 14:29:40 -0700 Received: by devvm2643.prn2.facebook.com (Postfix, from userid 111017) id 5D6F31251A298; Wed, 22 May 2019 14:29:39 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm2643.prn2.facebook.com To: CC: Alexei Starovoitov , Daniel Borkmann , , Tejun Heo , , , , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH bpf-next 2/4] selftests/bpf: convert test_cgrp2_attach2 example into kselftest Date: Wed, 22 May 2019 14:29:30 -0700 Message-ID: <20190522212932.2646247-3-guro@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522212932.2646247-1-guro@fb.com> References: <20190522212932.2646247-1-guro@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-05-22_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=13 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1905220148 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert test_cgrp2_attach2 example into a proper test_cgroup_attach kselftest. It's better because we do run kselftest on a constant basis, so there are better chances to spot a potential regression. Also make it slightly less verbose to conform kselftests output style. Output example: $ ./test_cgroup_attach #override:PASS #multi:PASS test_cgroup_attach:PASS Signed-off-by: Roman Gushchin --- samples/bpf/Makefile | 2 - tools/testing/selftests/bpf/Makefile | 4 +- .../selftests/bpf/test_cgroup_attach.c | 48 ++++++++++++------- 3 files changed, 35 insertions(+), 19 deletions(-) rename samples/bpf/test_cgrp2_attach2.c => tools/testing/selftests/bpf/test_cgroup_attach.c (92%) diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 4f0a1cdbfe7c..253e5a2856be 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -26,7 +26,6 @@ hostprogs-y += map_perf_test hostprogs-y += test_overhead hostprogs-y += test_cgrp2_array_pin hostprogs-y += test_cgrp2_attach -hostprogs-y += test_cgrp2_attach2 hostprogs-y += test_cgrp2_sock hostprogs-y += test_cgrp2_sock2 hostprogs-y += xdp1 @@ -81,7 +80,6 @@ map_perf_test-objs := bpf_load.o map_perf_test_user.o test_overhead-objs := bpf_load.o test_overhead_user.o test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o test_cgrp2_attach-objs := test_cgrp2_attach.o -test_cgrp2_attach2-objs := test_cgrp2_attach2.o $(CGROUP_HELPERS) test_cgrp2_sock-objs := test_cgrp2_sock.o test_cgrp2_sock2-objs := bpf_load.o test_cgrp2_sock2.o xdp1-objs := xdp1_user.o diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 66f2dca1dee1..e09f419f4d7e 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -23,7 +23,8 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user \ test_socket_cookie test_cgroup_storage test_select_reuseport test_section_names \ - test_netcnt test_tcpnotify_user test_sock_fields test_sysctl + test_netcnt test_tcpnotify_user test_sock_fields test_sysctl \ + test_cgroup_attach BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c))) TEST_GEN_FILES = $(BPF_OBJ_FILES) @@ -96,6 +97,7 @@ $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c $(OUTPUT)/test_netcnt: cgroup_helpers.c $(OUTPUT)/test_sock_fields: cgroup_helpers.c $(OUTPUT)/test_sysctl: cgroup_helpers.c +$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c .PHONY: force diff --git a/samples/bpf/test_cgrp2_attach2.c b/tools/testing/selftests/bpf/test_cgroup_attach.c similarity index 92% rename from samples/bpf/test_cgrp2_attach2.c rename to tools/testing/selftests/bpf/test_cgroup_attach.c index 0bb6507256b7..93d4fe295e7d 100644 --- a/samples/bpf/test_cgrp2_attach2.c +++ b/tools/testing/selftests/bpf/test_cgroup_attach.c @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0 + /* eBPF example program: * * - Creates arraymap in kernel with 4 bytes keys and 8 byte values @@ -25,20 +27,27 @@ #include #include #include +#include #include #include -#include "bpf_insn.h" +#include "bpf_util.h" #include "bpf_rlimit.h" #include "cgroup_helpers.h" #define FOO "/foo" #define BAR "/foo/bar/" -#define PING_CMD "ping -c1 -w1 127.0.0.1 > /dev/null" +#define PING_CMD "ping -q -c1 -w1 127.0.0.1 > /dev/null" char bpf_log_buf[BPF_LOG_BUF_SIZE]; +#ifdef DEBUG +#define debug(args...) printf(args) +#else +#define debug(args...) +#endif + static int prog_load(int verdict) { int ret; @@ -89,7 +98,7 @@ static int test_foo_bar(void) goto err; } - printf("Attached DROP prog. This ping in cgroup /foo should fail...\n"); + debug("Attached DROP prog. This ping in cgroup /foo should fail...\n"); assert(system(PING_CMD) != 0); /* Create cgroup /foo/bar, get fd, and join it */ @@ -100,7 +109,7 @@ static int test_foo_bar(void) if (join_cgroup(BAR)) goto err; - printf("Attached DROP prog. This ping in cgroup /foo/bar should fail...\n"); + debug("Attached DROP prog. This ping in cgroup /foo/bar should fail...\n"); assert(system(PING_CMD) != 0); if (bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS, @@ -109,7 +118,7 @@ static int test_foo_bar(void) goto err; } - printf("Attached PASS prog. This ping in cgroup /foo/bar should pass...\n"); + debug("Attached PASS prog. This ping in cgroup /foo/bar should pass...\n"); assert(system(PING_CMD) == 0); if (bpf_prog_detach(bar, BPF_CGROUP_INET_EGRESS)) { @@ -117,7 +126,7 @@ static int test_foo_bar(void) goto err; } - printf("Detached PASS from /foo/bar while DROP is attached to /foo.\n" + debug("Detached PASS from /foo/bar while DROP is attached to /foo.\n" "This ping in cgroup /foo/bar should fail...\n"); assert(system(PING_CMD) != 0); @@ -132,7 +141,7 @@ static int test_foo_bar(void) goto err; } - printf("Attached PASS from /foo/bar and detached DROP from /foo.\n" + debug("Attached PASS from /foo/bar and detached DROP from /foo.\n" "This ping in cgroup /foo/bar should pass...\n"); assert(system(PING_CMD) == 0); @@ -199,9 +208,9 @@ static int test_foo_bar(void) close(bar); cleanup_cgroup_environment(); if (!rc) - printf("### override:PASS\n"); + printf("#override:PASS\n"); else - printf("### override:FAIL\n"); + printf("#override:FAIL\n"); return rc; } @@ -441,19 +450,26 @@ static int test_multiprog(void) close(cg5); cleanup_cgroup_environment(); if (!rc) - printf("### multi:PASS\n"); + printf("#multi:PASS\n"); else - printf("### multi:FAIL\n"); + printf("#multi:FAIL\n"); return rc; } int main(int argc, char **argv) { - int rc = 0; + int (*tests[])(void) = {test_foo_bar, test_multiprog}; + int errors = 0; + int i; - rc = test_foo_bar(); - if (rc) - return rc; + for (i = 0; i < ARRAY_SIZE(tests); i++) + if (tests[i]()) + errors++; + + if (errors) + printf("test_cgroup_attach:FAIL\n"); + else + printf("test_cgroup_attach:PASS\n"); - return test_multiprog(); + return errors ? EXIT_FAILURE : EXIT_SUCCESS; } -- 2.20.1