On 25/05/2025 09.07, Alexandr Moshkov wrote:
Add new tests to check the correctness of the `-overcommit memlock`
option (possible values: off, on, on-fault) by using
`/proc/{qemu_pid}/status` file to check in VmSize, VmRSS and VmLck
values:

* if `memlock=off`, then VmLck = 0;
* if `memlock=on`, then VmLck > 0 and almost all memory is resident;
* if `memlock=on-fault`, then VmLck > 0 and only few memory is resident.

Signed-off-by: Alexandr Moshkov <dtalexund...@yandex-team.ru>
---
  tests/functional/meson.build     |  1 +
  tests/functional/test_memlock.py | 79 ++++++++++++++++++++++++++++++++
  2 files changed, 80 insertions(+)
  create mode 100755 tests/functional/test_memlock.py

diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index 52b4706cfe..13079f58b6 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -68,6 +68,7 @@ tests_generic_system = [
    'empty_cpu_model',
    'info_usernet',
    'version',
+  'memlock',
  ]
tests_generic_linuxuser = [
diff --git a/tests/functional/test_memlock.py b/tests/functional/test_memlock.py
new file mode 100755
index 0000000000..83cb5394cd
--- /dev/null
+++ b/tests/functional/test_memlock.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python3
+#
+# Functional test that check overcommit memlock options
+#
+# Copyright (c) Yandex Technologies LLC, 2025
+#
+# Author:
+#  Alexandr Moshkov <dtalexund...@yandex-team.ru>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import re
+
+from typing import Dict
+
+from qemu_test import QemuSystemTest
+from qemu_test import skipLockedMemoryTest
+
+
+STATUS_VALUE_PATTERN = re.compile(r'^(\w+):\s+(\d+) kB', re.MULTILINE)
+
+
+@skipLockedMemoryTest(2_097_152)  # 2GB
+class MemlockTest(QemuSystemTest):
+    """
+    Boots a Linux system with memlock options.

Nit: I'd maybe change this into "Runs a guest with..." since it does not really boot a Linux here. I could change it while picking up the patch if you like.

Apart from that: Works for me now, and the patch looks much simpler, thanks!

Reviewed-by: Thomas Huth <th...@redhat.com>
Tested-by: Thomas Huth <th...@redhat.com>


Reply via email to