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()
16 struct metrics_pid_aggr_info i1 [] =
22 total_logs = 8 + 12 + 4 + 16;
24 qos_distribution_proportional_raw(&(struct qos_module) { .max_throughput = 200 }, i1, 4);
25 assert(i1[0].count == 40);
26 assert(i1[1].count == 60);
27 assert(i1[2].count == 20);
28 assert(i1[3].count == 80);
33 struct metrics_pid_aggr_info i1 [] =
39 total_logs = 1 + 66 + 17 + 42;
41 qos_distribution_equal(&(struct qos_module) { .max_throughput = 200 }, i1, 4);
42 assert(i1[0].count == 50);
43 assert(i1[1].count == 50);
44 assert(i1[2].count == 50);
45 assert(i1[3].count == 50);
48 void test_equal_dual()
50 struct metrics_pid_aggr_info i1 [] =
55 total_logs = 20 + 85 + 120;
57 qos_distribution_equal_dual(&(struct qos_module) { .max_throughput = 200 }, i1, 3);
58 assert(i1[0].count == -1); // 20 < 200/3
59 assert(i1[1].count == 90); // 85 >= 200/3, 90 == (200-20)/2
60 assert(i1[2].count == 90); // 120 >= 200/3, 90 == (200-20)/2
63 void test_equal_multi()
65 struct metrics_pid_aggr_info i1 [] =
70 total_logs = 30 + 95 + 120;
72 qos_distribution_equal_multi(&(struct qos_module) { .max_throughput = 200 }, i1, 3);
73 assert(i1[0].count == -1); // 30 < 200/3
74 assert(i1[1].count == 85); // 95 >= 200/3, and 95 >= (200-30)/2
75 assert(i1[2].count == 85); // 120 >= 200/3, and 120 >= (200-30)/2
78 struct metrics_pid_aggr_info i2 [] =
83 total_logs = 20 + 85 + 120;
85 qos_distribution_equal_multi(&(struct qos_module) { .max_throughput = 200 }, i2, 3);
86 assert(i2[0].count == -1); // 20 < 200/3
87 assert(i2[1].count == -1); // 85 >= 200/3, but 85 < (200-20)/2
88 assert(i2[2].count == 95); // 120 >= 200/3, and 120 >= (200-20)/2, and 120 >= (200-20-85)/1
91 void test_proportional_talmud()
93 struct metrics_pid_aggr_info i1 [] =
97 total_logs = 50 + 100;
99 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 100 }, i1, 2);
100 assert(i1[0].count == 25);
101 assert(i1[1].count == 75);
103 struct metrics_pid_aggr_info i2 [] =
108 total_logs = 100 + 200 + 300;
110 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 100 }, i2, 3);
111 assert(i2[0].count == 33);
112 assert(i2[1].count == 33);
113 assert(i2[2].count == 33);
115 struct metrics_pid_aggr_info i3 [] =
120 total_logs = 100 + 200 + 300;
122 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 200 }, i3, 3);
123 assert(i3[0].count == 50);
124 assert(i3[1].count == 75);
125 assert(i3[2].count == 75);
127 struct metrics_pid_aggr_info i4 [] =
132 total_logs = 100 + 200 + 300;
134 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 300 }, i4, 3);
135 assert(i4[0].count == 50);
136 assert(i4[1].count == 100);
137 assert(i4[2].count == 150);
139 struct metrics_pid_aggr_info i5 [] =
144 total_logs = 100 + 200 + 300;
146 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 400 }, i5, 3);
147 assert(i5[0].count == 50);
148 assert(i5[1].count == 125);
149 assert(i5[2].count == 225);
151 struct metrics_pid_aggr_info i6 [] =
156 total_logs = 10 + 20 + 30;
158 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 100 }, i6, 3);
159 assert(i6[0].count == 10);
160 assert(i6[1].count == 20);
161 assert(i6[2].count == 30);
163 struct metrics_pid_aggr_info i7 [] =
168 total_logs = 100 + 200 + 300;
170 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 500 }, i7, 3);
171 assert(i7[0].count == 67);
172 assert(i7[1].count == 167);
173 assert(i7[2].count == 267);
175 struct metrics_pid_aggr_info i8 [] =
181 total_logs = 100 + 200 + 300 + 400;
183 qos_distribution_proportional_talmud(&(struct qos_module) { .max_throughput = 700 }, i8, 4);
184 assert(i8[0].count == 50);
185 assert(i8[1].count == 117);
186 assert(i8[2].count == 217);
187 assert(i8[3].count == 317);
192 test_proportional_raw();
196 test_proportional_talmud();