LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] selftests/memfd: move common code into common.c
@ 2018-04-17  8:59 Anders Roxell
  2018-05-08  9:38 ` Anders Roxell
  0 siblings, 1 reply; 3+ messages in thread
From: Anders Roxell @ 2018-04-17  8:59 UTC (permalink / raw)
  To: shuah, dh.herrmann; +Cc: linux-kselftest, linux-kernel, Anders Roxell

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 <anders.roxell@linaro.org>
---
 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/memfd: move common code into common.c
  2018-04-17  8:59 [PATCH] selftests/memfd: move common code into common.c Anders Roxell
@ 2018-05-08  9:38 ` Anders Roxell
  2018-05-08 15:33   ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Anders Roxell @ 2018-05-08  9:38 UTC (permalink / raw)
  To: Shuah Khan, David Herrmann
  Cc: linux-kselftest, Linux Kernel Mailing List, Anders Roxell

On 17 April 2018 at 10:59, Anders Roxell <anders.roxell@linaro.org> 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 <anders.roxell@linaro.org>
> ---
>  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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/memfd: move common code into common.c
  2018-05-08  9:38 ` Anders Roxell
@ 2018-05-08 15:33   ` Shuah Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2018-05-08 15:33 UTC (permalink / raw)
  To: Anders Roxell, David Herrmann
  Cc: linux-kselftest, Linux Kernel Mailing List, Shuah Khan

Hi David,

On 05/08/2018 03:38 AM, Anders Roxell wrote:
> On 17 April 2018 at 10:59, Anders Roxell <anders.roxell@linaro.org> 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 <anders.roxell@linaro.org>

Okay pull in this patch. I will queue this up for 4.18-rc1. 
Let me know if you have any objections.

>> ---
>>  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.
> 

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-08 15:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-17  8:59 [PATCH] selftests/memfd: move common code into common.c Anders Roxell
2018-05-08  9:38 ` Anders Roxell
2018-05-08 15:33   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).