1#! /bin/sh 2 3########################################################################### 4## ## 5## Copyright (c) 2015, Red Hat Inc. ## 6## ## 7## This program is free software: you can redistribute it and/or modify ## 8## it under the terms of the GNU General Public License as published by ## 9## the Free Software Foundation, either version 3 of the License, or ## 10## (at your option) any later version. ## 11## ## 12## This program is distributed in the hope that it will be useful, ## 13## but WITHOUT ANY WARRANTY; without even the implied warranty of ## 14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## 15## GNU General Public License for more details. ## 16## ## 17## You should have received a copy of the GNU General Public License ## 18## along with this program. If not, see <http://www.gnu.org/licenses/>. ## 19## ## 20## Author: Chunyu Hu <[email protected]> ## 21## ## 22########################################################################### 23 24. test.sh 25nr_cpus=`tst_ncpus` 26 27# the 32 bit integer count 32 cpus. One integer is not 28# enough to store the cpu mask for nr_cpu > 32. 29if [ $nr_cpus -gt 32 ]; then 30 group_cnt=$((nr_cpus / 32)) 31 range=31 32 rem=$((nr_cpus % 32)) 33 if [ $rem -ne 0 ]; then 34 range_last=$((rem -1)) 35 fi 36else 37 group_cnt=1 38 range=$((nr_cpus - 1)) 39fi 40 41get_test_cpumask() 42{ 43 mask="" 44 45 local i=0 46 while [ $i -lt $group_cnt ]; do 47 # select count of cpu in one group, include the duplicate. 48 local set_cnt=$(tst_random 1 $((range + 1))) 49 50 local c=0 51 local temp_mask=0 52 while [ $c -lt $set_cnt ]; do 53 local group_cpuid=$(tst_random 1 $range) 54 temp_mask=$((temp_mask | $((1 << $group_cpuid)))) 55 c=$((c + 1)) 56 done 57 58 if [ $i = 0 ]; then 59 mask=`echo $temp_mask | awk '{printf "%x",$0}'` 60 else 61 mask=$mask","`echo $temp_mask | awk '{printf "%x",$0}'` 62 fi 63 64 i=$((i + 1)) 65 done 66 67 if [ $group_cnt -gt 1 ]; then 68 set_cnt=$(tst_random 1 $((range_last +1))) 69 c=0; 70 temp_mask=0 71 while [ $c -lt $set_cnt ]; do 72 local group_cpuid=$(tst_random 1 $range_last) 73 temp_mask=$((temp_mask | $((1 << $group_cpuid)))) 74 c=$((c + 1)) 75 done 76 mask=`echo $temp_mask | awk '{printf "%x",$0}'` 77 fi 78 79 echo "$mask" 80} 81 82signal_handler() 83{ 84 tst_exit 85} 86 87trap signal_handler SIGTERM SIGKILL 88 89while true; do 90 get_test_cpumask > $TRACING_PATH/tracing_cpumask 91done 92