Skip to content

Commit 7f71edf

Browse files
Tejas ManhasTejas Manhas
Tejas Manhas
authored and
Tejas Manhas
committed
Adding functionalities for linux-next and email
Signed-off-by: Tejas Manhas <[email protected]>
1 parent 2c9104c commit 7f71edf

File tree

3 files changed

+159
-2
lines changed

3 files changed

+159
-2
lines changed

OpTestConfiguration.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ def get_parser():
460460
help="Don't exit if we find unknown command line arguments")
461461
misc_group.add_argument("--secvar-payload-url",
462462
help="Specify a URL for the secvar test data payload")
463-
463+
misc_group.add_argument("--bisect-flag",
464+
help="Specify if bisection is to be done or not")
464465
return parser
465466

466467

testcases/Build_bisector.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,21 @@ def runTest(self):
9191
makefile_path = os.path.join(self.conf.basedir, "make.sh")
9292
self.cv_HOST.copy_test_file_to_host(makefile_path, dstdir=self.linux_path)
9393
self.connection.run_command("git bisect start")
94-
self.connection.run_command("git bisect good {} ".format(self.good_commit))
94+
folder_type=re.split(r'[\/\\.]',str(self.repo))[-2]
95+
print("FOLDER",folder_type)
96+
if folder_type == 'linux-next':
97+
self.connection.run_command("git fetch --tags")
98+
good_tag=self.connection.run_command("git tag -l 'v[0-9]*' | sort -V | tail -n 1")
99+
self.connection.run_command("git bisect good {} ".format(good_tag))
100+
else:
101+
self.connection.run_command("git bisect good {} ".format(self.good_commit))
95102
self.connection.run_command(" git bisect bad ")
96103
self.connection.run_command("chmod +x ./make.sh ")
97104
commit = self.connection.run_command(" git bisect run ./make.sh")
98105
badCommit = [word for word in commit if word.endswith("is the first bad commit")]
99106
badCommit= badCommit[0].split()[0]
100107
email = self.get_email(badCommit)
108+
log.info("LOGGG")
109+
self.connection.run_command("git bisect log")
101110
self.connection.run_command("git bisect reset")
102111
return email , badCommit

testcases/Email_git.py

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#Email_git.py: to make boot of the repo and test it through exit code
2+
3+
#!/usr/bin/env python3
4+
# OpenPOWER Automated Test Project
5+
#
6+
# Contributors Listed Below - COPYRIGHT 2024
7+
# [+] International Business Machines Corp.
8+
#
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19+
# implied. See the License for the specific language governing
20+
# permissions and limitations under the License.
21+
import json
22+
# import requests
23+
import os
24+
import uuid
25+
from datetime import datetime
26+
import re
27+
import unittest
28+
import os
29+
from urllib.parse import urlparse
30+
from enum import Enum
31+
import subprocess
32+
import OpTestConfiguration
33+
import OpTestLogger
34+
import configparser
35+
import sys
36+
from testcases import BisectKernel
37+
from testcases import Test_build
38+
from common.OpTestSystem import OpSystemState
39+
from common.OpTestSOL import OpSOLMonitorThread
40+
from common.OpTestInstallUtil import InstallUtil
41+
from common.Exceptions import CommandFailed
42+
# from testcases import Boot
43+
log = OpTestLogger.optest_logger_glob.get_logger(__name__)
44+
class Email_git(unittest.TestCase):
45+
"""
46+
Test case for bisecting the Linux kernel using Git Bisect.
47+
This test downloads the Linux kernel from a specified repository,
48+
configures and compiles it, and then uses Git Bisect to find the
49+
commit that introduced a specific issue.
50+
"""
51+
def setUp(self):
52+
"""
53+
Set up the test environment.
54+
Initializes test parameters and checks required configurations.
55+
"""
56+
self.conf = OpTestConfiguration.conf
57+
self.cv_HOST = self.conf.host()
58+
self.cv_SYSTEM = self.conf.system()
59+
self.connection = self.cv_SYSTEM.cv_HOST.get_ssh_connection()
60+
self.console_thread = OpSOLMonitorThread(1, "console")
61+
self.host_cmd_timeout = self.conf.args.host_cmd_timeout
62+
self.repo = self.conf.args.git_repo
63+
self.repo_reference = self.conf.args.git_repo_reference
64+
self.branch = self.conf.args.git_branch
65+
self.home = self.conf.args.git_home
66+
# self.config_path = self.conf.args.git_repoconfigpatih
67+
self.config = self.conf.args.git_repoconfig
68+
self.good_commit = self.conf.args.good_commit
69+
self.bad_commit = self.conf.args.bad_commit
70+
self.bisect_script = self.conf.args.bisect_script
71+
self.bisect_category = self.conf.args.bisect_category
72+
self.append_kernel_cmdline = self.conf.args.append_kernel_cmdline
73+
self.linux_path = os.path.join(self.home, "linux")
74+
if not self.repo:
75+
self.fail("Provide git repo of kernel to install")
76+
if not (self.conf.args.host_ip and self.conf.args.host_user and self.conf.args.host_password):
77+
self.fail(
78+
"Provide host ip user details refer, --host-{ip,user,password}")
79+
def get_commit_message(self,commit_sha):
80+
try:
81+
self.connection.run_command(" if [ '$(pwd)' != {} ]; then cd {} || exit 1 ; fi ".format(self.linux_path,self.linux_path))
82+
83+
commit_message = self.connection.run_command("git log -n 1 --pretty=format:%s {} | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'".format(commit_sha))
84+
print(commit_message)
85+
except subprocess.CalledProcessError:
86+
commit_message = None
87+
print(commit_message[0].strip())
88+
return commit_message[0].strip()
89+
def runTest(self):
90+
# def generate_email_template(machine_type, gcc_version, commit, error_message):
91+
machine_type = self.connection.run_command("uname -m")
92+
gcc_version = self.connection.run_command("gcc --version")[0]
93+
kernel_version = self.connection.run_command("uname -r")
94+
try:
95+
with open("output.json", "r") as file:
96+
data = json.load(file)
97+
error_message = data.get("error", "")
98+
commit = str(data.get("commit", ""))[:7]
99+
except FileNotFoundError:
100+
print("Error: output.json not found.")
101+
error_message = ""
102+
commit = ""
103+
104+
fix_description = self.get_commit_message(commit)
105+
# self.repo = "https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git"
106+
107+
if "https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git" in self.repo:
108+
linux = "netdev/net"
109+
elif "https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git" in self.repo:
110+
linux = "netdev/net-next"
111+
elif "https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git" in self.repo or "git://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git" in self.repo:
112+
linux = "scsi/scsi-queue"
113+
elif "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git" in self.repo:
114+
linux = "mainline/master"
115+
elif "https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git" in self.repo:
116+
linux = "linux-next/master"
117+
else:
118+
linux = "linux"
119+
120+
subject = "[{}][bisected {}][PPC {}] build fail with error: {}".format(linux,commit, machine_type, error_message)
121+
122+
body = """
123+
Greetings,
124+
125+
Today's next kernel fails to build with gcc {} on {} machine.
126+
127+
Kernel build fail at error: {}
128+
129+
Kernel Version: {}
130+
Machine Type: {}
131+
gcc: {}
132+
Commit: {}
133+
134+
kernel builds fine when the bad commit ({}) is reverted
135+
{} - {}
136+
137+
--
138+
Regards
139+
PPC KBOT
140+
""".format(gcc_version, machine_type, error_message,kernel_version, machine_type, gcc_version, commit,commit, commit, fix_description)
141+
print(subject)
142+
print(body)
143+
144+
with open("email.json","w") as email:
145+
json.dump({"subject":subject,"body":body},email)
146+
# return subject, body
147+

0 commit comments

Comments
 (0)