]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-async.c
travis: use UBSan checks from OSS-Fuzz
[thirdparty/systemd.git] / src / test / test-async.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <fcntl.h>
4 #include <unistd.h>
5
6 #include "async.h"
7 #include "macro.h"
8 #include "tmpfile-util.h"
9 #include "util.h"
10
11 static bool test_async = false;
12
13 static void *async_func(void *arg) {
14 test_async = true;
15
16 return NULL;
17 }
18
19 int main(int argc, char *argv[]) {
20 int fd;
21 char name[] = "/tmp/test-asynchronous_close.XXXXXX";
22
23 fd = mkostemp_safe(name);
24 assert_se(fd >= 0);
25 asynchronous_close(fd);
26
27 assert_se(asynchronous_job(async_func, NULL) >= 0);
28
29 assert_se(asynchronous_sync(NULL) >= 0);
30
31 sleep(1);
32
33 assert_se(fcntl(fd, F_GETFD) == -1);
34 assert_se(test_async);
35
36 (void) unlink(name);
37
38 return 0;
39 }