]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-ratelimit.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / test / test-ratelimit.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
e80cde5e
RC
2/***
3 This file is part of systemd
4
5 Copyright 2014 Ronny Chevalier
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
21#include <unistd.h>
22
cf0fbc49 23#include "macro.h"
e80cde5e
RC
24#include "ratelimit.h"
25#include "time-util.h"
e80cde5e
RC
26
27static void test_ratelimit_test(void) {
28 int i;
29 RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
30
1f6b4113 31 for (i = 0; i < 10; i++)
e80cde5e 32 assert_se(ratelimit_test(&ratelimit));
e80cde5e
RC
33 assert_se(!ratelimit_test(&ratelimit));
34 sleep(1);
1f6b4113 35 for (i = 0; i < 10; i++)
e80cde5e 36 assert_se(ratelimit_test(&ratelimit));
e80cde5e
RC
37
38 RATELIMIT_INIT(ratelimit, 0, 10);
1f6b4113 39 for (i = 0; i < 10000; i++)
e80cde5e 40 assert_se(ratelimit_test(&ratelimit));
e80cde5e
RC
41}
42
43int main(int argc, char *argv[]) {
44 test_ratelimit_test();
45
46 return 0;
47}