aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tests/qemu/init.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-02-12 10:56:06 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-02-12 10:56:06 +0100
commit91a4aaa5ccca11fcb7a678436ddeff90f9d1b80a (patch)
treed20a7ef466978df41a236203f937586d4afb237a /src/tests/qemu/init.c
parentnetns: replace n0 ip with ip0, per custom (diff)
downloadwireguard-monolithic-historical-91a4aaa5ccca11fcb7a678436ddeff90f9d1b80a.tar.xz
wireguard-monolithic-historical-91a4aaa5ccca11fcb7a678436ddeff90f9d1b80a.zip
qemu: more granular memleak detection
Diffstat (limited to 'src/tests/qemu/init.c')
-rw-r--r--src/tests/qemu/init.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c
index de0b0eb..8d783e9 100644
--- a/src/tests/qemu/init.c
+++ b/src/tests/qemu/init.c
@@ -98,6 +98,8 @@ static void mount_filesystems(void)
panic("tmpfs mount");
if (mount("none", "/run", "tmpfs", 0, NULL))
panic("tmpfs mount");
+ if (mount("none", "/sys/kernel/debug", "debugfs", 0, NULL))
+ ; /* Not a problem if it fails.*/
if (symlink("/run", "/var/run"))
panic("run symlink");
if (symlink("/proc/self/fd", "/dev/fd"))
@@ -217,12 +219,22 @@ static void ensure_console(void)
panic("Unable to open console device");
}
-static void check_leaks(void)
+static void clear_leaks(void)
{
int fd;
- if (mount("none", "/sys/kernel/debug", "debugfs", 0, NULL) < 0)
+ fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
+ if (fd < 0)
return;
+ pretty_message("[+] Starting memory leak detection...");
+ write(fd, "clear\n", 5);
+ close(fd);
+}
+
+static void check_leaks(void)
+{
+ int fd;
+
fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
if (fd < 0)
return;
@@ -247,6 +259,7 @@ int main(int argc, char *argv[])
mount_filesystems();
kmod_selftests();
enable_logging();
+ clear_leaks();
launch_tests();
check_leaks();
poweroff();