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 02/12] selftests/mm: map_hugetlb: conform test to TAP format output
Date: Fri, 2 Feb 2024 16:31:09 +0500 [thread overview]
Message-ID: <20240202113119.2047740-3-usama.anjum@collabora.com> (raw)
In-Reply-To: <20240202113119.2047740-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/map_hugetlb.c | 42 +++++++++++-------------
1 file changed, 20 insertions(+), 22 deletions(-)
diff --git a/tools/testing/selftests/mm/map_hugetlb.c b/tools/testing/selftests/mm/map_hugetlb.c
index 86e8f2048a409..a1f005a90a4f0 100644
--- a/tools/testing/selftests/mm/map_hugetlb.c
+++ b/tools/testing/selftests/mm/map_hugetlb.c
@@ -16,6 +16,7 @@
#include <sys/mman.h>
#include <fcntl.h>
#include "vm_util.h"
+#include "../kselftest.h"
#define LENGTH (256UL*1024*1024)
#define PROTECTION (PROT_READ | PROT_WRITE)
@@ -31,7 +32,7 @@
static void check_bytes(char *addr)
{
- printf("First hex is %x\n", *((unsigned int *)addr));
+ ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
}
static void write_bytes(char *addr, size_t length)
@@ -42,23 +43,21 @@ static void write_bytes(char *addr, size_t length)
*(addr + i) = (char)i;
}
-static int read_bytes(char *addr, size_t length)
+static void read_bytes(char *addr, size_t length)
{
unsigned long i;
check_bytes(addr);
for (i = 0; i < length; i++)
- if (*(addr + i) != (char)i) {
- printf("Mismatch at %lu\n", i);
- return 1;
- }
- return 0;
+ if (*(addr + i) != (char)i)
+ ksft_exit_fail_msg("Mismatch at %lu\n", i);
+
+ ksft_test_result_pass("Read correct data\n");
}
int main(int argc, char **argv)
{
void *addr;
- int ret;
size_t hugepage_size;
size_t length = LENGTH;
int flags = FLAGS;
@@ -69,6 +68,9 @@ int main(int argc, char **argv)
if (hugepage_size > length)
length = hugepage_size;
+ ksft_print_header();
+ ksft_set_plan(1);
+
if (argc > 1)
length = atol(argv[1]) << 20;
if (argc > 2) {
@@ -78,27 +80,23 @@ int main(int argc, char **argv)
}
if (shift)
- printf("%u kB hugepages\n", 1 << (shift - 10));
+ ksft_print_msg("%u kB hugepages\n", 1 << (shift - 10));
else
- printf("Default size hugepages\n");
- printf("Mapping %lu Mbytes\n", (unsigned long)length >> 20);
+ ksft_print_msg("Default size hugepages\n");
+ ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20);
addr = mmap(ADDR, length, PROTECTION, flags, -1, 0);
- if (addr == MAP_FAILED) {
- perror("mmap");
- exit(1);
- }
+ if (addr == MAP_FAILED)
+ ksft_exit_fail_msg("mmap: %s\n", strerror(errno));
- printf("Returned address is %p\n", addr);
+ ksft_print_msg("Returned address is %p\n", addr);
check_bytes(addr);
write_bytes(addr, length);
- ret = read_bytes(addr, length);
+ read_bytes(addr, length);
/* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
- if (munmap(addr, length)) {
- perror("munmap");
- exit(1);
- }
+ if (munmap(addr, length))
+ ksft_exit_fail_msg("munmap: %s\n", strerror(errno));
- return ret;
+ ksft_finished();
}
--
2.42.0
next prev parent reply other threads:[~2024-02-02 11:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-02 11:31 [PATCH v2 00/12] conform tests " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 01/12] selftests/mm: map_fixed_noreplace: conform test " Muhammad Usama Anjum
2024-02-02 11:31 ` Muhammad Usama Anjum [this message]
2024-02-02 11:31 ` [PATCH v2 03/12] selftests/mm: map_populate: " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 04/12] selftests/mm: mlock-random-test: " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 05/12] selftests/mm: mlock2-tests: " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 06/12] selftests/mm: mrelease_test: " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 07/12] selftests/mm: mremap_dontunmap: " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 08/12] selftests/mm: split_huge_page_test: " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 09/12] selftests/mm: thp_settings: conform " Muhammad Usama Anjum
2024-02-14 17:19 ` Ryan Roberts
2024-02-14 18:00 ` Ryan Roberts
2024-02-15 4:59 ` Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 10/12] selftests/mm: thuge-gen: " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 11/12] selftests/mm: transhuge-stress: " Muhammad Usama Anjum
2024-02-02 11:31 ` [PATCH v2 12/12] selftests/mm: virtual_address_range: " Muhammad Usama Anjum
2024-03-14 5:00 ` Dev Jain
2024-03-14 8:46 ` Muhammad Usama Anjum
2024-03-14 12:22 ` [PATCH] selftests/mm: virtual_address_range: Switch to ksft_exit_fail_msg Dev Jain
2024-03-14 12:33 ` 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=20240202113119.2047740-3-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