#include #include int main(void) { struct timeval tv, old_tv; long count = 0; gettimeofday(&old_tv, NULL); while (1) { gettimeofday(&tv, NULL); if (((tv.tv_sec == old_tv.tv_sec) && (tv.tv_usec < old_tv.tv_usec)) || (tv.tv_sec < old_tv.tv_sec)) { printf("backwards\n"); printf("old %d.%06d new %d.%06d\n", old_tv.tv_sec, old_tv.tv_usec, tv.tv_sec, tv.tv_usec); printf("ok count: %ld\n", count); } else { if ( (tv.tv_sec == old_tv.tv_sec) && (tv.tv_usec - old_tv.tv_usec > 9900) ) { printf("You only have 10ms clock resolution. No point of testing.\n"); exit(0); } count++; } old_tv = tv; } return 0; }