]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
cpu plugin: Remove tests for `usage_global_ratio` and `usage_global_count`.
authorFlorian Forster <octo@collectd.org>
Wed, 10 Jan 2024 16:57:15 +0000 (17:57 +0100)
committerFlorian Forster <octo@collectd.org>
Mon, 22 Jan 2024 15:07:57 +0000 (16:07 +0100)
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

index 802850b27084e0c49e8efe97cf03b191f72ee427..c3304f1f580f73bf9994a26ca81faa0bb5e4abc0 100644 (file)
@@ -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;
 }