aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanjay Singh Rawat <sanjay.rawat@linaro.org>2014-02-05 18:12:17 +0530
committerSanjay Singh Rawat <sanjay.rawat@linaro.org>2014-02-20 11:40:57 +0530
commitd5963e55e84ba19740993e177b463a31e2dd8859 (patch)
tree6a1654ee1a8d3308f98392796cce8a3fe944659b
parent2876657a348f2a97471cf59a3a6833a66618c18e (diff)
add common function to check the userid
id command option doesn't return same output, as it does for ubuntu. Add function with will check the system type and return the userid. Signed-off-by: Sanjay Singh Rawat <sanjay.rawat@linaro.org>
-rwxr-xr-xcpufreq/cpufreq_03.sh11
-rwxr-xr-xcpufreq/cpufreq_04.sh11
-rwxr-xr-xcpufreq/cpufreq_05.sh5
-rwxr-xr-xcpufreq/cpufreq_06.sh5
-rwxr-xr-xcpufreq/cpufreq_07.sh5
-rwxr-xr-xcpufreq/cpufreq_08.sh5
-rwxr-xr-xcpufreq/cpufreq_09.sh5
-rwxr-xr-xcpuidle/cpuidle_02.sh5
-rwxr-xr-xcpuidle/cpuidle_03.sh5
-rw-r--r--cpuidle/cpuidle_04.sh5
-rw-r--r--include/functions.sh25
11 files changed, 61 insertions, 26 deletions
diff --git a/cpufreq/cpufreq_03.sh b/cpufreq/cpufreq_03.sh
index 0c59ce8..1e19e72 100755
--- a/cpufreq/cpufreq_03.sh
+++ b/cpufreq/cpufreq_03.sh
@@ -27,6 +27,12 @@
source ../include/functions.sh
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
+ exit 0
+fi
+
check_governor() {
local cpu=$1
@@ -43,10 +49,5 @@ check_governor() {
set_governor $cpu $oldgov
}
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
- exit 0
-fi
-
for_each_cpu for_each_governor check_governor || exit 1
test_status_show
diff --git a/cpufreq/cpufreq_04.sh b/cpufreq/cpufreq_04.sh
index 530366a..e75d9cb 100755
--- a/cpufreq/cpufreq_04.sh
+++ b/cpufreq/cpufreq_04.sh
@@ -27,6 +27,12 @@
source ../include/functions.sh
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
+ exit 0
+fi
+
check_frequency() {
local cpu=$1
@@ -46,11 +52,6 @@ check_frequency() {
set_governor $cpu $oldgov
}
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
- exit 0
-fi
-
supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "userspace")
if [ -z "$supported" ]; then
log_skip "userspace not supported"
diff --git a/cpufreq/cpufreq_05.sh b/cpufreq/cpufreq_05.sh
index 7830118..86c8b56 100755
--- a/cpufreq/cpufreq_05.sh
+++ b/cpufreq/cpufreq_05.sh
@@ -27,8 +27,9 @@
source ../include/functions.sh
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
diff --git a/cpufreq/cpufreq_06.sh b/cpufreq/cpufreq_06.sh
index 25c473e..7a3dd4b 100755
--- a/cpufreq/cpufreq_06.sh
+++ b/cpufreq/cpufreq_06.sh
@@ -101,8 +101,9 @@ check_deviation() {
for_each_frequency $cpu check_freq_deviation
}
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
diff --git a/cpufreq/cpufreq_07.sh b/cpufreq/cpufreq_07.sh
index abfad7f..029a5bd 100755
--- a/cpufreq/cpufreq_07.sh
+++ b/cpufreq/cpufreq_07.sh
@@ -77,8 +77,9 @@ check_ondemand() {
return 1
}
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
diff --git a/cpufreq/cpufreq_08.sh b/cpufreq/cpufreq_08.sh
index 79008f0..996472c 100755
--- a/cpufreq/cpufreq_08.sh
+++ b/cpufreq/cpufreq_08.sh
@@ -66,8 +66,9 @@ check_userspace() {
save_governors
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
diff --git a/cpufreq/cpufreq_09.sh b/cpufreq/cpufreq_09.sh
index a0c1171..08b7cb1 100755
--- a/cpufreq/cpufreq_09.sh
+++ b/cpufreq/cpufreq_09.sh
@@ -62,8 +62,9 @@ check_powersave() {
save_governors
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
diff --git a/cpuidle/cpuidle_02.sh b/cpuidle/cpuidle_02.sh
index e604a8b..77261c4 100755
--- a/cpuidle/cpuidle_02.sh
+++ b/cpuidle/cpuidle_02.sh
@@ -29,8 +29,9 @@ source ../include/functions.sh
CPUIDLE_KILLER=./cpuidle_killer
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
diff --git a/cpuidle/cpuidle_03.sh b/cpuidle/cpuidle_03.sh
index b07bc89..1138207 100755
--- a/cpuidle/cpuidle_03.sh
+++ b/cpuidle/cpuidle_03.sh
@@ -49,8 +49,9 @@ check_cpuidle_kill() {
check "cpuidle program runs successfully (120 secs)" "./$CPUIDLE_KILLER"
}
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
diff --git a/cpuidle/cpuidle_04.sh b/cpuidle/cpuidle_04.sh
index 1688873..028b3ee 100644
--- a/cpuidle/cpuidle_04.sh
+++ b/cpuidle/cpuidle_04.sh
@@ -27,8 +27,9 @@ source ../include/functions.sh
CPUIDLE_STATS=./cpuidle_stats
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
diff --git a/include/functions.sh b/include/functions.sh
index ffdac84..6d75e34 100644
--- a/include/functions.sh
+++ b/include/functions.sh
@@ -347,3 +347,28 @@ restore_frequencies() {
sigtrap() {
exit 255
}
+
+# currently we support ubuntu and android
+get_os() {
+ lsb_release -a 2>&1 | grep -i ubuntu > /dev/null
+ if [ $? -eq 0 ]; then
+ # for ubuntu
+ return 1
+ else
+ # for android (if needed can look for build.prop)
+ return 2
+ fi
+}
+
+is_root() {
+ local ret
+ get_os
+ if [ $? -eq 1 ]; then
+ # for ubuntu
+ ret=$(id -u)
+ else
+ # for android
+ ret=$(id | sed -n 's/uid=//p' | sed -n 's/(root) [a-z]*=[0-9]*(log)//p')
+ fi
+ return $ret
+}