On Mon, 19 Feb 2024 at 20:18, Arnaud Minier
<arnaud.min...@telecom-paris.fr> wrote:
>
> Tests:
> - the ability to change the sysclk of the device
> - the ability to enable/disable/configure the PLLs
> - if the clock multiplexers work
> - the register flags and the generation of irqs
>
> Signed-off-by: Arnaud Minier <arnaud.min...@telecom-paris.fr>
> Signed-off-by: Inès Varhol <ines.var...@telecom-paris.fr>
> Acked-by: Thomas Huth <th...@redhat.com>


> +static bool qts_wait_for_flag(QTestState *qts, uint32_t event_addr,
> +                              uint32_t flag, uint32_t value)
> +{
> +    /* Wait at most 5 seconds */
> +    for (int i = 0; i < 5000; i++) {
> +        if ((qtest_readl(qts, event_addr) & flag) == value) {
> +            return true;
> +        }
> +        g_usleep(1000);
> +    }
> +
> +    return false;
> +}

Tests using the qtest accelerator shouldn't wait for real
wall time to pass. The system under the test does not actually
run, it only moves forward the system clock when the test
asks it to do so by calling clock_step(). (We have only a few
tests under tests/qtest which need to really run guest code
and so can't use the qtest accelerator. Those may have a reason
for wallclock timeouts, but need to take care because the timeout
that works fine on a fast developer workstation may be insufficient
on a slow heavily loaded server running a CI job...)

Either the device being tested here will immediately
set the flag we're waiting for here, in which case we don't
need to do this loop at all, or else it will only set the
flag after some amount of simulation time has passed, in which
case the loop will always time out because simulation time won't
pass until you call clock_step().

Most device tests don't need to call clock_step(), because we tend
to write our device models so that things that take time on real
hardware (e.g. waiting for a PLL to settle) happen instantaneously.
Timer device tests are the ones that usually do want to see what
happens after simulation time has passed: you can look at
tests/qtest/cmsdk-apb-timer-test.c for a simple example of that.

thanks
-- PMM

Reply via email to