Skip to content

Commit

Permalink
controllers/cpuacct.sh: Convert to the new library
Browse files Browse the repository at this point in the history
TODO: Adapt assertions better for -i looping

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
  • Loading branch information
metan-ucw committed Oct 13, 2016
1 parent 5203cc5 commit 3b7092f
Showing 1 changed file with 67 additions and 51 deletions.
118 changes: 67 additions & 51 deletions testcases/kernel/controllers/cpuacct/cpuacct.sh
Expand Up @@ -35,33 +35,46 @@
# 2) Check that sum ltp_test/subgroup*/cpuacct.usage = ltp_test/cpuacct.usage
#

TST_ID="cpuacct"
TST_SETUP=setup
TST_CLEANUP=cleanup
TST_TESTFUNC=do_test
TST_POS_ARGS=2
TST_USAGE=usage
TST_NEEDS_ROOT=1

. tst_test.sh

mounted=1
max=$1
nbprocess=$2

export TCID="cpuacct_$1_$2"
export TST_TOTAL=2
usage()
{
cat << EOF
usage: $0 nsubgroup nprocess
. test.sh
nsubgroup - number of subgroups to create
nprocess - number of processes to attach to each subgroup
OPTIONS
EOF
}

setup()
{
tst_require_root

grep -q -w cpuacct /proc/cgroups
if [ $? -ne 0 ]; then
tst_brkm TCONF "cpuacct not supported on this system"
tst_brk TCONF "cpuacct not supported on this system"
fi

mount_point=`grep -w cpuacct /proc/mounts | cut -f 2 | cut -d " " -f2`
tst_resm TINFO "cpuacct: $mount_point"
tst_res TINFO "cpuacct: $mount_point"
if [ "$mount_point" = "" ]; then
mounted=0
mount_point=/dev/cgroup
fi

TST_CLEANUP=cleanup

testpath=$mount_point/ltp_$TCID

if [ "$mounted" -eq "0" ]; then
Expand All @@ -73,57 +86,60 @@ setup()

cleanup()
{
tst_resm TINFO "removing created directories"
tst_res TINFO "removing created directories"
rmdir $testpath/subgroup_*
rmdir $testpath
if [ "$mounted" -ne 1 ]; then
tst_resm TINFO "Umounting cpuacct"
tst_res TINFO "Umounting cpuacct"
umount $mount_point
rmdir $mount_point
fi
}

setup;
do_test()
{
tst_res TINFO "Creating $max subgroups each with $nbprocess processes"

# create subgroups
for i in `seq 1 $max`; do
ROD mkdir -p $testpath/subgroup_$i
done

# create subgroups
for i in `seq 1 $max`; do
ROD mkdir -p $testpath/subgroup_$i
done
# create and attach process to subgroups
for i in `seq 1 $max`; do
for j in `seq 1 $nbprocess`; do
cpuacct_task $testpath/subgroup_$i/tasks &
done
done

# create and attach process to subgroups
for i in `seq 1 $max`; do
for j in `seq 1 $nbprocess`; do
cpuacct_task $testpath/subgroup_$i/tasks &
for job in `jobs -p`; do
wait $job
done
done

for job in `jobs -p`; do
wait $job
done

acc=0
fails=0
for i in `seq 1 $max`; do
tmp=`cat $testpath/subgroup_$i/cpuacct.usage`
if [ "$tmp" -eq "0" ]; then
fails=$((fails + 1))

acc=0
fails=0
for i in `seq 1 $max`; do
tmp=`cat $testpath/subgroup_$i/cpuacct.usage`
if [ "$tmp" -eq "0" ]; then
fails=$((fails + 1))
fi
acc=$((acc + tmp))
done

## check that cpuacct.usage != 0 for every subgroup
if [ "$fails" -eq "1" ]; then
tst_res TFAIL "cpuacct.usage is not equal to 0 for $fails subgroups"
else
tst_res TPASS "cpuacct.usage is not equal to 0 for every subgroup"
fi
acc=$((acc + tmp))
done

## check that cpuacct.usage != 0 for every subgroup
if [ "$fails" -eq "1" ]; then
tst_resm TFAIL "cpuacct.usage is not equal to 0 for $fails subgroups"
else
tst_resm TPASS "cpuacct.usage is not equal to 0 for every subgroup"
fi

## check that ltp_subgroup/cpuacct.usage == sum ltp_subgroup/subgroup*/cpuacct.usage
ref=`cat $testpath/cpuacct.usage`
if [ "$ref" != "$acc" ]; then
tst_resm TFAIL "ltp_test/cpuacct.usage not equal to ltp_test/subgroup*/cpuacct.usage"
else
tst_resm TPASS "ltp_test/cpuacct.usage equal to ltp_test/subgroup*/cpuacct.usage"
fi

tst_exit

## check that ltp_subgroup/cpuacct.usage == sum ltp_subgroup/subgroup*/cpuacct.usage
ref=`cat $testpath/cpuacct.usage`
if [ "$ref" != "$acc" ]; then
tst_res TFAIL "ltp_test/cpuacct.usage not equal to ltp_test/subgroup*/cpuacct.usage"
else
tst_res TPASS "ltp_test/cpuacct.usage equal to ltp_test/subgroup*/cpuacct.usage"
fi
}

tst_run

0 comments on commit 3b7092f

Please sign in to comment.