Skip to content

Commit 4d94070

Browse files
authored
Merge pull request #81 from nuclearcat/fix-bisect
fix(bisect.py): Fix initial tree creation and params rename
2 parents 70d059c + c5b6427 commit 4d94070

File tree

3 files changed

+70
-63
lines changed

3 files changed

+70
-63
lines changed

docs/checkout.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ This might be useful in several cases:
1010
- You want to create snapshot of the test results on specific tags (releases, etc).
1111
- Use this command for regression bisection
1212

13-
This command can execute all tests configured for particular tree/branch, or you can provide jobfilter to execute specific tests and builds.
13+
This command can execute all tests configured for particular tree/branch, or you can provide job-filter to execute specific tests and builds.
1414

1515
Example:
1616
```sh
17-
kci-dev checkout --giturl https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --branch master --commit f06021a18fcf8d8a1e79c5e0a8ec4eb2b038e153 --jobfilter "kbuild-gcc-12-x86"
17+
kci-dev checkout --giturl https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --branch master --commit f06021a18fcf8d8a1e79c5e0a8ec4eb2b038e153 --job-filter "kbuild-gcc-12-x86"
1818
```
1919

2020
Where:
2121
- `giturl` is the URL of the git repository to test.
2222
- `branch` is the branch of the git repository to test.
2323
- `commit` is the commit hash to test.
24-
- `jobfilter` is the job filter to use for the test (optional parameter)
25-
- `platformfilter` is the platform filter (usually it is name of hardware platform for group of devices) to use for the test (optional parameter)
24+
- `job-filter` is the job filter to use for the test (optional parameter)
25+
- `platform-filter` is the platform filter (usually it is name of hardware platform for group of devices) to use for the test (optional parameter)
2626

27-
To figure out correct jobfilter and platformfilter, you need to check test json node. For example:
27+
To figure out correct job-filter and platform-filter, you need to check test json node. For example:
2828
```json
2929
{
3030
"id": "670f0c27493b6b8188c7667c",
@@ -81,7 +81,7 @@ To figure out correct jobfilter and platformfilter, you need to check test json
8181
"kernel_type": "image"
8282
},
8383
"debug": null,
84-
"jobfilter": null,
84+
"job-filter": null,
8585
"platform_filter": null,
8686
"created": "2024-10-16T00:43:19.079000",
8787
"updated": "2024-10-16T02:22:58.113000",
@@ -94,9 +94,9 @@ To figure out correct jobfilter and platformfilter, you need to check test json
9494
}
9595
```
9696

97-
In this example, the jobfilter is `tast-mm-misc-arm64-qualcomm` for test, if you look into path, you can figure out also build job named and the platformfilter is `kbuild-gcc-12-arm64-chromeos-qualcomm` and in data/platform: `sc7180-trogdor-lazor-limozeen`. So complete command to test this job would be:
97+
In this example, the job-filter is `tast-mm-misc-arm64-qualcomm` for test, if you look into path, you can figure out also build job named and the platform-filter is `kbuild-gcc-12-arm64-chromeos-qualcomm` and in data/platform: `sc7180-trogdor-lazor-limozeen`. So complete command to test this job would be:
9898
```sh
99-
kci-dev checkout --giturl https://github.com/kernelci/linux.git --branch staging-mainline --commit c862449c840a37bbe797a0b719881449beac75ca --jobfilter tast-mm-misc-arm64-qualcomm --jobfilter kbuild-gcc-12-arm64-chromeos-qualcomm --platformfilter sc7180-trogdor-lazor-limozeen
99+
kci-dev checkout --giturl https://github.com/kernelci/linux.git --branch staging-mainline --commit c862449c840a37bbe797a0b719881449beac75ca --job-filter tast-mm-misc-arm64-qualcomm --job-filter kbuild-gcc-12-arm64-chromeos-qualcomm --platform-filter sc7180-trogdor-lazor-limozeen
100100
```
101101

102102
Other options:
@@ -111,7 +111,7 @@ Additionally, you can use --watch option to watch the progress of the test.
111111

112112
After executing the command, you will see the output similar to the following:
113113
```sh
114-
./kci-dev.py checkout --giturl https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --branch master --tipoftree --jobfilter baseline-nfs-arm64-qualcomm --jobfilter kbuild-gcc-12-arm64-chromeos-qualcomm --watch
114+
./kci-dev.py checkout --giturl https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --branch master --tipoftree --job-filter baseline-nfs-arm64-qualcomm --job-filter kbuild-gcc-12-arm64-chromeos-qualcomm --watch
115115
api connect: https://staging.kernelci.org:9100/
116116
Retrieving latest commit on tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git branch: master
117117
Commit to checkout: d3d1556696c1a993eec54ac585fe5bf677e07474
@@ -170,7 +170,7 @@ Together with --watch option, you can use --test option to wait for particular t
170170

171171
For example:
172172
```sh
173-
kci-dev.py checkout --giturl https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --branch master --tipoftree --jobfilter baseline-nfs-arm64-qualcomm --jobfilter kbuild-gcc-12-arm64-chromeos-qualcomm --platformfilter sc7180-trogdor-kingoftown --watch --test crit
173+
kci-dev.py checkout --giturl https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git --branch master --tipoftree --job-filter baseline-nfs-arm64-qualcomm --job-filter kbuild-gcc-12-arm64-chromeos-qualcomm --platform-filter sc7180-trogdor-kingoftown --watch --test crit
174174
```
175175

176176
This command will wait for the test results of the test with the name `crit`.

kcidev/subcommands/bisect.py

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"good": "",
3030
"bad": "",
3131
"history": [],
32-
"jobfilter": [],
33-
"platformfilter": [],
32+
"job_filter": [],
33+
"platform_filter": [],
3434
"test": "",
3535
"workdir": "",
3636
"bisect_init": False,
@@ -59,8 +59,8 @@ def print_state(state):
5959
click.secho("bad: " + state["bad"], fg="green")
6060
click.secho("retryfail: " + str(state["retryfail"]), fg="green")
6161
click.secho("history: " + str(state["history"]), fg="green")
62-
click.secho("jobfilter: " + str(state["jobfilter"]), fg="green")
63-
click.secho("platformfilter: " + str(state["platformfilter"]), fg="green")
62+
click.secho("job_filter: " + str(state["job_filter"]), fg="green")
63+
click.secho("platform_filter: " + str(state["platform_filter"]), fg="green")
6464
click.secho("test: " + state["test"], fg="green")
6565
click.secho("workdir: " + state["workdir"], fg="green")
6666
click.secho("bisect_init: " + str(state["bisect_init"]), fg="green")
@@ -76,7 +76,9 @@ def git_exec_getcommit(cmd):
7676
click.secho("Executing git command: " + " ".join(cmd), fg="green")
7777
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7878
if result.returncode != 0:
79-
click.secho("git command return failed", fg="red")
79+
click.secho("git command return failed. Error:", fg="red")
80+
click.secho(result.stderr, fg="red")
81+
click.secho(result.stdout, fg="red")
8082
sys.exit(1)
8183
lines = result.stdout.split(b"\n")
8284
if len(lines) < 2:
@@ -133,6 +135,20 @@ def init_bisect(state):
133135
return commitid
134136

135137

138+
def update_tree(workdir, branch, giturl):
139+
if not os.path.exists(workdir):
140+
click.secho(
141+
"Cloning repository (this might take significant time!)", fg="green"
142+
)
143+
repo = Repo.clone_from(giturl, workdir)
144+
repo.git.checkout(branch)
145+
else:
146+
click.secho("Pulling repository", fg="green")
147+
repo = Repo(workdir)
148+
repo.git.checkout(branch)
149+
repo.git.pull()
150+
151+
136152
def bisection_loop(state):
137153
olddir = os.getcwd()
138154
os.chdir(state["workdir"])
@@ -154,12 +170,12 @@ def bisection_loop(state):
154170
commit,
155171
"--watch",
156172
]
157-
# jobfilter is array, so we need to add each element as a separate argument
158-
for job in state["jobfilter"]:
159-
cmd.append("--jobfilter")
173+
# job_filter is array, so we need to add each element as a separate argument
174+
for job in state["job_filter"]:
175+
cmd.append("--job_filter")
160176
cmd.append(job)
161-
for platform in state["platformfilter"]:
162-
cmd.append("--platformfilter")
177+
for platform in state["platform_filter"]:
178+
cmd.append("--platform_filter")
163179
cmd.append(platform)
164180
result = kcidev_exec(cmd)
165181
try:
@@ -199,8 +215,8 @@ def bisection_loop(state):
199215
@click.option("--workdir", help="define the repository origin", default="kcidev-src")
200216
@click.option("--ignorestate", help="ignore save state", is_flag=True)
201217
@click.option("--statefile", help="state file", default="state.json")
202-
@click.option("--jobfilter", help="filter the job", multiple=True)
203-
@click.option("--platformfilter", help="filter the platform", multiple=True)
218+
@click.option("--job-filter", help="filter the job", multiple=True)
219+
@click.option("--platform-filter", help="filter the platform", multiple=True)
204220
@click.option("--test", help="Test expected to fail")
205221

206222
# test
@@ -215,8 +231,8 @@ def bisect(
215231
workdir,
216232
ignorestate,
217233
statefile,
218-
jobfilter,
219-
platformfilter,
234+
job_filter,
235+
platform_filter,
220236
test,
221237
):
222238
config = ctx.obj.get("CFG")
@@ -239,11 +255,11 @@ def bisect(
239255
if not bad:
240256
click.secho("--bad is required", fg="red")
241257
return
242-
if not jobfilter:
243-
click.secho("--jobfilter is required", fg="red")
258+
if not job_filter:
259+
click.secho("--job_filter is required", fg="red")
244260
return
245-
if not platformfilter:
246-
click.secho("--platformfilter is required", fg="red")
261+
if not platform_filter:
262+
click.secho("--platform_filter is required", fg="red")
247263
return
248264
if not test:
249265
click.secho("--test is required", fg="red")
@@ -254,24 +270,15 @@ def bisect(
254270
state["good"] = good
255271
state["bad"] = bad
256272
state["retryfail"] = retryfail
257-
state["jobfilter"] = jobfilter
258-
state["platformfilter"] = platformfilter
273+
state["job_filter"] = job_filter
274+
state["platform_filter"] = platform_filter
259275
state["test"] = test
260276
state["workdir"] = workdir
277+
update_tree(workdir, branch, giturl)
261278
save_state(state, state_file)
262279
else:
263280
print_state(state)
264-
265-
# if workdir doesnt exist, clone the repository
266-
if not os.path.exists(workdir):
267-
click.secho("Cloning repository", fg="green")
268-
repo = Repo.clone_from(giturl, workdir)
269-
repo.git.checkout(branch)
270-
else:
271-
click.secho("Pulling repository", fg="green")
272-
repo = Repo(workdir)
273-
repo.git.checkout(branch)
274-
repo.git.pull()
281+
update_tree(workdir, branch, giturl)
275282

276283
if not state["bisect_init"]:
277284
state["next_commit"] = init_bisect(state)

kcidev/subcommands/checkout.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ def send_checkout_full(baseurl, token, **kwargs):
4141
"url": kwargs["giturl"],
4242
"branch": kwargs["branch"],
4343
"commit": kwargs["commit"],
44-
"jobfilter": kwargs["jobfilter"],
44+
"jobfilter": kwargs["job_filter"],
4545
}
46-
if "platformfilter" in kwargs:
47-
data["platformfilter"] = kwargs["platformfilter"]
46+
if "platform_filter" in kwargs:
47+
data["platformfilter"] = kwargs["platform_filter"]
4848
jdata = json.dumps(data)
4949
print(jdata)
5050
try:
@@ -107,13 +107,13 @@ def check_node(node):
107107
return "FAIL"
108108

109109

110-
def watch_jobs(baseurl, token, treeid, jobfilter, test):
111-
# we need to add to jobfilter "checkout" node
112-
jobfilter = list(jobfilter)
113-
jobfilter.append("checkout")
110+
def watch_jobs(baseurl, token, treeid, job_filter, test):
111+
# we need to add to job_filter "checkout" node
112+
job_filter = list(job_filter)
113+
job_filter.append("checkout")
114114
while True:
115115
inprogress = 0
116-
joblist = jobfilter.copy()
116+
joblist = job_filter.copy()
117117
nodes = retrieve_treeid_nodes(baseurl, token, treeid)
118118
if not nodes:
119119
click.secho("No nodes found. Retrying...", fg="yellow")
@@ -122,17 +122,17 @@ def watch_jobs(baseurl, token, treeid, jobfilter, test):
122122
time_local = time.localtime()
123123
click.echo(f"Current time: {time.strftime('%Y-%m-%d %H:%M:%S', time_local)}")
124124
click.secho(
125-
f"Total tree nodes {len(nodes)} found. Jobfilter: {jobfilter}", fg="green"
125+
f"Total tree nodes {len(nodes)} found. job_filter: {job_filter}", fg="green"
126126
)
127127

128-
# Tricky part in watch is that we might have one item in jobfilter (job, test),
128+
# Tricky part in watch is that we might have one item in job_filter (job, test),
129129
# but it might spawn multiple nodes with same name
130130
test_result = None
131131
jobs_done_ts = None
132132
for node in nodes:
133133
if node["name"] == test:
134134
test_result = node["result"]
135-
if node["name"] in jobfilter:
135+
if node["name"] in job_filter:
136136
result = check_node(node)
137137
if result == "DONE":
138138
if isinstance(joblist, list) and node["name"] in joblist:
@@ -219,17 +219,17 @@ def retrieve_tot_commit(repourl, branch):
219219
)
220220
@click.option(
221221
"--watch",
222-
help="Interactively watch for a tasks in jobfilter",
222+
help="Interactively watch for a tasks in job-filter",
223223
is_flag=True,
224224
)
225-
# jobfilter is a list, might be one or more jobs
225+
# job_filter is a list, might be one or more jobs
226226
@click.option(
227-
"--jobfilter",
227+
"--job-filter",
228228
help="Job filter to trigger",
229229
multiple=True,
230230
)
231231
@click.option(
232-
"--platformfilter",
232+
"--platform-filter",
233233
help="Platform filter to trigger",
234234
multiple=True,
235235
)
@@ -239,17 +239,17 @@ def retrieve_tot_commit(repourl, branch):
239239
)
240240
@click.pass_context
241241
def checkout(
242-
ctx, giturl, branch, commit, jobfilter, platformfilter, tipoftree, watch, test
242+
ctx, giturl, branch, commit, job_filter, platform_filter, tipoftree, watch, test
243243
):
244244
cfg = ctx.obj.get("CFG")
245245
instance = ctx.obj.get("INSTANCE")
246246
url = api_connection(cfg[instance]["pipeline"])
247247
apiurl = cfg[instance]["api"]
248248
token = cfg[instance]["token"]
249-
if not jobfilter:
250-
jobfilter = None
249+
if not job_filter:
250+
job_filter = None
251251
click.secho("No job filter defined. All jobs will be triggered!", fg="yellow")
252-
if watch and not jobfilter:
252+
if watch and not job_filter:
253253
click.secho("No job filter defined. Can't watch for a job(s)!", fg="red")
254254
return
255255
if test and not watch:
@@ -275,8 +275,8 @@ def checkout(
275275
giturl=giturl,
276276
branch=branch,
277277
commit=commit,
278-
jobfilter=jobfilter,
279-
platformfilter=platformfilter,
278+
job_filter=job_filter,
279+
platform_filter=platform_filter,
280280
watch=watch,
281281
)
282282
if resp and "message" in resp:
@@ -292,7 +292,7 @@ def checkout(
292292
if test:
293293
click.secho(f"Watching for test result: {test}", fg="green")
294294
# watch for jobs
295-
watch_jobs(apiurl, token, treeid, jobfilter, test)
295+
watch_jobs(apiurl, token, treeid, job_filter, test)
296296

297297

298298
if __name__ == "__main__":

0 commit comments

Comments
 (0)