Skip to content

Commit 9fc07f3

Browse files
authored
Merge pull request #857 from Tejas3772/boot_bisect
OpTestKernelTest: Git bisect automation for kexec boot failure
2 parents b71ad3c + 2f1038f commit 9fc07f3

File tree

1 file changed

+66
-13
lines changed

1 file changed

+66
-13
lines changed

testcases/OpTestKernelTest.py

+66-13
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def boot_kernel(self):
129129
"""
130130
Does kexec boot for Upstream Linux
131131
"""
132+
self.con.run_command("export TERM=dumb; export NO_COLOR=1; alias ls='ls --color=never'; alias grep='grep --color=never'; git config --global color.ui false; bind 'set enable-bracketed-paste off'")
132133
self.con.run_command("make olddefconfig")
133134
base_version = self.con.run_command("uname -r")
134135
ker_ver = self.con.run_command("make kernelrelease")[-1]
@@ -152,32 +153,37 @@ def boot_kernel(self):
152153
kexec_cmdline = "kexec --initrd %s --command-line=\"%s\" /boot/vmlinu*-%s -l" % (initrd_file, cmdline, ker_ver)
153154
self.con.run_command("grub2-mkconfig --output=/boot/grub2/grub.cfg")
154155
self.con.run_command(kexec_cmdline)
156+
self.con.run_command("bind 'set enable-bracketed-paste off'")
157+
self.con.close()
155158
self.console_thread.console_terminate()
156159
self.cv_SYSTEM.util.build_prompt()
157160
self.console_thread.console_terminate()
158-
self.con.close()
159-
time.sleep(10)
161+
time.sleep(15)
160162
for i in range(5):
161163
raw_pty = self.util.wait_for(self.cv_SYSTEM.console.get_console, timeout=20)
162164
time.sleep(10)
163165
if raw_pty is not None:
164166
raw_pty.sendline("uname -r")
165167
break
166-
raw_pty.sendline("kexec -e")
167-
boot_log=raw_pty.before
168-
raw_pty.expect("login:", timeout=600)
169-
raw_pty.close()
170-
con = self.cv_SYSTEM.cv_HOST.get_ssh_connection()
171-
kernel_version_output = con.run_command("uname -r")[-1]
168+
try:
169+
raw_pty.sendline("kexec -e")
170+
except Exception as e:
171+
log.info(e)
172+
rc = raw_pty.expect(["login:", "WARNING: CPU"], timeout=600)
173+
if rc == 1:
174+
raw_pty.close()
175+
self.con = self.cv_SYSTEM.cv_HOST.get_ssh_connection()
176+
dmessage = self.con.run_command("dmesg --color=never")
177+
log.info(dmessage)
178+
log.info("WARNING: CPU catched")
179+
return False
180+
kernel_version_output = self.con.run_command("uname -r")[-1]
172181
log.info("Installed upstream kernel version: %s", kernel_version_output[-1])
173182
if self.conf.args.host_cmd:
174-
con.run_command(self.conf.args.host_cmd,
183+
self.con.run_command(self.conf.args.host_cmd,
175184
timeout=60)
176185
self.cv_HOST.host_gather_opal_msg_log()
177186
self.cv_HOST.host_gather_kernel_log()
178-
if "error" in boot_log.lower() or "warning" in boot_log.lower():
179-
print("Error or warning detected during boot process. Exiting...")
180-
return False
181187
if kernel_version_output != base_version :
182188
print("Kernel booted fine. Kernel version:", kernel_version_output.strip())
183189
return True
@@ -268,7 +274,54 @@ def runTest(self):
268274
exit_code = error[0]
269275
if exit_code != 0:
270276
return "Build Failure in boot, check build bisection Aborting"
271-
self.boot_kernel()
277+
log.info("BOOOT STARTING")
278+
boot = False
279+
try :
280+
boot = self.boot_kernel()
281+
except Exception as e:
282+
log.info("EXCEPTION")
283+
if not boot and self.bisect_flag == '1':
284+
log.info("BISECTION STARTING")
285+
subprocess.run(f"if [ -d {self.linux_path} ]; then rm -rf {self.linux_path}; fi", shell=True, check=True)
286+
subprocess.run(f"if [ ! -d {self.linux_path} ]; then mkdir -p {self.linux_path}; fi", shell=True, check=True)
287+
subprocess.run(f"cd {self.home}", shell=True, check=True)
288+
subprocess.run("git config --global http.postBuffer 1048576000", shell=True, check=True)
289+
subprocess.run(f"git clone -b {self.branch} {self.repo} {self.linux_path}" , shell=True, check=True,timeout=1800)
290+
subprocess.run(f"cd {self.linux_path}",shell=True,check=True)
291+
try:
292+
subprocess.run("git bisect start", shell=True, check=True,cwd=self.linux_path)
293+
subprocess.run("git bisect bad", shell=True, check=True,cwd=self.linux_path)
294+
folder_type=re.split(r'[\/\\.]',str(self.repo))[-2]
295+
if folder_type == 'linux-next':
296+
subprocess.run("git fetch --tags" , shell=True, check=True)
297+
good_tag=subprocess.run("git tag -l 'v[0-9]*' | sort -V | tail -n 1", shell=True, check=True)
298+
subprocess.run(f"git bisect good {good_tag}", shell=True, check=True,cwd=self.linux_path)
299+
else:
300+
subprocess.run("pwd")
301+
subprocess.run(f"git bisect good {self.good_commit}", shell=True, check=True,cwd=self.linux_path)
302+
while True:
303+
print("ENTERED LOOP BISECT")
304+
subprocess.run("git bisect next", shell=True, check=True, cwd=self.linux_path)
305+
commit_to_test = subprocess.check_output("git rev-parse HEAD", shell=True, cwd=self.linux_path).decode().strip()
306+
log.info("commit to test is")
307+
log.info(commit_to_test)
308+
self.con.run_command(" if [ '$(pwd)' != {} ]; then cd {} || exit 1 ; fi ; bind 'set enable-bracketed-paste off'".format(self.linux_path,self.linux_path))
309+
self.con.run_command("git checkout {}; git checkout {};".format(self.branch,commit_to_test))
310+
result = self.boot_kernel()
311+
if result == True:
312+
subprocess.run("git bisect good", shell=True, check=True,cwd=self.linux_path)
313+
else:
314+
subprocess.run("git bisect bad", shell=True, check=True,cwd=self.linux_path)
315+
except subprocess.CalledProcessError as e:
316+
log.info("Error:", e)
317+
finally:
318+
bisect_log = subprocess.run("git bisect log", shell=True, check=True,cwd=self.linux_path)
319+
log.info(bisect_log)
320+
subprocess.run("git bisect reset", shell=True, check=True,cwd=self.linux_path)
321+
elif self.bisect_flag != '1':
322+
log.info("BOOT FAILURE, NO BISECTION")
323+
else:
324+
log.info("NO BISECTION NEEDED, NOT BOOT FAILURE")
272325

273326
def tearDown(self):
274327
self.console_thread.console_terminate()

0 commit comments

Comments
 (0)