Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp658463pxa; Sat, 1 Aug 2020 01:52:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMvIzIU+KX24qQgUx1D0dYMRSD/JGtGtox+qmaFVJRS7DIFBrlJr7Los05Sv65OaBLJJcu X-Received: by 2002:a17:906:7e15:: with SMTP id e21mr6416450ejr.509.1596271955121; Sat, 01 Aug 2020 01:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596271955; cv=none; d=google.com; s=arc-20160816; b=sdS4zpzcZrJglTtX6IPqS13KqUovcOvLjXW4sWv9qYpF0ABPB7cRJEJ/R3a+QPtQEi EJouaP6JRyzf2vBEdeOtsvTB+on+oj8wdIbsvyfDKGyzb/wSTgfAylzJWryuDnsoWBGZ ylTpbG3sfrZTIgesA3vRAt1zdT85uCcHYLf/g7gewZp9HGnwTL5yPO/dlhjl4BmWBXPj RbnV3WRkmUis0XuLaOfzvyqwAq7aI8Dwc7Pnltmwh1tfK6APRGs983Jk6aXxm1KRnuJM Y3GwcrdYo3MnBsRfJJFu3Q1i3kUzr97UekJfrcmmGRN2f+lJtaws5zsoOu91V5o3c5lp TAwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding: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=z7vjiGAmkhwUcg5IYNZ76D5TPUyJPfJv4wlpMkbHcUc=; b=Rfml0PgbJgc6n0lb5fYl+8XtZ3007OzD5JHRMa/QkmeCV5WGAA9J4Nw2YEEQPiVZhI c3Mw5ZttgPniz1LyD7jPQ8M6oaiJ3WrUtQhlFgqwH6h04soYPNpIZm3RWeVASvUSdXpZ GDRmLcQD6l1ghpF0wuPIRbG00h4nqaSmMnegTJKR93q1MAI71bVk88j/47eyz/D9c8qR ovq+IFt/FB9eMFtyuxOMhTsYGl7TOjEe2RLhw53lzW7r32Rw9sIYhtyf/03iukYEWMVf u663Vh/AK3n7schvLgnQj2rtvzECEgqZHeEJd5kF8/aJXooUaes4HrfAVLHmDvkLZnk3 Za5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=h6EFg7Jw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lm15si2920054ejb.129.2020.08.01.01.52.12; Sat, 01 Aug 2020 01:52:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=h6EFg7Jw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728645AbgHAIt6 (ORCPT + 99 others); Sat, 1 Aug 2020 04:49:58 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:35148 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727116AbgHAIt5 (ORCPT ); Sat, 1 Aug 2020 04:49:57 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0718nuln012052 for ; Sat, 1 Aug 2020 01:49:56 -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-transfer-encoding : content-type; s=facebook; bh=z7vjiGAmkhwUcg5IYNZ76D5TPUyJPfJv4wlpMkbHcUc=; b=h6EFg7JwV4Qe3IGjYRDknj85WTv9VzvZnno079iMsQk6UHU0AGGDDLgqoTb8t2dnpMDN S1hKMXQ9sbyfKMXy2eBdaJ/alDcUqbbeZwf5hTB7UHOMNjvdqb+mRFiZgpK120tGeaZB JubI5kCzG4LraJlGMq9egZ+THrRSq7yX4X0= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 32k7hwfg5a-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sat, 01 Aug 2020 01:49:56 -0700 Received: from intmgw002.08.frc2.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:21d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Sat, 1 Aug 2020 01:49:55 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id B2CAB62E53CF; Sat, 1 Aug 2020 01:47:31 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , , , , Song Liu Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next 4/5] selftests/bpf: move two functions to test_progs.c Date: Sat, 1 Aug 2020 01:47:20 -0700 Message-ID: <20200801084721.1812607-5-songliubraving@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200801084721.1812607-1-songliubraving@fb.com> References: <20200801084721.1812607-1-songliubraving@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-01_07:2020-07-31,2020-08-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 suspectscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 impostorscore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008010068 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move time_get_ns() and get_base_addr() to test_progs.c, so they can be used in other tests. Signed-off-by: Song Liu --- .../selftests/bpf/prog_tests/attach_probe.c | 21 ------------- .../selftests/bpf/prog_tests/test_overhead.c | 8 ----- tools/testing/selftests/bpf/test_progs.c | 30 +++++++++++++++++++ tools/testing/selftests/bpf/test_progs.h | 2 ++ 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tool= s/testing/selftests/bpf/prog_tests/attach_probe.c index a0ee87c8e1ea7..3bda8acbbafb5 100644 --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c @@ -2,27 +2,6 @@ #include #include "test_attach_probe.skel.h" =20 -ssize_t get_base_addr() { - size_t start, offset; - char buf[256]; - FILE *f; - - f =3D fopen("/proc/self/maps", "r"); - if (!f) - return -errno; - - while (fscanf(f, "%zx-%*x %s %zx %*[^\n]\n", - &start, buf, &offset) =3D=3D 3) { - if (strcmp(buf, "r-xp") =3D=3D 0) { - fclose(f); - return start - offset; - } - } - - fclose(f); - return -EINVAL; -} - void test_attach_probe(void) { int duration =3D 0; diff --git a/tools/testing/selftests/bpf/prog_tests/test_overhead.c b/too= ls/testing/selftests/bpf/prog_tests/test_overhead.c index 2702df2b23433..3fe32e9357c4b 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_overhead.c +++ b/tools/testing/selftests/bpf/prog_tests/test_overhead.c @@ -7,14 +7,6 @@ =20 #define MAX_CNT 100000 =20 -static __u64 time_get_ns(void) -{ - struct timespec ts; - - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1000000000ull + ts.tv_nsec; -} - static int test_task_rename(const char *prog) { int i, fd, duration =3D 0, err; diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/sel= ftests/bpf/test_progs.c index b1e4dadacd9b4..c9e6a5ad5b9a4 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -622,6 +622,36 @@ int cd_flavor_subdir(const char *exec_name) return chdir(flavor); } =20 +__u64 time_get_ns(void) +{ + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec * 1000000000ull + ts.tv_nsec; +} + +ssize_t get_base_addr(void) +{ + size_t start, offset; + char buf[256]; + FILE *f; + + f =3D fopen("/proc/self/maps", "r"); + if (!f) + return -errno; + + while (fscanf(f, "%zx-%*x %s %zx %*[^\n]\n", + &start, buf, &offset) =3D=3D 3) { + if (strcmp(buf, "r-xp") =3D=3D 0) { + fclose(f); + return start - offset; + } + } + + fclose(f); + return -EINVAL; +} + #define MAX_BACKTRACE_SZ 128 void crash_handler(int signum) { diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/sel= ftests/bpf/test_progs.h index 6e09bf738473e..2d617201024bf 100644 --- a/tools/testing/selftests/bpf/test_progs.h +++ b/tools/testing/selftests/bpf/test_progs.h @@ -91,6 +91,8 @@ extern bool test__start_subtest(const char *name); extern void test__skip(void); extern void test__fail(void); extern int test__join_cgroup(const char *path); +extern __u64 time_get_ns(void); +extern ssize_t get_base_addr(); =20 #define PRINT_FAIL(format...) = \ ({ = \ --=20 2.24.1