From: Michael Tremer Date: Mon, 11 Jan 2021 15:30:40 +0000 (+0000) Subject: Add tests for cgroup module X-Git-Tag: 0.9.28~1285^2~899 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab7f3f2b450728b29412915a985f97b79eaa1f20;p=pakfire.git Add tests for cgroup module Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 8667a337e..069a82b74 100644 --- a/Makefile.am +++ b/Makefile.am @@ -602,6 +602,7 @@ TESTS_ENVIRONMENT = \ topdir="$(shell pwd)" dist_check_SCRIPTS = \ + tests/python/cgroups.py \ tests/python/test.py TESTS = \ diff --git a/tests/python/cgroups.py b/tests/python/cgroups.py new file mode 100755 index 000000000..ea3cd0206 --- /dev/null +++ b/tests/python/cgroups.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 + +import os +import unittest + +import pakfire.cgroup as cgroups + +class Test(unittest.TestCase): + def setUp(self): + # Find our own cgroup + self.cgroup = cgroups.get_own_group() + + def test_find_own_group(self): + """ + Check if we found our own cgroup + """ + self.assertIsInstance(self.cgroup, cgroups.CGroup) + + def test_subgroup(self): + # Create a new sub group + subgroup = self.cgroup.create_subgroup("test-1") + self.assertIsInstance(subgroup, cgroups.CGroup) + + # Attach the test process to it + subgroup.attach_self() + + # Fetch pids + pids = subgroup.pids + + # There must be one pid in this list + self.assertTrue(len(pids) == 1) + + # The pid must be the one of this process + self.assertTrue(pids[0] == os.getpid()) + + # Can't really test killing ourselves here + #subgroup.killall() + + # Destroy it + subgroup.destroy() + + +if __name__ == "__main__": + unittest.main()