mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-03-27 07:58:47 -04:00
tests: add test_usleep and test_sleep functions
The former one was already used in tests, but was private. These functions can be shared across the tests, so make them public. Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
parent
7bf8049c48
commit
6ebe55060e
3 changed files with 44 additions and 15 deletions
|
|
@ -25,6 +25,7 @@
|
|||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "test-runner.h"
|
||||
|
||||
|
|
@ -62,3 +63,34 @@ exec_fd_leak_check(int nr_expected_fds)
|
|||
execl(exe, exe, number, (char *)NULL);
|
||||
assert(0 && "execing fd leak checker failed");
|
||||
}
|
||||
|
||||
#define USEC_TO_NSEC(n) (1000 * (n))
|
||||
|
||||
/* our implementation of usleep and sleep functions that are safe to use with
|
||||
* timeouts (timeouts are implemented using alarm(), so it is not safe use
|
||||
* usleep and sleep. See man pages of these functions)
|
||||
*/
|
||||
void
|
||||
test_usleep(useconds_t usec)
|
||||
{
|
||||
struct timespec ts = {
|
||||
.tv_sec = 0,
|
||||
.tv_nsec = USEC_TO_NSEC(usec)
|
||||
};
|
||||
|
||||
assert(nanosleep(&ts, NULL) == 0);
|
||||
}
|
||||
|
||||
/* we must write the whole function instead of
|
||||
* wrapping test_usleep, because useconds_t may not
|
||||
* be able to contain such a big number of microseconds */
|
||||
void
|
||||
test_sleep(unsigned int sec)
|
||||
{
|
||||
struct timespec ts = {
|
||||
.tv_sec = sec,
|
||||
.tv_nsec = 0
|
||||
};
|
||||
|
||||
assert(nanosleep(&ts, NULL) == 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue