Skip to content

Commit c811b0c

Browse files
musamaanjumakpm00
authored andcommitted
selftests/mm: transhuge-stress: conform to TAP format output
Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Link: https://lkml.kernel.org/r/20240202113119.2047740-12-usama.anjum@collabora.com Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b38bd9b commit c811b0c

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

tools/testing/selftests/mm/transhuge-stress.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <string.h>
1717
#include <sys/mman.h>
1818
#include "vm_util.h"
19+
#include "../kselftest.h"
1920

2021
int backing_fd = -1;
2122
int mmap_flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE;
@@ -34,6 +35,8 @@ int main(int argc, char **argv)
3435
int pagemap_fd;
3536
int duration = 0;
3637

38+
ksft_print_header();
39+
3740
ram = sysconf(_SC_PHYS_PAGES);
3841
if (ram > SIZE_MAX / psize() / 4)
3942
ram = SIZE_MAX / 4;
@@ -43,7 +46,8 @@ int main(int argc, char **argv)
4346

4447
while (++i < argc) {
4548
if (!strcmp(argv[i], "-h"))
46-
errx(1, "usage: %s [-f <filename>] [-d <duration>] [size in MiB]", argv[0]);
49+
ksft_exit_fail_msg("usage: %s [-f <filename>] [-d <duration>] [size in MiB]\n",
50+
argv[0]);
4751
else if (!strcmp(argv[i], "-f"))
4852
name = argv[++i];
4953
else if (!strcmp(argv[i], "-d"))
@@ -52,10 +56,12 @@ int main(int argc, char **argv)
5256
len = atoll(argv[i]) << 20;
5357
}
5458

59+
ksft_set_plan(1);
60+
5561
if (name) {
5662
backing_fd = open(name, O_RDWR);
5763
if (backing_fd == -1)
58-
errx(2, "open %s", name);
64+
ksft_exit_fail_msg("open %s\n", name);
5965
mmap_flags = MAP_SHARED;
6066
}
6167

@@ -65,21 +71,21 @@ int main(int argc, char **argv)
6571

6672
pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
6773
if (pagemap_fd < 0)
68-
err(2, "open pagemap");
74+
ksft_exit_fail_msg("open pagemap\n");
6975

7076
len -= len % HPAGE_SIZE;
7177
ptr = mmap(NULL, len + HPAGE_SIZE, PROT_RW, mmap_flags, backing_fd, 0);
7278
if (ptr == MAP_FAILED)
73-
err(2, "initial mmap");
79+
ksft_exit_fail_msg("initial mmap");
7480
ptr += HPAGE_SIZE - (uintptr_t)ptr % HPAGE_SIZE;
7581

7682
if (madvise(ptr, len, MADV_HUGEPAGE))
77-
err(2, "MADV_HUGEPAGE");
83+
ksft_exit_fail_msg("MADV_HUGEPAGE");
7884

7985
map_len = ram >> (HPAGE_SHIFT - 1);
8086
map = malloc(map_len);
8187
if (!map)
82-
errx(2, "map malloc");
88+
ksft_exit_fail_msg("map malloc\n");
8389

8490
clock_gettime(CLOCK_MONOTONIC, &start);
8591

@@ -103,7 +109,7 @@ int main(int argc, char **argv)
103109
if (idx >= map_len) {
104110
map = realloc(map, idx + 1);
105111
if (!map)
106-
errx(2, "map realloc");
112+
ksft_exit_fail_msg("map realloc\n");
107113
memset(map + map_len, 0, idx + 1 - map_len);
108114
map_len = idx + 1;
109115
}
@@ -114,17 +120,19 @@ int main(int argc, char **argv)
114120

115121
/* split transhuge page, keep last page */
116122
if (madvise(p, HPAGE_SIZE - psize(), MADV_DONTNEED))
117-
err(2, "MADV_DONTNEED");
123+
ksft_exit_fail_msg("MADV_DONTNEED");
118124
}
119125
clock_gettime(CLOCK_MONOTONIC, &b);
120126
s = b.tv_sec - a.tv_sec + (b.tv_nsec - a.tv_nsec) / 1000000000.;
121127

122-
warnx("%.3f s/loop, %.3f ms/page, %10.3f MiB/s\t"
123-
"%4d succeed, %4d failed, %4d different pages",
124-
s, s * 1000 / (len >> HPAGE_SHIFT), len / s / (1 << 20),
125-
nr_succeed, nr_failed, nr_pages);
128+
ksft_print_msg("%.3f s/loop, %.3f ms/page, %10.3f MiB/s\t"
129+
"%4d succeed, %4d failed, %4d different pages\n",
130+
s, s * 1000 / (len >> HPAGE_SHIFT), len / s / (1 << 20),
131+
nr_succeed, nr_failed, nr_pages);
126132

127-
if (duration > 0 && b.tv_sec - start.tv_sec >= duration)
128-
return 0;
133+
if (duration > 0 && b.tv_sec - start.tv_sec >= duration) {
134+
ksft_test_result_pass("Completed\n");
135+
ksft_finished();
136+
}
129137
}
130138
}

tools/testing/selftests/mm/vm_util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,17 @@ int64_t allocate_transhuge(void *ptr, int pagemap_fd)
232232
if (mmap(ptr, HPAGE_SIZE, PROT_READ | PROT_WRITE,
233233
MAP_FIXED | MAP_ANONYMOUS |
234234
MAP_NORESERVE | MAP_PRIVATE, -1, 0) != ptr)
235-
errx(2, "mmap transhuge");
235+
ksft_exit_fail_msg("mmap transhuge\n");
236236

237237
if (madvise(ptr, HPAGE_SIZE, MADV_HUGEPAGE))
238-
err(2, "MADV_HUGEPAGE");
238+
ksft_exit_fail_msg("MADV_HUGEPAGE\n");
239239

240240
/* allocate transparent huge page */
241241
*(volatile void **)ptr = ptr;
242242

243243
if (pread(pagemap_fd, ent, sizeof(ent),
244244
(uintptr_t)ptr >> (pshift() - 3)) != sizeof(ent))
245-
err(2, "read pagemap");
245+
ksft_exit_fail_msg("read pagemap\n");
246246

247247
if (PAGEMAP_PRESENT(ent[0]) && PAGEMAP_PRESENT(ent[1]) &&
248248
PAGEMAP_PFN(ent[0]) + 1 == PAGEMAP_PFN(ent[1]) &&

0 commit comments

Comments
 (0)