From: Jan Safranek Date: Thu, 3 Nov 2011 09:50:11 +0000 (+0100) Subject: tests: Added cgconfig tests X-Git-Tag: v0.38~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9c22a2f048d029d4426ede625c3f6186e0fb2cc;p=thirdparty%2Flibcgroup.git tests: Added cgconfig tests There are two tests: - cgclear_config_one - tests cgclear with one config file, incl. several error cases - cgclear_config_multi - tests cgclear with multiple config files, not so many error cases here Signed-off-by: Jan Safranek --- diff --git a/tests/tools/cgconfigparser/Makefile.am b/tests/tools/cgconfigparser/Makefile.am index 1bf0ef88..6e0066bb 100644 --- a/tests/tools/cgconfigparser/Makefile.am +++ b/tests/tools/cgconfigparser/Makefile.am @@ -4,6 +4,11 @@ EXTRA_DIST = cgconfigparser_simple \ cgconfigparser_conf_files/cgconfig.conf.5.ex2 \ cgconfigparser_conf_files/cgconfig.conf.5.ex3 \ cgconfigparser_conf_files/cgconfig.conf.5.ex4 \ - cgconfigparser_conf_files/permissions.conf + cgconfigparser_conf_files/permissions.conf \ + cgconfigparser_multiconfig \ + cgclear_config_multi \ + cgclear_config_one + +TESTS = cgconfigparser_simple cgconfigparser_conf_files_tests permissions \ + cgconfigparser_multiconfig cgclear_config_multi cgclear_config_one -TESTS = cgconfigparser_simple cgconfigparser_conf_files_tests permissions diff --git a/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_1.conf b/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_1.conf new file mode 100644 index 00000000..106be833 --- /dev/null +++ b/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_1.conf @@ -0,0 +1,12 @@ +mount { + cpu = /TMP/cgroups/cpu; + cpuacct = /TMP/cgroups/cpu; +} + +group 1 { + cpu { } +} + +group 1/1 { + cpu { } +} diff --git a/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_2.conf b/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_2.conf new file mode 100644 index 00000000..67d1d5a6 --- /dev/null +++ b/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_2.conf @@ -0,0 +1,11 @@ +group 2 { + cpu { } +} + +group 1/2 { + cpu { } +} + +group 1/2/2 { + cpu { } +} diff --git a/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_3.conf b/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_3.conf new file mode 100644 index 00000000..48c5f296 --- /dev/null +++ b/tests/tools/cgconfigparser/cgclear/cgclear_config_multi_3.conf @@ -0,0 +1,19 @@ +group 3 { + cpu { } +} + +group 1/2/3 { + cpu { } +} + +group 1/2/2/3 { + cpu { } +} + +group 1/3 { + cpu { } +} + +group 2/3 { + cpu { } +} diff --git a/tests/tools/cgconfigparser/cgclear/cgclear_config_one.conf b/tests/tools/cgconfigparser/cgclear/cgclear_config_one.conf new file mode 100644 index 00000000..37b32f12 --- /dev/null +++ b/tests/tools/cgconfigparser/cgclear/cgclear_config_one.conf @@ -0,0 +1,16 @@ +mount { + cpu = /TMP/cgroups/cpu; + cpuacct = /TMP/cgroups/cpu; +} + +group first { + cpu { } +} + +group first/subgroup { + cpu { } +} + +group second { + cpu { } +} diff --git a/tests/tools/cgconfigparser/cgclear_config_multi b/tests/tools/cgconfigparser/cgclear_config_multi new file mode 100755 index 00000000..765830d0 --- /dev/null +++ b/tests/tools/cgconfigparser/cgclear_config_multi @@ -0,0 +1,54 @@ +#!/bin/bash +# test cgclear with multiple config files + +. `dirname $0`/../testenv.sh + +# start a process to torture +/bin/sleep 10000 & +PID=$! + +# STEP1: parse three config files and cgclear them at once (in reverse order!) +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_multi_1.conf` \ + || die "STEP1: cgconfigparser multi_1 failed" +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_multi_2.conf` \ + || die "STEP1: cgconfigparser multi_2 failed" +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_multi_3.conf` \ + || die "STEP1: cgconfigparser multi_3 failed" +$TOOLSDIR/lscgroup > $TMP/groups.log +grep 1/2/3 <$TMP/groups.log >/dev/null \ + || die "STEP1: cannot find group '1/2/3'" + +# clear it all +$TOOLSDIR/cgclear -e -l `prepare_config cgclear/cgclear_config_multi_1.conf` \ + -l `prepare_config cgclear/cgclear_config_multi_2.conf` \ + -l `prepare_config cgclear/cgclear_config_multi_3.conf` \ + || die "STEP1: cgclear failed" + +# check all is gone +$TOOLSDIR/lscgroup 2>/dev/null \ + && die "STEP1: something is mounted after cgclear" + + +# STEP2: same as step1, but in wrong order - cgclear should fail +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_multi_1.conf` \ + || die "STEP2: cgconfigparser multi_1 failed" +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_multi_2.conf` \ + || die "STEP2: cgconfigparser multi_2 failed" +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_multi_3.conf` \ + || die "STEP2: cgconfigparser multi_3 failed" +$TOOLSDIR/lscgroup > $TMP/groups.log +grep 1/2/3 <$TMP/groups.log >/dev/null \ + || die "STEP2: cannot find group '1/2/3'" + +# clear it all +$TOOLSDIR/cgclear -e -l `prepare_config cgclear/cgclear_config_multi_3.conf` \ + -l `prepare_config cgclear/cgclear_config_multi_2.conf` \ + -l `prepare_config cgclear/cgclear_config_multi_1.conf` \ + && die "STEP2: cgclear should fail!" + +$TOOLSDIR/cgclear + + +cleanup +kill -9 $PID +exit 0 diff --git a/tests/tools/cgconfigparser/cgclear_config_one b/tests/tools/cgconfigparser/cgclear_config_one new file mode 100755 index 00000000..de43bd3d --- /dev/null +++ b/tests/tools/cgconfigparser/cgclear_config_one @@ -0,0 +1,140 @@ +#!/bin/bash +# test cgclear with one config file + +. `dirname $0`/../testenv.sh + +# start a process to torture +/bin/sleep 10000 & +PID=$! + +# STEP1: parse one simple config with mount and cgclear it (incl. unmount) +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_one.conf` \ + || die "STEP1: cgconfigparser failed" +$TOOLSDIR/lscgroup > $TMP/groups.log +grep first <$TMP/groups.log >/dev/null \ + || die "STEP1: cannot find group 'first'" + +# unmount it +$TOOLSDIR/cgclear -l `prepare_config cgclear/cgclear_config_one.conf` \ + || die "STEP1: cgclear failed" + +# check all is gone +$TOOLSDIR/lscgroup 2>/dev/null \ + && die "STEP1: something is mounted after cgclear" + + +# STEP2: create a cgroup out of config's tree - it must survive cgclear +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_one.conf` \ + || die "STEP2: cgconfigparser failed" +$TOOLSDIR/lscgroup > $TMP/groups.log +grep first <$TMP/groups.log >/dev/null \ + || die "STEP2: cannot find group 'first'" + +$TOOLSDIR/cgcreate -g cpu:/evil \ + || die "STEP2: cgcreate failed" + +# clear it - 'evil' should survive +$TOOLSDIR/cgclear -l `prepare_config cgclear/cgclear_config_one.conf` \ + || die "STEP2: cgclear1 failed" + +# check evil is there +$TOOLSDIR/lscgroup > $TMP/groups.log +grep evil <$TMP/groups.log >/dev/null \ + || die "STEP2: evil not found" + +# clear everything +$TOOLSDIR/cgclear || die "STEP2: cgclear2 failed" +$TOOLSDIR/lscgroup 2>/dev/null \ + && die "STEP2: something is mounted after cgclear" + + +# STEP3: leave a process and a subgroup somewhere and check cgclear *without* -e clears it +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_one.conf` \ + || die "STEP3: cgconfigparser failed" +$TOOLSDIR/lscgroup > $TMP/groups.log +grep first <$TMP/groups.log >/dev/null \ + || die "STEP3: cannot find group 'first'" + +$TOOLSDIR/cgclassify -g cpu:first $PID \ + || die "STEP3: cgclassify failed" +$TOOLSDIR/cgcreate -g cpu:first/evil \ + || die "STEP3: cgcreate failed" + +# unmount it +$TOOLSDIR/cgclear -l `prepare_config cgclear/cgclear_config_one.conf` \ + || die "STEP3: cgclear failed" + +# check all is gone +$TOOLSDIR/lscgroup 2>/dev/null \ + && die "STEP3: something is mounted after cgclear" + + + +# STEP4: leave a process somewhere and check cgclear with -e doesn't clear it +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_one.conf` \ + || die "STEP4: cgconfigparser failed" +$TOOLSDIR/lscgroup > $TMP/groups.log +grep first <$TMP/groups.log >/dev/null \ + || die "STEP4: cannot find group 'first'" + +$TOOLSDIR/cgclassify -g cpu:first $PID \ + || die "STEP4: cgclassify failed" + +# try to clear it - cgclear should fail +$TOOLSDIR/cgclear -e -l `prepare_config cgclear/cgclear_config_one.conf` \ + && die "STEP4: cgclear did not fail!" + +# cpu:first should survive +$TOOLSDIR/lscgroup > $TMP/groups.log +grep first <$TMP/groups.log >/dev/null \ + || die "STEP4: cannot find group 'first'" +# cpu:second should *not* survive +grep second <$TMP/groups.log >/dev/null \ + && die "STEP4: unexpected group 'second' found" +# cpu:first/subgroup should *not* survive +grep first/subgroup <$TMP/groups.log >/dev/null \ + && die "STEP4: unexpected group 'first/subgroup' found" + +$TOOLSDIR/cgclear + +# check all is gone +$TOOLSDIR/lscgroup 2>/dev/null \ + && die "STEP4: something is mounted after cgclear" + + + +# STEP5: leave a subgroup somewhere and check cgclear with -e doesn't clear it +$TOOLSDIR/cgconfigparser -l `prepare_config cgclear/cgclear_config_one.conf` \ + || die "STEP5: cgconfigparser failed" +$TOOLSDIR/lscgroup > $TMP/groups.log +grep first <$TMP/groups.log >/dev/null \ + || die "STEP5: cannot find group 'first'" + +$TOOLSDIR/cgcreate -g cpu:first/evil \ + || die "STEP5: cgcreate failed" + +# try to clear it - cgclear should fail +$TOOLSDIR/cgclear -e -l `prepare_config cgclear/cgclear_config_one.conf` \ + && die "STEP5: cgclear did not fail!" + +# cpu:first/evil should survive +$TOOLSDIR/lscgroup > $TMP/groups.log +grep first/evil <$TMP/groups.log >/dev/null \ + || die "STEP5: cannot find group 'first/evil'" +# cpu:second should *not* survive +grep second <$TMP/groups.log >/dev/null \ + && die "STEP5: unexpected group 'second' found" +# cpu:first/subgroup should *not* survive +grep first/subgroup <$TMP/groups.log >/dev/null \ + && die "STEP5: unexpected group 'first/subgroup' found" + +$TOOLSDIR/cgclear + +# check all is gone +$TOOLSDIR/lscgroup 2>/dev/null \ + && die "STEP4: something is mounted after cgclear" + +kill -9 $PID + +cleanup +exit 0 diff --git a/tests/tools/cgconfigparser/cgconfigparser_multiconfig b/tests/tools/cgconfigparser/cgconfigparser_multiconfig new file mode 100755 index 00000000..9a062297 --- /dev/null +++ b/tests/tools/cgconfigparser/cgconfigparser_multiconfig @@ -0,0 +1,41 @@ +#!/bin/bash +# test cgconfigparser with multiple config files + +. `dirname $0`/../testenv.sh + +# prepare config files in a temporary directory +mkdir -p $TMP/conf.d +for i in $TESTDIR/tools/cgconfigparser/multiconfig/*.conf; do + mv `prepare_config $i` $TMP/conf.d/ +done + +$TOOLSDIR/cgconfigparser -L $TMP/conf.d/ \ + || die "cgconfigparser failed" + +# check that all expected groups exist +$TOOLSDIR/lscgroup > $TMP/groups.out +grep "cpu,cpuacct:/1$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 1" +grep "freezer:/22$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 2" +grep "net_cls:/333$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 3" +grep "cpu,cpuacct:/1/4$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 1/4" +grep "freezer:/22/4$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 22/4" +grep "net_cls:/333/4$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 333/4" +grep "cpu,cpuacct:/5$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 5" +grep "freezer:/55$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 55" +grep "net_cls:/555$" <$TMP/groups.out >/dev/null \ + || die "cannot find group 555" + +# clear it at once +$TOOLSDIR/cgclear -e -L $TMP/conf.d/ \ + || die "cgclear failed" + +cleanup +exit 0 diff --git a/tests/tools/cgconfigparser/multiconfig/1.conf b/tests/tools/cgconfigparser/multiconfig/1.conf new file mode 100644 index 00000000..dbc16d24 --- /dev/null +++ b/tests/tools/cgconfigparser/multiconfig/1.conf @@ -0,0 +1,9 @@ +mount { + cpu = /TMP/cgroups/cpu; + cpuacct = /TMP/cgroups/cpu; +} + +group 1 { + cpu { } +} + diff --git a/tests/tools/cgconfigparser/multiconfig/2.conf b/tests/tools/cgconfigparser/multiconfig/2.conf new file mode 100644 index 00000000..c1039dc5 --- /dev/null +++ b/tests/tools/cgconfigparser/multiconfig/2.conf @@ -0,0 +1,12 @@ +mount { + freezer = /TMP/cgroups/freezer; +} + +# check that cpu is already mounted +group 2 { + cpu { } +} + +group 22 { + freezer { } +} diff --git a/tests/tools/cgconfigparser/multiconfig/3.conf b/tests/tools/cgconfigparser/multiconfig/3.conf new file mode 100644 index 00000000..620923bb --- /dev/null +++ b/tests/tools/cgconfigparser/multiconfig/3.conf @@ -0,0 +1,17 @@ +mount { + net_cls = /TMP/cgroups/net; +} + +# check that cpu is already mounted +group 3 { + cpu { } +} + +# check that freezer is already mounted +group 33 { + freezer { } +} + +group 333 { + net_cls { } +} diff --git a/tests/tools/cgconfigparser/multiconfig/4.conf b/tests/tools/cgconfigparser/multiconfig/4.conf new file mode 100644 index 00000000..d48f12fa --- /dev/null +++ b/tests/tools/cgconfigparser/multiconfig/4.conf @@ -0,0 +1,12 @@ +# now with a namespace +namespace { + cpu=1; + cpuacct=1; + freezer=22; + net_cls=333; +} +group 4 { + cpu { } + freezer { } + net_cls { } +} diff --git a/tests/tools/cgconfigparser/multiconfig/5.conf b/tests/tools/cgconfigparser/multiconfig/5.conf new file mode 100644 index 00000000..d4dc4653 --- /dev/null +++ b/tests/tools/cgconfigparser/multiconfig/5.conf @@ -0,0 +1,12 @@ +# now without mount section +group 5 { + cpu { } +} + +group 55 { + freezer { } +} + +group 555 { + net_cls { } +}