All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Dennis Brendel <dbrendel@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] munlockall: add test case that verifies memory has been unlocked
Date: Tue, 5 Mar 2024 14:30:22 +0100	[thread overview]
Message-ID: <ZecebvbXRWiWyWl_@yuki> (raw)
In-Reply-To: <c63c49c3-30e8-494d-9ceb-64fc55060e1f@redhat.com>

Hi!
Generally this is much better test than the munlockall01.c so it would
make more sense to replace munlockall01.c instead of adding a new test.

> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/* 
> + * Copyright Red Hat
> + * Author: Dennis Brendel <dbrendel@redhat.com>
> + */
> +
> +/*

This should be docparse comment, i.e. start with /*\ so that it's picked
up with the documentation parser.

> + * [Description]
> + *
> + * Verify that munlockall(2) unlocks all previously locked memory
> + */
> +
> +#include <sys/mman.h>
> +
> +#include "tst_test.h"
> +
> +static void verify_munlockall(void)
> +{
> +    unsigned long int size = 0;
> +
> +    SAFE_FILE_LINES_SCANF("/proc/self/status", "VmLck: %ld", &size);
> +
> +    if (size != 0UL) {
> +        tst_res(TFAIL, "Locked memory after init should be 0 "
> +                       "but is %ld", size);
> +    }
> +
> +    if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
> +        tst_res(TFAIL, "Could not lock memory using mlockall()");
> +    }
> +
> +    SAFE_FILE_LINES_SCANF("/proc/self/status", "VmLck: %ld", &size);
> +
> +    if (size == 0UL) {
> +        tst_res(TFAIL, "Locked memory after mlockall() should be greater "
> +                       "than 0, but is %ld", size);
> +    }
> +
> +    if (munlockall() != 0) {
> +        tst_res(TFAIL, "Could not unlock memory using munlockall()");
> +    }
> +
> +    SAFE_FILE_LINES_SCANF("/proc/self/status", "VmLck: %ld", &size);
> +
> +    if (size != 0UL) {
> +        tst_res(TFAIL, "Locked memory after munlockall() should be 0 "
> +                       "but is %ld", size);
> +    } else {
> +        tst_res(TPASS, "Test passed");
> +    }

This obviously does not work, you have to either return from the
function after each tst_res(TFAIL, ""); or set a flag and print TPASS
only if the flag wasn't set.

> +}
> +
> +static struct tst_test test = {
> +    .test_all = verify_munlockall,
> +};

Also have you checked the test with 'make check' before sending the
patch?

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2024-03-05 13:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05 12:32 [LTP] [PATCH v1] munlockall: add test case that verifies memory has been unlocked Dennis Brendel
2024-03-05 13:30 ` Cyril Hrubis [this message]

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=ZecebvbXRWiWyWl_@yuki \
    --to=chrubis@suse.cz \
    --cc=dbrendel@redhat.com \
    --cc=ltp@lists.linux.it \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.