1 From e333013ee167444adefd8a292e401b70e97dd4b2 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 074/124] wireguard: selftests: import harness makefile for
7 commit 65d88d04114bca7d85faebd5fed61069cb2b632c upstream.
9 WireGuard has been using this on build.wireguard.com for the last
10 several years with considerable success. It allows for very quick and
11 iterative development cycles, and supports several platforms.
13 To run the test suite on your current platform in QEMU:
15 $ make -C tools/testing/selftests/wireguard/qemu -j$(nproc)
17 To run it with KASAN and such turned on:
19 $ DEBUG_KERNEL=yes make -C tools/testing/selftests/wireguard/qemu -j$(nproc)
21 To run it emulated for another platform in QEMU:
23 $ ARCH=arm make -C tools/testing/selftests/wireguard/qemu -j$(nproc)
25 At the moment, we support aarch64_be, aarch64, arm, armeb, i686, m68k,
26 mips64, mips64el, mips, mipsel, powerpc64le, powerpc, and x86_64.
28 The system supports incremental rebuilding, so it should be very fast to
29 change a single file and then test it out and have immediate feedback.
31 This requires for the right toolchain and qemu to be installed prior.
32 I've had success with those from musl.cc.
34 This is tailored for WireGuard at the moment, though later projects
35 might generalize it for other network testing.
37 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
38 Signed-off-by: David S. Miller <davem@davemloft.net>
39 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
41 .../selftests/wireguard/qemu/.gitignore | 2 +
42 .../testing/selftests/wireguard/qemu/Makefile | 385 ++++++++++++++++++
43 .../wireguard/qemu/arch/aarch64.config | 5 +
44 .../wireguard/qemu/arch/aarch64_be.config | 6 +
45 .../selftests/wireguard/qemu/arch/arm.config | 9 +
46 .../wireguard/qemu/arch/armeb.config | 10 +
47 .../selftests/wireguard/qemu/arch/i686.config | 5 +
48 .../selftests/wireguard/qemu/arch/m68k.config | 9 +
49 .../selftests/wireguard/qemu/arch/mips.config | 11 +
50 .../wireguard/qemu/arch/mips64.config | 14 +
51 .../wireguard/qemu/arch/mips64el.config | 15 +
52 .../wireguard/qemu/arch/mipsel.config | 12 +
53 .../wireguard/qemu/arch/powerpc.config | 10 +
54 .../wireguard/qemu/arch/powerpc64le.config | 12 +
55 .../wireguard/qemu/arch/x86_64.config | 5 +
56 .../selftests/wireguard/qemu/debug.config | 67 +++
57 tools/testing/selftests/wireguard/qemu/init.c | 284 +++++++++++++
58 .../selftests/wireguard/qemu/kernel.config | 86 ++++
59 18 files changed, 947 insertions(+)
60 create mode 100644 tools/testing/selftests/wireguard/qemu/.gitignore
61 create mode 100644 tools/testing/selftests/wireguard/qemu/Makefile
62 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/aarch64.config
63 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/aarch64_be.config
64 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/arm.config
65 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/armeb.config
66 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/i686.config
67 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/m68k.config
68 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/mips.config
69 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/mips64.config
70 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/mips64el.config
71 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/mipsel.config
72 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/powerpc.config
73 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/powerpc64le.config
74 create mode 100644 tools/testing/selftests/wireguard/qemu/arch/x86_64.config
75 create mode 100644 tools/testing/selftests/wireguard/qemu/debug.config
76 create mode 100644 tools/testing/selftests/wireguard/qemu/init.c
77 create mode 100644 tools/testing/selftests/wireguard/qemu/kernel.config
80 +++ b/tools/testing/selftests/wireguard/qemu/.gitignore
85 +++ b/tools/testing/selftests/wireguard/qemu/Makefile
87 +# SPDX-License-Identifier: GPL-2.0
89 +# Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
93 +CHOST := $(shell gcc -dumpmachine)
95 +CBUILD := $(subst -gcc,,$(lastword $(subst /, ,$(firstword $(wildcard $(foreach bindir,$(subst :, ,$(PATH)),$(bindir)/$(ARCH)-*-gcc))))))
97 +$(error The toolchain for $(ARCH) is not installed)
101 +ARCH := $(firstword $(subst -, ,$(CBUILD)))
104 +# Set these from the environment to override
105 +KERNEL_PATH ?= $(PWD)/../../../../..
106 +BUILD_PATH ?= $(PWD)/build/$(ARCH)
107 +DISTFILES_PATH ?= $(PWD)/distfiles
110 +MIRROR := https://download.wireguard.com/qemu-test/distfiles/
114 +# variable name, tarball project name, version, tarball extension, default URI base
115 +define tar_download =
116 +$(1)_VERSION := $(3)
117 +$(1)_NAME := $(2)-$$($(1)_VERSION)
118 +$(1)_TAR := $(DISTFILES_PATH)/$$($(1)_NAME)$(4)
119 +$(1)_PATH := $(BUILD_PATH)/$$($(1)_NAME)
120 +$(call file_download,$$($(1)_NAME)$(4),$(5),$(6))
123 +define file_download =
124 +$(DISTFILES_PATH)/$(1):
125 + mkdir -p $(DISTFILES_PATH)
126 + 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'
127 + if echo "$(3) $$@.tmp" | sha256sum -c -; then mv $$@.tmp $$@; else rm -f $$@.tmp; exit 71; fi
130 +$(eval $(call tar_download,MUSL,musl,1.1.20,.tar.gz,https://www.musl-libc.org/releases/,44be8771d0e6c6b5f82dd15662eb2957c9a3173a19a8b49966ac0542bbd40d61))
131 +$(eval $(call tar_download,LIBMNL,libmnl,1.0.4,.tar.bz2,https://www.netfilter.org/projects/libmnl/files/,171f89699f286a5854b72b91d06e8f8e3683064c5901fb09d954a9ab6f551f81))
132 +$(eval $(call tar_download,IPERF,iperf,3.1.7,.tar.gz,http://downloads.es.net/pub/iperf/,a4ef73406fe92250602b8da2ae89ec53211f805df97a1d1d629db5a14043734f))
133 +$(eval $(call tar_download,BASH,bash,5.0,.tar.gz,https://ftp.gnu.org/gnu/bash/,b4a80f2ac66170b2913efbfb9f2594f1f76c7b1afd11f799e22035d63077fb4d))
134 +$(eval $(call tar_download,IPROUTE2,iproute2,5.1.0,.tar.gz,https://www.kernel.org/pub/linux/utils/net/iproute2/,9b43707d6075ecdca14803ca8ce0c8553848c49fa1586d12fd508d66577243f2))
135 +$(eval $(call tar_download,IPTABLES,iptables,1.6.1,.tar.bz2,https://www.netfilter.org/projects/iptables/files/,0fc2d7bd5d7be11311726466789d4c65fb4c8e096c9182b56ce97440864f0cf5))
136 +$(eval $(call tar_download,NMAP,nmap,7.60,.tar.bz2,https://nmap.org/dist/,a8796ecc4fa6c38aad6139d9515dc8113023a82e9d787e5a5fb5fa1b05516f21))
137 +$(eval $(call tar_download,IPUTILS,iputils,s20161105,.tar.gz,https://github.com/iputils/iputils/archive/s20161105.tar.gz/#,f813092f03d17294fd23544b129b95cdb87fe19f7970a51908a6b88509acad8a))
138 +$(eval $(call tar_download,WIREGUARD_TOOLS,WireGuard,0.0.20191212,.tar.xz,https://git.zx2c4.com/WireGuard/snapshot/,b0d718380f7a8822b2f12d75e462fa4eafa3a77871002981f367cd4fe2a1b071))
140 +KERNEL_BUILD_PATH := $(BUILD_PATH)/kernel$(if $(findstring yes,$(DEBUG_KERNEL)),-debug)
141 +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
142 +WIREGUARD_SOURCES := $(call rwildcard,$(KERNEL_PATH)/drivers/net/wireguard/,*)
144 +export CFLAGS ?= -O3 -pipe
146 +export CPPFLAGS := -I$(BUILD_PATH)/include
148 +ifeq ($(CHOST),$(CBUILD))
149 +CROSS_COMPILE_FLAG := --host=$(CHOST)
150 +NOPIE_GCC := gcc -fno-PIE
151 +CFLAGS += -march=native
154 +$(info Cross compilation: building for $(CBUILD) using $(CHOST))
155 +CROSS_COMPILE_FLAG := --build=$(CBUILD) --host=$(CHOST)
156 +export CROSS_COMPILE=$(CBUILD)-
157 +NOPIE_GCC := $(CBUILD)-gcc -fno-PIE
158 +STRIP := $(CBUILD)-strip
160 +ifeq ($(ARCH),aarch64)
161 +QEMU_ARCH := aarch64
162 +KERNEL_ARCH := arm64
163 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm64/boot/Image
164 +ifeq ($(CHOST),$(CBUILD))
165 +QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
167 +QEMU_MACHINE := -cpu cortex-a53 -machine virt
168 +CFLAGS += -march=armv8-a -mtune=cortex-a53
170 +else ifeq ($(ARCH),aarch64_be)
171 +QEMU_ARCH := aarch64
172 +KERNEL_ARCH := arm64
173 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm64/boot/Image
174 +ifeq ($(CHOST),$(CBUILD))
175 +QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
177 +QEMU_MACHINE := -cpu cortex-a53 -machine virt
178 +CFLAGS += -march=armv8-a -mtune=cortex-a53
180 +else ifeq ($(ARCH),arm)
183 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm/boot/zImage
184 +ifeq ($(CHOST),$(CBUILD))
185 +QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
187 +QEMU_MACHINE := -cpu cortex-a15 -machine virt
188 +CFLAGS += -march=armv7-a -mtune=cortex-a15 -mabi=aapcs-linux
190 +else ifeq ($(ARCH),armeb)
193 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/arm/boot/zImage
194 +ifeq ($(CHOST),$(CBUILD))
195 +QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
197 +QEMU_MACHINE := -cpu cortex-a15 -machine virt
198 +CFLAGS += -march=armv7-a -mabi=aapcs-linux # We don't pass -mtune=cortex-a15 due to a compiler bug on big endian.
199 +LDFLAGS += -Wl,--be8
201 +else ifeq ($(ARCH),x86_64)
203 +KERNEL_ARCH := x86_64
204 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
205 +ifeq ($(CHOST),$(CBUILD))
206 +QEMU_MACHINE := -cpu host -machine q35,accel=kvm
208 +QEMU_MACHINE := -cpu Skylake-Server -machine q35
209 +CFLAGS += -march=skylake-avx512
211 +else ifeq ($(ARCH),i686)
214 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
215 +ifeq ($(subst i686,x86_64,$(CBUILD)),$(CHOST))
216 +QEMU_MACHINE := -cpu host -machine q35,accel=kvm
218 +QEMU_MACHINE := -cpu coreduo -machine q35
219 +CFLAGS += -march=prescott
221 +else ifeq ($(ARCH),mips64)
224 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
225 +ifeq ($(CHOST),$(CBUILD))
226 +QEMU_MACHINE := -cpu host -machine malta,accel=kvm
229 +QEMU_MACHINE := -cpu MIPS64R2-generic -machine malta -smp 1
230 +CFLAGS += -march=mips64r2 -EB
232 +else ifeq ($(ARCH),mips64el)
233 +QEMU_ARCH := mips64el
235 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
236 +ifeq ($(CHOST),$(CBUILD))
237 +QEMU_MACHINE := -cpu host -machine malta,accel=kvm
240 +QEMU_MACHINE := -cpu MIPS64R2-generic -machine malta -smp 1
241 +CFLAGS += -march=mips64r2 -EL
243 +else ifeq ($(ARCH),mips)
246 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
247 +ifeq ($(CHOST),$(CBUILD))
248 +QEMU_MACHINE := -cpu host -machine malta,accel=kvm
251 +QEMU_MACHINE := -cpu 24Kf -machine malta -smp 1
252 +CFLAGS += -march=mips32r2 -EB
254 +else ifeq ($(ARCH),mipsel)
257 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
258 +ifeq ($(CHOST),$(CBUILD))
259 +QEMU_MACHINE := -cpu host -machine malta,accel=kvm
262 +QEMU_MACHINE := -cpu 24Kf -machine malta -smp 1
263 +CFLAGS += -march=mips32r2 -EL
265 +else ifeq ($(ARCH),powerpc64le)
267 +KERNEL_ARCH := powerpc
268 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
269 +ifeq ($(CHOST),$(CBUILD))
270 +QEMU_MACHINE := -cpu host,accel=kvm -machine pseries
272 +QEMU_MACHINE := -machine pseries
274 +CFLAGS += -mcpu=powerpc64le -mlong-double-64
275 +else ifeq ($(ARCH),powerpc)
277 +KERNEL_ARCH := powerpc
278 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/powerpc/boot/uImage
279 +ifeq ($(CHOST),$(CBUILD))
280 +QEMU_MACHINE := -cpu host,accel=kvm -machine ppce500
282 +QEMU_MACHINE := -machine ppce500
284 +CFLAGS += -mcpu=powerpc -mlong-double-64 -msecure-plt
285 +else ifeq ($(ARCH),m68k)
288 +KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
289 +ifeq ($(CHOST),$(CBUILD))
290 +QEMU_MACHINE := -cpu host,accel=kvm -machine q800
292 +QEMU_MACHINE := -machine q800
295 +$(error I only build: x86_64, i686, arm, armeb, aarch64, aarch64_be, mips, mipsel, mips64, mips64el, powerpc64le, powerpc, m68k)
298 +REAL_CC := $(CBUILD)-gcc
299 +MUSL_CC := $(BUILD_PATH)/musl-gcc
300 +export CC := $(MUSL_CC)
301 +USERSPACE_DEPS := $(MUSL_CC) $(BUILD_PATH)/include/.installed $(BUILD_PATH)/include/linux/.installed
303 +build: $(KERNEL_BZIMAGE)
304 +qemu: $(KERNEL_BZIMAGE)
305 + rm -f $(BUILD_PATH)/result
306 + timeout --foreground 20m qemu-system-$(QEMU_ARCH) \
311 + -m $$(grep -q CONFIG_DEBUG_KMEMLEAK=y $(KERNEL_BUILD_PATH)/.config && echo 1G || echo 256M) \
313 + -serial file:$(BUILD_PATH)/result \
317 + grep -Fq success $(BUILD_PATH)/result
319 +$(BUILD_PATH)/init-cpio-spec.txt:
320 + mkdir -p $(BUILD_PATH)
321 + echo "file /init $(BUILD_PATH)/init 755 0 0" > $@
322 + echo "file /init.sh $(PWD)/../netns.sh 755 0 0" >> $@
323 + echo "dir /dev 755 0 0" >> $@
324 + echo "nod /dev/console 644 0 0 c 5 1" >> $@
325 + echo "dir /bin 755 0 0" >> $@
326 + echo "file /bin/iperf3 $(IPERF_PATH)/src/iperf3 755 0 0" >> $@
327 + echo "file /bin/wg $(WIREGUARD_TOOLS_PATH)/src/tools/wg 755 0 0" >> $@
328 + echo "file /bin/bash $(BASH_PATH)/bash 755 0 0" >> $@
329 + echo "file /bin/ip $(IPROUTE2_PATH)/ip/ip 755 0 0" >> $@
330 + echo "file /bin/ss $(IPROUTE2_PATH)/misc/ss 755 0 0" >> $@
331 + echo "file /bin/ping $(IPUTILS_PATH)/ping 755 0 0" >> $@
332 + echo "file /bin/ncat $(NMAP_PATH)/ncat/ncat 755 0 0" >> $@
333 + echo "file /bin/xtables-multi $(IPTABLES_PATH)/iptables/xtables-multi 755 0 0" >> $@
334 + echo "slink /bin/iptables xtables-multi 777 0 0" >> $@
335 + echo "slink /bin/ping6 ping 777 0 0" >> $@
336 + echo "dir /lib 755 0 0" >> $@
337 + echo "file /lib/libc.so $(MUSL_PATH)/lib/libc.so 755 0 0" >> $@
338 + echo "slink /lib/ld-linux.so.1 libc.so 777 0 0" >> $@
340 +$(KERNEL_BUILD_PATH)/.config: kernel.config arch/$(ARCH).config
341 + mkdir -p $(KERNEL_BUILD_PATH)
342 + cp kernel.config $(KERNEL_BUILD_PATH)/minimal.config
343 + printf 'CONFIG_NR_CPUS=$(NR_CPUS)\nCONFIG_INITRAMFS_SOURCE="$(BUILD_PATH)/init-cpio-spec.txt"\n' >> $(KERNEL_BUILD_PATH)/minimal.config
344 + cat arch/$(ARCH).config >> $(KERNEL_BUILD_PATH)/minimal.config
345 + $(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) allnoconfig
346 + cd $(KERNEL_BUILD_PATH) && ARCH=$(KERNEL_ARCH) $(KERNEL_PATH)/scripts/kconfig/merge_config.sh -n $(KERNEL_BUILD_PATH)/.config $(KERNEL_BUILD_PATH)/minimal.config
347 + $(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,)
349 +$(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)
350 + $(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) CC="$(NOPIE_GCC)"
352 +$(BUILD_PATH)/include/linux/.installed: | $(KERNEL_BUILD_PATH)/.config
353 + $(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) INSTALL_HDR_PATH=$(BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) headers_install
356 +$(MUSL_PATH)/lib/libc.so: $(MUSL_TAR)
357 + mkdir -p $(BUILD_PATH)
358 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
359 + cd $(MUSL_PATH) && CC=$(REAL_CC) ./configure --prefix=/ --disable-static --build=$(CBUILD)
360 + $(MAKE) -C $(MUSL_PATH)
363 +$(BUILD_PATH)/include/.installed: $(MUSL_PATH)/lib/libc.so
364 + $(MAKE) -C $(MUSL_PATH) DESTDIR=$(BUILD_PATH) install-headers
367 +$(MUSL_CC): $(MUSL_PATH)/lib/libc.so
368 + sh $(MUSL_PATH)/tools/musl-gcc.specs.sh $(BUILD_PATH)/include $(MUSL_PATH)/lib /lib/ld-linux.so.1 > $(BUILD_PATH)/musl-gcc.specs
369 + printf '#!/bin/sh\nexec "$(REAL_CC)" --specs="$(BUILD_PATH)/musl-gcc.specs" -fno-stack-protector -no-pie "$$@"\n' > $(BUILD_PATH)/musl-gcc
370 + chmod +x $(BUILD_PATH)/musl-gcc
372 +$(IPERF_PATH)/.installed: $(IPERF_TAR)
373 + mkdir -p $(BUILD_PATH)
374 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
375 + sed -i '1s/^/#include <stdint.h>/' $(IPERF_PATH)/src/cjson.h $(IPERF_PATH)/src/timer.h
376 + sed -i -r 's/-p?g//g' $(IPERF_PATH)/src/Makefile*
379 +$(IPERF_PATH)/src/iperf3: | $(IPERF_PATH)/.installed $(USERSPACE_DEPS)
380 + cd $(IPERF_PATH) && CFLAGS="$(CFLAGS) -D_GNU_SOURCE" ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared
381 + $(MAKE) -C $(IPERF_PATH)
384 +$(LIBMNL_PATH)/.installed: $(LIBMNL_TAR)
385 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
388 +$(LIBMNL_PATH)/src/.libs/libmnl.a: | $(LIBMNL_PATH)/.installed $(USERSPACE_DEPS)
389 + cd $(LIBMNL_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared
390 + $(MAKE) -C $(LIBMNL_PATH)
391 + sed -i 's:prefix=.*:prefix=$(LIBMNL_PATH):' $(LIBMNL_PATH)/libmnl.pc
393 +$(WIREGUARD_TOOLS_PATH)/.installed: $(WIREGUARD_TOOLS_TAR)
394 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
397 +$(WIREGUARD_TOOLS_PATH)/src/tools/wg: | $(WIREGUARD_TOOLS_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
398 + LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" $(MAKE) -C $(WIREGUARD_TOOLS_PATH)/src/tools LIBMNL_CFLAGS="-I$(LIBMNL_PATH)/include" LIBMNL_LDLIBS="-lmnl" wg
401 +$(BUILD_PATH)/init: init.c | $(USERSPACE_DEPS)
402 + mkdir -p $(BUILD_PATH)
403 + $(MUSL_CC) -o $@ $(CFLAGS) $(LDFLAGS) -std=gnu11 $<
406 +$(IPUTILS_PATH)/.installed: $(IPUTILS_TAR)
407 + mkdir -p $(BUILD_PATH)
408 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
411 +$(IPUTILS_PATH)/ping: | $(IPUTILS_PATH)/.installed $(USERSPACE_DEPS)
412 + $(MAKE) -C $(IPUTILS_PATH) USE_CAP=no USE_IDN=no USE_NETTLE=no USE_CRYPTO=no ping
415 +$(BASH_PATH)/.installed: $(BASH_TAR)
416 + mkdir -p $(BUILD_PATH)
417 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
420 +$(BASH_PATH)/bash: | $(BASH_PATH)/.installed $(USERSPACE_DEPS)
421 + 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
422 + $(MAKE) -C $(BASH_PATH)
425 +$(IPROUTE2_PATH)/.installed: $(IPROUTE2_TAR)
426 + mkdir -p $(BUILD_PATH)
427 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
428 + 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
429 + 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
432 +$(IPROUTE2_PATH)/ip/ip: | $(IPROUTE2_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
433 + LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" PKG_CONFIG_LIBDIR="$(LIBMNL_PATH)" $(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ ip/ip
434 + $(STRIP) -s $(IPROUTE2_PATH)/ip/ip
436 +$(IPROUTE2_PATH)/misc/ss: | $(IPROUTE2_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
437 + LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" PKG_CONFIG_LIBDIR="$(LIBMNL_PATH)" $(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ misc/ss
438 + $(STRIP) -s $(IPROUTE2_PATH)/misc/ss
440 +$(IPTABLES_PATH)/.installed: $(IPTABLES_TAR)
441 + mkdir -p $(BUILD_PATH)
442 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
443 + sed -i -e "/nfnetlink=[01]/s:=[01]:=0:" -e "/nfconntrack=[01]/s:=[01]:=0:" $(IPTABLES_PATH)/configure
446 +$(IPTABLES_PATH)/iptables/xtables-multi: | $(IPTABLES_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
447 + 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
448 + $(MAKE) -C $(IPTABLES_PATH)
451 +$(NMAP_PATH)/.installed: $(NMAP_TAR)
452 + mkdir -p $(BUILD_PATH)
453 + flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
456 +$(NMAP_PATH)/ncat/ncat: | $(NMAP_PATH)/.installed $(USERSPACE_DEPS)
457 + 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
458 + $(MAKE) -C $(NMAP_PATH) build-ncat
462 + rm -rf $(BUILD_PATH)
465 + rm -rf $(DISTFILES_PATH)
467 +menuconfig: $(KERNEL_BUILD_PATH)/.config
468 + $(MAKE) -C $(KERNEL_PATH) O=$(KERNEL_BUILD_PATH) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(CROSS_COMPILE) CC="$(NOPIE_GCC)" menuconfig
470 +.PHONY: qemu build clean distclean menuconfig
473 +++ b/tools/testing/selftests/wireguard/qemu/arch/aarch64.config
475 +CONFIG_SERIAL_AMBA_PL011=y
476 +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
477 +CONFIG_CMDLINE_BOOL=y
478 +CONFIG_CMDLINE="console=ttyAMA0 wg.success=ttyAMA1"
479 +CONFIG_FRAME_WARN=1280
481 +++ b/tools/testing/selftests/wireguard/qemu/arch/aarch64_be.config
483 +CONFIG_CPU_BIG_ENDIAN=y
484 +CONFIG_SERIAL_AMBA_PL011=y
485 +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
486 +CONFIG_CMDLINE_BOOL=y
487 +CONFIG_CMDLINE="console=ttyAMA0 wg.success=ttyAMA1"
488 +CONFIG_FRAME_WARN=1280
490 +++ b/tools/testing/selftests/wireguard/qemu/arch/arm.config
493 +CONFIG_ARCH_MULTI_V7=y
495 +CONFIG_THUMB2_KERNEL=n
496 +CONFIG_SERIAL_AMBA_PL011=y
497 +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
498 +CONFIG_CMDLINE_BOOL=y
499 +CONFIG_CMDLINE="console=ttyAMA0 wg.success=ttyAMA1"
500 +CONFIG_FRAME_WARN=1024
502 +++ b/tools/testing/selftests/wireguard/qemu/arch/armeb.config
505 +CONFIG_ARCH_MULTI_V7=y
507 +CONFIG_THUMB2_KERNEL=n
508 +CONFIG_SERIAL_AMBA_PL011=y
509 +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
510 +CONFIG_CMDLINE_BOOL=y
511 +CONFIG_CMDLINE="console=ttyAMA0 wg.success=ttyAMA1"
512 +CONFIG_CPU_BIG_ENDIAN=y
513 +CONFIG_FRAME_WARN=1024
515 +++ b/tools/testing/selftests/wireguard/qemu/arch/i686.config
517 +CONFIG_SERIAL_8250=y
518 +CONFIG_SERIAL_8250_CONSOLE=y
519 +CONFIG_CMDLINE_BOOL=y
520 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
521 +CONFIG_FRAME_WARN=1024
523 +++ b/tools/testing/selftests/wireguard/qemu/arch/m68k.config
528 +CONFIG_SERIAL_PMACZILOG=y
529 +CONFIG_SERIAL_PMACZILOG_TTYS=y
530 +CONFIG_SERIAL_PMACZILOG_CONSOLE=y
531 +CONFIG_CMDLINE_BOOL=y
532 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
533 +CONFIG_FRAME_WARN=1024
535 +++ b/tools/testing/selftests/wireguard/qemu/arch/mips.config
537 +CONFIG_CPU_MIPS32_R2=y
540 +CONFIG_MIPS_FP_SUPPORT=y
541 +CONFIG_POWER_RESET=y
542 +CONFIG_POWER_RESET_SYSCON=y
543 +CONFIG_SERIAL_8250=y
544 +CONFIG_SERIAL_8250_CONSOLE=y
545 +CONFIG_CMDLINE_BOOL=y
546 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
547 +CONFIG_FRAME_WARN=1024
549 +++ b/tools/testing/selftests/wireguard/qemu/arch/mips64.config
552 +CONFIG_CPU_MIPS64_R2=y
554 +CONFIG_CPU_HAS_MSA=y
557 +CONFIG_MIPS_FP_SUPPORT=y
558 +CONFIG_POWER_RESET=y
559 +CONFIG_POWER_RESET_SYSCON=y
560 +CONFIG_SERIAL_8250=y
561 +CONFIG_SERIAL_8250_CONSOLE=y
562 +CONFIG_CMDLINE_BOOL=y
563 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
564 +CONFIG_FRAME_WARN=1280
566 +++ b/tools/testing/selftests/wireguard/qemu/arch/mips64el.config
569 +CONFIG_CPU_MIPS64_R2=y
571 +CONFIG_CPU_HAS_MSA=y
573 +CONFIG_CPU_LITTLE_ENDIAN=y
575 +CONFIG_MIPS_FP_SUPPORT=y
576 +CONFIG_POWER_RESET=y
577 +CONFIG_POWER_RESET_SYSCON=y
578 +CONFIG_SERIAL_8250=y
579 +CONFIG_SERIAL_8250_CONSOLE=y
580 +CONFIG_CMDLINE_BOOL=y
581 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
582 +CONFIG_FRAME_WARN=1280
584 +++ b/tools/testing/selftests/wireguard/qemu/arch/mipsel.config
586 +CONFIG_CPU_MIPS32_R2=y
588 +CONFIG_CPU_LITTLE_ENDIAN=y
590 +CONFIG_MIPS_FP_SUPPORT=y
591 +CONFIG_POWER_RESET=y
592 +CONFIG_POWER_RESET_SYSCON=y
593 +CONFIG_SERIAL_8250=y
594 +CONFIG_SERIAL_8250_CONSOLE=y
595 +CONFIG_CMDLINE_BOOL=y
596 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
597 +CONFIG_FRAME_WARN=1024
599 +++ b/tools/testing/selftests/wireguard/qemu/arch/powerpc.config
601 +CONFIG_PPC_QEMU_E500=y
602 +CONFIG_FSL_SOC_BOOKE=y
605 +CONFIG_SERIAL_8250=y
606 +CONFIG_SERIAL_8250_CONSOLE=y
607 +CONFIG_MATH_EMULATION=y
608 +CONFIG_CMDLINE_BOOL=y
609 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
610 +CONFIG_FRAME_WARN=1024
612 +++ b/tools/testing/selftests/wireguard/qemu/arch/powerpc64le.config
615 +CONFIG_PPC_PSERIES=y
618 +CONFIG_PPC_OF_BOOT_TRAMPOLINE=y
619 +CONFIG_PPC_RADIX_MMU=y
620 +CONFIG_HVC_CONSOLE=y
621 +CONFIG_CPU_LITTLE_ENDIAN=y
622 +CONFIG_CMDLINE_BOOL=y
623 +CONFIG_CMDLINE="console=hvc0 wg.success=hvc1"
624 +CONFIG_SECTION_MISMATCH_WARN_ONLY=y
625 +CONFIG_FRAME_WARN=1280
627 +++ b/tools/testing/selftests/wireguard/qemu/arch/x86_64.config
629 +CONFIG_SERIAL_8250=y
630 +CONFIG_SERIAL_8250_CONSOLE=y
631 +CONFIG_CMDLINE_BOOL=y
632 +CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
633 +CONFIG_FRAME_WARN=1280
635 +++ b/tools/testing/selftests/wireguard/qemu/debug.config
637 +CONFIG_LOCALVERSION="-debug"
638 +CONFIG_ENABLE_WARN_DEPRECATED=y
639 +CONFIG_ENABLE_MUST_CHECK=y
640 +CONFIG_FRAME_POINTER=y
641 +CONFIG_STACK_VALIDATION=y
642 +CONFIG_DEBUG_KERNEL=y
644 +CONFIG_DEBUG_INFO_DWARF4=y
645 +CONFIG_PAGE_EXTENSION=y
646 +CONFIG_PAGE_POISONING=y
647 +CONFIG_DEBUG_OBJECTS=y
648 +CONFIG_DEBUG_OBJECTS_FREE=y
649 +CONFIG_DEBUG_OBJECTS_TIMERS=y
650 +CONFIG_DEBUG_OBJECTS_WORK=y
651 +CONFIG_DEBUG_OBJECTS_RCU_HEAD=y
652 +CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER=y
653 +CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT=1
654 +CONFIG_SLUB_DEBUG_ON=y
656 +CONFIG_DEBUG_MEMORY_INIT=y
657 +CONFIG_HAVE_DEBUG_STACKOVERFLOW=y
658 +CONFIG_DEBUG_STACKOVERFLOW=y
659 +CONFIG_HAVE_ARCH_KMEMCHECK=y
660 +CONFIG_HAVE_ARCH_KASAN=y
662 +CONFIG_KASAN_INLINE=y
664 +CONFIG_UBSAN_SANITIZE_ALL=y
665 +CONFIG_UBSAN_NO_ALIGNMENT=y
667 +CONFIG_DEBUG_KMEMLEAK=y
668 +CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=8192
669 +CONFIG_DEBUG_STACK_USAGE=y
670 +CONFIG_DEBUG_SHIRQ=y
671 +CONFIG_WQ_WATCHDOG=y
672 +CONFIG_SCHED_DEBUG=y
675 +CONFIG_SCHED_STACK_END_CHECK=y
676 +CONFIG_DEBUG_TIMEKEEPING=y
677 +CONFIG_TIMER_STATS=y
678 +CONFIG_DEBUG_PREEMPT=y
679 +CONFIG_DEBUG_RT_MUTEXES=y
680 +CONFIG_DEBUG_SPINLOCK=y
681 +CONFIG_DEBUG_MUTEXES=y
682 +CONFIG_DEBUG_LOCK_ALLOC=y
683 +CONFIG_PROVE_LOCKING=y
685 +CONFIG_DEBUG_ATOMIC_SLEEP=y
686 +CONFIG_TRACE_IRQFLAGS=y
687 +CONFIG_DEBUG_BUGVERBOSE=y
689 +CONFIG_DEBUG_PI_LIST=y
691 +CONFIG_SPARSE_RCU_POINTER=y
692 +CONFIG_RCU_CPU_STALL_TIMEOUT=21
694 +CONFIG_RCU_EQS_DEBUG=y
695 +CONFIG_USER_STACKTRACE_SUPPORT=y
697 +CONFIG_DEBUG_NOTIFIERS=y
698 +CONFIG_DOUBLEFAULT=y
699 +CONFIG_X86_DEBUG_FPU=y
700 +CONFIG_DEBUG_SECTION_MISMATCH=y
701 +CONFIG_DEBUG_PAGEALLOC=y
702 +CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT=y
703 +CONFIG_DEBUG_WW_MUTEX_SLOWPATH=y
705 +++ b/tools/testing/selftests/wireguard/qemu/init.c
707 +// SPDX-License-Identifier: GPL-2.0
709 + * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
718 +#include <stdbool.h>
720 +#include <sys/wait.h>
721 +#include <sys/mount.h>
722 +#include <sys/types.h>
723 +#include <sys/stat.h>
724 +#include <sys/types.h>
726 +#include <sys/ioctl.h>
727 +#include <sys/reboot.h>
728 +#include <sys/utsname.h>
729 +#include <sys/sendfile.h>
730 +#include <linux/random.h>
731 +#include <linux/version.h>
733 +__attribute__((noreturn)) static void poweroff(void)
737 + reboot(RB_AUTOBOOT);
739 + fprintf(stderr, "\x1b[37m\x1b[41m\x1b[1mFailed to power off!!!\x1b[0m\n");
743 +static void panic(const char *what)
745 + 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));
749 +#define pretty_message(msg) puts("\x1b[32m\x1b[1m" msg "\x1b[0m")
751 +static void print_banner(void)
753 + struct utsname utsname;
756 + if (uname(&utsname) < 0)
759 + len = strlen(" WireGuard Test Suite on ") + strlen(utsname.sysname) + strlen(utsname.release) + strlen(utsname.machine);
760 + 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, "");
763 +static void seed_rng(void)
769 + unsigned char buffer[256];
771 + .entropy_count = sizeof(entropy.buffer) * 8,
772 + .buffer_size = sizeof(entropy.buffer),
773 + .buffer = "Adding real entropy is not actually important for these tests. Don't try this at home, kids!"
776 + if (mknod("/dev/urandom", S_IFCHR | 0644, makedev(1, 9)))
777 + panic("mknod(/dev/urandom)");
778 + fd = open("/dev/urandom", O_WRONLY);
780 + panic("open(urandom)");
781 + for (int i = 0; i < 256; ++i) {
782 + if (ioctl(fd, RNDADDENTROPY, &entropy) < 0)
783 + panic("ioctl(urandom)");
788 +static void mount_filesystems(void)
790 + pretty_message("[+] Mounting filesystems...");
791 + mkdir("/dev", 0755);
792 + mkdir("/proc", 0755);
793 + mkdir("/sys", 0755);
794 + mkdir("/tmp", 0755);
795 + mkdir("/run", 0755);
796 + mkdir("/var", 0755);
797 + if (mount("none", "/dev", "devtmpfs", 0, NULL))
798 + panic("devtmpfs mount");
799 + if (mount("none", "/proc", "proc", 0, NULL))
800 + panic("procfs mount");
801 + if (mount("none", "/sys", "sysfs", 0, NULL))
802 + panic("sysfs mount");
803 + if (mount("none", "/tmp", "tmpfs", 0, NULL))
804 + panic("tmpfs mount");
805 + if (mount("none", "/run", "tmpfs", 0, NULL))
806 + panic("tmpfs mount");
807 + if (mount("none", "/sys/kernel/debug", "debugfs", 0, NULL))
808 + ; /* Not a problem if it fails.*/
809 + if (symlink("/run", "/var/run"))
810 + panic("run symlink");
811 + if (symlink("/proc/self/fd", "/dev/fd"))
812 + panic("fd symlink");
815 +static void enable_logging(void)
818 + pretty_message("[+] Enabling logging...");
819 + fd = open("/proc/sys/kernel/printk", O_WRONLY);
821 + if (write(fd, "9\n", 2) != 2)
822 + panic("write(printk)");
825 + fd = open("/proc/sys/debug/exception-trace", O_WRONLY);
827 + if (write(fd, "1\n", 2) != 2)
828 + panic("write(exception-trace)");
831 + fd = open("/proc/sys/kernel/panic_on_warn", O_WRONLY);
833 + if (write(fd, "1\n", 2) != 2)
834 + panic("write(panic_on_warn)");
839 +static void kmod_selftests(void)
842 + char line[2048], *start, *pass;
843 + bool success = true;
844 + pretty_message("[+] Module self-tests:");
845 + file = fopen("/proc/kmsg", "r");
847 + panic("fopen(kmsg)");
848 + if (fcntl(fileno(file), F_SETFL, O_NONBLOCK) < 0)
849 + panic("fcntl(kmsg, nonblock)");
850 + while (fgets(line, sizeof(line), file)) {
851 + start = strstr(line, "wireguard: ");
855 + *strchrnul(start, '\n') = '\0';
856 + if (strstr(start, "www.wireguard.com"))
858 + pass = strstr(start, ": pass");
859 + if (!pass || pass[6] != '\0') {
861 + printf(" \x1b[31m* %s\x1b[0m\n", start);
863 + printf(" \x1b[32m* %s\x1b[0m\n", start);
867 + puts("\x1b[31m\x1b[1m[-] Tests failed! \u2639\x1b[0m");
872 +static void launch_tests(void)
874 + char cmdline[4096], *success_dev;
878 + pretty_message("[+] Launching tests...");
882 + else if (pid == 0) {
883 + execl("/init.sh", "init", NULL);
886 + if (waitpid(pid, &status, 0) < 0)
888 + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
889 + pretty_message("[+] Tests successful! :-)");
890 + fd = open("/proc/cmdline", O_RDONLY);
892 + panic("open(/proc/cmdline)");
893 + if (read(fd, cmdline, sizeof(cmdline) - 1) <= 0)
894 + panic("read(/proc/cmdline)");
895 + cmdline[sizeof(cmdline) - 1] = '\0';
896 + for (success_dev = strtok(cmdline, " \n"); success_dev; success_dev = strtok(NULL, " \n")) {
897 + if (strncmp(success_dev, "wg.success=", 11))
899 + memcpy(success_dev + 11 - 5, "/dev/", 5);
900 + success_dev += 11 - 5;
903 + if (!success_dev || !strlen(success_dev))
904 + panic("Unable to find success device");
906 + fd = open(success_dev, O_WRONLY);
908 + panic("open(success_dev)");
909 + if (write(fd, "success\n", 8) != 8)
910 + panic("write(success_dev)");
913 + const char *why = "unknown cause";
916 + if (WIFEXITED(status)) {
918 + what = WEXITSTATUS(status);
919 + } else if (WIFSIGNALED(status)) {
921 + what = WTERMSIG(status);
923 + printf("\x1b[31m\x1b[1m[-] Tests failed with %s %d! \u2639\x1b[0m\n", why, what);
927 +static void ensure_console(void)
929 + for (unsigned int i = 0; i < 1000; ++i) {
930 + int fd = open("/dev/console", O_RDWR);
939 + if (write(1, "\0\0\0\0\n", 5) == 5)
942 + panic("Unable to open console device");
945 +static void clear_leaks(void)
949 + fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
952 + pretty_message("[+] Starting memory leak detection...");
953 + write(fd, "clear\n", 5);
957 +static void check_leaks(void)
961 + fd = open("/sys/kernel/debug/kmemleak", O_WRONLY);
964 + pretty_message("[+] Scanning for memory leaks...");
965 + sleep(2); /* Wait for any grace periods. */
966 + write(fd, "scan\n", 5);
969 + fd = open("/sys/kernel/debug/kmemleak", O_RDONLY);
972 + if (sendfile(1, fd, NULL, 0x7ffff000) > 0)
973 + panic("Memory leaks encountered");
977 +int main(int argc, char *argv[])
982 + mount_filesystems();
992 +++ b/tools/testing/selftests/wireguard/qemu/kernel.config
994 +CONFIG_LOCALVERSION=""
1002 +CONFIG_NAMESPACES=y
1008 +CONFIG_NETFILTER_ADVANCED=y
1009 +CONFIG_NF_CONNTRACK=y
1011 +CONFIG_NETFILTER_XTABLES=y
1012 +CONFIG_NETFILTER_XT_NAT=y
1013 +CONFIG_NETFILTER_XT_MATCH_LENGTH=y
1014 +CONFIG_NF_CONNTRACK_IPV4=y
1015 +CONFIG_NF_NAT_IPV4=y
1016 +CONFIG_IP_NF_IPTABLES=y
1017 +CONFIG_IP_NF_FILTER=y
1019 +CONFIG_IP_ADVANCED_ROUTER=y
1020 +CONFIG_IP_MULTIPLE_TABLES=y
1021 +CONFIG_IPV6_MULTIPLE_TABLES=y
1023 +CONFIG_BINFMT_ELF=y
1024 +CONFIG_BINFMT_SCRIPT=y
1026 +CONFIG_VIRTUALIZATION=y
1027 +CONFIG_HYPERVISOR_GUEST=y
1030 +CONFIG_PARAVIRT_SPINLOCKS=y
1034 +CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y
1040 +CONFIG_SPARSEMEM_VMEMMAP=y
1047 +CONFIG_NO_HZ_IDLE=y
1048 +CONFIG_NO_HZ_FULL=n
1049 +CONFIG_HZ_PERIODIC=n
1050 +CONFIG_HIGH_RES_TIMERS=y
1051 +CONFIG_ARCH_RANDOM=y
1052 +CONFIG_FILE_LOCKING=y
1053 +CONFIG_POSIX_TIMERS=y
1056 +CONFIG_PROC_SYSCTL=y
1059 +CONFIG_CONSOLE_LOGLEVEL_DEFAULT=15
1060 +CONFIG_PRINTK_TIME=y
1061 +CONFIG_BLK_DEV_INITRD=y
1062 +CONFIG_LEGACY_VSYSCALL_NONE=y
1063 +CONFIG_KERNEL_GZIP=y
1064 +CONFIG_PANIC_ON_OOPS=y
1065 +CONFIG_BUG_ON_DATA_CORRUPTION=y
1066 +CONFIG_LOCKUP_DETECTOR=y
1067 +CONFIG_SOFTLOCKUP_DETECTOR=y
1068 +CONFIG_HARDLOCKUP_DETECTOR=y
1069 +CONFIG_WQ_WATCHDOG=y
1070 +CONFIG_DETECT_HUNG_TASK=y
1071 +CONFIG_BOOTPARAM_HARDLOCKUP_PANIC=y
1072 +CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y
1073 +CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y
1074 +CONFIG_PANIC_TIMEOUT=-1
1075 +CONFIG_STACKTRACE=y
1076 +CONFIG_EARLY_PRINTK=y
1077 +CONFIG_GDB_SCRIPTS=y
1079 +CONFIG_WIREGUARD_DEBUG=y