Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : 3 : #include "cgroup.h" 4 : #include "log.h" 5 : 6 1 : static void test_cgroup_cpu_adjust_period(void) { 7 1 : log_info("/* %s */", __func__); 8 : 9 : /* Period 1ms, quota 40% -> Period 2.5ms */ 10 1 : 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 1 : 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 1 : 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 1 : 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 1 : 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 1 : 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 1 : 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 1 : 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 1 : 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 1 : 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 1 : 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 1 : assert_se(2500 == cgroup_cpu_adjust_period(0, 400 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC)); 33 1 : } 34 : 35 1 : int main(int argc, char *argv[]) { 36 1 : test_cgroup_cpu_adjust_period(); 37 1 : return 0; 38 : }