public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] munlockall: add test case that verifies memory has been unlocked
@ 2024-03-05 17:26 Dennis Brendel
  2024-03-05 21:30 ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Dennis Brendel @ 2024-03-05 17:26 UTC (permalink / raw)
  To: ltp

Changes to v1:

- use a docparse comment
- use tabs for indentation
- report broken test and exit if any preparation/confirmation fails
  by using tst_brk(TBROK, ...)
- fix further violations reported by `make check`

I did not yet replace munlockall01.c because I am not familiar with
that (legacy?) syntax and why uclinux needs special handling.

---
 .../kernel/syscalls/munlockall/munlockall02.c | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 testcases/kernel/syscalls/munlockall/munlockall02.c

diff --git a/testcases/kernel/syscalls/munlockall/munlockall02.c b/testcases/kernel/syscalls/munlockall/munlockall02.c
new file mode 100644
index 000000000..06f781d86
--- /dev/null
+++ b/testcases/kernel/syscalls/munlockall/munlockall02.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright Red Hat
+ * Author: Dennis Brendel <dbrendel@redhat.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that munlockall(2) unlocks all previously locked memory
+ */
+
+#include <sys/mman.h>
+
+#include "tst_test.h"
+
+static void verify_munlockall(void)
+{
+	size_t size = 0;
+
+	SAFE_FILE_LINES_SCANF("/proc/self/status", "VmLck: %ld", &size);
+
+	if (size != 0UL)
+		tst_brk(TBROK, "Locked memory after init should be 0 but is "
+			       "%ld", size);
+
+	if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0)
+		tst_brk(TBROK, "Could not lock memory using mlockall()");
+
+	SAFE_FILE_LINES_SCANF("/proc/self/status", "VmLck: %ld", &size);
+
+	if (size == 0UL)
+		tst_brk(TBROK, "Locked memory after mlockall() should be "
+			       "greater than 0, but is %ld", size);
+
+	if (munlockall() != 0)
+		tst_brk(TBROK, "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");
+	}
+}
+
+static struct tst_test test = {
+	.test_all = verify_munlockall,
+};
-- 
2.44.0



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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-06 10:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-05 17:26 [LTP] [PATCH v2] munlockall: add test case that verifies memory has been unlocked Dennis Brendel
2024-03-05 21:30 ` Petr Vorel
2024-03-06  8:49   ` Dennis Brendel
2024-03-06  9:00   ` Dennis Brendel
2024-03-06 10:07     ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox