diff options
Diffstat (limited to 'recipes-production/mfg-tests/test-reset.sh')
-rwxr-xr-x | recipes-production/mfg-tests/test-reset.sh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/recipes-production/mfg-tests/test-reset.sh b/recipes-production/mfg-tests/test-reset.sh new file mode 100755 index 0000000..74474a1 --- /dev/null +++ b/recipes-production/mfg-tests/test-reset.sh @@ -0,0 +1,76 @@ +#!/bin/bash +#the script disables main reset-handler and it allows to test the reset button +# #test-reset 60 +# .....<user has pressed the reset button> +# echo $? +# 0 +# #test-reset 60 +# .....<user has not pressed the reset button> +# echo $? +# 2 +# in this example script is waiting for reset button pressing with 60 seconds timeout. +# if the button was pressed, the script stops and returns '0' return code. +# if the reset button was not pressed, the script returns '2' + +log="logger -t $name -s" +name=$0 +pid="$$" + +if (($(id -u) != 0)); then + echo "You must be root to do a reset test" + exit 1 +fi + +if [ "$#" -ne 1 ]; then + echo "Illegal usage." + echo "Usage: $name <timeout>" + exit 1 +fi + +timeout=$1 + +short_signal=10 # SIGUSR1 +long_signal=12 # SIGUSR2 +extralong_signal=1 # SIGHUP + +do_disable_reset_handler() { + #stop main reset handler + /etc/init.d/reset-handler stop >/dev/null 2>&1 +} + +do_restore_reset_handler() { + #restore main reset handler + /etc/init.d/reset-handler start >/dev/null 2>&1 +} + +do_press_reset() { + $log "reset pressed" + sleep 1 #it will protect if a user make 'double-click' + do_restore_reset_handler + exit 0 +} + +do_exit() { + do_restore_reset_handler + $log "Exiting on SIGTERM" + exit 2 +} + +trap do_press_reset $short_signal +trap do_press_reset $long_signal +trap do_press_reset $extralong_signal +trap do_exit TERM +trap do_exit SIGINT + +do_disable_reset_handler + +$log "Enabling reset-monitor for pid $pid" +mts-io-sysfs store reset-monitor "$pid $short_signal $long_signal $extralong_signal" +# set long press to 5 seconds for reset to defaults +mts-io-sysfs store reset-monitor-intervals "5 30" + +sleep $timeout & +wait + +do_restore_reset_handler +exit 2
\ No newline at end of file |