6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss This file is part of systemd.
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss Copyright 2013 David Strauss
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss systemd is free software; you can redistribute it and/or modify it
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss under the terms of the GNU Lesser General Public License as published by
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss the Free Software Foundation; either version 2.1 of the License, or
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss (at your option) any later version.
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss systemd is distributed in the hope that it will be useful, but
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss WITHOUT ANY WARRANTY; without even the implied warranty of
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss Lesser General Public License for more details.
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss You should have received a copy of the GNU Lesser General Public License
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss along with systemd; If not, see <http://www.gnu.org/licenses/>.
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering Unit *son, *daughter, *parent, *root, *grandchild, *parent_deep;
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss /* Prepare the manager. */
0d8c31ff7237149b505290652864b4e7e866b2a7Zbigniew Jędrzejewski-Szmek assert_se(set_unit_path(TEST_DIR) >= 0);
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss puts("manager_new: Permission denied. Skipping test.");
9ded9cd14cc03c67291b10a5c42ce5094ba0912fLennart Poettering /* Turn off all kinds of default accouning, so that we can
9ded9cd14cc03c67291b10a5c42ce5094ba0912fLennart Poettering * verify the masks resulting of our configuration and nothing
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss assert_se(manager_startup(m, serial, fdset) >= 0);
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss /* Load units and verify hierarchy. */
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss assert_se(manager_load_unit(m, "parent.slice", NULL, NULL, &parent) >= 0);
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss assert_se(manager_load_unit(m, "son.service", NULL, NULL, &son) >= 0);
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss assert_se(manager_load_unit(m, "daughter.service", NULL, NULL, &daughter) >= 0);
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering assert_se(manager_load_unit(m, "grandchild.service", NULL, NULL, &grandchild) >= 0);
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering assert_se(manager_load_unit(m, "parent-deep.slice", NULL, NULL, &parent_deep) >= 0);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(parent->load_state == UNIT_LOADED);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(son->load_state == UNIT_LOADED);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(daughter->load_state == UNIT_LOADED);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(grandchild->load_state == UNIT_LOADED);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(parent_deep->load_state == UNIT_LOADED);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(UNIT_DEREF(son->slice) == parent);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(UNIT_DEREF(daughter->slice) == parent);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(UNIT_DEREF(parent_deep->slice) == parent);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(UNIT_DEREF(grandchild->slice) == parent_deep);
6414b7c981378a6eef480f6806d7cbfc98ca22a1David Strauss /* Verify per-unit cgroups settings. */
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_own_mask(son) == (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT));
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_own_mask(daughter) == 0);
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_own_mask(grandchild) == 0);
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_own_mask(parent_deep) == CGROUP_MASK_MEMORY);
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_own_mask(parent) == CGROUP_MASK_BLKIO);
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering /* Verify aggregation of member masks */
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(unit_get_members_mask(son) == 0);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(unit_get_members_mask(daughter) == 0);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(unit_get_members_mask(grandchild) == 0);
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(unit_get_members_mask(parent_deep) == 0);
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_members_mask(parent) == (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_MEMORY));
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_members_mask(root) == (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY));
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering /* Verify aggregation of sibling masks. */
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_siblings_mask(son) == (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_MEMORY));
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_siblings_mask(daughter) == (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_MEMORY));
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(unit_get_siblings_mask(grandchild) == 0);
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_siblings_mask(parent_deep) == (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_MEMORY));
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_siblings_mask(parent) == (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY));
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_siblings_mask(root) == (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY));
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering /* Verify aggregation of target masks. */
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_target_mask(son) == ((CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_MEMORY) & m->cgroup_supported));
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_target_mask(daughter) == ((CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_MEMORY) & m->cgroup_supported));
bdf7026e9557349cd3eeb291c01655d5f2a55db8Thomas Hindoe Paaboel Andersen assert_se(unit_get_target_mask(grandchild) == 0);
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_target_mask(parent_deep) == ((CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_MEMORY) & m->cgroup_supported));
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_target_mask(parent) == ((CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY) & m->cgroup_supported));
efdb02375beb0a940c3320865572913780b4d7deLennart Poettering assert_se(unit_get_target_mask(root) == ((CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY) & m->cgroup_supported));