diff mbox series

mlock05: add log details about the success/failure

Message ID 20240724130553.126252-1-fstornio@redhat.com
State New
Headers show
Series mlock05: add log details about the success/failure | expand

Commit Message

Filippo Storniolo July 24, 2024, 1:05 p.m. UTC
In some testing environments, such as those related to safety
critical requirements, more detailed logs are needed when
the executed test passes or fails.
This format already exists in other LTP tests, such as
kernel/security/kallsyms/kallsyms.c

Signed-off-by: Filippo Storniolo <fstornio@redhat.com>
---
 testcases/kernel/syscalls/mlock/mlock05.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Cyril Hrubis July 24, 2024, 3:14 p.m. UTC | #1
Hi!
> In some testing environments, such as those related to safety
> critical requirements, more detailed logs are needed when
> the executed test passes or fails.
> This format already exists in other LTP tests, such as
> kernel/security/kallsyms/kallsyms.c

What exactly are the requirements? It would make more sense to improve
the TST_EXP_EQ_LU() macro to print the additional information instead...
Filippo Storniolo July 29, 2024, 3:43 p.m. UTC | #2
Hi!

Our test logs will be reviewed by people not familiar with the test purpose
or its implementation. These will be people who may not have the background
or time necessary to read and understand the source code.

However, improving the TST_EXP_EQ_LU() macro to print additional
information looks great and I believe it would be the better approach, as
it would also be useful for future contributions.
Do you already have something in mind for a possible implementation?
I was thinking of creating a new one that looks like this:
TST_EXP_EQ_LU_MSG() so that the test writer can add a custom message where
the test passes/fails.

Filippo Storniolo

On Wed, Jul 24, 2024 at 5:14 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Hi!
> > In some testing environments, such as those related to safety
> > critical requirements, more detailed logs are needed when
> > the executed test passes or fails.
> > This format already exists in other LTP tests, such as
> > kernel/security/kallsyms/kallsyms.c
>
> What exactly are the requirements? It would make more sense to improve
> the TST_EXP_EQ_LU() macro to print the additional information instead...
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
>
Cyril Hrubis July 30, 2024, 7:36 a.m. UTC | #3
Hi!
> Our test logs will be reviewed by people not familiar with the test purpose
> or its implementation. These will be people who may not have the background
> or time necessary to read and understand the source code.

You may be interested in the metadata extracted during the test build as
well. LTP produces a big a big html page with descriptions extracted
from the tests in docparse/metadata.html for mlock05 you get:

...

Description

Verify mlock() causes pre-faulting of PTEs and prevent memory to be swapped out.

Find the new mapping in /proc/$pid/smaps and check Rss and Locked fields
after mlock syscall: Rss and Locked size should be equal to the size of
the memory allocation

...

> However, improving the TST_EXP_EQ_LU() macro to print additional
> information looks great and I believe it would be the better approach, as
> it would also be useful for future contributions.
> Do you already have something in mind for a possible implementation?
> I was thinking of creating a new one that looks like this:
> TST_EXP_EQ_LU_MSG() so that the test writer can add a custom message where
> the test passes/fails.

Most of the TST_EXP_*() macros have optional printf-like format string
and parameters, it should be easy to add that functionality the
TST_EXP_EQ_*() macros as well.
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/mlock/mlock05.c b/testcases/kernel/syscalls/mlock/mlock05.c
index 8e805736d..8b217beb5 100644
--- a/testcases/kernel/syscalls/mlock/mlock05.c
+++ b/testcases/kernel/syscalls/mlock/mlock05.c
@@ -102,8 +102,15 @@  static void verify_mlock(void)
 	Rss *= 1024;
 	Locked *= 1024;
 
-	TST_EXP_EQ_LU(Rss, MMAPLEN);
-	TST_EXP_EQ_LU(Locked, MMAPLEN);
+	if (Rss == MMAPLEN)
+		tst_res(TPASS, "Pre-faulted %lu bytes and expected %lu", Rss, MMAPLEN);
+	else
+		tst_res(TFAIL, "Pre-faulted %lu bytes but expected %lu", Rss, MMAPLEN);
+
+	if (Locked == MMAPLEN)
+		tst_res(TPASS, "Locked %lu bytes and expected %lu", Locked, MMAPLEN);
+	else
+		tst_res(TFAIL, "Locked %lu bytes but expected %lu", Locked, MMAPLEN);
 
 	SAFE_MUNLOCK(buf, MMAPLEN);
 	SAFE_MUNMAP(buf, MMAPLEN);