[Buildroot] [PATCH 01/14 v4] support/testing: set date in emulated machine

Arnout Vandecappelle arnout at rnout.be
Wed Apr 16 21:07:43 UTC 2025


On 15/03/2025 20:56, Yann E. MORIN wrote:
> 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 <yann.morin.1998 at free.fr>
> Cc: Ricardo Martincoski <ricardo.martincoski at datacom.com.br>
> Cc: Thomas Petazzoni <thomas.petazzoni at bootlin.com>

  Applied to 2025.02.x, thanks.

  Regards,
  Arnout

>
> ---
> Changes v1 -> v2:
>    - catch failure to set the date
>
> Changes v3 -> v4:
>    - extend the rationale in the commit log  (Julien)
> ---
>   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',


More information about the buildroot mailing list