-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjudge_ltp-glibc.py
More file actions
112 lines (98 loc) · 3.89 KB
/
Copy pathjudge_ltp-glibc.py
File metadata and controls
112 lines (98 loc) · 3.89 KB
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
import re
import sys
import json
template = '''
RUN LTP CASE writev01
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_wriRnYU84 as tmpdir (ext2/ext3/ext4 filesystem)
tst_test.c:1860: TINFO: LTP version: 20240930
tst_test.c:1864: TINFO: Tested kernel: 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64
tst_test.c:1703: TINFO: Timeout per run is 0h 00m 30s
writev01.c:124: TPASS: invalid iov_len, expected: -1 (EINVAL), got: -1 (EINVAL)
writev01.c:124: TPASS: invalid fd, expected: -1 (EBADF), got: -1 (EBADF)
writev01.c:124: TPASS: invalid iovcnt, expected: -1 (EINVAL), got: -1 (EINVAL)
writev01.c:129: TPASS: zero iovcnt, expected: 0, got: 0
writev01.c:129: TPASS: NULL and zero length iovec, expected: 64, got: 64
writev01.c:124: TPASS: write to closed pipe, expected: -1 (EPIPE), got: -1 (EPIPE)
Summary:
passed 6
failed 0
broken 0
skipped 0
warnings 0
END LTP CASE writev01 : 0
RUN LTP CASE setegid02
tst_test.c:1860: TINFO: LTP version: 20240930
tst_test.c:1864: TINFO: Tested kernel: 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64
tst_test.c:1703: TINFO: Timeout per run is 0h 00m 30s
setegid02.c:29: TPASS: setegid(65534) : EPERM (1)
Summary:
passed 1
failed 0
broken 0
skipped 0
warnings 0
END LTP CASE setegid02: 0
'''
def parse_ltp_log(content):
lines = content.split('\n')
result = {}
current_case = None
return_code = None
in_summary = False
skip_summary = False
for line in lines:
line = re.sub(r'\x1b\[[0-9;]*m', '', line) # strip ANSI color codes so kernel log pollution doesn't crash the judge
stripped_line = line.strip()
if stripped_line.startswith('RUN LTP CASE'):
current_case = stripped_line.split()[-1]
summary_data = {'passed': 0, 'failed': 0, 'broken': 0, 'skipped': 0, 'warnings': 0, 'all': 0}
summary_seen = False
return_code = None
in_summary = False
elif current_case and stripped_line.startswith(f'FAIL LTP CASE {current_case}'):
parts = stripped_line.split()
return_code = int(parts[-1])
success = summary_data.get('passed', 0)
result[current_case] = {
'passed': summary_data['passed'],
'failed': summary_data['failed'],
'broken': summary_data['broken'],
'skipped': summary_data['skipped'],
'warnings': summary_data['warnings'],
'all': summary_data['all'],
'success': success
}
current_case = None
elif current_case:
if stripped_line == 'Summary:':
in_summary = True
if summary_seen:
skip_summary = True
continue
summary_seen = True
skip_summary = False
continue
if in_summary:
if not stripped_line:
in_summary = False
continue
if skip_summary:
continue
parts = stripped_line.split()
if len(parts) >= 2 and parts[0] in ['passed', 'failed', 'broken', 'skipped', 'warnings']:
key = parts[0]
m = re.match(r'\d+', parts[1])
if m is None:
continue # line polluted by interleaved kernel log, skip instead of crash
value = int(m.group())
summary_data[key] += value
summary_data['all'] += value
return result
result = parse_ltp_log(sys.stdin.read())
result = [{
"name": k,
"pass": v["success"],
"all": v["all"],
"score": v["success"] # 暂时用 success 值做分数
} for k, v in result.items()]
print(json.dumps(result))