Skip to content

Commit 27e5500

Browse files
test: add units tests for hardware details helpers (#1544)
* test: add units tests for hardware details helpers part of #1496 * test: improve hardware details helpers tests - Add missing edge cases for hardware details validation - Improve assertion specificity in test cases - Remove unused variables from hardware details fixtures - Refactor test organization by moving tests between classes --------- Co-authored-by: Gustavo Flores <[email protected]>
1 parent 0bd6841 commit 27e5500

File tree

2 files changed

+1738
-0
lines changed

2 files changed

+1738
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
from collections import defaultdict
2+
from kernelCI_app.typeModels.hardwareDetails import Tree
3+
from kernelCI_app.typeModels.commonDetails import (
4+
TestArchSummaryItem,
5+
TestSummary,
6+
)
7+
from kernelCI_app.typeModels.common import StatusCount
8+
9+
10+
def create_tree(**overrides):
11+
"""Create Tree."""
12+
base_tree = Tree(
13+
index="1",
14+
origin="test",
15+
tree_name="mainline",
16+
git_repository_branch="master",
17+
git_repository_url="https://git.kernel.org",
18+
head_git_commit_name="commit1",
19+
head_git_commit_hash="abc123",
20+
head_git_commit_tag=["v5.4"],
21+
selected_commit_status=None,
22+
is_selected=True,
23+
)
24+
25+
for key, value in overrides.items():
26+
setattr(base_tree, key, value)
27+
28+
return base_tree
29+
30+
31+
def create_tree_status_summary(**overrides):
32+
"""Create tree status summary."""
33+
summary = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
34+
35+
summary["1"]["builds"]["PASS"] = 5
36+
summary["2"]["builds"]["FAIL"] = 2
37+
38+
for tree_id, tree_data in overrides.items():
39+
for category, status_data in tree_data.items():
40+
for status, count in status_data.items():
41+
summary[tree_id][category][status] = count
42+
43+
return summary
44+
45+
46+
def create_build_record(**overrides):
47+
"""Create build record."""
48+
base_record = {
49+
"build_id": "build123",
50+
"status": "PASS",
51+
"duration": 200,
52+
"start_time": "2024-01-15T09:00:00Z",
53+
"architecture": "x86_64",
54+
"compiler": "gcc",
55+
"config_name": "defconfig",
56+
"config_url": "http://config.com",
57+
"log_url": "http://log.com",
58+
"origin": "test",
59+
"command": "make",
60+
"comment": "Test build",
61+
"tree_name": "mainline",
62+
"git_commit_hash": "abc123",
63+
"git_commit_name": "commit1",
64+
"git_commit_tag": ["v5.4"],
65+
"git_repository_url": "https://git.kernel.org",
66+
"git_repository_branch": "master",
67+
}
68+
69+
base_record.update(overrides)
70+
return base_record
71+
72+
73+
def create_test_summary(**overrides):
74+
"""Create TestSummary."""
75+
base_summary = TestSummary(
76+
status=StatusCount(DONE=0, PASS=50, FAIL=10, ERROR=2, SKIP=5, MISS=1, NULL=0),
77+
origins={
78+
"test": StatusCount(
79+
DONE=0, PASS=30, FAIL=5, ERROR=1, SKIP=3, MISS=0, NULL=0
80+
),
81+
"boot": StatusCount(
82+
DONE=0, PASS=20, FAIL=5, ERROR=1, SKIP=2, MISS=1, NULL=0
83+
),
84+
},
85+
architectures=[
86+
TestArchSummaryItem(
87+
arch="x86_64",
88+
compiler="gcc",
89+
status=StatusCount(
90+
DONE=0, PASS=25, FAIL=5, ERROR=1, SKIP=2, MISS=0, NULL=0
91+
),
92+
),
93+
TestArchSummaryItem(
94+
arch="arm64",
95+
compiler="gcc",
96+
status=StatusCount(
97+
DONE=0, PASS=25, FAIL=5, ERROR=1, SKIP=3, MISS=1, NULL=0
98+
),
99+
),
100+
],
101+
configs={
102+
"defconfig": StatusCount(
103+
DONE=0, PASS=40, FAIL=8, ERROR=1, SKIP=4, MISS=0, NULL=0
104+
),
105+
"allmodconfig": StatusCount(
106+
DONE=0, PASS=10, FAIL=2, ERROR=1, SKIP=1, MISS=1, NULL=0
107+
),
108+
},
109+
issues=[],
110+
unknown_issues=0,
111+
fail_reasons=defaultdict(
112+
int, {"Test failure": 5, "Timeout": 3, "Memory error": 2}
113+
),
114+
failed_platforms={"x86_64", "arm64"},
115+
environment_compatible={"hardware1": StatusCount()},
116+
environment_misc={"x86_64": StatusCount()},
117+
)
118+
119+
for key, value in overrides.items():
120+
setattr(base_summary, key, value)
121+
122+
return base_summary
123+
124+
125+
base_tree = create_tree()
126+
127+
tree_with_different_commit = create_tree(
128+
index="2",
129+
tree_name="stable",
130+
git_repository_branch="linux-5.4.y",
131+
head_git_commit_name="commit2",
132+
head_git_commit_hash="def456",
133+
head_git_commit_tag=["v5.4.1"],
134+
)
135+
136+
base_tree_status_summary = create_tree_status_summary()
137+
138+
139+
def create_process_filters_instance(**overrides):
140+
"""Create instance for process_filters tests."""
141+
from unittest.mock import MagicMock
142+
143+
instance = MagicMock()
144+
instance.global_configs = set()
145+
instance.global_architectures = set()
146+
instance.global_compilers = set()
147+
instance.unfiltered_build_issues = set()
148+
instance.unfiltered_boot_issues = set()
149+
instance.unfiltered_test_issues = set()
150+
instance.unfiltered_boot_platforms = set()
151+
instance.unfiltered_test_platforms = set()
152+
instance.unfiltered_uncategorized_issue_flags = {}
153+
instance.unfiltered_origins = {"build": set(), "boot": set(), "test": set()}
154+
155+
for key, value in overrides.items():
156+
setattr(instance, key, value)
157+
158+
return instance
159+
160+
161+
def create_process_filters_record(**overrides):
162+
"""Create record for process_filters tests."""
163+
base_record = {
164+
"id": "test123",
165+
"path": "test.specific",
166+
"status": "PASS",
167+
"environment_misc": "{}",
168+
"test_origin": "test",
169+
"build_id": "build123",
170+
"incidents__test_id": "test123",
171+
"incidents__issue__id": "test_issue123",
172+
"incidents__issue__version": 2,
173+
"build__incidents__issue__id": "issue123",
174+
"build__incidents__issue__version": 1,
175+
"build__status": "PASS",
176+
"build__config_name": "defconfig",
177+
"build__architecture": "x86_64",
178+
"build__compiler": "gcc",
179+
"build__origin": "test",
180+
}
181+
182+
base_record.update(overrides)
183+
return base_record
184+
185+
186+
def create_handle_test_summary_record(**overrides):
187+
"""Create record for handle_test_summary tests."""
188+
base_record = {
189+
"status": "PASS",
190+
"build__config_name": "defconfig",
191+
"build__architecture": "x86_64",
192+
"build__compiler": "gcc",
193+
"environment_misc": "{}",
194+
"misc": "{}",
195+
"test_origin": "test",
196+
}
197+
198+
base_record.update(overrides)
199+
return base_record
200+
201+
202+
process_filters_instance = create_process_filters_instance()
203+
204+
process_filters_instance_without_build = create_process_filters_instance()
205+
206+
process_filters_record_with_build = create_process_filters_record()
207+
208+
process_filters_record_without_build = create_process_filters_record(
209+
id=None,
210+
build_id=None,
211+
)
212+
213+
process_filters_record_boot = create_process_filters_record(
214+
id="boot123",
215+
path="boot.test",
216+
test_origin="boot",
217+
build_id=None,
218+
incidents__issue__id="boot_issue123",
219+
incidents__issue__version=1,
220+
)
221+
222+
223+
handle_test_summary_record_new_config = create_handle_test_summary_record(
224+
build__config_name="newconfig",
225+
)
226+
227+
handle_test_summary_record_new_platform = create_handle_test_summary_record(
228+
status="FAIL",
229+
environment_misc='{"platform": "newplatform"}',
230+
misc='{"error_msg": "Test failed"}',
231+
)
232+
233+
handle_test_summary_record_new_origin = create_handle_test_summary_record(
234+
test_origin="neworigin",
235+
)

0 commit comments

Comments
 (0)