From patchwork Tue Jul 26 12:46:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 3139 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D343C23F3F for ; Tue, 26 Jul 2011 12:47:06 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id A2C28A1828C for ; Tue, 26 Jul 2011 12:47:06 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so243495qwb.11 for ; Tue, 26 Jul 2011 05:47:06 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr553567qcc.148.1311684426426; Tue, 26 Jul 2011 05:47:06 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs110980qcb; Tue, 26 Jul 2011 05:47:06 -0700 (PDT) Received: by 10.216.133.146 with SMTP id q18mr732133wei.15.1311684423125; Tue, 26 Jul 2011 05:47:03 -0700 (PDT) Received: from mtagate3.uk.ibm.com (mtagate3.uk.ibm.com [194.196.100.163]) by mx.google.com with ESMTPS id f5si842360wed.18.2011.07.26.05.47.01 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 26 Jul 2011 05:47:02 -0700 (PDT) Received-SPF: neutral (google.com: 194.196.100.163 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=194.196.100.163; Authentication-Results: mx.google.com; spf=neutral (google.com: 194.196.100.163 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p6QCl11L012785; Tue, 26 Jul 2011 12:47:01 GMT Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p6QCl12Q2510848; Tue, 26 Jul 2011 13:47:01 +0100 Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p6QCl04g022452; Tue, 26 Jul 2011 06:47:00 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p6QCl0Pp022438; Tue, 26 Jul 2011 06:47:00 -0600 Received: from mai.lab.toulouse-stg.fr.ibm.com (dhcp7.lab.toulouse-stg.fr.ibm.com [9.101.4.207]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 823E3210FBD; Tue, 26 Jul 2011 14:47:00 +0200 (CEST) From: Daniel Lezcano To: linaro-dev@lists.linaro.org Cc: amit.kucheria@linaro.org Subject: [pm-qa 04/14] add script functions Date: Tue, 26 Jul 2011 14:46:54 +0200 Message-Id: <1311684424-8057-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1311684424-8057-1-git-send-email-daniel.lezcano@linaro.org> References: <1311684424-8057-1-git-send-email-daniel.lezcano@linaro.org> Add a common directory for all the functions we will use later in the test scripts. Signed-off-by: Daniel Lezcano --- include/functions.sh | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 251 insertions(+), 0 deletions(-) create mode 100644 include/functions.sh \ No newline at end of file diff --git a/include/functions.sh b/include/functions.sh new file mode 100644 index 0000000..67c356a --- /dev/null +++ b/include/functions.sh @@ -0,0 +1,251 @@ +#!/bin/bash +# +# PM-QA validation test suite for the power management on ARM +# +# Copyright (C) 2011, Linaro Limited. +# +# 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; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Contributors: +# Daniel Lezcano (IBM Corporation) +# - initial API and implementation +# + +CPU_PATH="/sys/devices/system/cpu" +TEST_NAME=$(basename ${0%.sh}) +PREFIX=$TEST_NAME +BLOCK=$(basename $(pwd)) + +setprefix_cpu() { + PREFIX=$BLOCK:$TEST_NAME/$1 +} + +log_begin() { + printf "%-75s" "$PREFIX $@ ... " +} + +log_end() { + printf "$*\n" +} + +log_skip() { + log_begin "$@" + log_end "SKIP" +} + +for_each_cpu() { + + local func=$1 + shift 1 + + cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") + + for cpu in $cpus; do + setprefix_cpu $cpu + $func $cpu $@ + done + + return 0 +} + +for_each_governor() { + + local cpu=$1 + local func=$2 + local dirpath=$CPU_PATH/$cpu/cpufreq + local governors=$(cat $dirpath/scaling_available_governors) + shift 2 + + for governor in $governors; do + $func $cpu $governor $@ + done + + return 0 +} + +for_each_frequency() { + + local cpu=$1 + local func=$2 + local dirpath=$CPU_PATH/$cpu/cpufreq + local frequencies=$(cat $dirpath/scaling_available_frequencies) + shift 2 + + for frequency in $frequencies; do + $func $cpu $frequency $@ + done + + return 0 +} + +set_governor() { + + local cpu=$1 + local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor + local newgov=$2 + + echo $newgov > $dirpath +} + +get_governor() { + + local cpu=$1 + local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor + + cat $dirpath +} + +wait_latency() { + local cpu=$1 + local dirpath=$CPU_PATH/$cpu/cpufreq + local latency=$(cat $dirpath/cpuinfo_transition_latency) + local nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w) + + nrfreq=$((nrfreq + 1)) + ../utils/nanosleep $(($nrfreq * $latency)) +} + +frequnit() { + local freq=$1 + local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) + local mhz=$(echo "scale=1;($freq / 1000)" | bc -l) + + res=$(echo "($ghz > 1.0)" | bc -l) + if [ "$res" = "1" ]; then + echo $ghz GHz + return 0 + fi + + res=$(echo "($mhz > 1.0)" | bc -l) + if [ "$res" = "1" ];then + echo $mhz MHz + return 0 + fi + + echo $freq KHz +} + +set_frequency() { + + local cpu=$1 + local dirpath=$CPU_PATH/$cpu/cpufreq + local newfreq=$2 + local setfreqpath=$dirpath/scaling_setspeed + + echo $newfreq > $setfreqpath + wait_latency $cpu +} + +get_frequency() { + local cpu=$1 + local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq + cat $dirpath +} + +get_max_frequency() { + local cpu=$1 + local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq + cat $dirpath +} + +get_min_frequency() { + local cpu=$1 + local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq + cat $dirpath +} + +check() { + + local descr=$1 + local func=$2 + shift 2; + + log_begin "checking $descr" + + $func $@ + if [ $? != 0 ]; then + log_end "FAIL" + return 1 + fi + + log_end "PASS" + + return 0 +} + +check_cpufreq_files() { + + local dirpath=$CPU_PATH/$1/cpufreq + shift 1 + + for i in $@; do + check "$i exists" "test -f" $dirpath/$i || return 1 + done + + return 0 +} + +save_governors() { + + governors_backup= + local index=0 + + for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do + governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor) + index=$((index + 1)) + done +} + +restore_governors() { + + local index=0 + local oldgov= + + for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do + oldgov=${governors_backup[$index]} + echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor + index=$((index + 1)) + done +} + +save_frequencies() { + + frequencies_backup= + local index=0 + local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") + local cpu= + + for cpu in $cpus; do + frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) + index=$((index + 1)) + done +} + +restore_frequencies() { + + local index=0 + local oldfreq= + local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") + + for cpu in $cpus; do + oldfreq=${frequencies_backup[$index]} + echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed + index=$((index + 1)) + done +} + +sigtrap() { + exit 255 +}