Skip to content

Commit 07e3f3f

Browse files
committed
tests: add test_sync_patches_pr_summary_success
Add a comprehensive test covering most of the sync_patches logic. Extend patchwork_mock to be able to load test responses from disk if appropriate. Use realistic json responses for this test to make KPD trigger relevant http calls. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 7b74b6a commit 07e3f3f

File tree

15 files changed

+1018
-10
lines changed

15 files changed

+1018
-10
lines changed

kernel_patches_daemon/github_sync.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def __init__(
133133

134134
async def get_mapped_branches(self, series: Series) -> List[str]:
135135
for tag in self.tag_to_branch_mapping:
136-
if tag in await series.all_tags():
136+
series_tags = await series.all_tags()
137+
if tag in series_tags:
137138
mapped_branches = self.tag_to_branch_mapping[tag]
138139
logging.info(f"Tag '{tag}' mapped to branch order {mapped_branches}")
139140
return mapped_branches
@@ -208,7 +209,8 @@ async def sync_patches(self) -> None:
208209
await loop.run_in_executor(None, worker.get_pulls)
209210
await loop.run_in_executor(None, worker.do_sync)
210211
worker._closed_prs = None
211-
worker.branches = [x.name for x in worker.repo.get_branches()]
212+
branches = worker.repo.get_branches()
213+
worker.branches = [b.name for b in branches]
212214

213215
mirror_done = time.time()
214216

kernel_patches_daemon/patchwork.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ async def __get_objects_recursive(
580580
params = {}
581581
while True:
582582
response = await self.__get(path, params=params)
583-
items += await response.json()
583+
j = await response.json()
584+
items += j
584585

585586
if "next" not in response.links:
586587
break
@@ -695,9 +696,8 @@ async def post_check_for_patch_id(
695696
async def get_series_by_id(self, series_id: int) -> Series:
696697
# fetches directly only if series is not available in local scope
697698
if series_id not in self.known_series:
698-
self.known_series[series_id] = Series(
699-
self, await self.__get_object_by_id("series", series_id)
700-
)
699+
series_json = await self.__get_object_by_id("series", series_id)
700+
self.known_series[series_id] = Series(self, series_json)
701701

702702
return self.known_series[series_id]
703703

tests/common/patchwork_mock.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
# pyre-unsafe
88

9+
import json
10+
import os
911
import re
10-
from typing import Any, Dict, Final
12+
13+
from typing import Any, Dict, Final, List
1114

1215
from aioresponses import aioresponses
1316

@@ -78,6 +81,31 @@ def get_dict_key(d: Dict[str, Any], idx: int = 0) -> str:
7881
return list(d)[idx]
7982

8083

84+
def load_test_data_file(file):
85+
with open(file, "r") as f:
86+
if file.endswith(".json"):
87+
return json.load(f)
88+
else:
89+
return f.read()
90+
91+
def load_test_data(path) -> Dict[str, Any]:
92+
jsons_by_path = {}
93+
with open(os.path.join(path, "responses.json"), "r") as f:
94+
jsons_by_path = json.load(f)
95+
data = {}
96+
for url, value in jsons_by_path.items():
97+
match value:
98+
case str():
99+
filepath = os.path.join(path, value)
100+
data[url] = load_test_data_file(filepath)
101+
case list():
102+
lst = []
103+
for filename in value:
104+
filepath = os.path.join(path, filename)
105+
lst.append(load_test_data_file(filepath))
106+
data[url] = lst
107+
return data
108+
81109
FOO_SERIES_FIRST = 2
82110
FOO_SERIES_LAST = 10
83111

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"id": 14114605,
3+
"url": "https://patchwork.test/api/1.1/patches/14114605/",
4+
"web_url": "https://patchwork.test/project/netdevbpf/patch/[email protected]/",
5+
"project": {
6+
"id": 399,
7+
"url": "https://patchwork.test/api/1.1/projects/399/",
8+
"name": "Netdev + BPF",
9+
"link_name": "netdevbpf",
10+
"list_id": "bpf.vger.kernel.org",
11+
"list_email": "[email protected]",
12+
"web_url": "",
13+
"scm_url": "",
14+
"webscm_url": ""
15+
},
16+
"msgid": "<[email protected]>",
17+
"date": "2025-06-11T15:48:58",
18+
"name": "[bpf-next] bpf: clear user buf when bpf_d_path failed",
19+
"commit_ref": "3b55a9e6738b7b82a7c57ebaa484aabd0c9d36bd",
20+
"pull_url": null,
21+
"state": "new",
22+
"archived": false,
23+
"hash": "ecb10e6ecea01d3f770e4d08eb251179b0f9a98b",
24+
"submitter": {
25+
"id": 216065,
26+
"url": "https://patchwork.test/api/1.1/people/216065/",
27+
"name": "Tao Chen",
28+
"email": "[email protected]"
29+
},
30+
"delegate": {
31+
"id": 121173,
32+
"url": "https://patchwork.test/api/1.1/users/121173/",
33+
"username": "bpf",
34+
"first_name": "BPF",
35+
"last_name": "",
36+
"email": "[email protected]"
37+
},
38+
"mbox": "https://patchwork.test/project/netdevbpf/patch/[email protected]/mbox/",
39+
"series": [
40+
{
41+
"id": 970926,
42+
"url": "https://patchwork.test/api/1.1/series/970926/",
43+
"web_url": "https://patchwork.test/project/netdevbpf/list/?series=970926",
44+
"date": "2025-06-11T15:48:58",
45+
"name": "[bpf-next] bpf: clear user buf when bpf_d_path failed",
46+
"version": 1,
47+
"mbox": "https://patchwork.test/series/970926/mbox/"
48+
}
49+
],
50+
"comments": "https://patchwork.test/api/patches/14114605/comments/",
51+
"check": "success",
52+
"checks": "https://patchwork.test/api/patches/14114605/checks/",
53+
"tags": {},
54+
"headers": {
55+
"Received": "from out-186.mta0.migadu.com (out-186.mta0.migadu.com\n [91.218.175.186])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 29219198E75\n\tfor <[email protected]>; Wed, 11 Jun 2025 15:49:31 +0000 (UTC)",
56+
"Authentication-Results": [
57+
"smtp.subspace.kernel.org;\n arc=none smtp.client-ip=91.218.175.186",
58+
"smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.dev",
59+
"smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=linux.dev",
60+
"smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=linux.dev [email protected]\n header.b=\"BLMetV01\""
61+
],
62+
"ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1749656974; cv=none;\n b=H3sJmO/4HOlIx6kUFl6H/+BRA9KPHHH4Q7GjlSA/LngQ6EFecK1QUciBapIR6C34s0H1sz1+glg3v1exuzPTkszlKJv44cGH+VioXoRre8Y0iWC1KVwdc7RHvgffJ0XPGihrNjrcuJjt4YmUCnouwVszIm4By1xzu3Sb6+nLec8=",
63+
"ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1749656974; c=relaxed/simple;\n\tbh=Vsu5Xaf2CfmWYXrEWUU8kTg6xy3/CnahfubB8AomyEw=;\n\th=From:To:Cc:Subject:Date:Message-ID:MIME-Version;\n b=dncJRD9nOpjZrsdcvYkxd2CfccDyNQ8uHadiFb/G4K5K4GAr1MRjBv/suIeI85s0iKBmv5NZ3r2PFI1g9Yus7+jBZ5z/wo42zqDVLhXSK87Dx3X+clSbiW9VqQ7wzQM1/2xFRgNIlZ12hswHopIjCQCr+w52ofYIXiH5Ug7o85Q=",
64+
"ARC-Authentication-Results": "i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.dev;\n spf=pass smtp.mailfrom=linux.dev;\n dkim=pass (1024-bit key) header.d=linux.dev [email protected]\n header.b=BLMetV01; arc=none smtp.client-ip=91.218.175.186",
65+
"X-Report-Abuse": "Please report any abuse attempt to [email protected] and\n include these headers.",
66+
"DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1;\n\tt=1749656960;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\t to:to:cc:cc:mime-version:mime-version:\n\t content-transfer-encoding:content-transfer-encoding;\n\tbh=NkpbyMsiJRwWnx6iOR+RLlbhyzNlbJ3e38I3A+4NmfI=;\n\tb=BLMetV01lS4FXWjpoxALr+a7Mi0irlvKqYcAZBywjBIwgNGKzGMwf6SP0SwobrqhyTbR8H\n\tNQ/nTgeRdr9+LbZ4t/A+vxRUTO28kF4R6uvFYTrAwmTj5i/qgFhOAX9bHiICSohUcwmfK3\n\tWvRPHYKGvp0Puq6S/5gBm2Q5AFHG7m4=",
67+
"From": "Tao Chen <[email protected]>",
68+
69+
70+
"Subject": "[PATCH bpf-next] bpf: clear user buf when bpf_d_path failed",
71+
"Date": "Wed, 11 Jun 2025 23:48:58 +0800",
72+
"Message-ID": "<[email protected]>",
73+
"Precedence": "bulk",
74+
"X-Mailing-List": "[email protected]",
75+
"List-Id": "<bpf.vger.kernel.org>",
76+
"List-Subscribe": "<mailto:[email protected]>",
77+
"List-Unsubscribe": "<mailto:[email protected]>",
78+
"MIME-Version": "1.0",
79+
"Content-Transfer-Encoding": "8bit",
80+
"X-Migadu-Flow": "FLOW_OUT",
81+
"X-Patchwork-Delegate": "[email protected]"
82+
},
83+
"content": "The bpf_d_path() function may fail. If it does,\nclear the user buf, like bpf_probe_read etc.\n\nSigned-off-by: Tao Chen <[email protected]>\n---\n kernel/trace/bpf_trace.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)",
84+
"diff": "diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c\nindex 0998cbbb963..bb1003cb271 100644\n--- a/kernel/trace/bpf_trace.c\n+++ b/kernel/trace/bpf_trace.c\n@@ -916,11 +916,14 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz)\n \t * potentially broken verifier.\n \t */\n \tlen = copy_from_kernel_nofault(&copy, path, sizeof(*path));\n-\tif (len < 0)\n+\tif (len < 0) {\n+\t\tmemset(buf, 0, sz);\n \t\treturn len;\n+\t}\n \n \tp = d_path(&copy, buf, sz);\n \tif (IS_ERR(p)) {\n+\t\tmemset(buf, 0, sz);\n \t\tlen = PTR_ERR(p);\n \t} else {\n \t\tlen = buf + sz - p;\n",
85+
"prefixes": [
86+
"bpf-next"
87+
]
88+
}

0 commit comments

Comments
 (0)