summaryrefslogtreecommitdiffstats
path: root/test/util.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-01-26 04:24:19 +0100
committerLouis Burda <quent.burda@gmail.com>2023-01-26 04:24:19 +0100
commit5e21196a9c7ee8eee921d74f6b5eef2f1980ec97 (patch)
treebaea207295fe1ad257506a8de08c1b64f06fbd4e /test/util.c
parentcb7c6b3d6767335d13892451c141cfb717807712 (diff)
downloadcachepc-5e21196a9c7ee8eee921d74f6b5eef2f1980ec97.tar.gz
cachepc-5e21196a9c7ee8eee921d74f6b5eef2f1980ec97.zip
Basic qemu eviction test with signalled stepping and added rip syscall
Diffstat (limited to 'test/util.c')
-rw-r--r--test/util.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/test/util.c b/test/util.c
index 8b27578..11cba55 100644
--- a/test/util.c
+++ b/test/util.c
@@ -2,8 +2,10 @@
#include "test/util.h"
-#include <pthread.h>
+#include <sys/types.h>
#include <sys/mman.h>
+#include <dirent.h>
+#include <pthread.h>
#include <err.h>
#include <sched.h>
#include <string.h>
@@ -69,6 +71,41 @@ read_stat_core(pid_t pid)
return cpu;
}
+pid_t
+pgrep(const char *bin)
+{
+ char path[PATH_MAX];
+ char buf[PATH_MAX];
+ struct dirent *ent;
+ char *cmp;
+ FILE *f;
+ DIR *dir;
+ pid_t pid;
+
+ dir = opendir("/proc");
+ if (!dir) err(1, "opendir");
+
+ pid = 0;
+ while (!pid && (ent = readdir(dir))) {
+ snprintf(path, sizeof(path), "/proc/%s/cmdline", ent->d_name);
+ f = fopen(path, "rb");
+ if (!f) continue;
+ memset(buf, 0, sizeof(buf));
+ fread(buf, 1, sizeof(buf), f);
+ if ((cmp = strrchr(buf, '/')))
+ cmp += 1;
+ else
+ cmp = buf;
+ if (!strcmp(cmp, bin))
+ pid = atoi(ent->d_name);
+ fclose(f);
+ }
+
+ closedir(dir);
+
+ return pid;
+}
+
void
print_counts(uint8_t *counts)
{