]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tests: Add functional test for basic cgget operations
authorTom Hromatka <tom.hromatka@oracle.com>
Thu, 27 Jun 2019 17:34:00 +0000 (11:34 -0600)
committerDhaval Giani <dhaval.giani@oracle.com>
Tue, 17 Sep 2019 22:14:02 +0000 (15:14 -0700)
This commit adds a functional test for a basic cgget call.  The
test utilizes the new functional text framework and lxc
containers to establish a non-destructive cgroup test
environment.

Tests added:
    001-cgget-basic_cgget.py - Test simple cgget functionality

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Signed-off-by: Dhaval Giani <dhaval.giani@oracle.com>
tests/ftests/001-cgget-basic_cgget.py [new file with mode: 0755]
tests/ftests/Makefile.am

diff --git a/tests/ftests/001-cgget-basic_cgget.py b/tests/ftests/001-cgget-basic_cgget.py
new file mode 100755 (executable)
index 0000000..9638335
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+#
+# Basic cgget functionality test
+#
+# Copyright (c) 2019 Oracle and/or its affiliates.  All rights reserved.
+# Author: Tom Hromatka <tom.hromatka@oracle.com>
+#
+
+#
+# This library is free software; you can redistribute it and/or modify it
+# under the terms of version 2.1 of the GNU Lesser General Public License as
+# published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+# for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, see <http://www.gnu.org/licenses>.
+#
+
+from cgroup import Cgroup
+import consts
+import ftests
+import os
+import sys
+
+CONTROLLER='cpu'
+CGNAME="001cgget"
+
+SETTING='cpu.shares'
+VALUE='512'
+
+def setup(config):
+    Cgroup.create(config, CONTROLLER, CGNAME)
+    Cgroup.set(config, CGNAME, SETTING, VALUE)
+
+def test(config):
+    result = consts.TEST_PASSED
+    cause = None
+
+    value = Cgroup.get(config, controller=None, cgname=CGNAME,
+                       setting=SETTING, print_headers=False,
+                       values_only=True)
+
+    if value != VALUE:
+        result = consts.TEST_FAILED
+        cause = "cgget expected {} but received {}".format(VALUE, value)
+
+    return result, cause
+
+def teardown(config):
+    Cgroup.delete(config, CONTROLLER, CGNAME)
+
+def main(config):
+    setup(config)
+    [result, cause] = test(config)
+    teardown(config)
+
+    return [result, cause]
+
+if __name__ == '__main__':
+    config = ftests.parse_args()
+    # this test was invoked directly.  run only it
+    config.test_num = int(os.path.basename(__file__).split('-')[0])
+    sys.exit(ftests.main(config))
index ede06b4e26330c76ff67bd1942180c7fde6ea81b..571503ba5909768006987108be0301d056723f78 100644 (file)
@@ -19,7 +19,7 @@
 # along with this library; if not, see <http://www.gnu.org/licenses>.
 #
 
-TESTS =
+TESTS = 001-cgget-basic_cgget.py
 
 clean-local: clean-local-check
 .PHONY: clean-local-check