summaryrefslogtreecommitdiffstats
path: root/third_party/rust/lucet-wasi-wasmsbx/tests/guests/gettimeofday.c
blob: f9e8d5a81198e70d063bf5b40796bc239e82a901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <assert.h>
#include <stdlib.h>
#include <sys/time.h>

int main()
{
    struct timeval tv1;
    gettimeofday(&tv1, NULL);

    for (int i = 0; i < 1000; i++) {
    }

    struct timeval tv2;
    gettimeofday(&tv2, NULL);

    // assert that some time has passed
    long long s1  = tv1.tv_sec;
    long long us1 = tv1.tv_usec;
    long long s2  = tv2.tv_sec;
    long long us2 = tv2.tv_usec;
    assert(s1 <= s2);
    if (s1 == s2) {
        // strictly less than, so the timestamps can't be equal
        assert(us1 < us2);
    }
}