[CRIU] [PATCH 3/3] zdtm: Make cgroup00 test check several tasks and sub-cgroup
Pavel Emelyanov
xemul at parallels.com
Fri Aug 8 06:59:12 PDT 2014
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
test/zdtm/live/static/cgroup00.c | 98 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/test/zdtm/live/static/cgroup00.c b/test/zdtm/live/static/cgroup00.c
index ca5e3fe..ae4eefc 100644
--- a/test/zdtm/live/static/cgroup00.c
+++ b/test/zdtm/live/static/cgroup00.c
@@ -4,6 +4,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mount.h>
+#include <stdlib.h>
#include "zdtmtst.h"
const char *test_doc = "Check that cgroups layout is preserved";
@@ -13,6 +14,7 @@ char *dirname;
TEST_OPTION(dirname, string, "cgroup directory name", 1);
static const char *cgname = "zdtmtst";
#define SUBNAME "subcg"
+#define SUBNAME2 SUBNAME"/subsubcg"
static int cg_move(char *name)
{
@@ -79,9 +81,22 @@ static void cg_cleanup(void)
int main(int argc, char **argv)
{
char aux[64];
+ int p1[2], p2[2], pr[2], status;
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) {
err("Can't make dir");
goto out;
@@ -96,14 +111,92 @@ int main(int argc, char **argv)
if (cg_move(SUBNAME))
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_waitsig();
+ close(pr[1]);
+
if (cg_check(SUBNAME)) {
fail("Top level task cg changed");
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();
out_rs:
@@ -113,4 +206,9 @@ out_rd:
rmdir(dirname);
out:
return 0;
+
+out_ks:
+ err("Error moving into cgroups");
+ close(pr[0]);
+ goto out_rs;
}
--
1.8.4.2
More information about the CRIU
mailing list