Skip to content

Commit d1d5169

Browse files
Tejas ManhasTejas Manhas
Tejas Manhas
authored and
Tejas Manhas
committed
adding new functionalities for linux-next and bisect_flag and email
Signed-off-by: Tejas Manhas <[email protected]>
1 parent d575d90 commit d1d5169

File tree

4 files changed

+171
-13
lines changed

4 files changed

+171
-13
lines changed

OpTestConfiguration.py

+2
Original file line numberDiff line numberDiff line change
@@ -460,6 +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+
misc_group.add_argument("--bisect-flag",
464+
help="Specify if bisection is to be done or not")
463465
return parser
464466

465467

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

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
try:
94+
with open("output.json", "r") as file:
95+
data = json.load(file)
96+
error_message = data.get("error", "")
97+
commit = data.get("commit", "")
98+
except FileNotFoundError:
99+
print("Error: output.json not found.")
100+
error_message = ""
101+
commit = ""
102+
103+
fix_description = self.get_commit_message(commit)
104+
linux = re.split(r'[/.]', self.repo)[-2]
105+
subject = "[{}][bisected {}][gcc {}] build fail with error: {}".format(linux,commit, gcc_version, error_message)
106+
107+
body = """
108+
Greetings,
109+
110+
Today's next kernel fails to build with gcc {} on {} machine.
111+
112+
{}
113+
114+
Machine Type: {}
115+
gcc: {}
116+
Commit: {}
117+
118+
Builds fine when below patch is reverted
119+
{} - {}
120+
121+
--
122+
Regards
123+
Linux CI
124+
""".format(gcc_version, machine_type, error_message, machine_type, gcc_version, commit, commit, fix_description)
125+
print(subject)
126+
print(body)
127+
128+
with open("email.json","w") as email:
129+
json.dump({"subject":subject,"body":body},email)
130+
# return subject, body
131+

testcases/Test_build.py

+28-12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import configparser
3131
import sys
3232
from testcases import Build_bisector
33+
from testcases import Email_git
3334
from common.OpTestSystem import OpSystemState
3435
from common.OpTestSOL import OpSOLMonitorThread
3536
from common.Exceptions import CommandFailed
@@ -60,6 +61,7 @@ def setUp(self):
6061
self.bisect_category = self.conf.args.bisect_category
6162
self.append_kernel_cmdline = self.conf.args.append_kernel_cmdline
6263
self.linux_path = os.path.join(self.home, "linux")
64+
self.bisect_flag = self.conf.args.bisect_flag
6365
if not self.repo:
6466
self.fail("Provide git repo of kernel to install")
6567
if not (self.conf.args.host_ip and self.conf.args.host_user and self.conf.args.host_password):
@@ -92,9 +94,14 @@ def runTest(self):
9294
self.branch='master'
9395
log.info("CD DONE")
9496

95-
self.connection.run_command("git clone --depth 1 {} -b {}".format(self.repo, self.branch))
97+
self.connection.run_command("git clone -b {} {} linux".format( self.branch, self.repo),timeout=3000)
98+
# self.connection.run_command("git reset --hard ")
9699
self.connection.run_command("cd linux")
97-
commit = self.connection.run_command(" git log -1 --format=%H")
100+
# self.connection.run_command("git tag")
101+
# self.connection.run_command("git checkout next-20240229")
102+
103+
# self.connection.run_command("git reset --hard next-20240229")
104+
commit = self.connection.run_command(" git log -1 --format=%H | sed -r 's/\x1B\[[0-9:]*[JKsu]//g'")
98105
self.connection.run_command("cd ..")
99106
self.connection.run_command("wget http://ltc-jenkins.aus.stglabs.ibm.com:81/abdul/ioci/kernel_config -o linux/.config")
100107
self.connection.run_command("cd linux && make olddefconfig")
@@ -107,16 +114,25 @@ def runTest(self):
107114
if exit_code != 0:
108115
entry = self.Store_loc(errVal)[-1]
109116
badCommit = commit[-1]
110-
log.info("BUILD_BISECTOR CALLED")
111-
bisect = Build_bisector.Buil_bisector()
112-
bisect.setUp()
113-
res = bisect.runTest()
114-
log.info("BUILD_BISECTOR END")
115-
em=res[0]
116-
commiti=res[1]
117-
else :
118-
em=""
117+
if self.bisect_flag == True or self.bisect_flag == 'true':
118+
log.info("BUILD_BISECTOR CALLED")
119+
bisect = Build_bisector.Buil_bisector()
120+
bisect.setUp()
121+
res = bisect.runTest()
122+
log.info("BUILD_BISECTOR END")
123+
emaili=res[0]
124+
commiti=res[1]
125+
log.info("COMMIT REVERT HAS TO BE CHECKED MANUALLY")
126+
else :
127+
emaili=""
128+
commiti=commit[-1]
129+
else :
130+
emaili=""
119131
commiti=commit[-1]
120132
with open('output.json','w') as f:
121-
json.dump({"exit_code":exit_code,"email":em,"commit": commiti,"error":entry},f)
133+
json.dump({"exit_code":exit_code,"email":emaili,"commit": commiti,"error":entry,"flag":self.bisect_flag},f)
134+
if exit_code != 0:
135+
email = Email_git.Email_git()
136+
email.setUp()
137+
email.runTest()
122138
return exit_code

0 commit comments

Comments
 (0)