Skip to content

Commit 959f370

Browse files
authored
Provide ltp_skip_test_file var for LTP, set can_install to False for Swap tools (#4287)
1 parent 7988f1c commit 959f370

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

lisa/microsoft/testsuites/ltp/ltp.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT license.
33
import os
44
import re
5+
import tempfile
56
from dataclasses import dataclass
67
from pathlib import PurePath, PurePosixPath
78
from typing import Any, Dict, List, Optional, Type
@@ -104,6 +105,7 @@ def run_test(
104105
ltp_tests: List[str],
105106
skip_tests: List[str],
106107
log_path: str,
108+
user_input_skip_file: str = "",
107109
block_device: Optional[str] = None,
108110
temp_dir: str = "/tmp/",
109111
ltp_run_timeout: int = 12000,
@@ -147,13 +149,32 @@ def run_test(
147149
parameters += f"-d {temp_dir} "
148150

149151
# add the list of skip tests to run
150-
if len(skip_tests) > 0:
151-
# write skip test to skipfile with newline separator
152-
skip_file_value = "\n".join(skip_tests)
153-
self.node.tools[Echo].write_to_file(
154-
skip_file_value, PurePosixPath(skip_file), sudo=True
152+
if user_input_skip_file:
153+
# copy user provided skip file to remote skip_file location
154+
if not os.path.exists(user_input_skip_file):
155+
raise LisaException(
156+
f"User provided skip file does not exist: {user_input_skip_file}"
157+
)
158+
self._log.debug(f"user_input_skip_file: {user_input_skip_file}")
159+
self.node.shell.copy(
160+
PurePath(user_input_skip_file),
161+
PurePosixPath(skip_file),
155162
)
156163
parameters += f"-S {skip_file} "
164+
elif len(skip_tests) > 0:
165+
# Write skip tests to a local temp file and copy to remote,
166+
# avoiding shell quoting issues entirely.
167+
skip_file_value = "\n".join(skip_tests)
168+
with tempfile.NamedTemporaryFile(
169+
mode="w", suffix=".skipfile", delete=False
170+
) as tmp:
171+
tmp.write(skip_file_value)
172+
local_tmp_path = tmp.name
173+
try:
174+
self.node.shell.copy(PurePath(local_tmp_path), PurePosixPath(skip_file))
175+
finally:
176+
os.unlink(local_tmp_path)
177+
parameters += f"-S {skip_file} "
157178

158179
# Minimum 4M swap space is needed by some mmp test
159180
if self.node.tools[Free].get_swap_size() < 4:

lisa/microsoft/testsuites/ltp/ltpsuite.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def _verify_ltp(
118118
) -> None:
119119
test_list = test_str.split(",") if test_str else []
120120
skip_test_str = variables.get("ltp_skip_test", "")
121+
skip_test_file = variables.get(
122+
"ltp_skip_test_file",
123+
"",
124+
)
121125
source_file = variables.get("ltp_source_file", "")
122126
git_tag = variables.get("ltp_tests_git_tag", "")
123127
run_timeout = int(variables.get("ltp_run_timeout", 12000))
@@ -152,9 +156,10 @@ def _verify_ltp(
152156
)
153157
ltp.run_test(
154158
result,
155-
test_list,
156-
skip_test_list,
157-
log_path,
159+
ltp_tests=test_list,
160+
skip_tests=skip_test_list,
161+
log_path=log_path,
162+
user_input_skip_file=skip_test_file,
158163
block_device=block_device,
159164
ltp_run_timeout=run_timeout,
160165
)

lisa/tools/swap.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,30 @@ class SwapOn(Tool):
2828
def command(self) -> str:
2929
return "swapon"
3030

31+
@property
32+
def can_install(self) -> bool:
33+
return False
34+
3135

3236
class SwapOff(Tool):
3337
@property
3438
def command(self) -> str:
3539
return "swapoff"
3640

41+
@property
42+
def can_install(self) -> bool:
43+
return False
44+
3745

3846
class MkSwap(Tool):
3947
@property
4048
def command(self) -> str:
4149
return "mkswap"
4250

51+
@property
52+
def can_install(self) -> bool:
53+
return False
54+
4355

4456
class Swap(Tool):
4557
# Filename Type Size Used Priority
@@ -137,6 +149,10 @@ class SwapInfoBSD(Swap):
137149
def command(self) -> str:
138150
return "swapinfo"
139151

152+
@property
153+
def can_install(self) -> bool:
154+
return False
155+
140156
def is_swap_enabled(self) -> bool:
141157
entries = find_patterns_in_lines(self.run("-k").stdout, [self._SWAP_ENTRIES])
142158
if len(entries[0]) > 0:

0 commit comments

Comments
 (0)