Skip to content

Commit

Permalink
add install_as_sudo = false for kself for linkedIn
Browse files Browse the repository at this point in the history
  • Loading branch information
panfengxue committed Nov 22, 2024
1 parent ceac54d commit 7cf95d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
3 changes: 1 addition & 2 deletions microsoft/testsuites/kselftest/kselftest-suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def verify_kselftest(
file_path = variables.get("kselftest_file_path", "")
try:
kselftest: Kselftest = node.tools.get(
Kselftest,
kselftest_file_path=file_path,
Kselftest, kselftest_file_path=file_path, install_as_sudo=False
)
kselftest.run_all(result, log_path, self._KSELF_TIMEOUT)
except UnsupportedDistroException as identifier:
Expand Down
33 changes: 25 additions & 8 deletions microsoft/testsuites/kselftest/kselftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class Kselftest(Tool):
r"^(?P<status>(not ok|ok))\s+\d+\s+selftests:\s+\S+:\s+(?P<name>\S+)\s*(?:# (?:exit=)?(?P<reason>SKIP|TIMEOUT\d+).*)?(?:# exit=(?P<exit>\d+))?" # noqa: E501
)

_install_as_sudo = True

@property
def command(self) -> str:
return str(self._command)
Expand All @@ -88,14 +90,25 @@ def can_install(self) -> bool:

def _check_exists(self) -> bool:
return (
len(self.node.tools[Ls].list(str(self._kself_installed_dir), sudo=True)) > 0
len(
self.node.tools[Ls].list(
str(self._kself_installed_dir), sudo=self._install_as_sudo
)
)
> 0
)

def __init__(
self, node: Node, kselftest_file_path: str, *args: Any, **kwargs: Any
self,
node: Node,
kselftest_file_path: str,
install_as_sudo: bool = True,
*args: Any,
**kwargs: Any,
) -> None:
super().__init__(node, *args, **kwargs)

self._install_as_sudo = install_as_sudo
# tar file path specified in yml
self._tar_file_path = kselftest_file_path
if self._tar_file_path:
Expand Down Expand Up @@ -128,7 +141,9 @@ def _install(self) -> bool:
mkdir.create_directory(self._remote_tar_path.parent.as_posix())
self.node.shell.copy(PurePath(self._tar_file_path), self._remote_tar_path)
self.node.tools[Tar].extract(
str(self._remote_tar_path), str(self._kself_installed_dir), sudo=True
str(self._remote_tar_path),
str(self._kself_installed_dir),
sudo=self._install_as_sudo,
)
self._log.debug(f"Extracted tar from path {self._remote_tar_path}!")
else:
Expand Down Expand Up @@ -170,13 +185,13 @@ def _install(self) -> bool:
),
dest=PurePath(".config"),
cwd=kernel_path,
sudo=True,
sudo=self._install_as_sudo,
)

self.node.tools[Make].run(
"headers",
cwd=kernel_path,
sudo=True,
sudo=self._install_as_sudo,
expected_exit_code=0,
expected_exit_code_failure_message="failed to build kernel headers.",
).assert_exit_code()
Expand All @@ -186,14 +201,16 @@ def _install(self) -> bool:
cmd=f"./kselftest_install.sh {self._kself_installed_dir}",
shell=True,
cwd=PurePosixPath(kernel_path, "tools/testing/selftests"),
sudo=True,
sudo=self._install_as_sudo,
expected_exit_code=0,
expected_exit_code_failure_message="fail to build & install kselftest",
).assert_exit_code()
# change permissions of kselftest-packages directory
# to run test as non root user.
chmod = self.node.tools[Chmod]
chmod.update_folder(self._kself_installed_dir.as_posix(), "777", sudo=True)
chmod.update_folder(
self._kself_installed_dir.as_posix(), "777", sudo=self._install_as_sudo
)

return self._check_exists()

Expand Down Expand Up @@ -227,7 +244,7 @@ def run_all(
# Allow read permissions for "others" to remote copy the file
# kselftest-results.txt
chmod = self.node.tools[Chmod]
chmod.update_folder(result_file, "644", sudo=True)
chmod.update_folder(result_file, "644", sudo=self._install_as_sudo)

# copy kselftest-results.txt from remote to local node for processing results
remote_copy = self.node.tools[RemoteCopy]
Expand Down

0 comments on commit 7cf95d1

Please sign in to comment.