Skip to content

Commit 829be05

Browse files
zx2c4kuba-moo
authored andcommitted
wireguard: selftests: set fake real time in init
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 <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent faa4e04 commit 829be05

File tree

8 files changed

+18
-0
lines changed

8 files changed

+18
-0
lines changed

tools/testing/selftests/wireguard/qemu/arch/arm.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
77
CONFIG_VIRTIO_MENU=y
88
CONFIG_VIRTIO_MMIO=y
99
CONFIG_VIRTIO_CONSOLE=y
10+
CONFIG_COMPAT_32BIT_TIME=y
1011
CONFIG_CMDLINE_BOOL=y
1112
CONFIG_CMDLINE="console=ttyAMA0 wg.success=vport0p1 panic_on_warn=1"
1213
CONFIG_FRAME_WARN=1024

tools/testing/selftests/wireguard/qemu/arch/armeb.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
77
CONFIG_VIRTIO_MENU=y
88
CONFIG_VIRTIO_MMIO=y
99
CONFIG_VIRTIO_CONSOLE=y
10+
CONFIG_COMPAT_32BIT_TIME=y
1011
CONFIG_CMDLINE_BOOL=y
1112
CONFIG_CMDLINE="console=ttyAMA0 wg.success=vport0p1 panic_on_warn=1"
1213
CONFIG_CPU_BIG_ENDIAN=y
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG_ACPI=y
22
CONFIG_SERIAL_8250=y
33
CONFIG_SERIAL_8250_CONSOLE=y
4+
CONFIG_COMPAT_32BIT_TIME=y
45
CONFIG_CMDLINE_BOOL=y
56
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
67
CONFIG_FRAME_WARN=1024

tools/testing/selftests/wireguard/qemu/arch/m68k.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ CONFIG_MAC=y
55
CONFIG_SERIAL_PMACZILOG=y
66
CONFIG_SERIAL_PMACZILOG_TTYS=y
77
CONFIG_SERIAL_PMACZILOG_CONSOLE=y
8+
CONFIG_COMPAT_32BIT_TIME=y
89
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
910
CONFIG_FRAME_WARN=1024

tools/testing/selftests/wireguard/qemu/arch/mips.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CONFIG_POWER_RESET=y
66
CONFIG_POWER_RESET_SYSCON=y
77
CONFIG_SERIAL_8250=y
88
CONFIG_SERIAL_8250_CONSOLE=y
9+
CONFIG_COMPAT_32BIT_TIME=y
910
CONFIG_CMDLINE_BOOL=y
1011
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
1112
CONFIG_FRAME_WARN=1024

tools/testing/selftests/wireguard/qemu/arch/mipsel.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CONFIG_POWER_RESET=y
77
CONFIG_POWER_RESET_SYSCON=y
88
CONFIG_SERIAL_8250=y
99
CONFIG_SERIAL_8250_CONSOLE=y
10+
CONFIG_COMPAT_32BIT_TIME=y
1011
CONFIG_CMDLINE_BOOL=y
1112
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"
1213
CONFIG_FRAME_WARN=1024

tools/testing/selftests/wireguard/qemu/arch/powerpc.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CONFIG_PPC_85xx=y
44
CONFIG_PHYS_64BIT=y
55
CONFIG_SERIAL_8250=y
66
CONFIG_SERIAL_8250_CONSOLE=y
7+
CONFIG_COMPAT_32BIT_TIME=y
78
CONFIG_MATH_EMULATION=y
89
CONFIG_CMDLINE_BOOL=y
910
CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1 panic_on_warn=1"

tools/testing/selftests/wireguard/qemu/init.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <stdlib.h>
1212
#include <stdbool.h>
1313
#include <fcntl.h>
14+
#include <time.h>
1415
#include <sys/wait.h>
1516
#include <sys/mount.h>
1617
#include <sys/stat.h>
@@ -70,6 +71,15 @@ static void seed_rng(void)
7071
close(fd);
7172
}
7273

74+
static void set_time(void)
75+
{
76+
if (time(NULL))
77+
return;
78+
pretty_message("[+] Setting fake time...");
79+
if (stime(&(time_t){1433512680}) < 0)
80+
panic("settimeofday()");
81+
}
82+
7383
static void mount_filesystems(void)
7484
{
7585
pretty_message("[+] Mounting filesystems...");
@@ -259,6 +269,7 @@ int main(int argc, char *argv[])
259269
print_banner();
260270
mount_filesystems();
261271
seed_rng();
272+
set_time();
262273
kmod_selftests();
263274
enable_logging();
264275
clear_leaks();

0 commit comments

Comments
 (0)