These tests are described at:

https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts

Signed-off-by: Daniel Lezcano <daniel.lezc...@linaro.org>
---
 Makefile           |    6 ++
 cpufreq/test_01.sh |   43 +++++++++++++++
 cpufreq/test_02.sh |   43 +++++++++++++++
 cpufreq/test_03.sh |   64 +++++++++++++++++++++++
 cpufreq/test_04.sh |   85 ++++++++++++++++++++++++++++++
 cpufreq/test_05.sh |  145 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 utils/Makefile     |   19 +++++++
 utils/nanosleep.c  |   45 ++++++++++++++++
 8 files changed, 450 insertions(+), 0 deletions(-)
 create mode 100644 cpufreq/test_01.sh
 create mode 100644 cpufreq/test_02.sh
 create mode 100644 cpufreq/test_03.sh
 create mode 100644 cpufreq/test_04.sh
 create mode 100644 cpufreq/test_05.sh
 create mode 100644 utils/Makefile
 create mode 100644 utils/nanosleep.c

diff --git a/Makefile b/Makefile
index 73d1f66..16f17b8 100644
--- a/Makefile
+++ b/Makefile
@@ -14,8 +14,14 @@
  
#******************************************************************************/
 
 all:
+       @(cd utils; $(MAKE))
        @(cd testcases; $(MAKE) all)
 
+check:
+       @(cd utils; $(MAKE) check)
+       @(cd cpufreq; $(MAKE) check)
+
 clean:
+       @(cd utils; $(MAKE) clean)
        @(cd testcases; $(MAKE) clean)
 
diff --git a/cpufreq/test_01.sh b/cpufreq/test_01.sh
new file mode 100644
index 0000000..38c6353
--- /dev/null
+++ b/cpufreq/test_01.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+#/*******************************************************************************
+# Copyright (C) 2011, Linaro Limited.
+#
+# This file is part of PM QA.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
+#       - initial API and implementation
+#******************************************************************************/
+
+# URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#test_01
+
+CPU_PATH="/sys/devices/system/cpu"
+FILES="scaling_available_frequencies scaling_cur_freq scaling_setspeed"
+
+check_file() {
+
+    for i in $FILES; do
+
+       printf "%-70s" "checking $i file presence ... "
+
+       if [ ! -f $1/$i ] ; then
+           printf "FAIL\n"
+           return 1;
+       fi
+
+       printf "PASS\n"
+
+    done
+
+    return 0;
+}
+
+for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+    printf "for '$i':\n"
+    check_file $CPU_PATH/$i/cpufreq || exit 1;
+done
diff --git a/cpufreq/test_02.sh b/cpufreq/test_02.sh
new file mode 100644
index 0000000..69239e1
--- /dev/null
+++ b/cpufreq/test_02.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+#/*******************************************************************************
+# Copyright (C) 2011, Linaro Limited.
+#
+# This file is part of PM QA.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
+#       - initial API and implementation
+#******************************************************************************/
+
+# URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#test_02
+
+CPU_PATH="/sys/devices/system/cpu"
+FILES="scaling_available_governors scaling_governor"
+
+check_file() {
+
+    for i in $FILES; do
+
+       printf "%-70s" "checking $i file presence ... "
+
+       if [ ! -f $1/$i ] ; then
+           printf "FAIL\n"
+           return 1;
+       fi
+
+       printf "PASS\n"
+
+    done
+
+    return 0;
+}
+
+for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+    printf "for '$i':\n"
+    check_file $CPU_PATH/$i/cpufreq || exit 1;
+done
diff --git a/cpufreq/test_03.sh b/cpufreq/test_03.sh
new file mode 100644
index 0000000..53a22c6
--- /dev/null
+++ b/cpufreq/test_03.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+#/*******************************************************************************
+# Copyright (C) 2011, Linaro Limited.
+#
+# This file is part of PM QA.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
+#       - initial API and implementation
+#******************************************************************************/
+
+# URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#test_03
+CPU_PATH="/sys/devices/system/cpu"
+
+check_governor_change() {
+
+    oldgov=$(cat $1/scaling_governor)
+
+    for i in $(cat $1/scaling_available_governors); do
+
+       printf "%-70s" "setting governor to $i ... "
+       echo $i > $1/scaling_governor
+
+       curgov=$(cat $1/scaling_governor)
+       if [ "$curgov" != "$i" ]; then
+           printf "FAIL\n"
+           echo $oldgov >  $1/scaling_governor
+           return 1
+       fi
+
+       printf "PASS\n"
+
+    done
+
+    echo $oldgov >  $1/scaling_governor
+
+    return 0
+}
+
+check_root() {
+
+    printf "%-70s" "checking if we are root ... "
+
+    if [ "$(id -u)" != "0" ]; then
+       printf "FAIL\n"
+       return 1
+    fi
+
+    printf "PASS\n"
+
+    return 0
+}
+
+check_root || exit 1
+
+for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+    printf "for '$i':\n"
+    check_governor_change $CPU_PATH/$i/cpufreq || exit 1;
+done
diff --git a/cpufreq/test_04.sh b/cpufreq/test_04.sh
new file mode 100644
index 0000000..aec33e8
--- /dev/null
+++ b/cpufreq/test_04.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+#/*******************************************************************************
+# Copyright (C) 2011, Linaro Limited.
+#
+# This file is part of PM QA.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
+#       - initial API and implementation
+#******************************************************************************/
+
+# URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#test_04
+CPU_PATH="/sys/devices/system/cpu"
+
+check_frequency_change() {
+
+    oldgov=$(cat $1/scaling_governor)
+    oldfreq=$(cat $1/scaling_cur_freq)
+
+    printf "%-70s" "setting governor to 'userspace' ... "
+    echo userspace > $1/scaling_governor
+    curgov=$(cat $1/scaling_governor)
+    if [ "$curgov" != "userspace" ]; then
+       printf "FAIL\n"
+       echo $oldgov >  $1/scaling_governor
+       return 1
+    fi
+
+    printf "PASS\n"
+
+    freqs=$(cat $1/scaling_available_frequencies)
+    nrfreqs=$(cat $1/scaling_available_frequencies | wc -w)
+    latency=$(cat $1/cpuinfo_transition_latency)
+
+    for i in $freqs; do
+
+       printf "%-70s" "setting frequency to $i KHz ... "
+       echo $i > $1/scaling_setspeed
+
+       # wait the latency period
+       ../utils/nanosleep $((nrfreqs * latency))
+
+       curfreq=$(cat $1/scaling_cur_freq)
+       if [ "$curfreq" != "$i" ]; then
+           printf "FAIL\n"
+           echo $oldfreq > $1/scaling_setspeed
+           echo $oldgov >  $1/scaling_governor
+           return 1
+       fi
+
+       printf "PASS\n"
+
+    done
+
+    echo $oldfreq > $1/scaling_setspeed
+    echo $oldgov >  $1/scaling_governor
+
+    return 0
+}
+
+check_root() {
+
+    printf "%-70s" "checking if we are root ... "
+
+    if [ "$(id -u)" != "0" ]; then
+       printf "FAIL\n"
+       return 1
+    fi
+
+    printf "PASS\n"
+
+    return 0
+}
+
+check_root || exit 1
+
+for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+    printf "for '$i':\n"
+    check_frequency_change $CPU_PATH/$i/cpufreq || exit 1;
+done
diff --git a/cpufreq/test_05.sh b/cpufreq/test_05.sh
new file mode 100644
index 0000000..4cc48f6
--- /dev/null
+++ b/cpufreq/test_05.sh
@@ -0,0 +1,145 @@
+#!/bin/bash
+#/*******************************************************************************
+# Copyright (C) 2011, Linaro Limited.
+#
+# This file is part of PM QA.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
+#       - initial API and implementation
+#******************************************************************************/
+
+# URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#test_05
+CPU_PATH="/sys/devices/system/cpu"
+
+oldgovs=
+
+save_governors() {
+    index=0
+    for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+       printf "%-70s" "saving governor for $i ... "
+       oldgovs[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor)
+       printf "DONE\n"
+       index=$((index + 1))
+    done
+}
+
+restore_governors() {
+    index=0
+    for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+       oldgov=${oldgovs[$index]}
+       printf "%-70s" "restoring governor '$oldgov' for $i ... "
+       echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor
+       printf "DONE\n"
+       index=$((index + 1))
+    done
+}
+
+exit_fail() {
+    restore_governors
+    exit 1
+}
+
+switch_governor() {
+
+    newgov=$2
+    oldgov=$(cat $1/scaling_governor)
+
+    printf "%-70s" "setting governor to '$newgov' ... "
+    echo $newgov > $1/scaling_governor
+    curgov=$(cat $1/scaling_governor)
+    if [ "$curgov" != "$newgov" ]; then
+       printf "FAIL\n"
+       echo $oldgov >  $1/scaling_governor
+       return 1
+    fi
+
+    printf "PASS\n"
+
+    return 0
+}
+
+check_cpufreq_governor() {
+
+    path=$CPU_PATH/cpufreq/$1
+    printf "%-70s" "checking '$1' configuration directory ... "
+    if [ ! -d $CPU_PATH/cpufreq/$1 ]; then
+       printf "FAIL\n"
+       return 1
+    fi
+
+    printf "PASS\n"
+
+    return 0
+}
+
+check_root() {
+
+    printf "%-70s" "checking if we are root ... "
+
+    if [ "$(id -u)" != "0" ]; then
+       printf "FAIL\n"
+       return 1
+    fi
+
+    printf "PASS\n"
+
+    return 0
+}
+
+check_root || exit 1
+
+save_governors || exit 1
+
+trap exit_fail SIGHUP SIGINT SIGTERM
+
+for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+    printf "for '$i':\n"
+    switch_governor $CPU_PATH/$i/cpufreq ondemand || exit_fail;
+done
+
+check_cpufreq_governor ondemand || exit_fail
+
+for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+    printf "for '$i':\n"
+    switch_governor $CPU_PATH/$i/cpufreq conservative || exit_fail;
+done
+
+check_cpufreq_governor conservative || exit_fail
+
+for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
+    printf "for '$i':\n"
+    switch_governor $CPU_PATH/$i/cpufreq userspace || exit_fail;
+done
+
+# the following functions should fail as all cpu are in 'userspace'
+# governor mode. The specified directories should not be present
+printf "%-70s" "checking 'ondemand' configuration directory is not there ... "
+if [ -d $CPU_PATH/cpufreq/ondemand ]; then
+    printf "FAIL\n" && exit_fail
+fi
+printf "PASS\n"
+
+printf "%-70s" "checking 'conservative' configuration directory is not there 
... "
+if [ -d $CPU_PATH/cpufreq/conservative ]; then
+    printf "FAIL\n" && exit_fail
+fi
+printf "PASS\n"
+
+# if more than one cpu, combine governors
+nrcpus=$(ls $CPU_PATH | grep "cpu[0-9].*" | wc -l)
+if [ $nrcpus > 0 ]; then
+    printf "for 'cpu0':\n"
+    switch_governor $CPU_PATH/cpu0/cpufreq ondemand || exit_fail;
+    printf "for 'cpu1':\n"
+    switch_governor $CPU_PATH/cpu1/cpufreq conservative || exit_fail;
+    check_cpufreq_governor ondemand || exit_fail
+    check_cpufreq_governor conservative || exit_fail
+fi
+
+restore_governors
diff --git a/utils/Makefile b/utils/Makefile
new file mode 100644
index 0000000..ebe9856
--- /dev/null
+++ b/utils/Makefile
@@ -0,0 +1,19 @@
+CFLAGS?=-g -Wall
+CC?=gcc
+EXEC=nanosleep
+SRC=$(wildcard *.c)
+OBJ= $(SRC:.c=.o)
+
+check: $(EXEC)
+
+nanosleep: $(OBJ)
+       @$(CC) -o $@ $^ $(LDFLAGS)
+
+%.o: %.c
+       $(CC) -o $@ -c $< $(CFLAGS)
+
+clean:
+       rm *.o
+
+mrproper: clean
+       rm $(EXEC)
diff --git a/utils/nanosleep.c b/utils/nanosleep.c
new file mode 100644
index 0000000..2ca17d5
--- /dev/null
+++ b/utils/nanosleep.c
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (C) 2011, Linaro Limited.
+ *
+ * This file is part of PM QA
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
+ *       - initial API and implementation
+ 
*******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <time.h>
+
+int main(int argc, char *argv[])
+{
+       struct timespec req = { 0 }, rem = { 0 };
+
+       if (argc != 2) {
+               fprintf(stderr, "%s <nanoseconds>\n", argv[0]);
+               return 1;
+       }
+
+       req.tv_nsec = atoi(argv[1]);
+
+       for (;;) {
+               if (!nanosleep(&req, &rem))
+                       break;
+
+               if (errno == EINTR) {
+                       req = rem;
+                       continue;
+               }
+
+               perror("failed to nanosleep");
+               return 1;
+       }
+
+       return 0;
+}
-- 
1.7.4.1


_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to