Branch data Line data Source code
1 : : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : :
3 : : #include "cgroup.h"
4 : : #include "log.h"
5 : :
6 : 4 : static void test_cgroup_cpu_adjust_period(void) {
7 [ + - ]: 4 : log_info("/* %s */", __func__);
8 : :
9 : : /* Period 1ms, quota 40% -> Period 2.5ms */
10 [ - + ]: 4 : assert_se(2500 == cgroup_cpu_adjust_period(USEC_PER_MSEC, 400 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
11 : : /* Period 10ms, quota 10% -> keep. */
12 [ - + ]: 4 : assert_se(10 * USEC_PER_MSEC == cgroup_cpu_adjust_period(10 * USEC_PER_MSEC, 100 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
13 : : /* Period 1ms, quota 1000% -> keep. */
14 [ - + ]: 4 : assert_se(USEC_PER_MSEC == cgroup_cpu_adjust_period(USEC_PER_MSEC, 10000 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
15 : : /* Period 100ms, quota 30% -> keep. */
16 [ - + ]: 4 : assert_se(100 * USEC_PER_MSEC == cgroup_cpu_adjust_period(100 * USEC_PER_MSEC, 300 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
17 : : /* Period 5s, quota 40% -> adjust to 1s. */
18 [ - + ]: 4 : assert_se(USEC_PER_SEC == cgroup_cpu_adjust_period(5 * USEC_PER_SEC, 400 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
19 : : /* Period 2s, quota 250% -> adjust to 1s. */
20 [ - + ]: 4 : assert_se(USEC_PER_SEC == cgroup_cpu_adjust_period(2 * USEC_PER_SEC, 2500 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
21 : : /* Period 10us, quota 5,000,000% -> adjust to 1ms. */
22 [ - + ]: 4 : assert_se(USEC_PER_MSEC == cgroup_cpu_adjust_period(10, 50000000 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
23 : : /* Period 10ms, quota 50,000% -> keep. */
24 [ - + ]: 4 : assert_se(10 * USEC_PER_MSEC == cgroup_cpu_adjust_period(10 * USEC_PER_MSEC, 500000 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
25 : : /* Period 10ms, quota 1% -> adjust to 100ms. */
26 [ - + ]: 4 : assert_se(100 * USEC_PER_MSEC == cgroup_cpu_adjust_period(10 * USEC_PER_MSEC, 10 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
27 : : /* Period 10ms, quota .001% -> adjust to 1s. */
28 [ - + ]: 4 : assert_se(1 * USEC_PER_SEC == cgroup_cpu_adjust_period(10 * USEC_PER_MSEC, 10, USEC_PER_MSEC, USEC_PER_SEC));
29 : : /* Period 0ms, quota 200% -> adjust to 1ms. */
30 [ - + ]: 4 : assert_se(1 * USEC_PER_MSEC == cgroup_cpu_adjust_period(0, 2 * USEC_PER_SEC, USEC_PER_MSEC, USEC_PER_SEC));
31 : : /* Period 0ms, quota 40% -> adjust to 2.5ms. */
32 [ - + ]: 4 : assert_se(2500 == cgroup_cpu_adjust_period(0, 400 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
33 : 4 : }
34 : :
35 : 4 : int main(int argc, char *argv[]) {
36 : 4 : test_cgroup_cpu_adjust_period();
37 : 4 : return 0;
38 : : }
|