From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: Andrew Morton <akpm@linux-foundation.org>, Shuah Khan <shuah@kernel.org>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>,
kernel@collabora.com, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/7] selftests/mm: hugepage-vmemmap: conform test to TAP format output
Date: Fri, 12 Jan 2024 12:21:35 +0500 [thread overview]
Message-ID: <20240112072144.620098-2-usama.anjum@collabora.com> (raw)
In-Reply-To: <20240112072144.620098-1-usama.anjum@collabora.com>
Conform the layout, informational and status messages to TAP. No
functional change is intended other than the layout of output messages.
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
tools/testing/selftests/mm/hugepage-vmemmap.c | 36 +++++++++----------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/tools/testing/selftests/mm/hugepage-vmemmap.c b/tools/testing/selftests/mm/hugepage-vmemmap.c
index 5b354c209e93..125b96a65286 100644
--- a/tools/testing/selftests/mm/hugepage-vmemmap.c
+++ b/tools/testing/selftests/mm/hugepage-vmemmap.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
+#include "../kselftest.h"
#define MAP_LENGTH (2UL * 1024 * 1024)
@@ -77,7 +78,7 @@ static int check_page_flags(unsigned long pfn)
read(fd, &pageflags, sizeof(pageflags));
if ((pageflags & HEAD_PAGE_FLAGS) != HEAD_PAGE_FLAGS) {
close(fd);
- printf("Head page flags (%lx) is invalid\n", pageflags);
+ ksft_print_msg("Head page flags (%lx) is invalid\n", pageflags);
return -1;
}
@@ -91,7 +92,7 @@ static int check_page_flags(unsigned long pfn)
if ((pageflags & TAIL_PAGE_FLAGS) != TAIL_PAGE_FLAGS ||
(pageflags & HEAD_PAGE_FLAGS) == HEAD_PAGE_FLAGS) {
close(fd);
- printf("Tail page flags (%lx) is invalid\n", pageflags);
+ ksft_print_msg("Tail page flags (%lx) is invalid\n", pageflags);
return -1;
}
}
@@ -106,11 +107,12 @@ int main(int argc, char **argv)
void *addr;
unsigned long pfn;
+ ksft_print_header();
+ ksft_set_plan(1);
+
addr = mmap(MAP_ADDR, MAP_LENGTH, PROT_READ | PROT_WRITE, MAP_FLAGS, -1, 0);
- if (addr == MAP_FAILED) {
- perror("mmap");
- exit(1);
- }
+ if (addr == MAP_FAILED)
+ ksft_exit_fail_msg("mmap: %s\n", strerror(errno));
/* Trigger allocation of HugeTLB page. */
write_bytes(addr, MAP_LENGTH);
@@ -118,23 +120,19 @@ int main(int argc, char **argv)
pfn = virt_to_pfn(addr);
if (pfn == -1UL) {
munmap(addr, MAP_LENGTH);
- perror("virt_to_pfn");
- exit(1);
+ ksft_exit_fail_msg("virt_to_pfn: %s\n", strerror(errno));
+ } else if (!pfn && geteuid()) {
+ ksft_test_result_skip("Unable to read the pfn as non-root user\n");
+ ksft_finished();
}
- printf("Returned address is %p whose pfn is %lx\n", addr, pfn);
+ ksft_print_msg("Returned address is %p whose pfn is %lx\n", addr, pfn);
- if (check_page_flags(pfn) < 0) {
- munmap(addr, MAP_LENGTH);
- perror("check_page_flags");
- exit(1);
- }
+ ksft_test_result(!check_page_flags(pfn), "Check page flags\n");
/* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
- if (munmap(addr, MAP_LENGTH)) {
- perror("munmap");
- exit(1);
- }
+ if (munmap(addr, MAP_LENGTH))
+ ksft_exit_fail_msg("munmap: %s\n", strerror(errno));
- return 0;
+ ksft_finished();
}
--
2.42.0
next prev parent reply other threads:[~2024-01-12 7:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-12 7:21 [PATCH v2 1/7] selftests/mm: hugepage-shm: " Muhammad Usama Anjum
2024-01-12 7:21 ` Muhammad Usama Anjum [this message]
2024-01-12 7:21 ` [PATCH v2 3/7] selftests/mm: hugetlb-madvise: " Muhammad Usama Anjum
2024-01-12 7:21 ` [PATCH v2 4/7] selftests/mm: khugepaged: " Muhammad Usama Anjum
2024-01-12 7:21 ` [PATCH v2 5/7] selftests/mm: hugetlb-read-hwpoison: " Muhammad Usama Anjum
2024-01-13 1:08 ` Jiaqi Yan
2024-01-15 6:33 ` Muhammad Usama Anjum
2024-01-15 6:52 ` Jiaqi Yan
2024-01-15 6:59 ` Muhammad Usama Anjum
2024-01-12 7:21 ` [PATCH v2 6/7] selftests/mm: ksm_tests: " Muhammad Usama Anjum
2024-01-12 7:21 ` [PATCH v2 7/7] selftests/mm: config: add missing configs Muhammad Usama Anjum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240112072144.620098-2-usama.anjum@collabora.com \
--to=usama.anjum@collabora.com \
--cc=akpm@linux-foundation.org \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox