Commit 7833260b authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm: Make cgroup00 test check several tasks and sub-cgroup

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 5a44f7f4
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <stdlib.h>
#include "zdtmtst.h" #include "zdtmtst.h"
const char *test_doc = "Check that cgroups layout is preserved"; const char *test_doc = "Check that cgroups layout is preserved";
...@@ -13,6 +14,7 @@ char *dirname; ...@@ -13,6 +14,7 @@ char *dirname;
TEST_OPTION(dirname, string, "cgroup directory name", 1); TEST_OPTION(dirname, string, "cgroup directory name", 1);
static const char *cgname = "zdtmtst"; static const char *cgname = "zdtmtst";
#define SUBNAME "subcg" #define SUBNAME "subcg"
#define SUBNAME2 SUBNAME"/subsubcg"
static int cg_move(char *name) static int cg_move(char *name)
{ {
...@@ -79,9 +81,22 @@ static void cg_cleanup(void) ...@@ -79,9 +81,22 @@ static void cg_cleanup(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char aux[64]; char aux[64];
int p1[2], p2[2], pr[2], status;
test_init(argc, argv); test_init(argc, argv);
/*
* Pipes to talk to two kids.
* First, they report that they are ready (int),
* then they report the restore status (int).
*/
pipe(p1);
pipe(p2);
/* "Restore happened" pipe */
pipe(pr);
if (mkdir(dirname, 0700) < 0) { if (mkdir(dirname, 0700) < 0) {
err("Can't make dir"); err("Can't make dir");
goto out; goto out;
...@@ -96,14 +111,92 @@ int main(int argc, char **argv) ...@@ -96,14 +111,92 @@ int main(int argc, char **argv)
if (cg_move(SUBNAME)) if (cg_move(SUBNAME))
goto out_rs; goto out_rs;
if (fork() == 0) {
if (fork() == 0) {
/*
* 2nd level kid -- moves into its own
* cgroup and triggers slow-path cg_set
* restore in criu
*/
close(p1[0]);
close(p1[1]);
close(p2[0]);
close(pr[1]);
status = cg_move(SUBNAME2);
write(p2[1], &status, sizeof(status));
if (status == 0) {
read(pr[0], &status, sizeof(status));
status = cg_check(SUBNAME2);
write(p2[1], &status, sizeof(status));
}
exit(0);
}
/*
* 1st level kid -- inherits cgroup from
* parent and triggers fast-path cg_set
* restore in criu
*/
close(p1[0]);
close(p2[0]);
close(p2[1]);
close(pr[1]);
status = 0;
write(p1[1], &status, sizeof(status));
read(pr[0], &status, sizeof(status));
status = cg_check(SUBNAME);
write(p1[1], &status, sizeof(status));
exit(0);
}
close(p1[1]);
close(p2[1]);
close(pr[0]);
status = -1;
read(p1[0], &status, sizeof(status));
if (status != 0)
goto out_ks;
status = -1;
read(p2[0], &status, sizeof(status));
if (status != 0)
goto out_ks;
test_daemon(); test_daemon();
test_waitsig(); test_waitsig();
close(pr[1]);
if (cg_check(SUBNAME)) { if (cg_check(SUBNAME)) {
fail("Top level task cg changed"); fail("Top level task cg changed");
goto out_rs; goto out_rs;
} }
status = -1;
read(p1[0], &status, sizeof(status));
if (status != 0) {
fail("1st level task cg changed");
goto out_rs;
}
status = -1;
read(p2[0], &status, sizeof(status));
if (status != 0) {
fail("2nd level task cg changed");
goto out_rs;
}
pass(); pass();
out_rs: out_rs:
...@@ -113,4 +206,9 @@ out_rd: ...@@ -113,4 +206,9 @@ out_rd:
rmdir(dirname); rmdir(dirname);
out: out:
return 0; return 0;
out_ks:
err("Error moving into cgroups");
close(pr[0]);
goto out_rs;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment