-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added test to run grub unit test cases. #2906
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
# | ||
# See LICENSE for more details. | ||
# | ||
# Copyright: 2024 IBM | ||
# Author: Krishan Gopal Saraswat <[email protected]> | ||
|
||
import os | ||
import shutil | ||
from avocado import Test | ||
from avocado.utils import process | ||
from avocado.utils.software_manager.manager import SoftwareManager | ||
|
||
|
||
class UnitTestCases(Test): | ||
""" | ||
GRUB Unit test cases | ||
""" | ||
def setUp(self): | ||
""" | ||
Build Qemu and install required packages | ||
Source: | ||
https://github.com/qemu/qemu.git | ||
""" | ||
sm = SoftwareManager() | ||
packages = ['meson', 'gcc', 'gettext-devel', 'libisoburn', 'xorriso'] | ||
for package in packages: | ||
if not sm.check_installed(package) and not sm.install(package): | ||
self.cancel( | ||
"Fail to install %s required for this test." % package) | ||
|
||
# Setup Qemu | ||
qemu_version = process.run("qemu-system-ppc --version", | ||
ignore_status=True, sudo=True, shell=True) | ||
if qemu_version.exit_status != 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if qemu_version.exit_status: has same effect and other places as well |
||
qemu_url = "https://github.com/qemu/qemu.git" | ||
process.run("git clone %s" % qemu_url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use avocado git API |
||
# build qemu | ||
cwd = os.getcwd() | ||
self.sourcedir_qemu = os.path.join(cwd, "qemu") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about just self.sourcedir_qemu = os.path.join(os.getcwd(), "qemu") it will help to eliminate extra variable and other places as well |
||
os.chdir(self.sourcedir_qemu) | ||
commands = ["./configure --target-list=ppc-softmmu", | ||
"make", "make install"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about using avocado build utility for make and make install ? |
||
for cmd in commands: | ||
process.run(cmd, ignore_status=True, sudo=True, shell=True) | ||
build_check = process.run("qemu-system-ppc --version", | ||
ignore_status=True, sudo=True, shell=True) | ||
if build_check.exit_status != 0: | ||
self.fail("qemu build is not successful") | ||
|
||
def test_grub_unit_testcases(self): | ||
""" | ||
Compile and build GRUB unit test cases | ||
Source: | ||
https://git.savannah.gnu.org/git/grub.git | ||
""" | ||
cwd = os.getcwd() | ||
self.sourcedir_grub = os.path.join(cwd, "grub") | ||
if not os.path.exists(self.sourcedir_grub): | ||
url = "https://git.savannah.gnu.org/git/grub.git" | ||
process.run("git clone %s" % url) | ||
os.chdir(self.sourcedir_grub) | ||
commands = ["./bootstrap", "./configure", "make -j`nproc`"] | ||
for cmd in commands: | ||
ret = process.run(cmd, ignore_status=True, sudo=True, shell=True) | ||
if ret.exit_status != 0: | ||
self.fail("{} command failed during grub testcase build process".format(cmd)) | ||
# Add unicode fonts before running test | ||
fonts_cmd = "cp /usr/share/grub/unicode.pf2 ." | ||
process.run(fonts_cmd, ignore_status=True, sudo=True, shell=True) | ||
# run the entire testsuite | ||
result = process.run("make check", ignore_status=True, sudo=True, shell=True) | ||
result = result.stdout.decode('utf-8').splitlines() | ||
for line in result: | ||
if "# XFAIL:" in line: | ||
xfail = int(line.strip().split(":")[-1]) | ||
if "# FAIL:" in line: | ||
fail = int(line.strip().split(":")[-1]) | ||
if xfail > 0: | ||
self.fail("Total test fail are {}, please check the logs".format(xfail)) | ||
if fail > 0: | ||
self.fail("Total test fail are {}, please check the logs".format(fail)) | ||
|
||
def tearDown(self): | ||
if os.path.exists(self.sourcedir_grub): | ||
shutil.rmtree(self.sourcedir_grub) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class name seems confusing, can you rename like GrubUnitTestCases