-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-kernel-ci.py
executable file
·1622 lines (1271 loc) · 51.1 KB
/
run-kernel-ci.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import os
import sys
import argparse
import logging
import subprocess
import configparser
import requests
import re
import smtplib
import shutil
import email.utils
import time
from enum import Enum
from github import Github
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from pathlib import Path
# Globals
logger = None
config = None
github_repo = None
github_pr = None
github_commits = None
pw_sid = None
pw_series = None
pw_series_patch_1 = None
src_dir = None
src2_dir = None
bluez_dir = None
output_dir = None
test_suite = {}
# Test Runner Context
test_runner_context = None
PW_BASE_URL = "https://patchwork.kernel.org/api/1.1"
EMAIL_MESSAGE = '''This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:{}
---Test result---
{}
---
Regards,
Linux Bluetooth
'''
def requests_url(url):
""" Helper function to requests WEB API GET with URL """
resp = requests.get(url)
if resp.status_code != 200:
raise requests.HTTPError("GET {}".format(resp.status_code))
return resp
def requests_post(url, headers, content):
""" Helper function to post data to URL """
resp = requests.post(url, content, headers=headers)
if resp.status_code != 201:
raise requests.HTTPError("POST {}".format(resp.status_code))
return resp
def patchwork_get_series(sid):
""" Get series detail from patchwork """
url = PW_BASE_URL + "/series/" + sid
req = requests_url(url)
return req.json()
def patchwork_get_patch(patch_id: str):
""" Get patch detsil from patchwork """
url = PW_BASE_URL + "/patches/" + patch_id
req = requests_url(url)
return req.json()
def patchwork_save_patch(patch, filename):
""" Save patch to file and return the file path """
patch_mbox = requests_url(patch["mbox"])
with open(filename, "wb") as file:
file.write(patch_mbox.content)
return filename
def patchwork_save_patch_msg(patch, filename):
""" Save patch commit message to file and return the file path """
with open(filename, "wb") as file:
file.write(bytes(patch['name'], 'utf-8'))
file.write(b"\n\n")
file.write(bytes(patch['content'], 'utf-8'))
return filename
def patchwork_get_sid(pr_title):
"""
Parse PR title prefix and get PatchWork Series ID
PR Title Prefix = "[PW_S_ID:<series_id>] XXXXX"
"""
try:
sid = re.search(r'^\[PW_SID:([0-9]+)\]', pr_title).group(1)
except AttributeError:
logger.error("Unable to find the series_id from title %s" % pr_title)
sid = None
return sid
def patchwork_get_patch_detail_title(title):
"""
Use :title to find a matching patch in series and get the detail
"""
for patch in pw_series['patches']:
if (patch['name'].find(title) != -1):
logger.debug("Found matching patch title in the series")
req = requests_url(patch['url'])
return req.json()
logger.debug("No matching patch title found")
logger.error("Cannot find a matching patch from PatchWork series")
def patchwork_post_checks(url, state, target_url, context, description):
"""
Post checks(test results) to the patchwork site(url)
"""
logger.debug("URL: %s" % url)
headers = {}
if 'PATCHWORK_TOKEN' in os.environ:
token = os.environ['PATCHWORK_TOKEN']
headers['Authorization'] = f'Token {token}'
content = {
'user': 104215,
'state': state,
'target_url': target_url,
'context': context,
'description': description
}
logger.debug("Content: %s" % content)
req = requests_post(url, headers, content)
return req.json()
GITHUB_COMMENT = '''**{display_name}**
Test ID: {name}
Desc: {desc}
Duration: {elapsed:.2f} seconds
**Result: {status}**
'''
GITHUB_COMMENT_OUTPUT = '''Output:
```
{output}
```
'''
def github_pr_post_comment(test):
""" Post message to PR page """
comment = GITHUB_COMMENT.format(name=test.name,
display_name=test.display_name,
desc=test.desc,
status=test.verdict.name,
elapsed=test.elapsed())
if test.output:
output = GITHUB_COMMENT_OUTPUT.format(output=test.output)
comment += output
github_pr.create_issue_comment(comment)
def run_cmd(*args, cwd=None):
""" Run command and return return code, stdout and stderr """
cmd = []
cmd.extend(args)
cmd_str = "{}".format(" ".join(str(w) for w in cmd))
logger.info("CMD: %s" % cmd_str)
stdout = ""
try:
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
bufsize=1,
universal_newlines=True,
cwd=cwd)
except OSError as e:
logger.error("ERROR: failed to run cmd: %s" % e)
return (-1, None, None)
for line in proc.stdout:
logger.debug(line.rstrip('\n'))
stdout += line
# stdout is consumed in previous line. so, communicate() returns empty
_ignore, stderr = proc.communicate()
logger.debug(">> STDERR\n{}".format(stderr))
return (proc.returncode, stdout, stderr)
def config_enable(config, name):
"""
Check "enable" in config[name].
Return False if it is specifed otherwise True
"""
if name in config:
if 'enable' in config[name]:
if config[name]['enable'] == 'no':
logger.info("config." + name + " is disabled")
return False
logger.info("config." + name + " is enabled")
return True
def config_submit_pw(config, name):
"""
Check "submit_pw" in config[name]
Return True if it is specified and value is "yes"
"""
if name in config:
if 'submit_pw' in config[name]:
if config[name]['submit_pw'] == 'yes':
logger.info("config." + name + ".submit_pw is enabled")
return True
logger.info("config." + name + ".submit_pw is disabled")
return False
def send_email(sender, receiver, msg):
""" Send email """
email_cfg = config['email']
logger.debug("Send email with result")
if 'EMAIL_TOKEN' not in os.environ:
logger.warning("missing EMAIL_TOKEN. Skip sending email")
return
logger.debug("EMAIL TOKEN is set in Environment")
try:
session = smtplib.SMTP(email_cfg['server'], int(email_cfg['port']))
logger.debug("SMTP session is created")
session.ehlo()
if 'starttls' not in email_cfg or email_cfg['starttls'] == 'yes':
session.starttls()
logger.debug("SMTP TLS is set")
session.ehlo()
session.login(sender, os.environ['EMAIL_TOKEN'])
logger.debug("SMTP EMAIL_TOKEN is set")
session.sendmail(sender, receiver, msg.as_string())
logger.info("Successfully sent email")
except Exception as e:
logger.error("Exception: {}".format(e))
finally:
session.quit()
logger.info("Sending email done")
def get_receivers(submitter):
"""
Get list of receivers
"""
logger.debug("Get Receivers list")
email_cfg = config['email']
receivers = []
if 'only-maintainers' in email_cfg and email_cfg['only-maintainers'] == 'yes':
# Send only to the addresses in the 'maintainers'
maintainers = "".join(email_cfg['maintainers'].splitlines()).split(",")
receivers.extend(maintainers)
else:
# Send to default-to address and submitter
receivers.append(email_cfg['default-to'])
receivers.append(submitter)
return receivers
def get_sender():
"""
Get Sender from configuration
"""
email_cfg = config['email']
return email_cfg['user']
def get_default_to():
"""
Get Default address which is a mailing list address
"""
email_cfg = config['email']
return email_cfg['default-to']
def is_maintainer_only():
"""
Return True if it is configured to send maintainer-only
"""
email_cfg = config['email']
if 'only-maintainers' in email_cfg and email_cfg['only-maintainers'] == 'yes':
return True
return False
def compose_email(title, body, submitter, msgid, attachments=[]):
"""
Compose and send email
"""
receivers = get_receivers(submitter)
sender = get_sender()
# Create message
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = ", ".join(receivers)
msg['Subject'] = "RE: " + title
# In case to use default-to address, set Reply-To to mailing list in case
# submitter reply to the result email.
if not is_maintainer_only():
msg['Reply-To'] = get_default_to()
# Message Header
msg.add_header('In-Reply-To', msgid)
msg.add_header('References', msgid)
logger.debug("Message Body: %s" % body)
msg.attach(MIMEText(body, 'plain'))
logger.debug("Mail Message: {}".format(msg))
# Attachment
# logger.debug("Attachment count=%d" % len(attachments))
# for logfile in attachments:
# logfile_base = os.path.basename(logfile)
# with open(logfile, "rb") as f:
# part = MIMEApplication(f.read(), Name=logfile_base)
# part['Content-Disposition'] = 'attachment; filename="%s"' % logfile_base
# msg.attach(part)
# logger.debug("Attached file: %s(%s)" % (logfile, logfile_base))
# Send email
send_email(sender, receivers, msg)
def is_workflow_patch(commit):
"""
If the message contains a word "workflow", then return True.
This is basically to prevent the workflow patch for github from running
checkpath and gitlint tests.
"""
if commit.commit.message.find("workflow:") >= 0:
return True
return False
class Verdict(Enum):
PENDING = 0
PASS = 1
FAIL = 2
ERROR = 3
SKIP = 4
WARNING = 5
def patchwork_state(verdict):
"""
Convert verdict to patchwork state
"""
if verdict == Verdict.PASS:
return 1
if verdict == Verdict.WARNING:
return 2
if verdict == Verdict.FAIL:
return 3
return 0
class CiBase:
"""
Base class for CI Tests.
"""
name = None
display_name = None
desc = None
enable = True
start_time = 0
end_time = 0
submit_pw = False
verdict = Verdict.PENDING
output = ""
def success(self):
self.end_timer()
self.verdict = Verdict.PASS
def add_success(self, msg):
self.verdict = Verdict.PASS
if not self.output:
self.output = msg
else:
self.output += "\n" + msg
self.end_timer()
def error(self, msg):
self.verdict = Verdict.ERROR
self.output = msg
self.end_timer()
raise EndTest
def skip(self, msg):
self.verdict = Verdict.SKIP
self.output = msg
self.end_timer()
raise EndTest
def add_failure(self, msg):
self.verdict = Verdict.FAIL
if not self.output:
self.output = msg
else:
self.output += "\n" + msg
self.end_timer()
def add_failure_end_test(self, msg):
self.add_failure(msg)
raise EndTest
def start_timer(self):
self.start_time = time.time()
def end_timer(self):
self.end_time = time.time()
def elapsed(self):
if self.start_time == 0:
return 0
if self.end_time == 0:
self.end_timer()
return self.end_time - self.start_time
def submit_result(self, patch, verdict, description, url=None, name=None):
"""
Submit the result to Patchwork
"""
if self.submit_pw == False:
logger.info("Submitting PW is disabled. Skipped")
return
if url == None:
url = github_pr.html_url
if name == None:
name = self.name
logger.debug("Submitting the result to Patchwork")
pw_output = patchwork_post_checks(patch['checks'],
patchwork_state(verdict),
url,
name,
description)
logger.debug("Submit result\n%s" % pw_output)
class CheckPatch(CiBase):
name = "checkpatch"
display_name = "CheckPatch"
desc = "Run checkpatch.pl script with rule in .checkpatch.conf"
checkpatch_pl = '/usr/bin/checkpatch.pl'
ignore = None
checkpatch_cmd = []
def config(self):
"""
Config the test cases.
"""
logger.debug("Parser configuration")
self.enable = config_enable(config, self.name)
self.submit_pw = config_submit_pw(config, self.name)
if self.name in config:
if 'bin_path' in config[self.name]:
self.checkpatch_pl = config[self.name]['bin_path']
if 'ignore' in config[self.name]:
self.ignore = config[self.name]['ignore']
logger.debug("checkpatch ignore: %s" % self.ignore)
logger.debug("checkpatch_pl = %s" % self.checkpatch_pl)
self.checkpatch_cmd.append(self.checkpatch_pl)
self.checkpatch_cmd.append('--show-types')
if self.ignore != None:
self.checkpatch_cmd.append('--ignore')
self.checkpatch_cmd.append(self.ignore)
def run(self):
logger.debug("##### Run CheckPatch Test #####")
self.start_timer()
self.config()
# Check if it is disabled.
if self.enable == False:
self.submit_result(pw_series_patch_1, Verdict.SKIP,
"CheckPatch SKIP(Disabled)")
self.skip("Disabled in configuration")
for patch_item in pw_series['patches']:
logger.debug("patch id: %s" % patch_item['id'])
patch = patchwork_get_patch(str(patch_item['id']))
# Run checkpatch
(output, error) = self.run_checkpatch(patch)
# Failed / Warning
if error != None:
msg = "{}\{}".format(patch['name'], error)
if error.find("WARNING: ") != -1:
if error.find("ERROR: ") != -1:
self.submit_result(patch, Verdict.FAIL, msg)
else:
self.submit_result(patch, Verdict.WARNING, msg)
else:
self.submit_result(patch, Verdict.FAIL, msg)
self.add_failure(msg)
continue
# Warning in output
if output.find("WARNING:") != -1:
self.submit_result(patch, Verdict.WARNING, output)
continue
# Success
self.submit_result(patch, Verdict.PASS, "Checkpatch PASS")
# Overall status
if self.verdict != Verdict.FAIL:
self.success()
def run_checkpatch(self, patch):
"""
Run checkpatch script with patch from the patchwork.
It saves to file first and run checkpatch with the saved patch file.
On success, it returns None.
On failure, it returns the stderr output string
"""
output = None
error = None
# Save the patch content to file
filename = os.path.join(src_dir, str(patch['id']) + ".patch")
logger.debug("Save patch: %s" % filename)
patch_file = patchwork_save_patch(patch, filename)
copied_cmd = self.checkpatch_cmd.copy()
copied_cmd.append(patch_file)
logger.debug("CMD: %s" % copied_cmd)
try:
output = subprocess.check_output(copied_cmd,
stderr=subprocess.STDOUT,
cwd=src_dir)
output = output.decode("utf-8")
except subprocess.CalledProcessError as ex:
error = ex.output.decode("utf-8")
logger.error("checkpatch.pl returned with error")
logger.error("output: %s" % error)
return (output, error)
class GitLint(CiBase):
name = "gitlint"
display_name = "GitLint"
desc = "Run gitlint with rule in .gitlint"
gitlint_config = '/.gitlint'
def config(self):
"""
Config the test cases.
"""
logger.debug("Parser configuration")
self.enable = config_enable(config, self.name)
self.submit_pw = config_submit_pw(config, self.name)
if self.name in config:
if 'config_path' in config[self.name]:
self.gitlint_config = config[self.name]['config_path']
logger.debug("gitlint_config = %s" % self.gitlint_config)
def run(self):
logger.debug("##### Run Gitlint Test #####")
self.start_timer()
self.config()
# Check if it is disabled.
if self.enable == False:
self.submit_result(pw_series_patch_1, Verdict.SKIP,
"Gitlint SKIP(Disabled)")
self.skip("Disabled in configuration")
# Use patches from patchwork
for patch_item in pw_series['patches']:
logger.debug("patch_id: %s" % patch_item['id'])
patch = patchwork_get_patch(str(patch_item['id']))
# Run gitlint
output = self.run_gitlint(patch)
# Failed
if output != None:
msg = "{}\n{}".format(patch['name'], output)
self.submit_result(patch, Verdict.FAIL, msg)
self.add_failure(msg)
continue
# Success
self.submit_result(patch, Verdict.PASS, "Gitlint PASS")
# Overall status
if self.verdict != Verdict.FAIL:
self.success()
def run_gitlint(self, patch):
"""
Run checkpatch script with patch from the patchwork.
It saves the commit message to the file first and run gitlint with it.
On success, it returns None.
On failure, it returns the stderr output string
"""
output = None
# Save the patch commit message to file
filename = os.path.join(src_dir, str(patch['id']) + ".commit_msg")
logger.debug("Save commit msg: %s" % filename)
commit_msg_file = patchwork_save_patch_msg(patch, filename)
try:
subprocess.check_output(('gitlint', '-C', self.gitlint_config,
"--msg-filename", commit_msg_file),
stderr=subprocess.STDOUT,
cwd=src_dir)
except subprocess.CalledProcessError as ex:
output = ex.output.decode("utf-8")
logger.error("gitlint returned error/warning")
logger.error("output: %s" % output)
return output
class SubjectPrefix(CiBase):
name = "subjectprefix"
display_name = "SubjectPrefix"
desc = "Check subject contains \"Bluetooth\" prefix"
def config(self):
"""
Config the test cases.
"""
logger.debug("Parser configuration")
self.enable = config_enable(config, self.name)
self.submit_pw = config_submit_pw(config, self.name)
def run(self):
logger.debug("##### Run SubjectPrefix Test #####")
self.start_timer()
self.config()
# Check if it is disabled.
if self.enable == False:
self.submit_result(pw_series_patch_1, Verdict.SKIP,
"SubjectPrefix SKIP(Disabled)")
self.skip("Disabled in configuration")
for patch_item in pw_series['patches']:
logger.debug("patch id: %s" % patch_item['id'])
patch = patchwork_get_patch(str(patch_item['id']))
# Check if the name contains "Bluetooth: "
s = patch['name'].find('Bluetooth: ')
if s < 0:
# No Bluetooth prefix found. Instead of failing it,
# set the result to WARNING just enough to get an
# attention
msg = "\"Bluetooth: \" is not specified in the subject"
self.submit_result(patch, Verdict.FAIL, msg)
self.add_failure(msg)
continue
self.submit_result(patch, Verdict.PASS, "PASS")
# Overall status
if self.verdict != Verdict.FAIL:
self.success()
class BuildKernel(CiBase):
name = "buildkernel"
display_name = "BuildKernel"
desc = "Build Kernel with minimal configuration supports Bluetooth"
build_config = "/bluetooth_build.config"
simple_build = False
def config(self):
"""
Configure the test cases.
"""
logger.debug("Parser configuration")
self.enable = config_enable(config, self.name)
self.submit_pw = config_submit_pw(config, self.name)
if self.name in config:
if 'config_path' in config[self.name]:
self.build_config = config[self.name]['config_path']
if 'simple_build' in config[self.name]:
if config[self.name]['simple_build'] == 'yes':
logger.info("config.simple_build" + " is enabled")
self.simple_build = True
logger.debug("build_config = %s" % self.build_config)
def run(self):
logger.debug("##### Run BuildKernel Test #####")
self.start_timer()
self.config()
# Check if it is disabled.
if self.enable == False:
self.submit_result(pw_series_patch_1, Verdict.SKIP,
"Build Kernel SKIP(Disabled)")
self.skip("Disabled in configuration")
# Copy bluetooth build config
logger.info("Copy config file: %s" % self.build_config)
(ret, stdout, stderr) = run_cmd("cp", self.build_config, ".config",
cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel Copy Config FAIL: " + stderr)
self.add_failure_end_test(stderr)
# Update .config
logger.info("Run make olddepconfig")
(ret, stdout, stderr) = run_cmd("make", "olddefconfig", cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel Make olddefconfig FAIL: " + stderr)
self.add_failure_end_test(stderr)
# make
if self.simple_build:
(ret, stdout, stderr) = run_cmd("make", "-j4", "W=1", "net/bluetooth/",
cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel make FAIL: " + stderr)
self.add_failure_end_test(stderr)
(ret, stdout, stderr) = run_cmd("make", "-j4", "W=1", "drivers/bluetooth/",
cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel make FAIL: " + stderr)
self.add_failure_end_test(stderr)
else:
# full build
(ret, stdout, stderr) = run_cmd("make", "-j4", cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel make FAIL: " + stderr)
self.add_failure_end_test(stderr)
# At this point, consider test passed here
self.submit_result(pw_series_patch_1, Verdict.PASS, "Build Kernel PASS")
self.success()
class BuildKernel32(CiBase):
name = "buildkernel32"
display_name = "BuildKernel32"
desc = "Build 32bit Kernel with minimal configuration supports Bluetooth"
build_config = "/bluetooth_build.config"
simple_build = False
def config(self):
"""
Configure the test cases.
"""
logger.debug("Parser configuration")
self.enable = config_enable(config, self.name)
self.submit_pw = config_submit_pw(config, self.name)
if self.name in config:
if 'config_path' in config[self.name]:
self.build_config = config[self.name]['config_path']
if 'simple_build' in config[self.name]:
if config[self.name]['simple_build'] == 'yes':
logger.info("config.simple_build" + " is enabled")
self.simple_build = True
logger.debug("build_config = %s" % self.build_config)
def run(self):
logger.debug("##### Run BuildKernel32 Test #####")
self.start_timer()
self.config()
# Check if it is disabled.
if self.enable == False:
self.submit_result(pw_series_patch_1, Verdict.SKIP,
"Build Kernel32 SKIP(Disabled)")
self.skip("Disabled in configuration")
# Copy bluetooth build config
logger.info("Copy config file: %s" % self.build_config)
(ret, stdout, stderr) = run_cmd("cp", self.build_config, ".config",
cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel32 Copy Config FAIL: " + stderr)
self.add_failure_end_test(stderr)
# Update .config
logger.info("Run make ARCH=i386 olddepconfig")
(ret, stdout, stderr) = run_cmd("make", "ARCH=i386", "olddefconfig", cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel32 Make olddefconfig FAIL: " + stderr)
self.add_failure_end_test(stderr)
# make
if self.simple_build:
(ret, stdout, stderr) = run_cmd("make", "ARCH=i386", "-j4", "W=1", "net/bluetooth/",
cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel32 make FAIL: " + stderr)
self.add_failure_end_test(stderr)
(ret, stdout, stderr) = run_cmd("make", "ARCH=i386", "-j4", "W=1", "drivers/bluetooth/",
cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel32 make FAIL: " + stderr)
self.add_failure_end_test(stderr)
else:
# full build
(ret, stdout, stderr) = run_cmd("make", "ARCH=i386", "-j4", cwd=src_dir)
if ret:
self.submit_result(pw_series_patch_1, Verdict.FAIL,
"Build Kernel32 make FAIL: " + stderr)
self.add_failure_end_test(stderr)
# At this point, consider test passed here
self.submit_result(pw_series_patch_1, Verdict.PASS, "Build Kernel32 PASS")
self.success()
class IncrementalBuild(CiBase):
name = "incremental_build"
display_name = "Incremental Build with patches"
desc = "Incremental build per patch in the series"
simple_build = False
def config(self):
"""
Configure the test cases.
"""
logger.debug("Parser configuration")
self.enable = config_enable(config, self.name)
self.submit_pw = config_submit_pw(config, self.name)
if self.name in config:
if 'config_path' in config[self.name]:
self.build_config = config[self.name]['config_path']
if 'simple_build' in config[self.name]:
if config[self.name]['simple_build'] == 'yes':
logger.info("config.simple_build" + " is enabled")
self.simple_build = True
logger.debug("build_config = %s" % self.build_config)
def run(self):
logger.debug("##### Run IncrementalBuild Test #####")
self.start_timer()
self.config()
# Check if it is disabled.
if self.enable == False:
self.submit_result(pw_series_patch_1, Verdict.SKIP,
"Incremental Build Kernel SKIP(Disabled)")
self.skip("Disabled in configuration")
# Run only if "BuildKernel" success
if test_suite["buildkernel"].verdict != Verdict.PASS:
logger.info("buildkernel test is not success. skip this test")
self.submit_result(pw_series_patch_1, Verdict.SKIP,
"Incremental Build Kernel SKIP(Build Fail)")
self.skip("buildkernel failed")
# If there is only one patch, no need to run and just return success
if github_pr.commits == 1:
logger.debug("Only 1 patch and no need to run here again")
self.success()
return
# Set the source to the base workflow branch
(ret, stdout, stderr) = run_cmd("git", "fetch", "--depth=2", "origin",
"workflow", cwd=src2_dir)
if ret:
msg = "Error: \n"
if stderr != None:
msg += "{}".format(stderr)
self.add_failure_end_test(msg)
(ret, stdout, stderr) = run_cmd("git", "checkout", "origin/workflow",
cwd=src2_dir)
if ret:
msg = "Error: \n"
if stderr != None:
msg += "{}".format(stderr)
self.add_failure_end_test(msg)
# Get the patch from the series, apply it and build.
for patch_item in pw_series['patches']:
logger.debug("patch id: %s" % patch_item['id'])
patch = patchwork_get_patch(str(patch_item['id']))
# Apply patch
(output, error) = self.apply_patch(patch, src2_dir)
if error != None:
msg = "{}\n{}".format(patch['name'], error)
self.submit_result(patch, Verdict.FAIL,
"Applying patch FAIL: " + error)
self.add_failure_end_test(msg)
logger.debug("Patch Applied")
# Copy bluetooth build config
logger.info("Copy config file: %s" % self.build_config)
(ret, stdout, stderr) = run_cmd("cp", self.build_config, ".config",