void test_cgroup_name_new (void) { CGroupName *cgname; nih_local char *parent = NULL; TEST_FUNCTION ("cgroup_name_new"); parent = nih_strdup (NULL, "a parent object"); TEST_NE_P (parent, NULL); TEST_FEATURE ("no parent, name"); TEST_ALLOC_FAIL { cgname = cgroup_name_new (NULL, "foo."); if (test_alloc_failed) { TEST_EQ_P (cgname, NULL); continue; } TEST_NE_P (cgname, NULL); TEST_ALLOC_SIZE (cgname, sizeof (CGroupName)); TEST_ALLOC_PARENT (cgname, NULL); TEST_EQ_STR (cgname->name, "foo."); TEST_ALLOC_SIZE (cgname->name, 1+strlen ("foo.")); TEST_ALLOC_PARENT (cgname->name, cgname); TEST_LIST_EMPTY (&cgname->settings); } TEST_FEATURE ("parent, name"); TEST_ALLOC_FAIL { cgname = cgroup_name_new (parent, "bar"); if (test_alloc_failed) { TEST_EQ_P (cgname, NULL); continue; } TEST_NE_P (cgname, NULL); TEST_ALLOC_SIZE (cgname, sizeof (CGroupName)); TEST_ALLOC_PARENT (cgname, parent); TEST_EQ_STR (cgname->name, "bar"); TEST_ALLOC_SIZE (cgname->name, 1+strlen ("bar")); TEST_ALLOC_PARENT (cgname->name, cgname); TEST_LIST_EMPTY (&cgname->settings); } }
void test_cgroup_new (void) { nih_local char *parent = NULL; CGroup *cgroup; TEST_FUNCTION ("cgroup_new"); parent = nih_strdup (NULL, "a parent object"); TEST_NE_P (parent, NULL); TEST_FEATURE ("no parent, controller"); TEST_ALLOC_FAIL { cgroup = cgroup_new (NULL, "cpuset"); if (test_alloc_failed) { TEST_EQ_P (cgroup, NULL); continue; } TEST_NE_P (cgroup, NULL); TEST_ALLOC_SIZE (cgroup, sizeof (CGroup)); TEST_ALLOC_PARENT (cgroup, NULL); TEST_EQ_STR (cgroup->controller, "cpuset"); TEST_ALLOC_SIZE (cgroup->controller, 1+strlen ("cpuset")); TEST_ALLOC_PARENT (cgroup->controller, cgroup); TEST_LIST_EMPTY (&cgroup->names); nih_free (cgroup); } TEST_FEATURE ("parent, controller"); TEST_ALLOC_FAIL { cgroup = cgroup_new (parent, "perf_event"); if (test_alloc_failed) { TEST_EQ_P (cgroup, NULL); continue; } TEST_NE_P (cgroup, NULL); TEST_ALLOC_SIZE (cgroup, sizeof (CGroup)); TEST_ALLOC_PARENT (cgroup, parent); TEST_EQ_STR (cgroup->controller, "perf_event"); TEST_ALLOC_SIZE (cgroup->controller, 1+strlen ("perf_event")); TEST_ALLOC_PARENT (cgroup->controller, cgroup); TEST_LIST_EMPTY (&cgroup->names); nih_free (cgroup); } }
void test_operator_events (void) { EventOperator *root, *oper1, *oper2, *oper3, *oper4, *oper5, *oper6; Event *event1, *event2, *event3; NihList *list = NULL; Blocked *blocked; TEST_FUNCTION ("event_operator_events"); root = event_operator_new (NULL, EVENT_OR, NULL, NULL); oper1 = event_operator_new (root, EVENT_AND, NULL, NULL); oper2 = event_operator_new (root, EVENT_AND, NULL, NULL); oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL); oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL); oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL); oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL); nih_tree_add (&root->node, &oper1->node, NIH_TREE_LEFT); nih_tree_add (&root->node, &oper2->node, NIH_TREE_RIGHT); nih_tree_add (&oper1->node, &oper3->node, NIH_TREE_LEFT); nih_tree_add (&oper1->node, &oper4->node, NIH_TREE_RIGHT); nih_tree_add (&oper2->node, &oper5->node, NIH_TREE_LEFT); nih_tree_add (&oper2->node, &oper6->node, NIH_TREE_RIGHT); root->value = TRUE; oper1->value = TRUE; oper3->value = TRUE; oper3->event = event1 = event_new (NULL, "foo", NULL); event_block (oper3->event); oper4->value = TRUE; oper4->event = event2 = event_new (NULL, "bar", NULL); event_block (oper4->event); oper6->value = TRUE; oper6->event = event3 = event_new (NULL, "bilbo", NULL); event_block (oper6->event); /* Check that the events are appended in tree order to the list * and each event is referenced and blocked; the event that was * matched, but not in the operator tree, should not be added. */ TEST_FEATURE ("with matches in tree"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { list = nih_list_new (NULL); } event_operator_events (root, NULL, list); TEST_LIST_NOT_EMPTY (list); blocked = (Blocked *)list->next; TEST_ALLOC_SIZE (blocked, sizeof (Blocked)); TEST_EQ (blocked->type, BLOCKED_EVENT); TEST_EQ_P (blocked->event, oper3->event); TEST_EQ (blocked->event->blockers, 2); event_unblock (blocked->event); nih_free (blocked); blocked = (Blocked *)list->next; TEST_ALLOC_SIZE (blocked, sizeof (Blocked)); TEST_EQ (blocked->type, BLOCKED_EVENT); TEST_EQ_P (blocked->event, oper4->event); TEST_EQ (blocked->event->blockers, 2); event_unblock (blocked->event); nih_free (blocked); TEST_LIST_EMPTY (list); TEST_EQ (oper6->event->blockers, 1); nih_free (list); } /* Check that if no events are matched, the list remains empty. */ TEST_FEATURE ("with no matches"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { list = nih_list_new (NULL); } event_operator_events (oper5, NULL, list); TEST_LIST_EMPTY (list); TEST_EQ (oper3->event->blockers, 1); TEST_EQ (oper4->event->blockers, 1); TEST_EQ (oper6->event->blockers, 1); nih_free (list); } nih_free (root); nih_free (event1); nih_free (event2); nih_free (event3); }