Received: by 10.192.165.156 with SMTP id m28csp1598883imm; Tue, 17 Apr 2018 02:02:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ONt1kvtMxZUNXHKB9XxVxYr3zPDoZSjMJOGuflhYGri7AaPZw90xMSUFynZUpAfCpmqAh X-Received: by 2002:a17:902:6b87:: with SMTP id p7-v6mr1274397plk.101.1523955762371; Tue, 17 Apr 2018 02:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523955762; cv=none; d=google.com; s=arc-20160816; b=kediugIZUs4Zg3bUsPq/+hmtTEoMKP08c5nDqG+Qa3Lmx++piqmNUFAppLUbwLfCwi X4XYP9u1aDgtF4ofsIfeghL9FLt1GmmsFuix52cezF/G0oMmKabwEtj/zar/8ebjNeB3 bTK+usbePk4GEaxSGyNUwO0n6AH9gm9WJNu0chj3TMdxAG1Vx6J6G6Lhy55KBbvwKkA9 hFwDQaYfifW7EBsXB8PNzmlJEyqTa4gH2YSogrlv51Tyfky+DiRjLZifP0Y1S7L74IXR eMtN0axfAC9SFuHLm52pNX4SDZdLT4qoXz+SdU4AN7enwXy2j5N6735U3Ze31T+TNIsR BYWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=qFUvZuRlU2ve+DMPjFXbDj2JciqqcU34JZOBCLmkueI=; b=mAnGKyM1Y+9Vy6uPDrPkS17UsAxJcjlXxW2VJqXQpkJC7Dhw7vC44HoajgXDh8EX1b bxwTLntbIujfwIV+NLTjqaJ8VaMeSQIC6a1D943KlKK8C9Fx9Fw5eLFhsxN8X0SGJxqW 8HUt10bTWDM/qTjkE4e5Bl4lY1JQ8lmRfTwOmsObB2oVF2BB1hVjIAHJAjpe3duLH9oT hu/u75JPTw281Pomq/vlPmREEsNUyEsiJFiYedkZJPG8vVKddV99mM92yd6rsqmvlsR7 Z+ys13yDFwNXkCjgjz+051/EVkBZFb7xs1NwzmPBeU20kupATJDw9n+9SU/BZ6hmfEBJ ZSeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZNAZo2Z2; 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 x1-v6si14196822plr.391.2018.04.17.02.02.28; Tue, 17 Apr 2018 02:02:42 -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=ZNAZo2Z2; 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 S1752332AbeDQJAD (ORCPT + 99 others); Tue, 17 Apr 2018 05:00:03 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:39778 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752231AbeDQJAC (ORCPT ); Tue, 17 Apr 2018 05:00:02 -0400 Received: by mail-lf0-f65.google.com with SMTP id p142-v6so26161420lfd.6 for ; Tue, 17 Apr 2018 02:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=qFUvZuRlU2ve+DMPjFXbDj2JciqqcU34JZOBCLmkueI=; b=ZNAZo2Z2MWimfPdKWXEo7PJZqzrs8O7t8URXG7SvTrDnlDujNIhmcLSNSLjXbR4t/J atlmW/7Qk0nHjSjBn1xf0O3zJsBnTDnfuZ2oSlgPXkaa+JNBdy/ewD0oPjignLVYr5uk c++l/W4hrsQCHNYzG4ftngOt2raiY4BBhosCI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qFUvZuRlU2ve+DMPjFXbDj2JciqqcU34JZOBCLmkueI=; b=Y0ow0ysORdq33f1y591+J3/wUloCusP0tbgpFswrTPnrDYFcw+ZtbVdJuaMMPl9huR oES7gJ/8ndq84l/D1O4Fgq890jQsEq/FHL9B4HFGxIM/s5J5+pG6jfL8SnkwflnbBHtl w7a4eHedjKF5k4i6Gt73CjFl1wkvjBjdQmbNWUrwY3CZbz/VFbddDDXTtmfZJoVHnILR xoddPqJ0876enP/crjr8OQ4L6lsP/MSlkINNVoEMBu40Fy3rVTUNE+M+Wv6YvgfjCcJB Q92lY7m3UMTj1CYG4dszi8gayqgG1nC5QWA2PULw3E3d5qv5P3c4gVrmZYreO940WJ4/ D3aA== X-Gm-Message-State: ALQs6tB7fs3C3C05ZvYrm1A4HsT4zzyxnbiS4Hqeokue3h9Cfmu7F5RB AtVKLmHCcxqv3/1Yh4IAmCv3Xg== X-Received: by 2002:a19:9d12:: with SMTP id g18-v6mr913267lfe.142.1523955600519; Tue, 17 Apr 2018 02:00:00 -0700 (PDT) Received: from localhost (c-2c3d70d5.07-21-73746f28.cust.bredbandsbolaget.se. [213.112.61.44]) by smtp.gmail.com with ESMTPSA id y3sm592864lje.34.2018.04.17.01.59.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Apr 2018 01:59:59 -0700 (PDT) From: Anders Roxell To: shuah@kernel.org, dh.herrmann@gmail.com Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Anders Roxell Subject: [PATCH] selftests/memfd: move common code into common.c Date: Tue, 17 Apr 2018 10:59:36 +0200 Message-Id: <20180417085936.19512-1-anders.roxell@linaro.org> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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