]> git.ipfire.org Git - thirdparty/libcgroup.git/log
thirdparty/libcgroup.git
5 years agoutils.py: Add functions to get permissions, users, and groups
Tom Hromatka [Tue, 9 Mar 2021 22:12:39 +0000 (22:12 +0000)] 
utils.py: Add functions to get permissions, users, and groups

Add a few functions to utils.py to get file permissions, owners,
and convert usernames to uids and group names to gids.

Functions added:
get_file_owner_uid()
get_file_owner_username()
get_file_owner_gid()
get_file_owner_group_name()
get_file_permissions()

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add a cgconfigparser test that loads a directory
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>
5 years agoftests: Add a simple cgconfigparser test
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>
5 years agocgroup.py: Add method to get a controller's mount point
Tom Hromatka [Wed, 10 Mar 2021 02:09:18 +0000 (02:09 +0000)] 
cgroup.py: Add method to get a controller's mount point

Add a static method to the Cgroup class to get a controller's
mount point.  Works with both cgroup v1 and cgroup v2.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agocgroup.py: Add support for cgconfigparser
Tom Hromatka [Tue, 9 Mar 2021 19:16:56 +0000 (19:16 +0000)] 
cgroup.py: Add support for cgconfigparser

Add support for running cgconfigparser in the functional
tests.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoapi.c: Don't fail a recursive write if value isn't dirty 30/head
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>
5 years agobootstrap: Use main branch of libcgroup-tests
Tom Hromatka [Mon, 1 Mar 2021 20:51:24 +0000 (13:51 -0700)] 
bootstrap: Use main branch of libcgroup-tests

The default branch of libcgroup-tests has been renamed to
main.  Utilize this branch.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #27 from drakenclimber/issues/daemoncodecov
Tom Hromatka [Mon, 1 Mar 2021 18:01:20 +0000 (11:01 -0700)] 
Merge pull request #27 from drakenclimber/issues/daemoncodecov

Makefile: Run code coverage on the daemon folder

5 years agoMakefile: Run code coverage on the daemon folder 27/head
Tom Hromatka [Mon, 22 Feb 2021 19:40:07 +0000 (19:40 +0000)] 
Makefile: Run code coverage on the daemon folder

Code coverage was not being gathered for src/daemon.
Add code coverage support for this directory.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #26 from drakenclimber/issues/cgget-refactor2
Tom Hromatka [Mon, 1 Mar 2021 17:44:05 +0000 (10:44 -0700)] 
Merge pull request #26 from drakenclimber/issues/cgget-refactor2

Refactor cgget

5 years agocgget: Major refactor 26/head
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>
5 years agowrapper.c: Add support for empty values in cgroup_add_value_string()
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>
5 years agoapi.c: Expose cgroup_test_subsys_mounted() to users of libcgroup.la
Tom Hromatka [Wed, 10 Feb 2021 17:21:23 +0000 (17:21 +0000)] 
api.c: Expose cgroup_test_subsys_mounted() to users of libcgroup.la

Remove the static qualifier from cgroup_test_subsys_mounted().  As
part of the cgget refactor, cgget will utilize this function.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoapi.c: Expose cgroup_fill_cgc() to users of libcgroup.la
Tom Hromatka [Mon, 8 Feb 2021 22:58:44 +0000 (15:58 -0700)] 
api.c: Expose cgroup_fill_cgc() to users of libcgroup.la

Remove the static qualifier from cgroup_fill_cgc().  As part
of the cgget refactor, cgget will utilize this function.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoapi: Expose cg_build_path_locked() to users of libcgroup.la
Tom Hromatka [Mon, 8 Feb 2021 22:48:54 +0000 (15:48 -0700)] 
api: Expose cg_build_path_locked() to users of libcgroup.la

Remove the static qualifier from cg_build_path_locked().  As part
of the cgget refactor, cgget will utilize this function.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #10 from drakenclimber/issues/cgget-tests2
Tom Hromatka [Mon, 1 Mar 2021 17:28:46 +0000 (10:28 -0700)] 
Merge pull request #10 from drakenclimber/issues/cgget-tests2

Add extensive cgget functional tests

5 years agoftests: Add pydoc documentation to Cgroup.get()
Tom Hromatka [Thu, 11 Feb 2021 20:22:51 +0000 (20:22 +0000)] 
ftests: Add pydoc documentation to Cgroup.get()

Add pydoc documentation for the Cgroup.get() method and reference
the automated test that exercise various cgget commands.

The pydoc for Cgroup.get() is available by running:
$ python -c "from cgroup import Cgroup;help(Cgroup.get)"

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add cgget invalid parameter test
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>
5 years agoftests: Add cgget '-a' test
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>
5 years agoftests: Add multiline cgget test
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>
5 years agoftests: Add cgget test with multiple '-g' flags
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>
5 years agoftests: Add cgget test with multiple '-r' flags and multiple cgroups
Tom Hromatka [Tue, 9 Feb 2021 21:39:14 +0000 (21:39 +0000)] 
ftests: Add cgget test with multiple '-r' flags and multiple cgroups

Add a test that exercises multiple '-r' flags and multiple
cgroups in cgget.  This test verifies the following cgget
operation:

$ cgget -r memory.limit_in_bytes -r memory.soft_limit_in_bytes \
  012cgget1 012cgget2

-----------------------------------------------------------------
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>
5 years agoftests: Add cgget test with '-r' flag and two cgroups
Tom Hromatka [Tue, 9 Feb 2021 21:22:28 +0000 (21:22 +0000)] 
ftests: Add cgget test with '-r' flag and two cgroups

Add a test that exercises the '-r' <name> <cgroup1> <cgroup2>
option in cgget.  This test verifies the following cgget
operation:

$ cgget -r memory.limit_in_bytes 011cgget1 011cgget2

-----------------------------------------------------------------
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>
5 years agoftests: Add cgget test with '-g' <controller>:<cgroup> flag
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>
5 years agoftests: Add cgget test with '-g' <controller> flag
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>
5 years agoftests: Add cgget test with multiple '-r' flags
Tom Hromatka [Tue, 9 Feb 2021 20:06:25 +0000 (20:06 +0000)] 
ftests: Add cgget test with multiple '-r' flags

Add a test that exercises multiple '-r' flags passed
into cgget.  This test verifies the following cgget
operation:

$ cgget -r memory.limit_in_bytes -r memory.soft_limit_in_bytes \
  008cgget
008cgget:
memory.limit_in_bytes: 1048576
memory.soft_limit_in_bytes: 1024000

-----------------------------------------------------------------
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>
5 years agoftests: Add support for getting cgget help string
Tom Hromatka [Wed, 10 Feb 2021 23:46:34 +0000 (23:46 +0000)] 
ftests: Add support for getting cgget help string

Add support for getting cgget help string

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Throw an exception if len(stderr) > 0
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>
5 years agoftests: Clean up handling of bytes vs string
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>
5 years agoMerge pull request #9 from drakenclimber/issues/cgrules5
Tom Hromatka [Mon, 1 Mar 2021 17:13:18 +0000 (10:13 -0700)] 
Merge pull request #9 from drakenclimber/issues/cgrules5

Add cgrules functional tests

5 years agoftests: Add cgroup v2 cgrules test
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>
5 years agoftests: Add cgroup v1 cgrules test
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

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit eeb176b289b5ac704d27ca52996423b1887c6c3e)

5 years agoftests: Clean up a few exceptions
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>
5 years agoftests: Add support for getting a process' cgroups
Tom Hromatka [Mon, 1 Mar 2021 16:37:23 +0000 (16:37 +0000)] 
ftests: Add support for getting a process' cgroups

Add support to get the current cgroup(s) of a running process.
Works with both cgroup v1 and cgroup v2.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add cgrulesengd support to the Cgroup class
Tom Hromatka [Mon, 1 Mar 2021 16:37:06 +0000 (16:37 +0000)] 
ftests: Add cgrulesengd support to the Cgroup class

Add cgrulesengd support to the Cgroup class.  Add methods
to insert a rule, initialize the daemon, and start the
daemon in a separate process.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #25 from drakenclimber/issues/nocontainer
Tom Hromatka [Mon, 1 Mar 2021 16:27:57 +0000 (09:27 -0700)] 
Merge pull request #25 from drakenclimber/issues/nocontainer

Run tests outside of a container

5 years agogithub: Log the results of the non-containerized tests 25/head
Tom Hromatka [Mon, 1 Mar 2021 16:17:46 +0000 (16:17 +0000)] 
github: Log the results of the non-containerized tests

Log the results of the non-containerized tests.  The
non-containerized tests will be automatically invoked
by `make check`.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #8 from drakenclimber/issues/nocontainer
Tom Hromatka [Mon, 1 Mar 2021 15:53:22 +0000 (08:53 -0700)] 
Merge pull request #8 from drakenclimber/issues/nocontainer

Add support to run the functional tests outside of a container

5 years agoMerge pull request #23 from drakenclimber/issues/21
Tom Hromatka [Thu, 25 Feb 2021 15:19:46 +0000 (08:19 -0700)] 
Merge pull request #23 from drakenclimber/issues/21

api.c: Fix erroneous error handling in cgroup_set_values_recursive()

5 years agoapi.c: Fix erroneous error handling in cgroup_set_values_recursive() 23/head
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>
5 years agoMerge pull request #7 from drakenclimber/issues/21
Tom Hromatka [Thu, 25 Feb 2021 15:13:44 +0000 (08:13 -0700)] 
Merge pull request #7 from drakenclimber/issues/21

gunit: Update test 009 to better test dirty flag

5 years agogunit: Update test 009 to better test dirty flag
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>
5 years agoftests: Add a script to run the non-containerized tests
Tom Hromatka [Wed, 3 Feb 2021 17:49:45 +0000 (10:49 -0700)] 
ftests: Add a script to run the non-containerized tests

Add a script to run the non-containerized tests and
invoke it from `make check`.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add permissions support to cgsnapshot parsing
Tom Hromatka [Wed, 3 Feb 2021 17:46:23 +0000 (10:46 -0700)] 
ftests: Add permissions support to cgsnapshot parsing

In a container cgsnapshot doesn't report owner/group
permissions, but on a bare-metal setup, it does.  Add
support to parse the permissions fields.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Make the Process() class instantiable
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>
5 years agoftests: Ensure the deny list file exists
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>
5 years agoftests: Use sudo for many cgroup commands when not in a container
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>
5 years agoftests: Test 004 must be run within a container
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>
5 years agoftests: Add --container and --no-container flags
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>
5 years agoftests: Fix failure cause when multiple tests don't pass
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>
5 years agogithub: Always display test logs
Tom Hromatka [Wed, 23 Dec 2020 18:12:39 +0000 (11:12 -0700)] 
github: Always display test logs

Always display the test logs in the github actions
GUI.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #19 from drakenclimber/issues/cgsnapshot2
Tom Hromatka [Wed, 23 Dec 2020 15:23:17 +0000 (08:23 -0700)] 
Merge pull request #19 from drakenclimber/issues/cgsnapshot2

Add support for cgroup v2 cgsnapshot

5 years agoMerge pull request #6 from drakenclimber/issues/cgsnapshot2
Tom Hromatka [Wed, 23 Dec 2020 15:17:37 +0000 (08:17 -0700)] 
Merge pull request #6 from drakenclimber/issues/cgsnapshot2

Add tests for cgroup v1 and cgroup v2 cgsnapshot

5 years agocgsnapshot: Replace hardcoded "tasks" file 19/head
Tom Hromatka [Thu, 17 Dec 2020 18:39:11 +0000 (11:39 -0700)] 
cgsnapshot: Replace hardcoded "tasks" file

Replace the hardcoded building of the tasks path in
cgsnapshot with a call to cgroup_build_tasks_procs_path().
By calling cgroup_build_tasks_procs_path(), cgsnapshot
now supports both cgroup v1 and cgroup v2.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Dhaval Giani <dhaval.giani@oracle.com>
5 years agoapi.c: Export cgroup_build_tasks_procs_path()
Tom Hromatka [Thu, 17 Dec 2020 18:38:52 +0000 (11:38 -0700)] 
api.c: Export cgroup_build_tasks_procs_path()

Make cgroup_build_tasks_procs_path() available to
libcgroup.la library users (i.e. the libcgroup tools).

This change will be used in the next commit so that
cgsnapshot can properly read the tasks/procs file.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Dhaval Giani <dhaval.giani@oracle.com>
5 years agoftests: Add cgroup v2 cgsnapshot test
Tom Hromatka [Thu, 17 Dec 2020 22:14:54 +0000 (15:14 -0700)] 
ftests: Add cgroup v2 cgsnapshot test

Add a cgroup v2 cgsnapshot test.

-----------------------------------------------------------------
Test Results:
Run Date:                          Dec 17 22:18:33
Passed:                                  1 test(s)
Skipped:                                 0 test(s)
Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
Test                                    Time (sec)
---------------------------------------------------------
setup                                        16.83
005-cgsnapshot-basic_snapshot_v2.py           1.13
teardown                                      0.00
---------------------------------------------------------
Total Run Time                               17.96

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add cgroup v1 cgsnapshot test
Tom Hromatka [Thu, 17 Dec 2020 20:48:35 +0000 (13:48 -0700)] 
ftests: Add cgroup v1 cgsnapshot test

Add a cgroup v1 cgsnapshot test.

-----------------------------------------------------------------
Test Results:
Run Date:                          Dec 17 22:13:22
Passed:                                  1 test(s)
Skipped:                                 0 test(s)
Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
Test                                    Time (sec)
---------------------------------------------------------
setup                                        18.66
004-cgsnapshot-basic_snapshot_v1.py           0.47
teardown                                      0.00
---------------------------------------------------------
Total Run Time                               19.14

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add support for cgsnapshot
Tom Hromatka [Thu, 17 Dec 2020 20:38:43 +0000 (13:38 -0700)] 
ftests: Add support for cgsnapshot

Add functional test support for cgsnapshot to the
Cgroup class.  The method, snapshot(), invokes libcgroup's
cgsnapshot and returns a dictionary of Cgroup class
instantiations (which are analogous to struct cgroup
within libcgroup.)

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Make the Cgroup class instantiable
Tom Hromatka [Thu, 17 Dec 2020 21:54:13 +0000 (14:54 -0700)] 
ftests: Make the Cgroup class instantiable

Add logic to the functional test's Cgroup class to
make it analogous to libcgroup's struct cgroup.
By adding  __init__(), __str__(), and __eq__() methods,
the cgroup class can very closely mirror struct cgroup.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add a cgroup controller class
Tom Hromatka [Thu, 17 Dec 2020 19:47:48 +0000 (12:47 -0700)] 
ftests: Add a cgroup controller class

Add a controller class that mirrors libcgroup's
struct cgroup_controller.  The controller class
contains a dictionary that represents the array
of struct control_values.  To simplify the usability
within the functional tests, the __str__() and
__eq__() methods have been overridden.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add a utilities file and an indent() function
Tom Hromatka [Thu, 17 Dec 2020 19:43:26 +0000 (12:43 -0700)] 
ftests: Add a utilities file and an indent() function

Add a new file to hold generic utilities for the
functional tests.  As part of this change, a function
that can indent a block of text has been added.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Move cgroup version enums to their own class
Tom Hromatka [Thu, 17 Dec 2020 19:02:06 +0000 (12:02 -0700)] 
ftests: Move cgroup version enums to their own class

In preparation for adding non-static functionality to
the Cgroup class, move the cgroup version enumerations
to their own class.  (Enums and __init__() can collide
in strange ways.)

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agogithub: Display ftests.sh.log in the CI GUI
Tom Hromatka [Thu, 17 Dec 2020 18:24:13 +0000 (11:24 -0700)] 
github: Display ftests.sh.log in the CI GUI

Now that we invoke ftests.sh in the functional tests'
Makefile.am, test-suite.log isn't that useful.  Display
ftests.sh.log in the Github Actions GUI since
ftests.sh.log contains pass/fail info for each test.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #18 from drakenclimber/issues/betterlogs
Tom Hromatka [Thu, 17 Dec 2020 15:50:12 +0000 (08:50 -0700)] 
Merge pull request #18 from drakenclimber/issues/betterlogs

github: Improve logging and reporting

5 years agoMerge pull request #5 from drakenclimber/issues/betterlogs
Tom Hromatka [Thu, 17 Dec 2020 15:45:15 +0000 (08:45 -0700)] 
Merge pull request #5 from drakenclimber/issues/betterlogs

ftests: Invoke ftests.sh in Makefile.am

5 years agogithub: Improve logging and reporting 18/head
Tom Hromatka [Thu, 17 Dec 2020 15:03:32 +0000 (08:03 -0700)] 
github: Improve logging and reporting

Display the high-level log, test-suite.log, in
the github work for all jobs.  Also, archive the
functional test logs to facilitate debugging a
failed run.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Invoke ftests.sh in Makefile.am
Tom Hromatka [Thu, 17 Dec 2020 14:59:52 +0000 (07:59 -0700)] 
ftests: Invoke ftests.sh in Makefile.am

Invoke a wrapper script, ftests.sh, in the TESTS target
within Makefile.am.  This provides two advantages:
1. When new tests are added, Makefile.am does not need
   to be updated
2. This adds verbose logging to the continuous integration
   suite

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoREADME.md: Update the coveralls badge
Tom Hromatka [Tue, 15 Dec 2020 22:11:01 +0000 (15:11 -0700)] 
README.md: Update the coveralls badge

The coveralls.io badge wasn't consistently updating
after a successful run.  Remove the "?branch=master"
parameter and switch to using a png rather than an
svg.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #17 from drakenclimber/issues/github_actions
Tom Hromatka [Tue, 15 Dec 2020 21:01:14 +0000 (14:01 -0700)] 
Merge pull request #17 from drakenclimber/issues/github_actions

Transition from Travis CI to Github Actions

5 years agoREADME.md: Transition from Travis CI to Github Actions 17/head
Tom Hromatka [Tue, 15 Dec 2020 20:46:58 +0000 (13:46 -0700)] 
README.md: Transition from Travis CI to Github Actions

Travis CI has now been disabled.  Delete the Travis CI
badge and display the Github Actions continuous integration
workflow badge.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agogithub: Add continuous integration Github workflow
Tom Hromatka [Tue, 15 Dec 2020 20:46:21 +0000 (13:46 -0700)] 
github: Add continuous integration Github workflow

Add a Github Actions continuous integration workflow.  This
workflow runs the unit tests, the cgroup v1 functional tests,
and the cgroup v2 functional tests.  The code coverage results
from all of the runs are collated at coveralls.io.

Like Travis CI, Github Actions currently does not provide a
distro that natively runs cgroup v2.  (And it also doesn't
expose the kernel boot command line.)  So, like our previous
Travis CI solution, unmount the cpuset controller and enable
it in cgroup v2.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agogithub: Add a Github Action to setup the libcgroup directory
Tom Hromatka [Tue, 15 Dec 2020 20:45:46 +0000 (13:45 -0700)] 
github: Add a Github Action to setup the libcgroup directory

Add a Github Action to setup the libcgroup directory.
This action installs the required dependencies, run
bootstrap.sh, runs configure, and invokes make.

Since the action is invoked locally (and not via Github
Action's published action mechanism), the repository must
be git cloned prior to running this action.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agotravis: Disable Travis CI
Tom Hromatka [Tue, 15 Dec 2020 20:45:16 +0000 (13:45 -0700)] 
travis: Disable Travis CI

Disable the Travis CI build by deleting the
.travis.yml file.  Subsequent commits will transition
to using Github Actions instead.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #16 from drakenclimber/issues/ftests_cgv2
Tom Hromatka [Mon, 23 Nov 2020 17:14:37 +0000 (10:14 -0700)] 
Merge pull request #16 from drakenclimber/issues/ftests_cgv2

Add cgroup v2 support to the functional tests

5 years agoMerge pull request #4 from drakenclimber/issues/ftests_cgv2
Tom Hromatka [Mon, 23 Nov 2020 16:29:40 +0000 (09:29 -0700)] 
Merge pull request #4 from drakenclimber/issues/ftests_cgv2

Add cgroup v2 support to the functional tests

5 years agoftests: Add a cgroup v2 basic cgget test
Tom Hromatka [Tue, 3 Nov 2020 15:04:20 +0000 (08:04 -0700)] 
ftests: Add a cgroup v2 basic cgget test

Add a test - 003-cgget-basic_cgget_v2.py - that tests
cgget on a cgroup v2 system.

-----------------------------------------------------------------
Test Results:
        Run Date:                          Nov 03 17:49:35
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                    Time (sec)
        ---------------------------------------------------------
        setup                                         3.76
        003-cgget-basic_cgget_v2.py                   0.70
        teardown                                      0.00
        ---------------------------------------------------------
        Total Run Time                                4.46

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Rename Test 001 to denote it is cgroup v1 only
Tom Hromatka [Tue, 3 Nov 2020 14:55:05 +0000 (07:55 -0700)] 
ftests: Rename Test 001 to denote it is cgroup v1 only

Rename test 1 from 001-cgget-basic_cgget.py to
001-cgget-basic_cgget_v1.py.  Also add logic to the test
to skip it on a v2 system.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Fix config typo in test 001
Tom Hromatka [Wed, 28 Oct 2020 15:34:13 +0000 (15:34 +0000)] 
ftests: Fix config typo in test 001

Test 001 erroneously set the test number in the wrong place -
config.test_num.  This caused all the tests to run when only
test 001 was invoked.  The correct setting is config.args.num

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Run a cgv1 process in the recursive cgdelete test
Tom Hromatka [Wed, 28 Oct 2020 14:43:19 +0000 (14:43 +0000)] 
ftests: Run a cgv1 process in the recursive cgdelete test

For cgroup v1, run a process in the child cgroup during
the recursive cgdelete tests - 002-cgdelete-recursive_delete.py.
In cgroup v1, cgdelete should migrate the process to its
parent cgroup.

If the test is being run on a cgroup v2 system, don't
create the process.  Cgroup v2 doesn't support processes
running in a non-leaf cgroup, so cgdelete's recursive
command doesn't really make sense.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add class to create and manage child processes
Tom Hromatka [Tue, 27 Oct 2020 19:12:07 +0000 (19:12 +0000)] 
ftests: Add class to create and manage child processes

Add a class that can create and delete child processes.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add support for shell commands in containers
Tom Hromatka [Wed, 28 Oct 2020 14:08:59 +0000 (14:08 +0000)] 
ftests: Add support for shell commands in containers

Add support for shell commands to Container.run() method.
The parameter, shell_bool, is passed directly to Run.run()
and is ultimately sent on to subprocess.Popen().  As the
name implies, when shell_bool is set to true, the requested
command will be executed through the shell.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add support for cgclassify to Cgroup class
Tom Hromatka [Wed, 28 Oct 2020 15:30:55 +0000 (15:30 +0000)] 
ftests: Add support for cgclassify to Cgroup class

Add support for cgclassify to Cgroup class.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add a method to get a controller's cgroup version
Tom Hromatka [Mon, 26 Oct 2020 17:53:06 +0000 (11:53 -0600)] 
ftests: Add a method to get a controller's cgroup version

Add a static method to the Cgroup class to get a
controller's cgroup version.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
5 years agoftests: Cleanup printing of test timing
Tom Hromatka [Mon, 26 Oct 2020 22:06:14 +0000 (16:06 -0600)] 
ftests: Cleanup printing of test timing

Combine the passed, skipped, and failed tests into a
single list when displaying the timing results of
each test.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Increase the display width for printing test results
Tom Hromatka [Mon, 26 Oct 2020 20:11:12 +0000 (14:11 -0600)] 
ftests: Increase the display width for printing test results

In the functional tests, increase the column width for
displaying the test name from 30 to 35 characters.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add symlink to sed
Tom Hromatka [Tue, 27 Oct 2020 18:18:57 +0000 (18:18 +0000)] 
ftests: Add symlink to sed

LXC on Ubuntu 20.04 placed at /bin/sed rather than
/usr/bin/sed like the cgtools scripts expect.  Create
a symlink at /usr/bin/sed so that the cgroup tools can
run like usual.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Remove unused config files
Tom Hromatka [Wed, 28 Oct 2020 18:39:38 +0000 (12:39 -0600)] 
ftests: Remove unused config files

Remove references to default.conf and tmp.conf.  When the ftests
switched from LXC to LXD, these files became no longer needed.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agotravis: Add test job on cgroup v2 Ubuntu 20.04 16/head
Tom Hromatka [Wed, 28 Oct 2020 14:57:09 +0000 (14:57 +0000)] 
travis: Add test job on cgroup v2 Ubuntu 20.04

Add a test job on Ubuntu 20.04.  Prior to running the tests, unmount
the cpuset cgroup controller and enable it in the cgroup v2 unified
hierarchy.  Once each job is complete, it notifies coveralls via a
REST call.

Unfortunately, Travis CI doesn't provide a cgroup v2 system image
and also doesn't allow us to modify the kernel boot parameters.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agotravis: Exclude lex.l and parse.y from code coverage
Tom Hromatka [Mon, 26 Oct 2020 16:48:31 +0000 (10:48 -0600)] 
travis: Exclude lex.l and parse.y from code coverage

Exclude lex.l and parse.y from code coverage numbers.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #14 from drakenclimber/issues/cgdelete
Tom Hromatka [Thu, 22 Oct 2020 18:13:27 +0000 (12:13 -0600)] 
Merge pull request #14 from drakenclimber/issues/cgdelete

api.c: Replace hardcoded "/tasks" in delete functions

5 years agoMerge pull request #3 from drakenclimber/issues/cgdelete
Tom Hromatka [Thu, 22 Oct 2020 18:13:13 +0000 (12:13 -0600)] 
Merge pull request #3 from drakenclimber/issues/cgdelete

ftests: Add recursive cgdelete functional test

5 years agoapi.c: Replace hardcoded "/tasks" in delete functions 14/head
Tom Hromatka [Thu, 15 Oct 2020 21:58:19 +0000 (15:58 -0600)] 
api.c: Replace hardcoded "/tasks" in delete functions

Replace the hardcoded building of the tasks path in
cg_delete_cgroup_controller() and cgroup_delete_cgroup_ext()
with a call to cgroup_build_tasks_procs_path().  By calling
cgroup_build_tasks_procs_path(), both delete functions now
support cgroup v1 and v2.

cgdelete now supports cgroup v2.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoftests: Add recursive cgdelete functional test
Tom Hromatka [Fri, 16 Oct 2020 14:58:12 +0000 (14:58 +0000)] 
ftests: Add recursive cgdelete functional test

Add a test that creates a cgroup hierarchy and then invokes
cgdelete on the parent cgroup with the recursive flag set.

-----------------------------------------------------------------
Test Results:
        Run Date:                     Oct 16 14:54:20
        Passed:                             2 test(s)
        Skipped:                            0 test(s)
        Failed:                             0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                               Time (sec)
        ---------------------------------------------------------
        setup                                   15.11
        001-cgget-basic_cgget.py                 0.53
        002-cgdelete-recursive_delete.py         0.26
        teardown                                 0.00
        ---------------------------------------------------------
        Total Run Time                          15.90

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoMerge pull request #13 from drakenclimber/issues/cgclassify2
Tom Hromatka [Thu, 15 Oct 2020 20:03:23 +0000 (14:03 -0600)] 
Merge pull request #13 from drakenclimber/issues/cgclassify2

Add cgroup v2 support for cgclassify and cgexec

5 years agoMerge pull request #2 from drakenclimber/issues/cgclassify
Tom Hromatka [Thu, 15 Oct 2020 20:00:05 +0000 (14:00 -0600)] 
Merge pull request #2 from drakenclimber/issues/cgclassify

Add unit tests for cgclassify and cgexec functions

5 years agoapi.c: Verify if a controller is enabled for a v2 cgroup 13/head
Tom Hromatka [Wed, 23 Sep 2020 16:41:32 +0000 (10:41 -0600)] 
api.c: Verify if a controller is enabled for a v2 cgroup

Add a function, cgroupv2_controller_enabled(), that checks if the
requested cgroup v2 controller can be used for the specified path.
Again, in cgroup v2, to use a controller, it must be added to the
parent cgroup's cgroup.subtree_control file.

This check is required to ensure that the cgexec and cgclassify
operations will succeed.  And with this commit, cgexec and cgclassify
work on both cgroup v1 and cgroup v2 hierarchies.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoapi.c: Add function to read the cgroup.subtree_control file
Tom Hromatka [Wed, 23 Sep 2020 16:41:00 +0000 (10:41 -0600)] 
api.c: Add function to read the cgroup.subtree_control file

Add a function, cgroupv2_get_subtree_control(), that verifies
if a controller is enabled in the cgroup.subtree_control file
for the requested path.

This function will be used in the next commit - "api.c: Add function
to check if a controller is enabled for a cgroup v2 cgroup" - to
determine if the requested cgroup v2 controller is enabled for a
cgroup.  This is a required check to ensure that the
cgclassify/cgexec operation will succeed.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agoapi.c: Add function to build tasks/procs path
Tom Hromatka [Wed, 23 Sep 2020 16:39:33 +0000 (10:39 -0600)] 
api.c: Add function to build tasks/procs path

Replace the inline logic in multiple functions that concatenates
the path and cgroup v1 tasks file with a function -
cgroup_build_tasks_procs_path() - that works for both cgroup v1
and v2.  In the v1 case, it appends tasks, and in the v2 case, it
appends cgroup.procs.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agogunit: Add unit tests for cgroupv2_controller_enabled()
Tom Hromatka [Wed, 23 Sep 2020 16:49:12 +0000 (10:49 -0600)] 
gunit: Add unit tests for cgroupv2_controller_enabled()

This commit adds unit tests for cgroupv2_controller_enabled()

[----------] 4 tests from CgroupV2ControllerEnabled
[ RUN      ] CgroupV2ControllerEnabled.CgroupV1Controller
[       OK ] CgroupV2ControllerEnabled.CgroupV1Controller (0 ms)
[ RUN      ] CgroupV2ControllerEnabled.RootCgroup
[       OK ] CgroupV2ControllerEnabled.RootCgroup (1 ms)
[ RUN      ] CgroupV2ControllerEnabled.ControllerEnabled
[       OK ] CgroupV2ControllerEnabled.ControllerEnabled (0 ms)
[ RUN      ] CgroupV2ControllerEnabled.ControllerDisabled
[       OK ] CgroupV2ControllerEnabled.ControllerDisabled (0 ms)
[----------] 4 tests from CgroupV2ControllerEnabled (1 ms total)

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
5 years agogunit: Add unit tests for cgroupv2_get_subtree_control()
Tom Hromatka [Wed, 23 Sep 2020 16:48:34 +0000 (10:48 -0600)] 
gunit: Add unit tests for cgroupv2_get_subtree_control()

This commit adds unit tests for cgroupv2_get_subtree_control()

[----------] 6 tests from GetSubtreeControlTest
[ RUN      ] GetSubtreeControlTest.SingleControllerEnabled
[       OK ] GetSubtreeControlTest.SingleControllerEnabled (0 ms)
[ RUN      ] GetSubtreeControlTest.SingleControllerNoMatch
[       OK ] GetSubtreeControlTest.SingleControllerNoMatch (0 ms)
[ RUN      ] GetSubtreeControlTest.SingleControllerNoMatch2
[       OK ] GetSubtreeControlTest.SingleControllerNoMatch2 (0 ms)
[ RUN      ] GetSubtreeControlTest.MultipleControllersEnabled
[       OK ] GetSubtreeControlTest.MultipleControllersEnabled (0 ms)
[ RUN      ] GetSubtreeControlTest.MultipleControllersEnabled2
[       OK ] GetSubtreeControlTest.MultipleControllersEnabled2 (0 ms)
[ RUN      ] GetSubtreeControlTest.MultipleControllersNoMatch
[       OK ] GetSubtreeControlTest.MultipleControllersNoMatch (0 ms)
[----------] 6 tests from GetSubtreeControlTest (0 ms total)

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>