@@ -49,8 +49,9 @@ check_governor() {
set_governor $cpu $oldgov
}
-if [ $(id -u) -ne 0 ]; then
- log_skip "run as non-root"
+get_uid
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
@@ -33,6 +33,12 @@ if [ $? -ne 0 ]; then
exit 0
fi
+get_uid
+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"
+get_uid
+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"
+get_uid
+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"
+get_uid
+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"
+get_uid
+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"
+get_uid
+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"
+get_uid
+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"
+get_uid
+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
+get_uid
+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"
+get_uid
+if [ $? -ne 0 ]; then
+ log_skip "user is not root"
exit 0
fi
@@ -348,3 +348,29 @@ 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)
+ return $ret
+ else
+ # for android
+ ret=$(id | sed -n 's/uid=//p' | sed -n 's/(root) [a-z]*=[0-9]*(log)//p')
+ return $ret
+ fi
+}
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> --- cpufreq/cpufreq_03.sh | 5 +++-- 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 | 26 ++++++++++++++++++++++++++ 11 files changed, 61 insertions(+), 24 deletions(-)