Skip to content

Commit 0f6ca83

Browse files
Tejas ManhasTejas Manhas
Tejas Manhas
authored and
Tejas Manhas
committed
APIs added to support kernel build test and bisection
Libraries added for error message parsing, build bisection email format, get git details Signed-off-by: Tejas Manhas <[email protected]>
1 parent 94f378e commit 0f6ca83

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

common/OpTestUtil.py

+116
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,122 @@ def prepare_source(self,spec_file, host, dest_path, package, build_option=None,
23532353
except OpTestError:
23542354
return ""
23552355

2356+
def err_message(self, er):
2357+
"""
2358+
To get entire error msg
2359+
"""
2360+
error_message = [str(item) for item in er]
2361+
combined_error = '\n'.join(error_message)
2362+
combined_error = re.sub(r'\x1b\[[0-9;]*[mK]|,', '', combined_error)
2363+
parts = combined_error.split('\x1b[')
2364+
cleaned_error = ''.join(char for char in combined_error if ord(char) < 128)
2365+
pattern = r'in file.*?compilation terminated'
2366+
match = re.search(pattern, cleaned_error, re.IGNORECASE | re.DOTALL)
2367+
if match:
2368+
relevant_part = match.group(0)
2369+
return relevant_part
2370+
return " "
2371+
2372+
def get_email(self, commit_id):
2373+
"""
2374+
To get email of Author from the identified bad commit
2375+
"""
2376+
connection = self.conf.host()
2377+
try :
2378+
connection.host_run_command("git config --global color.ui true")
2379+
result = connection.host_run_command("git show --format=%ce {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_id))
2380+
return result[0]
2381+
except subprocess.CalledProcessError as e:
2382+
log.info(e)
2383+
return None
2384+
2385+
def build_bisector(self, linux_path, good_commit, repo):
2386+
connection = self.conf.host()
2387+
connection.host_run_command(" if [ '$(pwd)' != {} ]; then cd {} || exit 1 ; fi ".format(linux_path,linux_path))
2388+
shallow = connection.host_run_command("git rev-parse --is-shallow-repository")
2389+
if shallow[-1] in [True,'true']:
2390+
connection.host_run_command("git fetch --unshallow",timeout=3000)
2391+
makefile_path = os.path.join(self.conf.basedir, "test_binaries/make.sh")
2392+
connection.copy_test_file_to_host(makefile_path, dstdir=linux_path)
2393+
connection.host_run_command("git bisect start")
2394+
folder_type=re.split(r'[\/\\.]',str(repo))[-2]
2395+
if folder_type == 'linux-next':
2396+
connection.host_run_command("git fetch --tags")
2397+
good_tag=connection.host_run_command("git tag -l 'v[0-9]*' | sort -V | tail -n 1")
2398+
connection.host_run_command("git bisect good {} ".format(good_tag))
2399+
else:
2400+
connection.host_run_command("git bisect good {} ".format(good_commit))
2401+
connection.host_run_command(" git bisect bad ")
2402+
connection.host_run_command("chmod +x ./make.sh ")
2403+
commit = connection.host_run_command(" git bisect run ./make.sh")
2404+
badCommit = [word for word in commit if word.endswith("is the first bad commit")]
2405+
badCommit= badCommit[0].split()[0]
2406+
email = self.get_email(badCommit)
2407+
connection.host_run_command("git bisect log")
2408+
connection.host_run_command("git bisect reset")
2409+
return email, badCommit
2410+
2411+
def get_commit_message(self, linux_path, commit_sha):
2412+
connection = self.conf.host()
2413+
try:
2414+
connection.host_run_command(" if [ '$(pwd)' != {} ]; then cd {} || exit 1 ; fi ".format(linux_path,linux_path))
2415+
commit_message = connection.host_run_command("git log -n 1 --pretty=format:%s {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_sha))
2416+
except subprocess.CalledProcessError as e:
2417+
log.info(e)
2418+
commit_message = None
2419+
return commit_message[0].strip()
2420+
2421+
def format_email(self, linux_path , repo):
2422+
connection = self.conf.host()
2423+
machine_type = connection.host_run_command("uname -m")
2424+
gcc_version = connection.host_run_command("gcc --version")[0]
2425+
kernel_version = connection.host_run_command("uname -r")
2426+
try:
2427+
with open("output.json", "r") as file:
2428+
data = json.load(file)
2429+
error_message = data.get("error", "")
2430+
err_long = data.get("err_msg","")
2431+
commit = str(data.get("commit", ""))[:7]
2432+
except FileNotFoundError:
2433+
log.error("Error: output.json not found.")
2434+
error_message = ""
2435+
commit = ""
2436+
fix_description = self.get_commit_message(linux_path,commit)
2437+
if "netdev/net" in repo:
2438+
linux = "netdev/net"
2439+
elif "netdev/net-next" in repo:
2440+
linux = "netdev/net-next"
2441+
elif "mkp/scsi" in repo :
2442+
linux = "scsi/scsi-queue"
2443+
elif "torvalds/linux" in repo:
2444+
linux = "mainline/master"
2445+
elif "next/linux-next" in repo:
2446+
linux = "linux-next/master"
2447+
else:
2448+
linux = "linux"
2449+
subject = "[{}][bisected {}] [{}] build fail with error: {}".format(linux,commit, machine_type, error_message)
2450+
body = """
2451+
Greetings,
2452+
2453+
Today's {} kernel fails to build on {} machine.
2454+
2455+
Kernel build fail at error: {}
2456+
{}
2457+
2458+
Kernel Version: {}
2459+
Machine Type: {}
2460+
gcc: {}
2461+
Bisected Commit: {}
2462+
2463+
kernel builds fine when the bad commit ({}) is reverted
2464+
{} - {}
2465+
--
2466+
Regards
2467+
Linux CI
2468+
""".format(linux, machine_type, error_message,err_long,kernel_version, machine_type, gcc_version, commit,commit, commit, fix_description)
2469+
with open("email.json","w") as email:
2470+
json.dump({"subject":subject,"body":body},email)
2471+
23562472

23572473
class Server(object):
23582474
'''

0 commit comments

Comments
 (0)