]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-ratelimit.c
tree-wide: drop 'This file is part of systemd' blurb
[thirdparty/systemd.git] / src / test / test-ratelimit.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2014 Ronny Chevalier
4 ***/
5
6 #include <unistd.h>
7
8 #include "macro.h"
9 #include "ratelimit.h"
10 #include "time-util.h"
11
12 static void test_ratelimit_below(void) {
13 int i;
14 RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
15
16 for (i = 0; i < 10; i++)
17 assert_se(ratelimit_below(&ratelimit));
18 assert_se(!ratelimit_below(&ratelimit));
19 sleep(1);
20 for (i = 0; i < 10; i++)
21 assert_se(ratelimit_below(&ratelimit));
22
23 RATELIMIT_INIT(ratelimit, 0, 10);
24 for (i = 0; i < 10000; i++)
25 assert_se(ratelimit_below(&ratelimit));
26 }
27
28 int main(int argc, char *argv[]) {
29 test_ratelimit_below();
30
31 return 0;
32 }