160TEST(SwitchStrategySWRoundRobin, Algorithm)
176 int32_t count1 = 0, count2 = 0, count3 = 0;
179 const int32_t steps = 120;
180 for (int32_t i = 0; i < steps; i++)
187 else CHECK_TEXT(
false,
"Unknown task selected");
190 const int32_t w1 = 1, w2 = 2, w3 = 3;
191 const int32_t total_w = w1 + w2 + w3;
193 const int32_t exp1 = (steps * w1) / total_w;
194 const int32_t exp2 = (steps * w2) / total_w;
195 const int32_t exp3 = steps - exp1 - exp2;
198 const float tol_frac = 0.25f;
200 auto within_tol = [&](
int expected,
int actual,
float frac) ->
bool
202 int tol = (int)(expected * frac) + 1;
203 int diff = expected > actual ? expected - actual : actual - expected;
207 CHECK_TRUE_TEXT(within_tol(exp1, count1, tol_frac),
"Task1 proportion off (weight 1)");
208 CHECK_TRUE_TEXT(within_tol(exp2, count2, tol_frac),
"Task2 proportion off (weight 2)");
209 CHECK_TRUE_TEXT(within_tol(exp3, count3, tol_frac),
"Task3 proportion off (weight 3)");
212 CHECK_TEXT(count1 > 0,
"Task1 must run at least once");
213 CHECK_TEXT(count2 > 0,
"Task2 must run at least once");
214 CHECK_TEXT(count3 > 0,
"Task3 must run at least once");
225 for (int32_t i = 0; i < steps; i++)
231 else CHECK_TEXT(
false,
"Unknown task selected after removal");
234 const int32_t nw1 = 1, nw2 = 2;
235 const int32_t ntotal = nw1 + nw2;
236 const int32_t nexp1 = (steps * nw1) / ntotal;
237 const int32_t nexp2 = steps - nexp1;
239 CHECK_TRUE_TEXT(within_tol(nexp1, count1, tol_frac),
"Task1 proportion off after removal");
240 CHECK_TRUE_TEXT(within_tol(nexp2, count2, tol_frac),
"Task2 proportion off after removal");
242 CHECK_TEXT(count1 > 0,
"Task1 must run after removal");
243 CHECK_TEXT(count2 > 0,
"Task2 must run after removal");
void Initialize(uint32_t resolution_us=PERIODICITY_DEFAULT)
Prepare kernel for use: reset state, configure the platform, and register the service singleton.