-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbbci.py
executable file
·1819 lines (1708 loc) · 76.7 KB
/
bbci.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
"""
BBCI, build and boot CI
"""
import argparse
from distutils.version import LooseVersion
import fcntl
import hashlib
import os
import platform
import pprint
import re
import subprocess
import shutil
import sys
import time
import xmlrpc.client
import yaml
import jinja2
###############################################################################
###############################################################################
# create a directory
def lab_create_directory(lab, directory):
destdir = lab["datadir"]
# check remote vs local (TODO)
for part in directory.split("/"):
destdir = destdir + '/' + part
if args.debug:
print("DEBUG: Check %s" % destdir)
if not os.path.isdir(destdir):
if args.debug:
print("DEBUG: create %s" % destdir)
os.mkdir(destdir)
###############################################################################
###############################################################################
def lab_copy(lab, src, directory):
destdir = lab["datadir"]
# check remote vs local (TODO)
for part in directory.split("/"):
destdir = destdir + '/' + part
if args.debug:
print("DEBUG: Check %s" % destdir)
if not os.path.isdir(destdir):
if args.debug:
print("DEBUG: create %s" % destdir)
os.mkdir(destdir)
if args.debug:
print("DEBUG: copy %s to %s" % (src, destdir))
shutil.copy(src, destdir)
###############################################################################
###############################################################################
def linuxmenu(param):
larch = param["larch"]
kdir = param["kdir"]
make_opts = param["make_opts"]
pbuild = subprocess.Popen("make %s menuconfig" % make_opts, shell=True)
outs, err = pbuild.communicate()
return err
###############################################################################
###############################################################################
def linux_clean(param):
larch = param["larch"]
kdir = param["kdir"]
make_opts = param["make_opts"]
pbuild = subprocess.Popen("make %s clean" % make_opts, shell=True)
outs, err = pbuild.communicate()
return err
###############################################################################
###############################################################################
def do_dtb_check(param):
larch = param["larch"]
kdir = param["kdir"]
make_opts = param["make_opts"]
logdir = os.path.expandvars(tc["config"]["logdir"])
if args.nolog:
logfile = sys.stdout
else:
logfile = open("%s/%s.dtb.log" % (logdir, param["targetname"]), 'w')
if args.quiet:
pbuild = subprocess.Popen("make %s dtbs_check" % make_opts, shell=True, stdout=subprocess.DEVNULL)
else:
pbuild = subprocess.Popen("make %s dtbs_check" % make_opts, shell=True, stdout=logfile, stderr=subprocess.STDOUT)
outs, err = pbuild.communicate()
print(outs)
return err
###############################################################################
###############################################################################
def build(param):
larch = param["larch"]
kdir = param["kdir"]
make_opts = param["make_opts"] + " %s" % param["full_tgt"]
print("BUILD: %s to %s" % (larch, kdir))
if args.debug:
print("DEBUG: makeopts=%s" % make_opts)
if args.noact:
print("Will run make %s" % make_opts)
return 0
logdir = os.path.expandvars(tc["config"]["logdir"])
if not os.path.exists(logdir):
os.mkdir(logdir)
if not args.noclean:
err = linux_clean(param)
if err != 0:
print("WARNING: make clean fail")
if args.nolog:
logfile = sys.stdout
else:
logfile = open("%s/%s.log" % (logdir, param["targetname"]), 'w')
if args.quiet:
pbuild = subprocess.Popen("make %s" % make_opts, shell=True, stdout=subprocess.DEVNULL)
else:
pbuild = subprocess.Popen("make %s" % make_opts, shell=True, stdout=logfile, stderr=subprocess.STDOUT)
outs, err = pbuild.communicate()
print(outs)
builds[param["targetname"]] = {}
if err is None and pbuild.returncode == 0:
if args.debug:
print("DEBUG: build success")
else:
builds[param["targetname"]]["result"] = 'FAIL'
if not args.nolog:
logfile.close()
return err
if "modules_dir" in param:
modules_dir = param["modules_dir"]
if os.path.isdir(modules_dir):
if args.debug:
print("DEBUG: clean old %s" % modules_dir)
if not args.noact:
shutil.rmtree(modules_dir)
os.mkdir(modules_dir)
if args.debug:
print("DEBUG: do modules_install")
if args.quiet:
pbuild = subprocess.Popen("make %s modules_install" % make_opts, shell=True, stdout=subprocess.DEVNULL)
else:
pbuild = subprocess.Popen("make %s modules_install 2>&1" % make_opts, shell=True, stdout=logfile)
outs, err = pbuild.communicate()
if not args.nolog:
logfile.close()
if err is None and pbuild.returncode == 0:
builds[param["targetname"]]["result"] = 'PASS'
else:
builds[param["targetname"]]["result"] = 'FAIL'
return err
###############################################################################
###############################################################################
def boot(param):
larch = param["larch"]
subarch = param["subarch"]
flavour = param["flavour"]
kdir = param["kdir"]
sourcename = param["sourcename"]
global qemu_boot_id
logdir = os.path.expandvars(tc["config"]["logdir"])
cachedir = os.path.expandvars(tc["config"]["cache"])
if not os.path.exists(logdir):
os.mkdir(logdir)
arch_endian = None
if os.path.exists("%s/.config" % kdir):
kconfig = open("%s/.config" % kdir)
kconfigs = kconfig.read()
kconfig.close()
if re.search("CONFIG_CPU_BIG_ENDIAN=y", kconfigs):
endian = "big"
else:
endian = "little"
if re.search("CONFIG_PARISC=", kconfigs):
arch = "parisc"
arch_endian = "hppa"
qarch = "hppa"
if re.search("CONFIG_M68K=", kconfigs):
arch = "m68k"
arch_endian = "m68k"
qarch = "m68k"
if re.search("CONFIG_NIOS2=", kconfigs):
arch = "nios2"
arch_endian = "nios2"
qarch = "nios2"
if re.search("CONFIG_XTENSA=", kconfigs):
arch = "xtensa"
arch_endian = "xtensa"
qarch = "xtensa"
if re.search("CONFIG_SPARC32=", kconfigs):
arch = "sparc"
arch_endian = "sparc"
qarch = "sparc"
if re.search("CONFIG_SPARC64=", kconfigs):
arch = "sparc64"
arch_endian = "sparc64"
qarch = "sparc64"
if re.search("CONFIG_ARM=", kconfigs):
arch = "arm"
qarch = "arm"
if re.search("CONFIG_CPU_BIG_ENDIAN=y", kconfigs):
arch_endian = "armbe"
qarch = "unsupported"
else:
arch_endian = "armel"
if re.search("CONFIG_ARM64=", kconfigs):
arch = "arm64"
qarch = "aarch64"
if re.search("CONFIG_CPU_BIG_ENDIAN=y", kconfigs):
arch_endian = "arm64be"
else:
arch_endian = "arm64"
if re.search("CONFIG_ARC=", kconfigs):
arch = "arc"
arch_endian = "arc"
qarch = None
if re.search("CONFIG_MIPS=", kconfigs):
if re.search("CONFIG_64BIT=y", kconfigs):
arch = "mips64"
qarch = "mips64"
if endian == 'big':
arch_endian = "mips64be"
else:
arch_endian = 'mips64el'
else:
arch = "mips"
qarch = "mips"
if endian == 'big':
arch_endian = "mipsbe"
else:
arch_endian = 'mipsel'
qarch = "mipsel"
if re.search("CONFIG_ALPHA=", kconfigs):
arch = "alpha"
arch_endian = "alpha"
qarch = "alpha"
if re.search("CONFIG_PPC=", kconfigs):
arch = "powerpc"
arch_endian = "powerpc"
qarch = "ppc"
if re.search("CONFIG_PPC64=", kconfigs):
arch = "powerpc64"
arch_endian = "ppc64"
qarch = "ppc64"
if re.search("CONFIG_OPENRISC=", kconfigs):
arch = "openrisc"
arch_endian = "openrisc"
qarch = "or1k"
if re.search("CONFIG_MICROBLAZE=", kconfigs):
arch = "microblaze"
if re.search("CONFIG_CPU_BIG_ENDIAN=y", kconfigs):
arch_endian = "microblaze"
qarch = "microblaze"
else:
arch_endian = "microblazeel"
qarch = "microblazeel"
if re.search("CONFIG_X86_64=", kconfigs):
arch = "x86_64"
arch_endian = "x86_64"
qarch = "x86_64"
if re.search("CONFIG_X86=", kconfigs) and not re.search("CONFIG_X86_64=", kconfigs):
arch = "x86"
arch_endian = "x86"
qarch = "i386"
else:
kconfigs = ""
# detect from the given larch
if larch == "x86_64":
arch = "x86_64"
arch_endian = "x86_64"
qarch = "x86_64"
endian = "little"
if larch == "arm":
arch = "arm"
arch_endian = "armel"
qarch = "arm"
endian = "little"
if larch == "arm64":
arch = "arm64"
arch_endian = "arm64"
qarch = "aarch64"
endian = "little"
if arch_endian is None:
print("ERROR: Missing endian arch")
return 1
print("INFO: arch is %s, Linux arch is %s, QEMU arch is %s, archendian is %s" % (arch, larch, qarch, arch_endian))
# TODO check RAMFS and INITRD and MODULES and DEVTMPFS_MOUNT
#TODO check error
if os.path.isdir(".git"):
git_describe = subprocess.check_output('git describe --always', shell=True).strip().decode("utf-8")
git_lastcommit = subprocess.check_output('git rev-parse HEAD', shell=True).strip().decode("utf-8")
git_branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD', shell=True).strip().decode("utf-8")
elif os.path.exists("Makefile"):
VERSION = subprocess.check_output('grep ^VERSION Makefile | sed "s,.* ,,"', shell=True).strip().decode("utf-8")
PATCHLEVEL = subprocess.check_output('grep ^PATCHLEVEL Makefile | sed "s,.* ,,"', shell=True).strip().decode("utf-8")
SUBLEVEL = subprocess.check_output('grep ^SUBLEVEL Makefile | sed "s,.* ,,"', shell=True).strip().decode("utf-8")
EXTRAVERSION = subprocess.check_output('grep ^EXTRAVERSION Makefile | sed "s,.* ,,"', shell=True).strip().decode("utf-8")
git_describe = "%s.%s.%s%s" % (VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION)
git_lastcommit = "None"
git_branch = "None"
else:
git_describe = "None"
git_lastcommit = "None"
git_branch = "None"
# generate modules.tar.gz
#TODO check error
if "modules_dir" in param:
modules_dir = param["modules_dir"]
else:
modules_dir = "%s/fake" % builddir
if os.path.exists(modules_dir):
shutil.rmtree(modules_dir)
os.mkdir(modules_dir)
os.mkdir("%s/lib/" % modules_dir)
os.mkdir("%s/lib/modules" % modules_dir)
if args.quiet:
pbuild = subprocess.Popen("cd %s && tar czf modules.tar.gz lib" % modules_dir, shell=True, stdout=subprocess.DEVNULL)
outs, err = pbuild.communicate()
else:
pbuild = subprocess.Popen("cd %s && tar czf modules.tar.gz lib" % modules_dir, shell=True)
outs, err = pbuild.communicate()
if err is not None and err != 0:
print("ERROR: fail to generate modules.tar.gz in %s (err=%d)" % (modules_dir, err))
print(outs)
return 1
for device in t["templates"]:
if "devicename" in device:
devicename = device["devicename"]
else:
devicename = device["devicetype"]
if "larch" in device:
device_larch = device["larch"]
else:
device_larch = device["arch"]
if device_larch != larch:
if args.debug:
print("SKIP: %s (wrong larch %s vs %s)" % (devicename, device_larch, larch))
continue
if device["arch"] != arch:
if args.debug:
print("SKIP: %s arch: %s vs %s" % (devicename, device["arch"], arch))
continue
print("==============================================")
print("CHECK: %s" % devicename)
# check config requirements
skip = False
if "configs" in device and device["configs"] is not None and kconfigs != "":
for config in device["configs"]:
if "name" not in config:
print("Invalid config")
print(config)
continue
if not re.search(config["name"], kconfigs):
if "type" in config and config["type"] == "mandatory":
print("\tSKIP: missing %s" % config["name"])
skip = True
else:
print("\tINFO: missing %s" % config["name"])
else:
print("DEBUG: found %s" % config["name"])
if skip:
continue
goodtag = True
if args.dtag:
for tag in args.dtag.split(","):
if "devicename" in device and tag == device["devicename"]:
tagfound = True
continue
if tag == device["devicetype"]:
tagfound = True
continue
if args.debug:
print("DEBUG: check tag %s" % tag)
if "tags" not in device:
print("SKIP: no tag")
gootdtag = False
continue
tagfound = False
for dtag in device["tags"]:
if tag == "qemu":
if "qemu" in device:
tagfound = True
if tag == "noqemu":
if "qemu" not in device:
tagfound = True
if args.debug:
print("DEBUG: found device tag %s" % dtag)
if dtag == tag:
tagfound = True
if not tagfound:
print("SKIP: cannot found tag %s" % tag)
goodtag = False
if not goodtag:
continue
kerneltype = "image"
kernelfile = device["kernelfile"]
if kernelfile == "zImage":
kerneltype = "zimage"
if kernelfile == "uImage":
kerneltype = "uimage"
# check needed files
if "kernelfile" not in device:
print("ERROR: missing kernelfile")
continue
if args.debug:
print("DEBUG: seek %s" % device["kernelfile"])
kfile = "%s/arch/%s/boot/%s" % (kdir, larch, device["kernelfile"])
if os.path.isfile(kfile):
if args.debug:
print("DEBUG: found %s" % kfile)
else:
if args.debug:
print("DEBUG: %s not found" % kfile)
kfile = "%s/%s" % (kdir, device["kernelfile"])
if os.path.isfile(kfile):
if args.debug:
print("DEBUG: found %s" % kfile)
else:
print("SKIP: no kernelfile")
continue
# Fill lab indepedant data
jobdict = {}
jobdict["KERNELFILE"] = kernelfile
with open(kfile, "rb") as fkernel:
jobdict["KERNEL_SHA256"] = hashlib.sha256(fkernel.read()).hexdigest()
jobdict["DEVICETYPE"] = device["devicetype"]
jobdict["MACH"] = device["mach"]
jobdict["ARCH"] = device["arch"]
jobdict["PATH"] = "%s/%s/%s/%s/%s" % (sourcename, larch, subarch, flavour, git_describe)
jobdict["ARCHENDIAN"] = arch_endian
jobdict["GIT_DESCRIBE"] = git_describe
jobdict["KVERSION"] = git_describe
jobdict["K_DEFCONFIG"] = param["configbase"]
jobdict["KENDIAN"] = endian
jobdict["KERNELTYPE"] = kerneltype
jobdict["GIT_LASTCOMMIT"] = git_lastcommit
jobdict["GIT_BRANCH"] = git_branch
jobdict["LAVA_BOOT_TYPE"] = kerneltype
jobdict["test"] = "True"
jobdict["TESTSUITES"] = "all"
if args.callback is not None:
jobdict["callback"] = args.callback
if args.callback_token is not None:
jobdict["callback_token"] = args.callback_token
jobdict["rootfs_method"] = "ramdisk"
jobdict["BUILD_OVERLAYS"] = args.configoverlay
jobdict["BUILD_PROFILE"] = "%s-%s-%s" % (larch, subarch, flavour)
jobdict["BUILD_TOOLCHAIN"] = param["toolchaininuse"].replace(" ", "_")
if "boot-method" in device:
jobdict["boot_method"] = device["boot-method"]
if args.rootfs == "nfs":
jobdict["rootfs_method"] = "nfs"
jobdict["boot_commands"] = "nfs"
jobdict["boot_media"] = "nfs"
if "qemu" in device:
jobdict["boot_method"] = "qemu-nfs"
elif args.rootfs == "vdisk":
if "qemu" not in device:
print("ERROR: vdisk is only for qemu")
continue
jobdict["rootfs_method"] = "vdisk"
elif args.rootfs == "nbd":
jobdict["rootfs_method"] = "nbd"
if "qemu" in device:
print("ERROR: NBD for qemu is unsupported")
continue
jobdict["boot_commands"] = "nbd"
jobdict["boot_to"] = "nbd"
spetial = param["toolchaininuse"]
if args.configoverlay:
spetial += "+%s" % args.configoverlay
if args.jobtitle:
jobdict["JOBNAME"] = args.jobtitle
else:
jobdict["JOBNAME"] = "AUTOTEST %s %s/%s/%s/%s on %s (%s,root=%s)" % (git_describe, sourcename, larch, subarch, flavour, devicename, spetial, jobdict["rootfs_method"])
if len(jobdict["JOBNAME"]) > 200:
jobdict["JOBNAME"] = "AUTOTEST %s %s/%s/%s/%s on %s (root=%s)" % (git_describe, sourcename, larch, subarch, flavour, devicename, jobdict["rootfs_method"])
nonetwork = False
netbroken = False
for dtag in device["tags"]:
if dtag == "nonetwork":
nonetwork = True
if dtag == "netbroken":
netbroken = True
if dtag == "noinitrd" or dtag == 'rootonsd':
jobdict["image_arg"] = '-drive format=raw,if=sd,file={ramdisk}'
jobdict["initrd_path"] = "/rootfs/%s/rootfs.ext2" % arch_endian
if dtag == "notests" or dtag == "nostorage" or args.testsuite is None:
jobdict["test"] = "False"
if args.debug:
print("DEBUG: Remove test from job")
# test are still enabled check testsuite
if jobdict["test"] and args.testsuite is not None:
jobdict["TESTSUITES"] = args.testsuite
if args.testsuite == "all":
jobdict["test_boot"] = 'True'
jobdict["test_network"] = 'True'
jobdict["test_hw"] = 'True'
jobdict["test_crypto"] = 'True'
jobdict["test_misc"] = 'True'
else:
for testsuite in args.testsuite.split(','):
print("DEBUG: enable test %s" % testsuite)
jobdict["test_%s" % testsuite] = 'True'
else:
jobdict["TESTSUITES"] = "none"
if "qemu" in device:
if qarch == "unsupported":
print("Qemu does not support this")
continue
print("\tQEMU")
jobdict["qemu_arch"] = qarch
if "netdevice" in device["qemu"]:
jobdict["qemu_netdevice"] = device["qemu"]["netdevice"]
if "model" in device["qemu"]:
jobdict["qemu_model"] = device["qemu"]["model"]
if "no_kvm" in device["qemu"]:
jobdict["qemu_no_kvm"] = device["qemu"]["no_kvm"]
if "machine" in device["qemu"]:
jobdict["qemu_machine"] = device["qemu"]["machine"]
if "cpu" in device["qemu"]:
jobdict["qemu_cpu"] = device["qemu"]["cpu"]
if "memory" in device["qemu"]:
jobdict["qemu_memory"] = device["qemu"]["memory"]
if "console_device" in device["qemu"]:
jobdict["console_device"] = device["qemu"]["console_device"]
if "guestfs_interface" in device["qemu"]:
jobdict["guestfs_interface"] = device["qemu"]["guestfs_interface"]
if "guestfs_driveid" in device["qemu"]:
jobdict["guestfs_driveid"] = device["qemu"]["guestfs_driveid"]
if "extra_options" in device["qemu"]:
jobdict["qemu_extra_options"] = device["qemu"]["extra_options"]
# with root on nfs/nbd, tests are not set on a storage, so we need to filter them
if args.rootfs == "nfs" or args.rootfs == "nbd":
newextrao = []
for extrao in device["qemu"]["extra_options"]:
if re.search("lavatest", extrao):
continue
newextrao.append(extrao)
jobdict["qemu_extra_options"] = newextrao
if "extra_options" not in device["qemu"]:
jobdict["qemu_extra_options"] = []
if "smp" in device["qemu"]:
jobdict["qemu_extra_options"].append("-smp cpus=%d" % device["qemu"]["smp"])
netoptions = "ip=dhcp"
if nonetwork or netbroken:
netoptions = ""
jobdict["qemu_extra_options"].append("-append '%s %s'" % (device["qemu"]["append"], netoptions))
templateLoader = jinja2.FileSystemLoader(searchpath=templatedir)
templateEnv = jinja2.Environment(loader=templateLoader)
if args.jobtemplate:
template = templateEnv.get_template(args.jobtemplate)
elif "qemu" in device:
template = templateEnv.get_template("defaultqemu.jinja2")
else:
template = templateEnv.get_template("default.jinja2")
if "doqemu" in param:
if "qemu" not in device:
return 0
failure = None
# The exec here permits a working qp.terminate()
qemu_cmd = "exec qemu-system-%s -kernel %s -nographic -machine %s" % (qarch, kfile, device["qemu"]["machine"])
if "qemu_bios_path" in tc["config"]:
qemu_cmd += " -L %s" % os.path.expandvars(tc["config"]["qemu_bios_path"])
if "qemu_bin_path" in tc["config"]:
os.environ["PATH"] = "%s:%s" % (os.path.expandvars(tc["config"]["qemu_bin_path"]), os.environ["PATH"])
if "audio" in device["qemu"]:
os.environ["QEMU_AUDIO_DRV"] = device["qemu"]["audio"]
if "extra_options" in device["qemu"]:
for extrao in device["qemu"]["extra_options"]:
qemu_cmd += " %s" % extrao
qemu_cmd += " -append '%s ip=dhcp'" % device["qemu"]["append"]
if re.search("CONFIG_SERIAL_PMACZILOG=", kconfigs) and re.search("CONFIG_SERIAL_PMACZILOG_TTYS=y", kconfigs):
print("INFO: PMACZILOG console hack")
qemu_cmd = qemu_cmd.replace("console=ttyPZ0", "console=ttyS0")
#qemu_cmd += " -drive format=qcow2,file=$HOME/bbci/flash.bin"
if "dtb" in device:
dtbfile = "%s/arch/%s/boot/dts/%s" % (kdir, larch, device["dtb"])
if not os.path.isfile(dtbfile):
#try at base directory
dtbfile = "%s/%s" % (kdir, device["dtb"])
if not os.path.isfile(dtbfile):
# retry with basename
dtbfile = "%s/%s" % (kdir, os.path.basename(device["dtb"]))
if not os.path.isfile(dtbfile):
print("SKIP: no dtb at %s" % dtbfile)
continue
with open(dtbfile, "rb") as fdtb:
jobdict["DTB_SHA256"] = hashlib.sha256(fdtb.read()).hexdigest()
qemu_cmd += " -dtb %s" % dtbfile
if "memory" in device["qemu"]:
qemu_cmd += " -m %s" % device["qemu"]["memory"]
if "cpu" in device["qemu"]:
qemu_cmd += " -cpu %s" % device["qemu"]["cpu"]
if "model" in device["qemu"]:
qemu_cmd += " -nic user,%s,mac=52:54:00:12:34:58" % device["qemu"]["model"]
if not os.path.isfile("%s/disk.img" % cachedir):
subprocess.run("qemu-img create -f qcow2 %s/disk.img 10M" % cachedir, shell=True)
guestfs_interface = 'ide'
if "guestfs_interface" in device["qemu"]:
guestfs_interface = device["qemu"]["guestfs_interface"]
qemu_cmd += " -drive format=qcow2,file=%s/disk.img,if=%s,id=lavatest" % (cachedir, guestfs_interface)
# Add initrd
for lab in tlabs["labs"]:
if "disabled" in lab and lab["disabled"]:
continue
datadir = lab["datadir"]
break
qemu_cmd += " -initrd %s/rootfs/%s/rootfs.cpio.gz" % (datadir, arch_endian)
print(qemu_cmd)
qp = subprocess.Popen(qemu_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
flags = fcntl.fcntl(qp.stdout, fcntl.F_GETFL)
flags = flags | os.O_NONBLOCK
fcntl.fcntl(qp.stdout, fcntl.F_SETFL, flags)
flags = fcntl.fcntl(qp.stderr, fcntl.F_GETFL)
flags = flags | os.O_NONBLOCK
fcntl.fcntl(qp.stderr, fcntl.F_SETFL, flags)
qlogfile = open("%s/%s-%s-%s.log" % (logdir, device["name"].replace('/', '_'), sourcename, param["targetname"]), 'w')
poweroff_done = False
qtimeout = 0
normal_halt = False
ret = 0
last_error_line = ""
while True:
try:
line = "x"
got_line = False
while line != "":
line = qp.stdout.readline().decode('UTF8')
if line != "":
print(line, end='')
qlogfile.write(line)
got_line = True
if not got_line:
qtimeout = qtimeout + 1
if re.search("^Kernel panic - not syncing", line):
qtimeout = 490
last_error_line = line
failure = "panic"
if re.search("end Kernel panic - not syncing", line):
qtimeout = 490
failure = "panic"
if re.search("/ #", line) and not poweroff_done:
qp.stdin.write(b'poweroff\r\n')
qp.stdin.flush()
poweroff_done = True
# System Halted, OK to turn off power
if line == "Machine halt..." or re.search("reboot: System halted", line) or re.search("reboot: power down", line) or re.search("reboot: Power Down", line):
if args.debug:
print("DEBUG: detected machine halt")
normal_halt = True
qtimeout = 490
except ValueError:
time.sleep(0.1)
qtimeout = qtimeout + 1
try:
line = "x"
while line != "":
line = qp.stderr.readline().decode('UTF8').strip()
if line != "":
print(line)
last_error_line = line
except ValueError:
time.sleep(0.1)
time.sleep(0.2)
if qtimeout > 500:
qp.terminate()
if normal_halt:
ret = 0
break
print("ERROR: QEMU TIMEOUT!")
ret = 1
if failure is None:
failure = "timeout"
break
ret = qp.poll()
if ret is not None:
# grab last stderr
try:
line = "x"
while line != "":
line = qp.stderr.readline().decode('UTF8').strip()
if line != "":
print(line)
last_error_line = line
except ValueError:
time.sleep(0.1)
ret = qp.returncode
if ret != 0:
failure = "Code: %d" % ret
break
qlogfile.close()
if "qemu" not in boots:
boots["qemu"] = {}
qemu_boot_id = qemu_boot_id + 1
boots["qemu"][qemu_boot_id] = {}
boots["qemu"][qemu_boot_id]["devicename"] = devicename
boots["qemu"][qemu_boot_id]["arch"] = arch
boots["qemu"][qemu_boot_id]["targetname"] = param["targetname"]
boots["qemu"][qemu_boot_id]["sourcename"] = sourcename
if ret == 0:
boots["qemu"][qemu_boot_id]["result"] = 'PASS'
else:
boots["qemu"][qemu_boot_id]["result"] = 'FAIL'
boots["qemu"][qemu_boot_id]["failure"] = failure
if last_error_line != "":
boots["qemu"][qemu_boot_id]["error"] = last_error_line
continue
return ret
# now try to boot on LAVA
for lab in tlabs["labs"]:
send_to_lab = False
print("\tCheck %s on %s" % (devicename, lab["name"]))
if "disabled" in lab and lab["disabled"]:
continue
# LAB dependant DATA
server = xmlrpc.client.ServerProxy(lab["lavauri"])
devlist = server.scheduler.devices.list()
for labdevice in devlist:
if labdevice["type"] == device["devicetype"]:
send_to_lab = True
alia_list = server.scheduler.aliases.list()
for alias in alia_list:
if alias == device["devicetype"]:
send_to_lab = True
if not send_to_lab:
print("\tSKIP: not found")
continue
#copy files
data_relpath = "%s/%s/%s/%s/%s" % (sourcename, larch, subarch, flavour, git_describe)
lab_create_directory(lab, data_relpath)
datadir = lab["datadir"]
destdir = "%s/%s/%s/%s/%s/%s" % (datadir, sourcename, larch, subarch, flavour, git_describe)
# copy kernel
lab_copy(lab, kfile, data_relpath)
# copy dtb
# TODO dtb metadata
if "dtb" in device:
jobdict["dtb_path"] = "/%s/%s/%s/%s/%s/dts/%s" % (sourcename, larch, subarch, flavour, git_describe, device["dtb"])
jobdict["DTB"] = device["dtb"]
dtbfile = "%s/arch/%s/boot/dts/%s" % (kdir, larch, device["dtb"])
dtbsubdir = device["dtb"].split('/')
dtb_relpath = "/dts/"
if len(dtbsubdir) > 1:
dtb_relpath = dtb_relpath + dtbsubdir[0]
if not os.path.isfile(dtbfile):
#try at base directory
dtbfile = "%s/%s" % (kdir, device["dtb"])
if not os.path.isfile(dtbfile):
# retry with basename
dtbfile = "%s/%s" % (kdir, os.path.basename(device["dtb"]))
if not os.path.isfile(dtbfile):
print("SKIP: no dtb at %s" % dtbfile)
continue
lab_copy(lab, dtbfile, "%s/%s" % (data_relpath, dtb_relpath))
with open(dtbfile, "rb") as fdtb:
jobdict["DTB_SHA256"] = hashlib.sha256(fdtb.read()).hexdigest()
# modules.tar.gz
lab_copy(lab, "%s/modules.tar.gz" % modules_dir, data_relpath)
with open("%s/modules.tar.gz" % modules_dir, "rb") as fmodules:
jobdict["MODULES_SHA256"] = hashlib.sha256(fmodules.read()).hexdigest()
# final job
if not os.path.isdir(outputdir):
os.mkdir(outputdir)
if not os.path.isdir("%s/%s" % (outputdir, lab["name"])):
os.mkdir("%s/%s" % (outputdir, lab["name"]))
result = subprocess.check_output("chmod -Rc o+rX %s" % datadir, shell=True)
if args.debug:
print(result.decode("UTF-8"))
jobdict["BOOT_FQDN"] = lab["datahost_baseuri"]
# ROOTFS cpio.gz are for ramdisk, tar.xz for nfs, ext4.gz for NBD
print(lab)
rootfs_loc = lab["rootfs_loc"]
if args.rootfs_loc:
rootfs_loc = args.rootfs_loc
if rootfs_loc not in trootfs["rootfs"]:
print("ERROR: cannot found %s" % rootfs_loc)
continue
print(trootfs["rootfs"][rootfs_loc])
rfs = trootfs["rootfs"][rootfs_loc]
if args.rootfs not in rfs:
print("ERROR: %s does not support rootfs for %s" % (rootfs_loc, args.rootfs))
continue
rfsm = rfs[args.rootfs]
if args.rootfs_path is None:
if "rootfs_script" in rfsm:
result = subprocess.check_output("%s/%s --arch %s --root %s --cachedir %s" % (bbci_dir, rfsm["rootfs_script"], arch_endian, args.rootfs, cachedir), shell=True)
for line in result.decode("utf-8").split("\n"):
what = line.split("=")
if what[0] == 'ROOTFS_PATH':
jobdict["rootfs_path"] = what[1]
if what[0] == 'ROOTFS_BASE':
jobdict["ROOT_FQDN"] = what[1]
if what[0] == 'ROOTFS_SHA512':
jobdict["rootfs_sha512"] = what[1]
if what[0] == 'PORTAGE_URL':
jobdict["portage_url"] = what[1]
if args.rootfs_loc == 'gentoo' or args.rootfs_loc == 'gentoo-m' or args.rootfs_loc == 'gentoo-selinux':
jobdict["auto_login_password"] = 'bob'
jobdict["test_gentoo"] = "True"
print(line)
else:
jobdict["rootfs_path"] = rfsm["rootfs"]
jobdict["ROOT_FQDN"] = rfs["rootfs_baseuri"]
print("DEBUG: rootfs is %s" % jobdict["rootfs_path"])
else:
jobdict["rootfs_path"] = args.rootfs_path
jobdict["rootfs_path"] = jobdict["rootfs_path"].replace("__ARCH_ENDIAN__", arch_endian).replace("__ARCH__", arch)
if re.search("gz$", jobdict["rootfs_path"]):
jobdict["ROOTFS_COMP"] = "gz"
if re.search("xz$", jobdict["rootfs_path"]):
jobdict["ROOTFS_COMP"] = "xz"
if re.search("bz2$", jobdict["rootfs_path"]):
jobdict["ROOTFS_COMP"] = "bz2"
if args.rootfs_base is not None:
jobdict["ROOT_FQDN"] = args.rootfs_base
# initrd handling
# by default the RAMDISK URI is the same as ROOT
jobdict["RAMD_FQDN"] = jobdict["ROOT_FQDN"]
if "initrd_baseuri" in rfs:
if rfs["initrd_baseuri"] == 'fromdefault':
jobdict["RAMD_FQDN"] = trootfs["rootfs"][lab["rootfs_loc"]]["initrd_baseuri"]
else:
jobdict["RAMD_FQDN"] = rfs["initrd_baseuri"]
if "initrd" in rfsm:
jobdict["initrd_path"] = rfsm["initrd"]
jobdict["initrd_path"] = jobdict["initrd_path"].replace("__ARCH_ENDIAN__", arch_endian).replace("__ARCH__", arch)
# HACK for device omap/sx1 omap/cheetah
for dtag in device["tags"]:
if dtag == "noinitrd" or dtag == 'rootonsd':
jobdict["image_arg"] = '-drive format=raw,if=sd,file={ramdisk}'
jobdict["initrd_path"] = "/rootfs/%s/rootfs.ext2" % arch_endian
jobt = template.render(jobdict)
# HACK CONFIG_SERIAL_PMACZILOG=y CONFIG_SERIAL_PMACZILOG_TTYS=y
if re.search("CONFIG_SERIAL_PMACZILOG=", kconfigs) and re.search("CONFIG_SERIAL_PMACZILOG_TTYS=y", kconfigs):
print("INFO: PMACZILOG console hack")
jobt = jobt.replace("console=ttyPZ0", "console=ttyS0")
fw = open("%s/job-%s.yaml" % (cachedir, devicename), "w")
fw.write(jobt)
fw.close()
if not args.noact:
jobid = server.scheduler.jobs.submit(jobt)
print(jobid)
if lab["name"] not in boots:
boots[lab["name"]] = {}
boots[lab["name"]][jobid] = {}
boots[lab["name"]][jobid]["devicename"] = devicename
# copy config
copyconfig = False
if "copyconfig" in tc["config"]:
copyconfig = tc["config"]["copyconfig"]
if os.path.exists("%s/.config" % kdir) and copyconfig:
if not os.path.exists("%s/configs" % cachedir):
os.mkdir("%s/configs" % cachedir)
if not os.path.exists("%s/configs/%s" % (cachedir, lab["name"])):
os.mkdir("%s/configs/%s" % (cachedir, lab["name"]))
kconfig = open("%s/.config" % kdir)
kconfigs = kconfig.read()
kconfig.close()
ckconfig = open("%s/configs/%s/%s.config" % (cachedir, lab["name"], jobid), 'w')
ckconfig.write(kconfigs)
ckconfig.close()
else:
print("\tSKIP: send job to %s" % lab["name"])
return 0
###############################################################################
###############################################################################
def enable_config(param, econfig):
rawconfig = econfig.split("=")[0]
if args.debug:
print("=================================================== %s" % econfig)
print("DEBUG: Try enable config %s" % econfig)
subprocess.run("cp %s/.config %s/.config.old" % (param["kdir"], param["kdir"]), shell=True)
with open("%s/.config" % param["kdir"], 'r') as fconfig:
wconfig = fconfig.read()
if re.search("=", econfig):
if re.search("%s" % econfig, wconfig):
if args.debug:
print("DEBUG: %s is already enabled" % econfig)
return 0
wconfig = re.sub("# %s is not set" % rawconfig, "%s" % econfig, wconfig)
# handle case CONFIG="" replaced by CONFIG="xxxx"
wconfig = re.sub("%s=.*" % rawconfig, "%s" % econfig, wconfig)
else:
if re.search("%s=" % econfig, wconfig):
if args.debug:
print("DEBUG: %s is already enabled" % econfig)
return 0
wconfig = re.sub("# %s is not set" % rawconfig, "%s=y" % econfig, wconfig)
with open("%s/.config" % param["kdir"], 'w') as fconfig:
fconfig.write(wconfig)
make_opts = param["make_opts"]
if args.debug:
subprocess.run("diff -u %s/.config.old %s/.config" % (param["kdir"], param["kdir"]), shell=True)
pbuild = subprocess.run("make %s olddefconfig > /dev/null" % make_opts, shell=True)
if args.debug:
subprocess.run("diff -u %s/.config.old %s/.config" % (param["kdir"], param["kdir"]), shell=True)
###############################################################################
###############################################################################
def disable_config(param, dconfig):
if args.debug:
print("=================================================== %s" % dconfig)
subprocess.run("cp %s/.config %s/.config.old" % (param["kdir"], param["kdir"]), shell=True)
with open("%s/.config" % param["kdir"], 'r') as fconfig:
wconfig = fconfig.read()
if not re.search("%s=" % dconfig, wconfig):
print("DEBUG: %s is already disabled" % dconfig)
return 0
wconfig = re.sub("%s.*" % dconfig, "# %s is not set" % dconfig, wconfig)
with open("%s/.config" % param["kdir"], 'w') as fconfig:
fconfig.write(wconfig)
if args.debug:
subprocess.run("diff -u %s/.config.old %s/.config" % (param["kdir"], param["kdir"]), shell=True)
make_opts = param["make_opts"]
pbuild = subprocess.run("make %s olddefconfig" % make_opts, shell=True)
# verify it is still disabled
with open("%s/.config" % param["kdir"], 'r') as fconfig:
wconfig = fconfig.read()
if re.search("^%s=" % dconfig, wconfig):
print("BADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD")
###############################################################################
###############################################################################
def genconfig(sourcedir, param, defconfig):
os.chdir(sourcedir)
make_opts = param["make_opts"]
if args.noact:
print("Will do make %s %s" % (make_opts, defconfig))
return 0
if defconfig == "randconfig" and args.randconfigseed is not None:
os.environ["KCONFIG_SEED"] = args.randconfigseed
logdir = os.path.expandvars(tc["config"]["logdir"])
if not os.path.exists(logdir):
os.mkdir(logdir)
if args.nolog:
logfile = sys.stdout
else:
logfile = open("%s/%s.log" % (logdir, param["targetname"]), 'w')
if args.quiet:
pbuild = subprocess.Popen("make %s %d" % (make_opts, defconfig), shell=True, stdout=subprocess.DEVNULL)
else:
pbuild = subprocess.Popen("make %s %s 2>&1" % (make_opts, defconfig), shell=True, stdout=logfile)
outs, err = pbuild.communicate()
if args.configoverlay:
for coverlay in args.configoverlay.split(","):
if coverlay == "vanilla":
if args.debug:
print("DEBUG: skip all config overlays")
return 0
shutil.copy("%s/.config" % param["kdir"], "%s/.config.def" % param["kdir"])
# add needed options for LAVA
if args.debug:
print("DEBUG: add LAVA configs")
enable_config(param, "CONFIG_BLK_DEV_INITRD")
enable_config(param, "CONFIG_BLK_DEV_RAM=y")
enable_config(param, "CONFIG_DEVTMPFS=y")
enable_config(param, "CONFIG_DEVTMPFS_MOUNT=y")
enable_config(param, "CONFIG_MODULES=y")