|
2 | 2 | # Licensed under the MIT license. |
3 | 3 | import os |
4 | 4 | import re |
| 5 | +import tempfile |
5 | 6 | from dataclasses import dataclass |
6 | 7 | from pathlib import PurePath, PurePosixPath |
7 | 8 | from typing import Any, Dict, List, Optional, Type |
@@ -104,6 +105,7 @@ def run_test( |
104 | 105 | ltp_tests: List[str], |
105 | 106 | skip_tests: List[str], |
106 | 107 | log_path: str, |
| 108 | + user_input_skip_file: str = "", |
107 | 109 | block_device: Optional[str] = None, |
108 | 110 | temp_dir: str = "/tmp/", |
109 | 111 | ltp_run_timeout: int = 12000, |
@@ -147,13 +149,32 @@ def run_test( |
147 | 149 | parameters += f"-d {temp_dir} " |
148 | 150 |
|
149 | 151 | # 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), |
155 | 162 | ) |
156 | 163 | 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} " |
157 | 178 |
|
158 | 179 | # Minimum 4M swap space is needed by some mmp test |
159 | 180 | if self.node.tools[Free].get_swap_size() < 4: |
|
0 commit comments