summaryrefslogtreecommitdiff
path: root/recipes-production/mfg-tests/test-reset.sh
blob: 74474a1d21e310c7f784bbbdcc9c260966f2061a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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