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.hroma...@oracle.com>
---
 tests/ftests/001-cgget-basic_cgget.py | 68 +++++++++++++++++++++++++++
 tests/ftests/Makefile.am              |  2 +-
 2 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100755 tests/ftests/001-cgget-basic_cgget.py

diff --git a/tests/ftests/001-cgget-basic_cgget.py 
b/tests/ftests/001-cgget-basic_cgget.py
new file mode 100755
index 0000000..a8720c0
--- /dev/null
+++ b/tests/ftests/001-cgget-basic_cgget.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+#
+# Basic cgget functionality test
+#
+# Copyright (c) 2019 Oracle and/or its affiliates.  All rights reserved.
+# Author: Tom Hromatka <tom.hroma...@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>.
+#
+# SPDX-License-Identifier: GPL-2.0
+
+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 %s but received %s" % (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))
diff --git a/tests/ftests/Makefile.am b/tests/ftests/Makefile.am
index ede06b4..571503b 100644
--- a/tests/ftests/Makefile.am
+++ b/tests/ftests/Makefile.am
@@ -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
-- 
2.21.0



_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to