From ccbd64ef1349cf676ab6d514527be792af0b2a49 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Sat, 15 Mar 2025 20:56:59 +0100 Subject: [PATCH] support/testing: set date in emulated machine When time comes to check certificates, the date and time in the emulated machine should be close enough to the actual values, so that certificate validity can be checked. Some Qemu machines have an RTC (e.g. arm vexpress-a9 has a pl031), and the kernel needs a driver for those RTC. It is not guaranteed that the machine used for a test meets those two conditions; in such a case, the time in the machine starts way back in the past (1970-01-01T00:00:00Z on sysv, or the release date of systemd). This is the case with the default kernel, so such tests do not have the proper time. Set the date to the date of the host system. This is going to be accurate to the second, which is, by far, enough for our purpose. To avoid having to consider what combination of emulated machine and kernel configuration are being used, we always set the date, as this is a generic step that should be done by the infra (like login in as root is). The Emulator() class doesn't inherit from unittest.TestCase, so we can't call any of the usual self.assertXXX() methods; instead, we just raise a standard exception, like is done a few lines above to detect the login prompt. Signed-off-by: Yann E. MORIN Cc: Ricardo Martincoski Cc: Thomas Petazzoni Signed-off-by: Julien Olivain (cherry picked from commit cf8641b73e7f1577637bfef0ece78dd519b25d19) --- support/testing/infra/emulator.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/support/testing/infra/emulator.py b/support/testing/infra/emulator.py index ef5be2a19e..9be1143944 100644 --- a/support/testing/infra/emulator.py +++ b/support/testing/infra/emulator.py @@ -5,6 +5,7 @@ import os import pexpect import pexpect.replwrap +import time import infra @@ -152,6 +153,10 @@ class Emulator(object): self.connect_shell() + output, exit_code = self.run(f"date @{int(time.time())}") + if exit_code: + raise SystemError("Cannot set date in virtual machine") + def connect_shell(self): extra_init_cmd = " && ".join([ 'export PAGER=cat',