-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_test.py
executable file
·248 lines (213 loc) · 8.33 KB
/
run_test.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env python
# Copyright (c) International Business Machines Corp., 2020
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details
# AUTHORS: [email protected], [email protected]
# PURPOSE: This is the thread script which actually calls runltp to execute LTP test
# 1. Reads the arguments passed by go_sls.py
# 2. Calls runltp to execute required LTP test
# 3. Captures the test results, updates REPORT.json and dumps html file to log directory
#
# SETUP: 1. Create or Edit ./sls_config file with test inputs
# 2. Install SLS: ./install_sls.py
# 3. Start SLS: ./start_sls.py <options>
# 4. go_sls.py gets called by ./start_sls.py
# 5. run_test.py gets called by go_sls.py as a multithreaded function
import os
import sys
import re
import fcntl
import datetime
import time
import json
from common_sls import lg,RunCommand,GetRandom
test = str(sys.argv[1])
iter = int(sys.argv[2])
suite = str(sys.argv[3])
dat = str(sys.argv[4])
str_time = str(sys.argv[5])
logdir = str(sys.argv[6])
START_TIME = datetime.datetime.strptime(str_time, '%Y%m%d%H%M%S')
C_TIME = datetime.datetime.now()
c_time = C_TIME.strftime('%Y%m%d%H%M%S')
tlog = '%s/run_test.log' % logdir
ltp_path = os.environ['ltp_path']
command = "mkdir -p %s/results" % (ltp_path)
RunCommand(command, tlog, 2, 0)
LOG_FILE = "%s/results/%s_%s" % (ltp_path,test, c_time)
#If its a IO test then give temp dir
if re.search(suite,os.environ['IO_LIST'],re.M):
command = "ls -d /tmp/*|grep ltp_io|tr '\n' ' '"
io_dirs = RunCommand(command, tlog, 2, 0)
iodirs = io_dirs.split(' ')
if len(iodirs) == 0:
io_dir = '/tmp'
elif len(iodirs) == 1:
io_dir = iodirs[0]
else:
ioindex = GetRandom(len(iodirs)-1,0)
io_dir = iodirs[ioindex]
command = "%s/runltp -I %d -f %s -s %s -g %s/LTP_HTML_LOG/%s.html -C /tmp/FAILCMDFILE -T /tmp/TCONFCMDFILE -o %s/output/%s_%s -l %s -p -d %s > /dev/null 2>&1" % (ltp_path, iter, suite, test, os.environ['TC_HTML_PATH'], test, ltp_path, test, c_time, LOG_FILE, io_dir)
else:
command = "%s/runltp -I %d -f %s -s %s -g %s/LTP_HTML_LOG/%s.html -C /tmp/FAILCMDFILE -T /tmp/TCONFCMDFILE -o %s/output/%s_%s -l %s -p > /dev/null 2>&1" % (ltp_path, iter, suite, test, os.environ['TC_HTML_PATH'], test, ltp_path, test, c_time, LOG_FILE)
os.system(command)
#Remove test line from In progress file
in_progess_file = os.environ['TC_OUTPUT'] + '/IN-PROGRESS-TEST'
lock_file = open('%s/ltp_inprogress.lock' % logdir, "w")
while True:
try:
fcntl.lockf(lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError:
time.sleep(GetRandom(5))
else:
break
with open(in_progess_file, 'r') as g:
ITESTS = g.readlines()
g.close()
inprog_tests = ''
for itst in ITESTS:
if not re.search(':', itst, re.M):
continue
t = itst.split(':')[0]
if test == t:
continue
inprog_tests = "%s\n%s" % (inprog_tests,itst)
g = open(in_progess_file, "w")
g.write(inprog_tests)
g.close()
fcntl.flock(lock_file, fcntl.LOCK_UN)
#Read TOTAL_TEST TOTAL_SKIP TOTAL_FAIL from log file
command = "grep 'Total Tests' %s | cut -f 2 -d :" % LOG_FILE
TOTAL_TEST = int(RunCommand(command, tlog, 2, 0).strip())
command = "grep 'Total Skipped Tests' %s | cut -f 2 -d :" % LOG_FILE
TOTAL_SKIP = int(RunCommand(command, tlog, 2, 0).strip())
command = "grep 'Total Failures' %s | cut -f 2 -d :" % LOG_FILE
TOTAL_FAIL = int(RunCommand(command, tlog, 2, 0).strip())
#Prepare Results
RESULTS = []
#Read Test numbers from html file
HTML_FILE = "%s/LTP_HTML_LOG/%s.html" % (os.environ['TC_HTML_PATH'], test)
command = "grep 'Total Test TBROK' %s|sed -e 's/<[^<>]*>//g'|sed 's/Total Test TBROK//'" % HTML_FILE
TOTAL_BROK = RunCommand(command, tlog, 2, 0).strip()
if TOTAL_BROK == '':
TOTAL_BROK = 0
else:
TOTAL_BROK = int(TOTAL_BROK)
command = "grep 'Total Test TCONF' %s|sed -e 's/<[^<>]*>//g'|sed 's/Total Test TCONF//'" % HTML_FILE
TOTAL_CONF = RunCommand(command, tlog, 2, 0).strip()
if TOTAL_CONF == '':
TOTAL_CONF = 0
else:
TOTAL_CONF = int(TOTAL_CONF)
TOTAL_PASS = TOTAL_TEST - TOTAL_SKIP - TOTAL_FAIL - TOTAL_CONF
if TOTAL_PASS < 0:
TOTAL_PASS = 0
if TOTAL_CONF == TOTAL_SKIP:
TOTAL_SKIP = 0
if (TOTAL_CONF + TOTAL_SKIP + TOTAL_BROK) >= TOTAL_TEST:
command = "echo '%s:%s' >> %s/sls_skip_conf_brok" % (test,suite,logdir)
RunCommand(command, tlog, 2, 0)
test_results = {}
test_results['TOTAL_ITRN'] = TOTAL_TEST
test_results['TOTAL_FAIL'] = TOTAL_FAIL
test_results['TOTAL_PASS'] = TOTAL_PASS
test_results['TOTAL_BROK'] = TOTAL_BROK
test_results['TOTAL_SKIP'] = TOTAL_SKIP
test_results['TOTAL_CONF'] = TOTAL_CONF
#Read REPORT.json for this test
MASTER_FILE=os.environ['TC_HTML_PATH'] + '/REPORT.json'
lock_file = open('%s/ltp.lock' % logdir, "w")
while True:
try:
fcntl.lockf(lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError:
time.sleep(GetRandom(5))
else:
break
with open(MASTER_FILE, 'r') as g:
REPORT = json.load(g)
g.close()
fcntl.flock(lock_file, fcntl.LOCK_UN)
REPORT_TESTS = REPORT['TESTS']
if test in REPORT_TESTS.keys():
OLD_RESULT = REPORT_TESTS[test]
NEW_RESULT = {}
NEW_RESULT['TOTAL_ITRN'] = OLD_RESULT['TOTAL_ITRN'] + test_results['TOTAL_ITRN']
NEW_RESULT['TOTAL_FAIL'] = OLD_RESULT['TOTAL_FAIL'] + test_results['TOTAL_FAIL']
NEW_RESULT['TOTAL_PASS'] = OLD_RESULT['TOTAL_PASS'] + test_results['TOTAL_PASS']
NEW_RESULT['TOTAL_BROK'] = OLD_RESULT['TOTAL_BROK'] + test_results['TOTAL_BROK']
NEW_RESULT['TOTAL_SKIP'] = OLD_RESULT['TOTAL_SKIP'] + test_results['TOTAL_SKIP']
NEW_RESULT['TOTAL_CONF'] = OLD_RESULT['TOTAL_CONF'] + test_results['TOTAL_CONF']
REPORT['TESTS'][test] = NEW_RESULT
else:
REPORT['TESTS'][test] = test_results
TOT_ITRN=0;TOT_PASS=0;TOT_FAIL=0;TOT_SKIP=0;TOT_BROK=0;TOT_CONF=0;
T_TC=0;T_TP=0;T_FL=0;T_BR=0;T_WA=0;T_CO=0
for tst in REPORT_TESTS.keys():
if REPORT_TESTS[tst]['TOTAL_ITRN'] != 0:
TOT_ITRN += REPORT_TESTS[tst]['TOTAL_ITRN']
if REPORT_TESTS[tst]['TOTAL_FAIL'] != 0:
TOT_FAIL += REPORT_TESTS[tst]['TOTAL_FAIL']
if REPORT_TESTS[tst]['TOTAL_PASS'] != 0:
TOT_PASS += REPORT_TESTS[tst]['TOTAL_PASS']
if REPORT_TESTS[tst]['TOTAL_BROK'] != 0:
TOT_BROK += REPORT_TESTS[tst]['TOTAL_BROK']
if REPORT_TESTS[tst]['TOTAL_SKIP'] != 0:
TOT_SKIP += REPORT_TESTS[tst]['TOTAL_SKIP']
if REPORT_TESTS[tst]['TOTAL_CONF'] != 0:
TOT_CONF += REPORT_TESTS[tst]['TOTAL_CONF']
if REPORT_TESTS[tst]['TOTAL_ITRN'] != 0:
T_TC += 1
if REPORT_TESTS[tst]['TOTAL_FAIL'] != 0:
T_FL += 1
elif REPORT_TESTS[tst]['TOTAL_CONF'] != 0:
T_CO += 1
elif REPORT_TESTS[tst]['TOTAL_BROK'] != 0:
T_BR += 1
elif REPORT_TESTS[tst]['TOTAL_SKIP'] != 0:
T_WA += 1
elif REPORT_TESTS[tst]['TOTAL_PASS'] != 0:
T_TP += 1
if TOT_ITRN == 0:
REPORT['RESULTS']['PASS%'] = 0
REPORT['RESULTS']['FAIL%'] = 0
REPORT['RESULTS']['SKIP%'] = 0
REPORT['RESULTS']['CONF%'] = 0
REPORT['RESULTS']['BROK%'] = 0
else:
REPORT['RESULTS']['PASS%'] = round((100 * TOT_PASS) / TOT_ITRN)
REPORT['RESULTS']['FAIL%'] = round((100 * TOT_FAIL) / TOT_ITRN)
REPORT['RESULTS']['SKIP%'] = round((100 * TOT_SKIP) / TOT_ITRN)
REPORT['RESULTS']['CONF%'] = round((100* TOT_CONF) / TOT_ITRN)
REPORT['RESULTS']['BROK%'] = round((100* TOT_BROK) / TOT_ITRN)
#Update RUNTIME
CURRENT_TIME = datetime.datetime.now()
cur_time = CURRENT_TIME.strftime('%Y%m%d%H%M%S')
CTIME = datetime.datetime.strptime(cur_time, '%Y%m%d%H%M%S')
if CTIME >= START_TIME:
REPORT['RESULTS']['RUNTIME'] = str(CTIME - START_TIME)
else:
REPORT['RESULTS']['RUNTIME'] = str(START_TIME - CTIME)
REPORT['RESULTS']['OVERVIEW'] = "TEST_CASES(%d) | TOTAL_ITR(%d/%d) | TOTAL_PASS(%d/%d) | TOTAL_FAIL(%d/%d) | TOTAL_BROK(%d/%d) | TOTAL_SKIP(%d/%d) | TOTAL_CONF(%d/%d)" % (T_TC,TOT_ITRN,T_TC,TOT_PASS,T_TP,TOT_FAIL,T_FL,TOT_BROK,T_BR,TOT_SKIP,T_WA,TOT_CONF,T_CO)
lock_file = open('%s/ltp.lock' % logdir, "w")
while True:
try:
fcntl.lockf(lock_file.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
except IOError:
time.sleep(1)
else:
break
with open(MASTER_FILE, "w") as g:
json.dump(REPORT, g)
g.close()
fcntl.flock(lock_file, fcntl.LOCK_UN)
fcntl.flock(lock_file, fcntl.LOCK_UN)
fcntl.flock(lock_file, fcntl.LOCK_UN)