0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-28 14:33:11 +01:00
nodejs/test/wasi/c/gettimeofday.c
cjihrig 09b1228c3a
wasi: introduce initial WASI support
Co-authored-by: Gus Caplan <me@gus.host>
Co-authored-by: Daniel Bevenius <daniel.bevenius@gmail.com>
Co-authored-by: Jiawen Geng <technicalcute@gmail.com>
Co-authored-by: Tobias Nießen <tniessen@tnie.de>
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/30258
Refs: https://github.com/nodejs/node/pull/27850
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2019-11-30 18:06:39 +01:00

36 lines
619 B
C

#include <assert.h>
#include <stdlib.h>
#include <sys/time.h>
int main() {
struct timeval tv1;
struct timeval tv2;
long long s1;
long long us1;
long long s2;
long long us2;
int r;
int success = 0;
r = gettimeofday(&tv1, NULL);
assert(r == 0);
s1 = tv1.tv_sec;
us1 = tv1.tv_usec;
for (int i = 0; i < 10000; i++) {
r = gettimeofday(&tv2, NULL);
assert(r == 0);
s2 = tv2.tv_sec;
us2 = tv2.tv_usec;
assert(s1 <= s2);
// Verify that some time has passed.
if (s2 > s1 || (s2 == s1 && us2 > us1)) {
success = 1;
break;
}
}
assert(success == 1);
}