Skip to content

Commit d575d90

Browse files
Tejas ManhasTejas Manhas
Tejas Manhas
authored and
Tejas Manhas
committed
Added the Test_build.py that builds the kernel and calls Build_bisector if build fails
Signed-off-by: Tejas Manhas <[email protected]>
1 parent 4412a5a commit d575d90

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

testcases/Test_build.py

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#test_build.py: to make build 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 os
23+
import re
24+
import unittest
25+
import os
26+
from urllib.parse import urlparse
27+
import subprocess
28+
import OpTestConfiguration
29+
import OpTestLogger
30+
import configparser
31+
import sys
32+
from testcases import Build_bisector
33+
from common.OpTestSystem import OpSystemState
34+
from common.OpTestSOL import OpSOLMonitorThread
35+
from common.Exceptions import CommandFailed
36+
log = OpTestLogger.optest_logger_glob.get_logger(__name__)
37+
class Test_build(unittest.TestCase):
38+
"""
39+
Test case for building kernel and calling Build_bisector.py in case of build failure
40+
"""
41+
def setUp(self):
42+
"""
43+
Set up the test environment.
44+
Initializes test parameters and checks required configurations.
45+
"""
46+
self.conf = OpTestConfiguration.conf
47+
self.cv_HOST = self.conf.host()
48+
self.cv_SYSTEM = self.conf.system()
49+
self.connection = self.cv_SYSTEM.cv_HOST.get_ssh_connection()
50+
self.console_thread = OpSOLMonitorThread(1, "console")
51+
self.host_cmd_timeout = self.conf.args.host_cmd_timeout
52+
self.repo = self.conf.args.git_repo
53+
self.repo_reference = self.conf.args.git_repo_reference
54+
self.branch = self.conf.args.git_branch
55+
self.home = self.conf.args.git_home
56+
self.config = self.conf.args.git_repoconfig
57+
self.good_commit = self.conf.args.good_commit
58+
self.bad_commit = self.conf.args.bad_commit
59+
self.bisect_script = self.conf.args.bisect_script
60+
self.bisect_category = self.conf.args.bisect_category
61+
self.append_kernel_cmdline = self.conf.args.append_kernel_cmdline
62+
self.linux_path = os.path.join(self.home, "linux")
63+
if not self.repo:
64+
self.fail("Provide git repo of kernel to install")
65+
if not (self.conf.args.host_ip and self.conf.args.host_user and self.conf.args.host_password):
66+
self.fail(
67+
"Provide host ip user details refer, --host-{ip,user,password}")
68+
69+
def build_kernel(self):
70+
"""
71+
Build and install the Linux kernel.
72+
"""
73+
try:
74+
build_command = "make -j && make modules_install && make install"
75+
err=self.connection.run_command(build_command, timeout=self.host_cmd_timeout)
76+
log.info("Kernel build successful")
77+
return 0,err
78+
except CommandFailed as e:
79+
log.error("Kernel build failed: {}".format(e))
80+
return 4,e
81+
82+
def Store_loc ( self, er) :
83+
pattern = r"([\w\d_]+\/(?:(?:[\w\d_]+\/)*[\w\d_]+\b))"
84+
matches = [match.group(1) for match in re.finditer(pattern,er)]
85+
return matches
86+
87+
def runTest(self):
88+
self.connection.run_command("if [ -d {} ]; then rm -rf {}; fi".format(self.home,self.home))
89+
self.connection.run_command("if [ ! -d {} ]; then mkdir -p {}; fi".format(self.home,self.home))
90+
self.connection.run_command("cd {}".format(self.home))
91+
if not self.branch:
92+
self.branch='master'
93+
log.info("CD DONE")
94+
95+
self.connection.run_command("git clone --depth 1 {} -b {}".format(self.repo, self.branch))
96+
self.connection.run_command("cd linux")
97+
commit = self.connection.run_command(" git log -1 --format=%H")
98+
self.connection.run_command("cd ..")
99+
self.connection.run_command("wget http://ltc-jenkins.aus.stglabs.ibm.com:81/abdul/ioci/kernel_config -o linux/.config")
100+
self.connection.run_command("cd linux && make olddefconfig")
101+
error = self.build_kernel()
102+
log.info("COMMAND RUN")
103+
exit_code = error[0]
104+
errVal = str(error[1])
105+
log.info("printing the exit code '{}'".format(exit_code))
106+
entry=[]
107+
if exit_code != 0:
108+
entry = self.Store_loc(errVal)[-1]
109+
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=""
119+
commiti=commit[-1]
120+
with open('output.json','w') as f:
121+
json.dump({"exit_code":exit_code,"email":em,"commit": commiti,"error":entry},f)
122+
return exit_code

0 commit comments

Comments
 (0)