[LTP] [PATCH 03/13] Hugetlb: Migrating libhugetlbfs mmap-gettest
Li Wang
liwang@redhat.com
Mon Dec 26 08:33:29 CET 2022
On Sun, Dec 25, 2022 at 11:42 PM Tarun Sahu <tsahu@linux.ibm.com> wrote:
> Migrating the libhugetlbfs/testcases/mmap-gettest.c test
>
> Test Description: This baseline test validates that a mapping of a
> certain size can be created, correctly. Once created, all the pages are
> filled with a pattern and rechecked to test for corruption. The mapping is
> then released. This process is repeated for a specified number of
> iterations.
>
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
>
Reviewed-by: Li Wang <liwang@redhat.com>
> ---
> runtest/hugetlb | 1 +
> testcases/kernel/mem/.gitignore | 1 +
> .../kernel/mem/hugetlb/hugemmap/hugemmap22.c | 104 ++++++++++++++++++
> 3 files changed, 106 insertions(+)
> create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
>
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index 71b4d57e4..8e80db140 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -23,6 +23,7 @@ hugemmap18 hugemmap18
> hugemmap19 hugemmap19
> hugemmap20 hugemmap20
> hugemmap21 hugemmap21
> +hugemmap22 hugemmap22
> hugemmap05_1 hugemmap05 -m
> hugemmap05_2 hugemmap05 -s
> hugemmap05_3 hugemmap05 -s -m
> diff --git a/testcases/kernel/mem/.gitignore
> b/testcases/kernel/mem/.gitignore
> index 74edfa392..0fd01dbce 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -22,6 +22,7 @@
> /hugetlb/hugemmap/hugemmap19
> /hugetlb/hugemmap/hugemmap20
> /hugetlb/hugemmap/hugemmap21
> +/hugetlb/hugemmap/hugemmap22
> /hugetlb/hugeshmat/hugeshmat01
> /hugetlb/hugeshmat/hugeshmat02
> /hugetlb/hugeshmat/hugeshmat03
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
> b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
> new file mode 100644
> index 000000000..50addbe62
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
> @@ -0,0 +1,104 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2005-2006 IBM Corporation.
> + * Author: David Gibson & Adam Litke
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This baseline test validates that a mapping of a certain size can be
> + * created, correctly. Once created, all the pages are filled with a
> + * pattern and rechecked to test for corruption. The mapping is then
> + * released. This process is repeated for a specified number of
> + * iterations.
> + */
> +
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <unistd.h>
> +#include <unistd.h>
> +
> +#include "hugetlb.h"
> +
> +#define ITERATIONS 10
>
I don't think we need too many iterations, it will cost too
much time and easily timed out on a slower machine,
so at most cycling up two times should be enough.
> +#define NR_HUGEPAGES 2
> +#define MNTPOINT "hugetlbfs/"
> +
> +static unsigned long hpage_size;
> +static int fd = -1;
> +
> +static void test_per_iteration(size_t size, int iter)
> +{
> + char *m;
> + size_t i, j;
> + char pattern = 'A';
> +
> + fd = tst_creat_unlinked(MNTPOINT, 0);
> + m = SAFE_MMAP(NULL, size, (PROT_READ|PROT_WRITE), MAP_SHARED, fd,
> 0);
> +
> + for (i = 0; i < NR_HUGEPAGES; i++) {
> + for (j = 0; j < hpage_size; j++) {
> + if (*(m+(i*hpage_size)+j) != 0) {
> + tst_res(TFAIL, "Iter %d: Verifying the
> mmap area failed. "
> + "Got %c, expected 0", iter,
> + *(m+(i*hpage_size)+j));
> + goto cleanup;
> + }
> + }
> + }
> + for (i = 0; i < NR_HUGEPAGES; i++) {
> + pattern = 65+(i%26);
> + memset(m+(i*hpage_size), pattern, hpage_size);
> + }
> +
> + for (i = 0; i < NR_HUGEPAGES; i++) {
> + pattern = 65+(i%26);
> + for (j = 0; j < hpage_size; j++) {
> + if (*(m+(i*hpage_size)+j) != pattern) {
> + tst_res(TFAIL, "Verifying the mmap area
> failed. "
> + "got: %c, expected: %c",
> + *(m+(i*hpage_size)+j), pattern);
> + goto cleanup;
> + }
> + }
> + }
> +
> +cleanup:
> + SAFE_MUNMAP(m, size);
> + SAFE_CLOSE(fd);
> +}
> +
> +static void run_test(void)
> +{
> + size_t size;
> + int i;
> +
> + size = NR_HUGEPAGES * hpage_size;
> + for (i = 0; i < ITERATIONS; i++)
> + test_per_iteration(size, i);
> +
> + tst_res(TPASS, "Successfully verified the mmap area.");
> +}
> +
> +static void setup(void)
> +{
> + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
>
hpage_size = tst_get_hugepage_size();
+}
> +
> +static void cleanup(void)
> +{
> + if (fd >= 0)
> + SAFE_CLOSE(fd);
> +}
> +
> +static struct tst_test test = {
> + .needs_root = 1,
> + .mntpoint = MNTPOINT,
> + .needs_hugetlbfs = 1,
> + .needs_tmpdir = 1,
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = run_test,
> + .hugepages = {NR_HUGEPAGES, TST_NEEDS},
> +};
> --
> 2.31.1
>
>
--
Regards,
Li Wang
More information about the ltp
mailing list