1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 Date: Sun, 15 Dec 2019 22:08:00 +0100
4 Subject: [PATCH] wireguard: selftests: import harness makefile for test suite
6 commit 65d88d04114bca7d85faebd5fed61069cb2b632c upstream.
8 WireGuard has been using this on build.wireguard.com for the last
9 several years with considerable success. It allows for very quick and
10 iterative development cycles, and supports several platforms.
12 To run the test suite on your current platform in QEMU:
14 $ make -C tools/testing/selftests/wireguard/qemu -j$(nproc)
16 To run it with KASAN and such turned on:
18 $ DEBUG_KERNEL=yes make -C tools/testing/selftests/wireguard/qemu -j$(nproc)
20 To run it emulated for another platform in QEMU:
22 $ ARCH=arm make -C tools/testing/selftests/wireguard/qemu -j$(nproc)
24 At the moment, we support aarch64_be, aarch64, arm, armeb, i686, m68k,
25 mips64, mips64el, mips, mipsel, powerpc64le, powerpc, and x86_64.
27 The system supports incremental rebuilding, so it should be very fast to
28 change a single file and then test it out and have immediate feedback.
30 This requires for the right toolchain and qemu to be installed prior.
31 I've had success with those from musl.cc.
33 This is tailored for WireGuard at the moment, though later projects
34 might generalize it for other network testing.
36 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
37 Signed-off-by: David S. Miller <davem@davemloft.net>
38 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
40 .../selftests/wireguard/qemu/.gitignore | 2 +
41 .../testing/selftests/wireguard/qemu/Makefile | 385 ++++++++++++++++++
42 .../wireguard/qemu/arch/aarch64.config | 5 +
43 .../wireguard/qemu/arch/aarch64_be.config | 6 +
44 .../selftests/wireguard/qemu/arch/arm.config | 9 +
45 .../wireguard/qemu/arch/armeb.config | 10 +
46 .../selftests/wireguard/qemu/arch/i686.config | 5 +
47 .../selftests/wireguard/qemu/arch/m68k.config | 9 +
48 .../selftests/wireguard/qemu/arch/mips.config | 11 +
49 .../wireguard/qemu/arch/mips64.config | 14 +
50 .../wireguard/qemu/arch/mips64el.config | 15 +
51 .../wireguard/qemu/arch/mipsel.config | 12 +
52 .../wireguard/qemu/arch/powerpc.config | 10 +
53 .../wireguard/qemu/arch/powerpc64le.config | 12 +
54 .../wireguard/qemu/arch/x86_64.config | 5 +
55 .../selftests/wireguard/qemu/debug.config | 67 +++
56 tools/testing/selftests/wireguard/qemu/init.c | 284 +++++++++++++
57 .../selftests/wireguard/qemu/kernel.config | 86 ++++
58 18 files changed, 947 insertions(+)
59 create mode 100644 tools/testing/selftests/wireguard/qemu/.gitignore
60 create mode 100644 tools/testing/selftests/wireguard/qemu/Makefile
61 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/aarch64.config
62 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/aarch64_be.config
63 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/arm.config
64 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/armeb.config
65 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/i686.config
66 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/m68k.config
67 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/mips.config
68 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/mips64.config
69 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/mips64el.config
70 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/mipsel.config
71 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/powerpc.config
72 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/powerpc64le.config
73 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/x86_64.config
74 create mode 100644 tools/testing/selftests/wireguard/qemu/debug.config
75 create mode 100644 tools/testing/selftests/wireguard/qemu/init.c
76 create mode 100644 tools/testing/selftests/wireguard/qemu/kernel.config
79 +++ b/tools/testing/selftests/wireguard/qemu/.gitignore
84 +++ b/tools/testing/selftests/wireguard/qemu/Makefile
86 +# SPDX-License-Identifier: GPL-2.0
88 +# Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
92 +CHOST := $(shell gcc -dumpmachine)
94 +CBUILD := $(subst -gcc,,$(lastword $(subst /, ,$(firstword $(wildcard $(foreach bindir,$(subst :, ,$(PATH)),$(bindir)/$(ARCH)-*-gcc))))))
96 +$(error The toolchain for $(ARCH) is not installed)
100 +ARCH := $(firstword $(subst -, ,$(CBUILD)))
103 +# Set these from the environment to override
104 +KERNEL_PATH ?= $(PWD)/../../../../..
105 +BUILD_PATH ?= $(PWD)/build/$(ARCH)
106 +DISTFILES_PATH ?= $(PWD)/distfiles
109 +MIRROR := https://download.wireguard.com/qemu-test/distfiles/
113 +# variable name, tarball project name, version, tarball extension, default URI base
114 +define tar_download =
115 +$(1)_VERSION := $(3)
116 +$(1)_NAME := $(2)-$$($(1)_VERSION)
117 +$(1)_TAR := $(DISTFILES_PATH)/$$($(1)_NAME)$(4)
118 +$(1)_PATH := $(BUILD_PATH)/$$($(1)_NAME)
119 +$(call file_download,$$($(1)_NAME)$(4),$(5),$(6))
122 +define file_download =
123 +$(DISTFILES_PATH)/$(1):
124 + mkdir -p $(DISTFILES_PATH)
125 + flock -x $$@.lock -c '[ -f $$@ ] && exit 0; wget -O $$@.tmp $(MIRROR)$(1) || wget -t inf --retry-on-http-error=404 -O $$@.tmp $(2)$(1) || rm -f $$@.tmp'
126 + if echo "$(3) $$@.tmp" | sha256sum -c -; then mv $$@.tmp $$@; else rm -f $$@.tmp; exit 71; fi
129 +$(eval $(call tar_download,MUSL,musl,1.1.20,.tar.gz,https://www.musl-libc.org/releases/,44be8771d0e6c6b5f82dd15662eb2957c9a3173a19a8b49966ac0542bbd40d61))
130 +$(eval $(call tar_download,LIBMNL,libmnl,1.0.4,.tar.bz2,https://www.netfilter.org/projects/libmnl/files/,171f89699f286a5854b72b91d06e8f8e3683064c5901fb09d954a9ab6f551f81))
131 +$(eval $(call tar_download,IPERF,iperf,3.1.7,.tar.gz,http://downloads.es.net/pub/iperf/,a4ef73406fe92250602b8da2ae89ec53211f805df97a1d1d629db5a14043734f))
132 +$(eval $(call tar_download,BASH,bash,5.0,.tar.gz,https://ftp.gnu.org/gnu/bash/,b4a80f2ac66170b2913efbfb9f2594f1f76c7b1afd11f799e22035d63077fb4d))
133 +$(eval $(call tar_download,IPROUTE2,iproute2,5.1.0,.tar.gz,https://www.kernel.org/pub/linux/utils/net/iproute2/,9b43707d6075ecdca14803ca8ce0c8553848c49fa1586d12fd508d66577243f2))
134 +$(eval $(call tar_download,IPTABLES,iptables,1.6.1,.tar.bz2,https://www.netfilter.org/projects/iptables/files/,0fc2d7bd5d7be11311726466789d4c65fb4c8e096c9182b56ce97440864f0cf5))
135 +$(eval $(call tar_download,NMAP,nmap,7.60,.tar.bz2,https://nmap.org/dist/,a8796ecc4fa6c38aad6139d9515dc8113023a82e9d787e5a5fb5fa1b05516f21))
136 +$(eval $(call tar_download,IPUTILS,iputils,s20161105,.tar.gz,https://github.com/iputils/iputils/archive/s20161105.tar.gz/#,f813092f03d17294fd23544b129b95cdb87fe19f7970a51908a6b88509acad8a))
137 +$(eval $(call tar_download,WIREGUARD_TOOLS,WireGuard,0.0.20191212,.tar.xz,https://git.zx2c4.com/WireGuard/snapshot/,b0d718380f7a8822b2f12d75e462fa4eafa3a77871002981f367cd4fe2a1b071))
139 +KERNEL_BUILD_PATH := $(BUILD_PATH)/kernel$(if $(findstring yes,$(DEBUG_KERNEL)),-debug)
140 +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
141 +WIREGUARD_SOURCES := $(call rwildcard,$(KERNEL_PATH)/drivers/net/wireguard/,*)
143 +export CFLAGS ?= -O3 -pipe
145 +export CPPFLAGS := -I$(BUILD_PATH)/include
147 +ifeq ($(CHOST),$(CBUILD))
148 +CROSS_COMPILE_FLAG := --host=$(CHOST)
149 +NOPIE_GCC := gcc -fno-PIE
150 +CFLAGS += -march=native
153 +$(info Cross compilation: building for $(CBUILD) using $(CHOST))
154 +CROSS_COMPILE_FLAG := --build=$(CBUILD) --host=$(CHOST)
155 +export CROSS_COMPILE=$(CBUILD)-
156 +NOPIE_GCC := $(CBUILD)-gcc -fno-PIE
157 +STRIP := $(CBUILD)-strip
159 +ifeq ($(ARCH),aarch64)
160 +QEMU_ARCH := aarch64
161 +KERNEL_ARCH := arm64
162 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm64/boot/Image
163 +ifeq ($(CHOST),$(CBUILD))
164 +QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
166 +QEMU_MACHINE := -cpu cortex-a53 -machine virt
167 +CFLAGS += -march=armv8-a -mtune=cortex-a53
169 +else ifeq ($(ARCH),aarch64_be)
170 +QEMU_ARCH := aarch64
171 +KERNEL_ARCH := arm64
172 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm64/boot/Image
173 +ifeq ($(CHOST),$(CBUILD))
174 +QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
176 +QEMU_MACHINE := -cpu cortex-a53 -machine virt
177 +CFLAGS += -march=armv8-a -mtune=cortex-a53
179 +else ifeq ($(ARCH),arm)
182 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm/boot/zImage
183 +ifeq ($(CHOST),$(CBUILD))
184 +QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
186 +QEMU_MACHINE := -cpu cortex-a15 -machine virt
187 +CFLAGS += -march=armv7-a -mtune=cortex-a15 -mabi=aapcs-linux
189 +else ifeq ($(ARCH),armeb)
192 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm/boot/zImage
193 +ifeq ($(CHOST),$(CBUILD))
194 +QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
196 +QEMU_MACHINE := -cpu cortex-a15 -machine virt
197 +CFLAGS += -march=armv7-a -mabi=aapcs-linux # We don't pass -mtune=cortex-a15 due to a compiler bug on big endian.
198 +LDFLAGS += -Wl,--be8
200 +else ifeq ($(ARCH),x86_64)
202 +KERNEL_ARCH := x86_64
203 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
204 +ifeq ($(CHOST),$(CBUILD))
205 +QEMU_MACHINE := -cpu host -machine q35,accel=kvm
207 +QEMU_MACHINE := -cpu Skylake-Server -machine q35
208 +CFLAGS += -march=skylake-avx512
210 +else ifeq ($(ARCH),i686)
213 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
214 +ifeq ($(subst i686,x86_64,$(CBUILD)),$(CHOST))
215 +QEMU_MACHINE := -cpu host -machine q35,accel=kvm
217 +QEMU_MACHINE := -cpu coreduo -machine q35
218 +CFLAGS += -march=prescott
220 +else ifeq ($(ARCH),mips64)
223 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
224 +ifeq ($(CHOST),$(CBUILD))
225 +QEMU_MACHINE := -cpu host -machine malta,accel=kvm
228 +QEMU_MACHINE := -cpu MIPS64R2-generic -machine malta -smp 1
229 +CFLAGS += -march=mips64r2 -EB
231 +else ifeq ($(ARCH),mips64el)
232 +QEMU_ARCH := mips64el
234 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
235 +ifeq ($(CHOST),$(CBUILD))
236 +QEMU_MACHINE := -cpu host -machine malta,accel=kvm
239 +QEMU_MACHINE := -cpu MIPS64R2-generic -machine malta -smp 1
240 +CFLAGS += -march=mips64r2 -EL
242 +else ifeq ($(ARCH),mips)
245 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
246 +ifeq ($(CHOST),$(CBUILD))
247 +QEMU_MACHINE := -cpu host -machine malta,accel=kvm
250 +QEMU_MACHINE := -cpu 24Kf -machine malta -smp 1
251 +CFLAGS += -march=mips32r2 -EB
253 +else ifeq ($(ARCH),mipsel)
256 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
257 +ifeq ($(CHOST),$(CBUILD))
258 +QEMU_MACHINE := -cpu host -machine malta,accel=kvm
261 +QEMU_MACHINE := -cpu 24Kf -machine malta -smp 1
262 +CFLAGS += -march=mips32r2 -EL
264 +else ifeq ($(ARCH),powerpc64le)
266 +KERNEL_ARCH := powerpc
267 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
268 +ifeq ($(CHOST),$(CBUILD))
269 +QEMU_MACHINE := -cpu host,accel=kvm -machine pseries
271 +QEMU_MACHINE := -machine pseries
273 +CFLAGS += -mcpu=powerpc64le -mlong-double-64
274 +else ifeq ($(ARCH),powerpc)
276 +KERNEL_ARCH := powerpc
277 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/powerpc/boot/uImage
278 +ifeq ($(CHOST),$(CBUILD))
279 +QEMU_MACHINE := -cpu host,accel=kvm -machine ppce500
281 +QEMU_MACHINE := -machine ppce500
283 +CFLAGS += -mcpu=powerpc -mlong-double-64 -msecure-plt
284 +else ifeq ($(ARCH),m68k)
287 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
288 +ifeq ($(CHOST),$(CBUILD))
289 +QEMU_MACHINE := -cpu host,accel=kvm -machine q800
291 +QEMU_MACHINE := -machine q800
294 +$(error I only build: x86_64, i686, arm, armeb, aarch64, aarch64_be, mips, mipsel, mips64, mips64el, powerpc64le, powerpc, m68k)
297 +REAL_CC := $(CBUILD)-gcc
298 +MUSL_CC := $(BUILD_PATH)/musl-gcc
299 +export CC := $(MUSL_CC)
300 +USERSPACE_DEPS := $(MUSL_CC) $(BUILD_PATH)/include/.installed $(BUILD_PATH)/include/linux/.installed
302 +build: $(KERNEL_BZIMAGE)
303 +qemu: $(KERNEL_BZIMAGE)
304 + rm -f $(BUILD_PATH)/result
305 + timeout --foreground 20m qemu-system-$(QEMU_ARCH) \
310 + -m $$(grep -q CONFIG_DEBUG_KMEMLEAK=y $(KERNEL_BUILD_PATH)/.config && echo 1G || echo 256M) \
312 + -serial file:$(BUILD_PATH)/result \
316 + grep -Fq success $(BUILD_PATH)/result
318 +$(BUILD_PATH)/init-cpio-spec.txt:
319 + mkdir -p $(BUILD_PATH)
320 + echo "file /init $(BUILD_PATH)/init 755 0 0" > $@
321 + echo "file /init.sh $(PWD)/../netns.sh 755 0 0" >> $@
322 + echo "dir /dev 755 0 0" >> $@
323 + echo "nod /dev/console 644 0 0 c 5 1" >> $@
324 + echo "dir /bin 755 0 0" >> $@
325 + echo "file /bin/iperf3 $(IPERF_PATH)/src/iperf3 755 0 0" >> $@
326 + echo "file /bin/wg $(WIREGUARD_TOOLS_PATH)/src/tools/wg 755 0 0" >> $@
327 + echo "file /bin/bash $(BASH_PATH)/bash 755 0 0" >> $@
328 + echo "file /bin/ip $(IPROUTE2_PATH)/ip/ip 755 0 0" >> $@
329 + echo "file /bin/ss $(IPROUTE2_PATH)/misc/ss 755 0 0" >> $@
330 + echo "file /bin/ping $(IPUTILS_PATH)/ping 755 0 0" >> $@
331 + echo "file /bin/ncat $(NMAP_PATH)/ncat/ncat 755 0 0" >> $@
332 + echo "file /bin/xtables-multi $(IPTABLES_PATH)/iptables/xtables-multi 755 0 0" >> $@
333 + echo "slink /bin/iptables xtables-multi 777 0 0" >> $@
334 + echo "slink /bin/ping6 ping 777 0 0" >> $@
335 + echo "dir /lib 755 0 0" >> $@
336 + echo "file /lib/libc.so $(MUSL_PATH)/lib/libc.so 755 0 0" >> $@
337 + echo "slink /lib/ld-linux.so.1 libc.so 777 0 0" >> $@
339 +$(KERNEL_BUILD_PATH)/.config: kernel.config arch/$(ARCH).config
340 + mkdir -p $(KERNEL_BUILD_PATH)
341 + cp kernel.config $(KERNEL_BUILD_PATH)/minimal.config
342 + printf 'CONFIG_NR_CPUS=$(NR_CPUS)\nCONFIG_INITRAMFS_SOURCE="$(BUILD_PATH)/init-cpio-spec.txt"\n' >> $(KERNEL_BUILD_PATH)/minimal.config
343 + cat arch/$(ARCH).config >> $(KERNEL_BUILD_PATH)/minimal.config
344 + $(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) allnoconfig
345 + cd $(KERNEL_BUILD_PATH) && ARCH=$(KERNEL_ARCH) $(KERNEL_PATH)/scripts/kconfig/merge_config.sh -n $(KERNEL_BUILD_PATH)/.config $(KERNEL_BUILD_PATH)/minimal.config
346 + $(if $(findstring yes,$(DEBUG_KERNEL)),cp debug.config $(KERNEL_BUILD_PATH) && cd $(KERNEL_BUILD_PATH) && ARCH=$(KERNEL_ARCH) $(KERNEL_PATH)/scripts/kconfig/merge_config.sh -n $(KERNEL_BUILD_PATH)/.config debug.config,)
348 +$(KERNEL_BZIMAGE): $(KERNEL_BUILD_PATH)/.config $(BUILD_PATH)/init-cpio-spec.txt $(MUSL_PATH)/lib/libc.so $(IPERF_PATH)/src/iperf3 $(IPUTILS_PATH)/ping $(BASH_PATH)/bash $(IPROUTE2_PATH)/misc/ss $(IPROUTE2_PATH)/ip/ip $(IPTABLES_PATH)/iptables/xtables-multi $(NMAP_PATH)/ncat/ncat $(WIREGUARD_TOOLS_PATH)/src/tools/wg $(BUILD_PATH)/init ../netns.sh $(WIREGUARD_SOURCES)
349 + $(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) CC="$(NOPIE_GCC)"
351 +$(BUILD_PATH)/include/linux/.installed: | $(KERNEL_BUILD_PATH)/.config
352 + $(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) INSTALL_HDR_PATH=$(BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) headers_install
355 +$(MUSL_PATH)/lib/libc.so: $(MUSL_TAR)
356 + mkdir -p $(BUILD_PATH)
357 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
358 + cd $(MUSL_PATH) && CC=$(REAL_CC) ./configure --prefix=/ --disable-static --build=$(CBUILD)
359 + $(MAKE) -C $(MUSL_PATH)
362 +$(BUILD_PATH)/include/.installed: $(MUSL_PATH)/lib/libc.so
363 + $(MAKE) -C $(MUSL_PATH) DESTDIR=$(BUILD_PATH) install-headers
366 +$(MUSL_CC): $(MUSL_PATH)/lib/libc.so
367 + sh $(MUSL_PATH)/tools/musl-gcc.specs.sh $(BUILD_PATH)/include $(MUSL_PATH)/lib /lib/ld-linux.so.1 > $(BUILD_PATH)/musl-gcc.specs
368 + printf '#!/bin/sh\nexec "$(REAL_CC)" --specs="$(BUILD_PATH)/musl-gcc.specs" -fno-stack-protector -no-pie "$$@"\n' > $(BUILD_PATH)/musl-gcc
369 + chmod +x $(BUILD_PATH)/musl-gcc
371 +$(IPERF_PATH)/.installed: $(IPERF_TAR)
372 + mkdir -p $(BUILD_PATH)
373 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
374 + sed -i '1s/^/#include <stdint.h>/' $(IPERF_PATH)/src/cjson.h $(IPERF_PATH)/src/timer.h
375 + sed -i -r 's/-p?g//g' $(IPERF_PATH)/src/Makefile*
378 +$(IPERF_PATH)/src/iperf3: | $(IPERF_PATH)/.installed $(USERSPACE_DEPS)
379 + cd $(IPERF_PATH) && CFLAGS="$(CFLAGS) -D_GNU_SOURCE" ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared
380 + $(MAKE) -C $(IPERF_PATH)
383 +$(LIBMNL_PATH)/.installed: $(LIBMNL_TAR)
384 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
387 +$(LIBMNL_PATH)/src/.libs/libmnl.a: | $(LIBMNL_PATH)/.installed $(USERSPACE_DEPS)
388 + cd $(LIBMNL_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared
389 + $(MAKE) -C $(LIBMNL_PATH)
390 + sed -i 's:prefix=.*:prefix=$(LIBMNL_PATH):' $(LIBMNL_PATH)/libmnl.pc
392 +$(WIREGUARD_TOOLS_PATH)/.installed: $(WIREGUARD_TOOLS_TAR)
393 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
396 +$(WIREGUARD_TOOLS_PATH)/src/tools/wg: | $(WIREGUARD_TOOLS_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
397 + LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" $(MAKE) -C $(WIREGUARD_TOOLS_PATH)/src/tools LIBMNL_CFLAGS="-I$(LIBMNL_PATH)/include" LIBMNL_LDLIBS="-lmnl" wg
400 +$(BUILD_PATH)/init: init.c | $(USERSPACE_DEPS)
401 + mkdir -p $(BUILD_PATH)
402 + $(MUSL_CC) -o $@ $(CFLAGS) $(LDFLAGS) -std=gnu11 $<
405 +$(IPUTILS_PATH)/.installed: $(IPUTILS_TAR)
406 + mkdir -p $(BUILD_PATH)
407 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
410 +$(IPUTILS_PATH)/ping: | $(IPUTILS_PATH)/.installed $(USERSPACE_DEPS)
411 + $(MAKE) -C $(IPUTILS_PATH) USE_CAP=no USE_IDN=no USE_NETTLE=no USE_CRYPTO=no ping
414 +$(BASH_PATH)/.installed: $(BASH_TAR)
415 + mkdir -p $(BUILD_PATH)
416 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
419 +$(BASH_PATH)/bash: | $(BASH_PATH)/.installed $(USERSPACE_DEPS)
420 + cd $(BASH_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --without-bash-malloc --disable-debugger --disable-help-builtin --disable-history --disable-multibyte --disable-progcomp --disable-readline --disable-mem-scramble
421 + $(MAKE) -C $(BASH_PATH)
424 +$(IPROUTE2_PATH)/.installed: $(IPROUTE2_TAR)
425 + mkdir -p $(BUILD_PATH)
426 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
427 + printf 'CC:=$(CC)\nPKG_CONFIG:=pkg-config\nTC_CONFIG_XT:=n\nTC_CONFIG_ATM:=n\nTC_CONFIG_IPSET:=n\nIP_CONFIG_SETNS:=y\nHAVE_ELF:=n\nHAVE_MNL:=y\nHAVE_BERKELEY_DB:=n\nHAVE_LATEX:=n\nHAVE_PDFLATEX:=n\nCFLAGS+=-DHAVE_SETNS -DHAVE_LIBMNL -I$(LIBMNL_PATH)/include\nLDLIBS+=-lmnl' > $(IPROUTE2_PATH)/config.mk
428 + printf 'lib: snapshot\n\t$$(MAKE) -C lib\nip/ip: lib\n\t$$(MAKE) -C ip ip\nmisc/ss: lib\n\t$$(MAKE) -C misc ss\n' >> $(IPROUTE2_PATH)/Makefile
431 +$(IPROUTE2_PATH)/ip/ip: | $(IPROUTE2_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
432 + LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" PKG_CONFIG_LIBDIR="$(LIBMNL_PATH)" $(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ ip/ip
433 + $(STRIP) -s $(IPROUTE2_PATH)/ip/ip
435 +$(IPROUTE2_PATH)/misc/ss: | $(IPROUTE2_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
436 + LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" PKG_CONFIG_LIBDIR="$(LIBMNL_PATH)" $(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ misc/ss
437 + $(STRIP) -s $(IPROUTE2_PATH)/misc/ss
439 +$(IPTABLES_PATH)/.installed: $(IPTABLES_TAR)
440 + mkdir -p $(BUILD_PATH)
441 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
442 + sed -i -e "/nfnetlink=[01]/s:=[01]:=0:" -e "/nfconntrack=[01]/s:=[01]:=0:" $(IPTABLES_PATH)/configure
445 +$(IPTABLES_PATH)/iptables/xtables-multi: | $(IPTABLES_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
446 + cd $(IPTABLES_PATH) && PKG_CONFIG_LIBDIR="$(LIBMNL_PATH)" ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared --disable-nftables --disable-bpf-compiler --disable-nfsynproxy --disable-libipq --with-kernel=$(BUILD_PATH)/include
447 + $(MAKE) -C $(IPTABLES_PATH)
450 +$(NMAP_PATH)/.installed: $(NMAP_TAR)
451 + mkdir -p $(BUILD_PATH)
452 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
455 +$(NMAP_PATH)/ncat/ncat: | $(NMAP_PATH)/.installed $(USERSPACE_DEPS)
456 + cd $(NMAP_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared --without-ndiff --without-zenmap --without-nping --with-libpcap=included --with-libpcre=included --with-libdnet=included --without-liblua --with-liblinear=included --without-nmap-update --without-openssl --with-pcap=linux
457 + $(MAKE) -C $(NMAP_PATH) build-ncat
461 + rm -rf $(BUILD_PATH)
464 + rm -rf $(DISTFILES_PATH)
466 +menuconfig: $(KERNEL_BUILD_PATH)/.config
467 + $(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) CC="$(NOPIE_GCC)" menuconfig
469 +.PHONY: qemu build clean distclean menuconfig
472 +++ b/tools/testing/selftests/wireguard/qemu/arch/aarch64.config
474 +CONFIG_SERIAL_AMBA_PL011=y
475 +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
476 +CONFIG_CMDLINE_BOOL=y
477 +CONFIG_CMDLINE="console=ttyAMA0 wg.success=ttyAMA1"
478 +CONFIG_FRAME_WARN=1280
480 +++ b/tools/testing/selftests/wireguard/qemu/arch/aarch64_be.config
482 +CONFIG_CPU_BIG_ENDIAN=y
483 +CONFIG_SERIAL_AMBA_PL011=y
484 +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
485 +CONFIG_CMDLINE_BOOL=y
486 +CONFIG_CMDLINE="console=ttyAMA0 wg.success=ttyAMA1"
487 +CONFIG_FRAME_WARN=1280
489 +++ b/tools/testing/selftests/wireguard/qemu/arch/arm.config
492 +CONFIG_ARCH_MULTI_V7=y
494 +CONFIG_THUMB2_KERNEL=n
495 +CONFIG_SERIAL_AMBA_PL011=y
496 +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
497 +CONFIG_CMDLINE_BOOL=y
498 +CONFIG_CMDLINE="console=ttyAMA0 wg.success=ttyAMA1"
499 +CONFIG_FRAME_WARN=1024
501 +++ b/tools/testing/selftests/wireguard/qemu/arch/armeb.config
504 +CONFIG_ARCH_MULTI_V7=y
506 +CONFIG_THUMB2_KERNEL=n
507 +CONFIG_SERIAL_AMBA_PL011=y
508 +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
509 +CONFIG_CMDLINE_BOOL=y
510 +CONFIG_CMDLINE="console=ttyAMA0 wg.success=ttyAMA1"
511 +CONFIG_CPU_BIG_ENDIAN=y
512 +CONFIG_FRAME_WARN=1024
514 +++ b/tools/testing/selftests/wireguard/qemu/arch/i686.config
516 +CONFIG_SERIAL_8250=y
517 +CONFIG_SERIAL_8250_CONSOLE=y
518 +CONFIG_CMDLINE_BOOL=y
519 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
520 +CONFIG_FRAME_WARN=1024
522 +++ b/tools/testing/selftests/wireguard/qemu/arch/m68k.config
527 +CONFIG_SERIAL_PMACZILOG=y
528 +CONFIG_SERIAL_PMACZILOG_TTYS=y
529 +CONFIG_SERIAL_PMACZILOG_CONSOLE=y
530 +CONFIG_CMDLINE_BOOL=y
531 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
532 +CONFIG_FRAME_WARN=1024
534 +++ b/tools/testing/selftests/wireguard/qemu/arch/mips.config
536 +CONFIG_CPU_MIPS32_R2=y
539 +CONFIG_MIPS_FP_SUPPORT=y
540 +CONFIG_POWER_RESET=y
541 +CONFIG_POWER_RESET_SYSCON=y
542 +CONFIG_SERIAL_8250=y
543 +CONFIG_SERIAL_8250_CONSOLE=y
544 +CONFIG_CMDLINE_BOOL=y
545 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
546 +CONFIG_FRAME_WARN=1024
548 +++ b/tools/testing/selftests/wireguard/qemu/arch/mips64.config
551 +CONFIG_CPU_MIPS64_R2=y
553 +CONFIG_CPU_HAS_MSA=y
556 +CONFIG_MIPS_FP_SUPPORT=y
557 +CONFIG_POWER_RESET=y
558 +CONFIG_POWER_RESET_SYSCON=y
559 +CONFIG_SERIAL_8250=y
560 +CONFIG_SERIAL_8250_CONSOLE=y
561 +CONFIG_CMDLINE_BOOL=y
562 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
563 +CONFIG_FRAME_WARN=1280
565 +++ b/tools/testing/selftests/wireguard/qemu/arch/mips64el.config
568 +CONFIG_CPU_MIPS64_R2=y
570 +CONFIG_CPU_HAS_MSA=y
572 +CONFIG_CPU_LITTLE_ENDIAN=y
574 +CONFIG_MIPS_FP_SUPPORT=y
575 +CONFIG_POWER_RESET=y
576 +CONFIG_POWER_RESET_SYSCON=y
577 +CONFIG_SERIAL_8250=y
578 +CONFIG_SERIAL_8250_CONSOLE=y
579 +CONFIG_CMDLINE_BOOL=y
580 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
581 +CONFIG_FRAME_WARN=1280
583 +++ b/tools/testing/selftests/wireguard/qemu/arch/mipsel.config
585 +CONFIG_CPU_MIPS32_R2=y
587 +CONFIG_CPU_LITTLE_ENDIAN=y
589 +CONFIG_MIPS_FP_SUPPORT=y
590 +CONFIG_POWER_RESET=y
591 +CONFIG_POWER_RESET_SYSCON=y
592 +CONFIG_SERIAL_8250=y
593 +CONFIG_SERIAL_8250_CONSOLE=y
594 +CONFIG_CMDLINE_BOOL=y
595 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
596 +CONFIG_FRAME_WARN=1024
598 +++ b/tools/testing/selftests/wireguard/qemu/arch/powerpc.config
600 +CONFIG_PPC_QEMU_E500=y
601 +CONFIG_FSL_SOC_BOOKE=y
604 +CONFIG_SERIAL_8250=y
605 +CONFIG_SERIAL_8250_CONSOLE=y
606 +CONFIG_MATH_EMULATION=y
607 +CONFIG_CMDLINE_BOOL=y
608 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
609 +CONFIG_FRAME_WARN=1024
611 +++ b/tools/testing/selftests/wireguard/qemu/arch/powerpc64le.config
614 +CONFIG_PPC_PSERIES=y
617 +CONFIG_PPC_OF_BOOT_TRAMPOLINE=y
618 +CONFIG_PPC_RADIX_MMU=y
619 +CONFIG_HVC_CONSOLE=y
620 +CONFIG_CPU_LITTLE_ENDIAN=y
621 +CONFIG_CMDLINE_BOOL=y
622 +CONFIG_CMDLINE="console=hvc0 wg.success=hvc1"
623 +CONFIG_SECTION_MISMATCH_WARN_ONLY=y
624 +CONFIG_FRAME_WARN=1280
626 +++ b/tools/testing/selftests/wireguard/qemu/arch/x86_64.config
628 +CONFIG_SERIAL_8250=y
629 +CONFIG_SERIAL_8250_CONSOLE=y
630 +CONFIG_CMDLINE_BOOL=y
631 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
632 +CONFIG_FRAME_WARN=1280
634 +++ b/tools/testing/selftests/wireguard/qemu/debug.config
636 +CONFIG_LOCALVERSION="-debug"
637 +CONFIG_ENABLE_WARN_DEPRECATED=y
638 +CONFIG_ENABLE_MUST_CHECK=y
639 +CONFIG_FRAME_POINTER=y
640 +CONFIG_STACK_VALIDATION=y
641 +CONFIG_DEBUG_KERNEL=y
643 +CONFIG_DEBUG_INFO_DWARF4=y
644 +CONFIG_PAGE_EXTENSION=y
645 +CONFIG_PAGE_POISONING=y
646 +CONFIG_DEBUG_OBJECTS=y
647 +CONFIG_DEBUG_OBJECTS_FREE=y
648 +CONFIG_DEBUG_OBJECTS_TIMERS=y
649 +CONFIG_DEBUG_OBJECTS_WORK=y
650 +CONFIG_DEBUG_OBJECTS_RCU_HEAD=y
651 +CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER=y
652 +CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT=1
653 +CONFIG_SLUB_DEBUG_ON=y
655 +CONFIG_DEBUG_MEMORY_INIT=y
656 +CONFIG_HAVE_DEBUG_STACKOVERFLOW=y
657 +CONFIG_DEBUG_STACKOVERFLOW=y
658 +CONFIG_HAVE_ARCH_KMEMCHECK=y
659 +CONFIG_HAVE_ARCH_KASAN=y
661 +CONFIG_KASAN_INLINE=y
663 +CONFIG_UBSAN_SANITIZE_ALL=y
664 +CONFIG_UBSAN_NO_ALIGNMENT=y
666 +CONFIG_DEBUG_KMEMLEAK=y
667 +CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=8192
668 +CONFIG_DEBUG_STACK_USAGE=y
669 +CONFIG_DEBUG_SHIRQ=y
670 +CONFIG_WQ_WATCHDOG=y
671 +CONFIG_SCHED_DEBUG=y
674 +CONFIG_SCHED_STACK_END_CHECK=y
675 +CONFIG_DEBUG_TIMEKEEPING=y
676 +CONFIG_TIMER_STATS=y
677 +CONFIG_DEBUG_PREEMPT=y
678 +CONFIG_DEBUG_RT_MUTEXES=y
679 +CONFIG_DEBUG_SPINLOCK=y
680 +CONFIG_DEBUG_MUTEXES=y
681 +CONFIG_DEBUG_LOCK_ALLOC=y
682 +CONFIG_PROVE_LOCKING=y
684 +CONFIG_DEBUG_ATOMIC_SLEEP=y
685 +CONFIG_TRACE_IRQFLAGS=y
686 +CONFIG_DEBUG_BUGVERBOSE=y
688 +CONFIG_DEBUG_PI_LIST=y
690 +CONFIG_SPARSE_RCU_POINTER=y
691 +CONFIG_RCU_CPU_STALL_TIMEOUT=21
693 +CONFIG_RCU_EQS_DEBUG=y
694 +CONFIG_USER_STACKTRACE_SUPPORT=y
696 +CONFIG_DEBUG_NOTIFIERS=y
697 +CONFIG_DOUBLEFAULT=y
698 +CONFIG_X86_DEBUG_FPU=y
699 +CONFIG_DEBUG_SECTION_MISMATCH=y
700 +CONFIG_DEBUG_PAGEALLOC=y
701 +CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT=y
702 +CONFIG_DEBUG_WW_MUTEX_SLOWPATH=y
704 +++ b/tools/testing/selftests/wireguard/qemu/init.c
706 +// SPDX-License-Identifier: GPL-2.0
708 + * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
717 +#include <stdbool.h>
719 +#include <sys/wait.h>
720 +#include <sys/mount.h>
721 +#include <sys/types.h>
722 +#include <sys/stat.h>
723 +#include <sys/types.h>
725 +#include <sys/ioctl.h>
726 +#include <sys/reboot.h>
727 +#include <sys/utsname.h>
728 +#include <sys/sendfile.h>
729 +#include <linux/random.h>
730 +#include <linux/version.h>
732 +__attribute__((noreturn)) static void poweroff(void)
736 + reboot(RB_AUTOBOOT);
738 + fprintf(stderr, "\x1b[37m\x1b[41m\x1b[1mFailed to power off!!!\x1b[0m\n");
742 +static void panic(const char *what)
744 + fprintf(stderr, "\n\n\x1b[37m\x1b[41m\x1b[1mSOMETHING WENT HORRIBLY WRONG\x1b[0m\n\n \x1b[31m\x1b[1m%s: %s\x1b[0m\n\n\x1b[37m\x1b[44m\x1b[1mPower off...\x1b[0m\n\n", what, strerror(errno));
748 +#define pretty_message(msg) puts("\x1b[32m\x1b[1m" msg "\x1b[0m")
750 +static void print_banner(void)
752 + struct utsname utsname;
755 + if (uname(&utsname) < 0)
758 + len = strlen(" WireGuard Test Suite on ") + strlen(utsname.sysname) + strlen(utsname.release) + strlen(utsname.machine);
759 + printf("\x1b[45m\x1b[33m\x1b[1m%*.s\x1b[0m\n\x1b[45m\x1b[33m\x1b[1m WireGuard Test Suite on %s %s %s \x1b[0m\n\x1b[45m\x1b[33m\x1b[1m%*.s\x1b[0m\n\n", len, "", utsname.sysname, utsname.release, utsname.machine, len, "");
762 +static void seed_rng(void)
768 + unsigned char buffer[256];
770 + .entropy_count = sizeof(entropy.buffer) * 8,
771 + .buffer_size = sizeof(entropy.buffer),
772 + .buffer = "Adding real entropy is not actually important for these tests. Don't try this at home, kids!"
775 + if (mknod("/dev/urandom", S_IFCHR | 0644, makedev(1, 9)))
776 + panic("mknod(/dev/urandom)");
777 + fd = open("/dev/urandom", O_WRONLY);
779 + panic("open(urandom)");
780 + for (int i = 0; i < 256; ++i) {
781 + if (ioctl(fd, RNDADDENTROPY, &entropy) < 0)
782 + panic("ioctl(urandom)");
787 +static void mount_filesystems(void)
789 + pretty_message("[+] Mounting filesystems...");
790 + mkdir("/dev", 0755);
791 + mkdir("/proc", 0755);
792 + mkdir("/sys", 0755);
793 + mkdir("/tmp", 0755);
794 + mkdir("/run", 0755);
795 + mkdir("/var", 0755);
796 + if (mount("none", "/dev", "devtmpfs", 0, NULL))
797 + panic("devtmpfs mount");
798 + if (mount("none", "/proc", "proc", 0, NULL))
799 + panic("procfs mount");
800 + if (mount("none", "/sys", "sysfs", 0, NULL))
801 + panic("sysfs mount");
802 + if (mount("none", "/tmp", "tmpfs", 0, NULL))
803 + panic("tmpfs mount");
804 + if (mount("none", "/run", "tmpfs", 0, NULL))
805 + panic("tmpfs mount");
806 + if (mount("none", "/sys/kernel/debug", "debugfs", 0, NULL))
807 + ; /* Not a problem if it fails.*/
808 + if (symlink("/run", "/var/run"))
809 + panic("run symlink");
810 + if (symlink("/proc/self/fd", "/dev/fd"))
811 + panic("fd symlink");
814 +static void enable_logging(void)
817 + pretty_message("[+] Enabling logging...");
818 + fd = open("/proc/sys/kernel/printk", O_WRONLY);
820 + if (write(fd, "9\n", 2) != 2)
821 + panic("write(printk)");
824 + fd = open("/proc/sys/debug/exception-trace", O_WRONLY);
826 + if (write(fd, "1\n", 2) != 2)
827 + panic("write(exception-trace)");
830 + fd = open("/proc/sys/kernel/panic_on_warn", O_WRONLY);
832 + if (write(fd, "1\n", 2) != 2)
833 + panic("write(panic_on_warn)");
838 +static void kmod_selftests(void)
841 + char line[2048], *start, *pass;
842 + bool success = true;
843 + pretty_message("[+] Module self-tests:");
844 + file = fopen("/proc/kmsg", "r");
846 + panic("fopen(kmsg)");
847 + if (fcntl(fileno(file), F_SETFL, O_NONBLOCK) < 0)
848 + panic("fcntl(kmsg, nonblock)");
849 + while (fgets(line, sizeof(line), file)) {
850 + start = strstr(line, "wireguard: ");
854 + *strchrnul(start, '\n') = '\0';
855 + if (strstr(start, "www.wireguard.com"))
857 + pass = strstr(start, ": pass");
858 + if (!pass || pass[6] != '\0') {
860 + printf(" \x1b[31m* %s\x1b[0m\n", start);
862 + printf(" \x1b[32m* %s\x1b[0m\n", start);
866 + puts("\x1b[31m\x1b[1m[-] Tests failed! \u2639\x1b[0m");
871 +static void launch_tests(void)
873 + char cmdline[4096], *success_dev;
877 + pretty_message("[+] Launching tests...");
881 + else if (pid == 0) {
882 + execl("/init.sh", "init", NULL);
885 + if (waitpid(pid, &status, 0) < 0)
887 + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
888 + pretty_message("[+] Tests successful! :-)");
889 + fd = open("/proc/cmdline", O_RDONLY);
891 + panic("open(/proc/cmdline)");
892 + if (read(fd, cmdline, sizeof(cmdline) - 1) <= 0)
893 + panic("read(/proc/cmdline)");
894 + cmdline[sizeof(cmdline) - 1] = '\0';
895 + for (success_dev = strtok(cmdline, " \n"); success_dev; success_dev = strtok(NULL, " \n")) {
896 + if (strncmp(success_dev, "wg.success=", 11))
898 + memcpy(success_dev + 11 - 5, "/dev/", 5);
899 + success_dev += 11 - 5;
902 + if (!success_dev || !strlen(success_dev))
903 + panic("Unable to find success device");
905 + fd = open(success_dev, O_WRONLY);
907 + panic("open(success_dev)");
908 + if (write(fd, "success\n", 8) != 8)
909 + panic("write(success_dev)");
912 + const char *why = "unknown cause";
915 + if (WIFEXITED(status)) {
917 + what = WEXITSTATUS(status);
918 + } else if (WIFSIGNALED(status)) {
920 + what = WTERMSIG(status);
922 + printf("\x1b[31m\x1b[1m[-] Tests failed with %s %d! \u2639\x1b[0m\n", why, what);
926 +static void ensure_console(void)
928 + for (unsigned int i = 0; i < 1000; ++i) {
929 + int fd = open("/dev/console", O_RDWR);
938 + if (write(1, "\0\0\0\0\n", 5) == 5)
941 + panic("Unable to open console device");
944 +static void clear_leaks(void)
948 + fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
951 + pretty_message("[+] Starting memory leak detection...");
952 + write(fd, "clear\n", 5);
956 +static void check_leaks(void)
960 + fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
963 + pretty_message("[+] Scanning for memory leaks...");
964 + sleep(2); /* Wait for any grace periods. */
965 + write(fd, "scan\n", 5);
968 + fd = open("/sys/kernel/debug/kmemleak", O_RDONLY);
971 + if (sendfile(1, fd, NULL, 0x7ffff000) > 0)
972 + panic("Memory leaks encountered");
976 +int main(int argc, char *argv[])
981 + mount_filesystems();
991 +++ b/tools/testing/selftests/wireguard/qemu/kernel.config
993 +CONFIG_LOCALVERSION=""
1001 +CONFIG_NAMESPACES=y
1007 +CONFIG_NETFILTER_ADVANCED=y
1008 +CONFIG_NF_CONNTRACK=y
1010 +CONFIG_NETFILTER_XTABLES=y
1011 +CONFIG_NETFILTER_XT_NAT=y
1012 +CONFIG_NETFILTER_XT_MATCH_LENGTH=y
1013 +CONFIG_NF_CONNTRACK_IPV4=y
1014 +CONFIG_NF_NAT_IPV4=y
1015 +CONFIG_IP_NF_IPTABLES=y
1016 +CONFIG_IP_NF_FILTER=y
1018 +CONFIG_IP_ADVANCED_ROUTER=y
1019 +CONFIG_IP_MULTIPLE_TABLES=y
1020 +CONFIG_IPV6_MULTIPLE_TABLES=y
1022 +CONFIG_BINFMT_ELF=y
1023 +CONFIG_BINFMT_SCRIPT=y
1025 +CONFIG_VIRTUALIZATION=y
1026 +CONFIG_HYPERVISOR_GUEST=y
1029 +CONFIG_PARAVIRT_SPINLOCKS=y
1033 +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y
1039 +CONFIG_SPARSEMEM_VMEMMAP=y
1046 +CONFIG_NO_HZ_IDLE=y
1047 +CONFIG_NO_HZ_FULL=n
1048 +CONFIG_HZ_PERIODIC=n
1049 +CONFIG_HIGH_RES_TIMERS=y
1050 +CONFIG_ARCH_RANDOM=y
1051 +CONFIG_FILE_LOCKING=y
1052 +CONFIG_POSIX_TIMERS=y
1055 +CONFIG_PROC_SYSCTL=y
1058 +CONFIG_CONSOLE_LOGLEVEL_DEFAULT=15
1059 +CONFIG_PRINTK_TIME=y
1060 +CONFIG_BLK_DEV_INITRD=y
1061 +CONFIG_LEGACY_VSYSCALL_NONE=y
1062 +CONFIG_KERNEL_GZIP=y
1063 +CONFIG_PANIC_ON_OOPS=y
1064 +CONFIG_BUG_ON_DATA_CORRUPTION=y
1065 +CONFIG_LOCKUP_DETECTOR=y
1066 +CONFIG_SOFTLOCKUP_DETECTOR=y
1067 +CONFIG_HARDLOCKUP_DETECTOR=y
1068 +CONFIG_WQ_WATCHDOG=y
1069 +CONFIG_DETECT_HUNG_TASK=y
1070 +CONFIG_BOOTPARAM_HARDLOCKUP_PANIC=y
1071 +CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y
1072 +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y
1073 +CONFIG_PANIC_TIMEOUT=-1
1074 +CONFIG_STACKTRACE=y
1075 +CONFIG_EARLY_PRINTK=y
1076 +CONFIG_GDB_SCRIPTS=y
1078 +CONFIG_WIREGUARD_DEBUG=y