qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	Alexandr Moshkov <dtalexundeer@yandex-team.ru>,
	Michael Tokarev <mjt@tls.msk.ru>,
	Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Subject: Re: [PULL 06/10] tests/functional: add memlock tests
Date: Fri, 24 Oct 2025 09:45:56 +0200	[thread overview]
Message-ID: <986e788c-6a94-4c27-9a6e-a761e3f763c0@linaro.org> (raw)
In-Reply-To: <20250611125846.125918-7-thuth@redhat.com>

Hi Alexandr,

On 11/6/25 14:58, Thomas Huth wrote:
> From: Alexandr Moshkov <dtalexundeer@yandex-team.ru>
> 
> 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 <dtalexundeer@yandex-team.ru>
> Message-ID: <20250605065908.299979-3-dtalexundeer@yandex-team.ru>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   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 557d59ddf4d..c3fca446cff 100644
> --- a/tests/functional/meson.build
> +++ b/tests/functional/meson.build
> @@ -312,6 +312,7 @@ tests_x86_64_system_quick = [
>     'virtio_version',
>     'x86_cpu_model_versions',
>     'vnc',
> +  'memlock',
>   ]
>   
>   tests_x86_64_system_thorough = [
> diff --git a/tests/functional/test_memlock.py b/tests/functional/test_memlock.py
> new file mode 100755
> index 00000000000..2b515ff979f
> --- /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 <dtalexundeer@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):
> +    """
> +    Runs a guest with memlock options.
> +    Then verify, that this options is working correctly
> +    by checking the status file of the QEMU process.
> +    """
> +
> +    def common_vm_setup_with_memlock(self, memlock):
> +        self.vm.add_args('-overcommit', f'mem-lock={memlock}')

This test fails on Darwin:

qemu-system-x86_64: mlockall: Function not implemented
qemu-system-x86_64: locking memory failed

Please consider using the @skipIfOperatingSystem("Darwin") decorator,
...

> +        self.vm.launch()
> +
> +    def test_memlock_off(self):
> +        self.common_vm_setup_with_memlock('off')
> +
> +        status = self.get_process_status_values(self.vm.get_pid())
> +
> +        self.assertTrue(status['VmLck'] == 0)
> +
> +    def test_memlock_on(self):
> +        self.common_vm_setup_with_memlock('on')
> +
> +        status = self.get_process_status_values(self.vm.get_pid())
> +
> +        # VmLck > 0 kB and almost all memory is resident
> +        self.assertTrue(status['VmLck'] > 0)
> +        self.assertTrue(status['VmRSS'] >= status['VmSize'] * 0.70)
> +
> +    def test_memlock_onfault(self):
> +        self.common_vm_setup_with_memlock('on-fault')
> +
> +        status = self.get_process_status_values(self.vm.get_pid())
> +
> +        # VmLck > 0 kB and only few memory is resident
> +        self.assertTrue(status['VmLck'] > 0)
> +        self.assertTrue(status['VmRSS'] <= status['VmSize'] * 0.30)
> +
> +    def get_process_status_values(self, pid: int) -> Dict[str, int]:
> +        result = {}
> +        raw_status = self._get_raw_process_status(pid)
> +
> +        for line in raw_status.split('\n'):
> +            if m := STATUS_VALUE_PATTERN.match(line):
> +                result[m.group(1)] = int(m.group(2))
> +
> +        return result
> +
> +    def _get_raw_process_status(self, pid: int) -> str:
> +        try:
> +            with open(f'/proc/{pid}/status', 'r') as f:

... or even better implement skipUntilOperatingSystem() and use
it instead, since this test is clearly Linux-focused.

> +                return f.read()
> +        except FileNotFoundError:
> +            self.skipTest("Can't open status file of the process")
> +
> +
> +if __name__ == '__main__':
> +    MemlockTest.main()
Regards,

Phil.



  reply	other threads:[~2025-10-24  7:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11 12:58 [PULL 00/10] Misc patches (functional tests, travis.yml, MAINTAINERS, ...) Thomas Huth
2025-06-11 12:58 ` [PULL 01/10] travis.yml: Remove the aarch64 job Thomas Huth
2025-06-11 12:58 ` [PULL 02/10] hw/s390x/s390-virtio-ccw: Remove the deprecated 4.1 machine type Thomas Huth
2025-06-11 12:58 ` [PULL 03/10] tests/functional: Use the 'none' machine for the VNC test Thomas Huth
2025-06-11 12:58 ` [PULL 04/10] tests/functional: Speed up the avr_mega2560 test Thomas Huth
2025-06-11 12:58 ` [PULL 05/10] tests/functional: add skipLockedMemoryTest decorator Thomas Huth
2025-06-11 12:58 ` [PULL 06/10] tests/functional: add memlock tests Thomas Huth
2025-10-24  7:45   ` Philippe Mathieu-Daudé [this message]
2025-10-24  7:51     ` Philippe Mathieu-Daudé
2025-06-11 12:58 ` [PULL 07/10] tests/vm/README: fix documentation path in tests/vm/README Thomas Huth
2025-06-11 12:58 ` [PULL 08/10] MAINTAINERS: Update the paths to the testing documentation files Thomas Huth
2025-06-11 12:58 ` [PULL 09/10] MAINTAINERS: Update Akihiko Odaki's affiliation Thomas Huth
2025-06-11 12:58 ` [PULL 10/10] scripts/meson-buildoptions: Sort coroutine_backend choices lexicographically Thomas Huth
2025-06-11 18:22 ` [PULL 00/10] Misc patches (functional tests, travis.yml, MAINTAINERS, ...) Stefan Hajnoczi

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=986e788c-6a94-4c27-9a6e-a761e3f763c0@linaro.org \
    --to=philmd@linaro.org \
    --cc=dtalexundeer@yandex-team.ru \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=mjt@tls.msk.ru \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).