summaryrefslogtreecommitdiffhomepage
path: root/tools/testing/selftests/wireguard/qemu/init.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2022-07-07 02:31:52 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2022-07-07 13:26:46 +0200
commitd0d610c254ea3e8b0ced33a2853efb3a2e8ee9f9 (patch)
tree926adf14b95b47255a10eeb90f5e698de34c8ed2 /tools/testing/selftests/wireguard/qemu/init.c
parentb33b459a4c28a40e53c812afd8e40caff2e436ed (diff)
downloadwireguard-linux-d0d610c254ea3e8b0ced33a2853efb3a2e8ee9f9.tar.xz
wireguard-linux-d0d610c254ea3e8b0ced33a2853efb3a2e8ee9f9.zip
wireguard: selftests: set fake real time in init
commit 829be057dbc1e71383b8d7de8edb31dcf07b4aa0 upstream. 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> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tools/testing/selftests/wireguard/qemu/init.c')
-rw-r--r--tools/testing/selftests/wireguard/qemu/init.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/testing/selftests/wireguard/qemu/init.c b/tools/testing/selftests/wireguard/qemu/init.c
index 2a0f48fac925..542c34b00eb0 100644
--- a/tools/testing/selftests/wireguard/qemu/init.c
+++ b/tools/testing/selftests/wireguard/qemu/init.c
@@ -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>
@@ -67,6 +68,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...");
@@ -256,6 +266,7 @@ int main(int argc, char *argv[])
print_banner();
mount_filesystems();
seed_rng();
+ set_time();
kmod_selftests();
enable_logging();
clear_leaks();