1 #include "intel_rdt.c" /* sic */
5 /***************************************************************************
8 #if PQOS_VERSION >= 30000
9 int pqos_alloc_reset(const enum pqos_cdp_config l3_cdp_cfg,
10 const enum pqos_cdp_config l2_cdp_cfg,
11 const enum pqos_mba_config mba_cfg) {
14 #elif PQOS_VERSION >= 2000
15 int pqos_alloc_reset(const enum pqos_cdp_config l3_cdp_cfg,
16 const enum pqos_cdp_config l2_cdp_cfg) {
20 int pqos_alloc_reset(const enum pqos_cdp_config l3_cdp_cfg) {
26 /***************************************************************************
29 int pqos_mon_reset(void) { return 0; }
30 int pqos_mon_assoc_get(const unsigned lcore, pqos_rmid_t *rmid) { return 0; }
31 int pqos_mon_start(const unsigned num_cores, const unsigned *cores,
32 const enum pqos_mon_event event, void *context,
33 struct pqos_mon_data *group) {
36 int pqos_mon_start_pids(const unsigned num_pids, const pid_t *pids,
37 const enum pqos_mon_event event, void *context,
38 struct pqos_mon_data *group) {
41 int pqos_mon_add_pids(const unsigned num_pids, const pid_t *pids,
42 struct pqos_mon_data *group) {
45 int pqos_mon_remove_pids(const unsigned num_pids, const pid_t *pids,
46 struct pqos_mon_data *group) {
49 int pqos_mon_stop(struct pqos_mon_data *group) { return 0; }
50 int pqos_mon_poll(struct pqos_mon_data **groups, const unsigned num_groups) {
53 int pqos_alloc_assoc_set(const unsigned lcore, const unsigned class_id) {
56 int pqos_alloc_assoc_get(const unsigned lcore, unsigned *class_id) { return 0; }
57 int pqos_alloc_assoc_set_pid(const pid_t task, const unsigned class_id) {
60 int pqos_alloc_assoc_get_pid(const pid_t task, unsigned *class_id) { return 0; }
61 int pqos_alloc_assign(const unsigned technology, const unsigned *core_array,
62 const unsigned core_num, unsigned *class_id) {
65 int pqos_alloc_release(const unsigned *core_array, const unsigned core_num) {
68 int pqos_alloc_assign_pid(const unsigned technology, const pid_t *task_array,
69 const unsigned task_num, unsigned *class_id) {
72 int pqos_alloc_release_pid(const pid_t *task_array, const unsigned task_num) {
75 int pqos_init(const struct pqos_config *config) { return 0; }
76 int pqos_fini(void) { return 0; }
77 int pqos_cap_get_type(const struct pqos_cap *cap, const enum pqos_cap_type type,
78 const struct pqos_capability **cap_item) {
81 int pqos_cap_get(const struct pqos_cap **cap, const struct pqos_cpuinfo **cpu) {
84 /***************************************************************************
90 * pids_list_get_element
93 * Gets list element at index position. Assumes list was created by
94 * pids_list_add_pid function.
98 * `index' Position of desired element relative to given list pointer.
101 * Pointer to element at index position.
102 * NULL if index exceeds list's length.
104 pids_list_t *pids_list_get_element(pids_list_t *list, const size_t index) {
107 while (list != NULL && current != index) {
114 typedef struct stub_proc_pid {
119 static const char *proc_fs = "/tmp/procfs_stub";
126 * Prepares testing environment by creating temporary
127 * PID/comm file structure.
130 * `proc_pids_array' Array of stub_proc_pid_t structs. Represents
131 * which PIDs should hold given process name.
132 * `proc_pids_array_length' Element count of input array.
136 * -1 on base dir creation error.
137 * -2 on comm file creation error.
139 int stub_procfs_setup(const stub_proc_pid_t *proc_pids_array,
140 const size_t proc_pids_array_length) {
141 if (mkdir(proc_fs, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
145 for (size_t i = 0; i < proc_pids_array_length; ++i) {
146 memset(path, 0, sizeof(path));
147 snprintf(path, STATIC_ARRAY_SIZE(path), "%s/%d", proc_fs,
148 proc_pids_array[i].pid);
149 mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
150 strncat(path, "/comm", STATIC_ARRAY_SIZE(path) - strlen(path) - 1);
152 FILE *fp = fopen(path, "w");
155 fwrite(proc_pids_array[i].comm, sizeof(char),
156 strlen(proc_pids_array[i].comm), fp);
164 * stub_procfs_teardown
167 * Clears testing environment: removes stub proc files.
168 * NOTE - This function could be implemented by usage of nftw, but this
169 * would require #define _XOPEN_SOURCE 500, which
170 * messes up intel_rdt includes.
173 * system command result
175 int stub_procfs_teardown() {
177 sstrncpy(cmd, "rm -rf ", STATIC_ARRAY_SIZE(cmd));
178 strncat(cmd, proc_fs, STATIC_ARRAY_SIZE(cmd) - strlen(cmd) - 1);
182 /* Max PID value. More info:
183 * http://web.archive.org/web/20111209081734/http://research.cs.wisc.edu/condor/condorg/linux_scalability.html
185 #define MAX_PID 4194304
186 #define MAX_PID_STR "4194304"
188 rdt_ctx_t *stub_rdt_setup() {
190 rdt_ctx_t *rdt = calloc(1, sizeof(*rdt));
191 struct pqos_cpuinfo *pqos_cpu = calloc(1, sizeof(*pqos_cpu));
192 struct pqos_cap *pqos_cap = calloc(1, sizeof(*pqos_cap));
193 struct pqos_cap_mon *mon = calloc(1, sizeof(*mon));
194 struct pqos_capability *cap_mon = calloc(1, sizeof(*cap_mon));
196 cap_mon->u.mon = mon;
197 rdt->pqos_cap = pqos_cap;
198 rdt->pqos_cpu = pqos_cpu;
199 rdt->cap_mon = cap_mon;
204 void stub_rdt_teardown(rdt_ctx_t *rdt) {
205 free(rdt->cap_mon->u.mon);
206 free((void *)rdt->cap_mon);
207 free((void *)rdt->pqos_cpu);
208 free((void *)rdt->pqos_cap);
212 /***************************************************************************
215 DEF_TEST(initialize_proc_pids__on_nullptr) {
217 const char *procs_names_array[] = {"proc1", "proc2", "proc3"};
218 const size_t procs_names_array_size = STATIC_ARRAY_SIZE(procs_names_array);
219 proc_pids_t *proc_pids_array = NULL;
222 int result = initialize_proc_pids(procs_names_array, procs_names_array_size,
224 EXPECT_EQ_INT(0, result);
225 for (size_t i = 0; i < procs_names_array_size; ++i)
226 EXPECT_EQ_STR(procs_names_array[i], proc_pids_array[i].proccess_name);
229 free(proc_pids_array);
233 DEF_TEST(add_proc_pid__empty_list) {
235 proc_pids_t proc_pids_instance;
236 proc_pids_instance.pids = NULL;
240 pids_list_add_pid(&proc_pids_instance.pids, pid);
241 pids_list_t *added = pids_list_get_element(proc_pids_instance.pids, 0);
242 EXPECT_EQ_INT(pid, added->pid);
245 pids_list_free(proc_pids_instance.pids);
249 DEF_TEST(add_proc_pid__non_empty_list) {
251 proc_pids_t proc_pids_instance;
252 proc_pids_instance.pids = NULL;
253 pid_t pids[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
256 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids); ++i)
257 pids_list_add_pid(&proc_pids_instance.pids, pids[i]);
259 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids); ++i) {
260 pids_list_t *added = pids_list_get_element(proc_pids_instance.pids, i);
261 EXPECT_EQ_INT(pids[i], added->pid);
265 pids_list_free(proc_pids_instance.pids);
269 DEF_TEST(pids_list_to_array__non_empty_list) {
271 pid_t pids[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
272 pids_list_t *pids_list = NULL;
273 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids); ++i)
274 pids_list_add_pid(&pids_list, pids[i]);
277 pid_t target_array[STATIC_ARRAY_SIZE(pids)];
278 pids_list_to_array(target_array, pids_list, STATIC_ARRAY_SIZE(target_array));
279 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids); ++i)
280 EXPECT_EQ_INT(pids[i], target_array[i]);
283 pids_list_free(pids_list);
287 DEF_TEST(pids_list_add_pids_list__non_empty_lists) {
289 pid_t pids_array_1[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
290 pid_t pids_array_2[] = {2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007};
291 pids_list_t *pids_list_1 = NULL;
292 pids_list_t *pids_list_2 = NULL;
294 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_1); ++i) {
295 pids_list_add_pid(&pids_list_1, pids_array_1[i]);
296 pids_list_add_pid(&pids_list_2, pids_array_2[i]);
300 int result = pids_list_add_pids_list(&pids_list_1, pids_list_2, &increase);
301 EXPECT_EQ_INT(0, result);
302 EXPECT_EQ_INT(STATIC_ARRAY_SIZE(pids_array_2), increase);
304 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_1); ++i) {
305 EXPECT_EQ_INT(1, pids_list_contains_pid(pids_list_1, pids_array_1[i]));
306 EXPECT_EQ_INT(1, pids_list_contains_pid(pids_list_1, pids_array_2[i]));
310 pids_list_free(pids_list_1);
311 pids_list_free(pids_list_2);
315 DEF_TEST(pids_list_add_pids_list__add_to_empty) {
317 pid_t pids_array[] = {2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007};
318 pids_list_t *pids_list_1 = NULL;
319 pids_list_t *pids_list_2 = NULL;
321 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array); ++i)
322 pids_list_add_pid(&pids_list_2, pids_array[i]);
325 int result = pids_list_add_pids_list(&pids_list_1, pids_list_2, &increase);
326 EXPECT_EQ_INT(0, result);
327 EXPECT_EQ_INT(STATIC_ARRAY_SIZE(pids_array), increase);
329 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array); ++i)
330 EXPECT_EQ_INT(1, pids_list_contains_pid(pids_list_1, pids_array[i]));
333 pids_list_free(pids_list_1);
334 pids_list_free(pids_list_2);
338 DEF_TEST(get_pid_number__valid_dir) {
341 sstrncpy(d.d_name, MAX_PID_STR, STATIC_ARRAY_SIZE(d.d_name));
346 int pid_conversion = get_pid_number(&d, &pid);
348 EXPECT_EQ_INT(0, pid_conversion);
349 EXPECT_EQ_INT(MAX_PID, pid);
355 DEF_TEST(get_pid_number__invalid_dir_name) {
358 sstrncpy(d.d_name, "invalid", STATIC_ARRAY_SIZE(d.d_name));
363 int pid_conversion = get_pid_number(&d, &pid);
365 EXPECT_EQ_INT(-1, pid_conversion);
366 EXPECT_EQ_INT(0, pid);
372 DEF_TEST(read_proc_name__valid_name) {
374 stub_proc_pid_t pp_stubs[] = {{"proc1", MAX_PID}};
375 stub_procfs_setup(pp_stubs, STATIC_ARRAY_SIZE(pp_stubs));
377 sstrncpy(d.d_name, MAX_PID_STR, STATIC_ARRAY_SIZE(d.d_name));
382 int read_result = read_proc_name(proc_fs, &d, comm, STATIC_ARRAY_SIZE(comm));
384 EXPECT_EQ_INT(strlen(pp_stubs[0].comm), read_result);
385 EXPECT_EQ_STR(pp_stubs[0].comm, comm);
388 stub_procfs_teardown();
392 DEF_TEST(read_proc_name__invalid_name) {
395 sstrncpy(d.d_name, MAX_PID_STR, STATIC_ARRAY_SIZE(d.d_name));
400 int read_result = read_proc_name(proc_fs, &d, comm, STATIC_ARRAY_SIZE(comm));
402 EXPECT_EQ_INT(-1, read_result);
408 DEF_TEST(fetch_pids_for_procs__one_proc_many_pid) {
410 const char *proc_names[] = {"proc1"};
411 stub_proc_pid_t pp_stubs[] = {{"proc1", 1007},
416 stub_procfs_setup(pp_stubs, STATIC_ARRAY_SIZE(pp_stubs));
417 proc_pids_t *output = NULL;
420 int result = fetch_pids_for_procs(proc_fs, proc_names,
421 STATIC_ARRAY_SIZE(proc_names), &output);
422 EXPECT_EQ_INT(0, result);
424 /* proc name check */
425 EXPECT_EQ_STR(proc_names[0], output[0].proccess_name);
427 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pp_stubs); ++i) {
428 if (0 == strcmp(pp_stubs[i].comm, proc_names[0]))
429 /* check if proc struct has correct pids */
430 EXPECT_EQ_INT(pids_list_contains_pid(output[0].pids, pp_stubs[i].pid), 1);
432 /* check if proc struct has no incorrect pids */
433 EXPECT_EQ_INT(pids_list_contains_pid(output[0].pids, pp_stubs[i].pid), 0);
437 for (size_t i = 0; i < STATIC_ARRAY_SIZE(proc_names); ++i)
438 pids_list_free(output[i].pids);
440 stub_procfs_teardown();
444 DEF_TEST(fetch_pids_for_procs__many_proc_many_pid) {
446 const char *proc_names[] = {"proc1", "proc2", "proc3"};
447 stub_proc_pid_t pp_stubs[] = {
448 {"proc1", 1007}, {"proc1", 1008}, {"proc1", 1009}, {"proc2", 2007},
449 {"proc2", 2008}, {"proc2", 2009}, {"proc3", 3007}, {"proc3", 3008},
450 {"proc3", 3009}, {"proc4", 4007}, {"proc4", 4008}, {"proc4", 4009},
451 {"proc5", 5007}, {"proc5", 5008}, {"proc5", 5009}};
452 stub_procfs_setup(pp_stubs, STATIC_ARRAY_SIZE(pp_stubs));
453 proc_pids_t *output = NULL;
456 int result = fetch_pids_for_procs(proc_fs, proc_names,
457 STATIC_ARRAY_SIZE(proc_names), &output);
458 EXPECT_EQ_INT(0, result);
460 for (size_t i = 0; i < STATIC_ARRAY_SIZE(proc_names); ++i) {
462 /* proc name check */
463 EXPECT_EQ_STR(proc_names[i], output[i].proccess_name);
465 for (size_t j = 0; j < STATIC_ARRAY_SIZE(pp_stubs); ++j) {
466 if (0 == strcmp(pp_stubs[j].comm, proc_names[i]))
467 /* check if proc struct has correct pids */
468 EXPECT_EQ_INT(pids_list_contains_pid(output[i].pids, pp_stubs[j].pid),
471 /* check if proc struct has no incorrect pids */
472 EXPECT_EQ_INT(pids_list_contains_pid(output[i].pids, pp_stubs[j].pid),
478 for (size_t i = 0; i < STATIC_ARRAY_SIZE(proc_names); ++i)
479 pids_list_free(output[i].pids);
481 stub_procfs_teardown();
485 DEF_TEST(rdt_config_ngroups__one_process) {
487 rdt_ctx_t *rdt = stub_rdt_setup();
489 oconfig_value_t values[] = {
490 {.value.string = "proc1", .type = OCONFIG_TYPE_STRING},
492 oconfig_item_t config_item = {
493 .values = values, .values_num = STATIC_ARRAY_SIZE(values),
497 int result = rdt_config_ngroups(rdt, &config_item);
498 EXPECT_EQ_INT(0, result);
499 EXPECT_EQ_STR(values[0].value.string, rdt->ngroups[0].desc);
500 EXPECT_EQ_INT(1, rdt->num_ngroups);
503 rdt_free_ngroups(rdt);
504 stub_rdt_teardown(rdt);
509 DEF_TEST(rdt_config_ngroups__two_groups) {
511 rdt_ctx_t *rdt = stub_rdt_setup();
513 oconfig_value_t values[] = {
514 {.value.string = "proc11,proc12,proc13", .type = OCONFIG_TYPE_STRING},
515 {.value.string = "proc21,proc22,proc23", .type = OCONFIG_TYPE_STRING},
517 oconfig_item_t config_item = {
518 .values = values, .values_num = STATIC_ARRAY_SIZE(values),
522 int result = rdt_config_ngroups(rdt, &config_item);
523 EXPECT_EQ_INT(0, result);
524 EXPECT_EQ_INT(2, rdt->num_ngroups);
525 EXPECT_EQ_STR("proc11,proc12,proc13", rdt->ngroups[0].desc);
526 EXPECT_EQ_STR("proc21,proc22,proc23", rdt->ngroups[1].desc);
527 EXPECT_EQ_STR("proc11", rdt->ngroups[0].names[0]);
528 EXPECT_EQ_STR("proc12", rdt->ngroups[0].names[1]);
529 EXPECT_EQ_STR("proc13", rdt->ngroups[0].names[2]);
530 EXPECT_EQ_STR("proc21", rdt->ngroups[1].names[0]);
531 EXPECT_EQ_STR("proc22", rdt->ngroups[1].names[1]);
532 EXPECT_EQ_STR("proc23", rdt->ngroups[1].names[2]);
535 rdt_free_ngroups(rdt);
536 stub_rdt_teardown(rdt);
541 DEF_TEST(rdt_config_ngroups__too_long_proc_name) {
543 rdt_ctx_t *rdt = stub_rdt_setup();
545 oconfig_value_t values[] = {
546 {.value.string = "_seventeen_chars_", .type = OCONFIG_TYPE_STRING},
548 oconfig_item_t config_item = {
549 .values = values, .values_num = STATIC_ARRAY_SIZE(values),
553 int result = rdt_config_ngroups(rdt, &config_item);
554 EXPECT_EQ_INT(-EINVAL, result);
557 stub_rdt_teardown(rdt);
562 DEF_TEST(rdt_config_ngroups__duplicate_proc_name_between_groups) {
564 rdt_ctx_t *rdt = stub_rdt_setup();
566 oconfig_value_t values[] = {
567 {.value.string = "proc11,proc12,proc", .type = OCONFIG_TYPE_STRING},
568 {.value.string = "proc21,proc,proc23", .type = OCONFIG_TYPE_STRING},
570 oconfig_item_t config_item = {
571 .values = values, .values_num = STATIC_ARRAY_SIZE(values),
575 int result = rdt_config_ngroups(rdt, &config_item);
576 EXPECT_EQ_INT(-EINVAL, result);
579 stub_rdt_teardown(rdt);
584 DEF_TEST(rdt_config_ngroups__duplicate_proc_name_in_group) {
586 rdt_ctx_t *rdt = stub_rdt_setup();
588 oconfig_value_t values[] = {
589 {.value.string = "proc11,proc,proc,proc14", .type = OCONFIG_TYPE_STRING},
591 oconfig_item_t config_item = {
592 .values = values, .values_num = STATIC_ARRAY_SIZE(values),
596 int result = rdt_config_ngroups(rdt, &config_item);
597 EXPECT_EQ_INT(-EINVAL, result);
600 stub_rdt_teardown(rdt);
605 DEF_TEST(rdt_config_ngroups__empty_group) {
607 rdt_ctx_t *rdt = stub_rdt_setup();
609 oconfig_value_t values[] = {
610 {.value.string = "proc11,proc12,proc13", .type = OCONFIG_TYPE_STRING},
611 {.value.string = "", .type = OCONFIG_TYPE_STRING},
614 oconfig_item_t config_item = {
615 .values = values, .values_num = STATIC_ARRAY_SIZE(values),
619 int result = rdt_config_ngroups(rdt, &config_item);
620 EXPECT_EQ_INT(-EINVAL, result);
623 stub_rdt_teardown(rdt);
628 DEF_TEST(rdt_config_ngroups__empty_proc_name) {
630 rdt_ctx_t *rdt = stub_rdt_setup();
632 oconfig_value_t values[] = {
633 {.value.string = "proc11,,proc13", .type = OCONFIG_TYPE_STRING},
635 oconfig_item_t config_item = {
636 .values = values, .values_num = STATIC_ARRAY_SIZE(values),
640 int result = rdt_config_ngroups(rdt, &config_item);
641 EXPECT_EQ_INT(-EINVAL, result);
644 stub_rdt_teardown(rdt);
649 DEF_TEST(rdt_pid_list_diff__all_changed) {
651 pid_t pids_array_before[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
652 pid_t pids_array_after[] = {2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007};
653 pids_list_t *pids_list_before = NULL;
654 pids_list_t *pids_list_after = NULL;
655 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_after); ++i) {
656 pids_list_add_pid(&pids_list_before, pids_array_before[i]);
657 pids_list_add_pid(&pids_list_after, pids_array_after[i]);
660 pids_list_t *new_pids = NULL;
661 size_t new_pids_count = 0;
662 pids_list_t *lost_pids = NULL;
663 size_t lost_pids_count = 0;
666 int result = rdt_pid_list_diff(pids_list_before, pids_list_after, &new_pids,
667 &new_pids_count, &lost_pids, &lost_pids_count);
668 EXPECT_EQ_INT(0, result);
669 EXPECT_EQ_INT(STATIC_ARRAY_SIZE(pids_array_before), lost_pids_count);
670 EXPECT_EQ_INT(STATIC_ARRAY_SIZE(pids_array_after), new_pids_count);
672 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_before); ++i) {
673 EXPECT_EQ_INT(1, pids_list_contains_pid(new_pids, pids_array_after[i]));
674 EXPECT_EQ_INT(1, pids_list_contains_pid(lost_pids, pids_array_before[i]));
678 pids_list_free(pids_list_before);
679 pids_list_free(pids_list_after);
680 pids_list_free(new_pids);
681 pids_list_free(lost_pids);
686 DEF_TEST(rdt_pid_list_diff__nothing_changed) {
688 pid_t pids_array_before[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
689 pids_list_t *pids_list_before = NULL;
690 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_before); ++i) {
691 pids_list_add_pid(&pids_list_before, pids_array_before[i]);
694 pids_list_t *new_pids = NULL;
695 size_t new_pids_count = 0;
696 pids_list_t *lost_pids = NULL;
697 size_t lost_pids_count = 0;
700 int result = rdt_pid_list_diff(pids_list_before, pids_list_before, &new_pids,
701 &new_pids_count, &lost_pids, &lost_pids_count);
702 EXPECT_EQ_INT(0, result);
703 EXPECT_EQ_INT(0, lost_pids_count);
704 EXPECT_EQ_INT(0, new_pids_count);
705 OK(NULL == new_pids);
706 OK(NULL == lost_pids);
709 pids_list_free(pids_list_before);
714 DEF_TEST(rdt_pid_list_diff__one_added) {
716 pid_t pids_array_before[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
717 pid_t pids_array_after[] = {1000, 1001, 1002, 1003, 1004,
718 1005, 1006, 1007, 1008};
719 pids_list_t *pids_list_before = NULL;
720 pids_list_t *pids_list_after = NULL;
721 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_before); ++i)
722 pids_list_add_pid(&pids_list_before, pids_array_before[i]);
724 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_after); ++i)
725 pids_list_add_pid(&pids_list_after, pids_array_after[i]);
727 pids_list_t *new_pids = NULL;
728 size_t new_pids_count = 0;
729 pids_list_t *lost_pids = NULL;
730 size_t lost_pids_count = 0;
733 int result = rdt_pid_list_diff(pids_list_before, pids_list_after, &new_pids,
734 &new_pids_count, &lost_pids, &lost_pids_count);
735 EXPECT_EQ_INT(0, result);
736 EXPECT_EQ_INT(0, lost_pids_count);
737 EXPECT_EQ_INT(1, new_pids_count);
738 EXPECT_EQ_INT(1008, new_pids->pid);
741 pids_list_free(pids_list_before);
742 pids_list_free(pids_list_after);
743 pids_list_free(new_pids);
748 DEF_TEST(rdt_pid_list_diff__one_removed) {
750 pid_t pids_array_before[] = {1000, 1001, 1002, 1003, 1004,
751 1005, 1006, 1007, 1008};
752 pid_t pids_array_after[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
753 pids_list_t *pids_list_before = NULL;
754 pids_list_t *pids_list_after = NULL;
755 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_before); ++i)
756 pids_list_add_pid(&pids_list_before, pids_array_before[i]);
758 for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_after); ++i)
759 pids_list_add_pid(&pids_list_after, pids_array_after[i]);
761 pids_list_t *new_pids = NULL;
762 size_t new_pids_count = 0;
763 pids_list_t *lost_pids = NULL;
764 size_t lost_pids_count = 0;
767 int result = rdt_pid_list_diff(pids_list_before, pids_list_after, &new_pids,
768 &new_pids_count, &lost_pids, &lost_pids_count);
769 EXPECT_EQ_INT(0, result);
770 EXPECT_EQ_INT(1, lost_pids_count);
771 EXPECT_EQ_INT(0, new_pids_count);
772 EXPECT_EQ_INT(1008, lost_pids->pid);
775 pids_list_free(pids_list_before);
776 pids_list_free(pids_list_after);
777 pids_list_free(lost_pids);
783 stub_procfs_teardown();
784 RUN_TEST(initialize_proc_pids__on_nullptr);
785 RUN_TEST(add_proc_pid__empty_list);
786 RUN_TEST(add_proc_pid__non_empty_list);
787 RUN_TEST(pids_list_to_array__non_empty_list);
788 RUN_TEST(pids_list_add_pids_list__non_empty_lists);
789 RUN_TEST(pids_list_add_pids_list__add_to_empty);
790 RUN_TEST(get_pid_number__valid_dir);
791 RUN_TEST(get_pid_number__invalid_dir_name);
792 RUN_TEST(read_proc_name__valid_name);
793 RUN_TEST(read_proc_name__invalid_name);
794 RUN_TEST(fetch_pids_for_procs__one_proc_many_pid);
795 RUN_TEST(fetch_pids_for_procs__many_proc_many_pid);
796 RUN_TEST(rdt_config_ngroups__one_process);
797 RUN_TEST(rdt_config_ngroups__two_groups);
798 RUN_TEST(rdt_config_ngroups__too_long_proc_name);
799 RUN_TEST(rdt_config_ngroups__duplicate_proc_name_between_groups);
800 RUN_TEST(rdt_config_ngroups__duplicate_proc_name_in_group);
801 RUN_TEST(rdt_config_ngroups__empty_group);
802 RUN_TEST(rdt_config_ngroups__empty_proc_name);
803 RUN_TEST(rdt_pid_list_diff__all_changed);
804 RUN_TEST(rdt_pid_list_diff__nothing_changed);
805 RUN_TEST(rdt_pid_list_diff__one_added);
806 RUN_TEST(rdt_pid_list_diff__one_removed);
807 stub_procfs_teardown();
812 /***************************************************************************
815 int pqos_mon_reset(void) { return 0; }
816 int pqos_mon_assoc_get(const unsigned lcore, pqos_rmid_t *rmid) { return 0; }
817 int pqos_mon_start(const unsigned num_cores, const unsigned *cores,
818 const enum pqos_mon_event event, void *context,
819 struct pqos_mon_data *group) {
822 int pqos_mon_start_pid(const pid_t pids, const enum pqos_mon_event event,
823 void *context, struct pqos_mon_data *group) {
826 int pqos_mon_stop(struct pqos_mon_data *group) { return 0; }
827 int pqos_mon_poll(struct pqos_mon_data **groups, const unsigned num_groups) {
830 int pqos_alloc_assoc_set(const unsigned lcore, const unsigned class_id) {
833 int pqos_alloc_assoc_get(const unsigned lcore, unsigned *class_id) { return 0; }
834 int pqos_alloc_assoc_set_pid(const pid_t task, const unsigned class_id) {
837 int pqos_alloc_assoc_get_pid(const pid_t task, unsigned *class_id) { return 0; }
838 int pqos_alloc_assign(const unsigned technology, const unsigned *core_array,
839 const unsigned core_num, unsigned *class_id) {
842 int pqos_alloc_release(const unsigned *core_array, const unsigned core_num) {
845 int pqos_alloc_assign_pid(const unsigned technology, const pid_t *task_array,
846 const unsigned task_num, unsigned *class_id) {
849 int pqos_alloc_release_pid(const pid_t *task_array, const unsigned task_num) {
852 int pqos_init(const struct pqos_config *config) { return 0; }
853 int pqos_fini(void) { return 0; }
854 int pqos_cap_get_type(const struct pqos_cap *cap, const enum pqos_cap_type type,
855 const struct pqos_capability **cap_item) {
858 int pqos_cap_get(const struct pqos_cap **cap, const struct pqos_cpuinfo **cpu) {
862 DEF_TEST(pqos12_test_stub) {
868 RUN_TEST(pqos12_test_stub);