Skip to content

Commit 1f9ef88

Browse files
authored
[test] Check for sftp-server for remote-run --debug-as-local tests (#18759)
Not all systems have sftp-server installed.
1 parent 9b29e8d commit 1f9ef88

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

test/lit.cfg

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,8 @@ ENV_VAR_PREFIXES = {
941941
}
942942
TARGET_ENV_PREFIX = ENV_VAR_PREFIXES.get(config.target_sdk_name, "")
943943

944-
if not config.target_run and 'remote_run_host' in lit_config.params:
944+
if (not getattr(config, 'target_run', None) and
945+
'remote_run_host' in lit_config.params):
945946
if 'remote_run_tmpdir' not in lit_config.params:
946947
lit_config.fatal("'remote_run_host' provided, but no "
947948
"'remote_run_tmpdir'")
@@ -1039,6 +1040,21 @@ base_runtime_lib_name = (
10391040
if os.path.exists(make_path(compiler_rt_dir, base_runtime_lib_name)):
10401041
config.available_features.add('c_runtime')
10411042

1043+
# For testing the remote-run utility itself, see if we can find an sftp-server
1044+
# binary.
1045+
def find_sftp_server():
1046+
paths_to_try = ['/usr/libexec/sftp-server', '/usr/lib/sftp-server',
1047+
'/usr/libexec/openssh/sftp-server',
1048+
'/usr/lib/openssh/sftp-server']
1049+
return next((path for path in paths_to_try if os.path.isfile(path)), None)
1050+
1051+
sftp_server_path = find_sftp_server()
1052+
if sftp_server_path:
1053+
config.available_features.add('sftp_server')
1054+
config.substitutions.append(('%sftp-server',
1055+
sftp_server_path or 'no-sftp-server'))
1056+
1057+
10421058
if not getattr(config, 'target_run_simple_swift', None):
10431059
config.target_run_simple_swift = (
10441060
'%%empty-directory(%%t) && '

test/remote-run/download.test-sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
REQUIRES: sftp_server
2+
13
RUN: %empty-directory(%t)
24
RUN: %empty-directory(%t-REMOTE)
35
RUN: %debug-remote-run --output-prefix %t touch %t/output

test/remote-run/lit.local.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
config.substitutions = list(config.substitutions)
33

44
config.substitutions.insert(0, ('%debug-remote-run',
5-
'%utils/remote-run --debug-as-local --remote-dir %t-REMOTE') )
5+
'%utils/remote-run --debug-as-local %sftp-server --remote-dir %t-REMOTE') )

test/remote-run/upload-and-download.test-sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
REQUIRES: sftp_server
2+
13
RUN: %empty-directory(%t)
24
RUN: %empty-directory(%t-REMOTE)
35
RUN: touch %t/input %t/BAD

test/remote-run/upload-stderr.test-sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
REQUIRES: sftp_server
2+
13
RUN: %empty-directory(%t)
24
RUN: %empty-directory(%t/REMOTE/input)
35
RUN: chmod a-w %t/REMOTE/input

test/remote-run/upload.test-sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
REQUIRES: sftp_server
2+
13
RUN: %debug-remote-run --input-prefix %S/Inputs/upload/ ls %S/Inputs/upload/1.txt %S/Inputs/upload/2.txt | %FileCheck -check-prefix CHECK-REMOTE %s
24
RUN: ls %t-REMOTE/input/ | %FileCheck %s
35

utils/remote-run

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,14 @@ class RemoteCommandRunner(CommandRunner):
119119
[self.remote_host])
120120

121121
class LocalCommandRunner(CommandRunner):
122-
def __init__(self):
123-
self.cached_sftp_server_path = None
124-
125-
def sftp_server_path(self):
126-
if not self.cached_sftp_server_path:
127-
paths_to_try = ['/usr/libexec/sftp-server', '/usr/lib/sftp-server']
128-
self.cached_sftp_server_path = next(
129-
(path for path in paths_to_try if os.path.exists(path)),
130-
paths_to_try[0])
131-
return self.cached_sftp_server_path
122+
def __init__(self, sftp_server_path):
123+
self.sftp_server_path = sftp_server_path
132124

133125
def remote_invocation(self, command):
134126
return command
135127

136128
def sftp_invocation(self):
137-
return ['/usr/bin/sftp', '-b', '-', '-q', '-D', self.sftp_server_path()]
129+
return ['/usr/bin/sftp', '-b', '-', '-q', '-D', self.sftp_server_path]
138130

139131
def find_transfers(args, source_prefix, dest_prefix):
140132
if source_prefix.endswith(os.path.sep):
@@ -172,7 +164,7 @@ def main():
172164

173165
parser.add_argument('-i', '--identity', dest='identity', metavar='FILE',
174166
help='an SSH identity file (private key) to use')
175-
parser.add_argument('--debug-as-local', action='store_true',
167+
parser.add_argument('--debug-as-local', metavar='/PATH/TO/SFTP-SERVER',
176168
help='run commands locally instead of over SSH, for '
177169
'debugging purposes. The "host" argument is '
178170
'omitted.')
@@ -185,7 +177,7 @@ def main():
185177
args = parser.parse_args()
186178

187179
if args.debug_as_local:
188-
runner = LocalCommandRunner()
180+
runner = LocalCommandRunner(args.debug_as_local)
189181
args.command.insert(0, args.host)
190182
del args.host
191183
else:

0 commit comments

Comments
 (0)