diff mbox series

[3/3] mm/selftests: Fix pagemap_ioctl memory map test

Message ID 20231116201547.536857-4-peterx@redhat.com (mailing list archive)
State New
Headers show
Series mm/pagemap: A few fixes to the recent PAGEMAP_SCAN | expand

Commit Message

Peter Xu Nov. 16, 2023, 8:15 p.m. UTC
__FILE__ is not guaranteed to exist in current dir.  Replace that with
argv[0] for memory map test.

Fixes: 46fd75d4a3c9 ("selftests: mm: add pagemap ioctl tests")
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 tools/testing/selftests/mm/pagemap_ioctl.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

David Hildenbrand Nov. 16, 2023, 11:10 p.m. UTC | #1
On 16.11.23 21:15, Peter Xu wrote:
> __FILE__ is not guaranteed to exist in current dir.  Replace that with
> argv[0] for memory map test.
> 
> Fixes: 46fd75d4a3c9 ("selftests: mm: add pagemap ioctl tests")
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>   tools/testing/selftests/mm/pagemap_ioctl.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
> index befab43719ba..d59517ed3d48 100644
> --- a/tools/testing/selftests/mm/pagemap_ioctl.c
> +++ b/tools/testing/selftests/mm/pagemap_ioctl.c
> @@ -36,6 +36,7 @@ int pagemap_fd;
>   int uffd;
>   int page_size;
>   int hpage_size;
> +const char *progname;
>   
>   #define LEN(region)	((region.end - region.start)/page_size)
>   
> @@ -1149,11 +1150,11 @@ int sanity_tests(void)
>   	munmap(mem, mem_size);
>   
>   	/* 9. Memory mapped file */
> -	fd = open(__FILE__, O_RDONLY);
> +	fd = open(progname, O_RDONLY);
>   	if (fd < 0)
>   		ksft_exit_fail_msg("%s Memory mapped file\n", __func__);
>   
> -	ret = stat(__FILE__, &sbuf);
> +	ret = stat(progname, &sbuf);
>   	if (ret < 0)
>   		ksft_exit_fail_msg("error %d %d %s\n", ret, errno, strerror(errno));
>   
> @@ -1472,12 +1473,14 @@ static void transact_test(int page_size)
>   			      extra_thread_faults);
>   }
>   
> -int main(void)
> +int main(int argc, char *argv[])
>   {
>   	int mem_size, shmid, buf_size, fd, i, ret;
>   	char *mem, *map, *fmem;
>   	struct stat sbuf;
>   
> +	progname = argv[0];
> +
>   	ksft_print_header();
>   
>   	if (init_uffd())

Reviewed-by: David Hildenbrand <david@redhat.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
index befab43719ba..d59517ed3d48 100644
--- a/tools/testing/selftests/mm/pagemap_ioctl.c
+++ b/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -36,6 +36,7 @@  int pagemap_fd;
 int uffd;
 int page_size;
 int hpage_size;
+const char *progname;
 
 #define LEN(region)	((region.end - region.start)/page_size)
 
@@ -1149,11 +1150,11 @@  int sanity_tests(void)
 	munmap(mem, mem_size);
 
 	/* 9. Memory mapped file */
-	fd = open(__FILE__, O_RDONLY);
+	fd = open(progname, O_RDONLY);
 	if (fd < 0)
 		ksft_exit_fail_msg("%s Memory mapped file\n", __func__);
 
-	ret = stat(__FILE__, &sbuf);
+	ret = stat(progname, &sbuf);
 	if (ret < 0)
 		ksft_exit_fail_msg("error %d %d %s\n", ret, errno, strerror(errno));
 
@@ -1472,12 +1473,14 @@  static void transact_test(int page_size)
 			      extra_thread_faults);
 }
 
-int main(void)
+int main(int argc, char *argv[])
 {
 	int mem_size, shmid, buf_size, fd, i, ret;
 	char *mem, *map, *fmem;
 	struct stat sbuf;
 
+	progname = argv[0];
+
 	ksft_print_header();
 
 	if (init_uffd())