linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests: hugetlb_dio: Check for initial conditions to skip in the start
@ 2024-11-01 14:15 Muhammad Usama Anjum
  2024-11-01 18:54 ` Andrew Morton
  2024-11-08 10:35 ` Donet Tom
  0 siblings, 2 replies; 11+ messages in thread
From: Muhammad Usama Anjum @ 2024-11-01 14:15 UTC (permalink / raw)
  To: Andrew Morton, Shuah Khan
  Cc: Muhammad Usama Anjum, kernel, linux-mm, linux-kselftest, linux-kernel

The test should be skipped if initial conditions aren't fulfilled in
the start instead of failing and outputting non-compliant TAP logs. This
kind of failure pollutes the results. The initial conditions are:
- The test should only execute if /tmp file can be allocated.
- The test should only execute if huge pages are free.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
Before:
TAP version 13
1..4
Bail out! Error opening file
: Read-only file system (30)
 # Planned tests != run tests (4 != 0)
 # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0

After:
TAP version 13
1..0 # SKIP Unable to allocate file: Read-only file system
---
 tools/testing/selftests/mm/hugetlb_dio.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
index f9ac20c657ec6..60001c142ce99 100644
--- a/tools/testing/selftests/mm/hugetlb_dio.c
+++ b/tools/testing/selftests/mm/hugetlb_dio.c
@@ -44,13 +44,6 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
 	if (fd < 0)
 		ksft_exit_fail_perror("Error opening file\n");
 
-	/* Get the free huge pages before allocation */
-	free_hpage_b = get_free_hugepages();
-	if (free_hpage_b == 0) {
-		close(fd);
-		ksft_exit_skip("No free hugepage, exiting!\n");
-	}
-
 	/* Allocate a hugetlb page */
 	orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0);
 	if (orig_buffer == MAP_FAILED) {
@@ -94,8 +87,20 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
 int main(void)
 {
 	size_t pagesize = 0;
+	int fd;
 
 	ksft_print_header();
+
+	/* Open the file to DIO */
+	fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);
+	if (fd < 0)
+		ksft_exit_skip("Unable to allocate file: %s\n", strerror(errno));
+	close(fd);
+
+	/* Check if huge pages are free */
+	if (!get_free_hugepages())
+		ksft_exit_skip("No free hugepage, exiting\n");
+
 	ksft_set_plan(4);
 
 	/* Get base page size */
-- 
2.39.5



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

end of thread, other threads:[~2024-12-05 15:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-01 14:15 [PATCH] selftests: hugetlb_dio: Check for initial conditions to skip in the start Muhammad Usama Anjum
2024-11-01 18:54 ` Andrew Morton
2024-11-08 10:35 ` Donet Tom
2024-11-08 10:49   ` Donet Tom
2024-11-08 14:13     ` Muhammad Usama Anjum
2024-11-10  6:20       ` Andrew Morton
2024-11-10  6:34         ` Andrew Morton
2024-11-10  6:49           ` [PATCH] selftests: hugetlb_dio: Fixup " Donet Tom
2024-11-10  6:52             ` Donet Tom
2024-11-11  6:59               ` Andrew Morton
2024-11-10  6:56             ` Donet Tom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox