Tom Hromatka [Mon, 12 Apr 2021 15:25:00 +0000 (09:25 -0600)]
wrapper.c: Fix fprintf argument warning
Fix a warning in cgroup_add_value_string() where '%d' was
being passed to fprintf when it should have been using '%ld'.
wrapper.c: In function ‘cgroup_add_value_string’:
wrapper.c:207:51: warning: format ‘%d’ expects argument of type ‘int’,
but argument 3 has type ‘long unsigned int’ [-Wformat=]
207 | fprintf(stderr, "value exceeds the maximum of %d
characters\n",
| ~^
| |
| int
| %ld
208 | sizeof(cntl_value->value) - 1);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long unsigned int
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 12 Apr 2021 15:18:56 +0000 (09:18 -0600)]
api.c: Fix string truncation warnings
Fix two snprintf string truncation warnings in
cg_build_path_locked().
api.c:1475:38: warning: ‘snprintf’ output may be truncated before the
last format character [-Wformat-truncation=]
1475 | snprintf(path, FILENAME_MAX, "%s/",
| ^
api.c:1475:5: note: ‘snprintf’ output between 2 and 4097 bytes into a
destination of size 4096
1475 | snprintf(path, FILENAME_MAX, "%s/",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1476 | cg_mount_table[i].mount.path);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
api.c:1470:40: warning: ‘/’ directive output may be truncated writing 1
byte into a region of size between 0 and 4095 [-Wformat-truncation=]
1470 | snprintf(path, FILENAME_MAX, "%s/%s/",
| ^
api.c:1470:5: note: ‘snprintf’ output 3 or more bytes (assuming 4098)
into a destination of size 4096
1470 | snprintf(path, FILENAME_MAX, "%s/%s/",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1471 | cg_mount_table[i].mount.path,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1472 | cg_namespace_table[i]);
| ~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Thu, 25 Mar 2021 16:35:32 +0000 (16:35 +0000)]
ftests: Add an lscgroup test with multiple '-g' flags
Add an lscgroup test with multiple '-g' flags.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 25 16:35:47
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 14.12
032-lscgroup-multiple_g_flags.py 4.63
teardown 0.00
---------------------------------------------------------
Total Run Time 18.75
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Thu, 25 Mar 2021 16:34:47 +0000 (16:34 +0000)]
ftests: Add an lscgroup test with a single '-g' flag
Add a test that invokes lscgroup with a single '-g' flag.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 25 16:34:25
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 18.41
031-lscgroup-g_flag.py 0.58
teardown 0.00
---------------------------------------------------------
Total Run Time 18.98
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 24 Mar 2021 19:12:44 +0000 (19:12 +0000)]
ftests: Add an lssubsys -a functional test
Add a functional test that exercises 'lssubsys -a'
-----------------------------------------------------------------
Test Results:
Run Date: Mar 24 19:12:33
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 20.06
030-lssubsys-lssubsys_all.py 0.18
teardown 0.00
---------------------------------------------------------
Total Run Time 20.23
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 24 Mar 2021 19:43:42 +0000 (19:43 +0000)]
cgroup.py: Add method to parse /proc/mounts for cgroup mounts
Add a method - Cgroup.get_cgroup_mounts() - that can parse
/proc/mounts and return a list of CgroupMount instances.
This method will be useful for validating results from lssubsys.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 31 Mar 2021 16:58:48 +0000 (16:58 +0000)]
gtest: Add unit test for cgset's parse_r_flag()
Add a unit test for parse_r_flag() in cgset.c.
[----------] 1 test from CgsetParseRFlagTest
[ RUN ] CgsetParseRFlagTest.EqualCharInValue
[ OK ] CgsetParseRFlagTest.EqualCharInValue (0 ms)
[----------] 1 test from CgsetParseRFlagTest (0 ms total)
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 31 Mar 2021 16:44:11 +0000 (16:44 +0000)]
tools: Create a cgset library for testing purposes
Create libcgset.la so that functions within cgset can be
unit tested.
A functional test would be preferable in this case, but I'm
looking to test a very specific scenario - where there's an
'=' sign in the value of a setting's name/value pair. To the
best of my knowledge, only the rdma (v1) and io (v2)
controllers have settings that utilize an '=' in such a fashion.
I can't think of an easy way to test rdma across our test fleet,
and our automated systems don't support the v2 io controller
yet. Thus a unit test for now.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 30 Mar 2021 18:54:06 +0000 (18:54 +0000)]
cgset: Fix parsing of name/values with an '=' in the value
Fix parsing of name/value pairs that contain an '='
character in the value string. For example, the io.max
setting utilizes the '=' character:
cgset -r io.max="8:16 wbps=1024" foo
Fixes: https://github.com/libcgroup/libcgroup/issues/33 Reported-by: Santiago Ruano Rincón <santiago.ruano-rincon@imt-atlantique.fr> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 29 Mar 2021 16:46:52 +0000 (16:46 +0000)]
bootstrap: github: Ignore systemd hierarchy
Ignore the "name=systemd" hierarchy by setting the autoconf
--enable-opaque-hierarchy flag equal to "name=systemd". This
instructs libcgroup to ignore mounts named "name=systemd" and
thus these mounts aren't added to the cg_mount_table[].
Suggested-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 29 Mar 2021 17:54:09 +0000 (17:54 +0000)]
gunit: Ignore systemd hierarchies in test 007
Now that systemd hierarchies are being ignored via the
OPAQUE_HIERARCHY setting, update unit test 007 to ensure
that systemd hierachies are not added to the mount table.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 23 Mar 2021 16:12:13 +0000 (16:12 +0000)]
ftests: Add a simple cgclear functional test
Add a test that invokes cgclear. Note that this test is especially
destructive and is skipped by default. Github Actions invokes it
separately as the final step.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 23 16:07:55
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 0.00
028-cgclear-basic_cgclear.py 1.80
teardown 0.00
---------------------------------------------------------
Total Run Time 1.80
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 18:51:45 +0000 (18:51 +0000)]
ftests: Add cgset invalid options test
Add a test that tests various invalid flag combinations to cgset.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 08 17:39:20
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 18.15
027-cgset-invalid_options.py 0.94
teardown 0.00
---------------------------------------------------------
Total Run Time 19.09
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 18:48:04 +0000 (18:48 +0000)]
ftests: Add a cgset test with multiple '-r' flags and cgroups
Add a cgset test that provides multiple '-r' flags to multiple
cgroups.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 08 19:30:43
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 15.33
026-cgset-multiple_r_multiple_cgroup.py 5.14
teardown 0.00
---------------------------------------------------------
Total Run Time 20.47
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 18:47:03 +0000 (18:47 +0000)]
ftests: Add multiple cgroup cgset set
Add a test that passes in multiple cgroups to cgset.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 08 19:14:20
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 19.85
025-cgset-multiple_cgroups.py 0.85
teardown 0.00
---------------------------------------------------------
Total Run Time 20.69
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 17:36:28 +0000 (17:36 +0000)]
ftests: Add cgset --copy-from test
Add a test that utilizes the cgset --copy-from flag.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 02 20:24:45
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 22.79
023-cgset-copy_from.py 1.13
teardown 0.00
---------------------------------------------------------
Total Run Time 23.93
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 17:32:18 +0000 (17:32 +0000)]
ftests: Add multiple -r flag cgset test
Add a test that provides multiple -r flags to cgset
-----------------------------------------------------------------
Test Results:
Run Date: Mar 02 19:04:36
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 14.53
022-cgset-multiple_r_flag.py 0.72
teardown 0.00
---------------------------------------------------------
Total Run Time 15.25
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 17:16:30 +0000 (17:16 +0000)]
cgroup.py: Allow for multiple cgroup names to be passed to cgset
Add support for multiple cgroup names - or no cgroup names -
to be passed into Cgroup.set(). cgset allows multiple cgroup
names to be supplied with either the '-r' flag or the '--copy-from'
option. No cgroup needs to be provided when '-h' is invoked.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 18:21:25 +0000 (18:21 +0000)]
gunit: Update test 009 to match cgroup_set_values_recursive()
cgroup_set_values_recursive() had a parameter added to ignore
the dirty flag on write failures. This is needed by
cgroup_modify_cgroup() as some writes may be expected to fail.
Update test 009 to utilize this new flag. Note that
cgroup_set_values_recursive() is now being heavily tested by
the functional tests, so this unit test is no longer the primary
means of testing this function.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 02:15:51 +0000 (02:15 +0000)]
ftests: Add invalid parameter test for cgconfigparser
Add a test that provides invalid parameters into cgconfigparser.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 10 02:15:56
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 13.46
021-cgconfig-invalid_options.py 0.31
teardown 0.00
---------------------------------------------------------
Total Run Time 13.77
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 00:18:02 +0000 (00:18 +0000)]
ftests: Add a cgconfigparser test that sets tasks owner/permissions
Add a cgconfigparser test that sets the owner, group, and
permissions on the tasks file. This test runs on cgroup v1
only.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 10 00:18:10
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 14.47
020-cgconfig-tasks_perms_owner.py 7.14
teardown 0.00
---------------------------------------------------------
Total Run Time 21.61
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 9 Mar 2021 22:30:33 +0000 (22:30 +0000)]
ftests: Add a cgconfigparser owner, fperm, and dperm test
Add a cgconfigparser test that verifies that the owner,
group, file permissions, and directory permissions are
properly set.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 09 22:29:07
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 20.58
019-cgconfig-uidgid_dperm_fperm.py 2.51
teardown 0.00
---------------------------------------------------------
Total Run Time 23.10
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 9 Mar 2021 19:50:11 +0000 (19:50 +0000)]
ftests: Add a cgconfigparser test that loads a directory
Add a cgconfigparser test that loads its configuration files
from a specified directory.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 09 19:49:49
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 21.22
018-cgconfig-load_dir.py 0.94
teardown 0.00
---------------------------------------------------------
Total Run Time 22.16
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 9 Mar 2021 19:17:49 +0000 (19:17 +0000)]
ftests: Add a simple cgconfigparser test
Add a simple cgconfigparser test that operates on a
single configuration file.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 09 19:19:17
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 17.78
017-cgconfig-load_file.py 0.70
teardown 0.00
---------------------------------------------------------
Total Run Time 18.48
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Mar 2021 18:20:24 +0000 (18:20 +0000)]
api.c: Don't fail a recursive write if value isn't dirty
When cgroup_modify_cgroup() invokes cgroup_set_values_recursive(),
some of the settings within the cgroup may not be writable. Avoid
failing the entire write by ignoring write failures on settings that
do not explicitly have the dirty flag set.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Feb 2021 17:25:10 +0000 (17:25 +0000)]
cgget: Major refactor
Previously cgget used data structures unlike anywhere else
within libcgroup. cgget had arrays of strings to hold the
list of controllers, settings, and values.
Update cgget to utilize struct cgroup and struct
cgroup_controller.
This patch is intended to have no functional changes.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 8 Feb 2021 23:05:24 +0000 (16:05 -0700)]
wrapper.c: Add support for empty values in cgroup_add_value_string()
cgroup_add_value_string() is the fundamental building block
for adding a name/value pair to a cgroup_controller struct.
Add support for a NULL value field.
Currently it only supports adding a valid value, but in a
subsequent commit, cgget will utilize this function to build
up a hierarchy of cgroups, controllers, and setting names.
The values are NULL at the time the struct are populated and
will be read from sysfs at a later time.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 9 Feb 2021 23:23:10 +0000 (23:23 +0000)]
ftests: Add cgget invalid parameter test
Add a cgget test that passes in various invalid parameter
combinations.
-----------------------------------------------------------------
Test Results:
Run Date: Feb 09 23:24:14
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 18.89
016-cgget-invalid_options.py 0.93
teardown 0.00
---------------------------------------------------------
Total Run Time 19.82
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Thu, 11 Feb 2021 19:28:18 +0000 (19:28 +0000)]
ftests: Add cgget '-a' test
Add a cgget test that utilizes the '-a' flag.
-----------------------------------------------------------------
Test Results:
Run Date: Feb 11 19:27:39
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 20.61
014-cgget-a_flag.py 1.01
teardown 0.00
---------------------------------------------------------
Total Run Time 21.62
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Thu, 11 Feb 2021 00:00:48 +0000 (00:00 +0000)]
ftests: Add multiline cgget test
Add a cgget test that receives a multiline setting.
-----------------------------------------------------------------
Test Results:
Run Date: Feb 11 00:00:16
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 16.49
015-cgget-multiline_r_flag.py 0.63
teardown 0.00
---------------------------------------------------------
Total Run Time 17.12
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 9 Feb 2021 22:35:05 +0000 (22:35 +0000)]
ftests: Add cgget test with multiple '-g' flags
Add cgget test with multiple '-g' flags. This test verifies
the following cgget operation:
$ cgget -g freezer -g cpu 013cgget
-----------------------------------------------------------------
Test Results:
Run Date: Feb 09 22:35:21
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 22.29
013-cgget-multiple_g_flags.py 1.18
teardown 0.00
---------------------------------------------------------
Total Run Time 23.47
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
-----------------------------------------------------------------
Test Results:
Run Date: Feb 09 21:39:23
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 16.92
012-cgget-multiple_r_flags2.py 1.83
teardown 0.00
---------------------------------------------------------
Total Run Time 18.75
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
-----------------------------------------------------------------
Test Results:
Run Date: Feb 09 21:24:10
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 17.28
011-cgget-r_flag_two_cgroups.py 1.47
teardown 0.00
---------------------------------------------------------
Total Run Time 18.76
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 9 Feb 2021 21:04:21 +0000 (21:04 +0000)]
ftests: Add cgget test with '-g' <controller>:<cgroup> flag
Add a test that exercises the '-g' <controller>:<cgroup> option
in cgget. This test verifies the following cgget operation:
$ cgget -g cpu:010cgget
-----------------------------------------------------------------
Test Results:
Run Date: Feb 09 21:04:46
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 20.73
010-cgget-g_flag_controller_and_cgroup.py 0.60
teardown 0.00
---------------------------------------------------------
Total Run Time 21.33
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 9 Feb 2021 20:49:43 +0000 (20:49 +0000)]
ftests: Add cgget test with '-g' <controller> flag
Add a test that exercises the '-g' <controller> option
in cgget. This test verifies the following cgget operation:
$ cgget -g cpu 009cgget
-----------------------------------------------------------------
Test Results:
Run Date: Feb 09 20:49:33
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 21.28
009-cgget-g_flag_controller_only.py 0.57
teardown 0.00
---------------------------------------------------------
Total Run Time 21.85
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
-----------------------------------------------------------------
Test Results:
Run Date: Feb 09 20:48:45
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 18.71
008-cgget-multiple_r_flags.py 0.78
teardown 0.00
---------------------------------------------------------
Total Run Time 19.49
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Feb 2021 20:29:13 +0000 (20:29 +0000)]
ftests: Throw an exception if len(stderr) > 0
To better facilitate error handling, throw a RunError
if the stderr has been populated.
cgclassify currently prints warnings to stderr if a
setting isn't in the allow or deny list; ignore these
warnings for now. Also, non-containerized Github
Actions runs complain about missing coverage files for
cgget; ignore those errors.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 10 Feb 2021 20:25:22 +0000 (20:25 +0000)]
ftests: Clean up handling of bytes vs string
The conversion of bytes to string was being done
piecemeal within the functional tests. Consolidate
these conversions all into one location within the
run() method.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 1 Mar 2021 16:38:58 +0000 (16:38 +0000)]
ftests: Add cgroup v2 cgrules test
Add a simple cgrulesengd tests. Note that it cannot run within
a container.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 01 16:56:22
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 0.00
007-cgrules-basic_cgrules_v2.py 7.13
teardown 0.00
---------------------------------------------------------
Total Run Time 7.13
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Mon, 1 Mar 2021 16:38:03 +0000 (16:38 +0000)]
ftests: Add cgroup v1 cgrules test
Add a simple cgrulesengd tests. Note that it cannot run within
a container.
-----------------------------------------------------------------
Test Results:
Run Date: Mar 01 16:43:17
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------------------
setup 0.00
006-cgrules-basic_cgrules_v1.py 5.21
teardown 0.00
---------------------------------------------------------
Total Run Time 5.21
Tom Hromatka [Mon, 1 Mar 2021 16:37:38 +0000 (16:37 +0000)]
ftests: Clean up a few exceptions
In the ftests and process files, two exceptions were
erroneously throwing ValueException rather than
ValueError. Fix this.
In CgroupVersion.get_version(), it returned CGROUP_UNK
if it couldn't determine the version. Make this method
more pythonic by raising a ValueError exception.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 23 Feb 2021 20:47:38 +0000 (13:47 -0700)]
api.c: Fix erroneous error handling in cgroup_set_values_recursive()
Ignore the positive length returned by asprintf() and only act
upon the error code returned from cg_set_control_value(). Previously
cgroup_set_values_recursive() mishandled the error handling when
the value's dirty flag was set.
Reported-by: Bharani viswas <bharani.viswas@gmail.com> Fixes: 092e4aeb0416f ("api.c: Refactor duplicate logic in cgroup modify and create") Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Tue, 23 Feb 2021 20:55:40 +0000 (13:55 -0700)]
gunit: Update test 009 to better test dirty flag
When the dirty flag is set, cgroup_set_values_recursive()
was erroneously failing the recursive setting of values.
There were two problems in the unit test that caused this to
be missed:
1. The dirty flag wasn't being set
2. If fgets() returned a NULL ptr, the contents of the
settings file weren't being checked
Reported-by: Bharani viswas <bharani.viswas@gmail.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 3 Feb 2021 17:32:14 +0000 (10:32 -0700)]
ftests: Make the Process() class instantiable
Make the process class instantiable so that it can
better manage its list of children processes. This
helps ensure that individual tests don't collide with
each other.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 3 Feb 2021 17:07:36 +0000 (10:07 -0700)]
ftests: Ensure the deny list file exists
It's possible that the libcgroup tests are being run
on a system that doesn't have libcgroup installed.
Ensure that the deny list file (currently named
cgsnapshot_blacklist.conf but slated to be renamed)
exists.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 3 Feb 2021 17:00:52 +0000 (10:00 -0700)]
ftests: Use sudo for many cgroup commands when not in a container
When not running in a container, prepend 'sudo' to the
front of cgcreate, cgdelete, cgset, and cgclassify.
It would be advantageous to properly utilize permissions
within Linux so that we don't need to 'sudo' these
commands, but that's more of a kernel/sysfs/cgroups
issue than a libcgroup issue. (Yes, libcgroup does allow
for setting owners and permissions, so someday we should
test this, but that's not a high priority at present.)
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 3 Feb 2021 16:54:55 +0000 (09:54 -0700)]
ftests: Test 004 must be run within a container
Test 004-cgsnapshot-basic_snapshot_v1.py must be
run within a container because the cgsnapshot
data will vary slightly when inside/outside of a
container. Add a check to its prereqs function
to enforce this.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Wed, 3 Feb 2021 16:42:44 +0000 (09:42 -0700)]
ftests: Add --container and --no-container flags
In preparation of running the tests outside of a
container, add two flags to ftests.py: --container
and --no-container. As the names imply, these flags
are used to specify whether the tests should be
containerized or not.
Note1: Some tests (cgrulesengd) will only work
in a non-containerized environment.
Note2: Running the tests in a non-containerized
environment could be destructive to a
system as cgroup changes could be made that
adversely affect the entire system.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Tom Hromatka [Thu, 24 Dec 2020 21:13:40 +0000 (21:13 +0000)]
ftests: Fix failure cause when multiple tests don't pass
When multiple tests don't pass, the last failure_cause
recorded was the one being displayed. Append the
failure_cause to the failed_tests[] and skipped_tests[]
arrays, so that each failure is properly saved and
reported.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>