+DEF_TEST(rdt_config_ngroups__one_process) {
+ /* setup */
+ rdt_ctx_t *rdt = stub_rdt_setup();
+
+ oconfig_value_t values[] = {
+ {.value.string = "proc1", .type = OCONFIG_TYPE_STRING},
+ };
+ oconfig_item_t config_item = {
+ .values = values, .values_num = STATIC_ARRAY_SIZE(values),
+ };
+
+ /* check */
+ int result = rdt_config_ngroups(rdt, &config_item);
+ EXPECT_EQ_INT(0, result);
+ EXPECT_EQ_STR(values[0].value.string, rdt->ngroups[0].desc);
+ EXPECT_EQ_INT(1, rdt->num_ngroups);
+
+ /* cleanup */
+ rdt_free_ngroups(rdt);
+ stub_rdt_teardown(rdt);
+
+ return 0;
+}
+
+DEF_TEST(rdt_config_ngroups__two_groups) {
+ /* setup */
+ rdt_ctx_t *rdt = stub_rdt_setup();
+
+ oconfig_value_t values[] = {
+ {.value.string = "proc11,proc12,proc13", .type = OCONFIG_TYPE_STRING},
+ {.value.string = "proc21,proc22,proc23", .type = OCONFIG_TYPE_STRING},
+ };
+ oconfig_item_t config_item = {
+ .values = values, .values_num = STATIC_ARRAY_SIZE(values),
+ };
+
+ /* check */
+ int result = rdt_config_ngroups(rdt, &config_item);
+ EXPECT_EQ_INT(0, result);
+ EXPECT_EQ_INT(2, rdt->num_ngroups);
+ EXPECT_EQ_STR("proc11,proc12,proc13", rdt->ngroups[0].desc);
+ EXPECT_EQ_STR("proc21,proc22,proc23", rdt->ngroups[1].desc);
+ EXPECT_EQ_STR("proc11", rdt->ngroups[0].names[0]);
+ EXPECT_EQ_STR("proc12", rdt->ngroups[0].names[1]);
+ EXPECT_EQ_STR("proc13", rdt->ngroups[0].names[2]);
+ EXPECT_EQ_STR("proc21", rdt->ngroups[1].names[0]);
+ EXPECT_EQ_STR("proc22", rdt->ngroups[1].names[1]);
+ EXPECT_EQ_STR("proc23", rdt->ngroups[1].names[2]);
+
+ /* cleanup */
+ rdt_free_ngroups(rdt);
+ stub_rdt_teardown(rdt);
+
+ return 0;
+}
+
+DEF_TEST(rdt_config_ngroups__too_long_proc_name) {
+ /* setup */
+ rdt_ctx_t *rdt = stub_rdt_setup();
+
+ oconfig_value_t values[] = {
+ {.value.string = "_seventeen_chars_", .type = OCONFIG_TYPE_STRING},
+ };
+ oconfig_item_t config_item = {
+ .values = values, .values_num = STATIC_ARRAY_SIZE(values),
+ };
+
+ /* check */
+ int result = rdt_config_ngroups(rdt, &config_item);
+ EXPECT_EQ_INT(-EINVAL, result);
+
+ /* cleanup */
+ stub_rdt_teardown(rdt);
+
+ return 0;
+}
+
+DEF_TEST(rdt_config_ngroups__duplicate_proc_name_between_groups) {
+ /* setup */
+ rdt_ctx_t *rdt = stub_rdt_setup();
+
+ oconfig_value_t values[] = {
+ {.value.string = "proc11,proc12,proc", .type = OCONFIG_TYPE_STRING},
+ {.value.string = "proc21,proc,proc23", .type = OCONFIG_TYPE_STRING},
+ };
+ oconfig_item_t config_item = {
+ .values = values, .values_num = STATIC_ARRAY_SIZE(values),
+ };
+
+ /* check */
+ int result = rdt_config_ngroups(rdt, &config_item);
+ EXPECT_EQ_INT(-EINVAL, result);
+
+ /* cleanup */
+ stub_rdt_teardown(rdt);
+
+ return 0;
+}
+
+DEF_TEST(rdt_config_ngroups__duplicate_proc_name_in_group) {
+ /* setup */
+ rdt_ctx_t *rdt = stub_rdt_setup();
+
+ oconfig_value_t values[] = {
+ {.value.string = "proc11,proc,proc,proc14", .type = OCONFIG_TYPE_STRING},
+ };
+ oconfig_item_t config_item = {
+ .values = values, .values_num = STATIC_ARRAY_SIZE(values),
+ };
+
+ /* check */
+ int result = rdt_config_ngroups(rdt, &config_item);
+ EXPECT_EQ_INT(-EINVAL, result);
+
+ /* cleanup */
+ stub_rdt_teardown(rdt);
+
+ return 0;
+}
+
+DEF_TEST(rdt_config_ngroups__empty_group) {
+ /* setup */
+ rdt_ctx_t *rdt = stub_rdt_setup();
+
+ oconfig_value_t values[] = {
+ {.value.string = "proc11,proc12,proc13", .type = OCONFIG_TYPE_STRING},
+ {.value.string = "", .type = OCONFIG_TYPE_STRING},
+
+ };
+ oconfig_item_t config_item = {
+ .values = values, .values_num = STATIC_ARRAY_SIZE(values),
+ };
+
+ /* check */
+ int result = rdt_config_ngroups(rdt, &config_item);
+ EXPECT_EQ_INT(-EINVAL, result);
+
+ /* cleanup */
+ stub_rdt_teardown(rdt);
+
+ return 0;
+}
+
+DEF_TEST(rdt_config_ngroups__empty_proc_name) {
+ /* setup */
+ rdt_ctx_t *rdt = stub_rdt_setup();
+
+ oconfig_value_t values[] = {
+ {.value.string = "proc11,,proc13", .type = OCONFIG_TYPE_STRING},
+ };
+ oconfig_item_t config_item = {
+ .values = values, .values_num = STATIC_ARRAY_SIZE(values),
+ };
+
+ /* check */
+ int result = rdt_config_ngroups(rdt, &config_item);
+ EXPECT_EQ_INT(-EINVAL, result);
+
+ /* cleanup */
+ stub_rdt_teardown(rdt);
+
+ return 0;
+}
+
+DEF_TEST(rdt_pid_list_diff__all_changed) {
+ /* setup */
+ pid_t pids_array_before[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
+ pid_t pids_array_after[] = {2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007};
+ pids_list_t *pids_list_before = NULL;
+ pids_list_t *pids_list_after = NULL;
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_after); ++i) {
+ pids_list_add_pid(&pids_list_before, pids_array_before[i]);
+ pids_list_add_pid(&pids_list_after, pids_array_after[i]);
+ }
+
+ pids_list_t *new_pids = NULL;
+ size_t new_pids_count = 0;
+ pids_list_t *lost_pids = NULL;
+ size_t lost_pids_count = 0;
+
+ /* check */
+ int result = rdt_pid_list_diff(pids_list_before, pids_list_after, &new_pids,
+ &new_pids_count, &lost_pids, &lost_pids_count);
+ EXPECT_EQ_INT(0, result);
+ EXPECT_EQ_INT(STATIC_ARRAY_SIZE(pids_array_before), lost_pids_count);
+ EXPECT_EQ_INT(STATIC_ARRAY_SIZE(pids_array_after), new_pids_count);
+
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_before); ++i) {
+ EXPECT_EQ_INT(1, pids_list_contains_pid(new_pids, pids_array_after[i]));
+ EXPECT_EQ_INT(1, pids_list_contains_pid(lost_pids, pids_array_before[i]));
+ }
+
+ /* cleanup */
+ pids_list_free(pids_list_before);
+ pids_list_free(pids_list_after);
+ pids_list_free(new_pids);
+ pids_list_free(lost_pids);
+
+ return 0;
+}
+
+DEF_TEST(rdt_pid_list_diff__nothing_changed) {
+ /* setup */
+ pid_t pids_array_before[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
+ pids_list_t *pids_list_before = NULL;
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_before); ++i) {
+ pids_list_add_pid(&pids_list_before, pids_array_before[i]);
+ }
+
+ pids_list_t *new_pids = NULL;
+ size_t new_pids_count = 0;
+ pids_list_t *lost_pids = NULL;
+ size_t lost_pids_count = 0;
+
+ /* check */
+ int result = rdt_pid_list_diff(pids_list_before, pids_list_before, &new_pids,
+ &new_pids_count, &lost_pids, &lost_pids_count);
+ EXPECT_EQ_INT(0, result);
+ EXPECT_EQ_INT(0, lost_pids_count);
+ EXPECT_EQ_INT(0, new_pids_count);
+ OK(NULL == new_pids);
+ OK(NULL == lost_pids);
+
+ /* cleanup */
+ pids_list_free(pids_list_before);
+
+ return 0;
+}
+
+DEF_TEST(rdt_pid_list_diff__one_added) {
+ /* setup */
+ pid_t pids_array_before[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
+ pid_t pids_array_after[] = {1000, 1001, 1002, 1003, 1004,
+ 1005, 1006, 1007, 1008};
+ pids_list_t *pids_list_before = NULL;
+ pids_list_t *pids_list_after = NULL;
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_before); ++i)
+ pids_list_add_pid(&pids_list_before, pids_array_before[i]);
+
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_after); ++i)
+ pids_list_add_pid(&pids_list_after, pids_array_after[i]);
+
+ pids_list_t *new_pids = NULL;
+ size_t new_pids_count = 0;
+ pids_list_t *lost_pids = NULL;
+ size_t lost_pids_count = 0;
+
+ /* check */
+ int result = rdt_pid_list_diff(pids_list_before, pids_list_after, &new_pids,
+ &new_pids_count, &lost_pids, &lost_pids_count);
+ EXPECT_EQ_INT(0, result);
+ EXPECT_EQ_INT(0, lost_pids_count);
+ EXPECT_EQ_INT(1, new_pids_count);
+ EXPECT_EQ_INT(1008, new_pids->pid);
+
+ /* cleanup */
+ pids_list_free(pids_list_before);
+ pids_list_free(pids_list_after);
+ pids_list_free(new_pids);
+
+ return 0;
+}
+
+DEF_TEST(rdt_pid_list_diff__one_removed) {
+ /* setup */
+ pid_t pids_array_before[] = {1000, 1001, 1002, 1003, 1004,
+ 1005, 1006, 1007, 1008};
+ pid_t pids_array_after[] = {1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007};
+ pids_list_t *pids_list_before = NULL;
+ pids_list_t *pids_list_after = NULL;
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_before); ++i)
+ pids_list_add_pid(&pids_list_before, pids_array_before[i]);
+
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE(pids_array_after); ++i)
+ pids_list_add_pid(&pids_list_after, pids_array_after[i]);
+
+ pids_list_t *new_pids = NULL;
+ size_t new_pids_count = 0;
+ pids_list_t *lost_pids = NULL;
+ size_t lost_pids_count = 0;
+
+ /* check */
+ int result = rdt_pid_list_diff(pids_list_before, pids_list_after, &new_pids,
+ &new_pids_count, &lost_pids, &lost_pids_count);
+ EXPECT_EQ_INT(0, result);
+ EXPECT_EQ_INT(1, lost_pids_count);
+ EXPECT_EQ_INT(0, new_pids_count);
+ EXPECT_EQ_INT(1008, lost_pids->pid);
+
+ /* cleanup */
+ pids_list_free(pids_list_before);
+ pids_list_free(pids_list_after);
+ pids_list_free(lost_pids);
+
+ return 0;
+}
+