public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH proxmox 01/26] sys: procfs: don't read from sysfs during unit tests
Date: Thu, 12 Mar 2026 14:52:02 +0100	[thread overview]
Message-ID: <20260312135229.420729-2-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260312135229.420729-1-l.wagner@proxmox.com>

When running tests in sbuild, /sys/kernel/mm/ksm/pages_sharing cannot be
read; the test fails with a 'permission denied' error. To solve this, we
move reading the file to the caller, allowing us to provide a static
string an input during the test.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-sys/src/linux/procfs/mod.rs | 30 +++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/proxmox-sys/src/linux/procfs/mod.rs b/proxmox-sys/src/linux/procfs/mod.rs
index 202b6a45..d399cdc3 100644
--- a/proxmox-sys/src/linux/procfs/mod.rs
+++ b/proxmox-sys/src/linux/procfs/mod.rs
@@ -434,10 +434,16 @@ pub fn read_meminfo() -> Result<ProcFsMemInfo, Error> {
     let path = "/proc/meminfo";
 
     let meminfo_str = std::fs::read_to_string(path)?;
-    parse_proc_meminfo(&meminfo_str)
+
+    let pages_sharing = match read_firstline("/sys/kernel/mm/ksm/pages_sharing") {
+        Ok(p) => Some(p),
+        Err(err) if err.kind() == std::io::ErrorKind::NotFound => None,
+        Err(err) => bail!("unable to get KSM pages_sharing - {err}"),
+    };
+    parse_proc_meminfo(&meminfo_str, pages_sharing.as_deref())
 }
 
-fn parse_proc_meminfo(text: &str) -> Result<ProcFsMemInfo, Error> {
+fn parse_proc_meminfo(text: &str, pages_sharing: Option<&str>) -> Result<ProcFsMemInfo, Error> {
     let mut meminfo = ProcFsMemInfo {
         memtotal: 0,
         memfree: 0,
@@ -471,10 +477,9 @@ fn parse_proc_meminfo(text: &str) -> Result<ProcFsMemInfo, Error> {
 
     meminfo.swapused = meminfo.swaptotal - meminfo.swapfree;
 
-    meminfo.memshared = match read_firstline("/sys/kernel/mm/ksm/pages_sharing") {
-        Ok(spages_line) => spages_line.trim_end().parse::<u64>()? * 4096,
-        Err(err) if err.kind() == std::io::ErrorKind::NotFound => 0,
-        Err(err) => bail!("unable to get KSM pages_sharing - {err}"),
+    meminfo.memshared = match pages_sharing {
+        Some(pages_sharing) => pages_sharing.trim_end().parse::<u64>()? * 4096,
+        None => 0,
     };
 
     Ok(meminfo)
@@ -482,8 +487,7 @@ fn parse_proc_meminfo(text: &str) -> Result<ProcFsMemInfo, Error> {
 
 #[test]
 fn test_read_proc_meminfo() {
-    let meminfo = parse_proc_meminfo(
-        "MemTotal:       32752584 kB
+    let proc_meminfo = "MemTotal:       32752584 kB
 MemFree:         2106048 kB
 MemAvailable:   13301592 kB
 Buffers:               0 kB
@@ -538,9 +542,14 @@ Hugetlb:               0 kB
 DirectMap4k:      237284 kB
 DirectMap2M:    13281280 kB
 DirectMap1G:    22020096 kB
+";
+
+    let pages_sharing = Some(
+        "2
 ",
-    )
-    .expect("successful parsed a sample /proc/meminfo entry");
+    );
+    let meminfo = parse_proc_meminfo(proc_meminfo, pages_sharing)
+        .expect("successful parsed a sample /proc/meminfo entry");
 
     assert_eq!(meminfo.memtotal, 33538646016);
     assert_eq!(meminfo.memused, 19917815808);
@@ -549,6 +558,7 @@ DirectMap1G:    22020096 kB
     assert_eq!(meminfo.swapfree, 2048);
     assert_eq!(meminfo.swaptotal, 3072);
     assert_eq!(meminfo.swapused, 1024);
+    assert_eq!(meminfo.memshared, 8192);
 }
 
 #[derive(Clone, Debug)]
-- 
2.47.3





  reply	other threads:[~2026-03-12 13:53 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 13:52 [PATCH datacenter-manager/proxmox{,-backup,-yew-comp} 00/26] metric collection for the PDM host Lukas Wagner
2026-03-12 13:52 ` Lukas Wagner [this message]
2026-03-12 13:52 ` [PATCH proxmox 02/26] parallel-handler: import code from Proxmox Backup Server Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox 03/26] parallel-handler: introduce custom error type Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox 04/26] parallel-handler: add documentation Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox 05/26] parallel-handler: add simple unit-test suite Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox 06/26] disks: import from Proxmox Backup Server Lukas Wagner
2026-03-16 13:13   ` Arthur Bied-Charreton
2026-03-12 13:52 ` [PATCH proxmox 07/26] disks: fix typo in `initialize_gpt_disk` Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox 08/26] disks: add parts of gather_disk_stats from PBS Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox 09/26] disks: gate api macro behind 'api-types' feature Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox 10/26] disks: clippy: collapse if-let chains where possible Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox 11/26] procfs: add helpers for querying pressure stall information Lukas Wagner
2026-03-16 13:25   ` Arthur Bied-Charreton
2026-03-12 13:52 ` [PATCH proxmox 12/26] time: use u64 parse helper from nom Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox-backup 13/26] tools: move ParallelHandler to new proxmox-parallel-handler crate Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox-backup 14/26] tools: replace disks module with proxmox-disks Lukas Wagner
2026-03-16 13:27   ` Arthur Bied-Charreton
2026-03-12 13:52 ` [PATCH proxmox-backup 15/26] metric collection: use blockdev_stat_for_path from proxmox_disks Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox-yew-comp 16/26] node status panel: add `children` property Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox-yew-comp 17/26] RRDGrid: fix size observer by attaching node reference to rendered container Lukas Wagner
2026-03-12 13:52 ` [PATCH proxmox-yew-comp 18/26] RRDGrid: add padding and increase gap between elements Lukas Wagner
2026-03-12 13:52 ` [PATCH datacenter-manager 19/26] metric collection: clarify naming for remote metric collection Lukas Wagner
2026-03-12 13:52 ` [PATCH datacenter-manager 20/26] metric collection: fix minor typo in error message Lukas Wagner
2026-03-12 13:52 ` [PATCH datacenter-manager 21/26] metric collection: collect PDM host metrics in a new collection task Lukas Wagner
2026-03-12 13:52 ` [PATCH datacenter-manager 22/26] api: fix /nodes/localhost/rrddata endpoint Lukas Wagner
2026-03-12 13:52 ` [PATCH datacenter-manager 23/26] pdm: node rrd data: rename 'total-time' to 'metric-collection-total-time' Lukas Wagner
2026-03-12 13:52 ` [PATCH datacenter-manager 24/26] pdm-api-types: add PDM host metric fields Lukas Wagner
2026-03-12 13:52 ` [PATCH datacenter-manager 25/26] ui: node status: add RRD graphs for PDM host metrics Lukas Wagner
2026-03-12 13:52 ` [PATCH datacenter-manager 26/26] ui: lxc/qemu/node: use RRD value render helpers Lukas Wagner
2026-03-16 13:42 ` [PATCH datacenter-manager/proxmox{,-backup,-yew-comp} 00/26] metric collection for the PDM host Arthur Bied-Charreton

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=20260312135229.420729-2-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pdm-devel@lists.proxmox.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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal