From 1ac636ea2836efdb79e4dcbd532c36d6bc49b274 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 10 Jan 2024 17:57:15 +0100 Subject: [PATCH] cpu plugin: Remove tests for `usage_global_ratio` and `usage_global_count`. The functionality is tested in the test cases for `usage_ratio` and `usage_count` and there is no need to test these separately. The opposite: the rest of the CPU plugin only uses `usage_ratio` and `usage_count`, so testing the global variants leaks abstraction. --- src/cpu_test.c | 115 ------------------------------------------------- 1 file changed, 115 deletions(-) diff --git a/src/cpu_test.c b/src/cpu_test.c index 802850b27..c3304f1f5 100644 --- a/src/cpu_test.c +++ b/src/cpu_test.c @@ -254,126 +254,11 @@ DEF_TEST(usage_global_rate) { return 0; } -DEF_TEST(usage_global_ratio) { - usage_t usage = {0}; - - cdtime_t t0 = TIME_T_TO_CDTIME_T(100); - usage_init(&usage, t0); - for (size_t cpu = 0; cpu < 4; cpu++) { - for (state_t s = 0; s < STATE_ACTIVE; s++) { - usage_record(&usage, cpu, s, 1000); - } - } - - cdtime_t t1 = t0 + TIME_T_TO_CDTIME_T(10); - usage_init(&usage, t1); - derive_t global_increment = 0; - for (size_t cpu = 0; cpu < 4; cpu++) { - for (state_t s = 0; s < STATE_ACTIVE; s++) { - derive_t increment = ((derive_t)cpu * STATE_ACTIVE) + ((derive_t)s); - global_increment += increment; - usage_record(&usage, cpu, s, 1000 + increment); - } - } - - derive_t global_active_increment = 0; - for (state_t s = 0; s < STATE_ACTIVE; s++) { - derive_t state_increment = 0; - for (size_t cpu = 0; cpu < 4; cpu++) { - derive_t increment = ((derive_t)cpu * STATE_ACTIVE) + ((derive_t)s); - state_increment += increment; - } - gauge_t want_state_ratio = - ((gauge_t)state_increment) / ((gauge_t)global_increment); - EXPECT_EQ_DOUBLE(want_state_ratio, usage_global_ratio(&usage, s)); - - if (s != STATE_IDLE) { - global_active_increment += state_increment; - } - } - gauge_t want_global_active_ratio = - ((gauge_t)global_active_increment) / ((gauge_t)global_increment); - EXPECT_EQ_DOUBLE(want_global_active_ratio, - usage_global_ratio(&usage, STATE_ACTIVE)); - - EXPECT_EQ_DOUBLE(1.0 - want_global_active_ratio, - usage_global_ratio(&usage, STATE_IDLE)); - - usage_reset(&usage); - return 0; -} - -/* sumup returns the sum of 1 + 2 + ... + n */ -static derive_t sumup(derive_t n) { return n * (n + 1) / 2; } - -DEF_TEST(usage_global_count) { - int ret = 0; - usage_t usage = {0}; -#define CPU_NUM 2 - - cdtime_t t0 = TIME_T_TO_CDTIME_T(100); - usage_init(&usage, t0); - for (size_t cpu = 0; cpu < CPU_NUM; cpu++) { - for (state_t s = 0; s < STATE_ACTIVE; s++) { - usage_record(&usage, cpu, s, 1000); - } - } - usage_finalize(&usage); - - cdtime_t interval = TIME_T_TO_CDTIME_T(300); - - cdtime_t t1 = t0 + interval; - usage_init(&usage, t1); - for (size_t cpu = 0; cpu < CPU_NUM; cpu++) { - for (state_t s = 0; s < STATE_ACTIVE; s++) { - derive_t increment = ((derive_t)cpu * STATE_ACTIVE) + ((derive_t)s); - usage_record(&usage, cpu, s, 1000 + increment); - } - } - - derive_t cpu_increment[CPU_NUM] = { - sumup(10), - sumup(21) - sumup(10), - }; - - gauge_t state_ratio[STATE_MAX] = {0}; - for (size_t cpu = 0; cpu < CPU_NUM; cpu++) { - for (state_t s = 0; s < STATE_ACTIVE; s++) { - derive_t increment = ((derive_t)cpu * STATE_ACTIVE) + ((derive_t)s); - gauge_t ratio = ((gauge_t)increment) / ((gauge_t)cpu_increment[cpu]); - - state_ratio[s] += ratio; - if (s != STATE_IDLE) { - state_ratio[STATE_ACTIVE] += ratio; - } - } - } - - for (state_t s = 0; s < STATE_MAX; s++) { - gauge_t want_time = - 1000000.0 * CDTIME_T_TO_DOUBLE(interval) * state_ratio[s]; - bool ok = expect_usage_count((derive_t)want_time, - usage_global_count(&usage, s), SIZE_MAX, s); - ret = ret || !ok; - } - - gauge_t sum_ratio = 0; - for (state_t s = 0; s < STATE_ACTIVE; s++) { - sum_ratio += state_ratio[s]; - } - EXPECT_EQ_DOUBLE(CPU_NUM, sum_ratio); - - usage_reset(&usage); - return ret; -} - int main(void) { RUN_TEST(usage_rate); RUN_TEST(usage_ratio); RUN_TEST(usage_count); RUN_TEST(usage_global_rate); - RUN_TEST(usage_global_ratio); - RUN_TEST(usage_global_count); END_TEST; } -- 2.47.2