Skip to content

Commit

Permalink
demo commit for jenkins run
Browse files Browse the repository at this point in the history
Signed-off-by: Tejas Manhas <[email protected]>
  • Loading branch information
Tejas Manhas authored and Tejas Manhas committed Jun 5, 2024
1 parent c1f976c commit b50e272
Show file tree
Hide file tree
Showing 2 changed files with 423 additions and 1 deletion.
123 changes: 122 additions & 1 deletion common/OpTestUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,6 @@ def get_distro_src(self, package, dest_path, build_option=None):
else:
return ""


def prepare_source(self,spec_file, host, dest_path, package, build_option=None):
"""
Rpmbuild the spec path and return build dir
Expand All @@ -2347,6 +2346,128 @@ def prepare_source(self,spec_file, host, dest_path, package, build_option=None):
return host.host_run_command(f"ls -d -- {dest_path}/* | grep {package}")[0]
except OpTestError:
return ""

def err_message(self,er):
"""
To get entire error msg
"""
error_message = [str(item) for item in er]
combined_error = '\n'.join(error_message)
combined_error = re.sub(r'\x1b\[[0-9;]*[mK]|,', '', combined_error)
parts = combined_error.split('\x1b[')
cleaned_error = ''.join(char for char in combined_error if ord(char) < 128)
pattern = r'in\sfile.*?compilation\sterminated'
match = re.search(pattern, cleaned_error, re.IGNORECASE | re.DOTALL)
if match:
relevant_part = match.group(0)
print(relevant_part)
return relevant_part
else:
print("No match found")
return None

def get_email(self, commit_id):
"""
To get email of Author from the identified bad commit
"""
connection = self.conf.host()
try :
connection.host_run_command("git config --global color.ui true")
result = connection.host_run_command("git show --format=%ce {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_id))
email = result[0]
return email
except subprocess.CalledProcessError as e:
return None

def Build_bisector(self,linux_path, good_commit,repo):
connection = self.conf.host()
connection.host_run_command(" if [ '$(pwd)' != {} ]; then cd {} || exit 1 ; fi ".format(linux_path,linux_path))
shallow = connection.host_run_command("git rev-parse --is-shallow-repository")
if shallow[-1] == True or shallow[-1] == 'true':
connection.host_run_command("git fetch --unshallow",timeout=3000)
makefile_path = os.path.join(self.conf.basedir, "test_binaries/make.sh")
connection.copy_test_file_to_host(makefile_path, dstdir=linux_path)
connection.host_run_command("git bisect start")
folder_type=re.split(r'[\/\\.]',str(repo))[-2]
if folder_type == 'linux-next':
connection.host_run_command("git fetch --tags")
good_tag=connection.host_run_command("git tag -l 'v[0-9]*' | sort -V | tail -n 1")
connection.host_run_command("git bisect good {} ".format(good_tag))
else:
connection.host_run_command("git bisect good {} ".format(good_commit))
connection.host_run_command(" git bisect bad ")
connection.host_run_command("chmod +x ./make.sh ")
commit = connection.host_run_command(" git bisect run ./make.sh")
badCommit = [word for word in commit if word.endswith("is the first bad commit")]
badCommit= badCommit[0].split()[0]
email = self.get_email(badCommit)
connection.host_run_command("git bisect log")
connection.host_run_command("git bisect reset")
return email , badCommit

def get_commit_message(self,linux_path,commit_sha):
connection = self.conf.host()
try:
connection.host_run_command(" if [ '$(pwd)' != {} ]; then cd {} || exit 1 ; fi ".format(linux_path,linux_path))
commit_message = connection.host_run_command("git log -n 1 --pretty=format:%s {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_sha))
except subprocess.CalledProcessError:
commit_message = None
return commit_message[0].strip()

def Email_git(self,linux_path ,repo):
connection = self.conf.host()
machine_type = connection.host_run_command("uname -m")
gcc_version = connection.host_run_command("gcc --version")[0]
kernel_version = connection.host_run_command("uname -r")
try:
with open("output.json", "r") as file:
data = json.load(file)
error_message = data.get("error", "")
err_long = data.get("err_msg","")
commit = str(data.get("commit", ""))[:7]
except FileNotFoundError:
print("Error: output.json not found.")
error_message = ""
commit = ""
fix_description = self.get_commit_message(linux_path,commit)
if "netdev/net" in repo:
linux = "netdev/net"
elif "netdev/net-next" in repo:
linux = "netdev/net-next"
elif "mkp/scsi" in repo :
linux = "scsi/scsi-queue"
elif "torvalds/linux" in repo:
linux = "mainline/master"
elif "next/linux-next" in repo:
linux = "linux-next/master"
else:
linux = "linux"
subject = "[{}][bisected {}][PPC {}] build fail with error: {}".format(linux,commit, machine_type, error_message)
body = """
Greetings,
Today's next kernel fails to build with gcc {} on {} machine.
Kernel build fail at error: {}
{}
Kernel Version: {}
Machine Type: {}
gcc: {}
Bisected Commit: {}
kernel builds fine when the bad commit ({}) is reverted
{} - {}
--
Regards
PPC KBOT
""".format(gcc_version, machine_type, error_message,err_long,kernel_version, machine_type, gcc_version, commit,commit, commit, fix_description)
print(subject)
print(body)
with open("email.json","w") as email:
json.dump({"subject":subject,"body":body},email)


class Server(object):
Expand Down
Loading

0 comments on commit b50e272

Please sign in to comment.