MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test_sequence

Function test_sequence

test/other/test_itimer.c:77–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75#define ERROR_MARGIN 3
76
77void test_sequence(int which) {
78 int64_t ms_to_sleep = NUM_TIMERS * 100 + 50;
79 printf("test_sequence (sleeping for %lldms)\n", ms_to_sleep);
80 memset(got_alarm, 0, sizeof(got_alarm));
81 // Set a timer to fire every 100ms
82 struct itimerval val;
83 val.it_value.tv_sec = 0;
84 val.it_value.tv_usec = 100 * 1000;
85 val.it_interval.tv_sec = 0;
86 val.it_interval.tv_usec = 100 * 1000;
87 int rtn = setitimer(which, &val, NULL);
88 // Sleep for a little over NUM_TIMERS * 100ms
89 usleep(ms_to_sleep * 1000);
90 printf("got %d alarms\n", got_alarm[which]);
91 // Normally we would expect NUM_TIMERS to fire in this time
92 // but leave some wiggle room for scheduling anomalies.
93 assert(got_alarm[which] > NUM_TIMERS - ERROR_MARGIN);
94 assert(got_alarm[which] < NUM_TIMERS + ERROR_MARGIN);
95 struct itimerval old;
96 val.it_value.tv_sec = 0;
97 val.it_value.tv_usec = 0;
98 rtn = setitimer(ITIMER_REAL, &val, &old);
99}
100
101void set_handlers() {
102 sighandler_t rtn;

Callers 1

mainFunction · 0.85

Calls 5

printfFunction · 0.85
memsetFunction · 0.85
setitimerFunction · 0.85
usleepFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected