public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] Adding new function read_maps required for hugemmap40.
@ 2025-11-27  7:22 Pavithra
  2025-11-27  7:22 ` [LTP] [PATCH 2/3] Adding magic definition " Pavithra
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Pavithra @ 2025-11-27  7:22 UTC (permalink / raw)
  To: ltp; +Cc: pavrampu

Function to read and parse the '/proc/self/maps' file to debug memory-related issues.

Signed-off-by: Pavithra <pavrampu@linux.ibm.com>
---
 testcases/kernel/mem/hugetlb/lib/hugetlb.c | 42 ++++++++++++++++++++++
 testcases/kernel/mem/hugetlb/lib/hugetlb.h |  1 +
 2 files changed, 43 insertions(+)

diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.c b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
index 6a2976a53..fdd745eda 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.c
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
@@ -141,3 +141,45 @@ void update_shm_size(size_t * shm_size)
 		*shm_size = shmmax;
 	}
 }
+
+#define MAPS_BUF_SZ 4096
+int read_maps(unsigned long addr, char *buf)
+{
+        FILE *f;
+        char line[MAPS_BUF_SZ];
+        char *tmp;
+
+        f = fopen("/proc/self/maps", "r");
+        if (!f) {
+                tst_res(TFAIL, "Failed to open /proc/self/maps: %s\n", strerror(errno));
+                return -1;
+        }
+
+        while (1) {
+                unsigned long start, end, off, ino;
+                int ret;
+
+                tmp = fgets(line, MAPS_BUF_SZ, f);
+                if (!tmp)
+                        break;
+
+                buf[0] = '\0';
+                ret = sscanf(line, "%lx-%lx %*s %lx %*s %ld %255s",
+                             &start, &end, &off, &ino,
+                             buf);
+                if ((ret < 4) || (ret > 5)) {
+                        tst_res(TFAIL, "Couldn't parse /proc/self/maps line: %s\n",
+                                        line);
+                        fclose(f);
+                        return -1;
+                }
+
+                if ((start <= addr) && (addr < end)) {
+                        fclose(f);
+                        return 1;
+                }
+        }
+
+        fclose(f);
+        return 0;
+}
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
index 22975c99a..a59382ab9 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.h
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
@@ -57,6 +57,7 @@ int getipckey(void);
 int getuserid(char *user);
 void rm_shm(int shm_id);
 int do_readback(void *p, size_t size, char *desc);
+int read_maps(unsigned long addr, char *buf);
 
 void update_shm_size(size_t *shm_size);
 
-- 
2.43.5


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

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

end of thread, other threads:[~2025-11-27 11:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-27  7:22 [LTP] [PATCH 1/3] Adding new function read_maps required for hugemmap40 Pavithra
2025-11-27  7:22 ` [LTP] [PATCH 2/3] Adding magic definition " Pavithra
2025-11-27  8:19   ` Petr Vorel
2025-11-27  7:22 ` [LTP] [PATCH 3/3] [PATCH] [PATCH] Migrating the libhugetlbfs/testcases/straddle_4GB.c v3 Pavithra
2025-11-27 11:33   ` Petr Vorel
2025-11-27 10:31 ` [LTP] [PATCH 1/3] Adding new function read_maps required for hugemmap40 Petr Vorel

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