@@ -27,6 +27,12 @@
source ../include/functions.sh
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
+ exit 0
+fi
+
cpufreq_enabled
if [ $? -ne 0 ]; then
log_skip "cpufreq not supported"
@@ -49,10 +55,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
@@ -33,6 +33,12 @@ if [ $? -ne 0 ]; then
exit 0
fi
+is_root
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
+ exit 0
+fi
+
check_frequency() {
local cpu=$1
@@ -52,11 +58,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"
@@ -33,8 +33,9 @@ if [ $? -ne 0 ]; then
exit 0
fi
-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
@@ -107,8 +107,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
@@ -83,8 +83,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
@@ -72,8 +72,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
@@ -68,8 +68,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
@@ -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
@@ -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
@@ -49,7 +50,8 @@ check_cpuidle_kill() {
check "cpuidle program runs successfully (120 secs)" "./$CPUIDLE_KILLER"
}
-if [ $(id -u) -ne 0 ]; then
+is_root
+if [ $? -ne 0 ]; then
log_skip "run as non-root"
exit 0
fi
@@ -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
@@ -348,3 +348,28 @@ sigtrap() {
cpufreq_enabled() {
test -d /sys/devices/system/cpu/cpufreq
}
+
+# 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
+}
+
+get_uid() {
+ 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
+}
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> --- On android the script shows error for "id" commadn return value. Added function to get the userid based on system type (ubuntu/android). - calling function in below manner doesn't return value to the _if_ case if [ $(is_root) -eq 0 ]; then so i am using is_root if [ $? -eq 0 ] - saving return value of function is not working on android. e.g local ret=$(is_root) Belows changes work find both. thanks, sanjay --- cpufreq/cpufreq_03.sh | 11 ++++++----- cpufreq/cpufreq_04.sh | 11 ++++++----- cpufreq/cpufreq_05.sh | 5 +++-- cpufreq/cpufreq_06.sh | 5 +++-- cpufreq/cpufreq_07.sh | 5 +++-- cpufreq/cpufreq_08.sh | 5 +++-- cpufreq/cpufreq_09.sh | 5 +++-- cpuidle/cpuidle_02.sh | 5 +++-- cpuidle/cpuidle_03.sh | 8 +++++--- cpuidle/cpuidle_04.sh | 5 +++-- include/functions.sh | 25 +++++++++++++++++++++++++ 11 files changed, 63 insertions(+), 27 deletions(-)