From: Tom Hromatka Date: Thu, 27 Jun 2019 17:34:00 +0000 (-0600) Subject: tests: Add functional test for basic cgget operations X-Git-Tag: v0.42.rc1~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30483060d66c2c05f74f49210527c4b75aef10d5;p=thirdparty%2Flibcgroup.git tests: Add functional test for basic cgget operations 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 Signed-off-by: Dhaval Giani --- diff --git a/tests/ftests/001-cgget-basic_cgget.py b/tests/ftests/001-cgget-basic_cgget.py new file mode 100755 index 00000000..9638335f --- /dev/null +++ b/tests/ftests/001-cgget-basic_cgget.py @@ -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 +# + +# +# 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 . +# + +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)) diff --git a/tests/ftests/Makefile.am b/tests/ftests/Makefile.am index ede06b4e..571503ba 100644 --- a/tests/ftests/Makefile.am +++ b/tests/ftests/Makefile.am @@ -19,7 +19,7 @@ # along with this library; if not, see . # -TESTS = +TESTS = 001-cgget-basic_cgget.py clean-local: clean-local-check .PHONY: clean-local-check