From: Michael Tremer Date: Tue, 9 Aug 2022 12:33:29 +0000 (+0000) Subject: tests: jail: Add test that launches a process into a cgroup X-Git-Tag: 0.9.28~554 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6962faab529a3c2c92ff6b30990dedf027c52833;p=pakfire.git tests: jail: Add test that launches a process into a cgroup Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/jail.c b/tests/libpakfire/jail.c index 757cd9e89..3866b8b30 100644 --- a/tests/libpakfire/jail.c +++ b/tests/libpakfire/jail.c @@ -18,6 +18,7 @@ # # #############################################################################*/ +#include #include #include "../testsuite.h" @@ -98,10 +99,41 @@ FAIL: return EXIT_FAILURE; } +static int test_launch_into_cgroup(const struct test* t) { + struct pakfire_cgroup* cgroup = NULL; + struct pakfire_jail* jail = NULL; + int r = EXIT_FAILURE; + + // Create a new cgroup + ASSERT_SUCCESS(pakfire_cgroup_open(&cgroup, t->pakfire, "pakfire-test", 0)); + + // Create a new jail + ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, 0)); + + // Connect jail to the cgroup + ASSERT_SUCCESS(pakfire_jail_set_cgroup(jail, cgroup)); + + // Run command + ASSERT(pakfire_jail_exec(jail, cmd, NULL) == 0); + + r = EXIT_SUCCESS; + +FAIL: + if (cgroup) { + pakfire_cgroup_destroy(cgroup); + pakfire_cgroup_unref(cgroup); + } + if (jail) + pakfire_jail_unref(jail); + + return r; +} + int main(int argc, char** argv) { testsuite_add_test(test_create); testsuite_add_test(test_env); testsuite_add_test(test_exec); + testsuite_add_test(test_launch_into_cgroup); return testsuite_run(); }