Re: [LTP] [PATCH] [PATCH] Migrating the libhugetlbfs/testcases/straddle_4GB.c

Geetika M
2024-03-27T10:05:03Z

Hi Petr,

On 28/11/23 5:20 pm, Petr Vorel wrote:
> Hi Geetika,
>
> Please have look at my comments at your previous patch [1] [2], these changes
> apply a lot for your patches as well.
>
> [1]https://lore.kernel.org/ltp/20231128111024.GA364870@pevik/
> [2]https://lore.kernel.org/ltp/20231128112254.GA367506@pevik/
>
Noted.
I will apply whatever changes are applicable to this testcase in the
next version.

...
>> +
>> +/*\
>> + * [Description]
>> + * This test tries to allocate hugepages to cover a memory range
>> + * that straddles the 4GB boundary.
>> + * Scenario 1 : mmap without MAP_FIXED
>> + * Scenario 2 : mmap with MAP_FIXED
> This will be badly formatted (it will not be list, but inline).
>
> How about:
>
> /*\
> * [Description]
> *
> * Test tries to allocate hugepages to cover a memory range that straddles the
> * 4GB boundary, using mmap(2) with and without MAP_FIXED.
> */
>> + */
>> +
>> +#define MAPS_BUF_SZ 4096
>> +#define FOURGB (1UL << 32)
>> +#define MNTPOINT "hugetlbfs/"
>> +#define HUGETLBFS_MAGIC 0x958458f6
> Could you please add this magic definition to include/tst_fs.h
> (as a separate patch), we store all magic there.
>
>> +#define _LARGEFILE64_SOURCE /* Need this for statfs64 */
> We would probably define it in Makefile
>
> hugemmap40: CFLAGS += -D_LARGEFILE64_SOURCE
Noted.
I will apply above changes with the next version.

...

> +
> +static void run_test(void)
> +{
> + void *p;
> +
> + /* We first try to get the mapping without MAP_FIXED */
> + tst_res(TINFO, "Mapping without MAP_FIXED at %lx...", straddle_addr);
> + p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
> + MAP_SHARED, fd, 0);
> + if (p == (void *)straddle_addr) {
> + /* These tests irrelevant if we didn't get the straddle address*/
> + if (test_addr_huge(p) != 1) {
> + tst_brk(TFAIL, "1st Mapped address is not hugepage");
> + goto windup;
> + }
> + if (test_addr_huge(p + hpage_size) != 1) {
> + tst_brk(TFAIL, "2nd Mapped address is not hugepage");
> + goto windup;
> + }
> + memset(p, 0, hpage_size);
> + memset(p + hpage_size, 0, hpage_size);
> + tst_res(TPASS, "Mapping without MAP_FIXED at %lx... completed", straddle_addr);
> + } else {
> + tst_res(TINFO, "Got %p instead, never mind, let's move to mapping with MAP_FIXED\n", p);
> + munmap(p, 2*hpage_size);
> + }
> + tst_res(TINFO, "Mapping with MAP_FIXED at %lx...", straddle_addr);
> Maybe use .tcnt = 2, in struct tst_test and separate these 2 cases into it's
> wonf functions?
>
> You would either use:
> static void run_test(unsigned int n)
>
> With that you would reduce code duplicity and make test function smaller.
>
> Also, sometimes we use test struct (pointer to the function and description, see
> e.g. testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c).
>
> ...

Can you suggest how we can handle the test exit upon failure inside one
of test cases then?

Currently I am handling it by using label windup placed at the end of
function.
In one of the other tests there was feedback to not use exit(0); then
how can we exit
easily upon failure from one of the testcase?

Thanks & Regards,
Geetika