This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
squad-stats-report
executable file
·460 lines (407 loc) · 13.3 KB
/
squad-stats-report
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: set ts=4
#
# Copyright 2022-present Linaro Limited
#
# SPDX-License-Identifier: MIT
import argparse
import json
import logging
import os
import sys
from collections import defaultdict
from datetime import date, timedelta
from pathlib import Path
from squad_client.core.api import SquadApi
from squad_client.core.models import ALL, Squad
from squad_client.utils import getid
squad_host_url = "https://qa-reports.linaro.org/"
SquadApi.configure(cache=3600, url=os.getenv("SQUAD_HOST", squad_host_url))
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
KNOWN_ARCHITECTURES = [
"arc",
"arm",
"arm64",
"i386",
"mips",
"parisc",
"powerpc",
"riscv",
"s390",
"sh",
"sparc",
"x86_64",
]
KNOWN_DEVICES = [
"bcm2711-rpi-4-b",
"dragonboard-410c",
"dragonboard-820c",
"dragonboard-845c",
"fvp-aemva",
"hi6220-hikey",
"i386",
"juno-r2",
"nxp-ls2088",
"qemu_arm",
"qemu_arm64",
"qemu_i386",
"qemu_x86_64",
"qemu-arm64",
"qemu-arm64be",
"qemu-armv5",
"qemu-armv7",
"qemu-armv7be",
"qemu-i386",
"qemu-mips32",
"qemu-mips32el",
"qemu-mips64",
"qemu-mips64el",
"qemu-ppc32",
"qemu-ppc64",
"qemu-ppc64le",
"qemu-riscv32",
"qemu-riscv64",
"qemu-s390",
"qemu-sh4",
"qemu-sparc64",
"qemu-x86_64",
"x15",
"x86",
]
KNOWN_SUITES = [
"kselftest-android",
"kselftest-arm64",
"kselftest-breakpoints",
"kselftest-capabilities",
"kselftest-cgroup",
"kselftest-clone3",
"kselftest-core",
"kselftest-cpu-hotplug",
"kselftest-cpufreq",
"kselftest-drivers-dma-buf",
"kselftest-efivarfs",
"kselftest-filesystems-binderfs",
"kselftest-filesystems",
"kselftest-firmware",
"kselftest-fpu",
"kselftest-futex",
"kselftest-gpio",
"kselftest-ipc",
"kselftest-ir",
"kselftest-kcmp",
"kselftest-lib",
"kselftest-membarrier",
"kselftest-memfd",
"kselftest-memory-hotplug",
"kselftest-mincore",
"kselftest-mount",
"kselftest-mqueue",
"kselftest-net-forwarding",
"kselftest-netfilter",
"kselftest-nsfs",
"kselftest-openat2",
"kselftest-pid_namespace",
"kselftest-pidfd",
"kselftest-proc",
"kselftest-pstore",
"kselftest-rseq",
"kselftest-rtc",
"kselftest-seccomp",
"kselftest-sigaltstack",
"kselftest-size",
"kselftest-splice",
"kselftest-static_keys",
"kselftest-sync",
"kselftest-sysctl",
"kselftest-tc-testing",
"kselftest-timens",
"kselftest-timers",
"kselftest-tmpfs",
"kselftest-tpm2",
"kselftest-user",
"kselftest-vm",
"kselftest-zram",
"kunit",
"kvm-unit-tests",
"libhugetlbfs",
"log-parser-boot",
"log-parser-test",
"ltp-cap_bounds",
"ltp-commands",
"ltp-containers",
"ltp-cpuhotplug",
"ltp-crypto",
"ltp-cve",
"ltp-dio",
"ltp-fcntl-locktests",
"ltp-filecaps",
"ltp-fs",
"ltp-fs_bind",
"ltp-fs_perms_simple",
"ltp-fsx",
"ltp-hugetlb",
"ltp-io",
"ltp-ipc",
"ltp-math",
"ltp-nptl",
"ltp-open-posix-tests",
"ltp-pty",
"ltp-sched",
"ltp-securebits",
"ltp-smoke",
"ltp-syscalls",
"ltp-tracing",
"network-basic-tests",
"perf",
"v4l2-compliance",
"vdso",
]
def parse_args():
parser = argparse.ArgumentParser(description="Compare builds within SQUAD")
parser.add_argument(
"--group",
required=True,
help="squad group",
)
parser.add_argument(
"--project",
required=True,
help="squad project",
)
parser.add_argument(
"--from-datetime",
required=True,
help="Starting date time. Example: 2022-01-01 or 2022-01-01T00:00:00",
)
parser.add_argument(
"--to-datetime",
required=True,
help="Ending date time. Example: 2022-12-31 or 2022-12-31T00:00:00",
)
parser.add_argument(
"--filename", help="Name of the output file where results will be written"
)
parser.add_argument(
"--debug",
action="store_true",
default=False,
help="Display debug messages",
)
return parser.parse_args()
def get_number_of_kernel_builts(project, builds):
suite = project.suite("build")
envs = project.environments(count=ALL)
archs = defaultdict(int)
total = 0
for build in builds:
logger.debug(f"Fetching build test from {build.version}")
tests = build.tests(suite=suite.id, fields="id,environment").values()
total += len(tests)
for test in tests:
for known_arches in KNOWN_ARCHITECTURES:
env = envs[getid(test.environment)].slug
if known_arches in env:
archs[env] += 1
break
return total, sorted_dict(archs)
def get_devices(environments, all_suites, builds):
actual_devices = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
all_testruns = {e.id: [] for e in environments}
for build in builds:
for testrun in build.testruns().values():
all_testruns[getid(testrun.environment)].append(testrun)
for env in environments:
for known_device in KNOWN_DEVICES:
if known_device in env.slug:
for testrun in all_testruns[env.id]:
for s in testrun.statuses(suite__isnull=False).values():
suite = all_suites[s.suite]
if suite.slug in KNOWN_SUITES:
tests_total = (
s.tests_pass
+ s.tests_skip
+ s.tests_fail
+ s.tests_xfail
)
actual_devices[known_device][suite.slug][
"total"
] += tests_total
actual_devices[known_device][suite.slug][
"pass"
] += s.tests_pass
actual_devices[known_device][suite.slug][
"skip"
] += s.tests_skip
actual_devices[known_device][suite.slug][
"fail"
] += s.tests_fail
actual_devices[known_device][suite.slug][
"xfail"
] += s.tests_xfail
return actual_devices
def get_total_number_of_tests(builds):
total = 0
for build in builds:
total += build.status.tests_total
return total
def sorted_dict(d):
return dict(sorted(d.items(), key=lambda k: k[0]))
def run():
args = parse_args()
if args.debug:
logger.setLevel(level=logging.DEBUG)
from_datetime = args.from_datetime
if "T" not in from_datetime:
from_datetime = f"{from_datetime}T00:00:00"
to_datetime = args.to_datetime
if "T" not in to_datetime:
to_datetime = f"{to_datetime}T23:59:59"
group = Squad().group(args.group)
project = group.project(args.project)
environments = project.environments(count=ALL).values()
json_dir = "stored_jsons"
if not os.path.exists(json_dir):
os.makedirs(json_dir)
print(f"Created dir: {json_dir}")
from_date = from_datetime.split("T")[0]
to_date = to_datetime.split("T")[0]
from_year = int(from_date.split("-")[0])
from_month = int(from_date.split("-")[1])
from_day = int(from_date.split("-")[2])
to_year = int(to_date.split("-")[0])
to_month = int(to_date.split("-")[1])
to_day = int(to_date.split("-")[2])
first_from_day = True
a = []
kernel_pushes = []
kernel_builts = []
num_tests = []
architectures = defaultdict(int)
devices = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
filename = args.filename or f"{json_dir}/stats-{args.group}-{args.project}.json"
if os.path.isfile(filename):
a = json.load(Path(filename).open(encoding="utf-8"))
tmp_from_date = date(from_year, from_month, from_day)
end_date = date(to_year, to_month, to_day)
delta = timedelta(days=1)
tmp_from_date -= delta
while tmp_from_date < end_date:
tmp_to_date = tmp_from_date + delta
tmp_from_date += delta
if first_from_day:
first_from_day = False
from_time = f"T{from_datetime.split('T')[1]}"
else:
from_time = "T00:00:00"
if tmp_to_date == end_date:
to_time = f"T{to_datetime.split('T')[1]}"
else:
to_time = "T23:59:59"
# if data already exists
ask_squad = True
for entry in a:
if (
entry["from_datetime"] == f"{tmp_from_date}{from_time}"
and entry["to_datetime"] == f"{tmp_to_date}{to_time}"
):
kernel_pushes.append(entry["kernel pushes"])
kernel_builts.append(entry["kernel builts"])
num_tests.append(entry["tests"])
for arch in entry["architectures"]:
architectures[arch] += entry["architectures"][arch]
for dev, suites in entry["devices"].items():
for suite in suites:
devices[dev][suite]["total"] += entry["devices"][dev][suite][
"total"
]
devices[dev][suite]["pass"] += entry["devices"][dev][suite][
"pass"
]
devices[dev][suite]["skip"] += entry["devices"][dev][suite][
"skip"
]
devices[dev][suite]["fail"] += entry["devices"][dev][suite][
"fail"
]
devices[dev][suite]["xfail"] += entry["devices"][dev][suite][
"xfail"
]
ask_squad = False
print(
f"Found dates in JSON file {filename}, from_datetime: {tmp_from_date}{from_time}, to_datetime: {tmp_to_date}{to_time}"
)
break
if ask_squad:
print(
f"Fetching builds from SQUAD, from_datetime: {tmp_from_date}{from_time}, to_datetime: {tmp_to_date}{to_time}"
)
builds = project.builds(
created_at__lt=f"{tmp_to_date}{to_time}",
created_at__gt=f"{tmp_from_date}{from_time}",
count=ALL,
).values()
number_of_kernel_builts, archs = get_number_of_kernel_builts(
project, builds
)
devs = get_devices(environments, project.suites(count=ALL), builds)
total_tests = get_total_number_of_tests(builds)
d = {}
d["from_datetime"] = f"{tmp_from_date}{from_time}"
d["to_datetime"] = f"{tmp_to_date}{to_time}"
d["kernel pushes"] = len(builds)
d["kernel builts"] = number_of_kernel_builts
d["tests"] = total_tests
d["architectures"] = archs
d["devices"] = devs
a.append(d)
print(
f"Write builds to JSON file {filename}, from_datetime: {tmp_from_date}{from_time}, to_datetime: {tmp_to_date}{to_time}"
)
Path(filename).write_text(json.dumps(a, indent=4), encoding="utf-8")
kernel_pushes.append(len(builds))
kernel_builts.append(number_of_kernel_builts)
num_tests.append(total_tests)
for arch in archs:
architectures[arch] += archs[arch]
for dev, suites in devs.items():
for suite in suites:
devices[dev][suite]["total"] += devs[dev][suite]["total"]
devices[dev][suite]["pass"] += devs[dev][suite]["pass"]
devices[dev][suite]["skip"] += devs[dev][suite]["skip"]
devices[dev][suite]["fail"] += devs[dev][suite]["fail"]
devices[dev][suite]["xfail"] += devs[dev][suite]["xfail"]
total_kernel_pushes = 0
for build in kernel_pushes:
total_kernel_pushes += build
total_kernel_builts = 0
for kernel in kernel_builts:
total_kernel_builts += kernel
total_tests = 0
for tests in num_tests:
total_tests += tests
archs_str = ""
arch_lines = list()
for arch in sorted_dict(architectures):
arch_lines.append(f"{arch:<10} ({architectures[arch]} builds)")
archs_str = "\n ".join(arch_lines)
devices_str = ""
device_lines = list()
for dev in sorted(devices):
device_lines.append(f"{dev:<20} ({len(devices[dev])} suites)")
devices_str += "\n ".join(device_lines)
report = f"""
project: {project.slug}
from: {from_datetime}
to: {to_datetime}
kernel pushes: {total_kernel_pushes}
kernel builts: {total_kernel_builts}
total tests: {total_tests}
architectures:
{archs_str}
devices:
{devices_str}"""
print(report)
if __name__ == "__main__":
sys.exit(run())