forked from intelxed/xed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-internal.py
280 lines (235 loc) · 9.19 KB
/
ci-internal.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#BEGIN_LEGAL
#
#Copyright (c) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#END_LEGAL
'''run CI checks on gitlab'''
import os
import sys
import platform
import subprocess
sys.path = ['scripts'] + sys.path
import send_sms
class jobs_status_t:
'''record job status (success, failure and (retval,job) list'''
def __init__(self):
self.jobs = 0
self.fails = 0
self.successes = 0
self.commands = [] # list of tuples of (retval, command)
def __str__(self):
s = []
s.append("JOBS: {}, SUCCESSES: {}, FAILS: {}".format(
self.jobs, self.successes, self.fails))
i = 0
for r, c in self.commands:
s.append("{}: status: {} cmd: {}".format(i, r, c))
i = i+1
return "\n".join(s) + '\n'
def addjob(self, retval, cmd):
self.jobs += 1
self.commands.append((retval, cmd))
def fail(self, retval, cmd):
self.fails += 1
self.addjob(retval, cmd)
def success(self, retval, cmd):
self.successes += 1
self.addjob(retval, cmd)
def pass_rate_fraction(self):
return '{}/{}'.format(self.successes, self.jobs)
def success(status):
'''send success SMS'''
sys.stdout.write("FINAL STATUS: PASS\n")
sys.stdout.write(str(status))
sys.stdout.flush()
#send_sms.send("XED CI: Passed ({} passing)".format(
# status.pass_rate_fraction()))
sys.exit(0)
def fail(status):
'''send failing SMS'''
sys.stdout.write("FINAL STATUS: FAIL\n")
sys.stdout.write(str(status))
sys.stdout.flush()
#send_sms.send("XED CI: Failed ({} passing)".format(
# status.pass_rate_fraction()))
sys.exit(1)
def ensure_string(x):
'''handle non unicode output'''
if isinstance(x, bytes):
return x.decode('utf-8')
return x
def run_subprocess(cmd, **kwargs):
'''front end to running subprocess'''
sub = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
**kwargs)
lines = sub.stdout.readlines()
lines = [ensure_string(x) for x in lines]
sub.wait()
return sub.returncode, lines
def run(status, cmd, required=False, cwd=None):
'''run subprocess, and record fails'''
print(cmd)
retval, output = run_subprocess(cmd, cwd=cwd)
for line in output:
sys.stdout.write(line)
if retval == 0:
print("[SUCCESS]")
status.success(retval, cmd)
else:
print("[FAIL] retval = {}".format(retval))
status.fail(retval, cmd)
if required:
fail("Required task failed")
return retval == 0 # 1=ok!
def get_python_cmds():
'''find python verions. return tuples of (name, command)'''
if platform.system() == 'Windows':
return [(x, 'C:/python{}/python'.format(x)) for x in ['37']]
if platform.system() in ['Darwin', 'Linux']:
# The file .travis.yml installs python3 on linux. Already present on mac
return [('3.x', 'python3')]
return [('dfltpython', 'python')]
def all_instr(pyver, pycmd, status, kind):
size = 'x86-64'
linkkind = 'static'
build_dir = 'obj-{}-{}-{}-{}'.format(kind, pyver, size, linkkind)
cwd = os.path.abspath(os.curdir)
flags = '--kind {} --enc2-test-checked'.format(kind)
cmd = '{} xedext/xed_build.py --xed-dir {} {} --build-dir={} host_cpu={}'.format(
pycmd, cwd, flags, build_dir, size)
ok = run(status, cmd)
if ok:
cmd = '{}/enc2-m64-a64/enc2tester-enc2-m64-a64 --reps 1 --main --gnuasm > a.c'.format(
build_dir)
ok = run(status, cmd)
if 1: # FIXME: ignore error code for now.
cmd = 'gcc a.c'
run(status, cmd)
if ok:
cmd = '{}/wkit/bin/xed -i a.out > all.dis'.format(build_dir)
run(status, cmd)
def archval(pyver, pycmd, status):
size = 'x86-64'
linkkind = 'static'
build_dir = 'obj-archval-{}-{}-{}'.format(pyver, size, linkkind)
cwd = os.path.abspath(os.curdir)
flags = '--kind architectural-val ' + os.getenv('ARCHVAL_OPTIONS')
cmd = '{} xedext/xed_build.py --xed-dir {} {} --build-dir={} host_cpu={}'.format(
pycmd, cwd, flags, build_dir, size)
run(status, cmd)
def get_branches_from_file():
f = open("misc/ci-branches.txt","r")
lines = f.readlines()
f.close()
d = {}
for x in lines:
x = x.strip()
a = x.split()
repo=a[0]
branch=a[1]
print("READING REPO: {} TO BRANCH: {}".format(repo, branch))
d[repo]=branch
return d
def checkout_branches(status, branches):
for repo,branch in branches.items():
print("CHANGING REPO: {} TO BRANCH: {}".format(repo, branch))
run(status, "git checkout {}".format(branch), cwd=repo)
def main():
status = jobs_status_t()
# FIXME: add knob for local use
# git_base = 'ssh://[email protected]/xed-group/'
git_base = 'https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.devtools.intel.com/xed-group/'
mbuild_git = git_base + 'mbuild.git'
cmd = 'git clone {} mbuild'.format(mbuild_git)
run(status, cmd, required=True)
# IPLDT scan XED and MBUILD
if 0: # disabled until get right branch
# obtain IPLDT scanner tool
bintools_git = git_base + 'binary-tools.git'
cmd = 'git clone --depth 1 {} binary-tools'.format(bintools_git)
run(status, cmd, required=True)
# clone another copy of xed sources just for IPLDT scanning
# FIXME: need to get the branch we are testing!
xed_git = git_base + 'xed.git'
cmd = 'git clone --depth 1 {} xed'.format(xed_git)
run(status, cmd, required=True)
cmd = 'binary-tools/lin/ipldt3 -i xed -r ipldt-results-xed'
run(status, cmd, required=False)
cmd = 'cat ipldt-results-xed/ipldt_results.txt'
run(status, cmd, required=True)
cmd = 'binary-tools/lin/ipldt3 -i mbuild -r ipldt-results-mbuild'
run(status, cmd, required=False)
cmd = 'cat ipldt-results-mbuild/ipldt_resuplts.txt'
run(status, cmd, required=True)
xedext_git = git_base + 'xedext.git'
cmd = 'git clone {} xedext'.format(xedext_git)
run(status, cmd, required=True)
# check a few lines to make sure we have latest commits
cmd = 'git -C xedext log --oneline -5'
run(status, cmd, required=True)
branches = get_branches_from_file()
checkout_branches(status, branches)
archval_repo = os.getenv('ARCHVAL_REPO')
if archval_repo:
archval_git = git_base + archval_repo
short_name = os.path.splitext(archval_repo)[0]
cmd = 'git clone {} {}'.format(archval_git, short_name)
run(status, cmd, required=True)
for pyver, pycmd in get_python_cmds():
cmd = '{} -m pip install --user ./mbuild'.format(pycmd)
run(status, cmd, required=True)
# {32b,64b} x {shared,dynamic} link
for size in ['ia32', 'x86-64']:
for linkkind, link in [('static', ''), ('dynamic', '--shared')]:
build_dir = 'obj-general-{}-{}-{}'.format(pyver, size, linkkind)
cmd = '{} mfile.py --build-dir={} host_cpu={} {} test'.format(pycmd,
build_dir,
size,
link)
run(status, cmd)
# do a build with asserts enabled
build_dir = 'obj-assert-{}-{}'.format(pyver, 'x86-64')
cmd = '{} mfile.py --asserts --build-dir={} host_cpu={} test'.format(pycmd,
build_dir,
'x86-64')
run(status, cmd)
# all instr tests
all_instr(pyver, pycmd, status, 'internal-conf')
all_instr(pyver, pycmd, status, 'external')
# arch val test
archval(pyver, pycmd, status)
# knc test
if 0:
size = 'x86-64'
linkkind = 'static'
build_dir = 'obj-knc-{}-{}-{}'.format(pyver, size, linkkind)
cmd = '{} mfile.py --knc --build-dir={} host_cpu={} test'.format(
pycmd, build_dir, size)
run(status, cmd)
if status.fails == 0:
success(status)
fail(status)
def test():
status = jobs_status_t()
status.success(1, 'foo')
status.success(1, 'bar')
fail(status)
if __name__ == "__main__":
#test()
main()
sys.exit(0)