2 * Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License version 2.1 as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * @author Krzysztof Dynowski (k.dynowski@samsung.com)
21 * @brief Unit tests of lxcpp cgroups managment
26 #include "logger/logger.hpp"
28 #include "lxcpp/cgroups/subsystem.hpp"
39 BOOST_FIXTURE_TEST_SUITE(LxcppCGroupsSuite, Fixture)
41 using namespace lxcpp;
43 // assume cgroups are supprted by the system
44 BOOST_AUTO_TEST_CASE(GetAvailable)
46 std::vector<std::string> subs;
47 BOOST_CHECK_NO_THROW(subs = Subsystem::availableSubsystems());
48 BOOST_CHECK(subs.size() > 0);
51 LOGD(s.getName() << ": " << (s.isAttached()?s.getMountPoint():"[not attached]"));
55 BOOST_AUTO_TEST_CASE(GetCGroupsByPid)
57 std::vector<std::string> cg;
58 BOOST_CHECK_NO_THROW(cg=Subsystem::getCGroups(::getpid()));
59 BOOST_CHECK(cg.size() > 0);
62 BOOST_AUTO_TEST_CASE(SubsysAttach)
64 Subsystem sub("freezer");
65 BOOST_CHECK_MESSAGE(sub.getName() == "freezer", "freezer not equal");
66 BOOST_CHECK_MESSAGE(sub.isAvailable(), "freezer not found");
68 if (!sub.isAvailable()) return ;
71 if (sub.isAttached()) {
72 std::string mp = sub.getMountPoint();
73 BOOST_CHECK_NO_THROW(Subsystem::detach(mp));
74 BOOST_CHECK_NO_THROW(Subsystem::attach(mp, {sub.getName()}));
77 std::string mp = "/sys/fs/cgroup/" + sub.getName();
78 BOOST_CHECK_NO_THROW(Subsystem::attach(mp, {sub.getName()}));
79 BOOST_CHECK_NO_THROW(Subsystem::detach(mp));
83 BOOST_AUTO_TEST_SUITE_END()