Received: by 10.192.165.148 with SMTP id m20csp4085378imm; Tue, 8 May 2018 02:40:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrOBbqzfB+yTaPv9bz6Tk8fsFwT7msQC2bzizcmQQmJ6G8TLtxsnPcOeQV47aSQ30H67ASH X-Received: by 10.98.7.140 with SMTP id 12mr27984340pfh.178.1525772414254; Tue, 08 May 2018 02:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525772414; cv=none; d=google.com; s=arc-20160816; b=B5B8skAIKI8gEKen6ks5MpDW8wN1eEt78EVqkSw346QxekEl11H/Cg39nhqW67A315 gH1oCgKkDoa+5eusThJpsqBl1NmvlEKvbbpi/4SWPkW/3Y8KKFg7fjJQb+lNllquFfBe bp12wnyUDVPAApu+aKhGLrRx5xZS1Lnhnze4xAOH2F6ku0sLLq89XHUIuwiaT+uktd/x kAs29Pv5OOWj1gvPUveysv90eYNG/VdGkwhXYa4Vj17AzjgRDmfXb3xEgEjJYM19RgO3 2S+1HGwK5qWLgcXMp3Sh/NFJJky8UveEYm0TPRe0tkfaFz0p3meFi9KCZfL/N+nGeZA4 vgEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=bLMkeAnnvP5MDbIOWIOHGH1q4NoLssmHA73zJSQJIyU=; b=G3W5y0t9v8zBPx93dXi0hsOifpm0tPA984Pv0GvHf8lWscxGsT+7HKh4e1DEhYn8U5 YkWVEocqwOYCpZdicUV70wO8RSzCZX6jQACKpbfmatzwcOS72z2YSLqVZLV45nVKhSQ4 qzvKoqLJgE9FBsnMQf0wk0KeUstt6yN2oYsRFm4RhAouK91V2WwCYmryNiIm74hkxNFT aGyBVtHUIqCu1wlIfi8pjHQ8ebe8UlZvMHVtlJ4aCpjXA1SjYInU7ArAeheVnsWqEiJK vE49aF8AXHxZjgNp5ScCnjW7U1iVw+rOecMEeMRP4RJF/b7Q7MLcpDJpNE8mwz75I7ym c2+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GnG8ERM5; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h6-v6si23583714pll.21.2018.05.08.02.40.00; Tue, 08 May 2018 02:40:14 -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=@linaro.org header.s=google header.b=GnG8ERM5; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932190AbeEHJim (ORCPT + 99 others); Tue, 8 May 2018 05:38:42 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:36213 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754291AbeEHJik (ORCPT ); Tue, 8 May 2018 05:38:40 -0400 Received: by mail-pl0-f67.google.com with SMTP id v24-v6so1900453plo.3 for ; Tue, 08 May 2018 02:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=bLMkeAnnvP5MDbIOWIOHGH1q4NoLssmHA73zJSQJIyU=; b=GnG8ERM5SNX7eBSZ2a+AzEN4OJM+fLzDgXnmmQlgGttr0O8ywzlsD/tAje6gB66XJ6 NB5WW0329LsA0ITuYbcNhPCmROz/VkyDhiYkIPWIDPR/7ZBPvsg8BMxfvKRpnRZfh+g8 isbLTz8NPbLDbsprEDJkWlY+RBHPdDrsaQQHY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=bLMkeAnnvP5MDbIOWIOHGH1q4NoLssmHA73zJSQJIyU=; b=A+v0FPI/RB5i0aWVjxt2mQD65sA0iaHUbBlu3gqJYXmPXYQETt1AhmZAB66uNTnkcW fGvLXOZojZnKcf8QNSvqiZZ5PumlWLR6owJ7+G89IhCvH6fEhfexY9HGoQ/nuFGBWCi2 cvj0/x9xYmUUE/OxGbIy3z8VFG4qXQ+rrSyAXjpt5Goi0IH0ew0vtYJV7ow6SKdSp+sV 4qj6vlaWlPcdjxVr7IvoT0gtq/x/qJjB2yQV7WzQ7Km25FyemWp9DntRu9CH5GGaK7i4 bvBoPKgU0lP4+YtT8qNJVgbHGzYe4uSCsBQc+OroueJtgr09dSnWrPR+5sBg+kMukWYY qGVg== X-Gm-Message-State: ALQs6tBoz0doIlwClwxgqZstX5+MEFGtMfAmrOjimcXL+Vyj9DSuYrMD IBymrpX7bMNsct7mhjKeOqqmqYf6llG2r3Trqgi2Vg== X-Received: by 2002:a17:902:9304:: with SMTP id bc4-v6mr18212795plb.189.1525772319970; Tue, 08 May 2018 02:38:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.140.147 with HTTP; Tue, 8 May 2018 02:38:39 -0700 (PDT) In-Reply-To: <20180417085936.19512-1-anders.roxell@linaro.org> References: <20180417085936.19512-1-anders.roxell@linaro.org> From: Anders Roxell Date: Tue, 8 May 2018 11:38:39 +0200 Message-ID: Subject: Re: [PATCH] selftests/memfd: move common code into common.c To: Shuah Khan , David Herrmann Cc: linux-kselftest@vger.kernel.org, Linux Kernel Mailing List , Anders Roxell Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17 April 2018 at 10:59, Anders Roxell wrote: > Remove code duplication, in the current code, we move common code for > memfd to common.c. > > The duplicate functions got added in commit 87b2d44026e0 ("selftests: > add memfd/sealing page-pinning tests") > > Signed-off-by: Anders Roxell > --- > tools/testing/selftests/memfd/common.c | 37 +++++++++++++++++++ > tools/testing/selftests/memfd/common.h | 4 ++ > tools/testing/selftests/memfd/fuse_test.c | 43 +--------------------- > tools/testing/selftests/memfd/memfd_test.c | 37 ------------------- > 4 files changed, 43 insertions(+), 78 deletions(-) > > diff --git a/tools/testing/selftests/memfd/common.c b/tools/testing/selftests/memfd/common.c > index 8eb3d75f6e60..fee1f07828a3 100644 > --- a/tools/testing/selftests/memfd/common.c > +++ b/tools/testing/selftests/memfd/common.c > @@ -44,3 +44,40 @@ int sys_memfd_create(const char *name, unsigned int flags) > > return syscall(__NR_memfd_create, name, flags); > } > + > +unsigned int mfd_assert_get_seals(int fd) > +{ > + int r; > + > + r = fcntl(fd, F_GET_SEALS); > + if (r < 0) { > + printf("GET_SEALS(%d) failed: %m\n", fd); > + abort(); > + } > + > + return (unsigned int)r; > +} > + > +void mfd_assert_add_seals(int fd, unsigned int seals) > +{ > + int r; > + unsigned int s; > + > + s = mfd_assert_get_seals(fd); > + r = fcntl(fd, F_ADD_SEALS, seals); > + if (r < 0) { > + printf("ADD_SEALS(%d, %u -> %u) failed: %m\n", fd, s, seals); > + abort(); > + } > +} > + > +void mfd_assert_has_seals(int fd, unsigned int seals) > +{ > + unsigned int s; > + > + s = mfd_assert_get_seals(fd); > + if (s != seals) { > + printf("%u != %u = GET_SEALS(%d)\n", seals, s, fd); > + abort(); > + } > +} > diff --git a/tools/testing/selftests/memfd/common.h b/tools/testing/selftests/memfd/common.h > index 522d2c630bd8..5c778d15e8c7 100644 > --- a/tools/testing/selftests/memfd/common.h > +++ b/tools/testing/selftests/memfd/common.h > @@ -6,4 +6,8 @@ extern int hugetlbfs_test; > unsigned long default_huge_page_size(void); > int sys_memfd_create(const char *name, unsigned int flags); > > +void mfd_assert_add_seals(int fd, unsigned int seals); > +void mfd_assert_has_seals(int fd, unsigned int seals); > +unsigned int mfd_assert_get_seals(int fd); > + > #endif > diff --git a/tools/testing/selftests/memfd/fuse_test.c b/tools/testing/selftests/memfd/fuse_test.c > index b018e835737d..231714615861 100644 > --- a/tools/testing/selftests/memfd/fuse_test.c > +++ b/tools/testing/selftests/memfd/fuse_test.c > @@ -60,49 +60,10 @@ static int mfd_assert_new(const char *name, loff_t sz, unsigned int flags) > return fd; > } > > -static __u64 mfd_assert_get_seals(int fd) > +static int mfd_busy_add_seals(int fd, unsigned int seals) > { > long r; > - > - r = fcntl(fd, F_GET_SEALS); > - if (r < 0) { > - printf("GET_SEALS(%d) failed: %m\n", fd); > - abort(); > - } > - > - return r; > -} > - > -static void mfd_assert_has_seals(int fd, __u64 seals) > -{ > - __u64 s; > - > - s = mfd_assert_get_seals(fd); > - if (s != seals) { > - printf("%llu != %llu = GET_SEALS(%d)\n", > - (unsigned long long)seals, (unsigned long long)s, fd); > - abort(); > - } > -} > - > -static void mfd_assert_add_seals(int fd, __u64 seals) > -{ > - long r; > - __u64 s; > - > - s = mfd_assert_get_seals(fd); > - r = fcntl(fd, F_ADD_SEALS, seals); > - if (r < 0) { > - printf("ADD_SEALS(%d, %llu -> %llu) failed: %m\n", > - fd, (unsigned long long)s, (unsigned long long)seals); > - abort(); > - } > -} > - > -static int mfd_busy_add_seals(int fd, __u64 seals) > -{ > - long r; > - __u64 s; > + unsigned int s; > > r = fcntl(fd, F_GET_SEALS); > if (r < 0) > diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c > index 10baa1652fc2..527789de69b5 100644 > --- a/tools/testing/selftests/memfd/memfd_test.c > +++ b/tools/testing/selftests/memfd/memfd_test.c > @@ -67,43 +67,6 @@ static void mfd_fail_new(const char *name, unsigned int flags) > } > } > > -static unsigned int mfd_assert_get_seals(int fd) > -{ > - int r; > - > - r = fcntl(fd, F_GET_SEALS); > - if (r < 0) { > - printf("GET_SEALS(%d) failed: %m\n", fd); > - abort(); > - } > - > - return (unsigned int)r; > -} > - > -static void mfd_assert_has_seals(int fd, unsigned int seals) > -{ > - unsigned int s; > - > - s = mfd_assert_get_seals(fd); > - if (s != seals) { > - printf("%u != %u = GET_SEALS(%d)\n", seals, s, fd); > - abort(); > - } > -} > - > -static void mfd_assert_add_seals(int fd, unsigned int seals) > -{ > - int r; > - unsigned int s; > - > - s = mfd_assert_get_seals(fd); > - r = fcntl(fd, F_ADD_SEALS, seals); > - if (r < 0) { > - printf("ADD_SEALS(%d, %u -> %u) failed: %m\n", fd, s, seals); > - abort(); > - } > -} > - > static void mfd_fail_add_seals(int fd, unsigned int seals) > { > int r; > -- > 2.17.0 > Ping.