2 #include "../logger/qos.h"
4 /* Some proportional modes look at the cached total log count, which
5 * is cached in the metrics struct which we don't want to fill normally,
6 * so we just implement this function instead of linking to the actual
7 * metrics implementation. */
9 int metrics_get_total(const struct metrics *m)
14 void test_proportional_raw(void)
16 const qos_distribution_func qos_distribution_proportional_raw = qos_get_distribution_func_by_name("proportional_raw");
17 assert(qos_distribution_proportional_raw);
19 struct metrics_pid_aggr_info i1 [] =
25 total_logs = 8 + 12 + 4 + 16;
27 qos_distribution_proportional_raw(&(struct qos_module) { .max_throughput = 200 }, i1, 4);
28 assert(i1[0].count == 40);
29 assert(i1[1].count == 60);
30 assert(i1[2].count == 20);
31 assert(i1[3].count == 80);
36 const qos_distribution_func qos_distribution_equal = qos_get_distribution_func_by_name("equal");
37 assert(qos_distribution_equal);
39 struct metrics_pid_aggr_info i1 [] =
45 total_logs = 1 + 66 + 17 + 42;
47 qos_distribution_equal(&(struct qos_module) { .max_throughput = 200 }, i1, 4);
48 assert(i1[0].count == 50);
49 assert(i1[1].count == 50);
50 assert(i1[2].count == 50);
51 assert(i1[3].count == 50);
54 void test_equal_dual(void)
56 const qos_distribution_func qos_distribution_equal_dual = qos_get_distribution_func_by_name("equal_dual");
57 assert(qos_distribution_equal_dual);
59 struct metrics_pid_aggr_info i1 [] =
64 total_logs = 20 + 85 + 120;
66 qos_distribution_equal_dual(&(struct qos_module) { .max_throughput = 200 }, i1, 3);
67 assert(i1[0].count == -1); // 20 < 200/3
68 assert(i1[1].count == 90); // 85 >= 200/3, 90 == (200-20)/2
69 assert(i1[2].count == 90); // 120 >= 200/3, 90 == (200-20)/2
72 void test_equal_multi(void)
74 const qos_distribution_func qos_distribution_equal_multi = qos_get_distribution_func_by_name("equal_multi");
75 assert(qos_distribution_equal_multi);
77 struct metrics_pid_aggr_info i1 [] =
82 total_logs = 30 + 95 + 120;
84 qos_distribution_equal_multi(&(struct qos_module) { .max_throughput = 200 }, i1, 3);
85 assert(i1[0].count == -1); // 30 < 200/3
86 assert(i1[1].count == 85); // 95 >= 200/3, and 95 >= (200-30)/2
87 assert(i1[2].count == 85); // 120 >= 200/3, and 120 >= (200-30)/2
90 struct metrics_pid_aggr_info i2 [] =
95 total_logs = 20 + 85 + 120;
97 qos_distribution_equal_multi(&(struct qos_module) { .max_throughput = 200 }, i2, 3);
98 assert(i2[0].count == -1); // 20 < 200/3
99 assert(i2[1].count == -1); // 85 >= 200/3, but 85 < (200-20)/2
100 assert(i2[2].count == 95); // 120 >= 200/3, and 120 >= (200-20)/2, and 120 >= (200-20-85)/1
103 void test_proportional_talmud(void)
105 const qos_distribution_func qos_distribution_proportional_talmud = qos_get_distribution_func_by_name("proportional_talmud");
106 assert(qos_distribution_proportional_talmud);
108 struct metrics_pid_aggr_info i1 [] =
112 total_logs = 50 + 100;
114 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 100 }, i1, 2);
115 assert(i1[0].count == 25);
116 assert(i1[1].count == 75);
118 struct metrics_pid_aggr_info i2 [] =
123 total_logs = 100 + 200 + 300;
125 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 100 }, i2, 3);
126 assert(i2[0].count == 33);
127 assert(i2[1].count == 33);
128 assert(i2[2].count == 33);
130 struct metrics_pid_aggr_info i3 [] =
135 total_logs = 100 + 200 + 300;
137 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 200 }, i3, 3);
138 assert(i3[0].count == 50);
139 assert(i3[1].count == 75);
140 assert(i3[2].count == 75);
142 struct metrics_pid_aggr_info i4 [] =
147 total_logs = 100 + 200 + 300;
149 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 300 }, i4, 3);
150 assert(i4[0].count == 50);
151 assert(i4[1].count == 100);
152 assert(i4[2].count == 150);
154 struct metrics_pid_aggr_info i5 [] =
159 total_logs = 100 + 200 + 300;
161 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 400 }, i5, 3);
162 assert(i5[0].count == 50);
163 assert(i5[1].count == 125);
164 assert(i5[2].count == 225);
166 struct metrics_pid_aggr_info i6 [] =
171 total_logs = 10 + 20 + 30;
173 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 100 }, i6, 3);
174 assert(i6[0].count == 10);
175 assert(i6[1].count == 20);
176 assert(i6[2].count == 30);
178 struct metrics_pid_aggr_info i7 [] =
183 total_logs = 100 + 200 + 300;
185 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 500 }, i7, 3);
186 assert(i7[0].count == 67);
187 assert(i7[1].count == 167);
188 assert(i7[2].count == 267);
190 struct metrics_pid_aggr_info i8 [] =
196 total_logs = 100 + 200 + 300 + 400;
198 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 700 }, i8, 4);
199 assert(i8[0].count == 50);
200 assert(i8[1].count == 117);
201 assert(i8[2].count == 217);
202 assert(i8[3].count == 317);
207 test_proportional_raw();
211 test_proportional_talmud();