Debian Codegraph @

util/remaining-gnu-error.py

raw
1 #!/usr/bin/env python3
2 # This script lists the GNU failing tests by size
3 # Just like with util/run-gnu-test.sh, we expect the gnu sources
4 # to be in ../
5 import glob
6 import json
7 import os
8 import sys
9 import urllib
10 import urllib.request
11
12 base = "../gnu/tests/"
13
14 # Try to download the file, use local copy if download fails
15 result_json = "result.json"
16 try:
17 urllib.request.urlretrieve(
18 "https://raw.githubusercontent.com/uutils/coreutils-tracking/main/aggregated-result.json",
19 result_json,
20 )
21 except OSError as e:
22 print(f"Failed to download the file: {e}")
23 if not os.path.exists(result_json):
24 print(f"Local file '{result_json}' not found. Exiting.")
25 sys.exit(1)
26 else:
27 print(f"Using local file '{result_json}'.")
28
29 types = ("/*/*.sh", "/*/*.pl", "/*/*.xpl")
30
31 tests = []
32 error_tests = []
33 skip_tests = []
34
35 for files in types:
36 tests.extend(glob.glob(base + files))
37 # sort by size
38 list_of_files = sorted(tests, key=lambda x: os.stat(x).st_size)
39
40
41 def show_list(list_test):
42 # Remove the factor tests and reverse the list (bigger first)
43 tests = list(filter(lambda k: "factor" not in k, list_test))
44
45 for f in reversed(tests):
46 if contains_require_root(f):
47 print(f"{f}: {os.stat(f).st_size} / require_root")
48 else:
49 print(f"{f}: {os.stat(f).st_size}")
50 print()
51 print(f"{len(tests)} tests remaining")
52
53
54 def contains_require_root(file_path):
55 try:
56 with open(file_path, "r") as file:
57 return "require_root_" in file.read()
58 except OSError:
59 return False
60
61
62 with open("result.json", "r") as json_file:
63 data = json.load(json_file)
64
65 for d in data:
66 for e in data[d]:
67 # Not all the tests are .sh files, rename them if not.
68 script = e.replace(".log", ".sh")
69 a = f"{base}{d}/{script}"
70 if not os.path.exists(a):
71 a = a.replace(".sh", ".pl")
72 if not os.path.exists(a):
73 a = a.replace(".pl", ".xpl")
74
75 # the tests pass, we don't care anymore
76 if data[d][e] == "PASS":
77 try:
78 list_of_files.remove(a)
79 except ValueError:
80 print(f"Could not find test '{a}'. Maybe update the GNU repo?")
81 sys.exit(1)
82
83 # if it is SKIP, show it
84 if data[d][e] == "SKIP":
85 list_of_files.remove(a)
86 skip_tests.append(a)
87
88 # if it is ERROR, show it
89 if data[d][e] == "ERROR":
90 list_of_files.remove(a)
91 error_tests.append(a)
92
93 print("===============")
94 print("SKIP tests:")
95 show_list(skip_tests)
96 print()
97 print("===============")
98 print("ERROR tests:")
99 show_list(error_tests)
100 print()
101 print("===============")
102 print("FAIL tests:")
103 show_list(list_of_files)