| 1 |
#include "intel_rdt.c" /* sic */ |
| 2 |
#include "testing.h" |
| 3 |
|
| 4 |
/*************************************************************************** |
| 5 |
* PQOS mocks |
| 6 |
*/ |
| 7 |
int pqos_mon_reset(void) { return 0; } |
| 8 |
int pqos_mon_assoc_get(const unsigned lcore, pqos_rmid_t *rmid) { return 0; } |
| 9 |
int pqos_mon_start(const unsigned num_cores, const unsigned *cores, |
| 10 |
const enum pqos_mon_event event, void *context, |
| 11 |
struct pqos_mon_data *group) { |
| 12 |
return 0; |
| 13 |
} |
| 14 |
#if PQOS_VERSION >= 30000 |
| 15 |
int pqos_mon_start_pids(const unsigned num_pids, const pid_t *pids, |
| 16 |
const enum pqos_mon_event event, void *context, |
| 17 |
struct pqos_mon_data *group) { |
| 18 |
return 0; |
| 19 |
} |
| 20 |
int pqos_mon_add_pids(const unsigned num_pids, const pid_t *pids, |
| 21 |
struct pqos_mon_data *group) { |
| 22 |
return 0; |
| 23 |
} |
| 24 |
int pqos_mon_remove_pids(const unsigned num_pids, const pid_t *pids, |
| 25 |
struct pqos_mon_data *group) { |
| 26 |
return 0; |
| 27 |
} |
| 28 |
|
| 29 |
#else |
| 30 |
int pqos_mon_start_pid(const pid_t pids, const enum pqos_mon_event event, |
| 31 |
void *context, struct pqos_mon_data *group) { |
| 32 |
return 0; |
| 33 |
} |
| 34 |
#endif |
| 35 |
int pqos_mon_stop(struct pqos_mon_data *group) { return 0; } |
| 36 |
int pqos_mon_poll(struct pqos_mon_data **groups, const unsigned num_groups) { |
| 37 |
return 0; |
| 38 |
} |
| 39 |
|
| 40 |
#if PQOS_VERSION >= 30000 |
| 41 |
int pqos_alloc_reset(const enum pqos_cdp_config l3_cdp_cfg, |
| 42 |
const enum pqos_cdp_config l2_cdp_cfg, |
| 43 |
const enum pqos_mba_config mba_cfg) { |
| 44 |
return 0; |
| 45 |
} |
| 46 |
#elif PQOS_VERSION >= 20000 |
| 47 |
int pqos_alloc_reset(const enum pqos_cdp_config l3_cdp_cfg, |
| 48 |
const enum pqos_cdp_config l2_cdp_cfg) { |
| 49 |
return 0; |
| 50 |
} |
| 51 |
#else |
| 52 |
int pqos_alloc_reset(const enum pqos_cdp_config l3_cdp_cfg) { return 0; } |
| 53 |
#endif |
| 54 |
int pqos_alloc_assoc_set(const unsigned lcore, const unsigned class_id) { |
| 55 |
return 0; |
| 56 |
} |
| 57 |
int pqos_alloc_assoc_get(const unsigned lcore, unsigned *class_id) { return 0; } |
| 58 |
int pqos_alloc_assoc_set_pid(const pid_t task, const unsigned class_id) { |
| 59 |
return 0; |
| 60 |
} |
| 61 |
int pqos_alloc_assoc_get_pid(const pid_t task, unsigned *class_id) { return 0; } |
| 62 |
int pqos_alloc_assign(const unsigned technology, const unsigned *core_array, |
| 63 |
const unsigned core_num, unsigned *class_id) { |
| 64 |
return 0; |
| 65 |
} |
| 66 |
int pqos_alloc_release(const unsigned *core_array, const unsigned core_num) { |
| 67 |
return 0; |
| 68 |
} |
| 69 |
int pqos_alloc_assign_pid(const unsigned technology, const pid_t *task_array, |
| 70 |
const unsigned task_num, unsigned *class_id) { |
| 71 |
return 0; |
| 72 |
} |
| 73 |
int pqos_alloc_release_pid(const pid_t *task_array, const unsigned task_num) { |
| 74 |
return 0; |
| 75 |
} |
| 76 |
int pqos_init(const struct pqos_config *config) { return 0; } |
| 77 |
int pqos_fini(void) { return 0; } |
| 78 |
int pqos_cap_get_type(const struct pqos_cap *cap, const enum pqos_cap_type type, |
| 79 |
const struct pqos_capability **cap_item) { |
| 80 |
return 0; |
| 81 |
} |
| 82 |
int pqos_cap_get(const struct pqos_cap **cap, const struct pqos_cpuinfo **cpu) { |
| 83 |
return 0; |
| 84 |
} |
| 85 |
int pqos_cap_get_event(const struct pqos_cap *cap, |
| 86 |
const enum pqos_mon_event event, |
| 87 |
const struct pqos_monitor **p_mon) { |
| 88 |
return 0; |
| 89 |
} |
| 90 |
#ifdef LIBPQOS2 |
| 91 |
/*************************************************************************** |
| 92 |
* helper functions |
| 93 |
*/ |
| 94 |
rdt_ctx_t *stub_rdt_setup() { |
| 95 |
|
| 96 |
rdt_ctx_t *rdt = calloc(1, sizeof(*rdt)); |
| 97 |
struct pqos_cpuinfo *pqos_cpu = calloc(1, sizeof(*pqos_cpu)); |
| 98 |
struct pqos_cap *pqos_cap = calloc(1, sizeof(*pqos_cap)); |
| 99 |
struct pqos_cap_mon *mon = calloc(1, sizeof(*mon)); |
| 100 |
struct pqos_capability *cap_mon = calloc(1, sizeof(*cap_mon)); |
| 101 |
|
| 102 |
cap_mon->u.mon = mon; |
| 103 |
rdt->pqos_cap = pqos_cap; |
| 104 |
rdt->pqos_cpu = pqos_cpu; |
| 105 |
rdt->cap_mon = cap_mon; |
| 106 |
|
| 107 |
return rdt; |
| 108 |
} |
| 109 |
|
| 110 |
void stub_rdt_teardown(rdt_ctx_t *rdt) { |
| 111 |
free(rdt->cap_mon->u.mon); |
| 112 |
free((void *)rdt->cap_mon); |
| 113 |
free((void *)rdt->pqos_cpu); |
| 114 |
free((void *)rdt->pqos_cap); |
| 115 |
free(rdt); |
| 116 |
} |
| 117 |
|
| 118 |
/*************************************************************************** |
| 119 |
* tests |
| 120 |
*/ |
| 121 |
DEF_TEST(rdt_config_ngroups__one_process) { |
| 122 |
/* setup */ |
| 123 |
rdt_ctx_t *rdt = stub_rdt_setup(); |
| 124 |
|
| 125 |
oconfig_value_t values[] = { |
| 126 |
{.value.string = "proc1", .type = OCONFIG_TYPE_STRING}, |
| 127 |
}; |
| 128 |
oconfig_item_t config_item = { |
| 129 |
.values = values, |
| 130 |
.values_num = STATIC_ARRAY_SIZE(values), |
| 131 |
}; |
| 132 |
|
| 133 |
/* check */ |
| 134 |
int result = rdt_config_ngroups(rdt, &config_item); |
| 135 |
EXPECT_EQ_INT(0, result); |
| 136 |
EXPECT_EQ_STR(values[0].value.string, rdt->ngroups[0].desc); |
| 137 |
EXPECT_EQ_INT(1, rdt->num_ngroups); |
| 138 |
|
| 139 |
/* cleanup */ |
| 140 |
rdt_free_ngroups(rdt); |
| 141 |
stub_rdt_teardown(rdt); |
| 142 |
|
| 143 |
return 0; |
| 144 |
} |
| 145 |
|
| 146 |
DEF_TEST(rdt_config_ngroups__two_groups) { |
| 147 |
/* setup */ |
| 148 |
rdt_ctx_t *rdt = stub_rdt_setup(); |
| 149 |
|
| 150 |
oconfig_value_t values[] = { |
| 151 |
{.value.string = "proc11,proc12,proc13", .type = OCONFIG_TYPE_STRING}, |
| 152 |
{.value.string = "proc21,proc22,proc23", .type = OCONFIG_TYPE_STRING}, |
| 153 |
}; |
| 154 |
oconfig_item_t config_item = { |
| 155 |
.values = values, |
| 156 |
.values_num = STATIC_ARRAY_SIZE(values), |
| 157 |
}; |
| 158 |
|
| 159 |
/* check */ |
| 160 |
int result = rdt_config_ngroups(rdt, &config_item); |
| 161 |
EXPECT_EQ_INT(0, result); |
| 162 |
EXPECT_EQ_INT(2, rdt->num_ngroups); |
| 163 |
EXPECT_EQ_STR("proc11,proc12,proc13", rdt->ngroups[0].desc); |
| 164 |
EXPECT_EQ_STR("proc21,proc22,proc23", rdt->ngroups[1].desc); |
| 165 |
EXPECT_EQ_STR("proc11", rdt->ngroups[0].names[0]); |
| 166 |
EXPECT_EQ_STR("proc12", rdt->ngroups[0].names[1]); |
| 167 |
EXPECT_EQ_STR("proc13", rdt->ngroups[0].names[2]); |
| 168 |
EXPECT_EQ_STR("proc21", rdt->ngroups[1].names[0]); |
| 169 |
EXPECT_EQ_STR("proc22", rdt->ngroups[1].names[1]); |
| 170 |
EXPECT_EQ_STR("proc23", rdt->ngroups[1].names[2]); |
| 171 |
|
| 172 |
/* cleanup */ |
| 173 |
rdt_free_ngroups(rdt); |
| 174 |
stub_rdt_teardown(rdt); |
| 175 |
|
| 176 |
return 0; |
| 177 |
} |
| 178 |
|
| 179 |
DEF_TEST(rdt_config_ngroups__too_long_proc_name) { |
| 180 |
/* setup */ |
| 181 |
rdt_ctx_t *rdt = stub_rdt_setup(); |
| 182 |
|
| 183 |
oconfig_value_t values[] = { |
| 184 |
{.value.string = "_seventeen_chars_", .type = OCONFIG_TYPE_STRING}, |
| 185 |
}; |
| 186 |
oconfig_item_t config_item = { |
| 187 |
.values = values, |
| 188 |
.values_num = STATIC_ARRAY_SIZE(values), |
| 189 |
}; |
| 190 |
|
| 191 |
/* check */ |
| 192 |
int result = rdt_config_ngroups(rdt, &config_item); |
| 193 |
EXPECT_EQ_INT(-EINVAL, result); |
| 194 |
|
| 195 |
/* cleanup */ |
| 196 |
stub_rdt_teardown(rdt); |
| 197 |
|
| 198 |
return 0; |
| 199 |
} |
| 200 |
|
| 201 |
DEF_TEST(rdt_config_ngroups__duplicate_proc_name_between_groups) { |
| 202 |
/* setup */ |
| 203 |
rdt_ctx_t *rdt = stub_rdt_setup(); |
| 204 |
|
| 205 |
oconfig_value_t values[] = { |
| 206 |
{.value.string = "proc11,proc12,proc", .type = OCONFIG_TYPE_STRING}, |
| 207 |
{.value.string = "proc21,proc,proc23", .type = OCONFIG_TYPE_STRING}, |
| 208 |
}; |
| 209 |
oconfig_item_t config_item = { |
| 210 |
.values = values, |
| 211 |
.values_num = STATIC_ARRAY_SIZE(values), |
| 212 |
}; |
| 213 |
|
| 214 |
/* check */ |
| 215 |
int result = rdt_config_ngroups(rdt, &config_item); |
| 216 |
EXPECT_EQ_INT(-EINVAL, result); |
| 217 |
|
| 218 |
/* cleanup */ |
| 219 |
stub_rdt_teardown(rdt); |
| 220 |
|
| 221 |
return 0; |
| 222 |
} |
| 223 |
|
| 224 |
DEF_TEST(rdt_config_ngroups__duplicate_proc_name_in_group) { |
| 225 |
/* setup */ |
| 226 |
rdt_ctx_t *rdt = stub_rdt_setup(); |
| 227 |
|
| 228 |
oconfig_value_t values[] = { |
| 229 |
{.value.string = "proc11,proc,proc,proc14", .type = OCONFIG_TYPE_STRING}, |
| 230 |
}; |
| 231 |
oconfig_item_t config_item = { |
| 232 |
.values = values, |
| 233 |
.values_num = STATIC_ARRAY_SIZE(values), |
| 234 |
}; |
| 235 |
|
| 236 |
/* check */ |
| 237 |
int result = rdt_config_ngroups(rdt, &config_item); |
| 238 |
EXPECT_EQ_INT(-EINVAL, result); |
| 239 |
|
| 240 |
/* cleanup */ |
| 241 |
stub_rdt_teardown(rdt); |
| 242 |
|
| 243 |
return 0; |
| 244 |
} |
| 245 |
|
| 246 |
DEF_TEST(rdt_config_ngroups__empty_group) { |
| 247 |
/* setup */ |
| 248 |
rdt_ctx_t *rdt = stub_rdt_setup(); |
| 249 |
|
| 250 |
oconfig_value_t values[] = { |
| 251 |
{.value.string = "proc11,proc12,proc13", .type = OCONFIG_TYPE_STRING}, |
| 252 |
{.value.string = "", .type = OCONFIG_TYPE_STRING}, |
| 253 |
|
| 254 |
}; |
| 255 |
oconfig_item_t config_item = { |
| 256 |
.values = values, |
| 257 |
.values_num = STATIC_ARRAY_SIZE(values), |
| 258 |
}; |
| 259 |
|
| 260 |
/* check */ |
| 261 |
int result = rdt_config_ngroups(rdt, &config_item); |
| 262 |
EXPECT_EQ_INT(-EINVAL, result); |
| 263 |
|
| 264 |
/* cleanup */ |
| 265 |
stub_rdt_teardown(rdt); |
| 266 |
|
| 267 |
return 0; |
| 268 |
} |
| 269 |
|
| 270 |
DEF_TEST(rdt_config_ngroups__empty_proc_name) { |
| 271 |
/* setup */ |
| 272 |
rdt_ctx_t *rdt = stub_rdt_setup(); |
| 273 |
|
| 274 |
oconfig_value_t values[] = { |
| 275 |
{.value.string = "proc11,,proc13", .type = OCONFIG_TYPE_STRING}, |
| 276 |
}; |
| 277 |
oconfig_item_t config_item = { |
| 278 |
.values = values, |
| 279 |
.values_num = STATIC_ARRAY_SIZE(values), |
| 280 |
}; |
| 281 |
|
| 282 |
/* check */ |
| 283 |
int result = rdt_config_ngroups(rdt, &config_item); |
| 284 |
EXPECT_EQ_INT(-EINVAL, result); |
| 285 |
|
| 286 |
/* cleanup */ |
| 287 |
stub_rdt_teardown(rdt); |
| 288 |
|
| 289 |
return 0; |
| 290 |
} |
| 291 |
|
| 292 |
int main(void) { |
| 293 |
RUN_TEST(rdt_config_ngroups__one_process); |
| 294 |
RUN_TEST(rdt_config_ngroups__two_groups); |
| 295 |
RUN_TEST(rdt_config_ngroups__too_long_proc_name); |
| 296 |
RUN_TEST(rdt_config_ngroups__duplicate_proc_name_between_groups); |
| 297 |
RUN_TEST(rdt_config_ngroups__duplicate_proc_name_in_group); |
| 298 |
RUN_TEST(rdt_config_ngroups__empty_group); |
| 299 |
RUN_TEST(rdt_config_ngroups__empty_proc_name); |
| 300 |
END_TEST; |
| 301 |
} |
| 302 |
|
| 303 |
#else |
| 304 |
DEF_TEST(pqos12_test_stub) { |
| 305 |
EXPECT_EQ_INT(0, 0); |
| 306 |
return 0; |
| 307 |
} |
| 308 |
|
| 309 |
int main(void) { |
| 310 |
RUN_TEST(pqos12_test_stub); |
| 311 |
END_TEST; |
| 312 |
} |
| 313 |
#endif |