-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhungtask.py
executable file
·75 lines (63 loc) · 2.75 KB
/
hungtask.py
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
#!/usr/bin/python
import os
import sys
import time
import datetime
import subprocess
import argparse
def main():
fnull = open(os.devnull,"w")
ret = subprocess.call(["which", "sshpass"], stdout=fnull, stderr=subprocess.STDOUT)
if ret == 1:
print "'sshpass' is required."
sys.exit(0)
ret = subprocess.call(["which", "ssh"], stdout=fnull, stderr=subprocess.STDOUT)
if ret == 1:
print "'openssh-client' is required."
sys.exit(0)
fnull.close()
parser = argparse.ArgumentParser(description='perform "HUNG_TASK" test via remote ssh')
parser.add_argument('--remote', dest='remote', type=str, metavar='IP', default='10.5.232.37', help='rermote IP address')
parser.add_argument('--loops', dest='loops', type=int, default=10, help='iterator loops')
parser.add_argument('--sleep', dest='sleep', type=int, default=30, help='sleep seconds per test')
args = parser.parse_args()
print args
prefix = ['sshpass', '-p', 'test0000', 'ssh', '-q',
'-oStrictHostKeyChecking=no', '-oUserKnownHostsFile=/dev/null',
'-oConnectTimeout=10', '-oServerAliveInterval=5' ]
cmd1 = ['echo 3 > /proc/sys/kernel/hung_task_timeout_secs']
cmd2 = ['cat /proc/sys/kernel/hung_task_timeout_secs']
cmd3 = ['echo HUNG_TASK > /sys/kernel/debug/provoke-crash/DIRECT &']
cmd4 = ['dmesg | tail -3']
cmd5 = ['i=1; while true; do echo $i; let i++; sleep 1; done']
prefix.append("root@" + args.remote)
for i in range(args.loops):
try:
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": cmd1: ", cmd1
ret = subprocess.check_output(prefix + cmd1)
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": cmd2: ", cmd2
ret = subprocess.check_output(prefix + cmd2)
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": hung_task_timeout_secs:", ret
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": cmd3: ", cmd3
subprocess.call(prefix + cmd3)
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": cmd4: ", cmd4
ret = subprocess.check_output(prefix + cmd4)
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": dmesg:\n", ret
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": cmd5: ", cmd5
subprocess.call(prefix + cmd5)
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": sleep: ", args.sleep
time.sleep(args.sleep)
except subprocess.CalledProcessError as err:
now = str(datetime.datetime.fromtimestamp(time.time()))
print now, ": ", str(i).rjust(4), ": error code: ", err.returncode
break;
if __name__ == '__main__':
main()