]> git.ipfire.org Git - pakfire.git/commitdiff
Add tests for cgroup module
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 Jan 2021 15:30:40 +0000 (15:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 Jan 2021 15:30:40 +0000 (15:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
tests/python/cgroups.py [new file with mode: 0755]

index 8667a337e8e6d71846cf61f803fe988d7526ae21..069a82b748435d841002796adc00df1c6a36161d 100644 (file)
@@ -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 (executable)
index 0000000..ea3cd02
--- /dev/null
@@ -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()