Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # PM-QA validation test suite for the power management on Linux |
| 4 | # |
| 5 | # Copyright (C) 2011, Linaro Limited. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or |
| 8 | # modify it under the terms of the GNU General Public License |
| 9 | # as published by the Free Software Foundation; either version 2 |
| 10 | # of the License, or (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, write to the Free Software |
| 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 20 | # |
| 21 | # Contributors: |
| 22 | # Amit Daniel <amit.kachhap@linaro.org> (Samsung Electronics) |
| 23 | # - initial API and implementation |
| 24 | # |
| 25 | |
| 26 | THERMAL_PATH="/sys/devices/virtual/thermal" |
| 27 | MAX_ZONE=0-12 |
| 28 | MAX_CDEV=0-50 |
| 29 | ALL_ZONE= |
| 30 | ALL_CDEV= |
| 31 | |
| 32 | check_valid_temp() { |
| 33 | local file=$1 |
| 34 | local zone_name=$2 |
| 35 | local dir=$THERMAL_PATH/$2 |
| 36 | |
| 37 | local temp_file=$dir/$1 |
| 38 | local func=cat |
| 39 | shift 2; |
| 40 | |
| 41 | local temp_val=$($func $temp_file) |
| 42 | local descr="'$zone_name'/'$file' ='$temp_val'" |
| 43 | log_begin "checking $descr" |
| 44 | |
| 45 | if [ $temp_val > 0 ]; then |
| 46 | log_end "pass" |
| 47 | return 0 |
| 48 | fi |
| 49 | |
| 50 | log_end "fail" |
| 51 | |
| 52 | return 1 |
| 53 | } |
| 54 | |
| 55 | for_each_thermal_zone() { |
| 56 | |
| 57 | local func=$1 |
| 58 | shift 1 |
| 59 | |
| 60 | zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
| 61 | |
| 62 | ALL_ZONE=$zone |
| 63 | for zone in $zones; do |
| 64 | INC=0 |
| 65 | $func $zone $@ |
| 66 | done |
| 67 | |
| 68 | return 0 |
| 69 | } |
| 70 | |
| 71 | get_total_trip_point_of_zone() { |
| 72 | |
| 73 | local zone_path=$THERMAL_PATH/$1 |
| 74 | local count=0 |
| 75 | shift 1 |
| 76 | trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") |
| 77 | for zone in $zones; do |
| 78 | count=$((count + 1)) |
| 79 | done |
| 80 | return $count |
| 81 | } |
| 82 | |
| 83 | for_each_trip_point_of_zone() { |
| 84 | |
| 85 | local zone_path=$THERMAL_PATH/$1 |
| 86 | local count=0 |
| 87 | local func=$2 |
| 88 | shift 2 |
| 89 | trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") |
| 90 | for trip in $trips; do |
| 91 | $func $zone $count |
| 92 | count=$((count + 1)) |
| 93 | done |
| 94 | return 0 |
| 95 | } |
| 96 | |
| 97 | for_each_binding_of_zone() { |
| 98 | |
| 99 | local zone_path=$THERMAL_PATH/$1 |
| 100 | local count=0 |
| 101 | local func=$2 |
| 102 | shift 2 |
| 103 | trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point") |
| 104 | for trip in $trips; do |
| 105 | $func $zone $count |
| 106 | count=$((count + 1)) |
| 107 | done |
| 108 | |
| 109 | return 0 |
| 110 | |
| 111 | } |
| 112 | |
| 113 | check_valid_binding() { |
| 114 | local trip_point=$1 |
| 115 | local zone_name=$2 |
| 116 | local dirpath=$THERMAL_PATH/$2 |
| 117 | local temp_file=$2/$1 |
| 118 | local trip_point_val = $(cat $dirpath/$trip_point) |
| 119 | local trip_point_max = get_total_trip_point_of_zone $zone_name |
| 120 | local descr="'$temp_file' valid binding" |
| 121 | shift 2 |
| 122 | |
| 123 | log_begin "checking $descr" |
| 124 | if [ $trip_point > $trip_point_max ]; then |
| 125 | log_end "fail" |
| 126 | return 1 |
| 127 | fi |
| 128 | |
| 129 | log_end "pass" |
| 130 | return 0 |
| 131 | } |
| 132 | |
| 133 | validate_trip_bindings() { |
| 134 | local zone_name=$1 |
| 135 | local bind_no=$2 |
| 136 | local dirpath=$THERMAL_PATH/$1 |
| 137 | local trip_point=cdev$2_trip_point |
| 138 | shift 2 |
| 139 | |
| 140 | check_file $trip_point $dirpath || return 1 |
| 141 | check_valid_binding $trip_point $zone_name || return 1 |
| 142 | } |
| 143 | |
| 144 | validate_trip_level() { |
| 145 | local zone_name=$1 |
| 146 | local trip_no=$2 |
| 147 | local dirpath=$THERMAL_PATH/$1 |
| 148 | local trip_temp=trip_point_$2_temp |
| 149 | local trip_type=trip_point_$2_type |
| 150 | shift 2 |
| 151 | |
| 152 | check_file $trip_temp $dirpath || return 1 |
| 153 | check_file $trip_type $dirpath || return 1 |
| 154 | check_valid_temp $trip_temp $zone_name || return 1 |
| 155 | } |
Amit Daniel Kachhap | 87adb0d | 2012-03-26 16:13:29 +0530 | [diff] [blame^] | 156 | |
| 157 | for_each_cooling_device() { |
| 158 | |
| 159 | local func=$1 |
| 160 | shift 1 |
| 161 | |
| 162 | devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']") |
| 163 | |
| 164 | ALL_DEVICE=$devices |
| 165 | for device in $devices; do |
| 166 | INC=0 |
| 167 | $func $device $@ |
| 168 | done |
| 169 | |
| 170 | return 0 |
| 171 | } |