|
Packit |
6bd9ab |
/*
|
|
Packit |
6bd9ab |
test_tio_timeout.c - tests for tio deadline calculations
|
|
Packit |
6bd9ab |
This file is part of the nss-pam-ldapd library.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
Copyright (C) 2013 Arthur de Jong
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is free software; you can redistribute it and/or
|
|
Packit |
6bd9ab |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License as published by the Free Software Foundation; either
|
|
Packit |
6bd9ab |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
This library is distributed in the hope that it will be useful,
|
|
Packit |
6bd9ab |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6bd9ab |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6bd9ab |
Lesser General Public License for more details.
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6bd9ab |
License along with this library; if not, write to the Free Software
|
|
Packit |
6bd9ab |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6bd9ab |
02110-1301 USA
|
|
Packit |
6bd9ab |
*/
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
/* we include the source because we want to test static methods */
|
|
Packit |
6bd9ab |
#include "../common/tio.c"
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
#include <assert.h>
|
|
Packit |
6bd9ab |
|
|
Packit |
6bd9ab |
int main(int UNUSED(argc), char UNUSED(*argv[]))
|
|
Packit |
6bd9ab |
{
|
|
Packit |
6bd9ab |
struct timespec deadline = {0, 0};
|
|
Packit |
6bd9ab |
int timeout = 100 * 1000;
|
|
Packit |
6bd9ab |
int sleeptime = 1000;
|
|
Packit |
6bd9ab |
int low = -100;
|
|
Packit |
6bd9ab |
int high = 200;
|
|
Packit |
6bd9ab |
int res;
|
|
Packit |
6bd9ab |
int ok;
|
|
Packit |
6bd9ab |
/* initialise deadline */
|
|
Packit |
6bd9ab |
assert(tio_time_remaining(&deadline, timeout) == timeout);
|
|
Packit |
6bd9ab |
/* wait one second */
|
|
Packit |
6bd9ab |
sleep(sleeptime / 1000);
|
|
Packit |
6bd9ab |
/* re-calculate the deadline */
|
|
Packit |
6bd9ab |
res = tio_time_remaining(&deadline, timeout);
|
|
Packit |
6bd9ab |
/* it should be timeout - sleeptime */
|
|
Packit |
6bd9ab |
res = timeout - sleeptime - res;
|
|
Packit |
6bd9ab |
ok = (res > low) && (res < high);
|
|
Packit |
6bd9ab |
printf("%s: %d msec difference (%swithin %d...%d msec)\n",
|
|
Packit |
6bd9ab |
ok ? "OK" : "FAIL", res, ok ? "" : "NOT ",
|
|
Packit |
6bd9ab |
low, high);
|
|
Packit |
6bd9ab |
return !ok;
|
|
Packit |
6bd9ab |
}
|