xref: /OK3568_Linux_fs/debian/overlay-debug/rockchip-test/auto_reboot/auto_reboot.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/bash
2
3delay=8
4total=${1:-10000}
5fudev=/dev/sda
6CNT=/data/rockchip-test/reboot_cnt
7
8if [ ! -e "/data/rockchip-test" ]; then
9	echo "no /data/rockchip-test"
10	mkdir -p /data/rockchip-test
11fi
12
13if [ ! -e "/data/rockchip-test/auto_reboot.sh" ]; then
14	cp -f /rockchip-test/auto_reboot/auto_reboot.sh /data/rockchip-test/
15	cp -f /rockchip-test/auto_reboot/auto_reboot_test.sh /etc/init.d/
16	cp -f /rockchip-test/auto_reboot/rockchip_reboot.service /lib/systemd/system/
17	ln -sf /lib/systemd/system/rockchip_reboot.service /etc/systemd/system/multi-user.target.wants/
18
19        echo $total > /data/rockchip-test/reboot_total_cnt
20    sync
21fi
22
23while true
24do
25
26#if [ ! -e "$fudev" ]; then
27#    echo "Please insert a U disk to start test!"
28#    exit 0
29#fi
30
31if [ -e $CNT ]
32then
33    cnt=`cat $CNT`
34else
35    echo reset Reboot count.
36    echo 0 > $CNT
37fi
38
39echo  Reboot after $delay seconds.
40
41let "cnt=$cnt+1"
42
43if [ $cnt -ge $total ]
44then
45    echo AutoReboot Finisned.
46    echo "off" > $CNT
47    echo "do cleaning ..."
48    rm -rf /data/rockchip-test/auto_reboot.sh
49    rm -rf /data/rockchip-test/reboot_total_cnt
50    rm -f $CNT
51    sync
52    exit 0
53fi
54
55echo $cnt > $CNT
56echo "current cnt = $cnt, total cnt = $total"
57echo "You can stop reboot by: echo off > /data/rockchip-test/reboot_cnt"
58sleep $delay
59cnt=`cat $CNT`
60if [ $cnt != "off" ]; then
61    sync
62    if [ -e /var/lib/systemd/pstore/console-ramoops-0 ]; then
63        echo "check console-ramoops-o message"
64        grep -q "Restarting system" /var/lib/systemd/pstore/console-ramoops-0
65        if [ $? -ne 0 -a $cnt -ge 2 ]; then
66           echo "no found 'Restarting system' log in last time kernel message"
67           echo "consider kernel crash in last time reboot test"
68           echo "quit reboot test"
69            rm -rf /data/rockchip-test/auto_reboot.sh
70            rm -rf /data/rockchip-test/reboot_total_cnt
71            sync
72	   exit 1
73        else
74	   reboot
75        fi
76    else
77	   reboot
78    fi
79else
80    echo "Auto reboot is off"
81    rm -rf /data/rockchip-test/auto_reboot.sh
82    rm -rf /data/rockchip-test/reboot_total_cnt
83    rm -f $CNT
84    sync
85fi
86exit 0
87done
88