[LTP] [PATCH] Migrating the libhugetlbfs/testcases/shm-gettest.c test

Cyril Hrubis chrubis@suse.cz
Fri Sep 8 14:35:05 CEST 2023


Hi!
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c b/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
> new file mode 100644
> index 000000000..fb603b4ef
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
> @@ -0,0 +1,93 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2005-2006, IBM Corporation.
> + * Author: David Gibson & Adam Litke
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Test Name: shm-gettest.c
> + *
> + * This testcase creates shared memory segments backed by hugepages, 
                                                                       ^
		                                                Trailing
								space.

There are a few in the source and other coding style errors, please run
'make check' and fix all the reported problems.

> + * writes specific patterns to each segment, verifies pattern,
> + * and detaches a shared memory segments in a loop. 
> + * It ensures that the hugepage backed shared memory functionalities 
> + * works correctly by validating the data written to segment.
> + */
> +
> +#include "hugetlb.h"
> +#include "tst_safe_sysv_ipc.h"
> +
> +#define MNTPOINT "hugetlbfs/"
> +#define NR_HUGEPAGES 4
> +
> +static long hpage_size;
> +static unsigned int iter;
> +static int shmid = -1, key = -1;
> +
> +static void do_shmtest(size_t size) {
> +        size_t i, j;
> +        char pattern;
> +        char *shmaddr;
> +
> +        shmid = SAFE_SHMGET(key, size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
> +        tst_res(TINFO, "shmid: 0x%x\n", shmid);
> +
> +        shmaddr = SAFE_SHMAT(shmid, 0, SHM_RND);
> +        tst_res(TINFO, "shmaddr: %p\n", shmaddr);
> +
> +        for (i = 0; i < NR_HUGEPAGES; i++) {
> +                pattern = 65 + (i % 26);
> +                tst_res(TINFO, "Touching %p with %c\n",
> +                                shmaddr + (i * hpage_size), pattern);
> +                memset(shmaddr + (i * hpage_size), pattern, hpage_size);
> +        }
> +
> +        for (i = 0; i < NR_HUGEPAGES; i++) {
> +                pattern = 65 + (i % 26);
> +                tst_res(TINFO, "Verifying %p\n", (shmaddr + (i * hpage_size)));
> +                for (j = 0; j < (size_t)hpage_size; j++)
> +                        if (*(shmaddr + (i * hpage_size) + j) != pattern)
> +                                tst_res(TFAIL, "Verifying the segment failed."
> +                                        "Got %c, expected %c",
> +                                        *(shmaddr + (i * hpage_size) + j),
> +                                        pattern);
> +        }
> +        SAFE_SHMDT((const void *)shmaddr);
> +}
> +
> +static void run_test(void)
> +{
> +        int i;
> +        iter = 2;
> +        size_t size;
> +        size = NR_HUGEPAGES * hpage_size;
> +        for (i=0; i < (int)iter; i++)
> +                do_shmtest(size);
> +        tst_res(TPASS, "Successfully tested shared memory segment operations "
> +                        "backed by hugepages");

This is obviously wrong, you are reporting TPASS regardless if the
do_shmtest() reported failure or not. Ideally you should report TPASS
in the do_shmtest() function in a case that no failures have had
happened.

Also LTP test can run a number of iterations when passed -i parameter,
so instead of duplicating the functionality here the test should be
executed with -i 2 instead.

Also the test is not added into .gitignore and to runtest file
(runtest/hugetlb), which means that it wouldn't be executed at all.\

> +}
> +
> +static void setup(void)
> +{
> +        hpage_size = tst_get_hugepage_size();
> +        tst_res(TINFO, "hugepage size is  %ld", hpage_size);
> +}
> +
> +static void cleanup(void)
> +{
> +        if (shmid >= 0)
> +                // Remove the shared memory segment
> +                SAFE_SHMCTL(shmid, IPC_RMID, NULL);
> +}
> +
> +static struct tst_test test = {
> +        .needs_root = 1,
> +        .mntpoint = MNTPOINT,
> +        .needs_hugetlbfs = 1,
> +        .setup = setup,
> +        .cleanup = cleanup,
> +        .test_all = run_test,
> +        .hugepages = {NR_HUGEPAGES, TST_NEEDS},
> +};
> -- 
> 2.39.3
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list