summaryrefslogtreecommitdiff
path: root/bin
diff options
authorray.chen <ray.chen@canonical.com>2020-02-27 17:56:32 +0800
committerray.chen <ray.chen@canonical.com>2020-03-25 17:04:09 +0800
commit485c2bb7fa522a4b0957eca0041a34f66910884c (patch)
tree543126d62075a4eed4f638acd32df5b63d26144a /bin
parent0c06eadd115b2cf015b8edcb756fe9236c151753 (diff)
power: add light sensor test
Diffstat (limited to 'bin')
-rw-r--r--bin/light_sensor_test46
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/light_sensor_test b/bin/light_sensor_test
new file mode 100644
index 0000000..f413396
--- /dev/null
+++ b/bin/light_sensor_test
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+#Check if light sensor driver available, this section will be retired after checkbox resource jobs implement the light sensor in Device check
+#Bug for reference https://bugs.launchpad.net/checkbox-support/+bug/1864960
+als_sensors=$(udevadm info --export-db|grep hid_sensor_als)
+
+#Check hid_sensor_als driver is loaded and available first.
+if [ -z "$als_sensors" ]
+then
+ echo "Light sensor driver not found"
+ exit 1
+else
+ echo "Light sensor driver is available"
+ echo "$als_sensors"
+fi
+
+echo -e "\e[91mStart testing Ambient Light Sensor......\e[0m"
+sleep 2
+echo -e "\e[92mwaiting for sensor to be covered......\e[0m"
+sleep 3
+
+#Output and print light sensor events 5 sec to light_sensor_test.log
+timeout 5 monitor-sensor | tee $PLAINBOX_SESSION_SHARE/light_sensor_test.log &
+
+
+#Print backlight value for 5 sec on the screen
+for i in {1..10}
+do
+ echo "Current Backlight Percentage is:" $(gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.freedesktop.DBus.Properties.Get org.gnome.SettingsDaemon.Power.Screen Brightness)| tr -d '()<>,'
+ sleep 0.5
+done
+
+# Fail when the user didn't wave their hand and no events have been collected.
+if [[ $(cat $PLAINBOX_SESSION_SHARE/light_sensor_test.log | grep "Light changed" | wc -l) -lt 5 ]]; then
+echo -e "\e[91mFAIL: Not enough data to be collect, Please rerun the test case and wave your hand around Light Sensor.\e[0m"
+exit 1
+fi
+
+
+#Print 5 values of the Light sensor value form log file
+for i in {1..5}
+do
+ echo "Ambient light sensor value " $i: `grep 'Light' $PLAINBOX_SESSION_SHARE/light_sensor_test.log | awk '{print $3}' | sed -n "$i"p`
+done
+exit 0
+