Skip to content

Commit

Permalink
wireguard: selftests: set fake real time in init
Browse files Browse the repository at this point in the history
Not all platforms have an RTC, and rather than trying to force one into
each, it's much easier to just set a fixed time. This is necessary
because WireGuard's latest handshakes parameter is returned in wallclock
time, and if the system time isn't set, and the system is really fast,
then this returns 0, which trips the test.

Turning this on requires setting CONFIG_COMPAT_32BIT_TIME=y, as musl
doesn't support settimeofday without it.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
zx2c4 authored and kuba-moo committed Jul 7, 2022
1 parent faa4e04 commit 829be05
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/wireguard/qemu/arch/arm.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
CONFIG_VIRTIO_MENU=y
CONFIG_VIRTIO_MMIO=y
CONFIG_VIRTIO_CONSOLE=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="console=ttyAMA0 wg.success=vport0p1 panic_on_warn=1"
CONFIG_FRAME_WARN=1024
1 change: 1 addition & 0 deletions tools/testing/selftests/wireguard/qemu/arch/armeb.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
CONFIG_VIRTIO_MENU=y
CONFIG_VIRTIO_MMIO=y
CONFIG_VIRTIO_CONSOLE=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="console=ttyAMA0 wg.success=vport0p1 panic_on_warn=1"
CONFIG_CPU_BIG_ENDIAN=y
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/wireguard/qemu/arch/i686.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CONFIG_ACPI=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
CONFIG_FRAME_WARN=1024
1 change: 1 addition & 0 deletions tools/testing/selftests/wireguard/qemu/arch/m68k.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ CONFIG_MAC=y
CONFIG_SERIAL_PMACZILOG=y
CONFIG_SERIAL_PMACZILOG_TTYS=y
CONFIG_SERIAL_PMACZILOG_CONSOLE=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
CONFIG_FRAME_WARN=1024
1 change: 1 addition & 0 deletions tools/testing/selftests/wireguard/qemu/arch/mips.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_SYSCON=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
CONFIG_FRAME_WARN=1024
1 change: 1 addition & 0 deletions tools/testing/selftests/wireguard/qemu/arch/mipsel.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONFIG_POWER_RESET=y
CONFIG_POWER_RESET_SYSCON=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
CONFIG_FRAME_WARN=1024
1 change: 1 addition & 0 deletions tools/testing/selftests/wireguard/qemu/arch/powerpc.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CONFIG_PPC_85xx=y
CONFIG_PHYS_64BIT=y
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_COMPAT_32BIT_TIME=y
CONFIG_MATH_EMULATION=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
Expand Down
11 changes: 11 additions & 0 deletions tools/testing/selftests/wireguard/qemu/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <fcntl.h>
#include <time.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -70,6 +71,15 @@ static void seed_rng(void)
close(fd);
}

static void set_time(void)
{
if (time(NULL))
return;
pretty_message("[+] Setting fake time...");
if (stime(&(time_t){1433512680}) < 0)
panic("settimeofday()");
}

static void mount_filesystems(void)
{
pretty_message("[+] Mounting filesystems...");
Expand Down Expand Up @@ -259,6 +269,7 @@ int main(int argc, char *argv[])
print_banner();
mount_filesystems();
seed_rng();
set_time();
kmod_selftests();
enable_logging();
clear_leaks();
Expand Down

0 comments on commit 829be05

Please sign in to comment.