summaryrefslogtreecommitdiffhomepage
path: root/src/tests/qemu
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
parent4f3b7e386cd32cdacdc287aaebd70677040eb316 (diff)
qemu: check for memory leaks
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/tests/qemu')
-rw-r--r--src/tests/qemu/Makefile2
-rw-r--r--src/tests/qemu/debug.config8
-rw-r--r--src/tests/qemu/init.c24
3 files changed, 28 insertions, 6 deletions
diff --git a/src/tests/qemu/Makefile b/src/tests/qemu/Makefile
index 4261b89..0469b3a 100644
--- a/src/tests/qemu/Makefile
+++ b/src/tests/qemu/Makefile
@@ -169,7 +169,7 @@ qemu: $(KERNEL_BZIMAGE)
-nographic \
-smp $(NR_CPUS) \
$(QEMU_MACHINE) \
- -m 192M \
+ -m $$(grep -q CONFIG_DEBUG_KMEMLEAK=y $(KERNEL_PATH)/.config && echo 1G || echo 192M) \
-serial stdio \
-serial file:$(BUILD_PATH)/result \
-no-reboot \
diff --git a/src/tests/qemu/debug.config b/src/tests/qemu/debug.config
index 1dc8a27..ac20063 100644
--- a/src/tests/qemu/debug.config
+++ b/src/tests/qemu/debug.config
@@ -26,10 +26,9 @@ CONFIG_KASAN_INLINE=y
CONFIG_UBSAN=y
CONFIG_UBSAN_SANITIZE_ALL=y
CONFIG_UBSAN_NULL=y
-CONFIG_KMEMCHECK=y
-CONFIG_KMEMCHECK_PARTIAL_OK=y
-CONFIG_KMEMCHECK_BITOPS_OK=y
-CONFIG_ARCH_HAS_KCOV=y
+CONFIG_DEBUG_KMEMLEAK=y
+CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=8192
+CONFIG_DEBUG_STACK_USAGE=y
CONFIG_KCOV=y
CONFIG_DEBUG_SHIRQ=y
CONFIG_WQ_WATCHDOG=y
@@ -56,5 +55,4 @@ CONFIG_SPARSE_RCU_POINTER=y
CONFIG_RCU_CPU_STALL_TIMEOUT=21
CONFIG_RCU_TRACE=y
CONFIG_RCU_EQS_DEBUG=y
-CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS=y
CONFIG_USER_STACKTRACE_SUPPORT=y
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;
}