controllers:new testcase blkio1
PATCH 1/1 controllers:new testcase blkio1
--- runtest/blkio | 1 + testcases/kernel/controllers/blkio/Makefile | 28 ++++++ testcases/kernel/controllers/blkio/blkio_setup.sh | 97 +++++++++++++++++++ testcases/kernel/controllers/blkio/blkio_test1.sh | 113 ++++++++++++++++++++++ 4 files changed, 239 insertions(+) create mode 100644 runtest/blkio create mode 100644 testcases/kernel/controllers/blkio/Makefile create mode 100755 testcases/kernel/controllers/blkio/blkio_setup.sh create mode 100755 testcases/kernel/controllers/blkio/blkio_test1.sh
runtest/blkio new file +1 -0
@@ -0,0 +1 @@ +blkio1 blkio_test1.sh
testcases/kernel/controllers/blkio/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# +# kernel/controllers/blkio test suite Makefile. +# +# Copyright (c) Huawei Technologies Co., Ltd., 2015 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. +# +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(abs_srcdir)/../Makefile.inc + +INSTALL_TARGETS := *.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/blkio/blkio_setup.sh new file +97 -0
97 lines not on this page · raw message
testcases/kernel/controllers/blkio/blkio_test1.sh new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 1/1 controllers:new testcase blkio1
Hi!
Quoted 109 lines · Yuan Sun
Signed-off-by Yuan Sun <[email protected]>--- runtest/blkio | 1 + testcases/kernel/controllers/blkio/Makefile | 28 ++++++ testcases/kernel/controllers/blkio/blkio_setup.sh | 97 +++++++++++++++++++ testcases/kernel/controllers/blkio/blkio_test1.sh | 113 ++++++++++++++++++++++ 4 files changed, 239 insertions(+)create mode 100644 runtest/blkio
create mode 100644 testcases/kernel/controllers/blkio/Makefile create mode 100755testcases/kernel/controllers/blkio/blkio_setup.shcreate mode 100755testcases/kernel/controllers/blkio/blkio_test1.shruntest/blkio new file +1
-0@@ -0,0 +1 @@ +blkio1 blkio_test1.shtestcases/kernel/controllers/blkio/Makefile new file +28
-0@@ -0,0 +1,28 @@ +# +# kernel/controllers/blkio test suite Makefile. +# +# Copyright (c) Huawei Technologies Co., Ltd., 2015 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. +# +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(abs_srcdir)/../Makefile.inc + +INSTALL_TARGETS := *.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/controllers/blkio/blkio_setup.sh new file +35
-0@@ -0,0 +1,97 @@ +#!/bin/bash +# usage ./blkio_setup.sh + +################################################################################ +# Copyright (c) Huawei Technologies Co., Ltd., 2015 # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # +# the GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. # +# # +################################################################################ +################################################################################ +# Name Of File: setup.sh # +# # +# Description: This file has functions for the setup for testing blkio # +# controller. Setup includes creating controller device, # +# mounting it with cgroup filesystem with option blkio # +# and creating groups in it. # +# # +# Functions: setup(): creaes /dev/blkio, mounts cgroup fs on it, creates # +# groups in that etc. # +# usage(): Shows the usage of this file. # +# cleanup(): Does full system cleanup # +# # +# Precaution: Avoid system use by other applications/users to get fair and # +#here it isand mount it only if it is needed? appropriate results (avoid unnecessary killing of applicatio) #
testcases/kernel/controllers/blkio/blkio_setup.sh new file +13
-0+# # +################################################################################ + +# umount blkio if it has been mounted. +umount_blkio_mounted() +{ + dir=`grep blkio /proc/mounts | awk '{print $2}'` + if [ -n "$dir" ]; then + umount "$dir" 2> /dev/null + fi +} + +# The cleanup function
testcases/kernel/controllers/blkio/blkio_setup.sh line 58
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +10
-0+cleanup() +{ + echo "Cleanup called" + rmdir /dev/blkio/group*/group* 2> /dev/null + rmdir /dev/blkio/group* 2> /dev/null + umount /dev/blkio/ 2> /dev/null + umount_blkio_mounted + rmdir /dev/blkio 2> /dev/null +} +
This can fail in some cases.
Why not keeping the cgroup mounted where it is
and mount it only if it is needed so that we can avoid this risk? And couldn't we keep blkio mounted at the end of the test if it was mounted before?
Quoted 7 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +7
-0+setup() +{ + if [ -e /dev/blkio ]; then + echo "WARN:/dev/blkio already exist..overwriting" + rmdir /dev/blkio/group*/group* 2> /dev/null + rmdir /dev/blkio/group* 2> /dev/null + umount /dev/blkio/ 2> /dev/null
testcases/kernel/controllers/blkio/blkio_setup.sh line 75
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +10
-0+ rmdir /dev/blkio 2> /dev/null + mkdir /dev/blkio + else + mkdir /dev/blkio + fi + umount_blkio_mounted + mount -t cgroup -oblkio none /dev/blkio 2> /dev/null + if [ $? -ne 0 ] + then + echo "TFAIL: Could not mount cgroup filesystem"
"tst_resm FAIL ..." can be used
Quoted 80 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +22
-0+ echo "Exiting test" + cleanup + exit 1 + fi + + # Group created earlier may again be visible if not cleaned properly. + #so clean them + if [ -e /dev/blkio/group_1 ]; then + rmdir /dev/blkio/group*/group* 2> /dev/null + rmdir /dev/blkio/group* 2> /dev/null + echo "WARN: Earlier groups found and removed..."; + fi + +} + +# The usage of the script file +usage() +{ + echo "Could not start blkio controller test"; + echo "usage: run_blkio_test.sh <TEST_NUM>"; + echo "Skipping the start blkio controller test..."; +}testcases/kernel/controllers/blkio/blkio_test1.sh new file +52
-0@@ -0,0 +1,113 @@ +#!/bin/bash +############################################################################# +# Copyright (c) Huawei Technologies Co., Ltd., 2015 # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # +# the GNU General Public License for more details. # +# # +############################################################################# +# Name Of File: blkio_test1.sh # +# # +# Description: This case is to test blkio which restrict the speed to # +# 1MB/s. # +# # +############################################################################# + + +export TCID="blkio_test1"; +export TST_TOTAL=1; +export TST_COUNT=1; + +tst_kvercmp 2 6 30 2> /dev/null +if [ $? -eq 0 ]; then + tst_brkm TCONF ignored "Test should be run with kernel 2.6.30 or newer" + exit 0 +fi + +. cmdlib.sh + +tst_require_root + +. blkio_setup.sh + +cleanup + +mes="Block Io Controller" +cg_path="/dev/blkio"; + +echo "BLKIO CONTROLLER TESTING"; +echo "RUNNING SETUP....."; +setup; + +ls /dev/sda > /dev/null +if [ $? -ne 0 ];then + echo "/dev/sda is unavailable" + exit 1
testcases/kernel/controllers/blkio/blkio_test1.sh line 62
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +10
-0+fi + +echo "TEST STARTED: Please avoid using system while this test executes"; + +status=0 +mkdir $cg_path/group_1 2> /dev/null +echo $$ > $cg_path/group_1/tasks + +if [ $? -ne 0 ]; then + echo "TFAIL Not able to move a task to the cgroup"
Same.
Quoted 12 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +12
-0+ echo "Exiting Test" + cleanup + exit 1 +fi + +#Limit the speed within 1MB/s. +echo "8:0 1048576" > $cg_path/group_1/blkio.throttle.read_bps_device +hdparm --direct -t /dev/sda | grep 'Timing O_DIRECT disk reads' | \ + sed 's/^.*= //' > hdparm_log +speed=`awk '{print $1}' hdparm_log` +unit=`awk '{print $2}' hdparm_log | sed 's/\/sec//'` +
testcases/kernel/controllers/blkio/blkio_test1.sh line 84
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +10
-0+if [ "$unit" = "MB" ];then + speed=`echo $speed \* 1024 | bc` +elif [ "$unit" = "GB" ];then + speed=`echo $speed \* 1024 \* 1024 | bc` +fi + +echo speed=$speed +result=`echo "$speed <= 1024.0" | bc` +if [ $result -ne 1 ];then + echo "TFAIL the speed should be less than or equal to 1MB/s"
Same.
Quoted 18 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +18
-0+ cleanup + exit 1 +fi + +#Disable the speed limitation. +echo "8:0 0 1048576" > $cg_path/group_1/blkio.throttle.read_bps_device +hdparm --direct -t /dev/sda | grep 'Timing O_DIRECT disk reads' | \ + sed 's/^.*= //' > hdparm_log +speed=`awk '{print $1}' hdparm_log` +unit=`awk '{print $2}' hdparm_log | sed 's/\/sec//'` + +if [ "$unit" = "MB" ];then + speed=`echo $speed \* 1024 | bc` +elif [ "$unit" = "GB" ];then + speed=`echo $speed \* 1024 \* 1024 | bc` +fi + +echo speed=$speed
testcases/kernel/controllers/blkio/blkio_test1.sh line 112
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +10
-0+ +result=`echo "$speed > 1024.0" | bc` +if [ $result -ne 1 ];then + echo "TFAIL the speed should be more than 1MB/s" + cleanup + exit 1 +fi + +cleanup +echo "TPASS PASSED"
Same here.
You should also add your testcases in the runtestfile for controllers.
Best,
Cedric
Signature · 1 line
Cedric Hnyda
PATCH 1/1 controllers:new testcase blkio1
In reply to Yuan SunHi!
runtest/blkio line 1
Quoted 4 lines
runtest/blkio new file +1
-0@@ -0,0 +1 @@ +blkio1 blkio_test1.sh
We have runtest/controllers please use that one instead.
Quoted 25 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +22
-0@@ -0,0 +1,97 @@ +#!/bin/bash +# usage ./blkio_setup.sh + +################################################################################ +# Copyright (c) Huawei Technologies Co., Ltd., 2015 # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # +# the GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. # +# # +################################################################################ +################################################################################ +# Name Of File: setup.sh #
testcases/kernel/controllers/blkio/blkio_setup.sh line 32
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +10
-0+# # +# Description: This file has functions for the setup for testing blkio # +# controller. Setup includes creating controller device, # +# mounting it with cgroup filesystem with option blkio # +# and creating groups in it. # +# # +# Functions: setup(): creaes /dev/blkio, mounts cgroup fs on it, creates # +# groups in that etc. # +# usage(): Shows the usage of this file. # +# cleanup(): Does full system cleanup #
Please avoid useless comments as these. There is no added value in comments as "function cleanup() does cleanup".
testcases/kernel/controllers/blkio/blkio_setup.sh line 35
Quoted 2 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +2
-0+# Precaution: Avoid system use by other applications/users to get fair and # +# appropriate results (avoid unnecessary killing of applicatio) #
This is the only part that should stay here.
Quoted 20 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +20
-0+################################################################################ + +# umount blkio if it has been mounted. +umount_blkio_mounted() +{ + dir=`grep blkio /proc/mounts | awk '{print $2}'` + if [ -n "$dir" ]; then + umount "$dir" 2> /dev/null + fi +} + +# The cleanup function +cleanup() +{ + echo "Cleanup called" + rmdir /dev/blkio/group*/group* 2> /dev/null + rmdir /dev/blkio/group* 2> /dev/null + umount /dev/blkio/ 2> /dev/null + umount_blkio_mounted + rmdir /dev/blkio 2> /dev/null
testcases/kernel/controllers/blkio/blkio_setup.sh
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +10
-0+} + +setup() +{ + if [ -e /dev/blkio ]; then + echo "WARN:/dev/blkio already exist..overwriting" + rmdir /dev/blkio/group*/group* 2> /dev/null + rmdir /dev/blkio/group* 2> /dev/null + + umount /dev/blkio/ 2> /dev/null
Here are spaces before tabs. Please use consistent style for indentation.
testcases/kernel/controllers/blkio/blkio_setup.sh line 70
Quoted 5 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +5
-0+ rmdir /dev/blkio 2> /dev/null + mkdir /dev/blkio + else + mkdir /dev/blkio + fi
No cleanups in setup please.
Quoted 7 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +7
-0+ umount_blkio_mounted + mount -t cgroup -oblkio none /dev/blkio 2> /dev/null + if [ $? -ne 0 ] + then + echo "TFAIL: Could not mount cgroup filesystem" + echo "Exiting test" + cleanup
testcases/kernel/controllers/blkio/blkio_setup.sh line 87
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +10
-0+ exit 1 + fi + + # Group created earlier may again be visible if not cleaned properly. + #so clean them + if [ -e /dev/blkio/group_1 ]; then + rmdir /dev/blkio/group*/group* 2> /dev/null + rmdir /dev/blkio/group* 2> /dev/null + echo "WARN: Earlier groups found and removed..."; + fi
Again please on cleanups in setup.
Quoted 21 lines
testcases/kernel/controllers/blkio/blkio_setup.sh new file +9
-0+} + +# The usage of the script file +usage() +{ + echo "Could not start blkio controller test"; + echo "usage: run_blkio_test.sh <TEST_NUM>"; + echo "Skipping the start blkio controller test..."; +}testcases/kernel/controllers/blkio/blkio_test1.sh new file +6
-0@@ -0,0 +1,113 @@ +#!/bin/bash +############################################################################# +# Copyright (c) Huawei Technologies Co., Ltd., 2015 # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by #
testcases/kernel/controllers/blkio/blkio_test1.sh line 16
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +10
-0+# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # +# the GNU General Public License for more details. # +# # +############################################################################# +# Name Of File: blkio_test1.sh #
The name of file is not usefull at all, please remove it.
Quoted 7 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +7
-0+# Description: This case is to test blkio which restrict the speed to # +# 1MB/s. # +# # +############################################################################# + + +export TCID="blkio_test1";
testcases/kernel/controllers/blkio/blkio_test1.sh line 34
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +10
-0+export TST_TOTAL=1; +export TST_COUNT=1; + +tst_kvercmp 2 6 30 2> /dev/null +if [ $? -eq 0 ]; then + tst_brkm TCONF ignored "Test should be run with kernel 2.6.30 or newer" + exit 0 +fi + +. cmdlib.sh
You should use test.sh, cmdlib has been retired. Have a look at our documentation at:
testcases/kernel/controllers/blkio/blkio_test1.sh line 46
Quoted 11 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +11
-0+tst_require_root + +. blkio_setup.sh + +cleanup + +mes="Block Io Controller" +cg_path="/dev/blkio"; + +echo "BLKIO CONTROLLER TESTING"; +echo "RUNNING SETUP.....";
This are pretty much useless messages, besides you should use
tst_resm TINFO "..."
testcases/kernel/controllers/blkio/blkio_test1.sh line 53
Quoted 7 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +7
-0+setup; + +ls /dev/sda > /dev/null +if [ $? -ne 0 ];then + echo "/dev/sda is unavailable" + exit 1 +fi
Relying on existence of /dev/sda is simply wrong.
testcases/kernel/controllers/blkio/blkio_test1.sh line 58
Quoted 4 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +4
-0+echo "TEST STARTED: Please avoid using system while this test executes"; + +status=0 +mkdir $cg_path/group_1 2> /dev/null
You should prefix the group_1 with ltp_ so that it's clear that it has been created by LTP. Also please do not redirect the stderr to /dev/null.
testcases/kernel/controllers/blkio/blkio_test1.sh line 65
Quoted 7 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +7
-0+echo $$ > $cg_path/group_1/tasks + +if [ $? -ne 0 ]; then + echo "TFAIL Not able to move a task to the cgroup" + echo "Exiting Test" + cleanup + exit 1
You should use tst_brkm TBROK "..." here. Or even better if you look at our docummentation we have ROD function that works as:
ROD echo $$ > $cg_path/group_1/tasks
You have to define CLEANUP variable to have the cleanup executed when the echo fails but that is covered in the documentation as well.
Quoted 4 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +4
-0+fi + +#Limit the speed within 1MB/s. +echo "8:0 1048576" > $cg_path/group_1/blkio.throttle.read_bps_device
testcases/kernel/controllers/blkio/blkio_test1.sh line 79
Quoted 10 lines
testcases/kernel/controllers/blkio/blkio_test1.sh new file +10
-0+hdparm --direct -t /dev/sda | grep 'Timing O_DIRECT disk reads' | \ + sed 's/^.*= //' > hdparm_log +speed=`awk '{print $1}' hdparm_log` +unit=`awk '{print $2}' hdparm_log | sed 's/\/sec//'` + +if [ "$unit" = "MB" ];then + speed=`echo $speed \* 1024 | bc` +elif [ "$unit" = "GB" ];then + speed=`echo $speed \* 1024 \* 1024 | bc` +fi
Now the hardcoded minor and major numbers are wrong as well as the fact that we use /dev/sda.
What we should do instead is to use tst_acquire_device shell function to get a device allocated for the test and then get it's minor and major number (hint use stat -c %t:%T).
Then we can do dd if=/dev/zero of=$device bs=1024 count=1024 and get the speed from the last line of the dd output.
Signature · 2 lines
Cyril Hrubis [email protected]