Skip to content

Commit

Permalink
(check) increased usleep tolerance due to some operating systems (issue
Browse files Browse the repository at this point in the history
  • Loading branch information
acid-maker committed Mar 26, 2020
1 parent 008bcc4 commit c4e365a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion buildno.txt
@@ -1 +1 @@
1132
1134
27 changes: 23 additions & 4 deletions mfstests/mfstest_clocks.c
Expand Up @@ -30,37 +30,56 @@

#include "mfstest.h"

uint64_t wallclock_utime(void) {
struct timeval tv;
uint64_t usec;

gettimeofday(&tv,NULL);
usec = tv.tv_sec;
usec *= 1000000;
usec += tv.tv_usec;
return usec;
}

int main(void) {
double st,en;
uint64_t stusec,enusec;
uint64_t stnsec,ennsec;
uint64_t wcstusec,wcenusec;

if (strcmp(monotonic_method(),"time")==0) {
printf("testing classic 'time(NULL)' clock doesn't make sense\n");
return 77;
}

mfstest_init();

mfstest_start(monotonic_clocks);

printf("used method: %s\n",monotonic_method());
st = monotonic_seconds();
stusec = monotonic_useconds();
stnsec = monotonic_nseconds();
wcstusec = wallclock_utime();
portable_usleep(10000);
en = monotonic_seconds();
enusec = monotonic_useconds();
ennsec = monotonic_nseconds();
wcenusec = wallclock_utime();
en -= st;
enusec -= stusec;
ennsec -= stnsec;
printf("second: %.6lf ; %"PRIu64" ; %"PRIu64"\n",en,enusec,ennsec);
wcenusec -= wcstusec;
printf("second: %.6lf ; %"PRIu64" ; %"PRIu64" ; %"PRIu64"\n",en,enusec,ennsec,wcenusec);

mfstest_assert_double_ge(en,0.01);
mfstest_assert_uint64_ge(enusec,10000);
mfstest_assert_uint64_ge(ennsec,10000000);
mfstest_assert_double_lt(en,0.012);
mfstest_assert_uint64_lt(enusec,12000);
mfstest_assert_uint64_lt(ennsec,12000000);
mfstest_assert_uint64_ge(wcenusec,10000);
mfstest_assert_double_lt(en,0.02);
mfstest_assert_uint64_lt(enusec,20000);
mfstest_assert_uint64_lt(ennsec,20000000);
mfstest_assert_uint64_lt(wcenusec,20000);

mfstest_end();
mfstest_return();
Expand Down
25 changes: 17 additions & 8 deletions mfstests/mfstest_delayrun.c
Expand Up @@ -39,6 +39,15 @@ void set_variable(void *arg) {
global_variable = *a;
}

void corrected_usleep(uint64_t us) {
uint64_t st,en;
st = monotonic_useconds();
do {
portable_usleep(100);
en = monotonic_useconds();
} while (st+us>=en);
}

int main(void) {
uint32_t values[7] = {0,1,2,3,4,5,6};
mfstest_init();
Expand All @@ -49,27 +58,27 @@ int main(void) {

global_variable = 0xFFFFFFFF;
delay_run(set_variable,values,10000);
portable_usleep(20000);
corrected_usleep(20000);
mfstest_assert_uint32_eq(global_variable,0);
delay_run(set_variable,values+2,30000);
delay_run(set_variable,values+3,50000);
delay_run(set_variable,values+1,10000);
mfstest_assert_uint32_eq(global_variable,0);
portable_usleep(20000);
corrected_usleep(20000);
mfstest_assert_uint32_eq(global_variable,1);
portable_usleep(20000);
corrected_usleep(20000);
mfstest_assert_uint32_eq(global_variable,2);
portable_usleep(20000);
corrected_usleep(20000);
mfstest_assert_uint32_eq(global_variable,3);
delay_run(set_variable,values+6,60000);
portable_usleep(10000);
corrected_usleep(10000);
delay_run(set_variable,values+4,10000);
portable_usleep(20000);
corrected_usleep(20000);
mfstest_assert_uint32_eq(global_variable,4);
delay_run(set_variable,values+5,10000);
portable_usleep(20000);
corrected_usleep(20000);
mfstest_assert_uint32_eq(global_variable,5);
portable_usleep(20000);
corrected_usleep(20000);
mfstest_assert_uint32_eq(global_variable,6);

delay_term();
Expand Down

0 comments on commit c4e365a

Please sign in to comment.