From: Kamalesh Babulal Date: Tue, 25 Apr 2023 12:36:28 +0000 (+0000) Subject: ftests: add test case to excerise cgroup_setup_mode helpers X-Git-Tag: v3.1.0~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73f594ee9784c90de3dc2dc6d566a0ebcf51b764;p=thirdparty%2Flibcgroup.git ftests: add test case to excerise cgroup_setup_mode helpers Add tests to excerise the cgroup_setup_mode() helpers pybindings is_cgroup_mode_{legacy,hybrid,unified} ----------------------------------------------------------------- Test Results: Run Date: Apr 25 12:46:29 Passed: 1 test(s) Skipped: 0 test(s) Failed: 0 test(s) ----------------------------------------------------------------- Timing Results: Test Time (sec) ---------------------------------------------------- setup 0.00 083-pybindings-helpers_cgroup_mode.py 0.00 teardown 0.00 ---------------------------------------------------- Total Run Time 0.00 Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/tests/ftests/083-pybindings-helpers_cgroup_mode.py b/tests/ftests/083-pybindings-helpers_cgroup_mode.py new file mode 100755 index 00000000..8808a03b --- /dev/null +++ b/tests/ftests/083-pybindings-helpers_cgroup_mode.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1-only +# +# Test to excerise cgroup_setup_mode() helpers +# +# Copyright (c) 2023 Oracle and/or its affiliates. +# Author: Kamalesh Babulal +# + +from cgroup import Cgroup as CgroupCli +from libcgroup import Cgroup, Mode +import consts +import ftests +import sys +import os + + +def prereqs(config): + pass + + +def setup(config): + pass + + +def test(config): + result = consts.TEST_PASSED + cause = None + + mode1 = Cgroup.cgroup_mode() + mode2 = CgroupCli.get_cgroup_mode(config) + + if mode1 != mode2: + result = consts.TEST_FAILED + cause = 'mode mismatch: libcgroup mode: {}, tests mode: {}'.format(mode1, mode2) + return result, cause + + if mode1 == Mode.CGROUP_MODE_LEGACY: + ret = Cgroup.is_cgroup_mode_legacy() + if ret is False: + result = consts.TEST_FAILED + cause = 'mode mismatch: libcgroup mode: legacy (v1) check, returned false' + elif mode1 == Mode.CGROUP_MODE_HYBRID: + ret = Cgroup.is_cgroup_mode_hybrid() + if ret is False: + result = consts.TEST_FAILED + cause = 'mode mismatch: libcgroup mode: hybrid (v1/v2) check, returned false' + elif mode1 == Mode.CGROUP_MODE_UNIFIED: + ret = Cgroup.is_cgroup_mode_unified() + if ret is False: + result = consts.TEST_FAILED + cause = 'mode mismatch: libcgroup mode: unified (v2) check, returned false' + else: + result = consts.TEST_FAILED + cause = 'Unknown libcgroup mode: {}'.format(mode1) + + return result, cause + + +def teardown(config): + pass + + +def main(config): + prereqs(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.args.num = int(os.path.basename(__file__).split('-')[0]) + sys.exit(ftests.main(config)) + +# vim: set et ts=4 sw=4: diff --git a/tests/ftests/Makefile.am b/tests/ftests/Makefile.am index c810eb64..2f82f8bb 100644 --- a/tests/ftests/Makefile.am +++ b/tests/ftests/Makefile.am @@ -101,6 +101,7 @@ EXTRA_DIST_PYTHON_TESTS = \ 078-sudo-cgcreate_systemd_scope.py \ 079-sudo-cgcreate_default_systemd_scope.py \ 080-kernel-domain_invalid.py \ + 083-pybindings-helpers_cgroup_mode.py \ 998-cgdelete-non-existing-shared-mnt-cgroup-v1.py # Intentionally omit the stress test from the extra dist # 999-stress-cgroup_init.py