summaryrefslogtreecommitdiffhomepage
path: root/src/tests/qemu/init.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-03 19:22:13 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-11-10 15:49:28 +0900
commit27e7d2fe25ed1bcfa72b3fc9d9728bcff34ca14d (patch)
tree1f45241b89884ba85a7a2816b755d728cb1229ff /src/tests/qemu/init.c
parent4f3b7e386cd32cdacdc287aaebd70677040eb316 (diff)
qemu: check for memory leaks
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/tests/qemu/init.c')
-rw-r--r--src/tests/qemu/init.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c
index afbc611..8f46e6c 100644
--- a/src/tests/qemu/init.c
+++ b/src/tests/qemu/init.c
@@ -17,6 +17,7 @@
#include <sys/ioctl.h>
#include <sys/reboot.h>
#include <sys/utsname.h>
+#include <sys/sendfile.h>
#include <linux/random.h>
#include <linux/version.h>
@@ -207,6 +208,28 @@ static void ensure_console(void)
panic("Unable to open console device");
}
+static void check_leaks(void)
+{
+ int fd;
+
+ if (mount("none", "/sys/kernel/debug", "debugfs", 0, NULL) < 0)
+ return;
+ fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
+ if (fd < 0)
+ return;
+ pretty_message("[+] Scanning for memory leaks...");
+ sleep(2); /* Wait for any grace periods. */
+ write(fd, "scan\n", 5);
+ close(fd);
+
+ fd = open("/sys/kernel/debug/kmemleak", O_RDONLY);
+ if (fd < 0)
+ return;
+ if (sendfile(1, fd, NULL, 0x7ffff000) > 0)
+ panic("Memory leaks encountered");
+ close(fd);
+}
+
int main(int argc, char *argv[])
{
seed_rng();
@@ -216,6 +239,7 @@ int main(int argc, char *argv[])
kmod_selftests();
enable_logging();
launch_tests();
+ check_leaks();
poweroff();
return 1;
}