1#!/bin/sh 2# 3# Copyright (c) 2015 Fujitsu Ltd. 4# Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com> 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19# 20# This is a regression test for commit: 21# http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/ 22# ?id=bb2bc55 23# 24 25TCID=cpuset_regression_test 26TST_TOTAL=1 27. test.sh 28 29setup() 30{ 31 tst_require_root 32 33 if tst_kvcmp -lt "3.18"; then 34 tst_brkm TCONF "Test must be run with kernel 3.18.0 or newer" 35 fi 36 37 local cpu_num=$(tst_getconf _NPROCESSORS_ONLN) 38 if [ $cpu_num -lt 2 ]; then 39 tst_brkm TCONF "We need 2 cpus at least to have test" 40 fi 41 42 tst_tmpdir 43 44 TST_CLEANUP=cleanup 45 46 # We need to mount cpuset if it is not found. 47 mount_flag=0 48 grep -w cpuset /proc/mounts > tmpfile 49 if [ $? -eq 0 ]; then 50 root_cpuset_dir=$(cat tmpfile | awk '{print $2}') 51 else 52 root_cpuset_dir="cpuset_test" 53 54 ROD_SILENT mkdir -p ${root_cpuset_dir} 55 56 ROD_SILENT mount -t cpuset cpuset ${root_cpuset_dir} 57 58 mount_flag=1 59 fi 60 61 if [ -f ${root_cpuset_dir}/cpuset.cpu_exclusive ]; then 62 cpu_exclusive=cpuset.cpu_exclusive 63 cpus=cpuset.cpus 64 elif [ -f ${root_cpuset_dir}/cpu_exclusive ]; then 65 cpu_exclusive=cpu_exclusive 66 cpus=cpus 67 else 68 tst_brkm TBROK "Both cpuset.cpu_exclusive and cpu_exclusive" \ 69 "do not exist." 70 fi 71 72 cpu_exclusive_value=$(cat ${root_cpuset_dir}/${cpu_exclusive}) 73 if [ "${cpu_exclusive_value}" != "1" ];then 74 echo 1 > ${root_cpuset_dir}/${cpu_exclusive} 75 if [ $? -ne 0 ]; then 76 tst_brkm TBROK "'echo 1 >" \ 77 "${root_cpuset_dir}/${cpu_exclusive}'" \ 78 "failed" 79 fi 80 fi 81} 82 83cleanup() 84{ 85 if [ -d "${root_cpuset_dir}/testdir" ]; then 86 rmdir ${root_cpuset_dir}/testdir 87 fi 88 89 if [ "$cpu_exclusive_value" != 1 ]; then 90 # Need to flush, or may be output: 91 # "write error: Device or resource busy" 92 sync 93 94 echo ${cpu_exclusive_value} > \ 95 ${root_cpuset_dir}/${cpu_exclusive} 96 fi 97 98 if [ "${mount_flag}" = "1" ]; then 99 umount ${root_cpuset_dir} 100 if [ $? -ne 0 ]; then 101 tst_resm TWARN "'umount ${root_cpuset_dir}' failed" 102 fi 103 104 if [ -d "${root_cpuset_dir}" ]; then 105 rmdir ${root_cpuset_dir} 106 fi 107 fi 108 109 tst_rmdir 110} 111 112cpuset_test() 113{ 114 ROD_SILENT mkdir ${root_cpuset_dir}/testdir 115 116 # Creat an exclusive cpuset. 117 echo 1 > ${root_cpuset_dir}/testdir/${cpu_exclusive} 118 if [ $? -ne 0 ]; then 119 tst_brkm TFAIL "'echo 1 >" \ 120 "${root_cpuset_dir}/testdir/${cpu_exclusive}'" \ 121 "failed" 122 fi 123 124 local cpu_exclusive_tmp=$(cat \ 125 ${root_cpuset_dir}/testdir/${cpu_exclusive}) 126 if [ "${cpu_exclusive_tmp}" != "1" ]; then 127 tst_brkm TFAIL "${cpu_exclusive} is '${cpu_exclusive_tmp}'," \ 128 "expected '1'" 129 fi 130 131 # ${cpus} is empty at the begin, that maybe make the system *crash*. 132 echo 0-1 > ${root_cpuset_dir}/testdir/${cpus} 133 if [ $? -ne 0 ]; then 134 tst_brkm TFAIL "'echo 0-1 >" \ 135 "${root_cpuset_dir}/testdir/${cpus}' failed" 136 fi 137 138 local cpus_value=$(cat ${root_cpuset_dir}/testdir/${cpus}) 139 if [ "${cpus_value}" != "0-1" ]; then 140 tst_brkm TFAIL "${cpus} is '${cpus_value}', expected '0-1'" 141 fi 142 143 tst_resm TPASS "Bug is not reproduced" 144} 145 146setup 147 148cpuset_test 149 150tst_exit 151