11bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda#!/bin/sh 21bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 31bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda################################################################################ 41bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## ## 51bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## Copyright (c) 2015 SUSE ## 61bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## ## 71bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## This program is free software; you can redistribute it and#or modify ## 81bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## it under the terms of the GNU General Public License as published by ## 91bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## the Free Software Foundation; either version 2 of the License, or ## 101bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## (at your option) any later version. ## 111bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## ## 121bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## This program is distributed in the hope that it will be useful, but ## 131bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 141bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 151bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## for more details. ## 161bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## ## 171bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## You should have received a copy of the GNU General Public License ## 181bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## along with this program; if not, write to the Free Software ## 191bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 ## 201bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## USA ## 211bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## ## 221bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## Author: Cedric Hnyda <chnyda@suse.com> ## 231bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda## ## 241bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda################################################################################ 251bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 261bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# Usage 271bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# ./cpuacct.sh nbsubgroup nbprocess 281bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# 291bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# 1) nbsubgroup : number of subgroup to create 301bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# 2) nbprocess : number of process to attach to each subgroup 311bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# 321bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# Description 331bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# 341bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# 1) Find if cpuacct is mounted, if not mounted, cpuacct will be mounted 351bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# 2) Check that sum ltp_test/subgroup*/cpuacct.usage = ltp_test/cpuacct.usage 361bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda# 371bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 387ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisTST_ID="cpuacct" 397ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisTST_SETUP=setup 407ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisTST_CLEANUP=cleanup 417ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisTST_TESTFUNC=do_test 427ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisTST_POS_ARGS=2 437ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisTST_USAGE=usage 447ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisTST_NEEDS_ROOT=1 457ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 467ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis. tst_test.sh 477ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 481bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnydamounted=1 491bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnydamax=$1 501bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnydanbprocess=$2 511bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 527ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubisusage() 537ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis{ 547ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis cat << EOF 557ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubisusage: $0 nsubgroup nprocess 567ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 577ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubisnsubgroup - number of subgroups to create 587ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubisnprocess - number of processes to attach to each subgroup 591bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 607ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisOPTIONS 617ceac0dd4af714ace579e8e8cf05cae53fee596fCyril HrubisEOF 627ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis} 631bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 641bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnydasetup() 651bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda{ 667ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis if ! grep -q -w cpuacct /proc/cgroups; then 677ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_brk TCONF "cpuacct not supported on this system" 682623d44abed6081cc08755171dec671ff5de0515Xiao Yang fi 692623d44abed6081cc08755171dec671ff5de0515Xiao Yang 701bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda mount_point=`grep -w cpuacct /proc/mounts | cut -f 2 | cut -d " " -f2` 717ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_res TINFO "cpuacct: $mount_point" 721bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda if [ "$mount_point" = "" ]; then 731bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda mounted=0 741bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda mount_point=/dev/cgroup 751bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda fi 761bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 777ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis testpath=$mount_point/ltp_$TST_ID 781bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 791bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda if [ "$mounted" -eq "0" ]; then 801bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda ROD mkdir -p $mount_point 811bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda ROD mount -t cgroup -o cpuacct none $mount_point 821bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda fi 837ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 841bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda ROD mkdir $testpath 857ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 867ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis # create subgroups 877ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis for i in `seq 1 $max`; do 887ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis ROD mkdir $testpath/subgroup_$i 897ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis done 907ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 911bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda} 921bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 931bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnydacleanup() 941bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda{ 957ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_res TINFO "removing created directories" 967ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 977ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis if [ -d "$testpath/subgroup_1" ]; then 987ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis rmdir $testpath/subgroup_* 997ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis fi 1007ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 1011bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda rmdir $testpath 1027ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 1031bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda if [ "$mounted" -ne 1 ]; then 1047ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_res TINFO "Umounting cpuacct" 1051bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda umount $mount_point 1061bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda rmdir $mount_point 1071bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda fi 1081bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda} 1091bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 1107ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubisdo_test() 1117ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis{ 1127ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_res TINFO "Creating $max subgroups each with $nbprocess processes" 1137ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 1147ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis # create and attach process to subgroups 1157ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis for i in `seq 1 $max`; do 1167ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis for j in `seq 1 $nbprocess`; do 1177ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis cpuacct_task $testpath/subgroup_$i/tasks & 1187ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis done 1197ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis done 1201bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 1217ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis wait 1221bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda 1237ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis acc=0 1247ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis fails=0 1257ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis for i in `seq 1 $max`; do 1267ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tmp=`cat $testpath/subgroup_$i/cpuacct.usage` 1277ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis if [ "$tmp" -eq "0" ]; then 1287ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis fails=$((fails + 1)) 1297ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis fi 1307ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis acc=$((acc + tmp)) 1311bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda done 1327ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 1337ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis ## check that cpuacct.usage != 0 for every subgroup 1347ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis if [ "$fails" -gt "0" ]; then 1357ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_res TFAIL "cpuacct.usage is not equal to 0 for $fails subgroups" 1367ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis else 1377ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_res TPASS "cpuacct.usage is not equal to 0 for every subgroup" 1387ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis fi 1397ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 1407ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis ## check that ltp_subgroup/cpuacct.usage == sum ltp_subgroup/subgroup*/cpuacct.usage 1417ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis ref=`cat $testpath/cpuacct.usage` 1427ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis if [ "$ref" -ne "$acc" ]; then 1437ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_res TFAIL "cpuacct.usage $ref not equal to subgroup*/cpuacct.usage $acc" 1447ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis else 1457ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis tst_res TPASS "cpuacct.usage equal to subgroup*/cpuacct.usage" 1461bdfee68c9cb04524d76dd239f5d8e42b1a29f8cCedric Hnyda fi 1477ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis} 1487ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubis 1497ceac0dd4af714ace579e8e8cf05cae53fee596fCyril Hrubistst_run 150